提交 0c6d0c44 authored 作者: Owner's avatar Owner

Removed last meta fix - seems to not be needed

上级 341a5915
...@@ -23,7 +23,6 @@ import org.h2.schema.Sequence; ...@@ -23,7 +23,6 @@ import org.h2.schema.Sequence;
import org.h2.table.Column; import org.h2.table.Column;
import org.h2.table.IndexColumn; import org.h2.table.IndexColumn;
import org.h2.table.Table; import org.h2.table.Table;
import org.h2.util.ColumnNamer;
import org.h2.util.New; import org.h2.util.New;
import org.h2.value.DataType; import org.h2.value.DataType;
import org.h2.value.Value; import org.h2.value.Value;
...@@ -100,7 +99,6 @@ public class CreateTable extends SchemaCommand { ...@@ -100,7 +99,6 @@ public class CreateTable extends SchemaCommand {
@Override @Override
public int update() { public int update() {
boolean metaLockAquired = false;
if (!transactional) { if (!transactional) {
session.commit(true); session.commit(true);
} }
...@@ -109,131 +107,122 @@ public class CreateTable extends SchemaCommand { ...@@ -109,131 +107,122 @@ public class CreateTable extends SchemaCommand {
data.persistIndexes = false; data.persistIndexes = false;
} }
boolean isSessionTemporary = data.temporary && !data.globalTemporary; boolean isSessionTemporary = data.temporary && !data.globalTemporary;
try { if (!isSessionTemporary) {
if (!isSessionTemporary) { db.lockMeta(session);
db.lockMeta(session); }
metaLockAquired = true; if (getSchema().resolveTableOrView(session, data.tableName) != null) {
if (ifNotExists) {
return 0;
} }
if (getSchema().resolveTableOrView(session, data.tableName) != null) { throw DbException.get(ErrorCode.TABLE_OR_VIEW_ALREADY_EXISTS_1, data.tableName);
if (ifNotExists) { }
return 0; if (asQuery != null) {
} asQuery.prepare();
throw DbException.get(ErrorCode.TABLE_OR_VIEW_ALREADY_EXISTS_1, data.tableName); if (data.columns.size() == 0) {
generateColumnsFromQuery();
} else if (data.columns.size() != asQuery.getColumnCount()) {
throw DbException.get(ErrorCode.COLUMN_COUNT_DOES_NOT_MATCH);
} }
if (asQuery != null) { }
asQuery.prepare(); if (pkColumns != null) {
if (data.columns.size() == 0) { for (Column c : data.columns) {
generateColumnsFromQuery(); for (IndexColumn idxCol : pkColumns) {
} else if (data.columns.size() != asQuery.getColumnCount()) { if (c.getName().equals(idxCol.columnName)) {
throw DbException.get(ErrorCode.COLUMN_COUNT_DOES_NOT_MATCH); c.setNullable(false);
}
} }
} }
if (pkColumns != null) { }
for (Column c : data.columns) { data.id = getObjectId();
for (IndexColumn idxCol : pkColumns) { data.create = create;
if (c.getName().equals(idxCol.columnName)) { data.session = session;
c.setNullable(false); Table table = getSchema().createTable(data);
} ArrayList<Sequence> sequences = New.arrayList();
} for (Column c : data.columns) {
if (c.isAutoIncrement()) {
int objId = getObjectId();
c.convertAutoIncrementToSequence(session, getSchema(), objId, data.temporary);
if (!Constants.CLUSTERING_DISABLED
.equals(session.getDatabase().getCluster())) {
throw DbException.getUnsupportedException(
"CLUSTERING && auto-increment columns");
} }
} }
data.id = getObjectId(); Sequence seq = c.getSequence();
data.create = create; if (seq != null) {
data.session = session; sequences.add(seq);
Table table = getSchema().createTable(data); }
ArrayList<Sequence> sequences = New.arrayList(); }
table.setComment(comment);
if (isSessionTemporary) {
if (onCommitDrop) {
table.setOnCommitDrop(true);
}
if (onCommitTruncate) {
table.setOnCommitTruncate(true);
}
session.addLocalTempTable(table);
} else {
db.lockMeta(session);
db.addSchemaObject(session, table);
}
try {
for (Column c : data.columns) { for (Column c : data.columns) {
if (c.isAutoIncrement()) { c.prepareExpression(session);
int objId = getObjectId();
c.convertAutoIncrementToSequence(session, getSchema(), objId, data.temporary);
if (!Constants.CLUSTERING_DISABLED
.equals(session.getDatabase().getCluster())) {
throw DbException.getUnsupportedException(
"CLUSTERING && auto-increment columns");
}
}
Sequence seq = c.getSequence();
if (seq != null) {
sequences.add(seq);
}
} }
table.setComment(comment); for (Sequence sequence : sequences) {
if (isSessionTemporary) { table.addSequence(sequence);
if (onCommitDrop) {
table.setOnCommitDrop(true);
}
if (onCommitTruncate) {
table.setOnCommitTruncate(true);
}
session.addLocalTempTable(table);
} else {
db.lockMeta(session);
db.addSchemaObject(session, table);
} }
try { for (DefineCommand command : constraintCommands) {
for (Column c : data.columns) { command.setTransactional(transactional);
c.prepareExpression(session); command.update();
} }
for (Sequence sequence : sequences) { if (asQuery != null) {
table.addSequence(sequence); boolean old = session.isUndoLogEnabled();
} try {
for (DefineCommand command : constraintCommands) { session.setUndoLogEnabled(false);
command.setTransactional(transactional); session.startStatementWithinTransaction();
command.update(); Insert insert = null;
insert = new Insert(session);
insert.setSortedInsertMode(sortedInsertMode);
insert.setQuery(asQuery);
insert.setTable(table);
insert.setInsertFromSelect(true);
insert.prepare();
insert.update();
} finally {
session.setUndoLogEnabled(old);
} }
if (asQuery != null) { }
boolean old = session.isUndoLogEnabled(); HashSet<DbObject> set = New.hashSet();
try { set.clear();
session.setUndoLogEnabled(false); table.addDependencies(set);
session.startStatementWithinTransaction(); for (DbObject obj : set) {
Insert insert = null; if (obj == table) {
insert = new Insert(session); continue;
insert.setSortedInsertMode(sortedInsertMode);
insert.setQuery(asQuery);
insert.setTable(table);
insert.setInsertFromSelect(true);
insert.prepare();
insert.update();
} finally {
session.setUndoLogEnabled(old);
}
} }
HashSet<DbObject> set = New.hashSet(); if (obj.getType() == DbObject.TABLE_OR_VIEW) {
set.clear(); if (obj instanceof Table) {
table.addDependencies(set); Table t = (Table) obj;
for (DbObject obj : set) { if (t.getId() > table.getId()) {
if (obj == table) { throw DbException.get(
continue; ErrorCode.FEATURE_NOT_SUPPORTED_1,
} "Table depends on another table " +
if (obj.getType() == DbObject.TABLE_OR_VIEW) { "with a higher ID: " + t +
if (obj instanceof Table) { ", this is currently not supported, " +
Table t = (Table) obj; "as it would prevent the database from " +
if (t.getId() > table.getId()) { "being re-opened");
throw DbException.get(
ErrorCode.FEATURE_NOT_SUPPORTED_1,
"Table depends on another table " +
"with a higher ID: " + t +
", this is currently not supported, " +
"as it would prevent the database from " +
"being re-opened");
}
} }
} }
} }
} catch (DbException e) {
db.checkPowerOff();
db.removeSchemaObject(session, table);
if (!transactional) {
session.commit(true);
}
throw e;
} }
} } catch (DbException e) {
finally{ db.checkPowerOff();
db.removeSchemaObject(session, table);
if (!isSessionTemporary && metaLockAquired) { if (!transactional) {
db.unlockMeta(session); session.commit(true);
} }
throw e;
} }
return 0; return 0;
} }
...@@ -241,11 +230,10 @@ public class CreateTable extends SchemaCommand { ...@@ -241,11 +230,10 @@ public class CreateTable extends SchemaCommand {
private void generateColumnsFromQuery() { private void generateColumnsFromQuery() {
int columnCount = asQuery.getColumnCount(); int columnCount = asQuery.getColumnCount();
ArrayList<Expression> expressions = asQuery.getExpressions(); ArrayList<Expression> expressions = asQuery.getExpressions();
ColumnNamer columnNamer= new ColumnNamer(session);
for (int i = 0; i < columnCount; i++) { for (int i = 0; i < columnCount; i++) {
Expression expr = expressions.get(i); Expression expr = expressions.get(i);
int type = expr.getType(); int type = expr.getType();
String name = columnNamer.getColumnName(expr,i,expr.getAlias()); String name = expr.getAlias();
long precision = expr.getPrecision(); long precision = expr.getPrecision();
int displaySize = expr.getDisplaySize(); int displaySize = expr.getDisplaySize();
DataType dt = DataType.getDataType(type); DataType dt = DataType.getDataType(type);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论