Search in sources :

Example 1 with CreateSynonym

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;
}
Also used : CreateSynonym(org.h2.command.ddl.CreateSynonym) DropSchema(org.h2.command.ddl.DropSchema) CreateSchema(org.h2.command.ddl.CreateSchema) Schema(org.h2.schema.Schema) ValueString(org.h2.value.ValueString)

Example 2 with CreateSynonym

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;
}
Also used : TableSynonym(org.h2.table.TableSynonym)

Aggregations

CreateSchema (org.h2.command.ddl.CreateSchema)1 CreateSynonym (org.h2.command.ddl.CreateSynonym)1 DropSchema (org.h2.command.ddl.DropSchema)1 Schema (org.h2.schema.Schema)1 TableSynonym (org.h2.table.TableSynonym)1 ValueString (org.h2.value.ValueString)1