提交 2a754e01 authored 作者: Thomas Mueller's avatar Thomas Mueller

Temporary linked tables are now supported.

上级 1302b53b
......@@ -27,6 +27,9 @@ public class CreateLinkedTable extends SchemaCommand {
private String comment;
private boolean emitUpdates;
private boolean force;
private boolean temporary;
private boolean globalTemporary;
private boolean readOnly;
public CreateLinkedTable(Session session, Schema schema) {
super(session, schema);
......@@ -73,8 +76,15 @@ public class CreateLinkedTable extends SchemaCommand {
}
int id = getObjectId(false, true);
TableLink table = getSchema().createTableLink(id, tableName, driver, url, user, password, originalTable, emitUpdates, force);
table.setTemporary(temporary);
table.setGlobalTemporary(globalTemporary);
table.setComment(comment);
db.addSchemaObject(session, table);
table.setReadOnly(readOnly);
if (temporary && !globalTemporary) {
session.addLocalTempTable(table);
} else {
db.addSchemaObject(session, table);
}
return 0;
}
......@@ -90,4 +100,16 @@ public class CreateLinkedTable extends SchemaCommand {
this.force = force;
}
public void setTemporary(boolean temp) {
this.temporary = temp;
}
public void setGlobalTemporary(boolean globalTemp) {
this.globalTemporary = globalTemp;
}
public void setReadOnly(boolean readOnly) {
this.readOnly = readOnly;
}
}
......@@ -49,7 +49,8 @@ public class TableLink extends Table {
private boolean storesLowerCase;
private boolean storesMixedCase;
private boolean supportsMixedCaseIdentifiers;
private boolean globalTemporary;
private boolean readOnly;
public TableLink(Schema schema, int id, String name, String driver, String url, String user, String password,
String originalTable, boolean emitUpdates, boolean force) throws SQLException {
......@@ -240,7 +241,14 @@ public class TableLink extends Table {
public String getCreateSQL() {
StringBuffer buff = new StringBuffer();
buff.append("CREATE FORCE LINKED TABLE ");
buff.append("CREATE FORCE ");
if (getTemporary()) {
if (globalTemporary) {
buff.append("GLOBAL ");
}
buff.append("TEMP ");
}
buff.append("LINKED TABLE ");
buff.append(getSQL());
if (comment != null) {
buff.append(" COMMENT ");
......@@ -260,6 +268,9 @@ public class TableLink extends Table {
if (emitUpdates) {
buff.append(" EMIT UPDATES");
}
if (readOnly) {
buff.append(" READONLY");
}
return buff.toString();
}
......@@ -279,12 +290,20 @@ public class TableLink extends Table {
public Index getScanIndex(Session session) {
return linkedIndex;
}
private void checkReadOnly() throws SQLException {
if (readOnly) {
throw Message.getSQLException(ErrorCode.DATABASE_IS_READ_ONLY);
}
}
public void removeRow(Session session, Row row) throws SQLException {
checkReadOnly();
getScanIndex(session).remove(session, row);
}
public void addRow(Session session, Row row) throws SQLException {
checkReadOnly();
getScanIndex(session).add(session, row);
}
......@@ -395,6 +414,7 @@ public class TableLink extends Table {
public void updateRows(Prepared prepared, Session session, RowList rows)
throws SQLException {
boolean deleteInsert;
checkReadOnly();
if (emitUpdates) {
for (rows.reset(); rows.hasNext();) {
prepared.checkCancelled();
......@@ -413,4 +433,12 @@ public class TableLink extends Table {
}
}
public void setGlobalTemporary(boolean globalTemporary) {
this.globalTemporary = globalTemporary;
}
public void setReadOnly(boolean readOnly) {
this.readOnly = readOnly;
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论