Search in sources :

Example 36 with MergerToken

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);
}
Also used : MergerToken(org.apache.cayenne.dbsync.merge.token.MergerToken)

Example 37 with MergerToken

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;
}
Also used : MergerToken(org.apache.cayenne.dbsync.merge.token.MergerToken) ArrayList(java.util.ArrayList) SetColumnTypeToDb(org.apache.cayenne.dbsync.merge.token.db.SetColumnTypeToDb)

Example 38 with MergerToken

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;
}
Also used : DbRelationship(org.apache.cayenne.map.DbRelationship) MergerToken(org.apache.cayenne.dbsync.merge.token.MergerToken) LinkedList(java.util.LinkedList)

Example 39 with MergerToken

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();
}
Also used : MergerToken(org.apache.cayenne.dbsync.merge.token.MergerToken) AbstractToDbToken(org.apache.cayenne.dbsync.merge.token.db.AbstractToDbToken)

Example 40 with MergerToken

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();
}
Also used : MergerToken(org.apache.cayenne.dbsync.merge.token.MergerToken)

Aggregations

MergerToken (org.apache.cayenne.dbsync.merge.token.MergerToken)41 Test (org.junit.Test)25 DbEntity (org.apache.cayenne.map.DbEntity)20 DataMap (org.apache.cayenne.map.DataMap)17 DbAttribute (org.apache.cayenne.map.DbAttribute)10 ObjEntity (org.apache.cayenne.map.ObjEntity)8 LinkedList (java.util.LinkedList)5 ObjAttribute (org.apache.cayenne.map.ObjAttribute)5 SetColumnTypeToDb (org.apache.cayenne.dbsync.merge.token.db.SetColumnTypeToDb)4 DbJoin (org.apache.cayenne.map.DbJoin)3 DbRelationship (org.apache.cayenne.map.DbRelationship)3 Connection (java.sql.Connection)2 SQLException (java.sql.SQLException)2 DataSource (javax.sql.DataSource)2 MergerContext (org.apache.cayenne.dbsync.merge.context.MergerContext)2 DbLoaderConfiguration (org.apache.cayenne.dbsync.reverse.dbload.DbLoaderConfiguration)2 ObjRelationship (org.apache.cayenne.map.ObjRelationship)2 ArrayList (java.util.ArrayList)1 AbstractTableModel (javax.swing.table.AbstractTableModel)1 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)1