Search in sources :

Example 1 with DefaultMergerTokenFactory

use of org.apache.cayenne.dbsync.merge.factory.DefaultMergerTokenFactory in project cayenne by apache.

the class TokensToModelExecutionTest method testCreateAndDropTable.

@Test
public void testCreateAndDropTable() throws Exception {
    DbEntity entity = dbEntity().build();
    DataMap dataMap = dataMap().build();
    assertTrue(dataMap.getDbEntityMap().isEmpty());
    assertTrue(dataMap.getObjEntityMap().isEmpty());
    MergerContext context = MergerContext.builder(dataMap).dataNode(new DataNode()).build();
    new DefaultMergerTokenFactory().createCreateTableToModel(entity).execute(context);
    assertEquals(1, dataMap.getDbEntityMap().size());
    assertEquals(1, dataMap.getObjEntities().size());
    assertEquals(entity, dataMap.getDbEntity(entity.getName()));
    new DefaultMergerTokenFactory().createDropTableToModel(entity).execute(context);
    assertTrue(dataMap.getDbEntityMap().isEmpty());
    assertTrue(dataMap.getObjEntityMap().isEmpty());
}
Also used : DbEntity(org.apache.cayenne.map.DbEntity) DataNode(org.apache.cayenne.access.DataNode) DefaultMergerTokenFactory(org.apache.cayenne.dbsync.merge.factory.DefaultMergerTokenFactory) MergerContext(org.apache.cayenne.dbsync.merge.context.MergerContext) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Example 2 with DefaultMergerTokenFactory

use of org.apache.cayenne.dbsync.merge.factory.DefaultMergerTokenFactory in project cayenne by apache.

the class DefaultDbImportActionTest method buildDbImportAction.

private DefaultDbImportAction buildDbImportAction(FileProjectSaver projectSaver, DataMapLoader mapLoader, final DbLoader dbLoader) throws Exception {
    Logger log = mock(Logger.class);
    when(log.isDebugEnabled()).thenReturn(true);
    when(log.isInfoEnabled()).thenReturn(true);
    DbAdapter dbAdapter = mock(DbAdapter.class);
    DbAdapterFactory adapterFactory = mock(DbAdapterFactory.class);
    when(adapterFactory.createAdapter((DataNodeDescriptor) any(), (DataSource) any())).thenReturn(dbAdapter);
    DataSourceFactory dataSourceFactory = mock(DataSourceFactory.class);
    DataSource mock = mock(DataSource.class);
    when(dataSourceFactory.getDataSource((DataNodeDescriptor) any())).thenReturn(mock);
    DataChannelMetaData metaData = mock(DataChannelMetaData.class);
    MergerTokenFactoryProvider mergerTokenFactoryProvider = mock(MergerTokenFactoryProvider.class);
    when(mergerTokenFactoryProvider.get((DbAdapter) any())).thenReturn(new DefaultMergerTokenFactory());
    DataChannelDescriptorLoader dataChannelDescriptorLoader = mock(DataChannelDescriptorLoader.class);
    return new DefaultDbImportAction(log, projectSaver, dataSourceFactory, adapterFactory, mapLoader, mergerTokenFactoryProvider, dataChannelDescriptorLoader, metaData) {

        protected DbLoader createDbLoader(DbAdapter adapter, Connection connection, DbImportConfiguration config) {
            return dbLoader;
        }
    };
}
Also used : DbAdapterFactory(org.apache.cayenne.configuration.server.DbAdapterFactory) DataSourceFactory(org.apache.cayenne.configuration.server.DataSourceFactory) DbAdapter(org.apache.cayenne.dba.DbAdapter) DataChannelMetaData(org.apache.cayenne.configuration.xml.DataChannelMetaData) DefaultMergerTokenFactory(org.apache.cayenne.dbsync.merge.factory.DefaultMergerTokenFactory) DataChannelDescriptorLoader(org.apache.cayenne.configuration.DataChannelDescriptorLoader) Connection(java.sql.Connection) Logger(org.slf4j.Logger) MergerTokenFactoryProvider(org.apache.cayenne.dbsync.merge.factory.MergerTokenFactoryProvider) DataSource(javax.sql.DataSource)

Example 3 with DefaultMergerTokenFactory

use of org.apache.cayenne.dbsync.merge.factory.DefaultMergerTokenFactory in project cayenne by apache.

the class TokensToModelExecutionTest method testCreateAndDropColumn.

@Test
public void testCreateAndDropColumn() throws Exception {
    DbAttribute attr = dbAttr("attr").build();
    DbEntity entity = dbEntity().build();
    DataMap dataMap = dataMap().with(entity).build();
    assertEquals(1, dataMap.getDbEntityMap().size());
    assertTrue(dataMap.getObjEntityMap().isEmpty());
    MergerContext context = MergerContext.builder(dataMap).dataNode(new DataNode()).build();
    new DefaultMergerTokenFactory().createAddColumnToModel(entity, attr).execute(context);
    assertEquals(1, dataMap.getDbEntityMap().size());
    assertEquals(1, entity.getAttributes().size());
    assertEquals(attr, entity.getAttribute(attr.getName()));
    new DefaultMergerTokenFactory().createDropColumnToModel(entity, attr).execute(context);
    assertEquals(1, dataMap.getDbEntityMap().size());
    assertTrue(entity.getAttributes().isEmpty());
    assertTrue(dataMap.getObjEntityMap().isEmpty());
}
Also used : DbEntity(org.apache.cayenne.map.DbEntity) DataNode(org.apache.cayenne.access.DataNode) DefaultMergerTokenFactory(org.apache.cayenne.dbsync.merge.factory.DefaultMergerTokenFactory) DbAttribute(org.apache.cayenne.map.DbAttribute) MergerContext(org.apache.cayenne.dbsync.merge.context.MergerContext) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Aggregations

DefaultMergerTokenFactory (org.apache.cayenne.dbsync.merge.factory.DefaultMergerTokenFactory)3 DataNode (org.apache.cayenne.access.DataNode)2 MergerContext (org.apache.cayenne.dbsync.merge.context.MergerContext)2 DataMap (org.apache.cayenne.map.DataMap)2 DbEntity (org.apache.cayenne.map.DbEntity)2 Test (org.junit.Test)2 Connection (java.sql.Connection)1 DataSource (javax.sql.DataSource)1 DataChannelDescriptorLoader (org.apache.cayenne.configuration.DataChannelDescriptorLoader)1 DataSourceFactory (org.apache.cayenne.configuration.server.DataSourceFactory)1 DbAdapterFactory (org.apache.cayenne.configuration.server.DbAdapterFactory)1 DataChannelMetaData (org.apache.cayenne.configuration.xml.DataChannelMetaData)1 DbAdapter (org.apache.cayenne.dba.DbAdapter)1 MergerTokenFactoryProvider (org.apache.cayenne.dbsync.merge.factory.MergerTokenFactoryProvider)1 DbAttribute (org.apache.cayenne.map.DbAttribute)1 Logger (org.slf4j.Logger)1