use of org.apache.cayenne.dbsync.merge.token.db.SetColumnTypeToDb 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.db.SetColumnTypeToDb in project cayenne by apache.
the class DataMapMergerTest method testChangeColumnTypeSimple.
@Test
public void testChangeColumnTypeSimple() throws Exception {
DataMap existing = dataMap().with(dbEntity("table1").attributes(dbAttr("attr01").typeInt())).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.db.SetColumnTypeToDb 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.db.SetColumnTypeToDb in project cayenne by apache.
the class MergeCase method filterEmptyTypeChange.
/**
* Filter out tokens for db attribute type change when types is same for specific DB
*/
private List<MergerToken> filterEmptyTypeChange(List<MergerToken> tokens) {
List<MergerToken> tokensOut = new ArrayList<>();
for (MergerToken token : tokens) {
if (!(token instanceof SetColumnTypeToDb)) {
tokensOut.add(token);
continue;
}
SetColumnTypeToDb setColumnToDb = (SetColumnTypeToDb) token;
int toType = setColumnToDb.getColumnNew().getType();
int fromType = setColumnToDb.getColumnOriginal().getType();
// filter out conversions between date/time types
if (accessStackAdapter.onlyGenericDateType()) {
if (isDateTimeType(toType) && isDateTimeType(fromType)) {
continue;
}
}
// filter out conversions between numeric types
if (accessStackAdapter.onlyGenericNumberType()) {
if (TypesMapping.isNumeric(toType) && TypesMapping.isNumeric(fromType)) {
continue;
}
}
tokensOut.add(token);
}
return tokensOut;
}
Aggregations