Search in sources :

Example 31 with MergerToken

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

the class DataMapMergerTest method testChangeColumnType.

/**
 * Test unsupported type changes
 */
@Test
public void testChangeColumnType() throws Exception {
    DbEntity fromModel = dbEntity("table1").attributes(dbAttr("attr01").typeInt(), dbAttr("attr02").type("DATE"), dbAttr("attr03").type("BOOLEAN"), dbAttr("attr04").type("FLOAT")).build();
    DataMap existing = dataMap().with(fromModel).build();
    DbEntity fromDb = dbEntity("table1").attributes(dbAttr("attr01").typeBigInt(), dbAttr("attr02").type("NUMERIC"), dbAttr("attr03").type("BLOB"), dbAttr("attr04").type("TIMESTAMP")).build();
    DataMap db = dataMap().with(fromDb).build();
    List<MergerToken> tokens = dbMerger().createMergeTokens(existing, db);
    assertEquals(4, tokens.size());
    for (MergerToken token : tokens) {
        assertTrue(token instanceof SetColumnTypeToDb);
    }
    MergerToken attr02Token = findChangeTypeToken(tokens, "attr02");
    assertNotNull(attr02Token);
    assertEquals(factory().createSetColumnTypeToDb(fromModel, fromDb.getAttribute("attr02"), fromModel.getAttribute("attr02")).getTokenValue(), attr02Token.getTokenValue());
}
Also used : DbEntity(org.apache.cayenne.map.DbEntity) MergerToken(org.apache.cayenne.dbsync.merge.token.MergerToken) SetColumnTypeToDb(org.apache.cayenne.dbsync.merge.token.db.SetColumnTypeToDb) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Example 32 with MergerToken

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

the class DataMapMergerTest method testAttributeNameUppercaseRelationship.

@Test
public void testAttributeNameUppercaseRelationship() throws Exception {
    DataMap existing = dataMap().with(dbEntity("table1").attributes(dbAttr("ATTR01").typeInt(), dbAttr("attr02").typeInt()), dbEntity("table2").attributes(dbAttr("attr01").typeInt().primaryKey(), dbAttr("attr02").typeInt().primaryKey(), dbAttr("attr03").typeInt().primaryKey())).join("rel", "table1.ATTR01", "table2.attr01").build();
    DataMap db = dataMap().with(dbEntity("table1").attributes(dbAttr("attr01").typeInt(), dbAttr("attr02").typeInt()), dbEntity("table2").attributes(dbAttr("attr01").typeInt().primaryKey(), dbAttr("attr02").typeInt().primaryKey(), dbAttr("attr03").typeInt().primaryKey())).join("rel", "table1.attr01", "table2.attr01").build();
    List<MergerToken> tokens = dbMerger().createMergeTokens(existing, db);
    assertEquals(0, tokens.size());
}
Also used : MergerToken(org.apache.cayenne.dbsync.merge.token.MergerToken) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Example 33 with MergerToken

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

the class DataMapMergerTest method testAddRelationship.

@Test
public void testAddRelationship() throws Exception {
    DataMap existing = dataMap().with(dbEntity("table1").attributes(dbAttr("attr01").typeInt(), dbAttr("attr02").typeInt()), dbEntity("table2").attributes(dbAttr("attr01").typeInt().primaryKey(), dbAttr("attr02").typeInt())).join("rel", "table1.attr01", "table2.attr01").build();
    DataMap db = dataMap().with(dbEntity("table1").attributes(dbAttr("attr01").typeInt(), dbAttr("attr02").typeInt()), dbEntity("table2").attributes(dbAttr("attr01").typeInt().primaryKey(), dbAttr("attr02").typeInt())).build();
    List<MergerToken> tokens = dbMerger().createMergeTokens(existing, db);
    assertEquals(1, tokens.size());
    DbEntity entity = existing.getDbEntity("table1");
    assertEquals(factory().createAddRelationshipToDb(entity, entity.getRelationship("rel")).getTokenValue(), tokens.get(0).getTokenValue());
}
Also used : DbEntity(org.apache.cayenne.map.DbEntity) MergerToken(org.apache.cayenne.dbsync.merge.token.MergerToken) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Example 34 with MergerToken

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

the class DataMapMergerTest method testTableNameUppercaseRelationship.

@Test
public void testTableNameUppercaseRelationship() throws Exception {
    DataMap existing = dataMap().with(dbEntity("TABLE1").attributes(dbAttr("attr01").typeInt(), dbAttr("attr02").typeInt()), dbEntity("table2").attributes(dbAttr("attr01").typeInt().primaryKey(), dbAttr("attr02").typeInt().primaryKey(), dbAttr("attr03").typeInt().primaryKey())).join("rel", "TABLE1.attr01", "table2.attr01").build();
    DataMap db = dataMap().with(dbEntity("table1").attributes(dbAttr("attr01").typeInt(), dbAttr("attr02").typeInt()), dbEntity("table2").attributes(dbAttr("attr01").typeInt().primaryKey(), dbAttr("attr02").typeInt().primaryKey(), dbAttr("attr03").typeInt().primaryKey())).join("rel", "table1.attr01", "table2.attr01").build();
    List<MergerToken> tokens = dbMerger().createMergeTokens(existing, db);
    assertEquals(0, tokens.size());
}
Also used : MergerToken(org.apache.cayenne.dbsync.merge.token.MergerToken) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Example 35 with MergerToken

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

the class MergeCase method createMergeTokens.

protected List<MergerToken> createMergeTokens(String tableFilterInclude) {
    FiltersConfig filters = FiltersConfig.create(null, null, TableFilter.include(tableFilterInclude), PatternFilter.INCLUDE_NOTHING);
    DbLoaderConfiguration loaderConfiguration = new DbLoaderConfiguration();
    loaderConfiguration.setFiltersConfig(filters);
    DataMap dbImport;
    try (Connection conn = node.getDataSource().getConnection()) {
        dbImport = new DbLoader(node.getAdapter(), conn, loaderConfiguration, new LoggingDbLoaderDelegate(LoggerFactory.getLogger(DbLoader.class)), new DefaultObjectNameGenerator(NoStemStemmer.getInstance())).load();
    } catch (SQLException e) {
        throw new CayenneRuntimeException("Can't doLoad dataMap from db.", e);
    }
    List<MergerToken> tokens = merger().filters(filters).build().createMergeTokens(map, dbImport);
    return filter(tokens);
}
Also used : LoggingDbLoaderDelegate(org.apache.cayenne.dbsync.reverse.dbload.LoggingDbLoaderDelegate) DefaultObjectNameGenerator(org.apache.cayenne.dbsync.naming.DefaultObjectNameGenerator) SQLException(java.sql.SQLException) FiltersConfig(org.apache.cayenne.dbsync.reverse.filters.FiltersConfig) Connection(java.sql.Connection) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) MergerToken(org.apache.cayenne.dbsync.merge.token.MergerToken) DbLoader(org.apache.cayenne.dbsync.reverse.dbload.DbLoader) DbLoaderConfiguration(org.apache.cayenne.dbsync.reverse.dbload.DbLoaderConfiguration) DataMap(org.apache.cayenne.map.DataMap)

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