Search in sources :

Example 16 with DataNode

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

the class BatchActionIT method testHasGeneratedKeys2.

@Test
public void testHasGeneratedKeys2() throws Exception {
    EntityResolver resolver = runtime.getChannel().getEntityResolver();
    // test with adapter that does not support keys...
    JdbcAdapter adapter = buildAdapter(false);
    DataNode node = new DataNode();
    node.setAdapter(adapter);
    node.setEntityResolver(resolver);
    node.setRowReaderFactory(mock(RowReaderFactory.class));
    InsertBatchQuery batch2 = new InsertBatchQuery(resolver.getObjEntity(Artist.class).getDbEntity(), 5);
    assertFalse(new BatchAction(batch2, node, false).hasGeneratedKeys());
}
Also used : JdbcAdapter(org.apache.cayenne.dba.JdbcAdapter) InsertBatchQuery(org.apache.cayenne.query.InsertBatchQuery) DataNode(org.apache.cayenne.access.DataNode) RowReaderFactory(org.apache.cayenne.access.jdbc.reader.RowReaderFactory) EntityResolver(org.apache.cayenne.map.EntityResolver) Test(org.junit.Test)

Example 17 with DataNode

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

the class SchemaBuilder method initNode.

private void initNode(DataMap map) throws Exception {
    DataNode node = new DataNode(map.getName());
    node.setJdbcEventLogger(jdbcEventLogger);
    node.setAdapter(dbAdapter);
    node.setDataSource(dataSourceFactory.getSharedDataSource());
    // setup test extended types
    node.getAdapter().getExtendedTypes().registerType(new StringET1ExtendedType());
    // tweak mapping with a delegate
    for (Procedure proc : map.getProcedures()) {
        unitDbAdapter.tweakProcedure(proc);
    }
    filterDataMap(map);
    node.addDataMap(map);
    node.setSchemaUpdateStrategy(new SkipSchemaUpdateStrategy());
    node.setRowReaderFactory(new DefaultRowReaderFactory());
    node.setBatchTranslatorFactory(new DefaultBatchTranslatorFactory());
    node.setSelectTranslatorFactory(new DefaultSelectTranslatorFactory());
    domain.addNode(node);
}
Also used : DefaultRowReaderFactory(org.apache.cayenne.access.jdbc.reader.DefaultRowReaderFactory) SkipSchemaUpdateStrategy(org.apache.cayenne.access.dbsync.SkipSchemaUpdateStrategy) DefaultSelectTranslatorFactory(org.apache.cayenne.access.translator.select.DefaultSelectTranslatorFactory) DataNode(org.apache.cayenne.access.DataNode) StringET1ExtendedType(org.apache.cayenne.testdo.extended_type.StringET1ExtendedType) Procedure(org.apache.cayenne.map.Procedure) DefaultBatchTranslatorFactory(org.apache.cayenne.access.translator.batch.DefaultBatchTranslatorFactory)

Example 18 with DataNode

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

the class ServerCaseDataNodeFactory method createDataNode.

@Override
public DataNode createDataNode(DataNodeDescriptor nodeDescriptor) throws Exception {
    DataNode dataNode = new DataNode(nodeDescriptor.getName());
    dataNode.setJdbcEventLogger(jdbcEventLogger);
    dataNode.setRowReaderFactory(rowReaderFactory);
    dataNode.setBatchTranslatorFactory(batchTranslatorFactory);
    dataNode.setSelectTranslatorFactory(selectTranslatorFactory);
    // shared or dedicated DataSources can be mapped per DataMap
    dataNode.setDataSource(dataSourceFactory.getDataSource(nodeDescriptor.getName()));
    dataNode.setAdapter(adapter);
    dataNode.setSchemaUpdateStrategy(new SkipSchemaUpdateStrategy());
    dataNode.setSqlTemplateProcessor(sqlTemplateProcessor);
    return dataNode;
}
Also used : SkipSchemaUpdateStrategy(org.apache.cayenne.access.dbsync.SkipSchemaUpdateStrategy) DataNode(org.apache.cayenne.access.DataNode)

Example 19 with DataNode

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

the class DataDomainProvider method addDataNode.

/**
 * @since 4.0
 */
protected DataNode addDataNode(DataDomain dataDomain, DataNodeDescriptor nodeDescriptor) throws Exception {
    DataNode dataNode = dataNodeFactory.createDataNode(nodeDescriptor);
    // DataMaps
    for (String dataMapName : nodeDescriptor.getDataMapNames()) {
        dataNode.addDataMap(dataDomain.getDataMap(dataMapName));
    }
    dataDomain.addNode(dataNode);
    return dataNode;
}
Also used : DataNode(org.apache.cayenne.access.DataNode)

Example 20 with DataNode

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

the class DataDomainProvider method createAndInitDataDomain.

protected DataDomain createAndInitDataDomain() throws Exception {
    DataChannelDescriptor descriptor = loadDescriptor();
    DataDomain dataDomain = createDataDomain(descriptor.getName());
    dataDomain.setMaxIdQualifierSize(runtimeProperties.getInt(Constants.SERVER_MAX_ID_QUALIFIER_SIZE_PROPERTY, -1));
    dataDomain.setQueryCache(new NestedQueryCache(queryCache));
    dataDomain.setEntitySorter(injector.getInstance(EntitySorter.class));
    dataDomain.setEventManager(injector.getInstance(EventManager.class));
    dataDomain.setDataRowStoreFactory(injector.getInstance(DataRowStoreFactory.class));
    dataDomain.initWithProperties(descriptor.getProperties());
    for (DataMap dataMap : descriptor.getDataMaps()) {
        dataDomain.addDataMap(dataMap);
    }
    dataDomain.getEntityResolver().applyDBLayerDefaults();
    dataDomain.getEntityResolver().setValueObjectTypeRegistry(valueObjectTypeRegistry);
    for (DataNodeDescriptor nodeDescriptor : descriptor.getNodeDescriptors()) {
        addDataNode(dataDomain, nodeDescriptor);
    }
    // init default node
    DataNode defaultNode = null;
    if (descriptor.getDefaultNodeName() != null) {
        defaultNode = dataDomain.getDataNode(descriptor.getDefaultNodeName());
    }
    if (defaultNode == null) {
        Collection<DataNode> allNodes = dataDomain.getDataNodes();
        if (allNodes.size() == 1) {
            defaultNode = allNodes.iterator().next();
        }
    }
    if (defaultNode != null) {
        logger.info("setting DataNode '" + defaultNode.getName() + "' as default, used by all unlinked DataMaps");
        dataDomain.setDefaultNode(defaultNode);
    }
    for (DataChannelFilter filter : filters) {
        dataDomain.addFilter(filter);
    }
    for (Object listener : listeners) {
        dataDomain.addListener(listener);
    }
    return dataDomain;
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) DataDomain(org.apache.cayenne.access.DataDomain) EntitySorter(org.apache.cayenne.map.EntitySorter) DataChannelFilter(org.apache.cayenne.DataChannelFilter) EventManager(org.apache.cayenne.event.EventManager) NestedQueryCache(org.apache.cayenne.cache.NestedQueryCache) DataNode(org.apache.cayenne.access.DataNode) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) DataRowStoreFactory(org.apache.cayenne.access.DataRowStoreFactory) DataMap(org.apache.cayenne.map.DataMap)

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