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

Temporary linked tables are now supported.

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