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() + "'");
}
};
}
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);
}
};
}
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);
}
Aggregations