Package com.webobjects.eoaccess

Examples of com.webobjects.eoaccess.EORelationship


           
            if(foreignAttribute == null) {
                foreignAttribute = addAttributeNamed(targetEntity, selectedName+"id", selectedPK.prototype());
            }
           
            EORelationship relationship = new EORelationship();
            relationship.setName(targetName+(isToMany ? "s" : ""));
            selectedEntity.addRelationship(relationship);

           
            EOJoin join = new EOJoin(selectedPK, foreignAttribute);
            relationship.addJoin(join);
            relationship.setToMany(isToMany);
            relationship.setJoinSemantic(EORelationship.InnerJoin);
           
            if(addBack) {
                relationship = new EORelationship();
                join = new EOJoin(foreignAttribute,selectedPK);
                relationship.setName(selectedName);
                targetEntity.addRelationship(relationship);
                relationship.addJoin(join);
                relationship.setToMany(false);
                relationship.setJoinSemantic(EORelationship.InnerJoin);
            }
        }
View Full Code Here


                relationship.setToMany(false);
                relationship.setJoinSemantic(EORelationship.InnerJoin);
            }
        }
        public void addBackRelationship(EOEntity selectedEntity, EOEntity targetEntity, EOAttribute foreignAttribute, boolean isToMany, boolean addBack) {
            EORelationship relationship = new EORelationship();
            String targetName = targetEntity.name().toLowerCase();
            String selectedName = selectedEntity.name().toLowerCase();
            EOAttribute selectedPK = (EOAttribute)targetEntity.primaryKeyAttributes().objectAtIndex(0);

            if(foreignAttribute == null) {
                foreignAttribute = addAttributeNamed(selectedEntity, targetName+"id", selectedPK.prototype());
            }
            relationship.setName(targetName+(isToMany ? "s" : ""));
            selectedEntity.addRelationship(relationship);

            EOJoin join = new EOJoin(foreignAttribute,selectedPK);
            relationship.addJoin(join);
            relationship.setToMany(isToMany);
            relationship.setJoinSemantic(EORelationship.InnerJoin);
        }
View Full Code Here

            addRelationship(null, true, true);
            return null;
        }

        public EORelationship addFlattenedRelationshipWithNamePathToEntity(String name, String path, EOEntity entity) {
            relationship = new EORelationship();
            relationship.setName(name);
            relationship.setDefinition(path);
            relationship.setJoinSemantic(EORelationship.InnerJoin);
            selectedEntity.addRelationship(relationship);
            return relationship;
View Full Code Here

      if (eos.count() > 0) {
        EOEnterpriseObject eo = (EOEnterpriseObject)eos.lastObject();
        String entityName = eo.entityName();
        EOEditingContext ec = eo.editingContext();
        EOEntity entity = ERXEOAccessUtilities.entityNamed(ec, entityName);
        EORelationship relationship = entity.relationshipNamed(relKey);
        if(relationship.sourceAttributes().count() == 1) {
          EOAttribute attribute = relationship.sourceAttributes().lastObject();
          EODatabaseContext context = EOUtilities.databaseContextForModelNamed(ec, entity.model().name());
          String name = attribute.name();
          for (Enumeration e = eos.objectEnumerator(); e.hasMoreElements();) {
            EOEnterpriseObject target = (EOEnterpriseObject) e.nextElement();
            Object value = (context.snapshotForGlobalID(ec.globalIDForObject(target))).valueForKey(name);
View Full Code Here

        NSMutableArray<EOProperty> result = new NSMutableArray<EOProperty>();
        String[] parts = keyPath.split("\\.");
        String part;
        for (int i = 0; i < parts.length - 1; i++) {
            part = parts[i];
            EORelationship relationship = entity.anyRelationshipNamed(part);
            if(relationship == null) {
              // CHECKME AK:  it would probably be better to return null
              // to indicate that this is not a valid path?
              return NSArray.EmptyArray;
            }
            entity = relationship.destinationEntity();
            result.addObject(relationship);
        }
        part = parts[parts.length-1];
        EOAttribute attribute = entity.anyAttributeNamed(part);
        if(attribute == null) {
            EORelationship relationship = entity.anyRelationshipNamed(part);
            if(relationship == null) {
                throw new IllegalArgumentException("Last element is not an attribute nor a relationship: " + keyPath);
            }
            if (relationship.isFlattened()) {
              NSArray<EOProperty> path = attributePathForKeyPath(entity, relationship.definition());
              result.addObjectsFromArray(path);
              return result;
            }
            attribute = relationship.joins().lastObject().sourceAttribute();
         }
        result.addObject(attribute);
        return result;
    }
View Full Code Here

        if(keyPath == null || keyPath.length() == 0) {
            return entity;
        }
        NSArray<String> keyArray = NSArray.componentsSeparatedByString(keyPath, ".");
        for(String key : keyArray) {
            EORelationship rel = entity.anyRelationshipNamed(key);
            if(rel == null) {
                if(entity.anyAttributeNamed(key) == null) {
                  if(key.indexOf("@") != 0) {
                    if(!_keysWithWarning.contains(key + "-" + entity)) {
                      _keysWithWarning.add(key + "-" + entity);
                      log.warn("No relationship or attribute <" + key + "> in entity: " + entity);
                    }
                  }
                }
                return null;
            }
            entity = rel.destinationEntity();
        }
        return entity;
    }
View Full Code Here

       
        NSArray parentRelationships = (NSArray) entity.parentEntity().relationships().valueForKey("name");
        NSArray relationships = entity.relationships();
       
        for (int i = relationships.count(); i-- > 0;) {
            EORelationship element = (EORelationship) relationships.objectAtIndex(i);
            if ((element.isToMany() && includeToManyRelationships)
                    || (!element.isToMany() && includeToOneRelationships)) {
                String name = element.name();
                if (cpNames.containsObject(name) && !parentRelationships.containsObject(name)) {
                    ret.addObject(element);
                }
            }
        }
View Full Code Here

     * @param relationshipName name of relationship on entity
     * @return source attribute for the relationship
     */
    public static EOAttribute sourceAttributeForRelationship(EOEntity entity, String relationshipName)
    {
        EORelationship relationship = entity.relationshipNamed(relationshipName);
        return sourceAttributeForRelationship(relationship);
    }
View Full Code Here

     * @param relationshipName name of relationship on entity
     * @return the external column name for the source attribute for the relationship
     */
    public static String sourceColumnForRelationship(EOEntity entity, String relationshipName)
    {
        EORelationship relationship = entity.relationshipNamed(relationshipName);
        return sourceColumnForRelationship(relationship);
    }
View Full Code Here

                log.error("Changed value found that isn't an attribute: " + key + "->" + changedValues.objectForKey(key));
            }
        }

        for (Enumeration enumerator = relationships.objectEnumerator(); enumerator.hasMoreElements();) {
            EORelationship relationship = (EORelationship) enumerator.nextElement();
            NSMutableDictionary pk = EOUtilities.destinationKeyForSourceObject(ec, eo, relationship.name()).mutableClone();
            for (int i=0; i<keys.count(); i++) {
                String key = (String)keys.objectAtIndex(i);
                if(pk.objectForKey(key) != null) {
                    Object val = changedValues.objectForKey(key);
                    pk.setObjectForKey(val, key);
                }
            }
            EOEntity destEnt = relationship.destinationEntity();
            EOGlobalID gid = destEnt.globalIDForRow(pk);
            if(gid != null) {
                EOEnterpriseObject destEO = ec.faultForGlobalID(gid, ec);
                eo.takeValueForKey(destEO, relationship.name());
            } else {
                throw new NullPointerException("Gid is null: " + pk);
            }
        }
    }
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.