Search in sources :

Example 1 with AddColumnToDb

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

the class SybaseMergerTokenFactory method createAddColumnToDb.

/**
 * @since 3.0
 */
@Override
public MergerToken createAddColumnToDb(DbEntity entity, final DbAttribute column) {
    return new AddColumnToDb(entity, column) {

        @Override
        public List<String> createSql(DbAdapter adapter) {
            StringBuffer sqlBuffer = new StringBuffer();
            QuotingStrategy context = adapter.getQuotingStrategy();
            sqlBuffer.append("ALTER TABLE ");
            sqlBuffer.append(context.quotedFullyQualifiedName(getEntity()));
            sqlBuffer.append(" ADD ");
            boolean magnatory = column.isMandatory();
            column.setMandatory(false);
            adapter.createTableAppendColumn(sqlBuffer, column);
            if (magnatory) {
                column.setMandatory(magnatory);
            }
            return Collections.singletonList(sqlBuffer.toString());
        }
    };
}
Also used : AddColumnToDb(org.apache.cayenne.dbsync.merge.token.db.AddColumnToDb) DbAdapter(org.apache.cayenne.dba.DbAdapter) QuotingStrategy(org.apache.cayenne.dba.QuotingStrategy)

Example 2 with AddColumnToDb

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

the class TokenSortTest method testToModelTokensCompare.

@Test
public void testToModelTokensCompare() throws Exception {
    List<MergerToken> tokens = Arrays.<MergerToken>asList(new DropColumnToModel(null, null), new DropRelationshipToModel(null, null), new DropTableToModel(null), new AddColumnToDb(null, null), new AddRelationshipToModel(null, null), new AddColumnToModel(null, null), new CreateTableToModel(null));
    Collections.sort(tokens);
    List<String> actual = toClassesNames(tokens);
    List<String> expected = Arrays.asList("DropRelationshipToModel", "DropColumnToModel", "DropTableToModel", "CreateTableToModel", "AddColumnToDb", "AddColumnToModel", "AddRelationshipToModel");
    assertEquals(expected, actual);
}
Also used : AddColumnToDb(org.apache.cayenne.dbsync.merge.token.db.AddColumnToDb) DropTableToModel(org.apache.cayenne.dbsync.merge.token.model.DropTableToModel) CreateTableToModel(org.apache.cayenne.dbsync.merge.token.model.CreateTableToModel) DropRelationshipToModel(org.apache.cayenne.dbsync.merge.token.model.DropRelationshipToModel) AddRelationshipToModel(org.apache.cayenne.dbsync.merge.token.model.AddRelationshipToModel) AddColumnToModel(org.apache.cayenne.dbsync.merge.token.model.AddColumnToModel) DropColumnToModel(org.apache.cayenne.dbsync.merge.token.model.DropColumnToModel) Test(org.junit.Test)

Example 3 with AddColumnToDb

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

the class TokenSortTest method testSortStability.

@Test
public void testSortStability() throws Exception {
    List<MergerToken> tokens = Arrays.<MergerToken>asList(new AddRelationshipToModel(null, null), new AddColumnToModel(null, null), new AddColumnToDb(null, null), new CreateTableToModel(null), new DropTableToModel(null), new DropColumnToModel(null, null), new DropRelationshipToModel(null, null));
    Collections.sort(tokens);
    List<String> actual = toClassesNames(tokens);
    List<String> expected = Arrays.asList("DropRelationshipToModel", "DropColumnToModel", "DropTableToModel", "CreateTableToModel", "AddColumnToDb", "AddColumnToModel", "AddRelationshipToModel");
    assertEquals(expected, actual);
    Collections.sort(tokens);
    actual = toClassesNames(tokens);
    assertEquals(expected, actual);
    List<MergerToken> tokens2 = Arrays.<MergerToken>asList(new AddColumnToModel(null, null), new AddRelationshipToModel(null, null), new CreateTableToModel(null), new AddColumnToDb(null, null), new DropColumnToModel(null, null), new DropRelationshipToModel(null, null), new DropTableToModel(null));
    Collections.sort(tokens2);
    actual = toClassesNames(tokens);
    assertEquals(expected, actual);
}
Also used : AddColumnToDb(org.apache.cayenne.dbsync.merge.token.db.AddColumnToDb) CreateTableToModel(org.apache.cayenne.dbsync.merge.token.model.CreateTableToModel) DropTableToModel(org.apache.cayenne.dbsync.merge.token.model.DropTableToModel) AddRelationshipToModel(org.apache.cayenne.dbsync.merge.token.model.AddRelationshipToModel) DropRelationshipToModel(org.apache.cayenne.dbsync.merge.token.model.DropRelationshipToModel) AddColumnToModel(org.apache.cayenne.dbsync.merge.token.model.AddColumnToModel) DropColumnToModel(org.apache.cayenne.dbsync.merge.token.model.DropColumnToModel) Test(org.junit.Test)

Example 4 with AddColumnToDb

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

AddColumnToDb (org.apache.cayenne.dbsync.merge.token.db.AddColumnToDb)4 AddColumnToModel (org.apache.cayenne.dbsync.merge.token.model.AddColumnToModel)3 Test (org.junit.Test)3 AddRelationshipToModel (org.apache.cayenne.dbsync.merge.token.model.AddRelationshipToModel)2 CreateTableToModel (org.apache.cayenne.dbsync.merge.token.model.CreateTableToModel)2 DropColumnToModel (org.apache.cayenne.dbsync.merge.token.model.DropColumnToModel)2 DropRelationshipToModel (org.apache.cayenne.dbsync.merge.token.model.DropRelationshipToModel)2 DropTableToModel (org.apache.cayenne.dbsync.merge.token.model.DropTableToModel)2 DbAdapter (org.apache.cayenne.dba.DbAdapter)1 QuotingStrategy (org.apache.cayenne.dba.QuotingStrategy)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 DropRelationshipToDb (org.apache.cayenne.dbsync.merge.token.db.DropRelationshipToDb)1 DropTableToDb (org.apache.cayenne.dbsync.merge.token.db.DropTableToDb)1