Search in sources :

Example 11 with DataNodeDescriptor

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

the class LinkDataMapsAction method performAction.

@Override
public void performAction(ActionEvent e) {
    ProjectController mediator = getProjectController();
    DataChannelDescriptor dataChannelDescriptor = (DataChannelDescriptor) mediator.getProject().getRootNode();
    Collection<String> linkedDataMaps = new ArrayList<>();
    DataNodeDescriptor dataNodeDescriptor = mediator.getCurrentDataNode();
    for (DataNodeDescriptor dataNodeDesc : dataChannelDescriptor.getNodeDescriptors()) {
        linkedDataMaps.addAll(dataNodeDesc.getDataMapNames());
    }
    for (DataMap dataMap : dataChannelDescriptor.getDataMaps()) {
        if (!linkedDataMaps.contains(dataMap.getName())) {
            dataNodeDescriptor.getDataMapNames().add(dataMap.getName());
            mediator.fireDataNodeEvent(new DataNodeEvent(this, dataNodeDescriptor));
        }
    }
    application.getUndoManager().addEdit(new LinkDataMapsUndoableEdit(dataNodeDescriptor, linkedDataMaps, mediator));
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) DataNodeEvent(org.apache.cayenne.configuration.event.DataNodeEvent) ArrayList(java.util.ArrayList) LinkDataMapsUndoableEdit(org.apache.cayenne.modeler.undo.LinkDataMapsUndoableEdit) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) ProjectController(org.apache.cayenne.modeler.ProjectController) DataMap(org.apache.cayenne.map.DataMap)

Example 12 with DataNodeDescriptor

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

the class RemoveAction method removeLastPathComponent.

/**
 * Removes an object, depending on its type
 */
private UndoableEdit removeLastPathComponent(ConfigurationNode object, ConfigurationNode parentObject) {
    UndoableEdit undo = null;
    if (object instanceof DataMap) {
        if (parentObject != null && parentObject instanceof DataNodeDescriptor) {
            undo = new RemoveUndoableEdit(application, (DataNodeDescriptor) parentObject, (DataMap) object);
            removeDataMapFromDataNode((DataNodeDescriptor) parentObject, (DataMap) object);
        } else {
            // Not under Data Node, remove completely
            undo = new RemoveUndoableEdit(application, (DataMap) object);
            removeDataMap((DataMap) object);
        }
    } else if (object instanceof DataNodeDescriptor) {
        undo = new RemoveUndoableEdit(application, (DataNodeDescriptor) object);
        removeDataNode((DataNodeDescriptor) object);
    } else if (object instanceof DbEntity) {
        undo = new RemoveUndoableEdit(((DbEntity) object).getDataMap(), (DbEntity) object);
        removeDbEntity(((DbEntity) object).getDataMap(), (DbEntity) object);
    } else if (object instanceof ObjEntity) {
        undo = new RemoveUndoableEdit(((ObjEntity) object).getDataMap(), (ObjEntity) object);
        removeObjEntity(((ObjEntity) object).getDataMap(), (ObjEntity) object);
    } else if (object instanceof QueryDescriptor) {
        undo = new RemoveUndoableEdit(((QueryDescriptor) object).getDataMap(), (QueryDescriptor) object);
        removeQuery(((QueryDescriptor) object).getDataMap(), (QueryDescriptor) object);
    } else if (object instanceof Procedure) {
        undo = new RemoveUndoableEdit(((Procedure) object).getDataMap(), (Procedure) object);
        removeProcedure(((Procedure) object).getDataMap(), (Procedure) object);
    } else if (object instanceof Embeddable) {
        undo = new RemoveUndoableEdit(((Embeddable) object).getDataMap(), (Embeddable) object);
        removeEmbeddable(((Embeddable) object).getDataMap(), (Embeddable) object);
    }
    return undo;
}
Also used : QueryDescriptor(org.apache.cayenne.map.QueryDescriptor) ObjEntity(org.apache.cayenne.map.ObjEntity) DbEntity(org.apache.cayenne.map.DbEntity) RemoveAttributeUndoableEdit(org.apache.cayenne.modeler.undo.RemoveAttributeUndoableEdit) RemoveCallbackMethodUndoableEdit(org.apache.cayenne.modeler.undo.RemoveCallbackMethodUndoableEdit) UndoableEdit(javax.swing.undo.UndoableEdit) RemoveRelationshipUndoableEdit(org.apache.cayenne.modeler.undo.RemoveRelationshipUndoableEdit) RemoveUndoableEdit(org.apache.cayenne.modeler.undo.RemoveUndoableEdit) RemoveCompoundUndoableEdit(org.apache.cayenne.modeler.undo.RemoveCompoundUndoableEdit) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) Procedure(org.apache.cayenne.map.Procedure) RemoveUndoableEdit(org.apache.cayenne.modeler.undo.RemoveUndoableEdit) DataMap(org.apache.cayenne.map.DataMap) Embeddable(org.apache.cayenne.map.Embeddable)

Example 13 with DataNodeDescriptor

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

the class ServerCaseDataDomainProvider method createAndInitDataDomain.

@Override
protected DataDomain createAndInitDataDomain() throws Exception {
    DataDomain domain = super.createAndInitDataDomain();
    DataNode node = null;
    for (DataMap dataMap : domain.getDataMaps()) {
        // add nodes and DataSources dynamically...
        DataNodeDescriptor descriptor = new DataNodeDescriptor(dataMap.getName());
        node = dataNodeFactory.createDataNode(descriptor);
        node.addDataMap(dataMap);
        // tweak procedures for testing...
        for (Procedure proc : dataMap.getProcedures()) {
            unitDbAdapter.tweakProcedure(proc);
        }
        // customizations from SimpleAccessStackAdapter that are not yet
        // ported...
        // those can be done better now
        // node
        // .getAdapter()
        // .getExtendedTypes()
        // .registerType(new StringET1ExtendedType());
        // 
        domain.addNode(node);
    }
    if (domain.getDataMaps().size() == 1) {
        domain.setDefaultNode(node);
    }
    return domain;
}
Also used : DataDomain(org.apache.cayenne.access.DataDomain) DataNode(org.apache.cayenne.access.DataNode) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) Procedure(org.apache.cayenne.map.Procedure) DataMap(org.apache.cayenne.map.DataMap)

Example 14 with DataNodeDescriptor

use of org.apache.cayenne.configuration.DataNodeDescriptor 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);
}
Also used : RuntimeProperties(org.apache.cayenne.configuration.RuntimeProperties) Injector(org.apache.cayenne.di.Injector) MockDataSourceFactory1(org.apache.cayenne.configuration.mock.MockDataSourceFactory1) DefaultClassLoaderManager(org.apache.cayenne.di.spi.DefaultClassLoaderManager) Module(org.apache.cayenne.di.Module) AdhocObjectFactory(org.apache.cayenne.di.AdhocObjectFactory) Assert.assertSame(org.junit.Assert.assertSame) Slf4jJdbcEventLogger(org.apache.cayenne.log.Slf4jJdbcEventLogger) JdbcEventLogger(org.apache.cayenne.log.JdbcEventLogger) DIBootstrap(org.apache.cayenne.di.DIBootstrap) Key(org.apache.cayenne.di.Key) Before(org.junit.Before) ResourceLocator(org.apache.cayenne.resource.ResourceLocator) Assert.assertNotNull(org.junit.Assert.assertNotNull) MockResourceLocator(org.apache.cayenne.resource.mock.MockResourceLocator) Constants(org.apache.cayenne.configuration.Constants) DefaultAdhocObjectFactory(org.apache.cayenne.di.spi.DefaultAdhocObjectFactory) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) ClassLoaderManager(org.apache.cayenne.di.ClassLoaderManager) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) DataSourceInfo(org.apache.cayenne.conn.DataSourceInfo) Assert.assertFalse(org.junit.Assert.assertFalse) Mockito.mock(org.mockito.Mockito.mock) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) DefaultAdhocObjectFactory(org.apache.cayenne.di.spi.DefaultAdhocObjectFactory) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) Slf4jJdbcEventLogger(org.apache.cayenne.log.Slf4jJdbcEventLogger) Injector(org.apache.cayenne.di.Injector) MockDataSourceFactory1(org.apache.cayenne.configuration.mock.MockDataSourceFactory1) Module(org.apache.cayenne.di.Module) DefaultClassLoaderManager(org.apache.cayenne.di.spi.DefaultClassLoaderManager) RuntimeProperties(org.apache.cayenne.configuration.RuntimeProperties) MockResourceLocator(org.apache.cayenne.resource.mock.MockResourceLocator) ResourceLocator(org.apache.cayenne.resource.ResourceLocator) MockResourceLocator(org.apache.cayenne.resource.mock.MockResourceLocator) Test(org.junit.Test)

Example 15 with DataNodeDescriptor

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

the class DefaultDataSourceFactoryLoaderTest method testGetDataSourceFactory_Implicit.

@Test
public void testGetDataSourceFactory_Implicit() throws Exception {
    DataNodeDescriptor nodeDescriptor = new DataNodeDescriptor();
    nodeDescriptor.setName("node1");
    nodeDescriptor.setDataSourceDescriptor(new DataSourceInfo());
    DelegatingDataSourceFactory factoryLoader = new DelegatingDataSourceFactory();
    injector.injectMembers(factoryLoader);
    DataSourceFactory factory = factoryLoader.getDataSourceFactory(nodeDescriptor);
    assertNotNull(factory);
    assertTrue(factory instanceof XMLPoolingDataSourceFactory);
}
Also used : DataSourceInfo(org.apache.cayenne.conn.DataSourceInfo) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) Test(org.junit.Test)

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