Search in sources :

Example 1 with SqlDialect

use of com.google.gwtorm.schema.sql.SqlDialect in project gerrit by GerritCodeReview.

the class Schema_145 method migrateData.

@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException, SQLException {
    JdbcSchema schema = (JdbcSchema) db;
    SqlDialect dialect = schema.getDialect();
    try (StatementExecutor e = newExecutor(db)) {
        try {
            dialect.dropIndex(e, "account_external_ids", "account_external_ids_byEmail");
        } catch (OrmException ex) {
        // Ignore.  The index did not exist.
        }
        e.execute("CREATE INDEX account_external_ids_byEmail" + " ON account_external_ids" + " (email_address)");
    }
}
Also used : JdbcSchema(com.google.gwtorm.jdbc.JdbcSchema) OrmException(com.google.gwtorm.server.OrmException) SqlDialect(com.google.gwtorm.schema.sql.SqlDialect) StatementExecutor(com.google.gwtorm.server.StatementExecutor)

Example 2 with SqlDialect

use of com.google.gwtorm.schema.sql.SqlDialect in project gerrit by GerritCodeReview.

the class Schema_89 method migrateData.

@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException, SQLException {
    SqlDialect dialect = ((JdbcSchema) db).getDialect();
    try (StatementExecutor e = newExecutor(db)) {
        dialect.dropIndex(e, "patch_set_approvals", "patch_set_approvals_openByUser");
        dialect.dropIndex(e, "patch_set_approvals", "patch_set_approvals_closedByU");
    }
}
Also used : JdbcSchema(com.google.gwtorm.jdbc.JdbcSchema) SqlDialect(com.google.gwtorm.schema.sql.SqlDialect) StatementExecutor(com.google.gwtorm.server.StatementExecutor)

Example 3 with SqlDialect

use of com.google.gwtorm.schema.sql.SqlDialect in project gerrit by GerritCodeReview.

the class ScriptRunner method run.

void run(final ReviewDb db) throws OrmException {
    try {
        final JdbcSchema schema = (JdbcSchema) db;
        final Connection c = schema.getConnection();
        final SqlDialect dialect = schema.getDialect();
        try (Statement stmt = c.createStatement()) {
            for (String sql : commands) {
                try {
                    if (!dialect.isStatementDelimiterSupported()) {
                        sql = CharMatcher.is(';').trimTrailingFrom(sql);
                    }
                    stmt.execute(sql);
                } catch (SQLException e) {
                    throw new OrmException("Error in " + name + ":\n" + sql, e);
                }
            }
        }
    } catch (SQLException e) {
        throw new OrmException("Cannot run statements for " + name, e);
    }
}
Also used : JdbcSchema(com.google.gwtorm.jdbc.JdbcSchema) SQLException(java.sql.SQLException) OrmException(com.google.gwtorm.server.OrmException) Statement(java.sql.Statement) Connection(java.sql.Connection) SqlDialect(com.google.gwtorm.schema.sql.SqlDialect)

Example 4 with SqlDialect

use of com.google.gwtorm.schema.sql.SqlDialect in project gerrit by GerritCodeReview.

the class Schema_102 method migrateData.

@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException, SQLException {
    JdbcSchema schema = (JdbcSchema) db;
    SqlDialect dialect = schema.getDialect();
    try (StatementExecutor e = newExecutor(db)) {
        // Drop left over indexes that were missed to be removed in schema 84.
        // See "Delete SQL index support" commit for more details:
        // d4ae3a16d5e1464574bd04f429a63eb9c02b3b43
        Pattern pattern = Pattern.compile("^changes_(allOpen|allClosed|byBranchClosed)$", Pattern.CASE_INSENSITIVE);
        String table = "changes";
        Set<String> listIndexes = dialect.listIndexes(schema.getConnection(), table);
        for (String index : listIndexes) {
            if (pattern.matcher(index).matches()) {
                dialect.dropIndex(e, table, index);
            }
        }
        dialect.dropIndex(e, table, "changes_byProjectOpen");
        if (dialect instanceof DialectPostgreSQL) {
            e.execute("CREATE INDEX changes_byProjectOpen" + " ON " + table + " (dest_project_name, last_updated_on)" + " WHERE open = 'Y'");
        } else {
            e.execute("CREATE INDEX changes_byProjectOpen" + " ON " + table + " (open, dest_project_name, last_updated_on)");
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) JdbcSchema(com.google.gwtorm.jdbc.JdbcSchema) DialectPostgreSQL(com.google.gwtorm.schema.sql.DialectPostgreSQL) SqlDialect(com.google.gwtorm.schema.sql.SqlDialect) StatementExecutor(com.google.gwtorm.server.StatementExecutor)

Example 5 with SqlDialect

use of com.google.gwtorm.schema.sql.SqlDialect in project gerrit by GerritCodeReview.

the class Schema_105 method migrateData.

@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws SQLException, OrmException {
    JdbcSchema schema = (JdbcSchema) db;
    SqlDialect dialect = schema.getDialect();
    Map<String, OrmException> errors = new HashMap<>();
    try (StatementExecutor e = newExecutor(db)) {
        for (String index : listChangesIndexes(schema)) {
            ui.message("Dropping index " + index + " on table " + TABLE);
            try {
                dialect.dropIndex(e, TABLE, index);
            } catch (OrmException err) {
                errors.put(index, err);
            }
        }
    }
    for (String index : listChangesIndexes(schema)) {
        String msg = "Failed to drop index " + index;
        OrmException err = errors.get(index);
        if (err != null) {
            msg += ": " + err.getMessage();
        }
        ui.message(msg);
    }
}
Also used : JdbcSchema(com.google.gwtorm.jdbc.JdbcSchema) HashMap(java.util.HashMap) OrmException(com.google.gwtorm.server.OrmException) SqlDialect(com.google.gwtorm.schema.sql.SqlDialect) StatementExecutor(com.google.gwtorm.server.StatementExecutor)

Aggregations

JdbcSchema (com.google.gwtorm.jdbc.JdbcSchema)5 SqlDialect (com.google.gwtorm.schema.sql.SqlDialect)5 StatementExecutor (com.google.gwtorm.server.StatementExecutor)4 OrmException (com.google.gwtorm.server.OrmException)3 DialectPostgreSQL (com.google.gwtorm.schema.sql.DialectPostgreSQL)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 HashMap (java.util.HashMap)1 Pattern (java.util.regex.Pattern)1