use of org.apache.cayenne.configuration.DataChannelDescriptor in project cayenne by apache.
the class PasteAction method performAction.
/**
* Performs pasting items from the system buffer
*/
@Override
public void performAction(ActionEvent e) {
try {
Object content = Toolkit.getDefaultToolkit().getSystemClipboard().getData(CayenneTransferable.CAYENNE_FLAVOR);
Object currentObject = getProjectController().getCurrentObject();
if (content != null && currentObject != null) {
DataChannelDescriptor domain = (DataChannelDescriptor) getProjectController().getProject().getRootNode();
DataMap map = getProjectController().getCurrentDataMap();
UndoableEdit undoableEdit;
if (content instanceof List) {
undoableEdit = new PasteCompoundUndoableEdit();
for (Object o : (List) content) {
paste(currentObject, o);
undoableEdit.addEdit(new PasteUndoableEdit(domain, map, currentObject, o));
}
} else {
paste(currentObject, content);
undoableEdit = new PasteUndoableEdit(domain, map, currentObject, content);
}
application.getUndoManager().addEdit(undoableEdit);
}
} catch (UnsupportedFlavorException ufe) {
// do nothing
} catch (Exception ex) {
ErrorDebugDialog.guiException(ex);
}
}
use of org.apache.cayenne.configuration.DataChannelDescriptor in project cayenne by apache.
the class DefaultDataSourceFactoryLoaderTest method testGetDataSourceFactory_UnusedProperties.
@Test
public void testGetDataSourceFactory_UnusedProperties() throws Exception {
final RuntimeProperties properties = mock(RuntimeProperties.class);
when(properties.get(Constants.JDBC_DRIVER_PROPERTY)).thenReturn("x");
when(properties.get(Constants.JDBC_URL_PROPERTY)).thenReturn(null);
when(properties.get(Constants.JDBC_USERNAME_PROPERTY)).thenReturn("username");
when(properties.get(Constants.JDBC_PASSWORD_PROPERTY)).thenReturn("12345");
DataChannelDescriptor channelDescriptor = new DataChannelDescriptor();
channelDescriptor.setName("X");
DataNodeDescriptor nodeDescriptor = new DataNodeDescriptor();
nodeDescriptor.setName("node1");
nodeDescriptor.setDataSourceFactoryType(MockDataSourceFactory1.class.getName());
nodeDescriptor.setDataChannelDescriptor(channelDescriptor);
Module testModule = binder -> {
binder.bind(ClassLoaderManager.class).to(DefaultClassLoaderManager.class);
binder.bind(AdhocObjectFactory.class).to(DefaultAdhocObjectFactory.class);
binder.bind(ResourceLocator.class).to(MockResourceLocator.class);
binder.bind(Key.get(ResourceLocator.class, Constants.SERVER_RESOURCE_LOCATOR)).to(MockResourceLocator.class);
binder.bind(RuntimeProperties.class).toInstance(properties);
binder.bind(JdbcEventLogger.class).to(Slf4jJdbcEventLogger.class);
};
Injector injector = DIBootstrap.createInjector(testModule);
DelegatingDataSourceFactory factoryLoader = new DelegatingDataSourceFactory();
injector.injectMembers(factoryLoader);
DataSourceFactory factory = factoryLoader.getDataSourceFactory(nodeDescriptor);
assertNotNull(factory);
assertFalse(factory instanceof PropertyDataSourceFactory);
nodeDescriptor.setName("node2");
when(properties.get(Constants.JDBC_MIN_CONNECTIONS_PROPERTY + ".X.node2")).thenReturn("3");
when(properties.get(Constants.JDBC_PASSWORD_PROPERTY + ".X.node2")).thenReturn("123456");
factory = factoryLoader.getDataSourceFactory(nodeDescriptor);
assertNotNull(factory);
assertFalse(factory instanceof PropertyDataSourceFactory);
nodeDescriptor.setName("node3");
when(properties.get(Constants.JDBC_URL_PROPERTY + ".X.node3")).thenReturn("url");
factory = factoryLoader.getDataSourceFactory(nodeDescriptor);
assertNotNull(factory);
assertTrue(factory instanceof PropertyDataSourceFactory);
}
use of org.apache.cayenne.configuration.DataChannelDescriptor in project cayenne by apache.
the class DefaultDataSourceFactoryLoaderTest method testGetDataSourceFactory_Property.
@Test
public void testGetDataSourceFactory_Property() throws Exception {
final RuntimeProperties properties = mock(RuntimeProperties.class);
when(properties.get(Constants.JDBC_DRIVER_PROPERTY)).thenReturn("x");
when(properties.get(Constants.JDBC_URL_PROPERTY)).thenReturn("y");
DataChannelDescriptor channelDescriptor = new DataChannelDescriptor();
channelDescriptor.setName("X");
DataNodeDescriptor nodeDescriptor = new DataNodeDescriptor();
nodeDescriptor.setName("node1");
nodeDescriptor.setDataSourceFactoryType(MockDataSourceFactory1.class.getName());
nodeDescriptor.setDataChannelDescriptor(channelDescriptor);
Module testModule = binder -> {
binder.bind(ClassLoaderManager.class).to(DefaultClassLoaderManager.class);
binder.bind(AdhocObjectFactory.class).to(DefaultAdhocObjectFactory.class);
binder.bind(ResourceLocator.class).to(MockResourceLocator.class);
binder.bind(Key.get(ResourceLocator.class, Constants.SERVER_RESOURCE_LOCATOR)).to(MockResourceLocator.class);
binder.bind(RuntimeProperties.class).toInstance(properties);
binder.bind(JdbcEventLogger.class).to(Slf4jJdbcEventLogger.class);
};
Injector injector = DIBootstrap.createInjector(testModule);
DelegatingDataSourceFactory factoryLoader = new DelegatingDataSourceFactory();
injector.injectMembers(factoryLoader);
DataSourceFactory factory = factoryLoader.getDataSourceFactory(nodeDescriptor);
assertNotNull(factory);
assertTrue(factory instanceof PropertyDataSourceFactory);
when(properties.get(Constants.JDBC_URL_PROPERTY)).thenReturn(null);
factory = factoryLoader.getDataSourceFactory(nodeDescriptor);
assertNotNull(factory);
assertFalse(factory instanceof PropertyDataSourceFactory);
when(properties.get(Constants.JDBC_URL_PROPERTY + ".X.node2")).thenReturn("y");
factory = factoryLoader.getDataSourceFactory(nodeDescriptor);
assertNotNull(factory);
assertFalse(factory instanceof PropertyDataSourceFactory);
when(properties.get(Constants.JDBC_URL_PROPERTY + ".X.node1")).thenReturn("y");
factory = factoryLoader.getDataSourceFactory(nodeDescriptor);
assertNotNull(factory);
assertTrue(factory instanceof PropertyDataSourceFactory);
}
use of org.apache.cayenne.configuration.DataChannelDescriptor in project cayenne by apache.
the class DataDomainProvider method loadDescriptorFromConfigs.
private DataChannelDescriptor loadDescriptorFromConfigs() {
long t0 = System.currentTimeMillis();
if (logger.isDebugEnabled()) {
logger.debug("starting configuration loading: " + locations);
}
DataChannelDescriptor[] descriptors = new DataChannelDescriptor[locations.size()];
for (int i = 0; i < locations.size(); i++) {
String location = locations.get(i);
Collection<Resource> configurations = resourceLocator.findResources(location);
if (configurations.isEmpty()) {
throw new DataDomainLoadException("Configuration resource \"%s\" is not found.", location);
}
Resource configurationResource = configurations.iterator().next();
// no support for multiple configs yet, but this is not a hard error
if (configurations.size() > 1) {
logger.info("found " + configurations.size() + " configurations for " + location + ", will use the first one: " + configurationResource.getURL());
}
ConfigurationTree<DataChannelDescriptor> tree = loader.load(configurationResource);
if (!tree.getLoadFailures().isEmpty()) {
// TODO: andrus 03/10/2010 - log the errors before throwing?
throw new DataDomainLoadException(tree, "Error loading DataChannelDescriptor");
}
descriptors[i] = tree.getRootNode();
}
long t1 = System.currentTimeMillis();
if (logger.isDebugEnabled()) {
logger.debug("finished configuration loading in " + (t1 - t0) + " ms.");
}
return descriptorMerger.merge(descriptors);
}
use of org.apache.cayenne.configuration.DataChannelDescriptor in project cayenne by apache.
the class DataDomainProvider method loadDescriptor.
/**
* @since 4.0
*/
protected DataChannelDescriptor loadDescriptor() {
DataChannelDescriptor descriptor = locations.isEmpty() ? new DataChannelDescriptor() : loadDescriptorFromConfigs();
String nameOverride = runtimeProperties.get(Constants.SERVER_DOMAIN_NAME_PROPERTY);
if (nameOverride != null) {
descriptor.setName(nameOverride);
}
return descriptor;
}
Aggregations