use of org.apache.cayenne.dbsync.merge.token.MergerToken in project cayenne by apache.
the class DataMapMergerTest method testChangeColumnType.
/**
* Test unsupported type changes
*/
@Test
public void testChangeColumnType() throws Exception {
DbEntity fromModel = dbEntity("table1").attributes(dbAttr("attr01").typeInt(), dbAttr("attr02").type("DATE"), dbAttr("attr03").type("BOOLEAN"), dbAttr("attr04").type("FLOAT")).build();
DataMap existing = dataMap().with(fromModel).build();
DbEntity fromDb = dbEntity("table1").attributes(dbAttr("attr01").typeBigInt(), dbAttr("attr02").type("NUMERIC"), dbAttr("attr03").type("BLOB"), dbAttr("attr04").type("TIMESTAMP")).build();
DataMap db = dataMap().with(fromDb).build();
List<MergerToken> tokens = dbMerger().createMergeTokens(existing, db);
assertEquals(4, tokens.size());
for (MergerToken token : tokens) {
assertTrue(token instanceof SetColumnTypeToDb);
}
MergerToken attr02Token = findChangeTypeToken(tokens, "attr02");
assertNotNull(attr02Token);
assertEquals(factory().createSetColumnTypeToDb(fromModel, fromDb.getAttribute("attr02"), fromModel.getAttribute("attr02")).getTokenValue(), attr02Token.getTokenValue());
}
use of org.apache.cayenne.dbsync.merge.token.MergerToken in project cayenne by apache.
the class DataMapMergerTest method testAttributeNameUppercaseRelationship.
@Test
public void testAttributeNameUppercaseRelationship() 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().primaryKey(), dbAttr("attr03").typeInt().primaryKey())).join("rel", "table1.ATTR01", "table2.attr01").build();
DataMap db = dataMap().with(dbEntity("table1").attributes(dbAttr("attr01").typeInt(), dbAttr("attr02").typeInt()), dbEntity("table2").attributes(dbAttr("attr01").typeInt().primaryKey(), dbAttr("attr02").typeInt().primaryKey(), dbAttr("attr03").typeInt().primaryKey())).join("rel", "table1.attr01", "table2.attr01").build();
List<MergerToken> tokens = dbMerger().createMergeTokens(existing, db);
assertEquals(0, tokens.size());
}
use of org.apache.cayenne.dbsync.merge.token.MergerToken in project cayenne by apache.
the class DataMapMergerTest method testAddRelationship.
@Test
public void testAddRelationship() 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())).join("rel", "table1.attr01", "table2.attr01").build();
DataMap db = dataMap().with(dbEntity("table1").attributes(dbAttr("attr01").typeInt(), dbAttr("attr02").typeInt()), dbEntity("table2").attributes(dbAttr("attr01").typeInt().primaryKey(), dbAttr("attr02").typeInt())).build();
List<MergerToken> tokens = dbMerger().createMergeTokens(existing, db);
assertEquals(1, tokens.size());
DbEntity entity = existing.getDbEntity("table1");
assertEquals(factory().createAddRelationshipToDb(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 DataMapMergerTest method testTableNameUppercaseRelationship.
@Test
public void testTableNameUppercaseRelationship() 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().primaryKey(), dbAttr("attr03").typeInt().primaryKey())).join("rel", "TABLE1.attr01", "table2.attr01").build();
DataMap db = dataMap().with(dbEntity("table1").attributes(dbAttr("attr01").typeInt(), dbAttr("attr02").typeInt()), dbEntity("table2").attributes(dbAttr("attr01").typeInt().primaryKey(), dbAttr("attr02").typeInt().primaryKey(), dbAttr("attr03").typeInt().primaryKey())).join("rel", "table1.attr01", "table2.attr01").build();
List<MergerToken> tokens = dbMerger().createMergeTokens(existing, db);
assertEquals(0, tokens.size());
}
use of org.apache.cayenne.dbsync.merge.token.MergerToken in project cayenne by apache.
the class MergeCase method createMergeTokens.
protected List<MergerToken> createMergeTokens(String tableFilterInclude) {
FiltersConfig filters = FiltersConfig.create(null, null, TableFilter.include(tableFilterInclude), PatternFilter.INCLUDE_NOTHING);
DbLoaderConfiguration loaderConfiguration = new DbLoaderConfiguration();
loaderConfiguration.setFiltersConfig(filters);
DataMap dbImport;
try (Connection conn = node.getDataSource().getConnection()) {
dbImport = new DbLoader(node.getAdapter(), conn, loaderConfiguration, new LoggingDbLoaderDelegate(LoggerFactory.getLogger(DbLoader.class)), new DefaultObjectNameGenerator(NoStemStemmer.getInstance())).load();
} catch (SQLException e) {
throw new CayenneRuntimeException("Can't doLoad dataMap from db.", e);
}
List<MergerToken> tokens = merger().filters(filters).build().createMergeTokens(map, dbImport);
return filter(tokens);
}
Aggregations