use of org.h2.command.ddl.CreateSynonym in project h2database by h2database.
the class Parser method parseCreateSynonym.
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;
}
use of org.h2.command.ddl.CreateSynonym in project h2database by h2database.
the class CreateSynonym method createTableSynonym.
private int createTableSynonym(Database db) {
TableSynonym old = getSchema().getSynonym(data.synonymName);
if (old != null) {
if (orReplace) {
// ok, we replacing the existing synonym
} else if (ifNotExists) {
return 0;
} else {
throw DbException.get(ErrorCode.TABLE_OR_VIEW_ALREADY_EXISTS_1, data.synonymName);
}
}
TableSynonym table;
if (old != null) {
table = old;
data.schema = table.getSchema();
table.updateData(data);
table.setComment(comment);
table.setModified();
db.updateMeta(session, table);
} else {
data.id = getObjectId();
table = getSchema().createSynonym(data);
table.setComment(comment);
db.addSchemaObject(session, table);
}
table.updateSynonymFor();
return 0;
}
Aggregations