Search in sources :

Example 1 with JdbcExecutor

use of com.google.gwtorm.jdbc.JdbcExecutor in project gerrit by GerritCodeReview.

the class Schema_101 method migrateData.

@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException, SQLException {
    conn = ((JdbcSchema) db).getConnection();
    dialect = ((JdbcSchema) db).getDialect();
    Map<String, PrimaryKey> corrections = findPKUpdates();
    if (corrections.isEmpty()) {
        return;
    }
    ui.message("Wrong Primary Key Column Order Detected");
    ui.message("The following tables are affected:");
    ui.message(Joiner.on(", ").join(corrections.keySet()));
    ui.message("fixing primary keys...");
    try (JdbcExecutor executor = new JdbcExecutor(conn)) {
        for (Map.Entry<String, PrimaryKey> c : corrections.entrySet()) {
            ui.message(String.format("  table: %s ... ", c.getKey()));
            recreatePK(executor, c.getKey(), c.getValue(), ui);
            ui.message("done");
        }
        ui.message("done");
    }
}
Also used : JdbcExecutor(com.google.gwtorm.jdbc.JdbcExecutor) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 2 with JdbcExecutor

use of com.google.gwtorm.jdbc.JdbcExecutor in project gerrit by GerritCodeReview.

the class SchemaVersion method updateSchema.

private void updateSchema(List<SchemaVersion> pending, UpdateUI ui, ReviewDb db) throws OrmException, SQLException {
    for (SchemaVersion v : pending) {
        ui.message(String.format("Upgrading schema to %d ...", v.getVersionNbr()));
        v.preUpdateSchema(db);
    }
    JdbcSchema s = (JdbcSchema) db;
    try (JdbcExecutor e = new JdbcExecutor(s)) {
        s.updateSchema(e);
    }
}
Also used : CurrentSchemaVersion(com.google.gerrit.reviewdb.client.CurrentSchemaVersion) JdbcSchema(com.google.gwtorm.jdbc.JdbcSchema) JdbcExecutor(com.google.gwtorm.jdbc.JdbcExecutor)

Example 3 with JdbcExecutor

use of com.google.gwtorm.jdbc.JdbcExecutor in project gerrit by GerritCodeReview.

the class SchemaCreator method create.

public void create(final ReviewDb db) throws OrmException, IOException, ConfigInvalidException {
    final JdbcSchema jdbc = (JdbcSchema) db;
    try (JdbcExecutor e = new JdbcExecutor(jdbc)) {
        jdbc.updateSchema(e);
    }
    final CurrentSchemaVersion sVer = CurrentSchemaVersion.create();
    sVer.versionNbr = SchemaVersion.getBinaryVersion();
    db.schemaVersion().insert(Collections.singleton(sVer));
    createDefaultGroups(db);
    initSystemConfig(db);
    allProjectsCreator.setAdministrators(GroupReference.forGroup(admin)).setBatchUsers(GroupReference.forGroup(batch)).create();
    allUsersCreator.setAdministrators(GroupReference.forGroup(admin)).create();
    dataSourceType.getIndexScript().run(db);
}
Also used : CurrentSchemaVersion(com.google.gerrit.reviewdb.client.CurrentSchemaVersion) JdbcSchema(com.google.gwtorm.jdbc.JdbcSchema) JdbcExecutor(com.google.gwtorm.jdbc.JdbcExecutor)

Example 4 with JdbcExecutor

use of com.google.gwtorm.jdbc.JdbcExecutor in project gerrit by GerritCodeReview.

the class SchemaVersion method upgradeFrom.

/** Runs check on the prior schema version, and then upgrades. */
private void upgradeFrom(UpdateUI ui, CurrentSchemaVersion curr, ReviewDb db) throws OrmException, SQLException {
    List<SchemaVersion> pending = pending(curr.versionNbr);
    updateSchema(pending, ui, db);
    migrateData(pending, ui, curr, db);
    JdbcSchema s = (JdbcSchema) db;
    final List<String> pruneList = new ArrayList<>();
    s.pruneSchema(new StatementExecutor() {

        @Override
        public void execute(String sql) {
            pruneList.add(sql);
        }

        @Override
        public void close() {
        // Do nothing.
        }
    });
    try (JdbcExecutor e = new JdbcExecutor(s)) {
        if (!pruneList.isEmpty()) {
            ui.pruneSchema(e, pruneList);
        }
    }
}
Also used : CurrentSchemaVersion(com.google.gerrit.reviewdb.client.CurrentSchemaVersion) JdbcSchema(com.google.gwtorm.jdbc.JdbcSchema) ArrayList(java.util.ArrayList) JdbcExecutor(com.google.gwtorm.jdbc.JdbcExecutor) StatementExecutor(com.google.gwtorm.server.StatementExecutor)

Aggregations

JdbcExecutor (com.google.gwtorm.jdbc.JdbcExecutor)4 CurrentSchemaVersion (com.google.gerrit.reviewdb.client.CurrentSchemaVersion)3 JdbcSchema (com.google.gwtorm.jdbc.JdbcSchema)3 StatementExecutor (com.google.gwtorm.server.StatementExecutor)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1