说明
java updateui示例是从最受好评的开源项目中提取的实现代码,你可以参考下面示例的使用方式。
编程语言: Java
类/类型: UpdateUI
示例#1
/** 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);
}
}
}
示例#2
private void migrateData(
List<SchemaVersion> pending, UpdateUI ui, CurrentSchemaVersion curr, ReviewDb db)
throws OrmException, SQLException {
for (SchemaVersion v : pending) {
ui.message(String.format("Migrating data to schema %d ...", v.getVersionNbr()));
v.migrateData(db, ui);
v.finish(curr, db);
}
}
示例#3文件:
SchemaVersion.java项目:
TYPO3-infrastructure/gerrit
/** Runs check on the prior schema version, and then upgrades. */
protected void upgradeFrom(
UpdateUI ui, CurrentSchemaVersion curr, ReviewDb db, boolean toTargetVersion)
throws OrmException, SQLException {
final JdbcSchema s = (JdbcSchema) db;
if (curr.versionNbr > versionNbr) {
throw new OrmException(
"Cannot downgrade database schema from version "
+ curr.versionNbr
+ " to "
+ versionNbr
+ ".");
}
prior.get().check(ui, curr, db, false);
ui.message(
"Upgrading database schema from version " + curr.versionNbr + " to " + versionNbr + " ...");
preUpdateSchema(db);
final JdbcExecutor e = new JdbcExecutor(s);
try {
s.updateSchema(e);
migrateData(db, ui);
if (toTargetVersion) {
final List<String> pruneList = new ArrayList<String>();
s.pruneSchema(
new StatementExecutor() {
public void execute(String sql) {
pruneList.add(sql);
}
});
if (!pruneList.isEmpty()) {
ui.pruneSchema(e, pruneList);
}
}
} finally {
e.close();
}
finish(curr, db);
}
示例#4
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);
}
}
示例#5文件:
Schema_65.java项目:
willdeberry/aokp-gerrit
@Override
protected void migrateData(ReviewDb db, UpdateUI ui) throws OrmException, SQLException {
Repository git;
try {
git = mgr.openRepository(allProjects);
} catch (IOException e) {
throw new OrmException(e);
}
try {
MetaDataUpdate md = new MetaDataUpdate(GitReferenceUpdated.DISABLED, allProjects, git);
ProjectConfig config = ProjectConfig.read(md);
Map<Integer, ContributorAgreement> agreements = getAgreementToAdd(db, config);
if (agreements.isEmpty()) {
return;
}
ui.message("Moved contributor agreements to project.config");
// Create the auto verify groups.
List<AccountGroup.UUID> adminGroupUUIDs = getAdministrateServerGroups(db, config);
for (ContributorAgreement agreement : agreements.values()) {
if (agreement.getAutoVerify() != null) {
getOrCreateGroupForIndividuals(db, config, adminGroupUUIDs, agreement);
}
}
// Scan AccountAgreement
long minTime = addAccountAgreements(db, config, adminGroupUUIDs, agreements);
ProjectConfig base = ProjectConfig.read(md, null);
for (ContributorAgreement agreement : agreements.values()) {
base.replace(agreement);
}
base.getAccountsSection()
.setSameGroupVisibility(config.getAccountsSection().getSameGroupVisibility());
BatchMetaDataUpdate batch = base.openUpdate(md);
try {
// Scan AccountGroupAgreement
List<AccountGroupAgreement> groupAgreements = getAccountGroupAgreements(db, agreements);
// Find the earliest change
for (AccountGroupAgreement aga : groupAgreements) {
minTime = Math.min(minTime, aga.getTime());
}
minTime -= 60 * 1000; // 1 Minute
CommitBuilder commit = new CommitBuilder();
commit.setAuthor(new PersonIdent(serverUser, new Date(minTime)));
commit.setCommitter(new PersonIdent(serverUser, new Date(minTime)));
commit.setMessage(
"Add the ContributorAgreements for upgrade to Gerrit Code Review schema 65\n");
batch.write(commit);
for (AccountGroupAgreement aga : groupAgreements) {
AccountGroup group = db.accountGroups().get(aga.groupId);
if (group == null) {
continue;
}
ContributorAgreement agreement = agreements.get(aga.claId);
agreement.getAccepted().add(new PermissionRule(config.resolve(group)));
base.replace(agreement);
PersonIdent ident = null;
if (aga.reviewedBy != null) {
Account ua = db.accounts().get(aga.reviewedBy);
if (ua != null) {
String name = ua.getFullName();
String email = ua.getPreferredEmail();
if (email == null || email.isEmpty()) {
// No preferred email is configured. Use a generic identity so we
// don't leak an address the user may have given us, but doesn't
// necessarily want to publish through Git records.
//
String user = ua.getUserName();
if (user == null || user.isEmpty()) {
user = "account-" + ua.getId().toString();
}
String host = SystemReader.getInstance().getHostname();
email = user + "@" + host;
}
if (name == null || name.isEmpty()) {
final int at = email.indexOf('@');
if (0 < at) {
name = email.substring(0, at);
} else {
name = anonymousCowardName;
}
}
ident = new PersonIdent(name, email, new Date(aga.getTime()), TimeZone.getDefault());
}
}
if (ident == null) {
ident = new PersonIdent(serverUser, new Date(aga.getTime()));
}
// Build the commits such that it keeps track of the date added and
// who added it.
commit = new CommitBuilder();
commit.setAuthor(ident);
commit.setCommitter(new PersonIdent(serverUser, new Date(aga.getTime())));
String msg =
String.format(
"Accept %s contributor agreement for %s\n", agreement.getName(), group.getName());
if (!Strings.isNullOrEmpty(aga.reviewComments)) {
msg += "\n" + aga.reviewComments + "\n";
}
commit.setMessage(msg);
batch.write(commit);
}
// Merge the agreements with the other data in project.config.
commit = new CommitBuilder();
commit.setAuthor(serverUser);
commit.setCommitter(serverUser);
commit.setMessage("Upgrade to Gerrit Code Review schema 65\n");
commit.addParentId(config.getRevision());
batch.write(config, commit);
// Save the the final metadata.
batch.commitAt(config.getRevision());
} finally {
batch.close();
}
} catch (IOException e) {
throw new OrmException(e);
} catch (ConfigInvalidException e) {
throw new OrmException(e);
} finally {
git.close();
}
}