Search in sources :

Example 41 with DataChannelDescriptor

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

the class XMLDataChannelDescriptorLoader method load.

@Override
public ConfigurationTree<DataChannelDescriptor> load(Resource configurationResource) throws ConfigurationException {
    if (configurationResource == null) {
        throw new NullPointerException("Null configurationResource");
    }
    URL configurationURL = configurationResource.getURL();
    logger.info("Loading XML configuration resource from " + configurationURL);
    final DataChannelDescriptor descriptor = new DataChannelDescriptor();
    descriptor.setConfigurationSource(configurationResource);
    descriptor.setName(nameMapper.configurationNodeName(DataChannelDescriptor.class, configurationResource));
    try (InputStream in = configurationURL.openStream()) {
        XMLReader parser = xmlReaderProvider.get();
        LoaderContext loaderContext = new LoaderContext(parser, handlerFactory);
        loaderContext.addDataMapListener(dataMap -> descriptor.getDataMaps().add(dataMap));
        DataChannelHandler rootHandler = new DataChannelHandler(this, descriptor, loaderContext);
        parser.setContentHandler(rootHandler);
        parser.setErrorHandler(rootHandler);
        InputSource input = new InputSource(in);
        input.setSystemId(configurationURL.toString());
        parser.parse(input);
        loaderContext.dataChannelLoaded(descriptor);
    } catch (Exception e) {
        throw new ConfigurationException("Error loading configuration from %s", e, configurationURL);
    }
    // TODO: andrus 03/10/2010 - actually provide load failures here...
    return new ConfigurationTree<>(descriptor, null);
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) InputSource(org.xml.sax.InputSource) ConfigurationTree(org.apache.cayenne.configuration.ConfigurationTree) ConfigurationException(org.apache.cayenne.ConfigurationException) InputStream(java.io.InputStream) URL(java.net.URL) XMLReader(org.xml.sax.XMLReader) IOException(java.io.IOException) ConfigurationException(org.apache.cayenne.ConfigurationException)

Example 42 with DataChannelDescriptor

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

the class ProjectUtil method findObjAttributesForDbRelationship.

public static Collection<ObjAttribute> findObjAttributesForDbRelationship(ProjectController mediator, DbRelationship relationship) {
    DataChannelDescriptor domain = (DataChannelDescriptor) mediator.getProject().getRootNode();
    List<ObjAttribute> attributes = new ArrayList<>();
    String[] dbAttrPathByDot;
    if (domain != null) {
        for (DataMap map : domain.getDataMaps()) {
            for (ObjEntity entity : map.getObjEntities()) {
                for (ObjAttribute objAttribute : entity.getAttributes()) {
                    if (objAttribute.getDbAttributePath() != null) {
                        dbAttrPathByDot = objAttribute.getDbAttributePath().split(Pattern.quote("."));
                        for (String partOfPath : dbAttrPathByDot) {
                            if (partOfPath.equals(relationship.getName())) {
                                attributes.add(objAttribute);
                            }
                        }
                    }
                }
            }
        }
    }
    return attributes;
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) ObjEntity(org.apache.cayenne.map.ObjEntity) ObjAttribute(org.apache.cayenne.map.ObjAttribute) ArrayList(java.util.ArrayList) DataMap(org.apache.cayenne.map.DataMap)

Example 43 with DataChannelDescriptor

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

the class ProjectUtil method findObjRelationshipsForDbRelationship.

public static Collection<ObjRelationship> findObjRelationshipsForDbRelationship(ProjectController mediator, DbRelationship relationship) {
    DataChannelDescriptor domain = (DataChannelDescriptor) mediator.getProject().getRootNode();
    List<ObjRelationship> objRelationships = new ArrayList<>();
    if (domain != null) {
        for (DataMap map : domain.getDataMaps()) {
            for (ObjEntity entity : map.getObjEntities()) {
                for (ObjRelationship objRelationship : entity.getRelationships()) {
                    if (objRelationship.getDbRelationships().contains(relationship)) {
                        objRelationships.add(objRelationship);
                    }
                }
            }
        }
    }
    return objRelationships;
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) ObjRelationship(org.apache.cayenne.map.ObjRelationship) ObjEntity(org.apache.cayenne.map.ObjEntity) ArrayList(java.util.ArrayList) DataMap(org.apache.cayenne.map.DataMap)

Example 44 with DataChannelDescriptor

use of org.apache.cayenne.configuration.DataChannelDescriptor 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);
    }
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) DbEntity(org.apache.cayenne.map.DbEntity) Entity(org.apache.cayenne.map.Entity) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) AttributeDisplayEvent(org.apache.cayenne.modeler.event.AttributeDisplayEvent) ObjEntity(org.apache.cayenne.map.ObjEntity) EntityDisplayEvent(org.apache.cayenne.modeler.event.EntityDisplayEvent) DbEntity(org.apache.cayenne.map.DbEntity) Attribute(org.apache.cayenne.map.Attribute) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) DataMap(org.apache.cayenne.map.DataMap)

Example 45 with DataChannelDescriptor

use of org.apache.cayenne.configuration.DataChannelDescriptor 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);
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) DataNodeDisplayEvent(org.apache.cayenne.modeler.event.DataNodeDisplayEvent) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor)

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