use of org.apache.cayenne.dbsync.merge.token.MergerToken in project cayenne by apache.
the class DataMapMergerTest method testAddColumn.
@Test
public void testAddColumn() throws Exception {
DataMap existing = dataMap().with(dbEntity("table1").attributes(dbAttr("attr01").typeInt(), dbAttr("attr02").typeInt())).build();
DataMap db = dataMap().with(dbEntity("table1").attributes(dbAttr("attr01").typeInt())).build();
List<MergerToken> tokens = dbMerger().createMergeTokens(existing, db);
assertEquals(1, tokens.size());
DbEntity entity = existing.getDbEntity("table1");
assertEquals(factory().createAddColumnToDb(entity, entity.getAttribute("attr02")).getTokenValue(), tokens.get(0).getTokenValue());
}
use of org.apache.cayenne.dbsync.merge.token.MergerToken in project cayenne by apache.
the class DataMapMergerTest method testAddPrimaryKey.
@Test
public void testAddPrimaryKey() throws Exception {
DataMap existing = dataMap().with(dbEntity("table1").attributes(dbAttr("attr01").typeInt().primaryKey())).build();
DataMap db = dataMap().with(dbEntity("table1").attributes(dbAttr("attr01").typeInt())).build();
List<MergerToken> tokens = dbMerger().createMergeTokens(existing, db);
assertEquals(1, tokens.size());
}
use of org.apache.cayenne.dbsync.merge.token.MergerToken in project cayenne by apache.
the class DataMapMergerTest method testChangeColumnLength.
@Test
public void testChangeColumnLength() throws Exception {
DataMap existing = dataMap().with(dbEntity("table1").attributes(dbAttr("attr01").typeVarchar(60))).build();
DataMap db = dataMap().with(dbEntity("table1").attributes(dbAttr("attr01").typeVarchar(30))).build();
List<MergerToken> tokens = dbMerger().createMergeTokens(existing, db);
assertEquals(1, tokens.size());
DbEntity entity = existing.getDbEntity("table1");
DbEntity entityDb = db.getDbEntity("table1");
assertTrue(tokens.get(0) instanceof SetColumnTypeToDb);
assertEquals(factory().createSetColumnTypeToDb(entity, entityDb.getAttribute("attr01"), entity.getAttribute("attr01")).getTokenValue(), tokens.get(0).getTokenValue());
}
use of org.apache.cayenne.dbsync.merge.token.MergerToken in project cayenne by apache.
the class DataMapMergerTest method testRemoveRelationship.
@Test
public void testRemoveRelationship() throws Exception {
DataMap existing = dataMap().with(dbEntity("table1").attributes(dbAttr("attr01").typeInt(), dbAttr("attr02").typeInt()), dbEntity("table2").attributes(dbAttr("attr01").typeInt().primaryKey(), dbAttr("attr02").typeInt())).build();
DataMap db = dataMap().with(dbEntity("table1").attributes(dbAttr("attr01").typeInt(), dbAttr("attr02").typeInt()), dbEntity("table2").attributes(dbAttr("attr01").typeInt().primaryKey(), dbAttr("attr02").typeInt())).join("rel", "table1.attr01", "table2.attr01").build();
List<MergerToken> tokens = dbMerger().createMergeTokens(existing, db);
assertEquals(1, tokens.size());
DbEntity entity = db.getDbEntity("table1");
assertEquals(factory().createDropRelationshipToDb(entity, entity.getRelationship("rel")).getTokenValue(), tokens.get(0).getTokenValue());
}
use of org.apache.cayenne.dbsync.merge.token.MergerToken in project cayenne by apache.
the class MergerOptions method applyTokens.
private boolean applyTokens(List<MergerToken> tokensToMigrate, MergerContext mergerContext) {
boolean modelChanged = false;
try {
for (MergerToken tok : tokensToMigrate) {
int numOfFailuresBefore = getFailuresCount(mergerContext);
tok.execute(mergerContext);
if (!modelChanged && tok.getDirection().equals(MergeDirection.TO_MODEL)) {
modelChanged = true;
}
if (numOfFailuresBefore == getFailuresCount(mergerContext)) {
// looks like the token executed without failures
tokens.removeToken(tok);
}
}
} catch (Throwable th) {
reportError("Migration Error", th);
}
return modelChanged;
}
Aggregations