Search in sources :

Example 56 with DataChannelDescriptor

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

the class XMLDataChannelDescriptorLoaderTest method testLoadDataEverything.

@Test
public void testLoadDataEverything() {
    // create and initialize loader instance to test
    XMLDataChannelDescriptorLoader loader = new XMLDataChannelDescriptorLoader();
    injector.injectMembers(loader);
    String testConfigName = "testConfig3";
    URL url = getClass().getResource("cayenne-" + testConfigName + ".xml");
    ConfigurationTree<DataChannelDescriptor> tree = loader.load(new URLResource(url));
    assertNotNull(tree);
    DataChannelDescriptor descriptor = tree.getRootNode();
    assertNotNull(descriptor);
    assertEquals(testConfigName, descriptor.getName());
    Collection<DataMap> maps = descriptor.getDataMaps();
    assertEquals(2, maps.size());
    Iterator<DataMap> mapsIt = maps.iterator();
    DataMap map1 = mapsIt.next();
    DataMap map2 = mapsIt.next();
    assertEquals("testConfigMap3_1", map1.getName());
    assertEquals("testConfigMap3_2", map2.getName());
    Collection<DataNodeDescriptor> nodes = descriptor.getNodeDescriptors();
    assertEquals(1, nodes.size());
    DataNodeDescriptor node1 = nodes.iterator().next();
    assertEquals("testConfigNode3", node1.getName());
    assertNull(node1.getParameters());
    assertNotNull(node1.getDataSourceDescriptor());
    assertEquals(1, node1.getDataSourceDescriptor().getMinConnections());
    assertEquals(1, node1.getDataSourceDescriptor().getMaxConnections());
    assertEquals("org.example.test.Adapter", node1.getAdapterType());
    assertEquals("org.example.test.DataSourceFactory", node1.getDataSourceFactoryType());
    assertEquals("org.example.test.SchemaUpdateStartegy", node1.getSchemaUpdateStrategyType());
    assertNotNull(node1.getDataMapNames());
    assertEquals(1, node1.getDataMapNames().size());
    assertEquals("testConfigMap3_2", node1.getDataMapNames().iterator().next());
}
Also used : URLResource(org.apache.cayenne.resource.URLResource) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) URL(java.net.URL) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Example 57 with DataChannelDescriptor

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

the class XMLDataChannelDescriptorLoaderTest method testLoadEmpty.

@Test
public void testLoadEmpty() {
    // create and initialize loader instance to test
    XMLDataChannelDescriptorLoader loader = new XMLDataChannelDescriptorLoader();
    injector.injectMembers(loader);
    String testConfigName = "testConfig1";
    URL url = getClass().getResource("cayenne-" + testConfigName + ".xml");
    ConfigurationTree<DataChannelDescriptor> tree = loader.load(new URLResource(url));
    assertNotNull(tree);
    assertNotNull(tree.getRootNode());
    assertEquals(testConfigName, tree.getRootNode().getName());
}
Also used : URLResource(org.apache.cayenne.resource.URLResource) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) URL(java.net.URL) Test(org.junit.Test)

Example 58 with DataChannelDescriptor

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

the class XMLDataChannelDescriptorLoaderTest method testLoadDataMap.

@Test
public void testLoadDataMap() {
    // create and initialize loader instance to test
    XMLDataChannelDescriptorLoader loader = new XMLDataChannelDescriptorLoader();
    injector.injectMembers(loader);
    String testConfigName = "testConfig2";
    URL url = getClass().getResource("cayenne-" + testConfigName + ".xml");
    ConfigurationTree<DataChannelDescriptor> tree = loader.load(new URLResource(url));
    assertNotNull(tree);
    assertNotNull(tree.getRootNode());
    assertEquals(testConfigName, tree.getRootNode().getName());
    Collection<DataMap> maps = tree.getRootNode().getDataMaps();
    assertEquals(1, maps.size());
    assertEquals("testConfigMap2", maps.iterator().next().getName());
}
Also used : URLResource(org.apache.cayenne.resource.URLResource) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) URL(java.net.URL) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Example 59 with DataChannelDescriptor

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

the class DBCleaner method clean.

public void clean() throws SQLException {
    XMLDataChannelDescriptorLoader loader = new XMLDataChannelDescriptorLoader();
    injector.injectMembers(loader);
    URL url = getClass().getClassLoader().getResource(location);
    ConfigurationTree<DataChannelDescriptor> tree = loader.load(new URLResource(url));
    for (DataMap map : tree.getRootNode().getDataMaps()) {
        List<DbEntity> entities = schemaBuilder.dbEntitiesInDeleteOrder(map);
        for (DbEntity entity : entities) {
            dbHelper.deleteAll(entity.getName());
        }
    }
}
Also used : XMLDataChannelDescriptorLoader(org.apache.cayenne.configuration.xml.XMLDataChannelDescriptorLoader) URLResource(org.apache.cayenne.resource.URLResource) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) DbEntity(org.apache.cayenne.map.DbEntity) URL(java.net.URL) DataMap(org.apache.cayenne.map.DataMap)

Example 60 with DataChannelDescriptor

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

the class ManyToManyCandidateEntityTest method setUp.

@Before
public void setUp() throws Exception {
    Module testModule = binder -> {
        binder.bind(ClassLoaderManager.class).to(DefaultClassLoaderManager.class);
        binder.bind(AdhocObjectFactory.class).to(DefaultAdhocObjectFactory.class);
        binder.bind(DataMapLoader.class).to(XMLDataMapLoader.class);
        binder.bind(ConfigurationNameMapper.class).to(DefaultConfigurationNameMapper.class);
        binder.bind(HandlerFactory.class).to(DefaultHandlerFactory.class);
        binder.bind(DataChannelMetaData.class).to(NoopDataChannelMetaData.class);
        binder.bind(XMLReader.class).toProviderInstance(new XMLReaderProvider(false)).withoutScope();
    };
    Injector injector = DIBootstrap.createInjector(testModule);
    // create and initialize loader instance to test
    XMLDataChannelDescriptorLoader loader = new XMLDataChannelDescriptorLoader();
    injector.injectMembers(loader);
    String testConfigName = "relationship-optimisation";
    URL url = getClass().getResource("cayenne-" + testConfigName + ".xml");
    ConfigurationTree<DataChannelDescriptor> tree = loader.load(new URLResource(url));
    map = tree.getRootNode().getDataMap(testConfigName);
}
Also used : Injector(org.apache.cayenne.di.Injector) ObjEntity(org.apache.cayenne.map.ObjEntity) HandlerFactory(org.apache.cayenne.configuration.xml.HandlerFactory) XMLReaderProvider(org.apache.cayenne.configuration.xml.XMLReaderProvider) DefaultClassLoaderManager(org.apache.cayenne.di.spi.DefaultClassLoaderManager) Relationship(org.apache.cayenne.map.Relationship) URL(java.net.URL) ConfigurationNameMapper(org.apache.cayenne.configuration.ConfigurationNameMapper) Module(org.apache.cayenne.di.Module) DefaultConfigurationNameMapper(org.apache.cayenne.configuration.DefaultConfigurationNameMapper) AdhocObjectFactory(org.apache.cayenne.di.AdhocObjectFactory) ArrayList(java.util.ArrayList) DataMapLoader(org.apache.cayenne.configuration.DataMapLoader) XMLDataChannelDescriptorLoader(org.apache.cayenne.configuration.xml.XMLDataChannelDescriptorLoader) DefaultObjectNameGenerator(org.apache.cayenne.dbsync.naming.DefaultObjectNameGenerator) XMLReader(org.xml.sax.XMLReader) DefaultHandlerFactory(org.apache.cayenne.configuration.xml.DefaultHandlerFactory) ConfigurationTree(org.apache.cayenne.configuration.ConfigurationTree) NoopDataChannelMetaData(org.apache.cayenne.configuration.xml.NoopDataChannelMetaData) NoStemStemmer(org.apache.cayenne.dbsync.naming.NoStemStemmer) XMLDataMapLoader(org.apache.cayenne.configuration.xml.XMLDataMapLoader) DIBootstrap(org.apache.cayenne.di.DIBootstrap) Before(org.junit.Before) URLResource(org.apache.cayenne.resource.URLResource) DefaultAdhocObjectFactory(org.apache.cayenne.di.spi.DefaultAdhocObjectFactory) Test(org.junit.Test) DataChannelMetaData(org.apache.cayenne.configuration.xml.DataChannelMetaData) ClassLoaderManager(org.apache.cayenne.di.ClassLoaderManager) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) Assert(org.junit.Assert) DataMap(org.apache.cayenne.map.DataMap) DefaultAdhocObjectFactory(org.apache.cayenne.di.spi.DefaultAdhocObjectFactory) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) DefaultConfigurationNameMapper(org.apache.cayenne.configuration.DefaultConfigurationNameMapper) XMLDataMapLoader(org.apache.cayenne.configuration.xml.XMLDataMapLoader) URL(java.net.URL) NoopDataChannelMetaData(org.apache.cayenne.configuration.xml.NoopDataChannelMetaData) XMLDataChannelDescriptorLoader(org.apache.cayenne.configuration.xml.XMLDataChannelDescriptorLoader) XMLReaderProvider(org.apache.cayenne.configuration.xml.XMLReaderProvider) URLResource(org.apache.cayenne.resource.URLResource) DefaultHandlerFactory(org.apache.cayenne.configuration.xml.DefaultHandlerFactory) Injector(org.apache.cayenne.di.Injector) Module(org.apache.cayenne.di.Module) DefaultClassLoaderManager(org.apache.cayenne.di.spi.DefaultClassLoaderManager) XMLReader(org.xml.sax.XMLReader) Before(org.junit.Before)

Aggregations

DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)100 DataMap (org.apache.cayenne.map.DataMap)50 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)28 Test (org.junit.Test)20 ObjEntity (org.apache.cayenne.map.ObjEntity)18 DbEntity (org.apache.cayenne.map.DbEntity)12 ProjectController (org.apache.cayenne.modeler.ProjectController)12 URL (java.net.URL)11 Embeddable (org.apache.cayenne.map.Embeddable)11 ArrayList (java.util.ArrayList)10 URLResource (org.apache.cayenne.resource.URLResource)10 ObjAttribute (org.apache.cayenne.map.ObjAttribute)8 QueryDescriptor (org.apache.cayenne.map.QueryDescriptor)8 EntityDisplayEvent (org.apache.cayenne.modeler.event.EntityDisplayEvent)8 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)7 DataNodeEvent (org.apache.cayenne.configuration.event.DataNodeEvent)6 Injector (org.apache.cayenne.di.Injector)6 Procedure (org.apache.cayenne.map.Procedure)6 ProcedureDisplayEvent (org.apache.cayenne.modeler.event.ProcedureDisplayEvent)6 Resource (org.apache.cayenne.resource.Resource)6