use of org.apache.cayenne.dbsync.merge.token.MergerToken in project cayenne by apache.
the class MergeCase method assertTokens.
protected void assertTokens(List<MergerToken> tokens, int expectedToDb, int expectedToModel) {
int actualToDb = 0;
int actualToModel = 0;
for (MergerToken token : tokens) {
if (token.getDirection().isToDb()) {
actualToDb++;
} else if (token.getDirection().isToModel()) {
actualToModel++;
}
}
assertEquals("tokens to db", expectedToDb, actualToDb);
assertEquals("tokens to model", expectedToModel, actualToModel);
}
use of org.apache.cayenne.dbsync.merge.token.MergerToken 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;
}
use of org.apache.cayenne.dbsync.merge.token.MergerToken in project cayenne by apache.
the class DbEntityMerger method createTokensForMissingImported.
/**
* Generate Create Table in model token
* @param original DbEntity found in model but not found in DB
*/
@Override
Collection<MergerToken> createTokensForMissingImported(DbEntity original) {
Collection<MergerToken> tokens = new LinkedList<>();
// add entity
tokens.add(getTokenFactory().createCreateTableToDb(original));
// add it's relationships
for (DbRelationship rel : original.getRelationships()) {
tokens.add(getTokenFactory().createAddRelationshipToDb(original, rel));
}
return tokens;
}
use of org.apache.cayenne.dbsync.merge.token.MergerToken in project cayenne by apache.
the class MergerOptions method createSQL.
/**
* Returns SQL statements generated for selected schema generation options.
*/
protected void createSQL() {
// convert them to string representation for display
StringBuilder buf = new StringBuilder();
Iterator<MergerToken> it = tokens.getSelectedTokens().iterator();
String batchTerminator = adapter.getBatchTerminator();
String lineEnd = batchTerminator != null ? "\n" + batchTerminator + "\n\n" : "\n\n";
while (it.hasNext()) {
MergerToken token = it.next();
if (token instanceof AbstractToDbToken) {
AbstractToDbToken tdb = (AbstractToDbToken) token;
for (String sql : tdb.createSql(adapter)) {
buf.append(sql);
buf.append(lineEnd);
}
}
}
textForSQL = buf.toString();
}
use of org.apache.cayenne.dbsync.merge.token.MergerToken in project cayenne by apache.
the class MergerTokenSelectorController method setDirection.
public void setDirection(MergerToken token, MergeDirection direction) {
if (token.getDirection().equals(direction)) {
return;
}
int i = selectableTokensList.indexOf(token);
MergerToken reverse = token.createReverse(mergerTokenFactory);
selectableTokensList.set(i, reverse);
if (excludedTokens.remove(token)) {
excludedTokens.add(reverse);
}
// Repaint, so that "Operation" column updates properly
view.getTokens().repaint();
}
Aggregations