Search in sources :

Example 26 with MergerToken

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

the class DataMapMergerTest method testChangeColumnTypeSimple.

@Test
public void testChangeColumnTypeSimple() throws Exception {
    DataMap existing = dataMap().with(dbEntity("table1").attributes(dbAttr("attr01").typeInt())).build();
    DataMap db = dataMap().with(dbEntity("table1").attributes(dbAttr("attr01").typeVarchar(30))).build();
    List<MergerToken> tokens = dbMerger().createMergeTokens(existing, db);
    assertEquals(1, tokens.size());
    DbEntity entity = existing.getDbEntity("table1");
    DbEntity entityDb = db.getDbEntity("table1");
    assertTrue(tokens.get(0) instanceof SetColumnTypeToDb);
    assertEquals(factory().createSetColumnTypeToDb(entity, entityDb.getAttribute("attr01"), entity.getAttribute("attr01")).getTokenValue(), tokens.get(0).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 27 with MergerToken

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

the class DataMapMergerTest method testRemoveTable.

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

Example 28 with MergerToken

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

the class DataMapMergerTest method testDropPrimaryKey.

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

Example 29 with MergerToken

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

the class DataMapMergerTest method testChangeGeneratedStatus.

@Test
public void testChangeGeneratedStatus() {
    DataMap existing = dataMap().with(dbEntity("table1").attributes(dbAttr("attr01").typeVarchar(10))).build();
    DataMap db = dataMap().with(dbEntity("table1").attributes(dbAttr("attr01").typeInt().generated())).build();
    List<MergerToken> tokens = dbMerger().createMergeTokens(existing, db);
    assertEquals(2, tokens.size());
}
Also used : MergerToken(org.apache.cayenne.dbsync.merge.token.MergerToken) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Example 30 with MergerToken

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

the class DataMapMergerTest method testRemoveColumn.

@Test
public void testRemoveColumn() throws Exception {
    DataMap existing = dataMap().with(dbEntity("table1").attributes(dbAttr("attr01").typeInt())).build();
    DataMap db = dataMap().with(dbEntity("table1").attributes(dbAttr("attr01").typeInt(), dbAttr("attr02").typeInt())).build();
    List<MergerToken> tokens = dbMerger().createMergeTokens(existing, db);
    assertEquals(1, tokens.size());
    DbEntity entity = db.getDbEntity("table1");
    assertEquals(factory().createDropColumnToModel(entity, entity.getAttribute("attr02")).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)

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