Search in sources :

Example 6 with DataSourceInfo

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);
}
Also used : DataSourceInfo(org.apache.cayenne.conn.DataSourceInfo) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) Test(org.junit.Test)

Example 7 with DataSourceInfo

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();
}
Also used : DataSourceInfo(org.apache.cayenne.conn.DataSourceInfo) ConfigurationException(org.apache.cayenne.ConfigurationException) Driver(java.sql.Driver)

Example 8 with DataSourceInfo

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());
}
Also used : DataSourceInfo(org.apache.cayenne.conn.DataSourceInfo) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) Test(org.junit.Test)

Example 9 with DataSourceInfo

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());
    }
}
Also used : DataSourceInfo(org.apache.cayenne.conn.DataSourceInfo) BuildException(org.apache.tools.ant.BuildException)

Example 10 with DataSourceInfo

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;
}
Also used : DataSourceInfo(org.apache.cayenne.conn.DataSourceInfo) ConfigurationException(org.apache.cayenne.ConfigurationException)

Aggregations

DataSourceInfo (org.apache.cayenne.conn.DataSourceInfo)12 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)4 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)3 Driver (java.sql.Driver)2 ConfigurationException (org.apache.cayenne.ConfigurationException)2 XMLPoolingDataSourceFactory (org.apache.cayenne.configuration.server.XMLPoolingDataSourceFactory)2 ProjectController (org.apache.cayenne.modeler.ProjectController)2 Test (org.junit.Test)2 Map (java.util.Map)1 SkipSchemaUpdateStrategy (org.apache.cayenne.access.dbsync.SkipSchemaUpdateStrategy)1 DataNodeEvent (org.apache.cayenne.configuration.event.DataNodeEvent)1 JNDIDataSourceFactory (org.apache.cayenne.configuration.server.JNDIDataSourceFactory)1 DriverDataSource (org.apache.cayenne.datasource.DriverDataSource)1 DbAdapter (org.apache.cayenne.dba.DbAdapter)1 DataMap (org.apache.cayenne.map.DataMap)1 CayenneModelerController (org.apache.cayenne.modeler.CayenneModelerController)1 DataNodeDisplayEvent (org.apache.cayenne.modeler.event.DataNodeDisplayEvent)1 DBConnectionInfo (org.apache.cayenne.modeler.pref.DBConnectionInfo)1 AdapterMapping (org.apache.cayenne.modeler.util.AdapterMapping)1 BuildException (org.apache.tools.ant.BuildException)1