private Schema getSchema() { return getSchema(schemaName); } /*
private Schema getSchemaWithDefault() { if (schemaName == null) { schemaName = session.getCurrentSchemaName(); } return getSchema(schemaName); }
private void checkSchema(Schema old) { if (old != null && getSchema() != old) { throw DbException.get(ErrorCode.SCHEMA_NAME_MUST_MATCH); } }
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 CreateSynonym parseCreateSynonym(boolean orReplace) { boolean ifNotExists = readIfNotExists(); String name = readIdentifierWithSchema(); Schema synonymSchema = getSchema(); read("FOR"); String tableName = readIdentifierWithSchema(); Schema targetSchema = getSchema(); CreateSynonym command = new CreateSynonym(session, synonymSchema); command.setName(name); command.setSynonymFor(tableName); command.setSynonymForSchema(targetSchema); command.setComment(readCommentIf()); command.setIfNotExists(ifNotExists); command.setOrReplace(orReplace); return command; }
private AlterView parseAlterView() { AlterView command = new AlterView(session); boolean ifExists = readIfExists(false); command.setIfExists(ifExists); String viewName = readIdentifierWithSchema(); Table tableView = getSchema().findTableOrView(session, viewName); if (!(tableView instanceof TableView) && !ifExists) { 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()) .resolveTableOrView(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.resolveTableOrView(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 AlterIndexRename parseAlterIndex() { boolean ifExists = readIfExists(false); String indexName = readIdentifierWithSchema(); Schema old = getSchema(); AlterIndexRename command = new AlterIndexRename(session); command.setOldSchema(old); command.setOldName(indexName); command.setIfExists(ifExists); read("RENAME"); read("TO"); String newName = readIdentifierWithSchema(old.getName()); checkSchema(old); command.setNewName(newName); return command; }
private TableView parseSingleCommonTableExpression(boolean isPersistent) { String cteViewName = readIdentifierWithSchema(); Schema schema = getSchema(); Table recursiveTable = null; ArrayList<Column> columns = New.arrayList(); oldViewFound = getSchema().findTableOrView(session, cteViewName); } else { oldViewFound = session.findLocalTempTable(cteViewName);
private Prepared parseAlterSchema() { boolean ifExists = readIfExists(false); String schemaName = readIdentifierWithSchema(); Schema old = getSchema(); read("RENAME"); read("TO"); String newName = readIdentifierWithSchema(old.getName()); Schema schema = findSchema(schemaName); if (schema == null) { if (ifExists) { return new NoOperation(session); } throw DbException.get(ErrorCode.SCHEMA_NOT_FOUND_1, schemaName); } AlterSchemaRename command = new AlterSchemaRename(session); command.setOldSchema(schema); checkSchema(old); command.setNewName(newName); return command; }
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) != null) { 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 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"); } }
boolean isTableExpression = readIf("TABLE_EXPRESSION"); String viewName = readIdentifierWithSchema(); CreateView command = new CreateView(session, getSchema()); this.createView = command; command.setViewName(viewName);
private CreateTrigger parseCreateTrigger(boolean force) { boolean ifNotExists = readIfNotExists(); String triggerName = readIdentifierWithSchema(null); Schema schema = getSchema(); boolean insteadOf, isBefore; if (readIf("INSTEAD")) { String tableName = readIdentifierWithSchema(); checkSchema(schema); CreateTrigger command = new CreateTrigger(session, getSchema()); command.setForce(force); command.setTriggerName(triggerName);
getSchema()); command.setForce(force); command.setAliasName(aliasName);
boolean ifNotExists = readIfNotExists(); String tableName = readIdentifierWithSchema(); CreateLinkedTable command = new CreateLinkedTable(session, getSchema()); command.setTemporary(temp); command.setGlobalTemporary(globalTemp);
private AlterSequence parseAlterSequence() { boolean ifExists = readIfExists(false); String sequenceName = readIdentifierWithSchema(); AlterSequence command = new AlterSequence(session, getSchema()); command.setSequenceName(sequenceName); command.setIfExists(ifExists);
private CreateSequence parseCreateSequence() { boolean ifNotExists = readIfNotExists(); String sequenceName = readIdentifierWithSchema(); CreateSequence command = new CreateSequence(session, getSchema()); command.setIfNotExists(ifNotExists); command.setSequenceName(sequenceName);