Search in sources :

Example 1 with CreateTrigger

use of org.h2.command.ddl.CreateTrigger in project siena by mandubian.

the class FullText method reindex.

/**
     * Re-creates the full text index for this database. Calling this method is
     * usually not needed, as the index is kept up-to-date automatically.
     *
     * @param conn the connection
     */
public static void reindex(Connection conn) throws SQLException {
    init(conn);
    removeAllTriggers(conn, TRIGGER_PREFIX);
    FullTextSettings setting = FullTextSettings.getInstance(conn);
    setting.getWordList().clear();
    Statement stat = conn.createStatement();
    stat.execute("TRUNCATE TABLE " + SCHEMA + ".WORDS");
    stat.execute("TRUNCATE TABLE " + SCHEMA + ".ROWS");
    stat.execute("TRUNCATE TABLE " + SCHEMA + ".MAP");
    ResultSet rs = stat.executeQuery("SELECT * FROM " + SCHEMA + ".FT_INDEXES");
    while (rs.next()) {
        String schema = rs.getString("SCHEMA");
        String table = rs.getString("TABLE");
        createTrigger(conn, schema, table);
        indexExistingRows(conn, schema, table);
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) SimpleResultSet(org.h2.tools.SimpleResultSet) ResultSet(java.sql.ResultSet)

Example 2 with CreateTrigger

use of org.h2.command.ddl.CreateTrigger in project h2database by h2database.

the class Parser method parseCreateTrigger.

private CreateTrigger parseCreateTrigger(boolean force) {
    boolean ifNotExists = readIfNotExists();
    String triggerName = readIdentifierWithSchema(null);
    Schema schema = getSchema();
    boolean insteadOf, isBefore;
    if (readIf("INSTEAD")) {
        read("OF");
        isBefore = true;
        insteadOf = true;
    } else if (readIf("BEFORE")) {
        insteadOf = false;
        isBefore = true;
    } else {
        read("AFTER");
        insteadOf = false;
        isBefore = false;
    }
    int typeMask = 0;
    boolean onRollback = false;
    do {
        if (readIf("INSERT")) {
            typeMask |= Trigger.INSERT;
        } else if (readIf("UPDATE")) {
            typeMask |= Trigger.UPDATE;
        } else if (readIf("DELETE")) {
            typeMask |= Trigger.DELETE;
        } else if (readIf("SELECT")) {
            typeMask |= Trigger.SELECT;
        } else if (readIf("ROLLBACK")) {
            onRollback = true;
        } else {
            throw getSyntaxError();
        }
    } while (readIf(","));
    read("ON");
    String tableName = readIdentifierWithSchema();
    checkSchema(schema);
    CreateTrigger command = new CreateTrigger(session, getSchema());
    command.setForce(force);
    command.setTriggerName(triggerName);
    command.setIfNotExists(ifNotExists);
    command.setInsteadOf(insteadOf);
    command.setBefore(isBefore);
    command.setOnRollback(onRollback);
    command.setTypeMask(typeMask);
    command.setTableName(tableName);
    if (readIf("FOR")) {
        read("EACH");
        read("ROW");
        command.setRowBased(true);
    } else {
        command.setRowBased(false);
    }
    if (readIf("QUEUE")) {
        command.setQueueSize(readPositiveInt());
    }
    command.setNoWait(readIf("NOWAIT"));
    if (readIf("AS")) {
        command.setTriggerSource(readString());
    } else {
        read("CALL");
        command.setTriggerClassName(readUniqueIdentifier());
    }
    return command;
}
Also used : CreateTrigger(org.h2.command.ddl.CreateTrigger) DropSchema(org.h2.command.ddl.DropSchema) CreateSchema(org.h2.command.ddl.CreateSchema) Schema(org.h2.schema.Schema) ValueString(org.h2.value.ValueString) AlterTableRenameConstraint(org.h2.command.ddl.AlterTableRenameConstraint) AlterTableAddConstraint(org.h2.command.ddl.AlterTableAddConstraint) AlterTableDropConstraint(org.h2.command.ddl.AlterTableDropConstraint)

Example 3 with CreateTrigger

use of org.h2.command.ddl.CreateTrigger in project frostwire by frostwire.

the class FullTextLucene2 method reindex.

/**
 * Re-creates the full text index for this database. Calling this method is
 * usually not needed, as the index is kept up-to-date automatically.
 *
 * @param conn the connection
 */
public static void reindex(Connection conn) throws SQLException {
    init(conn);
    removeAllTriggers(conn, TRIGGER_PREFIX);
    removeIndexFiles(conn);
    Statement stat = conn.createStatement();
    ResultSet rs = stat.executeQuery("SELECT * FROM " + SCHEMA + ".INDEXES");
    while (rs.next()) {
        String schema = rs.getString("SCHEMA");
        String table = rs.getString("TABLE");
        createTrigger(conn, schema, table);
        indexExistingRows(conn, schema, table);
    }
}
Also used : SimpleResultSet(org.h2.tools.SimpleResultSet)

Example 4 with CreateTrigger

use of org.h2.command.ddl.CreateTrigger in project h2database by h2database.

the class FullText method reindex.

/**
 * Re-creates the full text index for this database. Calling this method is
 * usually not needed, as the index is kept up-to-date automatically.
 *
 * @param conn the connection
 */
public static void reindex(Connection conn) throws SQLException {
    init(conn);
    removeAllTriggers(conn, TRIGGER_PREFIX);
    FullTextSettings setting = FullTextSettings.getInstance(conn);
    setting.clearWordList();
    Statement stat = conn.createStatement();
    stat.execute("TRUNCATE TABLE " + SCHEMA + ".WORDS");
    stat.execute("TRUNCATE TABLE " + SCHEMA + ".ROWS");
    stat.execute("TRUNCATE TABLE " + SCHEMA + ".MAP");
    ResultSet rs = stat.executeQuery("SELECT * FROM " + SCHEMA + ".INDEXES");
    while (rs.next()) {
        String schema = rs.getString("SCHEMA");
        String table = rs.getString("TABLE");
        createTrigger(conn, schema, table);
        indexExistingRows(conn, schema, table);
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) SimpleResultSet(org.h2.tools.SimpleResultSet) ResultSet(java.sql.ResultSet)

Example 5 with CreateTrigger

use of org.h2.command.ddl.CreateTrigger in project h2database by h2database.

the class FullTextLucene method reindex.

/**
 * Re-creates the full text index for this database. Calling this method is
 * usually not needed, as the index is kept up-to-date automatically.
 *
 * @param conn the connection
 */
public static void reindex(Connection conn) throws SQLException {
    init(conn);
    removeAllTriggers(conn, TRIGGER_PREFIX);
    removeIndexFiles(conn);
    Statement stat = conn.createStatement();
    ResultSet rs = stat.executeQuery("SELECT * FROM " + SCHEMA + ".INDEXES");
    while (rs.next()) {
        String schema = rs.getString("SCHEMA");
        String table = rs.getString("TABLE");
        createTrigger(conn, schema, table);
        indexExistingRows(conn, schema, table);
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) SimpleResultSet(org.h2.tools.SimpleResultSet) ResultSet(java.sql.ResultSet)

Aggregations

SimpleResultSet (org.h2.tools.SimpleResultSet)4 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 Statement (java.sql.Statement)3 AlterTableAddConstraint (org.h2.command.ddl.AlterTableAddConstraint)1 AlterTableDropConstraint (org.h2.command.ddl.AlterTableDropConstraint)1 AlterTableRenameConstraint (org.h2.command.ddl.AlterTableRenameConstraint)1 CreateSchema (org.h2.command.ddl.CreateSchema)1 CreateTrigger (org.h2.command.ddl.CreateTrigger)1 DropSchema (org.h2.command.ddl.DropSchema)1 Schema (org.h2.schema.Schema)1 ValueString (org.h2.value.ValueString)1