Package com.webobjects.eoaccess

Examples of com.webobjects.eoaccess.EORelationship


                    String key = (String) e.nextElement();
                    EOEntity source = entity;
                    // AK: for now this only handles non-flattened rels
                    for (Enumeration e1 = NSArray.componentsSeparatedByString(key, ".").objectEnumerator(); e1.hasMoreElements();) {
                        String part = (String) e1.nextElement();
                        EORelationship rel = source._relationshipForPath(key);
                        if (rel != null) {
                            if (rel.isFlattened()) {
                                throw new IllegalStateException("Can't handle flattened relations, use the definition: " + rel);
                            }
                            if (rel.isToMany()) {
                                EOEntity destinationEntity = rel.destinationEntity();
                                Configuration destinationConfiguration = configureEntity(destinationEntity);
                                String inverseName = rel.anyInverseRelationship().name();
                                destinationConfiguration.notificationKeys.addObject(inverseName);
                                source = rel.destinationEntity();
                            } else {
                                config.keys.addObject(rel.name());
                            }
                        }
                    }
                }
            }
View Full Code Here


              EOModel parentModel = parentEntity.model();
              _buildDependenciesForModel(parentModel, LATEST_VERSION, versions, migrations);
            }
            Enumeration relationshipsEnum = entity.relationships().objectEnumerator();
            while (relationshipsEnum.hasMoreElements()) {
              EORelationship relationship = (EORelationship) relationshipsEnum.nextElement();
              EOEntity destinationEntity = relationship.destinationEntity();
              if (destinationEntity != null && !destinationEntity.model().equals(model)) {
                EOModel destinationModel = destinationEntity.model();
                _buildDependenciesForModel(destinationModel, LATEST_VERSION, versions, migrations);
              }
            }
View Full Code Here

            EOEnterpriseObject eo = (EOEnterpriseObject) sourceObjects.objectAtIndex(0);
            EOEditingContext ec = eo.editingContext();
            EOEntity entity = EOUtilities.entityForObject(ec, eo);

            EORelationship relationship = entity.relationshipNamed(path);

            if (relationship == null) return;

            batchFetchRelationshipOnSourceObjects(relationship, sourceObjects, skipFaultedSourceObjects);
View Full Code Here

        // ENHANCEME: This should support restrictive qualifiers on the root entity
        @Override
        public EOQualifier schemaBasedQualifierWithRootEntity(EOQualifier eoqualifier, EOEntity eoentity) {
            EOKeyValueQualifier eokeyvaluequalifier = (EOKeyValueQualifier)eoqualifier;
            String key = eokeyvaluequalifier.key();
            EORelationship eorelationship = eoentity._relationshipForPath(key);
            if(eorelationship == null) {
              if(!(eokeyvaluequalifier instanceof ERXInQualifier)) {
                eokeyvaluequalifier = new ERXInQualifier(key, (NSArray) eokeyvaluequalifier.value());
              }
                return eokeyvaluequalifier;
            }
            if(eorelationship.isFlattened()) {
                eorelationship = ERXEOAccessUtilities.lastRelationship(eorelationship);
            }
            NSArray joins = eorelationship.joins();
            int l = joins.count();
            NSMutableArray destinationAttibuteNames = new NSMutableArray(l);
            for(int i = l - 1; i >= 0; i--) {
                destinationAttibuteNames.addObject(((EOJoin)joins.objectAtIndex(i)).destinationAttribute().name());
            }
View Full Code Here

  public ERXQualifierInSubquery(EOQualifier qualifier, String entityName, String relationshipName) {
    this.qualifier = qualifier;
    this.entityName = entityName;
    if(relationshipName != null) {
      this.relationshipName = relationshipName;
      EORelationship rel = ERXEOAccessUtilities.entityNamed(null, entityName).relationshipNamed(relationshipName);
      attributeName = rel.sourceAttributes().lastObject().name();
      destinationAttName = rel.destinationAttributes().lastObject().name();
    }
  }
View Full Code Here

            ERXToManyQualifier qualifier = (ERXToManyQualifier)eoqualifier;
            StringBuilder result = new StringBuilder();
            EOEntity targetEntity=e.entity();

            NSArray<String> toManyKeys=NSArray.componentsSeparatedByString(qualifier.key(),".");
            EORelationship targetRelationship=null;
            for (int i=0; i<toManyKeys.count()-1;i++) {
                targetRelationship= targetEntity.anyRelationshipNamed(toManyKeys.objectAtIndex(i));
                targetEntity=targetRelationship.destinationEntity();
            }
            targetRelationship=targetEntity.relationshipNamed(toManyKeys.lastObject());
            targetEntity=targetRelationship.destinationEntity();

            if (targetRelationship.joins()==null || targetRelationship.joins().isEmpty()) {
                // we have a flattened many to many
                String definitionKeyPath=targetRelationship.definition();                       
                NSArray<String> definitionKeys=NSArray.componentsSeparatedByString(definitionKeyPath,".");
                EOEntity lastStopEntity=targetRelationship.entity();
                EORelationship firstHopRelationship= lastStopEntity.relationshipNamed(definitionKeys.objectAtIndex(0));
                EOEntity endOfFirstHopEntity= firstHopRelationship.destinationEntity();
                EOJoin join= firstHopRelationship.joins().objectAtIndex(0); // assumes 1 join
                EOAttribute sourceAttribute=join.sourceAttribute();
                EOAttribute targetAttribute=join.destinationAttribute();
                EORelationship secondHopRelationship=endOfFirstHopEntity.relationshipNamed(definitionKeys.objectAtIndex(1));
                join= secondHopRelationship.joins().objectAtIndex(0); // assumes 1 join
                EOAttribute secondHopSourceAttribute=join.sourceAttribute();

                NSMutableArray<String> lastStopPKeyPath = toManyKeys.mutableClone();
                lastStopPKeyPath.removeLastObject();
                lastStopPKeyPath.addObject(firstHopRelationship.name());
View Full Code Here

            ERXExistsQualifier existsQualifier = (ERXExistsQualifier)qualifier;
            EOQualifier subqualifier = existsQualifier.subqualifier();
            String baseKeyPath = existsQualifier.baseKeyPath();

            EOEntity baseEntity = expression.entity();
            EORelationship relationship = null;

            // Walk the key path to the last entity.
            if (baseKeyPath != null) {
                for (String path : NSArray.componentsSeparatedByString(baseKeyPath, ".")) {
                    if (null == relationship) {
                        relationship = baseEntity.anyRelationshipNamed(path);
                    } else {
                        relationship = relationship.destinationEntity().anyRelationshipNamed(path);
                    }
                }
            }

            EOEntity srcEntity = relationship != null ? relationship.entity() : baseEntity;
            EOEntity destEntity = relationship != null ? relationship.destinationEntity() : baseEntity;

            // We need to do a bunch of hand-waiving to get the right table aliases for the table used in the exists
            // subquery and for the join clause back to the source table.
            String sourceTableAlias = "t0"; // The alias for the the source table of the baseKeyPath from the main query.
            String destTableAlias; // The alias for the table used in the subquery.
            if (!srcEntity.equals(baseEntity)) { // The exists clause is applied to the different table.
                sqlStringForAttributeNamedInExpression(baseKeyPath, expression);
                destTableAlias = (String)expression.aliasesByRelationshipPath().valueForKey(baseKeyPath);
                if (null == destTableAlias) {
                    destTableAlias = EXISTS_ALIAS + (expression.aliasesByRelationshipPath().count()); // The first entry = "t0".
                    expression.aliasesByRelationshipPath().takeValueForKey(destTableAlias, baseKeyPath);
                }
            } else { // The exists clause is applied to the base table.
                destTableAlias = EXISTS_ALIAS + expression.aliasesByRelationshipPath().count(); // Probably "t1"
            }

            String srcEntityForeignKey = null;
            NSArray<EOAttribute> sourceAttributes = relationship.sourceAttributes();
            if (sourceAttributes != null && sourceAttributes.count() > 0) {
                EOAttribute fk = sourceAttributes.lastObject();
                srcEntityForeignKey = expression.sqlStringForAttribute(fk);
            } else {
              // (AR) could not find relationship from source object into "exists" clause, use primary key then instead
                EOAttribute pk = srcEntity.primaryKeyAttributes().lastObject();
                srcEntityForeignKey = expression.sqlStringForAttribute(pk);
            }
           
            EOJoin parentChildJoin = ERXArrayUtilities.firstObject(relationship.joins());
            String destEntityForeignKey = "." + expression.sqlStringForSchemaObjectName(parentChildJoin.destinationAttribute().columnName());
           
            EOQualifier qual = EOQualifierSQLGeneration.Support._schemaBasedQualifierWithRootEntity(subqualifier, destEntity);
            EOFetchSpecification fetchSpecification = new EOFetchSpecification(destEntity.name(), qual, null, false, true, null);
View Full Code Here

         * @return the SQL string for the attribute
         */
        private String sqlStringForAttributeNamedInExpression(String name, EOSQLExpression expression) {
            NSArray<String> pieces = NSArray.componentsSeparatedByString(name, ".");
            EOEntity entity = expression.entity();
            EORelationship rel;
            EOAttribute att;
            NSMutableArray<EOProperty> path = new NSMutableArray<EOProperty>();
            int numPieces = pieces.count();

            if (numPieces == 1 && null == entity.anyRelationshipNamed(name)) {
                att = entity.anyAttributeNamed(name);
                if (null == att) { return null; }
                return expression.sqlStringForAttribute(att);
            }
           
            for (int i = 0; i < numPieces - 1; i++) {
                rel = entity.anyRelationshipNamed(pieces.objectAtIndex(i));
                if (null == rel) {
                    return null;
                }
                path.addObject(rel);
                entity = rel.destinationEntity();
            }

            String key = pieces.lastObject();
            if (entity.anyRelationshipNamed(key) != null) { // Test first for a relationship.
                rel = entity.anyRelationshipNamed(key);
                if (rel.isFlattened()) {
                    String relPath = rel.relationshipPath();
                    for (String relPart : NSArray.componentsSeparatedByString(relPath, ".")) {
                        rel = entity.anyRelationshipNamed(relPart);
                        path.addObject(rel);
                        entity = rel.destinationEntity();
                    }
                } else {
                    path.addObject(rel);
                }
                att = rel.destinationAttributes().lastObject();
            } else { // The test for an attribute.
                att = entity.anyAttributeNamed(key);
            }

            if (null == att) {
View Full Code Here

        for (Enumeration entityEnum = allEntities().objectEnumerator(); entityEnum.hasMoreElements();) {
            EOEntity entity = (EOEntity) entityEnum.nextElement();
            logger.trace("Finding dependencies of " + entity.name());

            for (Enumeration relationshipEnum = entity.relationships().objectEnumerator(); relationshipEnum.hasMoreElements();) {
                EORelationship relationship = (EORelationship) relationshipEnum.nextElement();

                if (hasForeignKeyConstraint(relationship)) {
                    EOEntity destinationEntity = relationship.destinationEntity();
                    logger.trace("Recording dependency on " + destinationEntity.name());
                    entitiesDependentOn(dependencyList, destinationEntity).addObject(entity.name());
                }
                else {
                    logger.trace("Ignoring, is not FK relationship or vertical inheritance parent");
View Full Code Here

      EOAttribute destinationAttribute = destinationColumns[columnNum]._newAttribute(destinationEntity);
      destinationAttributes.addObject(destinationAttribute);
    }
    destinationEntity.setPrimaryKeyAttributes(destinationAttributes);

    EORelationship relationship = new EORelationship();
    relationship.setName(sourceAttributes.objectAtIndex(0).name() + "_" + destinationAttributes.objectAtIndex(0).name());
    relationship.setEntity(sourceEntity);
   
    for (int attributeNum = 0; attributeNum < sourceAttributes.count(); attributeNum ++) {
      EOJoin join = new EOJoin(sourceAttributes.objectAtIndex(attributeNum), destinationAttributes.objectAtIndex(attributeNum));
      relationship.addJoin(join);
    }
   
    return relationship;
  }
View Full Code Here

TOP

Related Classes of com.webobjects.eoaccess.EORelationship

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.