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());
}
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"));
}
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"));
}
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;
}
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();
}
Aggregations