private Schema getSchema() { return getSchema(schemaName); }
private void checkSchema(Schema old) { if (old != null && getSchema() != old) { throw DbException.get(ErrorCode.SCHEMA_NAME_MUST_MATCH); } }
private AlterSchemaRename parseAlterSchema() { String schemaName = readIdentifierWithSchema(); Schema old = getSchema(); AlterSchemaRename command = new AlterSchemaRename(session); command.setOldSchema(getSchema(schemaName)); read("RENAME"); read("TO"); String newName = readIdentifierWithSchema(old.getName()); checkSchema(old); command.setNewName(newName); return command; }
private AlterIndexRename parseAlterIndex() { String indexName = readIdentifierWithSchema(); Schema old = getSchema(); AlterIndexRename command = new AlterIndexRename(session); command.setOldIndex(getSchema().getIndex(indexName)); read("RENAME"); read("TO"); String newName = readIdentifierWithSchema(old.getName()); checkSchema(old); command.setNewName(newName); return command; }
private Sequence readSequence() { // same algorithm as readTableOrView String sequenceName = readIdentifierWithSchema(null); if (schemaName != null) { return getSchema().getSequence(sequenceName); } Sequence sequence = findSequence(session.getCurrentSchemaName(), sequenceName); if (sequence != null) { return sequence; } throw DbException.get(ErrorCode.SEQUENCE_NOT_FOUND_1, sequenceName); }
private AlterView parseAlterView() { AlterView command = new AlterView(session); String viewName = readIdentifierWithSchema(); Table tableView = getSchema().findTableOrView(session, viewName); if (!(tableView instanceof TableView)) { throw DbException.get(ErrorCode.VIEW_NOT_FOUND_1, viewName); } TableView view = (TableView) tableView; command.setView(view); read("RECOMPILE"); return command; }
String schemaName = getSchema().getName(); paramValues.add(ValueString.get(tableName)); if (readIf("FROM")) {
private Table readTableOrView(String tableName) { // same algorithm than readSequence if (schemaName != null) { return getSchema().getTableOrView(session, tableName); } Table table = database.getSchema(session.getCurrentSchemaName()) .findTableOrView(session, tableName); if (table != null) { return table; } String[] schemaNames = session.getSchemaSearchPath(); if (schemaNames != null) { for (String name : schemaNames) { Schema s = database.getSchema(name); table = s.findTableOrView(session, tableName); if (table != null) { return table; } } } throw DbException.get(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, tableName); }
private CreateConstant parseCreateConstant() { boolean ifNotExists = readIfNotExists(); String constantName = readIdentifierWithSchema(); Schema schema = getSchema(); if (isKeyword(constantName)) { throw DbException.get(ErrorCode.CONSTANT_ALREADY_EXISTS_1, constantName); } read("VALUE"); Expression expr = readExpression(); CreateConstant command = new CreateConstant(session, schema); command.setConstantName(constantName); command.setExpression(expr); command.setIfNotExists(ifNotExists); return command; }
private void parseReferences(AlterTableAddConstraint command, Schema schema, String tableName) { if (readIf("(")) { command.setRefTableName(schema, tableName); command.setRefIndexColumns(parseIndexColumnList()); } else { String refTableName = readIdentifierWithSchema(schema.getName()); command.setRefTableName(getSchema(), refTableName); if (readIf("(")) { command.setRefIndexColumns(parseIndexColumnList()); } } if (readIf("INDEX")) { String indexName = readIdentifierWithSchema(); command.setRefIndex(getSchema().findIndex(session, indexName)); } while (readIf("ON")) { if (readIf("DELETE")) { command.setDeleteAction(parseAction()); } else { read("UPDATE"); command.setUpdateAction(parseAction()); } } if (readIf("NOT")) { read("DEFERRABLE"); } else { readIf("DEFERRABLE"); } }
private CreateAggregate parseCreateAggregate(boolean force) { boolean ifNotExists = readIfNotExists(); CreateAggregate command = new CreateAggregate(session); command.setForce(force); String name = readIdentifierWithSchema(); if (isKeyword(name) || Function.getFunction(database, name) != null || getAggregateType(name) >= 0) { throw DbException.get(ErrorCode.FUNCTION_ALIAS_ALREADY_EXISTS_1, name); } command.setName(name); command.setSchema(getSchema()); command.setIfNotExists(ifNotExists); read("FOR"); command.setJavaClassMethod(readUniqueIdentifier()); return command; }
private CreateView parseCreateView(boolean force, boolean orReplace) { boolean ifNotExists = readIfNotExists(); String viewName = readIdentifierWithSchema(); CreateView command = new CreateView(session, getSchema()); command.setViewName(viewName); command.setIfNotExists(ifNotExists);
boolean ifExists = readIfExists(false); String tableName = readIdentifierWithSchema(); DropTable command = new DropTable(session, getSchema()); command.setTableName(tableName); while (readIf(",")) { tableName = readIdentifierWithSchema(); DropTable next = new DropTable(session, getSchema()); next.setTableName(tableName); command.addNextDropTable(next); boolean ifExists = readIfExists(false); String indexName = readIdentifierWithSchema(); DropIndex command = new DropIndex(session, getSchema()); command.setIndexName(indexName); ifExists = readIfExists(ifExists); boolean ifExists = readIfExists(false); String sequenceName = readIdentifierWithSchema(); DropSequence command = new DropSequence(session, getSchema()); command.setSequenceName(sequenceName); ifExists = readIfExists(ifExists); boolean ifExists = readIfExists(false); String constantName = readIdentifierWithSchema(); DropConstant command = new DropConstant(session, getSchema()); command.setConstantName(constantName); ifExists = readIfExists(ifExists); boolean ifExists = readIfExists(false);
private Query parseWith() { readIf("RECURSIVE"); String tempViewName = readIdentifierWithSchema(); Schema schema = getSchema(); Table recursiveTable; read("(");
ifNotExists = readIfNotExists(); indexName = readIdentifierWithSchema(null); oldSchema = getSchema(); ifNotExists = readIfNotExists(); indexName = readIdentifierWithSchema(null); oldSchema = getSchema(); String tableName = readIdentifierWithSchema(); checkSchema(oldSchema); CreateIndex command = new CreateIndex(session, getSchema()); command.setIfNotExists(ifNotExists); command.setHash(hash);
private AlterSequence parseAlterSequence() { String sequenceName = readIdentifierWithSchema(); Sequence sequence = getSchema().getSequence(sequenceName); AlterSequence command = new AlterSequence(session, sequence.getSchema()); command.setSequence(sequence);
private CreateSequence parseCreateSequence() { boolean ifNotExists = readIfNotExists(); String sequenceName = readIdentifierWithSchema(); CreateSequence command = new CreateSequence(session, getSchema()); command.setIfNotExists(ifNotExists); command.setSequenceName(sequenceName);
checkSchema(table.getSchema()); AlterTableRename command = new AlterTableRename(session, getSchema()); command.setOldTable(table); command.setNewTableName(newName); checkSchema(table.getSchema()); AlterTableDropConstraint command = new AlterTableDropConstraint( session, getSchema(), ifExists); command.setConstraintName(constraintName); return command; checkSchema(table.getSchema()); AlterTableDropConstraint command = new AlterTableDropConstraint( session, getSchema(), false); command.setConstraintName(constraintName); return command; DropIndex command = new DropIndex(session, getSchema()); command.setIndexName(indexName); command.setTableName(table.getName());
} else { String tableName = readIdentifierWithSchema(null); Schema schema = getSchema(); boolean foundLeftBracket = readIf("("); if (foundLeftBracket && readIf("INDEX")) {