use of com.google.gwtorm.jdbc.JdbcSchema 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)");
}
}
use of com.google.gwtorm.jdbc.JdbcSchema in project gerrit by GerritCodeReview.
the class Schema_117 method preUpdateSchema.
@Override
protected void preUpdateSchema(ReviewDb db) throws OrmException, SQLException {
JdbcSchema schema = (JdbcSchema) db;
Connection connection = schema.getConnection();
String tableName = "patch_sets";
String oldColumnName = "push_certficate";
String newColumnName = "push_certificate";
Set<String> columns = schema.getDialect().listColumns(connection, tableName);
if (columns.contains(oldColumnName)) {
renameColumn(db, tableName, oldColumnName, newColumnName);
}
try (Statement stmt = schema.getConnection().createStatement()) {
stmt.execute("ALTER TABLE " + tableName + " MODIFY " + newColumnName + " clob");
} catch (SQLException e) {
// Ignore. Type may have already been modified manually.
}
}
use of com.google.gwtorm.jdbc.JdbcSchema in project gerrit by GerritCodeReview.
the class Schema_119 method migrateData.
@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException, SQLException {
JdbcSchema schema = (JdbcSchema) db;
Connection connection = schema.getConnection();
String tableName = "accounts";
String emailStrategy = "email_strategy";
Set<String> columns = schema.getDialect().listColumns(connection, tableName);
Map<Account.Id, GeneralPreferencesInfo> imports = new HashMap<>();
try (Statement stmt = ((JdbcSchema) db).getConnection().createStatement();
ResultSet rs = stmt.executeQuery("select " + "account_id, " + "maximum_page_size, " + "show_site_header, " + "use_flash_clipboard, " + "download_url, " + "download_command, " + (columns.contains(emailStrategy) ? emailStrategy + ", " : "copy_self_on_email, ") + "date_format, " + "time_format, " + "relative_date_in_change_table, " + "diff_view, " + "size_bar_in_change_table, " + "legacycid_in_change_table, " + "review_category_strategy, " + "mute_common_path_prefixes " + "from " + tableName)) {
while (rs.next()) {
GeneralPreferencesInfo p = new GeneralPreferencesInfo();
Account.Id accountId = new Account.Id(rs.getInt(1));
p.changesPerPage = (int) rs.getShort(2);
p.showSiteHeader = toBoolean(rs.getString(3));
p.useFlashClipboard = toBoolean(rs.getString(4));
p.downloadScheme = convertToModernNames(rs.getString(5));
p.downloadCommand = toDownloadCommand(rs.getString(6));
p.emailStrategy = toEmailStrategy(rs.getString(7), columns.contains(emailStrategy));
p.dateFormat = toDateFormat(rs.getString(8));
p.timeFormat = toTimeFormat(rs.getString(9));
p.relativeDateInChangeTable = toBoolean(rs.getString(10));
p.diffView = toDiffView(rs.getString(11));
p.sizeBarInChangeTable = toBoolean(rs.getString(12));
p.legacycidInChangeTable = toBoolean(rs.getString(13));
p.reviewCategoryStrategy = toReviewCategoryStrategy(rs.getString(14));
p.muteCommonPathPrefixes = toBoolean(rs.getString(15));
p.defaultBaseForMerges = GeneralPreferencesInfo.defaults().defaultBaseForMerges;
imports.put(accountId, p);
}
}
if (imports.isEmpty()) {
return;
}
try (Repository git = mgr.openRepository(allUsersName);
RevWalk rw = new RevWalk(git)) {
BatchRefUpdate bru = git.getRefDatabase().newBatchUpdate();
for (Map.Entry<Account.Id, GeneralPreferencesInfo> e : imports.entrySet()) {
try (MetaDataUpdate md = new MetaDataUpdate(GitReferenceUpdated.DISABLED, allUsersName, git, bru)) {
md.getCommitBuilder().setAuthor(serverUser);
md.getCommitBuilder().setCommitter(serverUser);
VersionedAccountPreferences p = VersionedAccountPreferences.forUser(e.getKey());
p.load(md);
storeSection(p.getConfig(), UserConfigSections.GENERAL, null, e.getValue(), GeneralPreferencesInfo.defaults());
p.commit(md);
}
}
bru.execute(rw, NullProgressMonitor.INSTANCE);
} catch (ConfigInvalidException | IOException ex) {
throw new OrmException(ex);
}
}
use of com.google.gwtorm.jdbc.JdbcSchema 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");
}
}
use of com.google.gwtorm.jdbc.JdbcSchema 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);
}
}
Aggregations