Search in sources :

Example 21 with DataNode

use of org.apache.cayenne.access.DataNode in project cayenne by apache.

the class SyntheticNodeDataDomainProvider method createAndInitDataDomain.

@Override
protected DataDomain createAndInitDataDomain() throws Exception {
    DataDomain dataDomain = super.createAndInitDataDomain();
    // no nodes... add a synthetic node... it will become the default
    if (dataDomain.getDataNodes().isEmpty()) {
        DataChannelDescriptor channelDescriptor = new DataChannelDescriptor();
        DataNodeDescriptor nodeDescriptor = new DataNodeDescriptor(createSyntheticDataNodeName(dataDomain));
        for (DataMap map : dataDomain.getDataMaps()) {
            nodeDescriptor.getDataMapNames().add(map.getName());
        }
        nodeDescriptor.setDataChannelDescriptor(channelDescriptor);
        DataNode node = addDataNode(dataDomain, nodeDescriptor);
        dataDomain.setDefaultNode(node);
    }
    return dataDomain;
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) DataDomain(org.apache.cayenne.access.DataDomain) DataNode(org.apache.cayenne.access.DataNode) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) DataMap(org.apache.cayenne.map.DataMap)

Example 22 with DataNode

use of org.apache.cayenne.access.DataNode in project cayenne by apache.

the class CreateTableToDb method execute.

@Override
public void execute(MergerContext mergerContext) {
    try {
        DataNode node = mergerContext.getDataNode();
        DbAdapter adapter = node.getAdapter();
        if (needAutoPkSupport()) {
            adapter.getPkGenerator().createAutoPk(node, Collections.singletonList(getEntity()));
        }
        executeSql(mergerContext, adapter.createTable(getEntity()));
    } catch (Exception e) {
        mergerContext.getValidationResult().addFailure(new SimpleValidationFailure(this, e.getMessage()));
    }
}
Also used : DbAdapter(org.apache.cayenne.dba.DbAdapter) SimpleValidationFailure(org.apache.cayenne.validation.SimpleValidationFailure) DataNode(org.apache.cayenne.access.DataNode)

Example 23 with DataNode

use of org.apache.cayenne.access.DataNode 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

DataNode (org.apache.cayenne.access.DataNode)23 Test (org.junit.Test)12 DataMap (org.apache.cayenne.map.DataMap)8 RowReaderFactory (org.apache.cayenne.access.jdbc.reader.RowReaderFactory)7 DataDomain (org.apache.cayenne.access.DataDomain)6 JdbcAdapter (org.apache.cayenne.dba.JdbcAdapter)6 EntityResolver (org.apache.cayenne.map.EntityResolver)6 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)4 DbEntity (org.apache.cayenne.map.DbEntity)4 InsertBatchQuery (org.apache.cayenne.query.InsertBatchQuery)4 SkipSchemaUpdateStrategy (org.apache.cayenne.access.dbsync.SkipSchemaUpdateStrategy)3 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)3 PreparedStatementResultSetHandler (com.mockrunner.jdbc.PreparedStatementResultSetHandler)2 MockConnection (com.mockrunner.mock.jdbc.MockConnection)2 HashMap (java.util.HashMap)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 DataRowStoreFactory (org.apache.cayenne.access.DataRowStoreFactory)2 MockOperationObserver (org.apache.cayenne.access.MockOperationObserver)2 DefaultBatchTranslatorFactory (org.apache.cayenne.access.translator.batch.DefaultBatchTranslatorFactory)2 DeleteBatchTranslator (org.apache.cayenne.access.translator.batch.DeleteBatchTranslator)2