Search in sources :

Example 1 with AbstractToDbToken

use of org.apache.cayenne.dbsync.merge.token.db.AbstractToDbToken in project cayenne by apache.

the class MergeCase method dropTableIfPresent.

protected void dropTableIfPresent(String tableName) throws Exception {
    // must have a dummy datamap for the dummy table for the downstream code
    // to work
    DataMap map = new DataMap("dummy");
    map.setQuotingSQLIdentifiers(map.isQuotingSQLIdentifiers());
    DbEntity entity = new DbEntity(tableName);
    map.addDbEntity(entity);
    AbstractToDbToken t = (AbstractToDbToken) mergerFactory().createDropTableToDb(entity);
    for (String sql : t.createSql(node.getAdapter())) {
        try {
            executeSql(sql);
        } catch (Exception e) {
            logger.info("Exception dropping table " + tableName + ", probably abscent..");
        }
    }
}
Also used : DbEntity(org.apache.cayenne.map.DbEntity) AbstractToDbToken(org.apache.cayenne.dbsync.merge.token.db.AbstractToDbToken) SQLException(java.sql.SQLException) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) DataMap(org.apache.cayenne.map.DataMap)

Example 2 with AbstractToDbToken

use of org.apache.cayenne.dbsync.merge.token.db.AbstractToDbToken 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)

Aggregations

AbstractToDbToken (org.apache.cayenne.dbsync.merge.token.db.AbstractToDbToken)2 SQLException (java.sql.SQLException)1 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)1 MergerToken (org.apache.cayenne.dbsync.merge.token.MergerToken)1 DataMap (org.apache.cayenne.map.DataMap)1 DbEntity (org.apache.cayenne.map.DbEntity)1