Search in sources :

Example 1 with DropRelationshipToDb

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

the class OpenBaseMergerTokenFactory method createDropRelationshipToDb.

@Override
public MergerToken createDropRelationshipToDb(final DbEntity entity, final DbRelationship rel) {
    return new DropRelationshipToDb(entity, rel) {

        @Override
        public List<String> createSql(DbAdapter adapter) {
            // FK_NAME form jdbc metadata seem to be wrong. It contain a column name
            // and not the 'relationshipName'
            // TODO: tell openbase developer mail list
            DbEntity source = getEntity();
            DbEntity dest = rel.getTargetEntity();
            // only use the first. See adapter
            // TODO: can we be sure this is the first and same as used by the adapter?
            DbJoin join = rel.getJoins().get(0);
            return Collections.singletonList("delete from _SYS_RELATIONSHIP where " + " source_table = '" + dest.getFullyQualifiedName() + "'" + " and source_column = '" + join.getTargetName() + "'" + " and dest_table = '" + source.getFullyQualifiedName() + "'" + " and dest_column = '" + join.getSourceName() + "'");
        }
    };
}
Also used : DbAdapter(org.apache.cayenne.dba.DbAdapter) DbEntity(org.apache.cayenne.map.DbEntity) DropRelationshipToDb(org.apache.cayenne.dbsync.merge.token.db.DropRelationshipToDb) DbJoin(org.apache.cayenne.map.DbJoin)

Example 2 with DropRelationshipToDb

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

the class MySQLMergerTokenFactory method createDropRelationshipToDb.

@Override
public MergerToken createDropRelationshipToDb(final DbEntity entity, DbRelationship rel) {
    return new DropRelationshipToDb(entity, rel) {

        @Override
        public List<String> createSql(DbAdapter adapter) {
            String fkName = getFkName();
            if (fkName == null) {
                return Collections.emptyList();
            }
            QuotingStrategy context = adapter.getQuotingStrategy();
            // http://dev.mysql.com/tech-resources/articles/mysql-cluster-50.html
            return Collections.singletonList("ALTER TABLE " + context.quotedFullyQualifiedName(entity) + " DROP FOREIGN KEY " + fkName);
        }
    };
}
Also used : DbAdapter(org.apache.cayenne.dba.DbAdapter) DropRelationshipToDb(org.apache.cayenne.dbsync.merge.token.db.DropRelationshipToDb) QuotingStrategy(org.apache.cayenne.dba.QuotingStrategy)

Example 3 with DropRelationshipToDb

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

the class TokenSortTest method testToDbTokensCompare.

@Test
public void testToDbTokensCompare() throws Exception {
    List<MergerToken> tokens = Arrays.<MergerToken>asList(new DropColumnToDb(null, null), new DropRelationshipToDb(null, null), new DropTableToDb(null), new AddColumnToModel(null, null), new AddRelationshipToDb(null, null), new AddColumnToDb(null, null), new CreateTableToDb(null));
    Collections.sort(tokens);
    List<String> actual = toClassesNames(tokens);
    List<String> expected = Arrays.asList("DropRelationshipToDb", "DropColumnToDb", "DropTableToDb", "CreateTableToDb", "AddColumnToDb", "AddColumnToModel", "AddRelationshipToDb");
    assertEquals(expected, actual);
}
Also used : AddColumnToDb(org.apache.cayenne.dbsync.merge.token.db.AddColumnToDb) CreateTableToDb(org.apache.cayenne.dbsync.merge.token.db.CreateTableToDb) DropColumnToDb(org.apache.cayenne.dbsync.merge.token.db.DropColumnToDb) AddRelationshipToDb(org.apache.cayenne.dbsync.merge.token.db.AddRelationshipToDb) DropTableToDb(org.apache.cayenne.dbsync.merge.token.db.DropTableToDb) DropRelationshipToDb(org.apache.cayenne.dbsync.merge.token.db.DropRelationshipToDb) AddColumnToModel(org.apache.cayenne.dbsync.merge.token.model.AddColumnToModel) Test(org.junit.Test)

Aggregations

DropRelationshipToDb (org.apache.cayenne.dbsync.merge.token.db.DropRelationshipToDb)3 DbAdapter (org.apache.cayenne.dba.DbAdapter)2 QuotingStrategy (org.apache.cayenne.dba.QuotingStrategy)1 AddColumnToDb (org.apache.cayenne.dbsync.merge.token.db.AddColumnToDb)1 AddRelationshipToDb (org.apache.cayenne.dbsync.merge.token.db.AddRelationshipToDb)1 CreateTableToDb (org.apache.cayenne.dbsync.merge.token.db.CreateTableToDb)1 DropColumnToDb (org.apache.cayenne.dbsync.merge.token.db.DropColumnToDb)1 DropTableToDb (org.apache.cayenne.dbsync.merge.token.db.DropTableToDb)1 AddColumnToModel (org.apache.cayenne.dbsync.merge.token.model.AddColumnToModel)1 DbEntity (org.apache.cayenne.map.DbEntity)1 DbJoin (org.apache.cayenne.map.DbJoin)1 Test (org.junit.Test)1