提交 0a6b0263 authored 作者: Thomas Mueller's avatar Thomas Mueller

Merge pull request #152 from svladykin/table_engine

Table engine improvements
...@@ -5890,8 +5890,6 @@ public class Parser { ...@@ -5890,8 +5890,6 @@ public class Parser {
command.setTableEngineParams(tableEngineParams); command.setTableEngineParams(tableEngineParams);
} }
} }
} else if (database.getSettings().defaultTableEngine != null) {
command.setTableEngine(database.getSettings().defaultTableEngine);
} }
// MySQL compatibility // MySQL compatibility
if (readIf("AUTO_INCREMENT")) { if (readIf("AUTO_INCREMENT")) {
......
...@@ -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;
}
} }
...@@ -328,7 +328,7 @@ public class DbSettings extends SettingsBase { ...@@ -328,7 +328,7 @@ public class DbSettings extends SettingsBase {
* (default: null).<br /> * (default: null).<br />
* The default table engine to use for new tables. * The default table engine to use for new tables.
*/ */
public String defaultTableEngine = get("DEFAULT_TABLE_ENGINE", null); public final String defaultTableEngine = get("DEFAULT_TABLE_ENGINE", null);
/** /**
* Database setting <code>MV_STORE</code> * Database setting <code>MV_STORE</code>
......
...@@ -8,7 +8,6 @@ package org.h2.schema; ...@@ -8,7 +8,6 @@ package org.h2.schema;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import org.h2.api.ErrorCode; import org.h2.api.ErrorCode;
import org.h2.api.TableEngine; import org.h2.api.TableEngine;
import org.h2.command.ddl.CreateTableData; import org.h2.command.ddl.CreateTableData;
...@@ -16,6 +15,7 @@ import org.h2.constraint.Constraint; ...@@ -16,6 +15,7 @@ import org.h2.constraint.Constraint;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.engine.DbObject; import org.h2.engine.DbObject;
import org.h2.engine.DbObjectBase; import org.h2.engine.DbObjectBase;
import org.h2.engine.DbSettings;
import org.h2.engine.FunctionAlias; import org.h2.engine.FunctionAlias;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.engine.SysProperties; import org.h2.engine.SysProperties;
...@@ -568,18 +568,15 @@ public class Schema extends DbObjectBase { ...@@ -568,18 +568,15 @@ public class Schema extends DbObjectBase {
} }
data.schema = this; data.schema = this;
if (data.tableEngine == null) { if (data.tableEngine == null) {
if (database.getSettings().mvStore) { DbSettings s = database.getSettings();
if (s.defaultTableEngine != null) {
data.tableEngine = s.defaultTableEngine;
} else if (s.mvStore) {
data.tableEngine = MVTableEngine.class.getName(); data.tableEngine = MVTableEngine.class.getName();
} }
} }
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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论