Package com.webobjects.eoaccess

Examples of com.webobjects.eoaccess.EORelationship


      NSArray<String> keys = NSArray.componentsSeparatedByString(keyPath, ".");
      EOEntity ent = entity();

      for (int i = 0; i < keys.count(); i++) {
        String k = keys.objectAtIndex(i);
        EORelationship rel = ent.anyRelationshipNamed(k);
        if (rel == null) {
          // it may be an attribute
          if (ent.anyAttributeNamed(k) != null) {
            break;
          }
          throw new IllegalArgumentException("relationship " + keyPath + " generated null");
        }
        ent = rel.destinationEntity();
      }
      return ent;
    }
View Full Code Here


       
        NSArray<String> k;
        EOEntity rightEntity;
        EOEntity leftEntity;
        String relationshipKey = null;
        EORelationship r;
       
       
        if (leftAlias.equals("t0")) {
            leftEntity = entity();
        } else {
            k = aliasesByRelationshipPath().allKeysForObject(leftAlias);
            relationshipKey = k.count()>0? (String)k.lastObject() : "";
            leftEntity = entityForKeyPath(relationshipKey);
        }
       
        if (rightAlias.equals("t0")) {
            rightEntity = entity();
        } else {
            k = aliasesByRelationshipPath().allKeysForObject(rightAlias);
            relationshipKey = k.count()>0? (String)k.lastObject() : "";
            rightEntity = entityForKeyPath(relationshipKey);
        }
        int dotIndex = relationshipKey.indexOf( "." );
        relationshipKey = dotIndex == -1
            ? relationshipKey
            : relationshipKey.substring( relationshipKey.lastIndexOf( "." ) + 1 );
        r = rightEntity.anyRelationshipNamed( relationshipKey );
        // fix from Michael Müller for the case Foo.fooBars.bar has a Bar.foo relationship (instead of Bar.foos)
        if( r == null || r.destinationEntity() != leftEntity ) {
            r = leftEntity.anyRelationshipNamed( relationshipKey );
        }
        //timc 2006-02-26 IMPORTANT or quotes are ignored and mixed case field names won't work
        String rightTable;
        String leftTable;
        if(enableIdentifierQuoting()) {
            rightTable = rightEntity.valueForSQLExpression(this);
            leftTable = leftEntity.valueForSQLExpression(this);
        } else {
            rightTable = rightEntity.externalName();
            leftTable = leftEntity.externalName();
        }
        JoinClause jc = new JoinClause();
       
        jc.setTable1(leftTable, leftAlias);
       
        switch (semantic) {
            case EORelationship.LeftOuterJoin:
                jc.op = " LEFT OUTER JOIN ";
                break;
            case EORelationship.RightOuterJoin:
                jc.op = " RIGHT OUTER JOIN ";
                break;
            case EORelationship.FullOuterJoin:
                jc.op = " FULL OUTER JOIN ";
                break;
            case EORelationship.InnerJoin:
                jc.op = " INNER JOIN ";
                break;
        }
       
        jc.table2 = rightTable + " " + rightAlias;
        NSArray<EOJoin> joins = r.joins();
        int joinsCount = joins.count();
        NSMutableArray<String> joinStrings = new NSMutableArray<String>(joinsCount);
        for( int i = 0; i < joinsCount; i++ ) {
            EOJoin currentJoin = joins.objectAtIndex(i);
            String left;
View Full Code Here

        NSArray keys = NSArray.componentsSeparatedByString(keyPath, ".");
        EOEntity ent = entity();
       
        for (int i = 0; i < keys.count(); i++) {
            String k = (String)keys.objectAtIndex(i);
            EORelationship rel = ent.anyRelationshipNamed(k);
            if (rel == null) {
                // it may be an attribute
                if (ent.anyAttributeNamed(k) != null) {
                    break;
                }
                throw new IllegalArgumentException("relationship " + keyPath + " generated null");
            }
            ent = rel.destinationEntity();
        }
        return ent;
    }
View Full Code Here

        if (_parentList==null) {
            // FIXME this list should be shared with all other JSTwoLevel.. sharing the same sourceEntityName!
            String entityName=(String)valueForBinding("sourceEntityName");
            EOEditingContext ec=((EOEnterpriseObject)valueForBinding("sourceObject")).editingContext();
            EOEntity sourceEntity=EOUtilities.entityNamed(ec,entityName);
            EORelationship r1=sourceEntity.relationshipNamed((String)valueForBinding("relationshipKey"));
            EOEntity childEntity=r1.destinationEntity();
            EORelationship r2= childEntity.relationshipNamed((String)valueForBinding("restrictingRelationshipKey"));
            EOEntity parentEntity=r2.destinationEntity();
            NSArray unsortedList=EOUtilities.objectsForEntityNamed(ec,parentEntity.name());
            EOSortOrdering sortOrdering=new EOSortOrdering((String)valueForBinding("restrictingRelationshipSortKey"),
                                                           EOSortOrdering.CompareAscending);
            NSMutableArray sortArray=new NSMutableArray(sortOrdering);
            String secondarySortKey=(String)valueForBinding("restrictingSecondarySortKey");
View Full Code Here

                Object _source = sourceObject();
                EOEditingContext ec = editingContext();
                EOEntity destinationEntity = null;
               
                if(_source instanceof EOEnterpriseObject) {
                    EORelationship relationship = ERXUtilities.relationshipWithObjectAndKeyPath((EOEnterpriseObject)_source, relationshipKey());
                   
                    destinationEntity = relationship != null ? relationship.destinationEntity() : null;
                } else {
                    String anEntityName = sourceEntityName();
                    if(anEntityName != null) {
                        EOEntity anEntity = ERXEOAccessUtilities.entityNamed(ec, anEntityName);
                        if (anEntity == null) {
View Full Code Here

            EOEntity currentEntity = (EOEntity) group.objectAtIndex(i);
            if (currentEntity.externalName() != null) {
                NSArray relationships = currentEntity.relationships();
                int relCount = relationships.count();
                for (int j = 0; j < relCount; j++) {
                    EORelationship currentRelationship = ((EORelationship) relationships.objectAtIndex(j));
                    if (_shouldGenerateForeignKeyConstraints(currentRelationship)) {
                        NSArray statements = foreignKeyConstraintStatementsForRelationship(currentRelationship);
                        if (!generatedStatements.containsObject(statements.valueForKey("statement"))) {
                            result.addObjectsFromArray(statements);
                            generatedStatements.addObject(statements.valueForKey("statement"));
View Full Code Here

     * @return relationship object corresponding to the last property key of
     *     the key path.
     */
    public static EORelationship relationshipWithObjectAndKeyPath(EOEnterpriseObject object, String keyPath) {
        EOEnterpriseObject lastEO = relationshipObjectWithObjectAndKeyPath(object, keyPath);
        EORelationship relationship = null;
       
        if (lastEO!=null) {
            EOEntity entity=ERXEOAccessUtilities.entityNamed(object.editingContext(), lastEO.entityName());
            String lastKey=ERXStringUtilities.lastPropertyKeyInKeyPath(keyPath);
            relationship=entity.relationshipNamed(lastKey);
View Full Code Here

            return d;
        }

        while (keyPath.indexOf(".") != -1) {
            String key = ERXStringUtilities.firstPropertyKeyInKeyPath(keyPath);
            EORelationship rel = srcentity.relationshipNamed(key);
            if (rel == null) {
                break;
            }
            srcentity = rel.destinationEntity();
            keyPath = ERXStringUtilities.keyPathWithoutFirstProperty(keyPath);
        }
        NSDictionary d = new NSDictionary(new Object[]{srcentity, keyPath}, new Object[]{"entity", "keyPath"});
        return d;
    }
View Full Code Here

        EOEditingContext ec = handler.editingContext();
        EOEnterpriseObject source = ec.faultForGlobalID(handler.sourceGlobalID(), ec);
        if (source instanceof AutoBatchFaultingEnterpriseObject) {
          String key = handler.relationshipName();
          EOEntityClassDescription cd = (EOEntityClassDescription) source.classDescription();
          EORelationship relationship = cd.entity().relationshipNamed(key);
          if (_handler.batchSizeForRelationship(ec, relationship) > 0) {
            markStart("ToMany.Calculation", source, key);
            NSArray<EOEnterpriseObject> candidates = null;
            NSArray currentObjects = (NSArray) ERXThreadStorage.valueForKey(THREAD_KEY);
            boolean fromThreadStorage = false;
            if (currentObjects != null) {
              NSMutableArray<EOEnterpriseObject> tmpList = new NSMutableArray<EOEnterpriseObject>();
              for (Object tmpItem : currentObjects) {
                if (tmpItem instanceof AutoBatchFaultingEnterpriseObject) {
                  tmpList.add((EOEnterpriseObject) tmpItem);
                }
              }
              if (tmpList.count() > 0) {
                candidates = tmpList;
                fromThreadStorage = true;
              }
            }
            if (candidates == null) {
              candidates = ec.registeredObjects();
            }
            long timestamp = ((AutoBatchFaultingEnterpriseObject) source).batchFaultingTimeStamp();
            NSMutableArray<EOEnterpriseObject> eos = new NSMutableArray<EOEnterpriseObject>();
            NSMutableArray faults = new NSMutableArray();
            for (EOEnterpriseObject current : candidates) {
              if (current instanceof AutoBatchFaultingEnterpriseObject) {
                AutoBatchFaultingEnterpriseObject currentEO = (AutoBatchFaultingEnterpriseObject) current;
                if (currentEO.batchFaultingTimeStamp() == timestamp || fromThreadStorage) {
                  if (!EOFaultHandler.isFault(currentEO) && currentEO.classDescription() == source.classDescription()) {
                    Object fault = currentEO.storedValueForKey(key);
                    if (EOFaultHandler.isFault(fault)) {
                      faults.addObject(fault);
                      eos.addObject(currentEO);
                      if (eos.count() == autoBatchFetchSize()) {
                        break;
                      }
                    }
                  }
                }
              }
            }
            markEnd("ToMany.Calculation", source, key);
            if (eos.count() > 1) {
              markStart("ToMany.Fetching", source, key);
              doFetch(dbc, ec, relationship, eos);
              int cnt = 0;
              for(Object fault: faults) {
                if(!EOFaultHandler.isFault(fault)) {
                  NSArray array = (NSArray)fault;
                  freshenFetchTimestamps(array, timestamp);
                  cnt += array.count();
                }
              }
              markEnd("ToMany.Fetching", source, key);
              if(batchLog.isDebugEnabled()) {
                batchLog.debug("Fetched " + cnt + " to-many " + relationship.destinationEntity().name() + " from " + eos.count() " " + source.entityName() + " for " + key);
              }
              return EOFaultHandler.isFault(obj);
            }
          }
        }
View Full Code Here

        String key = eo.batchFaultingRelationshipName();
        if(sourceGID != null && key != null) {
          EOEditingContext ec = eo.editingContext();
          AutoBatchFaultingEnterpriseObject source = (AutoBatchFaultingEnterpriseObject) ec.faultForGlobalID(sourceGID, ec);
          EOEntityClassDescription cd = (EOEntityClassDescription)source.classDescription();
          EORelationship relationship = cd.entity().relationshipNamed(key);
          if(_handler.batchSizeForRelationship(ec, relationship) > 0 && !relationship.isToMany()) {
            markStart("ToOne.Calculation", source, key);
            long timestamp = source.batchFaultingTimeStamp();
            boolean fromThreadStorage = false;
            NSMutableArray<EOEnterpriseObject> eos = new NSMutableArray<EOEnterpriseObject>();
            NSMutableSet faults = new NSMutableSet();
            NSArray<EOEnterpriseObject> candidates = null;
            NSArray currentObjects = (NSArray) ERXThreadStorage.valueForKey(THREAD_KEY);
            if (currentObjects != null) {
              NSMutableArray<EOEnterpriseObject> tmpList = new NSMutableArray<EOEnterpriseObject>();
              for (Object tmpItem : currentObjects) {
                if (tmpItem instanceof AutoBatchFaultingEnterpriseObject) {
                  tmpList.add((EOEnterpriseObject) tmpItem);
                }
              }
              if (tmpList.count() > 0) {
                candidates = tmpList;
                fromThreadStorage = true;
              }
            }
            if (candidates == null) {
              candidates = ec.registeredObjects();
            }
            for (EOEnterpriseObject current : candidates) {
              if (current instanceof AutoBatchFaultingEnterpriseObject) {
                AutoBatchFaultingEnterpriseObject currentEO = (AutoBatchFaultingEnterpriseObject) current;
                if(currentEO.batchFaultingTimeStamp() == timestamp || fromThreadStorage) {
                  if(source.classDescription() == currentEO.classDescription()) {
                    if(!EOFaultHandler.isFault(currentEO)) {
                      Object fault = currentEO.storedValueForKey(key);
                      if(EOFaultHandler.isFault(fault)) {
                        faults.addObject(fault);
                        eos.addObject(currentEO);
                        if(eos.count() == autoBatchFetchSize()) {
                          break;
                        }
                      }
                    }
                  }
                }
              }
            }

            markEnd("ToOne.Calculation", source, key);
            if(eos.count() > 1) {
              markStart("ToOne.Fetching", source, key);
              doFetch(dbc, ec, relationship, eos);
              freshenFetchTimestamps(faults.allObjects(), timestamp);
              markEnd("ToOne.Fetching", source, key);
              if(batchLog.isDebugEnabled()) {
                batchLog.debug("Fetched " + faults.count() + " to-one " + relationship.destinationEntity().name() + " from " + eos.count() " " + source.entityName() + " for " + key);
              }
              return EOFaultHandler.isFault(eo);
            }
          }
        }
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.