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