提交 c7579a70 authored 作者: S.Vladykin's avatar S.Vladykin

Reuse TableEngine instances to avoid calling loadUserClass each time.

上级 cf0b53af
...@@ -14,10 +14,10 @@ import java.util.HashSet; ...@@ -14,10 +14,10 @@ import java.util.HashSet;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import org.h2.api.DatabaseEventListener; import org.h2.api.DatabaseEventListener;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
import org.h2.api.JavaObjectSerializer; import org.h2.api.JavaObjectSerializer;
import org.h2.api.TableEngine;
import org.h2.command.CommandInterface; import org.h2.command.CommandInterface;
import org.h2.command.ddl.CreateTableData; import org.h2.command.ddl.CreateTableData;
import org.h2.command.dml.SetTypes; import org.h2.command.dml.SetTypes;
...@@ -104,6 +104,7 @@ public class Database implements DataHandler { ...@@ -104,6 +104,7 @@ public class Database implements DataHandler {
private final HashMap<String, UserDataType> userDataTypes = New.hashMap(); private final HashMap<String, UserDataType> userDataTypes = New.hashMap();
private final HashMap<String, UserAggregate> aggregates = New.hashMap(); private final HashMap<String, UserAggregate> aggregates = New.hashMap();
private final HashMap<String, Comment> comments = New.hashMap(); private final HashMap<String, Comment> comments = New.hashMap();
private final HashMap<String, TableEngine> tableEngines = New.hashMap();
private final Set<Session> userSessions = private final Set<Session> userSessions =
Collections.synchronizedSet(new HashSet<Session>()); Collections.synchronizedSet(new HashSet<Session>());
...@@ -2780,4 +2781,19 @@ public class Database implements DataHandler { ...@@ -2780,4 +2781,19 @@ public class Database implements DataHandler {
} }
} }
public TableEngine getTableEngine(String tableEngine) {
assert Thread.holdsLock(this);
TableEngine engine = tableEngines.get(tableEngine);
if (engine == null) {
try {
engine = (TableEngine) JdbcUtils.loadUserClass(tableEngine).newInstance();
} catch (Exception e) {
throw DbException.convert(e);
}
tableEngines.put(tableEngine, engine);
}
return engine;
}
} }
...@@ -576,13 +576,7 @@ public class Schema extends DbObjectBase { ...@@ -576,13 +576,7 @@ public class Schema extends DbObjectBase {
} }
} }
if (data.tableEngine != null) { if (data.tableEngine != null) {
TableEngine engine; return database.getTableEngine(data.tableEngine).createTable(data);
try {
engine = (TableEngine) JdbcUtils.loadUserClass(data.tableEngine).newInstance();
} catch (Exception e) {
throw DbException.convert(e);
}
return engine.createTable(data);
} }
return new RegularTable(data); return new RegularTable(data);
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论