Search in sources :

Example 1 with DataNodeDescriptor

use of org.apache.cayenne.configuration.DataNodeDescriptor in project cayenne by apache.

the class ConfigurationSourceSetter method visitDataChannelDescriptor.

@Override
public Void visitDataChannelDescriptor(DataChannelDescriptor node) {
    node.setConfigurationSource(configurationSource);
    // update child configurations
    for (DataNodeDescriptor childDescriptor : node.getNodeDescriptors()) {
        childDescriptor.setDataChannelDescriptor(node);
        childDescriptor.setConfigurationSource(configurationSource);
    }
    return null;
}
Also used : DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor)

Example 2 with DataNodeDescriptor

use of org.apache.cayenne.configuration.DataNodeDescriptor in project cayenne by apache.

the class NameBuilderTest method testName_DataChannelDescriptorContext.

@Test
public void testName_DataChannelDescriptorContext() throws Exception {
    DataChannelDescriptor descriptor = new DataChannelDescriptor();
    DataMap m0 = new DataMap();
    m0.setName(NameBuilder.builder(m0).in(descriptor).name());
    assertEquals("datamap", m0.getName());
    descriptor.getDataMaps().add(m0);
    DataMap m1 = new DataMap();
    m1.setName(NameBuilder.builder(m1).in(descriptor).name());
    assertEquals("datamap1", m1.getName());
    descriptor.getDataMaps().add(m1);
    DataNodeDescriptor nd0 = new DataNodeDescriptor();
    nd0.setName(NameBuilder.builder(nd0).in(descriptor).name());
    assertEquals("datanode", nd0.getName());
    descriptor.getNodeDescriptors().add(nd0);
    DataNodeDescriptor nd1 = new DataNodeDescriptor();
    nd1.setName(NameBuilder.builder(nd1).in(descriptor).name());
    assertEquals("datanode1", nd1.getName());
    descriptor.getNodeDescriptors().add(nd1);
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Example 3 with DataNodeDescriptor

use of org.apache.cayenne.configuration.DataNodeDescriptor in project cayenne by apache.

the class DBCP2DataSourceFactoryTest method testGetDataSource.

@Test
public void testGetDataSource() throws Exception {
    String baseUrl = getClass().getPackage().getName().replace('.', '/');
    URL url = getClass().getClassLoader().getResource(baseUrl + "/");
    assertNotNull(url);
    DataNodeDescriptor nodeDescriptor = new DataNodeDescriptor();
    nodeDescriptor.setConfigurationSource(new URLResource(url));
    nodeDescriptor.setParameters("testDBCP2.properties");
    DBCPDataSourceFactory factory = new DBCPDataSourceFactory();
    DataSource dataSource = factory.getDataSource(nodeDescriptor);
    assertNotNull(dataSource);
    assertTrue(dataSource instanceof BasicDataSource);
    try (BasicDataSource basicDataSource = (BasicDataSource) dataSource) {
        assertEquals("com.example.jdbc.Driver", basicDataSource.getDriverClassName());
        assertEquals("jdbc:somedb://localhost/cayenne", basicDataSource.getUrl());
        assertEquals("john", basicDataSource.getUsername());
        assertEquals("secret", basicDataSource.getPassword());
        assertEquals(20, basicDataSource.getMaxTotal());
        assertEquals(5, basicDataSource.getMinIdle());
        assertEquals(8, basicDataSource.getMaxIdle());
        assertEquals(10000, basicDataSource.getMaxWaitMillis());
        assertEquals("select 1 from xyz;", basicDataSource.getValidationQuery());
    }
}
Also used : URLResource(org.apache.cayenne.resource.URLResource) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) BasicDataSource(org.apache.commons.dbcp2.BasicDataSource) URL(java.net.URL) BasicDataSource(org.apache.commons.dbcp2.BasicDataSource) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 4 with DataNodeDescriptor

use of org.apache.cayenne.configuration.DataNodeDescriptor in project cayenne by apache.

the class DefaultDbImportAction method execute.

@Override
public void execute(DbImportConfiguration config) throws Exception {
    if (logger.isDebugEnabled()) {
        logger.debug("DB connection: " + config.getDataSourceInfo());
        logger.debug(String.valueOf(config));
    }
    boolean hasChanges = false;
    DataNodeDescriptor dataNodeDescriptor = config.createDataNodeDescriptor();
    DataSource dataSource = dataSourceFactory.getDataSource(dataNodeDescriptor);
    DbAdapter adapter = adapterFactory.createAdapter(dataNodeDescriptor, dataSource);
    DataMap sourceDataMap;
    try (Connection connection = dataSource.getConnection()) {
        sourceDataMap = load(config, adapter, connection);
    }
    DataMap targetDataMap = existingTargetMap(config);
    if (targetDataMap == null) {
        String path = config.getTargetDataMap() == null ? "null" : config.getTargetDataMap().getAbsolutePath() + "'";
        logger.info("");
        logger.info("Map file does not exist. Loaded db model will be saved into '" + path);
        hasChanges = true;
        targetDataMap = newTargetDataMap(config);
    }
    // transform source DataMap before merging
    transformSourceBeforeMerge(sourceDataMap, targetDataMap, config);
    MergerTokenFactory mergerTokenFactory = mergerTokenFactoryProvider.get(adapter);
    DbLoaderConfiguration loaderConfig = config.getDbLoaderConfig();
    Collection<MergerToken> tokens = DataMapMerger.builder(mergerTokenFactory).filters(loaderConfig.getFiltersConfig()).skipPKTokens(loaderConfig.isSkipPrimaryKeyLoading()).skipRelationshipsTokens(loaderConfig.isSkipRelationshipsLoading()).build().createMergeTokens(targetDataMap, sourceDataMap);
    tokens = log(sort(reverse(mergerTokenFactory, tokens)));
    hasChanges |= syncDataMapProperties(targetDataMap, config);
    hasChanges |= applyTokens(targetDataMap, tokens, config);
    hasChanges |= syncProcedures(targetDataMap, sourceDataMap, loaderConfig.getFiltersConfig());
    if (hasChanges) {
        saveLoaded(targetDataMap, config);
    }
}
Also used : DbAdapter(org.apache.cayenne.dba.DbAdapter) Connection(java.sql.Connection) MergerToken(org.apache.cayenne.dbsync.merge.token.MergerToken) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) MergerTokenFactory(org.apache.cayenne.dbsync.merge.factory.MergerTokenFactory) DataSource(javax.sql.DataSource) DataMap(org.apache.cayenne.map.DataMap) DbLoaderConfiguration(org.apache.cayenne.dbsync.reverse.dbload.DbLoaderConfiguration)

Example 5 with DataNodeDescriptor

use of org.apache.cayenne.configuration.DataNodeDescriptor in project cayenne by apache.

the class ProjectTreeView method dataNodeAdded.

public void dataNodeAdded(DataNodeEvent e) {
    if (e.getSource() == this) {
        return;
    }
    DefaultMutableTreeNode node = getProjectModel().getNodeForObjectPath(new Object[] { e.getDomain() != null ? e.getDomain() : (DataChannelDescriptor) mediator.getProject().getRootNode() });
    if (node == null) {
        return;
    }
    DataNodeDescriptor dataNode = e.getDataNode();
    DefaultMutableTreeNode currentNode = ProjectTreeFactory.wrapProjectNode(dataNode);
    positionNode(node, currentNode, Comparators.getDataDomainChildrenComparator());
    showNode(currentNode);
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor)

Aggregations

DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)58 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)28 DataMap (org.apache.cayenne.map.DataMap)23 Test (org.junit.Test)22 DbEntity (org.apache.cayenne.map.DbEntity)11 ArrayList (java.util.ArrayList)8 Injector (org.apache.cayenne.di.Injector)8 Constants (org.apache.cayenne.configuration.Constants)7 RuntimeProperties (org.apache.cayenne.configuration.RuntimeProperties)7 DbAdapter (org.apache.cayenne.dba.DbAdapter)7 AdhocObjectFactory (org.apache.cayenne.di.AdhocObjectFactory)7 ClassLoaderManager (org.apache.cayenne.di.ClassLoaderManager)7 DIBootstrap (org.apache.cayenne.di.DIBootstrap)7 Key (org.apache.cayenne.di.Key)7 Module (org.apache.cayenne.di.Module)7 DefaultAdhocObjectFactory (org.apache.cayenne.di.spi.DefaultAdhocObjectFactory)7 DefaultClassLoaderManager (org.apache.cayenne.di.spi.DefaultClassLoaderManager)7 JdbcEventLogger (org.apache.cayenne.log.JdbcEventLogger)7 Slf4jJdbcEventLogger (org.apache.cayenne.log.Slf4jJdbcEventLogger)7 ObjEntity (org.apache.cayenne.map.ObjEntity)7