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");
}
}
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);
}
}
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);
}
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);
}
}
}
Aggregations