提交 1ce2de09 authored 作者: Sergi Vladykin's avatar Sergi Vladykin

Fixes and improvements in PG protocol support. New method getCommandType() was…

Fixes and improvements in PG protocol support. New method getCommandType() was added to CommandInterface to return the type of current SQL statement.
上级 76ba1ff8
...@@ -94,4 +94,8 @@ public class CommandContainer extends Command { ...@@ -94,4 +94,8 @@ public class CommandContainer extends Command {
return prepared.isCacheable(); return prepared.isCacheable();
} }
public int getCommandType() {
return prepared.getType();
}
} }
...@@ -15,6 +15,445 @@ import org.h2.result.ResultInterface; ...@@ -15,6 +15,445 @@ import org.h2.result.ResultInterface;
*/ */
public interface CommandInterface { public interface CommandInterface {
/**
* The type for unknown statement.
*/
int UNKNOWN = 0;
// ddl operations
/**
* The type of a ALTER INDEX RENAME statement.
*/
int ALTER_INDEX_RENAME = 1;
/**
* The type of a ALTER SCHEMA RENAME statement.
*/
int ALTER_SCHEMA_RENAME = 2;
/**
* The type of a ALTER TABLE ADD CHECK statement.
*/
int ALTER_TABLE_ADD_CONSTRAINT_CHECK = 3;
/**
* The type of a ALTER TABLE ADD UNIQUE statement.
*/
int ALTER_TABLE_ADD_CONSTRAINT_UNIQUE = 4;
/**
* The type of a ALTER TABLE ADD FOREIGN KEY statement.
*/
int ALTER_TABLE_ADD_CONSTRAINT_REFERENTIAL = 5;
/**
* The type of a ALTER TABLE ADD PRIMARY KEY statement.
*/
int ALTER_TABLE_ADD_CONSTRAINT_PRIMARY_KEY = 6;
/**
* The type of a ALTER TABLE ADD statement.
*/
int ALTER_TABLE_ADD_COLUMN = 7;
/**
* The type of a ALTER TABLE ALTER COLUMN SET NOT NULL statement.
*/
int ALTER_TABLE_ALTER_COLUMN_NOT_NULL = 8;
/**
* The type of a ALTER TABLE ALTER COLUMN SET NULL statement.
*/
int ALTER_TABLE_ALTER_COLUMN_NULL = 9;
/**
* The type of a ALTER TABLE ALTER COLUMN SET DEFAULT statement.
*/
int ALTER_TABLE_ALTER_COLUMN_DEFAULT = 10;
/**
* The type of an ALTER TABLE ALTER COLUMN statement that changes the column
* data type.
*/
int ALTER_TABLE_ALTER_COLUMN_CHANGE_TYPE = 11;
/**
* The type of a ALTER TABLE DROP COLUMN statement.
*/
int ALTER_TABLE_DROP_COLUMN = 12;
/**
* The type of a ALTER TABLE ALTER COLUMN SELECTIVITY statement.
*/
int ALTER_TABLE_ALTER_COLUMN_SELECTIVITY = 13;
/**
* The type of a ALTER TABLE DROP CONSTRAINT statement.
*/
int ALTER_TABLE_DROP_CONSTRAINT = 14;
/**
* The type of a ALTER TABLE RENAME statement.
*/
int ALTER_TABLE_RENAME = 15;
/**
* The type of a ALTER TABLE ALTER COLUMN RENAME statement.
*/
int ALTER_TABLE_ALTER_COLUMN_RENAME = 16;
/**
* The type of a ALTER USER ADMIN statement.
*/
int ALTER_USER_ADMIN = 17;
/**
* The type of a ALTER USER RENAME statement.
*/
int ALTER_USER_RENAME = 18;
/**
* The type of a ALTER USER SET PASSWORD statement.
*/
int ALTER_USER_SET_PASSWORD = 19;
/**
* The type of a ALTER VIEW statement.
*/
int ALTER_VIEW = 20;
/**
* The type of a ANALYZE statement.
*/
int ANALYZE = 21;
/**
* The type of a CREATE AGGREGATE statement.
*/
int CREATE_AGGREGATE = 22;
/**
* The type of a CREATE CONSTANT statement.
*/
int CREATE_CONSTANT = 23;
/**
* The type of a CREATE ALIAS statement.
*/
int CREATE_ALIAS = 24;
/**
* The type of a CREATE INDEX statement.
*/
int CREATE_INDEX = 25;
/**
* The type of a CREATE LINKED TABLE statement.
*/
int CREATE_LINKED_TABLE = 26;
/**
* The type of a CREATE ROLE statement.
*/
int CREATE_ROLE = 27;
/**
* The type of a CREATE SCHEMA statement.
*/
int CREATE_SCHEMA = 28;
/**
* The type of a CREATE SEQUENCE statement.
*/
int CREATE_SEQUENCE = 29;
/**
* The type of a CREATE TABLE statement.
*/
int CREATE_TABLE = 30;
/**
* The type of a CREATE TRIGGER statement.
*/
int CREATE_TRIGGER = 31;
/**
* The type of a CREATE USER statement.
*/
int CREATE_USER = 32;
/**
* The type of a CREATE DOMAIN statement.
*/
int CREATE_DOMAIN = 33;
/**
* The type of a CREATE VIEW statement.
*/
int CREATE_VIEW = 34;
/**
* The type of a DEALLOCATE statement.
*/
int DEALLOCATE = 35;
/**
* The type of a DROP AGGREGATE statement.
*/
int DROP_AGGREGATE = 36;
/**
* The type of a DROP CONSTANT statement.
*/
int DROP_CONSTANT = 37;
/**
* The type of a DROP ALL OBJECTS statement.
*/
int DROP_ALL_OBJECTS = 38;
/**
* The type of a DROP ALIAS statement.
*/
int DROP_ALIAS = 39;
/**
* The type of a DROP INDEX statement.
*/
int DROP_INDEX = 40;
/**
* The type of a DROP ROLE statement.
*/
int DROP_ROLE = 41;
/**
* The type of a DROP SCHEMA statement.
*/
int DROP_SCHEMA = 42;
/**
* The type of a DROP SEQUENCE statement.
*/
int DROP_SEQUENCE = 43;
/**
* The type of a DROP TABLE statement.
*/
int DROP_TABLE = 44;
/**
* The type of a DROP TRIGGER statement.
*/
int DROP_TRIGGER = 45;
/**
* The type of a DROP USER statement.
*/
int DROP_USER = 46;
/**
* The type of a DROP DOMAIN statement.
*/
int DROP_DOMAIN = 47;
/**
* The type of a DROP VIEW statement.
*/
int DROP_VIEW = 48;
/**
* The type of a GRANT statement.
*/
int GRANT = 49;
/**
* The type of a REVOKE statement.
*/
int REVOKE = 50;
/**
* The type of a PREPARE statement.
*/
int PREPARE = 51;
/**
* The type of a COMMENT statement.
*/
int COMMENT = 52;
/**
* The type of a TRUNCATE TABLE statement.
*/
int TRUNCATE_TABLE = 53;
// dml operations
/**
* The type of a ALTER SEQUENCE statement.
*/
int ALTER_SEQUENCE = 54;
/**
* The type of a ALTER TABLE SET REFERENTIAL_INTEGRITY statement.
*/
int ALTER_TABLE_SET_REFERENTIAL_INTEGRITY = 55;
/**
* The type of a BACKUP statement.
*/
int BACKUP = 56;
/**
* The type of a CALL statement.
*/
int CALL = 57;
/**
* The type of a DELETE statement.
*/
int DELETE = 58;
/**
* The type of a EXECUTE statement.
*/
int EXECUTE = 59;
/**
* The type of a EXPLAIN statement.
*/
int EXPLAIN = 60;
/**
* The type of a INSERT statement.
*/
int INSERT = 61;
/**
* The type of a MERGE statement.
*/
int MERGE = 62;
/**
* The type of a no operation statement.
*/
int NO_OPERATION = 63;
/**
* The type of a RUNSCRIPT statement.
*/
int RUNSCRIPT = 64;
/**
* The type of a SCRIPT statement.
*/
int SCRIPT = 65;
/**
* The type of a SELECT statement.
*/
int SELECT = 66;
/**
* The type of a SET statement.
*/
int SET = 67;
/**
* The type of a UPDATE statement.
*/
int UPDATE = 68;
// transaction commands
/**
* The type of a SET AUTOCOMMIT statement.
*/
int SET_AUTOCOMMIT_TRUE = 69;
/**
* The type of a SET AUTOCOMMIT statement.
*/
int SET_AUTOCOMMIT_FALSE = 70;
/**
* The type of a COMMIT statement.
*/
int COMMIT = 71;
/**
* The type of a ROLLBACK statement.
*/
int ROLLBACK = 72;
/**
* The type of a CHECKPOINT statement.
*/
int CHECKPOINT = 73;
/**
* The type of a SAVEPOINT statement.
*/
int SAVEPOINT = 74;
/**
* The type of a ROLLBACK TO SAVEPOINT statement.
*/
int ROLLBACK_TO_SAVEPOINT = 75;
/**
* The type of a CHECKPOINT SYNC statement.
*/
int CHECKPOINT_SYNC = 76;
/**
* The type of a PREPARE COMMIT statement.
*/
int PREPARE_COMMIT = 77;
/**
* The type of a COMMIT TRANSACTION statement.
*/
int COMMIT_TRANSACTION = 78;
/**
* The type of a ROLLBACK TRANSACTION statement.
*/
int ROLLBACK_TRANSACTION = 79;
/**
* The type of a SHUTDOWN statement.
*/
int SHUTDOWN = 80;
/**
* The type of a SHUTDOWN IMMEDIATELY statement.
*/
int SHUTDOWN_IMMEDIATELY = 81;
/**
* The type of a SHUTDOWN COMPACT statement.
*/
int SHUTDOWN_COMPACT = 82;
/**
* The type of a BEGIN {WORK|TRANSACTION} statement.
*/
int BEGIN = 83;
/**
* The type of a SHUTDOWN DEFRAG statement.
*/
int SHUTDOWN_DEFRAG = 84;
/**
* Get command type.
*
* @return one of the constants above
*/
int getCommandType();
/** /**
* Check if this is a query. * Check if this is a query.
* *
......
...@@ -65,4 +65,8 @@ public class CommandList extends Command { ...@@ -65,4 +65,8 @@ public class CommandList extends Command {
return command.queryMeta(); return command.queryMeta();
} }
public int getCommandType() {
return command.getCommandType();
}
} }
...@@ -248,4 +248,8 @@ public class CommandRemote implements CommandInterface { ...@@ -248,4 +248,8 @@ public class CommandRemote implements CommandInterface {
return TraceObject.toString(sql, getParameters()); return TraceObject.toString(sql, getParameters());
} }
public int getCommandType() {
return UNKNOWN;
}
} }
...@@ -81,6 +81,14 @@ public abstract class Prepared { ...@@ -81,6 +81,14 @@ public abstract class Prepared {
*/ */
public abstract ResultInterface queryMeta(); public abstract ResultInterface queryMeta();
/**
* Get the command type as defined in CommandInterface
*
* @return the statement type
*/
public abstract int getType();
/** /**
* Check if this command is read only. * Check if this command is read only.
* *
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
package org.h2.command.ddl; package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.engine.Right; import org.h2.engine.Right;
...@@ -47,4 +48,8 @@ public class AlterIndexRename extends DefineCommand { ...@@ -47,4 +48,8 @@ public class AlterIndexRename extends DefineCommand {
return 0; return 0;
} }
public int getType() {
return CommandInterface.ALTER_INDEX_RENAME;
}
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
package org.h2.command.ddl; package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.engine.Session; import org.h2.engine.Session;
...@@ -51,4 +52,8 @@ public class AlterSchemaRename extends DefineCommand { ...@@ -51,4 +52,8 @@ public class AlterSchemaRename extends DefineCommand {
return 0; return 0;
} }
public int getType() {
return CommandInterface.ALTER_SCHEMA_RENAME;
}
} }
...@@ -8,6 +8,7 @@ package org.h2.command.ddl; ...@@ -8,6 +8,7 @@ package org.h2.command.ddl;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.constraint.Constraint; import org.h2.constraint.Constraint;
import org.h2.constraint.ConstraintCheck; import org.h2.constraint.ConstraintCheck;
...@@ -34,26 +35,6 @@ import org.h2.util.New; ...@@ -34,26 +35,6 @@ import org.h2.util.New;
*/ */
public class AlterTableAddConstraint extends SchemaCommand { public class AlterTableAddConstraint extends SchemaCommand {
/**
* The type of a ALTER TABLE ADD CHECK statement.
*/
public static final int CHECK = 0;
/**
* The type of a ALTER TABLE ADD UNIQUE statement.
*/
public static final int UNIQUE = 1;
/**
* The type of a ALTER TABLE ADD FOREIGN KEY statement.
*/
public static final int REFERENTIAL = 2;
/**
* The type of a ALTER TABLE ADD PRIMARY KEY statement.
*/
public static final int PRIMARY_KEY = 3;
private int type; private int type;
private String constraintName; private String constraintName;
private String tableName; private String tableName;
...@@ -111,7 +92,7 @@ public class AlterTableAddConstraint extends SchemaCommand { ...@@ -111,7 +92,7 @@ public class AlterTableAddConstraint extends SchemaCommand {
table.lock(session, true, true); table.lock(session, true, true);
Constraint constraint; Constraint constraint;
switch (type) { switch (type) {
case PRIMARY_KEY: { case CommandInterface.ALTER_TABLE_ADD_CONSTRAINT_PRIMARY_KEY: {
IndexColumn.mapColumns(indexColumns, table); IndexColumn.mapColumns(indexColumns, table);
index = table.findPrimaryKey(); index = table.findPrimaryKey();
ArrayList<Constraint> constraints = table.getConstraints(); ArrayList<Constraint> constraints = table.getConstraints();
...@@ -153,7 +134,7 @@ public class AlterTableAddConstraint extends SchemaCommand { ...@@ -153,7 +134,7 @@ public class AlterTableAddConstraint extends SchemaCommand {
constraint = pk; constraint = pk;
break; break;
} }
case UNIQUE: { case CommandInterface.ALTER_TABLE_ADD_CONSTRAINT_UNIQUE: {
IndexColumn.mapColumns(indexColumns, table); IndexColumn.mapColumns(indexColumns, table);
boolean isOwner = false; boolean isOwner = false;
if (index != null && canUseUniqueIndex(index, table, indexColumns)) { if (index != null && canUseUniqueIndex(index, table, indexColumns)) {
...@@ -174,7 +155,7 @@ public class AlterTableAddConstraint extends SchemaCommand { ...@@ -174,7 +155,7 @@ public class AlterTableAddConstraint extends SchemaCommand {
constraint = unique; constraint = unique;
break; break;
} }
case CHECK: { case CommandInterface.ALTER_TABLE_ADD_CONSTRAINT_CHECK: {
int id = getObjectId(); int id = getObjectId();
String name = generateConstraintName(table); String name = generateConstraintName(table);
ConstraintCheck check = new ConstraintCheck(getSchema(), id, name, table); ConstraintCheck check = new ConstraintCheck(getSchema(), id, name, table);
...@@ -189,7 +170,7 @@ public class AlterTableAddConstraint extends SchemaCommand { ...@@ -189,7 +170,7 @@ public class AlterTableAddConstraint extends SchemaCommand {
} }
break; break;
} }
case REFERENTIAL: { case CommandInterface.ALTER_TABLE_ADD_CONSTRAINT_REFERENTIAL: {
Table refTable = refSchema.getTableOrView(session, refTableName); Table refTable = refSchema.getTableOrView(session, refTableName);
session.getUser().checkRight(refTable, Right.ALL); session.getUser().checkRight(refTable, Right.ALL);
if (!refTable.canReference()) { if (!refTable.canReference()) {
......
...@@ -8,6 +8,7 @@ package org.h2.command.ddl; ...@@ -8,6 +8,7 @@ package org.h2.command.ddl;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.h2.command.CommandInterface;
import org.h2.command.Parser; import org.h2.command.Parser;
import org.h2.command.Prepared; import org.h2.command.Prepared;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
...@@ -44,42 +45,6 @@ import org.h2.util.New; ...@@ -44,42 +45,6 @@ import org.h2.util.New;
*/ */
public class AlterTableAlterColumn extends SchemaCommand { public class AlterTableAlterColumn extends SchemaCommand {
/**
* The type of a ALTER TABLE ALTER COLUMN SET NOT NULL statement.
*/
public static final int NOT_NULL = 0;
/**
* The type of a ALTER TABLE ALTER COLUMN SET NULL statement.
*/
public static final int NULL = 1;
/**
* The type of a ALTER TABLE ALTER COLUMN SET DEFAULT statement.
*/
public static final int DEFAULT = 2;
/**
* The type of a ALTER TABLE ALTER COLUMN statement that changes the column
* data type.
*/
public static final int CHANGE_TYPE = 3;
/**
* The type of a ALTER TABLE ADD statement.
*/
public static final int ADD = 4;
/**
* The type of a ALTER TABLE DROP COLUMN statement.
*/
public static final int DROP = 5;
/**
* The type of a ALTER TABLE ALTER COLUMN SELECTIVITY statement.
*/
public static final int SELECTIVITY = 6;
private Table table; private Table table;
private Column oldColumn; private Column oldColumn;
private Column newColumn; private Column newColumn;
...@@ -112,7 +77,7 @@ public class AlterTableAlterColumn extends SchemaCommand { ...@@ -112,7 +77,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
table.lock(session, true, true); table.lock(session, true, true);
Sequence sequence = oldColumn == null ? null : oldColumn.getSequence(); Sequence sequence = oldColumn == null ? null : oldColumn.getSequence();
switch (type) { switch (type) {
case NOT_NULL: { case CommandInterface.ALTER_TABLE_ALTER_COLUMN_NOT_NULL: {
if (!oldColumn.isNullable()) { if (!oldColumn.isNullable()) {
// no change // no change
break; break;
...@@ -122,7 +87,7 @@ public class AlterTableAlterColumn extends SchemaCommand { ...@@ -122,7 +87,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
db.update(session, table); db.update(session, table);
break; break;
} }
case NULL: { case CommandInterface.ALTER_TABLE_ALTER_COLUMN_NULL: {
if (oldColumn.isNullable()) { if (oldColumn.isNullable()) {
// no change // no change
break; break;
...@@ -132,14 +97,14 @@ public class AlterTableAlterColumn extends SchemaCommand { ...@@ -132,14 +97,14 @@ public class AlterTableAlterColumn extends SchemaCommand {
db.update(session, table); db.update(session, table);
break; break;
} }
case DEFAULT: { case CommandInterface.ALTER_TABLE_ALTER_COLUMN_DEFAULT: {
oldColumn.setSequence(null); oldColumn.setSequence(null);
oldColumn.setDefaultExpression(session, defaultExpression); oldColumn.setDefaultExpression(session, defaultExpression);
removeSequence(sequence); removeSequence(sequence);
db.update(session, table); db.update(session, table);
break; break;
} }
case CHANGE_TYPE: { case CommandInterface.ALTER_TABLE_ALTER_COLUMN_CHANGE_TYPE: {
oldColumn.setSequence(null); oldColumn.setSequence(null);
oldColumn.setDefaultExpression(session, null); oldColumn.setDefaultExpression(session, null);
oldColumn.setConvertNullToDefault(false); oldColumn.setConvertNullToDefault(false);
...@@ -152,12 +117,12 @@ public class AlterTableAlterColumn extends SchemaCommand { ...@@ -152,12 +117,12 @@ public class AlterTableAlterColumn extends SchemaCommand {
copyData(); copyData();
break; break;
} }
case ADD: { case CommandInterface.ALTER_TABLE_ADD_COLUMN: {
convertAutoIncrementColumn(newColumn); convertAutoIncrementColumn(newColumn);
copyData(); copyData();
break; break;
} }
case DROP: { case CommandInterface.ALTER_TABLE_DROP_COLUMN: {
if (table.getColumns().length == 1) { if (table.getColumns().length == 1) {
throw DbException.get(ErrorCode.CANNOT_DROP_LAST_COLUMN, oldColumn.getSQL()); throw DbException.get(ErrorCode.CANNOT_DROP_LAST_COLUMN, oldColumn.getSQL());
} }
...@@ -166,7 +131,7 @@ public class AlterTableAlterColumn extends SchemaCommand { ...@@ -166,7 +131,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
copyData(); copyData();
break; break;
} }
case SELECTIVITY: { case CommandInterface.ALTER_TABLE_ALTER_COLUMN_SELECTIVITY: {
int value = newSelectivity.optimize(session).getValue(session).getInt(); int value = newSelectivity.optimize(session).getValue(session).getInt();
oldColumn.setSelectivity(value); oldColumn.setSelectivity(value);
db.update(session, table); db.update(session, table);
...@@ -249,10 +214,10 @@ public class AlterTableAlterColumn extends SchemaCommand { ...@@ -249,10 +214,10 @@ public class AlterTableAlterColumn extends SchemaCommand {
for (Column col : columns) { for (Column col : columns) {
newColumns.add(col.getClone()); newColumns.add(col.getClone());
} }
if (type == DROP) { if (type == CommandInterface.ALTER_TABLE_DROP_COLUMN) {
int position = oldColumn.getColumnId(); int position = oldColumn.getColumnId();
newColumns.remove(position); newColumns.remove(position);
} else if (type == ADD) { } else if (type == CommandInterface.ALTER_TABLE_ADD_COLUMN) {
int position; int position;
if (addBefore == null) { if (addBefore == null) {
position = columns.length; position = columns.length;
...@@ -260,7 +225,7 @@ public class AlterTableAlterColumn extends SchemaCommand { ...@@ -260,7 +225,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
position = table.getColumn(addBefore).getColumnId(); position = table.getColumn(addBefore).getColumnId();
} }
newColumns.add(position, newColumn); newColumns.add(position, newColumn);
} else if (type == CHANGE_TYPE) { } else if (type == CommandInterface.ALTER_TABLE_ALTER_COLUMN_CHANGE_TYPE) {
int position = oldColumn.getColumnId(); int position = oldColumn.getColumnId();
newColumns.remove(position); newColumns.remove(position);
newColumns.add(position, newColumn); newColumns.add(position, newColumn);
...@@ -290,7 +255,7 @@ public class AlterTableAlterColumn extends SchemaCommand { ...@@ -290,7 +255,7 @@ public class AlterTableAlterColumn extends SchemaCommand {
if (columnList.length() > 0) { if (columnList.length() > 0) {
columnList.append(", "); columnList.append(", ");
} }
if (type == ADD && nc == newColumn) { if (type == CommandInterface.ALTER_TABLE_ADD_COLUMN && nc == newColumn) {
Expression def = nc.getDefaultExpression(); Expression def = nc.getDefaultExpression();
columnList.append(def == null ? "NULL" : def.getSQL()); columnList.append(def == null ? "NULL" : def.getSQL());
} else { } else {
...@@ -489,4 +454,8 @@ public class AlterTableAlterColumn extends SchemaCommand { ...@@ -489,4 +454,8 @@ public class AlterTableAlterColumn extends SchemaCommand {
this.newColumn = newColumn; this.newColumn = newColumn;
} }
public int getType() {
return type;
}
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
package org.h2.command.ddl; package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.constraint.Constraint; import org.h2.constraint.Constraint;
import org.h2.engine.Right; import org.h2.engine.Right;
...@@ -46,4 +47,8 @@ public class AlterTableDropConstraint extends SchemaCommand { ...@@ -46,4 +47,8 @@ public class AlterTableDropConstraint extends SchemaCommand {
return 0; return 0;
} }
public int getType() {
return CommandInterface.ALTER_TABLE_DROP_CONSTRAINT;
}
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
package org.h2.command.ddl; package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.engine.Right; import org.h2.engine.Right;
...@@ -49,4 +50,8 @@ public class AlterTableRename extends SchemaCommand { ...@@ -49,4 +50,8 @@ public class AlterTableRename extends SchemaCommand {
return 0; return 0;
} }
public int getType() {
return CommandInterface.ALTER_TABLE_RENAME;
}
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
package org.h2.command.ddl; package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.engine.DbObject; import org.h2.engine.DbObject;
import org.h2.engine.Right; import org.h2.engine.Right;
...@@ -55,4 +56,8 @@ public class AlterTableRenameColumn extends DefineCommand { ...@@ -55,4 +56,8 @@ public class AlterTableRenameColumn extends DefineCommand {
return 0; return 0;
} }
public int getType() {
return CommandInterface.ALTER_TABLE_ALTER_COLUMN_RENAME;
}
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
package org.h2.command.ddl; package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.engine.Session; import org.h2.engine.Session;
...@@ -23,21 +24,6 @@ import org.h2.util.StringUtils; ...@@ -23,21 +24,6 @@ import org.h2.util.StringUtils;
*/ */
public class AlterUser extends DefineCommand { public class AlterUser extends DefineCommand {
/**
* The command type to set the password.
*/
public static final int SET_PASSWORD = 0;
/**
* The command type to rename the user.
*/
public static final int RENAME = 1;
/**
* The command type to change the admin flag.
*/
public static final int ADMIN = 2;
private int type; private int type;
private User user; private User user;
private String newName; private String newName;
...@@ -90,7 +76,7 @@ public class AlterUser extends DefineCommand { ...@@ -90,7 +76,7 @@ public class AlterUser extends DefineCommand {
session.commit(true); session.commit(true);
Database db = session.getDatabase(); Database db = session.getDatabase();
switch (type) { switch (type) {
case SET_PASSWORD: case CommandInterface.ALTER_USER_SET_PASSWORD:
if (user != session.getUser()) { if (user != session.getUser()) {
session.getUser().checkAdmin(); session.getUser().checkAdmin();
} }
...@@ -104,14 +90,14 @@ public class AlterUser extends DefineCommand { ...@@ -104,14 +90,14 @@ public class AlterUser extends DefineCommand {
user.setUserPasswordHash(userPasswordHash); user.setUserPasswordHash(userPasswordHash);
} }
break; break;
case RENAME: case CommandInterface.ALTER_USER_RENAME:
session.getUser().checkAdmin(); session.getUser().checkAdmin();
if (db.findUser(newName) != null || newName.equals(user.getName())) { if (db.findUser(newName) != null || newName.equals(user.getName())) {
throw DbException.get(ErrorCode.USER_ALREADY_EXISTS_1, newName); throw DbException.get(ErrorCode.USER_ALREADY_EXISTS_1, newName);
} }
db.renameDatabaseObject(session, user, newName); db.renameDatabaseObject(session, user, newName);
break; break;
case ADMIN: case CommandInterface.ALTER_USER_ADMIN:
session.getUser().checkAdmin(); session.getUser().checkAdmin();
if (!admin) { if (!admin) {
user.checkOwnsNoSchemas(); user.checkOwnsNoSchemas();
...@@ -125,4 +111,8 @@ public class AlterUser extends DefineCommand { ...@@ -125,4 +111,8 @@ public class AlterUser extends DefineCommand {
return 0; return 0;
} }
public int getType() {
return type;
}
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
package org.h2.command.ddl; package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.engine.Right; import org.h2.engine.Right;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.table.TableView; import org.h2.table.TableView;
...@@ -33,4 +34,8 @@ public class AlterView extends DefineCommand { ...@@ -33,4 +34,8 @@ public class AlterView extends DefineCommand {
return 0; return 0;
} }
public int getType() {
return CommandInterface.ALTER_VIEW;
}
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
package org.h2.command.ddl; package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.command.Prepared; import org.h2.command.Prepared;
import org.h2.constant.SysProperties; import org.h2.constant.SysProperties;
import org.h2.engine.Database; import org.h2.engine.Database;
...@@ -109,4 +110,8 @@ public class Analyze extends DefineCommand { ...@@ -109,4 +110,8 @@ public class Analyze extends DefineCommand {
this.sampleRows = top; this.sampleRows = top;
} }
public int getType() {
return CommandInterface.ANALYZE;
}
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
package org.h2.command.ddl; package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.engine.Session; import org.h2.engine.Session;
...@@ -65,4 +66,8 @@ public class CreateAggregate extends DefineCommand { ...@@ -65,4 +66,8 @@ public class CreateAggregate extends DefineCommand {
this.force = force; this.force = force;
} }
public int getType() {
return CommandInterface.CREATE_AGGREGATE;
}
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
package org.h2.command.ddl; package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.engine.Session; import org.h2.engine.Session;
...@@ -60,4 +61,8 @@ public class CreateConstant extends SchemaCommand { ...@@ -60,4 +61,8 @@ public class CreateConstant extends SchemaCommand {
this.expression = expr; this.expression = expr;
} }
public int getType() {
return CommandInterface.CREATE_CONSTANT;
}
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
package org.h2.command.ddl; package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.engine.FunctionAlias; import org.h2.engine.FunctionAlias;
...@@ -82,4 +83,8 @@ public class CreateFunctionAlias extends SchemaCommand { ...@@ -82,4 +83,8 @@ public class CreateFunctionAlias extends SchemaCommand {
this.source = source; this.source = source;
} }
public int getType() {
return CommandInterface.CREATE_ALIAS;
}
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
package org.h2.command.ddl; package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.engine.Constants; import org.h2.engine.Constants;
import org.h2.engine.Database; import org.h2.engine.Database;
...@@ -106,4 +107,8 @@ public class CreateIndex extends SchemaCommand { ...@@ -106,4 +107,8 @@ public class CreateIndex extends SchemaCommand {
this.comment = comment; this.comment = comment;
} }
public int getType() {
return CommandInterface.CREATE_INDEX;
}
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
package org.h2.command.ddl; package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.engine.Session; import org.h2.engine.Session;
...@@ -114,4 +115,8 @@ public class CreateLinkedTable extends SchemaCommand { ...@@ -114,4 +115,8 @@ public class CreateLinkedTable extends SchemaCommand {
this.originalSchema = originalSchema; this.originalSchema = originalSchema;
} }
public int getType() {
return CommandInterface.CREATE_LINKED_TABLE;
}
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
package org.h2.command.ddl; package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.engine.Role; import org.h2.engine.Role;
...@@ -52,4 +53,8 @@ public class CreateRole extends DefineCommand { ...@@ -52,4 +53,8 @@ public class CreateRole extends DefineCommand {
return 0; return 0;
} }
public int getType() {
return CommandInterface.CREATE_ROLE;
}
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
package org.h2.command.ddl; package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.engine.Session; import org.h2.engine.Session;
...@@ -57,4 +58,8 @@ public class CreateSchema extends DefineCommand { ...@@ -57,4 +58,8 @@ public class CreateSchema extends DefineCommand {
this.authorization = userName; this.authorization = userName;
} }
public int getType() {
return CommandInterface.CREATE_SCHEMA;
}
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
package org.h2.command.ddl; package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.engine.Session; import org.h2.engine.Session;
...@@ -80,4 +81,8 @@ public class CreateSequence extends SchemaCommand { ...@@ -80,4 +81,8 @@ public class CreateSequence extends SchemaCommand {
this.cacheSize = cacheSize; this.cacheSize = cacheSize;
} }
public int getType() {
return CommandInterface.CREATE_SEQUENCE;
}
} }
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
package org.h2.command.ddl; package org.h2.command.ddl;
import java.util.ArrayList; import java.util.ArrayList;
import org.h2.command.CommandInterface;
import org.h2.command.dml.Insert; import org.h2.command.dml.Insert;
import org.h2.command.dml.Query; import org.h2.command.dml.Query;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
...@@ -77,7 +78,7 @@ public class CreateTable extends SchemaCommand { ...@@ -77,7 +78,7 @@ public class CreateTable extends SchemaCommand {
} else { } else {
AlterTableAddConstraint con = (AlterTableAddConstraint) command; AlterTableAddConstraint con = (AlterTableAddConstraint) command;
boolean alreadySet; boolean alreadySet;
if (con.getType() == AlterTableAddConstraint.PRIMARY_KEY) { if (con.getType() == CommandInterface.ALTER_TABLE_ADD_CONSTRAINT_PRIMARY_KEY) {
alreadySet = setPrimaryKeyColumns(con.getIndexColumns()); alreadySet = setPrimaryKeyColumns(con.getIndexColumns());
} else { } else {
alreadySet = false; alreadySet = false;
...@@ -278,4 +279,8 @@ public class CreateTable extends SchemaCommand { ...@@ -278,4 +279,8 @@ public class CreateTable extends SchemaCommand {
data.isHidden = isHidden; data.isHidden = isHidden;
} }
public int getType() {
return CommandInterface.CREATE_TABLE;
}
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
package org.h2.command.ddl; package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.engine.Session; import org.h2.engine.Session;
...@@ -111,4 +112,8 @@ public class CreateTrigger extends SchemaCommand { ...@@ -111,4 +112,8 @@ public class CreateTrigger extends SchemaCommand {
this.onRollback = onRollback; this.onRollback = onRollback;
} }
public int getType() {
return CommandInterface.CREATE_TRIGGER;
}
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
package org.h2.command.ddl; package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties; import org.h2.constant.SysProperties;
import org.h2.engine.Database; import org.h2.engine.Database;
...@@ -106,4 +107,8 @@ public class CreateUser extends DefineCommand { ...@@ -106,4 +107,8 @@ public class CreateUser extends DefineCommand {
this.comment = comment; this.comment = comment;
} }
public int getType() {
return CommandInterface.CREATE_USER;
}
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
package org.h2.command.ddl; package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.engine.Session; import org.h2.engine.Session;
...@@ -69,4 +70,8 @@ public class CreateUserDataType extends DefineCommand { ...@@ -69,4 +70,8 @@ public class CreateUserDataType extends DefineCommand {
return 0; return 0;
} }
public int getType() {
return CommandInterface.CREATE_DOMAIN;
}
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
package org.h2.command.ddl; package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.command.Prepared; import org.h2.command.Prepared;
import org.h2.command.dml.Query; import org.h2.command.dml.Query;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
...@@ -195,4 +196,8 @@ public class CreateView extends SchemaCommand { ...@@ -195,4 +196,8 @@ public class CreateView extends SchemaCommand {
session.commit(true); session.commit(true);
} }
} }
public int getType() {
return CommandInterface.CREATE_VIEW;
}
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
package org.h2.command.ddl; package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.engine.Session; import org.h2.engine.Session;
/** /**
...@@ -29,4 +30,8 @@ public class DeallocateProcedure extends DefineCommand { ...@@ -29,4 +30,8 @@ public class DeallocateProcedure extends DefineCommand {
this.procedureName = name; this.procedureName = name;
} }
public int getType() {
return CommandInterface.DEALLOCATE;
}
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
package org.h2.command.ddl; package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.engine.Session; import org.h2.engine.Session;
...@@ -48,4 +49,8 @@ public class DropAggregate extends DefineCommand { ...@@ -48,4 +49,8 @@ public class DropAggregate extends DefineCommand {
this.ifExists = ifExists; this.ifExists = ifExists;
} }
public int getType() {
return CommandInterface.DROP_AGGREGATE;
}
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
package org.h2.command.ddl; package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.engine.Session; import org.h2.engine.Session;
...@@ -49,4 +50,8 @@ public class DropConstant extends SchemaCommand { ...@@ -49,4 +50,8 @@ public class DropConstant extends SchemaCommand {
return 0; return 0;
} }
public int getType() {
return CommandInterface.DROP_CONSTANT;
}
} }
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
package org.h2.command.ddl; package org.h2.command.ddl;
import java.util.ArrayList; import java.util.ArrayList;
import org.h2.command.CommandInterface;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.engine.DbObject; import org.h2.engine.DbObject;
import org.h2.engine.Role; import org.h2.engine.Role;
...@@ -114,4 +115,8 @@ public class DropDatabase extends DefineCommand { ...@@ -114,4 +115,8 @@ public class DropDatabase extends DefineCommand {
this.deleteFiles = b; this.deleteFiles = b;
} }
public int getType() {
return CommandInterface.DROP_ALL_OBJECTS;
}
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
package org.h2.command.ddl; package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.engine.FunctionAlias; import org.h2.engine.FunctionAlias;
...@@ -49,4 +50,8 @@ public class DropFunctionAlias extends SchemaCommand { ...@@ -49,4 +50,8 @@ public class DropFunctionAlias extends SchemaCommand {
this.ifExists = ifExists; this.ifExists = ifExists;
} }
public int getType() {
return CommandInterface.DROP_ALIAS;
}
} }
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
package org.h2.command.ddl; package org.h2.command.ddl;
import java.util.ArrayList; import java.util.ArrayList;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.constraint.Constraint; import org.h2.constraint.Constraint;
import org.h2.engine.Database; import org.h2.engine.Database;
...@@ -72,4 +73,8 @@ public class DropIndex extends SchemaCommand { ...@@ -72,4 +73,8 @@ public class DropIndex extends SchemaCommand {
return 0; return 0;
} }
public int getType() {
return CommandInterface.DROP_INDEX;
}
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
package org.h2.command.ddl; package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.engine.Constants; import org.h2.engine.Constants;
import org.h2.engine.Database; import org.h2.engine.Database;
...@@ -52,4 +53,8 @@ public class DropRole extends DefineCommand { ...@@ -52,4 +53,8 @@ public class DropRole extends DefineCommand {
this.ifExists = ifExists; this.ifExists = ifExists;
} }
public int getType() {
return CommandInterface.DROP_ROLE;
}
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
package org.h2.command.ddl; package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.engine.Session; import org.h2.engine.Session;
...@@ -51,4 +52,8 @@ public class DropSchema extends DefineCommand { ...@@ -51,4 +52,8 @@ public class DropSchema extends DefineCommand {
this.ifExists = ifExists; this.ifExists = ifExists;
} }
public int getType() {
return CommandInterface.DROP_SCHEMA;
}
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
package org.h2.command.ddl; package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.engine.Session; import org.h2.engine.Session;
...@@ -52,4 +53,8 @@ public class DropSequence extends SchemaCommand { ...@@ -52,4 +53,8 @@ public class DropSequence extends SchemaCommand {
return 0; return 0;
} }
public int getType() {
return CommandInterface.DROP_SEQUENCE;
}
} }
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
package org.h2.command.ddl; package org.h2.command.ddl;
import java.util.ArrayList; import java.util.ArrayList;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties; import org.h2.constant.SysProperties;
import org.h2.constraint.ConstraintReferential; import org.h2.constraint.ConstraintReferential;
...@@ -120,4 +121,8 @@ public class DropTable extends SchemaCommand { ...@@ -120,4 +121,8 @@ public class DropTable extends SchemaCommand {
} }
} }
public int getType() {
return CommandInterface.DROP_TABLE;
}
} }
\ No newline at end of file
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
package org.h2.command.ddl; package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.engine.Right; import org.h2.engine.Right;
...@@ -52,4 +53,8 @@ public class DropTrigger extends SchemaCommand { ...@@ -52,4 +53,8 @@ public class DropTrigger extends SchemaCommand {
return 0; return 0;
} }
public int getType() {
return CommandInterface.DROP_TRIGGER;
}
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
package org.h2.command.ddl; package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.engine.Session; import org.h2.engine.Session;
...@@ -64,4 +65,8 @@ public class DropUser extends DefineCommand { ...@@ -64,4 +65,8 @@ public class DropUser extends DefineCommand {
return false; return false;
} }
public int getType() {
return CommandInterface.DROP_USER;
}
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
package org.h2.command.ddl; package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.engine.Session; import org.h2.engine.Session;
...@@ -48,4 +49,8 @@ public class DropUserDataType extends DefineCommand { ...@@ -48,4 +49,8 @@ public class DropUserDataType extends DefineCommand {
this.typeName = name; this.typeName = name;
} }
public int getType() {
return CommandInterface.DROP_DOMAIN;
}
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
package org.h2.command.ddl; package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties; import org.h2.constant.SysProperties;
import org.h2.constraint.ConstraintReferential; import org.h2.constraint.ConstraintReferential;
...@@ -70,4 +71,8 @@ public class DropView extends SchemaCommand { ...@@ -70,4 +71,8 @@ public class DropView extends SchemaCommand {
return 0; return 0;
} }
public int getType() {
return CommandInterface.DROP_VIEW;
}
} }
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
package org.h2.command.ddl; package org.h2.command.ddl;
import java.util.ArrayList; import java.util.ArrayList;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.engine.Right; import org.h2.engine.Right;
...@@ -26,16 +27,6 @@ import org.h2.util.New; ...@@ -26,16 +27,6 @@ import org.h2.util.New;
*/ */
public class GrantRevoke extends DefineCommand { public class GrantRevoke extends DefineCommand {
/**
* The operation type to grant a right.
*/
public static final int GRANT = 0;
/**
* The operation type to revoke a right.
*/
public static final int REVOKE = 1;
private ArrayList<String> roleNames; private ArrayList<String> roleNames;
private int operationType; private int operationType;
private int rightMask; private int rightMask;
...@@ -92,18 +83,18 @@ public class GrantRevoke extends DefineCommand { ...@@ -92,18 +83,18 @@ public class GrantRevoke extends DefineCommand {
if (grantedRole == null) { if (grantedRole == null) {
throw DbException.get(ErrorCode.ROLE_NOT_FOUND_1, name); throw DbException.get(ErrorCode.ROLE_NOT_FOUND_1, name);
} }
if (operationType == GRANT) { if (operationType == CommandInterface.GRANT) {
grantRole(grantedRole); grantRole(grantedRole);
} else if (operationType == REVOKE) { } else if (operationType == CommandInterface.REVOKE) {
revokeRole(grantedRole); revokeRole(grantedRole);
} else { } else {
DbException.throwInternalError("type=" + operationType); DbException.throwInternalError("type=" + operationType);
} }
} }
} else { } else {
if (operationType == GRANT) { if (operationType == CommandInterface.GRANT) {
grantRight(); grantRight();
} else if (operationType == REVOKE) { } else if (operationType == CommandInterface.REVOKE) {
revokeRight(); revokeRight();
} else { } else {
DbException.throwInternalError("type=" + operationType); DbException.throwInternalError("type=" + operationType);
...@@ -185,4 +176,8 @@ public class GrantRevoke extends DefineCommand { ...@@ -185,4 +176,8 @@ public class GrantRevoke extends DefineCommand {
tables.add(table); tables.add(table);
} }
public int getType() {
return operationType;
}
} }
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
package org.h2.command.ddl; package org.h2.command.ddl;
import java.util.ArrayList; import java.util.ArrayList;
import org.h2.command.CommandInterface;
import org.h2.command.Prepared; import org.h2.command.Prepared;
import org.h2.engine.Procedure; import org.h2.engine.Procedure;
import org.h2.engine.Session; import org.h2.engine.Session;
...@@ -51,4 +52,8 @@ public class PrepareProcedure extends DefineCommand { ...@@ -51,4 +52,8 @@ public class PrepareProcedure extends DefineCommand {
return New.arrayList(); return New.arrayList();
} }
public int getType() {
return CommandInterface.PREPARE;
}
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
package org.h2.command.ddl; package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.engine.Comment; import org.h2.engine.Comment;
import org.h2.engine.Database; import org.h2.engine.Database;
...@@ -146,4 +147,8 @@ public class SetComment extends DefineCommand { ...@@ -146,4 +147,8 @@ public class SetComment extends DefineCommand {
this.column = column; this.column = column;
} }
public int getType() {
return CommandInterface.COMMENT;
}
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
package org.h2.command.ddl; package org.h2.command.ddl;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.engine.Right; import org.h2.engine.Right;
import org.h2.engine.Session; import org.h2.engine.Session;
...@@ -39,4 +40,8 @@ public class TruncateTable extends DefineCommand { ...@@ -39,4 +40,8 @@ public class TruncateTable extends DefineCommand {
return 0; return 0;
} }
public int getType() {
return CommandInterface.TRUNCATE_TABLE;
}
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
package org.h2.command.dml; package org.h2.command.dml;
import org.h2.command.CommandInterface;
import org.h2.command.ddl.SchemaCommand; import org.h2.command.ddl.SchemaCommand;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.engine.Database; import org.h2.engine.Database;
...@@ -84,4 +85,8 @@ public class AlterSequence extends SchemaCommand { ...@@ -84,4 +85,8 @@ public class AlterSequence extends SchemaCommand {
return 0; return 0;
} }
public int getType() {
return CommandInterface.ALTER_SEQUENCE;
}
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
package org.h2.command.dml; package org.h2.command.dml;
import org.h2.command.CommandInterface;
import org.h2.command.ddl.SchemaCommand; import org.h2.command.ddl.SchemaCommand;
import org.h2.engine.Right; import org.h2.engine.Right;
import org.h2.engine.Session; import org.h2.engine.Session;
...@@ -19,23 +20,16 @@ import org.h2.table.Table; ...@@ -19,23 +20,16 @@ import org.h2.table.Table;
*/ */
public class AlterTableSet extends SchemaCommand { public class AlterTableSet extends SchemaCommand {
/**
* Enable the referential integrity.
*/
public static final int REFERENTIAL_INTEGRITY_TRUE = 0;
/**
* Disable the referential integrity.
*/
public static final int REFERENTIAL_INTEGRITY_FALSE = 1;
private String tableName; private String tableName;
private final int type; private final int type;
private boolean value;
private boolean checkExisting; private boolean checkExisting;
public AlterTableSet(Session session, Schema schema, int type) { public AlterTableSet(Session session, Schema schema, int type, boolean value) {
super(session, schema); super(session, schema);
this.type = type; this.type = type;
this.value = value;
} }
public void setCheckExisting(boolean b) { public void setCheckExisting(boolean b) {
...@@ -55,11 +49,8 @@ public class AlterTableSet extends SchemaCommand { ...@@ -55,11 +49,8 @@ public class AlterTableSet extends SchemaCommand {
session.getUser().checkRight(table, Right.ALL); session.getUser().checkRight(table, Right.ALL);
table.lock(session, true, true); table.lock(session, true, true);
switch(type) { switch(type) {
case REFERENTIAL_INTEGRITY_TRUE: case CommandInterface.ALTER_TABLE_SET_REFERENTIAL_INTEGRITY:
table.setCheckForeignKeyConstraints(session, true, checkExisting); table.setCheckForeignKeyConstraints(session, value, value ? checkExisting : false);
break;
case REFERENTIAL_INTEGRITY_FALSE:
table.setCheckForeignKeyConstraints(session, false, false);
break; break;
default: default:
DbException.throwInternalError("type="+type); DbException.throwInternalError("type="+type);
...@@ -67,4 +58,8 @@ public class AlterTableSet extends SchemaCommand { ...@@ -67,4 +58,8 @@ public class AlterTableSet extends SchemaCommand {
return 0; return 0;
} }
public int getType() {
return type;
}
} }
...@@ -13,6 +13,7 @@ import java.util.ArrayList; ...@@ -13,6 +13,7 @@ import java.util.ArrayList;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
import org.h2.api.DatabaseEventListener; import org.h2.api.DatabaseEventListener;
import org.h2.command.CommandInterface;
import org.h2.command.Prepared; import org.h2.command.Prepared;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.engine.Constants; import org.h2.engine.Constants;
...@@ -138,4 +139,8 @@ public class BackupCommand extends Prepared { ...@@ -138,4 +139,8 @@ public class BackupCommand extends Prepared {
return null; return null;
} }
public int getType() {
return CommandInterface.BACKUP;
}
} }
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
package org.h2.command.dml; package org.h2.command.dml;
import java.sql.ResultSet; import java.sql.ResultSet;
import org.h2.command.CommandInterface;
import org.h2.command.Prepared; import org.h2.command.Prepared;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.expression.Expression; import org.h2.expression.Expression;
...@@ -104,4 +105,8 @@ public class Call extends Prepared { ...@@ -104,4 +105,8 @@ public class Call extends Prepared {
} }
public int getType() {
return CommandInterface.CALL;
}
} }
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
package org.h2.command.dml; package org.h2.command.dml;
import org.h2.api.Trigger; import org.h2.api.Trigger;
import org.h2.command.CommandInterface;
import org.h2.command.Prepared; import org.h2.command.Prepared;
import org.h2.engine.Right; import org.h2.engine.Right;
import org.h2.engine.Session; import org.h2.engine.Session;
...@@ -114,4 +115,8 @@ public class Delete extends Prepared { ...@@ -114,4 +115,8 @@ public class Delete extends Prepared {
return null; return null;
} }
public int getType() {
return CommandInterface.DELETE;
}
} }
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
package org.h2.command.dml; package org.h2.command.dml;
import java.util.ArrayList; import java.util.ArrayList;
import org.h2.command.CommandInterface;
import org.h2.command.Prepared; import org.h2.command.Prepared;
import org.h2.engine.Procedure; import org.h2.engine.Procedure;
import org.h2.engine.Session; import org.h2.engine.Session;
...@@ -78,4 +79,8 @@ public class ExecuteProcedure extends Prepared { ...@@ -78,4 +79,8 @@ public class ExecuteProcedure extends Prepared {
return prepared.queryMeta(); return prepared.queryMeta();
} }
public int getType() {
return CommandInterface.EXECUTE;
}
} }
...@@ -9,6 +9,7 @@ package org.h2.command.dml; ...@@ -9,6 +9,7 @@ package org.h2.command.dml;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.Map.Entry; import java.util.Map.Entry;
import org.h2.command.CommandInterface;
import org.h2.command.Prepared; import org.h2.command.Prepared;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.engine.Session; import org.h2.engine.Session;
...@@ -113,4 +114,8 @@ public class Explain extends Prepared { ...@@ -113,4 +114,8 @@ public class Explain extends Prepared {
public boolean isReadOnly() { public boolean isReadOnly() {
return true; return true;
} }
public int getType() {
return CommandInterface.EXPLAIN;
}
} }
...@@ -9,6 +9,7 @@ package org.h2.command.dml; ...@@ -9,6 +9,7 @@ package org.h2.command.dml;
import java.util.ArrayList; import java.util.ArrayList;
import org.h2.api.Trigger; import org.h2.api.Trigger;
import org.h2.command.Command; import org.h2.command.Command;
import org.h2.command.CommandInterface;
import org.h2.command.Prepared; import org.h2.command.Prepared;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.engine.Database; import org.h2.engine.Database;
...@@ -235,4 +236,8 @@ public class Insert extends Prepared { ...@@ -235,4 +236,8 @@ public class Insert extends Prepared {
this.sortedInsertMode = sortedInsertMode; this.sortedInsertMode = sortedInsertMode;
} }
public int getType() {
return CommandInterface.INSERT;
}
} }
...@@ -9,6 +9,7 @@ package org.h2.command.dml; ...@@ -9,6 +9,7 @@ package org.h2.command.dml;
import java.util.ArrayList; import java.util.ArrayList;
import org.h2.api.Trigger; import org.h2.api.Trigger;
import org.h2.command.Command; import org.h2.command.Command;
import org.h2.command.CommandInterface;
import org.h2.command.Prepared; import org.h2.command.Prepared;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.engine.Right; import org.h2.engine.Right;
...@@ -274,4 +275,8 @@ public class Merge extends Prepared { ...@@ -274,4 +275,8 @@ public class Merge extends Prepared {
return null; return null;
} }
public int getType() {
return CommandInterface.MERGE;
}
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
package org.h2.command.dml; package org.h2.command.dml;
import org.h2.command.CommandInterface;
import org.h2.command.Prepared; import org.h2.command.Prepared;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.result.ResultInterface; import org.h2.result.ResultInterface;
...@@ -43,4 +44,8 @@ public class NoOperation extends Prepared { ...@@ -43,4 +44,8 @@ public class NoOperation extends Prepared {
return null; return null;
} }
public int getType() {
return CommandInterface.NO_OPERATION;
}
} }
...@@ -9,6 +9,7 @@ package org.h2.command.dml; ...@@ -9,6 +9,7 @@ package org.h2.command.dml;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.Reader; import java.io.Reader;
import org.h2.command.CommandInterface;
import org.h2.command.Prepared; import org.h2.command.Prepared;
import org.h2.constant.SysProperties; import org.h2.constant.SysProperties;
import org.h2.engine.Session; import org.h2.engine.Session;
...@@ -79,4 +80,8 @@ public class RunScriptCommand extends ScriptBase { ...@@ -79,4 +80,8 @@ public class RunScriptCommand extends ScriptBase {
return null; return null;
} }
public int getType() {
return CommandInterface.RUNSCRIPT;
}
} }
...@@ -17,6 +17,7 @@ import java.sql.SQLException; ...@@ -17,6 +17,7 @@ import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import org.h2.command.CommandInterface;
import org.h2.command.Parser; import org.h2.command.Parser;
import org.h2.constant.SysProperties; import org.h2.constant.SysProperties;
import org.h2.constraint.Constraint; import org.h2.constraint.Constraint;
...@@ -582,4 +583,8 @@ public class ScriptCommand extends ScriptBase { ...@@ -582,4 +583,8 @@ public class ScriptCommand extends ScriptBase {
this.charset = charset; this.charset = charset;
} }
public int getType() {
return CommandInterface.SCRIPT;
}
} }
...@@ -11,6 +11,7 @@ import java.util.Arrays; ...@@ -11,6 +11,7 @@ import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import org.h2.api.Trigger; import org.h2.api.Trigger;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties; import org.h2.constant.SysProperties;
import org.h2.engine.Constants; import org.h2.engine.Constants;
...@@ -1172,4 +1173,8 @@ public class Select extends Query { ...@@ -1172,4 +1173,8 @@ public class Select extends Query {
return !isForUpdate; return !isForUpdate;
} }
public int getType() {
return CommandInterface.SELECT;
}
} }
...@@ -8,6 +8,7 @@ package org.h2.command.dml; ...@@ -8,6 +8,7 @@ package org.h2.command.dml;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import org.h2.command.CommandInterface;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties; import org.h2.constant.SysProperties;
import org.h2.engine.Session; import org.h2.engine.Session;
...@@ -372,4 +373,8 @@ public class SelectUnion extends Query { ...@@ -372,4 +373,8 @@ public class SelectUnion extends Query {
right.fireBeforeSelectTriggers(); right.fireBeforeSelectTriggers();
} }
public int getType() {
return CommandInterface.SELECT;
}
} }
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
package org.h2.command.dml; package org.h2.command.dml;
import java.text.Collator; import java.text.Collator;
import org.h2.command.CommandInterface;
import org.h2.command.Prepared; import org.h2.command.Prepared;
import org.h2.compress.Compressor; import org.h2.compress.Compressor;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
...@@ -416,4 +417,8 @@ public class Set extends Prepared { ...@@ -416,4 +417,8 @@ public class Set extends Prepared {
this.stringValueList = list; this.stringValueList = list;
} }
public int getType() {
return CommandInterface.SET;
}
} }
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
package org.h2.command.dml; package org.h2.command.dml;
import org.h2.command.CommandInterface;
import org.h2.command.Prepared; import org.h2.command.Prepared;
import org.h2.engine.Database; import org.h2.engine.Database;
import org.h2.engine.Session; import org.h2.engine.Session;
...@@ -17,86 +18,6 @@ import org.h2.result.ResultInterface; ...@@ -17,86 +18,6 @@ import org.h2.result.ResultInterface;
*/ */
public class TransactionCommand extends Prepared { public class TransactionCommand extends Prepared {
/**
* The type of a SET AUTOCOMMIT TRUE statement.
*/
public static final int AUTOCOMMIT_TRUE = 1;
/**
* The type of a SET AUTOCOMMIT FALSE statement.
*/
public static final int AUTOCOMMIT_FALSE = 2;
/**
* The type of a COMMIT statement.
*/
public static final int COMMIT = 3;
/**
* The type of a ROLLBACK statement.
*/
public static final int ROLLBACK = 4;
/**
* The type of a CHECKPOINT statement.
*/
public static final int CHECKPOINT = 5;
/**
* The type of a SAVEPOINT statement.
*/
public static final int SAVEPOINT = 6;
/**
* The type of a ROLLBACK TO SAVEPOINT statement.
*/
public static final int ROLLBACK_TO_SAVEPOINT = 7;
/**
* The type of a CHECKPOINT SYNC statement.
*/
public static final int CHECKPOINT_SYNC = 8;
/**
* The type of a PREPARE COMMIT statement.
*/
public static final int PREPARE_COMMIT = 9;
/**
* The type of a COMMIT TRANSACTION statement.
*/
public static final int COMMIT_TRANSACTION = 10;
/**
* The type of a ROLLBACK TRANSACTION statement.
*/
public static final int ROLLBACK_TRANSACTION = 11;
/**
* The type of a SHUTDOWN statement.
*/
public static final int SHUTDOWN = 12;
/**
* The type of a SHUTDOWN IMMEDIATELY statement.
*/
public static final int SHUTDOWN_IMMEDIATELY = 13;
/**
* The type of a SHUTDOWN COMPACT statement.
*/
public static final int SHUTDOWN_COMPACT = 14;
/**
* The type of a BEGIN {WORK|TRANSACTION} statement.
*/
public static final int BEGIN = 15;
/**
* The type of a SHUTDOWN DEFRAG statement.
*/
public static final int SHUTDOWN_DEFRAG = 16;
private int type; private int type;
private String savepointName; private String savepointName;
private String transactionName; private String transactionName;
...@@ -112,56 +33,56 @@ public class TransactionCommand extends Prepared { ...@@ -112,56 +33,56 @@ public class TransactionCommand extends Prepared {
public int update() { public int update() {
switch (type) { switch (type) {
case AUTOCOMMIT_TRUE: case CommandInterface.SET_AUTOCOMMIT_TRUE:
session.setAutoCommit(true); session.setAutoCommit(true);
break; break;
case AUTOCOMMIT_FALSE: case CommandInterface.SET_AUTOCOMMIT_FALSE:
session.setAutoCommit(false); session.setAutoCommit(false);
break; break;
case BEGIN: case CommandInterface.BEGIN:
session.begin(); session.begin();
break; break;
case COMMIT: case CommandInterface.COMMIT:
session.commit(false); session.commit(false);
break; break;
case ROLLBACK: case CommandInterface.ROLLBACK:
session.rollback(); session.rollback();
break; break;
case CHECKPOINT: case CommandInterface.CHECKPOINT:
session.getUser().checkAdmin(); session.getUser().checkAdmin();
session.getDatabase().checkpoint(); session.getDatabase().checkpoint();
break; break;
case SAVEPOINT: case CommandInterface.SAVEPOINT:
session.addSavepoint(savepointName); session.addSavepoint(savepointName);
break; break;
case ROLLBACK_TO_SAVEPOINT: case CommandInterface.ROLLBACK_TO_SAVEPOINT:
session.rollbackToSavepoint(savepointName); session.rollbackToSavepoint(savepointName);
break; break;
case CHECKPOINT_SYNC: case CommandInterface.CHECKPOINT_SYNC:
session.getUser().checkAdmin(); session.getUser().checkAdmin();
session.getDatabase().sync(); session.getDatabase().sync();
break; break;
case PREPARE_COMMIT: case CommandInterface.PREPARE_COMMIT:
session.prepareCommit(transactionName); session.prepareCommit(transactionName);
break; break;
case COMMIT_TRANSACTION: case CommandInterface.COMMIT_TRANSACTION:
session.getUser().checkAdmin(); session.getUser().checkAdmin();
session.setPreparedTransaction(transactionName, true); session.setPreparedTransaction(transactionName, true);
break; break;
case ROLLBACK_TRANSACTION: case CommandInterface.ROLLBACK_TRANSACTION:
session.getUser().checkAdmin(); session.getUser().checkAdmin();
session.setPreparedTransaction(transactionName, false); session.setPreparedTransaction(transactionName, false);
break; break;
case SHUTDOWN_IMMEDIATELY: case CommandInterface.SHUTDOWN_IMMEDIATELY:
session.getUser().checkAdmin(); session.getUser().checkAdmin();
session.getDatabase().shutdownImmediately(); session.getDatabase().shutdownImmediately();
break; break;
case SHUTDOWN: case CommandInterface.SHUTDOWN:
case SHUTDOWN_COMPACT: case CommandInterface.SHUTDOWN_COMPACT:
case SHUTDOWN_DEFRAG: { case CommandInterface.SHUTDOWN_DEFRAG: {
session.getUser().checkAdmin(); session.getUser().checkAdmin();
session.commit(false); session.commit(false);
if (type == SHUTDOWN_COMPACT || type == SHUTDOWN_DEFRAG) { if (type == CommandInterface.SHUTDOWN_COMPACT || type == CommandInterface.SHUTDOWN_DEFRAG) {
session.getDatabase().setCompactMode(type); session.getDatabase().setCompactMode(type);
} }
// close the database, but don't update the persistent setting // close the database, but don't update the persistent setting
...@@ -211,4 +132,8 @@ public class TransactionCommand extends Prepared { ...@@ -211,4 +132,8 @@ public class TransactionCommand extends Prepared {
return null; return null;
} }
public int getType() {
return type;
}
} }
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
package org.h2.command.dml; package org.h2.command.dml;
import org.h2.api.Trigger; import org.h2.api.Trigger;
import org.h2.command.CommandInterface;
import org.h2.command.Prepared; import org.h2.command.Prepared;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.engine.Right; import org.h2.engine.Right;
...@@ -182,4 +183,8 @@ public class Update extends Prepared { ...@@ -182,4 +183,8 @@ public class Update extends Prepared {
return null; return null;
} }
public int getType() {
return CommandInterface.UPDATE;
}
} }
...@@ -37,6 +37,7 @@ public class JdbcStatement extends TraceObject implements Statement { ...@@ -37,6 +37,7 @@ public class JdbcStatement extends TraceObject implements Statement {
protected final int resultSetConcurrency; protected final int resultSetConcurrency;
protected boolean closedByResultSet; protected boolean closedByResultSet;
private CommandInterface executingCommand; private CommandInterface executingCommand;
private int lastExecutedCommandType;
private ArrayList<String> batchCommands; private ArrayList<String> batchCommands;
private boolean escapeProcessing = true; private boolean escapeProcessing = true;
...@@ -926,10 +927,23 @@ public class JdbcStatement extends TraceObject implements Statement { ...@@ -926,10 +927,23 @@ public class JdbcStatement extends TraceObject implements Statement {
* @param c the command * @param c the command
*/ */
protected void setExecutingStatement(CommandInterface c) { protected void setExecutingStatement(CommandInterface c) {
conn.setExecutingStatement(c == null ? null : this); if (c == null) {
conn.setExecutingStatement(null);
} else {
conn.setExecutingStatement(this);
lastExecutedCommandType = c.getCommandType();
}
executingCommand = c; executingCommand = c;
} }
/**
* INTERNAL.
* Get the command type of the last executed command.
*/
public int getLastExecutedCommandType() {
return lastExecutedCommandType;
}
/** /**
* Returns whether this statement is closed. * Returns whether this statement is closed.
* *
......
...@@ -28,15 +28,18 @@ import java.sql.Statement; ...@@ -28,15 +28,18 @@ import java.sql.Statement;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Properties; import java.util.Properties;
import org.h2.command.CommandInterface;
import org.h2.constant.SysProperties; import org.h2.constant.SysProperties;
import org.h2.engine.ConnectionInfo; import org.h2.engine.ConnectionInfo;
import org.h2.jdbc.JdbcConnection; import org.h2.jdbc.JdbcConnection;
import org.h2.jdbc.JdbcPreparedStatement;
import org.h2.jdbc.JdbcStatement;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.util.Utils;
import org.h2.util.IOUtils; import org.h2.util.IOUtils;
import org.h2.util.JdbcUtils; import org.h2.util.JdbcUtils;
import org.h2.util.New; import org.h2.util.New;
import org.h2.util.ScriptReader; import org.h2.util.ScriptReader;
import org.h2.util.Utils;
/** /**
* One server thread is opened for each client. * One server thread is opened for each client.
...@@ -131,7 +134,7 @@ public class PgServerThread implements Runnable { ...@@ -131,7 +134,7 @@ public class PgServerThread implements Runnable {
byte[] data = Utils.newBytes(len); byte[] data = Utils.newBytes(len);
dataInRaw.readFully(data, 0, len); dataInRaw.readFully(data, 0, len);
dataIn = new DataInputStream(new ByteArrayInputStream(data, 0, len)); dataIn = new DataInputStream(new ByteArrayInputStream(data, 0, len));
switch (x) { switchBlock: switch (x) {
case 0: case 0:
server.trace("Init"); server.trace("Init");
int version = readInt(); int version = readInt();
...@@ -214,7 +217,7 @@ public class PgServerThread implements Runnable { ...@@ -214,7 +217,7 @@ public class PgServerThread implements Runnable {
p.paramType[i] = type; p.paramType[i] = type;
} }
try { try {
p.prep = conn.prepareStatement(p.sql); p.prep = (JdbcPreparedStatement) conn.prepareStatement(p.sql);
prepared.put(p.name, p); prepared.put(p.name, p);
sendParseComplete(); sendParseComplete();
} catch (Exception e) { } catch (Exception e) {
...@@ -248,6 +251,7 @@ public class PgServerThread implements Runnable { ...@@ -248,6 +251,7 @@ public class PgServerThread implements Runnable {
setParameter(prep.prep, i, d2, formatCodes); setParameter(prep.prep, i, d2, formatCodes);
} catch (Exception e) { } catch (Exception e) {
sendErrorResponse(e); sendErrorResponse(e);
break switchBlock;
} }
} }
int resultCodeCount = readShort(); int resultCodeCount = readShort();
...@@ -317,7 +321,7 @@ public class PgServerThread implements Runnable { ...@@ -317,7 +321,7 @@ public class PgServerThread implements Runnable {
} }
int maxRows = readShort(); int maxRows = readShort();
Prepared prepared = p.prep; Prepared prepared = p.prep;
PreparedStatement prep = prepared.prep; JdbcPreparedStatement prep = prepared.prep;
server.trace(prepared.sql); server.trace(prepared.sql);
try { try {
prep.setMaxRows(maxRows); prep.setMaxRows(maxRows);
...@@ -330,12 +334,12 @@ public class PgServerThread implements Runnable { ...@@ -330,12 +334,12 @@ public class PgServerThread implements Runnable {
while (rs.next()) { while (rs.next()) {
sendDataRow(rs); sendDataRow(rs);
} }
sendCommandComplete(prepared.sql, 0); sendCommandComplete(prep, 0);
} catch (Exception e) { } catch (Exception e) {
sendErrorResponse(e); sendErrorResponse(e);
} }
} else { } else {
sendCommandComplete(prepared.sql, prep.getUpdateCount()); sendCommandComplete(prep, prep.getUpdateCount());
} }
} catch (Exception e) { } catch (Exception e) {
sendErrorResponse(e); sendErrorResponse(e);
...@@ -352,28 +356,34 @@ public class PgServerThread implements Runnable { ...@@ -352,28 +356,34 @@ public class PgServerThread implements Runnable {
String query = readString(); String query = readString();
ScriptReader reader = new ScriptReader(new StringReader(query)); ScriptReader reader = new ScriptReader(new StringReader(query));
while (true) { while (true) {
Statement stat = null; JdbcStatement stat = null;
try { try {
String s = reader.readStatement(); String s = reader.readStatement();
if (s == null) { if (s == null) {
break; break;
} }
s = getSQL(s); s = getSQL(s);
stat = conn.createStatement(); stat = (JdbcStatement) conn.createStatement();
boolean result = stat.execute(s); boolean result = stat.execute(s);
if (result) { if (result) {
ResultSet rs = stat.getResultSet(); ResultSet rs = stat.getResultSet();
ResultSetMetaData meta = rs.getMetaData(); ResultSetMetaData meta = rs.getMetaData();
try {
sendRowDescription(meta); sendRowDescription(meta);
while (rs.next()) { while (rs.next()) {
sendDataRow(rs); sendDataRow(rs);
} }
sendCommandComplete(s, 0); sendCommandComplete(stat, 0);
} catch (Exception e) {
sendErrorResponse(e);
break;
}
} else { } else {
sendCommandComplete(s, stat.getUpdateCount()); sendCommandComplete(stat, stat.getUpdateCount());
} }
} catch (SQLException e) { } catch (SQLException e) {
sendErrorResponse(e); sendErrorResponse(e);
break;
} finally { } finally {
JdbcUtils.closeSilently(stat); JdbcUtils.closeSilently(stat);
} }
...@@ -406,31 +416,37 @@ public class PgServerThread implements Runnable { ...@@ -406,31 +416,37 @@ public class PgServerThread implements Runnable {
return s; return s;
} }
private void sendCommandComplete(String sql, int updateCount) throws IOException { private void sendCommandComplete(JdbcStatement stat, int updateCount) throws IOException {
startMessage('C'); startMessage('C');
sql = sql.trim().toUpperCase(); switch (stat.getLastExecutedCommandType()) {
// TODO remove remarks at the beginning case CommandInterface.INSERT:
String tag; writeStringPart("INSERT 0 ");
if (sql.startsWith("INSERT")) { writeString(Integer.toString(updateCount));
tag = "INSERT 0 " + updateCount; break;
} else if (sql.startsWith("DELETE")) { case CommandInterface.UPDATE:
tag = "DELETE " + updateCount; writeStringPart("UPDATE ");
} else if (sql.startsWith("UPDATE")) { writeString(Integer.toString(updateCount));
tag = "UPDATE " + updateCount; break;
} else if (sql.startsWith("SELECT") || sql.startsWith("CALL")) { case CommandInterface.DELETE:
tag = "SELECT"; writeStringPart("DELETE ");
} else if (sql.startsWith("BEGIN")) { writeString(Integer.toString(updateCount));
tag = "BEGIN"; break;
} else { case CommandInterface.SELECT:
server.trace("Check command tag: " + sql); case CommandInterface.CALL:
tag = "UPDATE " + updateCount; writeString("SELECT");
break;
case CommandInterface.BEGIN:
writeString("BEGIN");
break;
default:
server.trace("check CommandComplete tag for command " + stat);
writeStringPart("UPDATE ");
writeString(Integer.toString(updateCount));
} }
writeString(tag);
sendMessage(); sendMessage();
} }
private void sendDataRow(ResultSet rs) throws IOException { private void sendDataRow(ResultSet rs) throws Exception {
try {
int columns = rs.getMetaData().getColumnCount(); int columns = rs.getMetaData().getColumnCount();
String[] values = new String[columns]; String[] values = new String[columns];
for (int i = 0; i < columns; i++) { for (int i = 0; i < columns; i++) {
...@@ -449,9 +465,6 @@ public class PgServerThread implements Runnable { ...@@ -449,9 +465,6 @@ public class PgServerThread implements Runnable {
} }
} }
sendMessage(); sendMessage();
} catch (Exception e) {
sendErrorResponse(e);
}
} }
private String getEncoding() { private String getEncoding() {
...@@ -525,8 +538,7 @@ public class PgServerThread implements Runnable { ...@@ -525,8 +538,7 @@ public class PgServerThread implements Runnable {
sendMessage(); sendMessage();
} }
private void sendRowDescription(ResultSetMetaData meta) throws IOException { private void sendRowDescription(ResultSetMetaData meta) throws Exception {
try {
if (meta == null) { if (meta == null) {
sendNoData(); sendNoData();
} else { } else {
...@@ -568,9 +580,6 @@ public class PgServerThread implements Runnable { ...@@ -568,9 +580,6 @@ public class PgServerThread implements Runnable {
} }
sendMessage(); sendMessage();
} }
} catch (Exception e) {
sendErrorResponse(e);
}
} }
private int getTypeSize(int pgType, int precision) { private int getTypeSize(int pgType, int precision) {
...@@ -739,10 +748,14 @@ public class PgServerThread implements Runnable { ...@@ -739,10 +748,14 @@ public class PgServerThread implements Runnable {
} }
private void writeString(String s) throws IOException { private void writeString(String s) throws IOException {
write(s.getBytes(getEncoding())); writeStringPart(s);
write(0); write(0);
} }
private void writeStringPart(String s) throws IOException {
write(s.getBytes(getEncoding()));
}
private void writeInt(int i) throws IOException { private void writeInt(int i) throws IOException {
dataOut.writeInt(i); dataOut.writeInt(i);
} }
...@@ -813,7 +826,7 @@ public class PgServerThread implements Runnable { ...@@ -813,7 +826,7 @@ public class PgServerThread implements Runnable {
/** /**
* The prepared statement. * The prepared statement.
*/ */
PreparedStatement prep; JdbcPreparedStatement prep;
/** /**
* The list of parameter types (if set). * The list of parameter types (if set).
......
...@@ -13,8 +13,8 @@ import java.util.BitSet; ...@@ -13,8 +13,8 @@ import java.util.BitSet;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.zip.CRC32; import java.util.zip.CRC32;
import org.h2.command.CommandInterface;
import org.h2.command.ddl.CreateTableData; import org.h2.command.ddl.CreateTableData;
import org.h2.command.dml.TransactionCommand;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties; import org.h2.constant.SysProperties;
import org.h2.engine.Constants; import org.h2.engine.Constants;
...@@ -465,8 +465,8 @@ public class PageStore implements CacheWriter { ...@@ -465,8 +465,8 @@ public class PageStore implements CacheWriter {
recoveryRunning = false; recoveryRunning = false;
} }
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
boolean isCompactFully = compactMode == TransactionCommand.SHUTDOWN_COMPACT; boolean isCompactFully = compactMode == CommandInterface.SHUTDOWN_COMPACT;
boolean isDefrag = compactMode == TransactionCommand.SHUTDOWN_DEFRAG; boolean isDefrag = compactMode == CommandInterface.SHUTDOWN_DEFRAG;
int test; int test;
// isCompactFully = isDefrag = true; // isCompactFully = isDefrag = true;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论