Search in sources :

Example 6 with DataNode

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

the class BatchActionLockingIT method testRunAsIndividualQueriesSuccess.

@Test
public void testRunAsIndividualQueriesSuccess() throws Exception {
    EntityResolver resolver = runtime.getDataDomain().getEntityResolver();
    // test with adapter that supports keys...
    JdbcAdapter adapter = buildAdapter(true);
    DbEntity dbEntity = resolver.getObjEntity(SimpleLockingTestEntity.class).getDbEntity();
    List<DbAttribute> qualifierAttributes = Arrays.asList(dbEntity.getAttribute("LOCKING_TEST_ID"), dbEntity.getAttribute("NAME"));
    Collection<String> nullAttributeNames = Collections.singleton("NAME");
    Map<String, Object> qualifierSnapshot = new HashMap<>();
    qualifierSnapshot.put("LOCKING_TEST_ID", new Integer(1));
    DeleteBatchQuery batchQuery = new DeleteBatchQuery(dbEntity, qualifierAttributes, nullAttributeNames, 5);
    batchQuery.setUsingOptimisticLocking(true);
    batchQuery.add(qualifierSnapshot);
    DeleteBatchTranslator batchQueryBuilder = new DeleteBatchTranslator(batchQuery, adapter, null);
    MockConnection mockConnection = new MockConnection();
    PreparedStatementResultSetHandler preparedStatementResultSetHandler = mockConnection.getPreparedStatementResultSetHandler();
    preparedStatementResultSetHandler.setExactMatch(false);
    preparedStatementResultSetHandler.setCaseSensitive(false);
    preparedStatementResultSetHandler.prepareUpdateCount("DELETE", 1);
    boolean generatesKeys = false;
    DataNode node = new DataNode();
    node.setAdapter(adapter);
    node.setEntityResolver(resolver);
    node.setRowReaderFactory(mock(RowReaderFactory.class));
    BatchAction action = new BatchAction(batchQuery, node, false);
    action.runAsIndividualQueries(mockConnection, batchQueryBuilder, new MockOperationObserver(), generatesKeys);
    assertEquals(0, mockConnection.getNumberCommits());
    assertEquals(0, mockConnection.getNumberRollbacks());
}
Also used : JdbcAdapter(org.apache.cayenne.dba.JdbcAdapter) HashMap(java.util.HashMap) DeleteBatchQuery(org.apache.cayenne.query.DeleteBatchQuery) SimpleLockingTestEntity(org.apache.cayenne.testdo.locking.SimpleLockingTestEntity) DbAttribute(org.apache.cayenne.map.DbAttribute) RowReaderFactory(org.apache.cayenne.access.jdbc.reader.RowReaderFactory) EntityResolver(org.apache.cayenne.map.EntityResolver) MockConnection(com.mockrunner.mock.jdbc.MockConnection) DbEntity(org.apache.cayenne.map.DbEntity) PreparedStatementResultSetHandler(com.mockrunner.jdbc.PreparedStatementResultSetHandler) DataNode(org.apache.cayenne.access.DataNode) DeleteBatchTranslator(org.apache.cayenne.access.translator.batch.DeleteBatchTranslator) MockOperationObserver(org.apache.cayenne.access.MockOperationObserver) Test(org.junit.Test)

Example 7 with DataNode

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

the class ServerRuntimeBuilderIT method tesConfigFree_WithDBParams.

@Test
public void tesConfigFree_WithDBParams() {
    localRuntime = new ServerRuntimeBuilder(null).addConfig(CayenneProjects.TESTMAP_PROJECT).jdbcDriver(dsi.getJdbcDriver()).url(dsi.getDataSourceUrl()).password(dsi.getPassword()).user(dsi.getUserName()).minConnections(1).maxConnections(2).build();
    DataMap map = localRuntime.getDataDomain().getDataMap("testmap");
    assertNotNull(map);
    DataNode node = localRuntime.getDataDomain().getDefaultNode();
    assertNotNull(node);
    assertEquals(1, node.getDataMaps().size());
    assertSame(map, node.getDataMap("testmap"));
}
Also used : DataNode(org.apache.cayenne.access.DataNode) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Example 8 with DataNode

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

the class ServerRuntimeBuilderIT method testNoNodeConfig_WithDataSource.

@Test
public void testNoNodeConfig_WithDataSource() {
    localRuntime = new ServerRuntimeBuilder(null).addConfig(CayenneProjects.TESTMAP_PROJECT).dataSource(dataSource).build();
    DataMap map = localRuntime.getDataDomain().getDataMap("testmap");
    assertNotNull(map);
    DataNode node = localRuntime.getDataDomain().getDefaultNode();
    assertNotNull(node);
    assertEquals(1, node.getDataMaps().size());
    assertSame(map, node.getDataMap("testmap"));
}
Also used : DataNode(org.apache.cayenne.access.DataNode) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Example 9 with DataNode

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

the class DefaultDataNodeFactory 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);
    dataNode.setSqlTemplateProcessor(sqlTemplateProcessor);
    DataSource dataSource = dataSourceFactory.getDataSource(nodeDescriptor);
    dataNode.setDataSourceFactory(nodeDescriptor.getDataSourceFactoryType());
    dataNode.setDataSource(dataSource);
    dataNode.setSchemaUpdateStrategy(schemaUpdateStrategyFactory.create(nodeDescriptor));
    dataNode.setAdapter(adapterFactory.createAdapter(nodeDescriptor, dataSource));
    return dataNode;
}
Also used : DataNode(org.apache.cayenne.access.DataNode) DataSource(javax.sql.DataSource)

Example 10 with DataNode

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

the class ServerRuntime method getDataSource.

/**
 * Returns a default DataSource for this runtime. If no default DataSource
 * exists, an exception is thrown.
 *
 * @since 4.0
 */
public DataSource getDataSource() {
    DataDomain domain = getDataDomain();
    DataNode defaultNode = domain.getDefaultNode();
    if (defaultNode == null) {
        int s = domain.getDataNodes().size();
        if (s == 0) {
            throw new IllegalStateException("No DataSources configured");
        } else {
            throw new IllegalArgumentException("No default DataSource configured. You can get explicitly named DataSource by using 'getDataSource(String)'");
        }
    }
    return defaultNode.getDataSource();
}
Also used : DataDomain(org.apache.cayenne.access.DataDomain) DataNode(org.apache.cayenne.access.DataNode)

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