Search in sources :

Example 41 with DataNodeDescriptor

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

the class DbImportConfigurationValidator method validate.

public void validate() throws Exception {
    DataNodeDescriptor dataNodeDescriptor = config.createDataNodeDescriptor();
    DbAdapter adapter;
    try {
        DataSource dataSource = injector.getInstance(DataSourceFactory.class).getDataSource(dataNodeDescriptor);
        adapter = injector.getInstance(DbAdapterFactory.class).createAdapter(dataNodeDescriptor, dataSource);
    } catch (Exception ex) {
        throw new Exception("Error creating DataSource or DbAdapter for DataNodeDescriptor (" + dataNodeDescriptor + ")", ex);
    }
    if (adapter != null && !adapter.supportsCatalogsOnReverseEngineering() && !isReverseEngineeringCatalogsEmpty()) {
        String message = "Your database does not support catalogs on reverse engineering. " + "It allows to connect to only one at the moment. " + "Please don't note catalogs in <dbimport> configuration.";
        throw new Exception(message);
    }
}
Also used : DataSourceFactory(org.apache.cayenne.configuration.server.DataSourceFactory) DbAdapter(org.apache.cayenne.dba.DbAdapter) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) DataSource(javax.sql.DataSource)

Example 42 with DataNodeDescriptor

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

the class DBCP2DataSourceFactoryTest method testGetDataSource_InvalidLocation.

@Test
public void testGetDataSource_InvalidLocation() 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.nosuchfile");
    DBCPDataSourceFactory factory = new DBCPDataSourceFactory();
    try {
        factory.getDataSource(nodeDescriptor);
        fail("didn't throw on absent config file");
    } catch (IOException ex) {
    // expected
    }
}
Also used : URLResource(org.apache.cayenne.resource.URLResource) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) IOException(java.io.IOException) URL(java.net.URL) Test(org.junit.Test)

Example 43 with DataNodeDescriptor

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

the class MainDataNodeEditor method setNodeName.

public void setNodeName(String newName) {
    if (node == null) {
        return;
    }
    // validate...
    if (newName == null) {
        throw new ValidationException("Empty DataNode Name");
    }
    ProjectController parent = (ProjectController) getParent();
    DataNodeDefaults oldPref = parent.getDataNodePreferences();
    DataChannelDescriptor dataChannelDescriptor = (DataChannelDescriptor) getApplication().getProject().getRootNode();
    Collection<DataNodeDescriptor> matchingNode = dataChannelDescriptor.getNodeDescriptors();
    Iterator<DataNodeDescriptor> it = matchingNode.iterator();
    while (it.hasNext()) {
        DataNodeDescriptor node = it.next();
        if (node.getName().equals(newName)) {
            // there is an entity with the same name
            throw new ValidationException("There is another DataNode named '" + newName + "'. Use a different name.");
        }
    }
    // passed validation, set value...
    // TODO: fixme....there is a slight chance that domain is different than
    // the one
    // cached node belongs to
    ProjectUtil.setDataNodeName((DataChannelDescriptor) parent.getProject().getRootNode(), node, newName);
    oldPref.copyPreferences(newName);
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) ValidationException(org.apache.cayenne.validation.ValidationException) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) DataNodeDefaults(org.apache.cayenne.modeler.pref.DataNodeDefaults) ProjectController(org.apache.cayenne.modeler.ProjectController)

Example 44 with DataNodeDescriptor

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

the class LinkDataMapUndoableEdit method undo.

@Override
public void undo() throws CannotUndoException {
    if (node != null) {
        node.getDataMapNames().remove(map.getName());
        mediator.fireDataNodeEvent(new DataNodeEvent(this, node));
    }
    if (!unlinkedNodes.isEmpty()) {
        for (DataNodeDescriptor unlinkedNode : unlinkedNodes) {
            unlinkedNode.getDataMapNames().add(map.getName());
            mediator.fireDataNodeEvent(new DataNodeEvent(this, unlinkedNode));
        }
    }
}
Also used : DataNodeEvent(org.apache.cayenne.configuration.event.DataNodeEvent) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor)

Example 45 with DataNodeDescriptor

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

the class PasteUndoableEdit method undo.

@Override
public void undo() throws CannotUndoException {
    RemoveAttributeAction rAttributeAction = actionManager.getAction(RemoveAttributeAction.class);
    RemoveAction rAction = actionManager.getAction(RemoveAction.class);
    RemoveRelationshipAction rRelationShipAction = actionManager.getAction(RemoveRelationshipAction.class);
    RemoveCallbackMethodAction rCallbackMethodAction = actionManager.getAction(RemoveCallbackMethodAction.class);
    RemoveProcedureParameterAction rProcedureParamAction = actionManager.getAction(RemoveProcedureParameterAction.class);
    if (content instanceof DataMap) {
        if (where instanceof DataChannelDescriptor) {
            rAction.removeDataMap((DataMap) content);
        } else if (where instanceof DataNodeDescriptor) {
            rAction.removeDataMapFromDataNode((DataNodeDescriptor) where, (DataMap) content);
        }
    } else if (where instanceof DataMap) {
        if (content instanceof DbEntity) {
            rAction.removeDbEntity(map, (DbEntity) content);
        } else if (content instanceof ObjEntity) {
            rAction.removeObjEntity(map, (ObjEntity) content);
        } else if (content instanceof Embeddable) {
            rAction.removeEmbeddable(map, (Embeddable) content);
        } else if (content instanceof QueryDescriptor) {
            rAction.removeQuery(map, (QueryDescriptor) content);
        } else if (content instanceof Procedure) {
            rAction.removeProcedure(map, (Procedure) content);
        }
    } else if (where instanceof DbEntity) {
        if (content instanceof DbEntity) {
            rAction.removeDbEntity(map, (DbEntity) content);
        } else if (content instanceof DbAttribute) {
            rAttributeAction.removeDbAttributes(map, (DbEntity) where, new DbAttribute[] { (DbAttribute) content });
        } else if (content instanceof DbRelationship) {
            rRelationShipAction.removeDbRelationships((DbEntity) where, new DbRelationship[] { (DbRelationship) content });
        }
    } else if (where instanceof ObjEntity) {
        if (content instanceof ObjEntity) {
            rAction.removeObjEntity(map, (ObjEntity) content);
        } else if (content instanceof ObjAttribute) {
            rAttributeAction.removeObjAttributes((ObjEntity) where, new ObjAttribute[] { (ObjAttribute) content });
        } else if (content instanceof ObjRelationship) {
            rRelationShipAction.removeObjRelationships((ObjEntity) where, new ObjRelationship[] { (ObjRelationship) content });
        } else if (content instanceof ObjCallbackMethod) {
            ObjCallbackMethod[] methods = new ObjCallbackMethod[] { (ObjCallbackMethod) content };
            for (ObjCallbackMethod callbackMethod : methods) {
                rCallbackMethodAction.removeCallbackMethod(methods[0].getCallbackType(), callbackMethod.getName());
            }
        }
    } else if (where instanceof Procedure) {
        final Procedure procedure = (Procedure) where;
        if (content instanceof ProcedureParameter) {
            rProcedureParamAction.removeProcedureParameters(procedure, new ProcedureParameter[] { (ProcedureParameter) content });
        }
    } else if (where instanceof Embeddable) {
        if (content instanceof Embeddable) {
            rAction.removeEmbeddable(map, (Embeddable) content);
        } else if (content instanceof EmbeddableAttribute) {
            rAttributeAction.removeEmbeddableAttributes((Embeddable) where, new EmbeddableAttribute[] { (EmbeddableAttribute) content });
        }
    }
}
Also used : ProcedureParameter(org.apache.cayenne.map.ProcedureParameter) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) ObjRelationship(org.apache.cayenne.map.ObjRelationship) ObjAttribute(org.apache.cayenne.map.ObjAttribute) DbAttribute(org.apache.cayenne.map.DbAttribute) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) DataMap(org.apache.cayenne.map.DataMap) Embeddable(org.apache.cayenne.map.Embeddable) RemoveProcedureParameterAction(org.apache.cayenne.modeler.action.RemoveProcedureParameterAction) QueryDescriptor(org.apache.cayenne.map.QueryDescriptor) ObjEntity(org.apache.cayenne.map.ObjEntity) DbEntity(org.apache.cayenne.map.DbEntity) DbRelationship(org.apache.cayenne.map.DbRelationship) RemoveCallbackMethodAction(org.apache.cayenne.modeler.action.RemoveCallbackMethodAction) Procedure(org.apache.cayenne.map.Procedure) RemoveRelationshipAction(org.apache.cayenne.modeler.action.RemoveRelationshipAction) EmbeddableAttribute(org.apache.cayenne.map.EmbeddableAttribute) RemoveAction(org.apache.cayenne.modeler.action.RemoveAction) ObjCallbackMethod(org.apache.cayenne.modeler.editor.ObjCallbackMethod) RemoveAttributeAction(org.apache.cayenne.modeler.action.RemoveAttributeAction)

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