Package com.webobjects.eoaccess

Examples of com.webobjects.eoaccess.EOEntity


                        if (type.equals(EOEditingContext.DeletedKey)) {
                            value = ec.committedSnapshotForObject(eo);
                        }

                        EOEntity source = ERXEOAccessUtilities.entityForEo(eo);

                        if (source.classPropertyNames().containsObject(key)) {
                            value = eo.valueForKey(key);
                        } else {
                            if (eo.isNewObject()) {
                                if (!_warned.containsObject(entityName)) {
                                    log.error("We currently don't support unsaved related objects for this entity: " + entityName);
                                    _warned.addObject(entityName);
                                }
                            } else {
                                EORelationship rel = source.anyRelationshipNamed(key);
                                EOKeyGlobalID sourceGlobalID = (EOKeyGlobalID) ec.globalIDForObject(eo);
                                // AK: I wish I could, but when a relationship
                                // is
                                // not a class prop, there's nothing we can do.
                                // value =
                                // ec.arrayFaultWithSourceGlobalID(sourceGlobalID,
                                // rel.name(), ec);
                                EOFetchSpecification fs = new EOFetchSpecification(rel.destinationEntity().name(), null, null);
                                NSMutableArray<EOQualifier> qualifiers = new NSMutableArray(rel.joins().count());
                                NSDictionary pk = source.primaryKeyForGlobalID(sourceGlobalID);
                                for (Iterator iterator = rel.joins().iterator(); iterator.hasNext();) {
                                    EOJoin join = (EOJoin) iterator.next();
                                    Object pkValue = pk.objectForKey(join.sourceAttribute().name());
                                    EOKeyValueQualifier qualifier = new EOKeyValueQualifier(join.destinationAttribute().name(), EOQualifier.QualifierOperatorEqual, pkValue);
                                    qualifiers.addObject(qualifier);
View Full Code Here


    // FIXME: The ec parameter is not needed, nor used.
    public EOFetchSpecification primaryKeyFetchSpecificationForEntity(EOEditingContext ec, EOQualifier eoqualifier, NSArray sortOrderings, NSArray additionalKeys) {
        String entityName = entityName();
        EOFetchSpecification fs = new EOFetchSpecification(entityName, eoqualifier, sortOrderings);
        fs.setFetchesRawRows(true);
        EOEntity entity = entity(ec);
        NSMutableArray keys = new NSMutableArray(entity.primaryKeyAttributeNames());
        if(additionalKeys != null) {
            keys.addObjectsFromArray(additionalKeys);
        }
        if(entity.restrictingQualifier() != null) {
            NSArray restrict = entity.restrictingQualifier().allQualifierKeys().allObjects();
            keys.addObjectsFromArray(restrict);
        }
        if(entity.isAbstractEntity()) {
            NSArray restrict = (NSArray)entity.subEntities().valueForKeyPath("restrictingQualifier.allQualifierKeys.allObjects.@flatten.@unique");
            keys.addObjectsFromArray(restrict);
        }
        fs.setRawRowKeyPaths(keys);
        return fs;
    }
View Full Code Here

            } else {
                EORelationship relationship = d2wContext.relationship();
                if (relationship != null && !(value instanceof EOEnterpriseObject)) {
                    String keyWhenRelationship = (String)d2wContext.valueForKey("keyWhenRelationship");
                    if (keyWhenRelationship != null) {
                        EOEntity destinationEntity = relationship.destinationEntity();
                        attribute = destinationEntity.attributeNamed(keyWhenRelationship);
                    }
                }
            }

            if (attribute != null) {
View Full Code Here

    /** @return a beautified, localized display name for the current <code>destinationEntity</code> */
    public Object displayNameForDestinationEntity(D2WContext c) {
        Object result = null;
//        if(true) return null;
        EOEntity destinationEntity = (EOEntity)c.valueForKeyPath("smartRelationship.destinationEntity");
        //destinationEntity = (EOEntity)c.valueForKeyPath("destinationEntity");
        if(destinationEntity != null) {
            EOEntity entity = (EOEntity)c.valueForKey("entity");
            c.takeValueForKey(destinationEntity, "entity");
            result = c.valueForKey("displayNameForEntity");
            c.takeValueForKey(entity, "entity");
        }
        return result;
View Full Code Here

     * <b>keyWhenRelationship</b>.
     * @return the current propertyKey + "." + the current value for
     *    keyWhenRelationship.
     */
    public Object keyWhenRelationship(D2WContext context) {
        EOEntity joinEntity=context.entity();
        NSArray relationships=joinRelationshipsForJoinEntity(joinEntity);
       
        EORelationship destinationRelationship=null;
        String originEntityName=(String)context.valueForKeyPath("object.entityName");
        for (Enumeration e=relationships.objectEnumerator(); e.hasMoreElements();) {
View Full Code Here

   // a fake entity that can be used for tasks such as error/confirm..
    private transient EOEntity _dummyEntity;
    public EOEntity dummyEntity() {
        if (_dummyEntity==null) {
            _dummyEntity=new EOEntity();
            _dummyEntity.setName("__Dummy__");
        }
        return _dummyEntity;
    }
View Full Code Here

     */
    public String displayNameForDestinationEntity(D2WContext context) {
        String displayName = null;
        EORelationship relationship = (EORelationship)context.valueForKey("smartRelationship");
        if (relationship != null) {
            EOEntity entity = (EOEntity)context.valueForKey("entity");
            if (entity != null) {
                context.takeValueForKey(relationship.destinationEntity(), "entity");
                displayName = (String)context.valueForKey("displayNameForEntity");
            } else {
                log.warn("Current context: " + context + " doesn't have an entity, very strange, defaulting to destination entity name.");
View Full Code Here

    public static EOFetchSpecification primaryKeyFetchSpecificationForEntity(EOEditingContext ec,
                                                                      String entityName,
                                                                      EOQualifier eoqualifier,
                                                                      NSArray<EOSortOrdering> sortOrderings,
                                                                      NSArray<String> additionalKeys) {
        EOEntity entity = ERXEOAccessUtilities.entityNamed(ec, entityName);
        EOFetchSpecification fs = new EOFetchSpecification(entityName, eoqualifier, sortOrderings);
        fs.setFetchesRawRows(true);
        NSMutableArray<String> keys = new NSMutableArray<String>(entity.primaryKeyAttributeNames());
        if (additionalKeys != null) {
            keys.addObjectsFromArray(additionalKeys);
        }
        fs.setRawRowKeyPaths(keys);
        return fs;
View Full Code Here

    @SuppressWarnings("unchecked")
    public static EOEnterpriseObject objectWithPrimaryKeyValue(EOEditingContext ec,
                                                               String entityName,
                                                               Object primaryKeyValue,
                                                               NSArray prefetchingKeyPaths, boolean refreshRefetchedObjects, boolean throwIfMissing) {
        EOEntity entity = EOUtilities.entityNamed(ec, entityName);
        NSDictionary<String, Object> values;
        if(primaryKeyValue instanceof NSDictionary) {
            values = (NSDictionary<String, Object>)primaryKeyValue;
        else {
            if (entity.primaryKeyAttributes().count() != 1) {
                throw new IllegalStateException("The entity '" + entity.name() + "' has a compound primary key and cannot be used with a single primary key value.");
            }
            values = new NSDictionary<String, Object>(primaryKeyValue, entity.primaryKeyAttributeNames().lastObject());
        }
        NSArray eos;
        if (prefetchingKeyPaths == null && !refreshRefetchedObjects) {
          EOGlobalID gid = entity.globalIDForRow(values);
          EOEnterpriseObject eo = ec.faultForGlobalID(gid, ec);
          if (throwIfMissing) {
            eo.willRead();
          }
          eos = new NSArray<EOEnterpriseObject>(eo);
        }
        else {
          EOQualifier qualfier = EOQualifier.qualifierToMatchAllValues(values);
          EOFetchSpecification fs = new EOFetchSpecification(entityName, qualfier, null);
          // Might as well get fresh stuff
          fs.setRefreshesRefetchedObjects(refreshRefetchedObjects);
          if (prefetchingKeyPaths != null) {
            fs.setPrefetchingRelationshipKeyPaths(prefetchingKeyPaths);
          }
          eos = ec.objectsWithFetchSpecification(fs);
        }
        if (eos.count() > 1) {
          throw new MoreThanOneException("Found multiple objects for the entity '" + entity.name() + "' with primary key value: " + primaryKeyValue);
        }
        if (eos.count() == 0) {
          if (throwIfMissing) {
            throw new EOObjectNotAvailableException("There was no '" + entity.name() + "' found with the id '" + primaryKeyValue + "'.");
          }
          return null;
        }
        return (EOEnterpriseObject)eos.lastObject();
    }
View Full Code Here

                String partialKeyPath=KeyValuePath.keyPathWithoutLastProperty(propertyKey);
                Object rawLastEO=object.valueForKeyPath(partialKeyPath);
                lastEO=rawLastEO instanceof EOEnterpriseObject ? (EOEnterpriseObject)rawLastEO : null;
            }
            if (lastEO!=null) {
                EOEntity entity=EOModelGroup.defaultGroup().entityNamed(lastEO.entityName());
                String lastKey=KeyValuePath.lastPropertyKeyInKeyPath(propertyKey);
                result=entity.attributeNamed(lastKey);
            }
        }
        if (result==null) {
            // default to the basic attribute if the above didnt' work
            if (propertyKey!=null) result=c.attribute();
View Full Code Here

TOP

Related Classes of com.webobjects.eoaccess.EOEntity

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.