use of org.apache.cayenne.configuration.DataNodeDescriptor 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.DataNodeDescriptor in project cayenne by apache.
the class DefaultDbAdapterFactoryTest method testCreatedAdapter_Auto.
@Test
public void testCreatedAdapter_Auto() throws Exception {
final DbAdapter adapter = mock(DbAdapter.class);
when(adapter.createTable(any(DbEntity.class))).thenReturn("XXXXX");
List<DbAdapterDetector> detectors = new ArrayList<DbAdapterDetector>();
detectors.add(new DbAdapterDetector() {
public DbAdapter createAdapter(DatabaseMetaData md) throws SQLException {
return adapter;
}
});
MockConnection connection = new MockConnection();
MockDataSource dataSource = new MockDataSource();
dataSource.setupConnection(connection);
Module testModule = binder -> {
ServerModule.contributeProperties(binder);
binder.bind(JdbcEventLogger.class).to(Slf4jJdbcEventLogger.class);
binder.bind(ClassLoaderManager.class).to(DefaultClassLoaderManager.class);
binder.bind(AdhocObjectFactory.class).to(DefaultAdhocObjectFactory.class);
binder.bind(RuntimeProperties.class).to(DefaultRuntimeProperties.class);
};
Injector injector = DIBootstrap.createInjector(testModule);
DefaultDbAdapterFactory factory = new DefaultDbAdapterFactory(detectors);
injector.injectMembers(factory);
DbAdapter createdAdapter = factory.createAdapter(new DataNodeDescriptor(), dataSource);
assertTrue(createdAdapter instanceof AutoAdapter);
assertEquals("XXXXX", createdAdapter.createTable(new DbEntity("Test")));
}
use of org.apache.cayenne.configuration.DataNodeDescriptor in project cayenne by apache.
the class JNDIDataSourceFactoryIT method testGetDataSource_NameNotBound.
@Test
public void testGetDataSource_NameNotBound() throws Exception {
DataNodeDescriptor descriptor = new DataNodeDescriptor();
descriptor.setParameters("jdbc/TestDS");
JNDISetup.doSetup();
JNDIDataSourceFactory factory = new JNDIDataSourceFactory();
injector.injectMembers(factory);
try {
factory.getDataSource(descriptor);
fail("Didn't throw on unbound name");
} catch (NameNotFoundException e) {
// expected
}
}
use of org.apache.cayenne.configuration.DataNodeDescriptor in project cayenne by apache.
the class AttributeDisplayEventType method fireLastDisplayEvent.
@Override
public void fireLastDisplayEvent() {
DataChannelDescriptor dataChannel = (DataChannelDescriptor) controller.getProject().getRootNode();
if (!dataChannel.getName().equals(preferences.getDomain())) {
return;
}
DataNodeDescriptor dataNode = dataChannel.getNodeDescriptor(preferences.getNode());
DataMap dataMap = dataChannel.getDataMap(preferences.getDataMap());
if (dataMap == null) {
return;
}
Entity entity = getLastEntity(dataMap);
if (entity == null) {
return;
}
Attribute[] attributes = getLastEntityAttributes(entity);
EntityDisplayEvent entityDisplayEvent = new EntityDisplayEvent(this, entity, dataMap, dataNode, dataChannel);
AttributeDisplayEvent attributeDisplayEvent = new AttributeDisplayEvent(this, attributes, entity, dataMap, dataChannel);
if (entity instanceof ObjEntity) {
controller.fireObjEntityDisplayEvent(entityDisplayEvent);
controller.fireObjAttributeDisplayEvent(attributeDisplayEvent);
} else if (entity instanceof DbEntity) {
controller.fireDbEntityDisplayEvent(entityDisplayEvent);
controller.fireDbAttributeDisplayEvent(attributeDisplayEvent);
}
}
use of org.apache.cayenne.configuration.DataNodeDescriptor in project cayenne by apache.
the class DataNodeDisplayEventType method fireLastDisplayEvent.
@Override
public void fireLastDisplayEvent() {
DataChannelDescriptor dataChannel = (DataChannelDescriptor) controller.getProject().getRootNode();
if (!dataChannel.getName().equals(preferences.getDomain())) {
return;
}
DataNodeDescriptor dataNode = dataChannel.getNodeDescriptor(preferences.getNode());
if (dataNode == null) {
return;
}
DataNodeDisplayEvent dataNodeDisplayEvent = new DataNodeDisplayEvent(this, dataChannel, dataNode);
controller.fireDataNodeDisplayEvent(dataNodeDisplayEvent);
}
Aggregations