use of com.google.gwtorm.schema.RelationModel in project gerrit by GerritCodeReview.
the class ProtobufImport method run.
@Override
public int run() throws Exception {
mustHaveValidSite();
Injector dbInjector = createDbInjector(SINGLE_USER);
manager.add(dbInjector);
manager.start();
RuntimeShutdown.add(manager::stop);
dbInjector.injectMembers(this);
ProgressMonitor progress = new TextProgressMonitor();
progress.beginTask("Importing entities", ProgressMonitor.UNKNOWN);
try (ReviewDb db = schemaFactory.open()) {
for (RelationModel model : new JavaSchemaModel(ReviewDb.class).getRelations()) {
relations.put(model.getRelationID(), Relation.create(model, db));
}
Parser<UnknownFieldSet> parser = UnknownFieldSet.getDefaultInstance().getParserForType();
try (InputStream in = new BufferedInputStream(Files.newInputStream(file.toPath()))) {
UnknownFieldSet msg;
while ((msg = parser.parseDelimitedFrom(in)) != null) {
Map.Entry<Integer, UnknownFieldSet.Field> e = Iterables.getOnlyElement(msg.asMap().entrySet());
Relation rel = checkNotNull(relations.get(e.getKey()), "unknown relation ID %s in message: %s", e.getKey(), msg);
List<ByteString> values = e.getValue().getLengthDelimitedList();
checkState(values.size() == 1, "expected one string field in message: %s", msg);
upsert(rel, values.get(0));
progress.update(1);
}
}
progress.endTask();
}
return 0;
}
use of com.google.gwtorm.schema.RelationModel in project gerrit by GerritCodeReview.
the class Schema_101 method findPKUpdates.
private Map<String, PrimaryKey> findPKUpdates() throws OrmException, SQLException {
Map<String, PrimaryKey> corrections = new TreeMap<>();
DatabaseMetaData meta = conn.getMetaData();
JavaSchemaModel jsm = new JavaSchemaModel(ReviewDb.class);
for (RelationModel rm : jsm.getRelations()) {
String tableName = rm.getRelationName();
List<String> expectedPKCols = relationPK(rm);
PrimaryKey actualPK = dbTablePK(meta, tableName);
if (!expectedPKCols.equals(actualPK.cols)) {
actualPK.cols = expectedPKCols;
corrections.put(tableName, actualPK);
}
}
return corrections;
}
Aggregations