use of org.apache.cayenne.conn.DataSourceInfo in project cayenne by apache.
the class DefaultDataSourceFactoryLoaderTest method testGetDataSourceFactory_Implicit.
@Test
public void testGetDataSourceFactory_Implicit() throws Exception {
DataNodeDescriptor nodeDescriptor = new DataNodeDescriptor();
nodeDescriptor.setName("node1");
nodeDescriptor.setDataSourceDescriptor(new DataSourceInfo());
DelegatingDataSourceFactory factoryLoader = new DelegatingDataSourceFactory();
injector.injectMembers(factoryLoader);
DataSourceFactory factory = factoryLoader.getDataSourceFactory(nodeDescriptor);
assertNotNull(factory);
assertTrue(factory instanceof XMLPoolingDataSourceFactory);
}
use of org.apache.cayenne.conn.DataSourceInfo in project cayenne by apache.
the class XMLPoolingDataSourceFactory method getDataSource.
@Override
public DataSource getDataSource(DataNodeDescriptor nodeDescriptor) throws Exception {
DataSourceInfo descriptor = nodeDescriptor.getDataSourceDescriptor();
if (descriptor == null) {
String message = "Null dataSourceDescriptor for nodeDescriptor '" + nodeDescriptor.getName() + "'";
logger.info(message);
throw new ConfigurationException(message);
}
long maxQueueWaitTime = properties.getLong(Constants.JDBC_MAX_QUEUE_WAIT_TIME, UnmanagedPoolingDataSource.MAX_QUEUE_WAIT_DEFAULT);
Driver driver = objectFactory.newInstance(Driver.class, descriptor.getJdbcDriver());
return DataSourceBuilder.url(descriptor.getDataSourceUrl()).driver(driver).userName(descriptor.getUserName()).password(descriptor.getPassword()).pool(descriptor.getMinConnections(), descriptor.getMaxConnections()).maxQueueWaitTime(maxQueueWaitTime).build();
}
use of org.apache.cayenne.conn.DataSourceInfo in project cayenne by apache.
the class CreateNodeActionTest method testCreateDataNode.
@Test
public void testCreateDataNode() {
CreateNodeAction action;
try {
action = new CreateNodeAction(null);
} catch (InternalError e) {
// TODO: setup test environment DISPLAY variable
return;
}
DataChannelDescriptor domain = new DataChannelDescriptor();
domain.setName("aa");
DataNodeDescriptor node = action.buildDataNode(domain);
assertNotNull(node);
assertNotNull(node.getName());
DataSourceInfo ds1 = new DataSourceInfo();
node.setDataSourceDescriptor(ds1);
assertSame("Project DataNode must not wrap the DataSource", ds1, node.getDataSourceDescriptor());
}
use of org.apache.cayenne.conn.DataSourceInfo in project cayenne by apache.
the class DbImporterTask method validateAttributes.
/**
* Validates attributes that are not related to internal
* DefaultClassGenerator. Throws BuildException if attributes are invalid.
*/
protected void validateAttributes() throws BuildException {
StringBuilder error = new StringBuilder("");
if (config.getTargetDataMap() == null) {
error.append("The 'map' attribute must be set.\n");
}
DataSourceInfo dataSourceInfo = config.getDataSourceInfo();
if (dataSourceInfo.getJdbcDriver() == null) {
error.append("The 'driver' attribute must be set.\n");
}
if (dataSourceInfo.getDataSourceUrl() == null) {
error.append("The 'url' attribute must be set.\n");
}
if (error.length() > 0) {
throw new BuildException(error.toString());
}
}
use of org.apache.cayenne.conn.DataSourceInfo in project cayenne by apache.
the class ServerCaseDataSourceInfoProvider method get.
@Override
public DataSourceInfo get() throws ConfigurationException {
String connectionKey = property(CONNECTION_NAME_KEY);
if (connectionKey == null) {
connectionKey = "hsql";
}
logger.info("Connection key: " + connectionKey);
DataSourceInfo connectionInfo = connectionProperties.getConnection(connectionKey);
// attempt default if invalid key is specified
if (connectionInfo == null) {
connectionInfo = inMemoryDataSources.get(connectionKey);
}
connectionInfo = applyOverrides(connectionInfo);
if (connectionInfo == null) {
throw new ConfigurationException("No connection info for key: " + connectionKey);
}
logger.info("loaded connection info: " + connectionInfo);
return connectionInfo;
}
Aggregations