Package com.webobjects.eoaccess

Examples of com.webobjects.eoaccess.EOEntity


 
  private Comparison convertComparison(EOKeyValueQualifier qual) {
    ComparisonOperator operator = operator(qual.selector());
    String key = qual.key();
    Object value = NSTranslator.instance.toNeutralValue(qual.value(), entity.attributeNamed(key));
    EOEntity currentEntity = entity;
    String [] splits = key.split("\\.");
    Collection<EORelationship> rels = new ArrayList<EORelationship>();
   
    for (int i=0; i<splits.length - 1; i++) {
      EORelationship rel = currentEntity.relationshipNamed(splits[i]);
     
      rels.add(rel);
      currentEntity = rel.destinationEntity();
    }
   
View Full Code Here


                    eo.removeObjectFromBothSidesOfRelationshipWithKey(relatedObject, relationshipName);
                    ec.deleteObject(relatedObject);
                }
            }
            NSArray pickedObjects = (NSArray)eo.valueForKeyPath(relationshipName +"." + pickRelationshipName +".@unique");
            EOEntity entity = ERXEOAccessUtilities.destinationEntityForKeyPath(ERXEOAccessUtilities.entityForEo(eo), relationshipName);
            for(Enumeration e = selectedObjects.objectEnumerator(); e.hasMoreElements(); ) {
                EOEnterpriseObject selectedObject = (EOEnterpriseObject)e.nextElement();
                if(!pickedObjects.containsObject(selectedObject)) {
                    EOEnterpriseObject relatedObject = ERXEOControlUtilities.createAndInsertObject(ec, entity.name());
                    relatedObject.addObjectToBothSidesOfRelationshipWithKey(selectedObject, pickRelationshipName);
                    eo.addObjectToBothSidesOfRelationshipWithKey(relatedObject, relationshipName);
                }
            }
        } finally {
View Full Code Here

  public NSArray referenceEOs() {
    if (_referenceEOs == null) {
      String relationshipName = (String) d2wContext().valueForKey("referenceRelationshipForBackgroupColor");
      if (relationshipName != null) {
        EOEntity entity = EOModelGroup.defaultGroup().entityNamed(entityName());
        EORelationship relationship = entity.relationshipNamed(relationshipName);
        _referenceEOs = EOUtilities.objectsForEntityNamed(EOSharedEditingContext.defaultSharedEditingContext(), relationship.destinationEntity().name());
        _referenceEOs = ERXArrayUtilities.sortedArraySortedWithKey(_referenceEOs, "ordering", EOSortOrdering.CompareAscending);
      }
    }
    return _referenceEOs;
View Full Code Here

    super._followFetchSpecification(fetchSpec, relationshipName, sourceObjects, context);
  }

  @Override
  public void _verifyNoChangesToReadonlyEntity(EODatabaseOperation dbOp) {
    EOEntity entity = dbOp.entity();
    if (entity.isReadOnly()) {
      switch (dbOp.databaseOperator()) {
      case 0: // '\0'
        return;

      case 1: // '\001'
        throw new IllegalStateException("cannot insert object:" + dbOp.object() + " that corresponds to read-only entity: " + entity.name() + " in databaseContext " + this);

      case 3: // '\003'
        throw new IllegalStateException("cannot delete object:" + dbOp.object() + " that corresponds to read-only entity:" + entity.name() + " in databaseContext " + this);

      case 2: // '\002'
        if (!dbOp.dbSnapshot().equals(dbOp.newRow())) {
          throw new IllegalStateException("cannot update '" + dbOp.rowDiffsForAttributes(entity.attributes()).allKeys() + "' keys on object:" + dbOp.object() + " that corresponds to read-only entity: " + entity.name() + " in databaseContext " + this);
        }
        return;
      }
    }
    // HACK: ak these methods are protected, so we call them via KVC
    if (dbOp.databaseOperator() == 2 && ((Boolean) NSKeyValueCoding.Utility.valueForKey(entity, "_hasNonUpdateableAttributes")).booleanValue()) {
      NSArray keys = (NSArray) NSKeyValueCoding.Utility.valueForKey(entity, "dbSnapshotKeys");
      NSDictionary dbSnapshot = dbOp.dbSnapshot();
      NSDictionary newRow = dbOp.newRow();
      for (int i = keys.count() - 1; i >= 0; i--) {
        String key = (String) keys.objectAtIndex(i);
        EOAttribute att = entity.attributeNamed(key);
        // FIX: ak when you have single-table inheritance and in the
        // child there are foreign keys that are not in the parent
        // THEN, if the entity _hasNonUpdateableAttributes (public PK or
        // read only props) the DB op is checked
        // against the attributes. BUT this dictionary has all entries,
        // even from the child (most likely NULL values)
        // and the current implementation doesn't check against the case
        // when the attribute isn't present in the first place.
        // SO we add this check and live happily ever after
        if (att != null && att._isNonUpdateable() && !dbSnapshot.objectForKey(key).equals(newRow.objectForKey(key))) {
          if (att.isReadOnly()) {
            throw new IllegalStateException("cannot update read-only key '" + key + "' on object:" + dbOp.object() + " of entity: " + entity.name() + " in databaseContext " + this);
          }
          throw new IllegalStateException("cannot update primary-key '" + key + "' from '" + dbSnapshot.objectForKey(key) + "' to '" + newRow.objectForKey(key) + "' on object:" + dbOp.object() + " of entity: " + entity.name() + " in databaseContext " + this);
        }
      }

    }
  }
View Full Code Here

        }
    }

    public void indexAllObjects(EOModel model) {
        for (Enumeration entities = model.entities().objectEnumerator(); entities.hasMoreElements();) {
            EOEntity entity = (EOEntity) entities.nextElement();
            indexAllObjects(entity);
        }
    }
View Full Code Here

            if (config == null) {
                config = new ConfigurationEntry();
                configuration.setObjectForKey(config, entityName);
            }

            EOEntity source = ERXEOAccessUtilities.entityNamed(null, entityName);
            for (Enumeration e = keys.objectEnumerator(); e.hasMoreElements();) {
                String keyPath = (String) e.nextElement();
                configureKeyPath(config, keyPath, source);
            }
            return config;
View Full Code Here

            if (rel != null) {
                if (rel.isFlattened()) {
                    ConfigurationEntry c = configureKeyPath(config, rel.definition() + (rest != null ? "." + rest : ""), source);
                    return c;
                }
                EOEntity destinationEntity = rel.destinationEntity();

                ConfigurationEntry destinationConfiguration;
                if (rest != null) {
                    destinationConfiguration = configureEntity(destinationEntity.name(), new NSArray(rest));
                } else {
                    destinationConfiguration = configureEntity(destinationEntity.name(), new NSArray());
                }
                String inverseName = rel.anyInverseRelationship().name();
                destinationConfiguration.notificationKeys.addObject(inverseName);
            } else {
                config.keys.addObject(key);
View Full Code Here

          EOQualifier q = new EOKeyValueQualifier("className", EOQualifier.QualifierOperatorEqual, className);
          NSArray candidates = EOQualifier.filteredArrayWithQualifier(entities, q);
          if(candidates.count() > 1) {
            log.warn("More than one entity found: " + candidates);
          }
          EOEntity entity = (EOEntity) candidates.lastObject();
          if(entity != null) {
            String entityName = entity.name();
            // HACK AK: this relies on you having set up your classes correctly,
            // meaning that you have exactly one final class var per EO class, with the correct
            // superclasses set up (so EOBase gets loaded before EOSubclass)
            if(allClazzes.containsKey(entityName)) {
              _entityName = entityName;
View Full Code Here

     * @param ec am editing context
     * @param i number of primary keys to generate
     * @return array of new primary keys
     */
    public NSArray newPrimaryKeys(EOEditingContext ec, int i) {
        EOEntity entity = entity(ec);
        EODatabaseContext dbc = EODatabaseContext.registeredDatabaseContextForModel(entity.model(), ec);
        dbc.lock();
        try {
          return dbc.availableChannel().adaptorChannel().primaryKeysForNewRowsWithEntity(i, entity);
        } finally {
          dbc.unlock();
View Full Code Here

     * @param dict raw row dictionary
     * @return entity name, if any
     */
    protected String entityNameFromRawRow(EOEditingContext ec, NSDictionary dict) {
        String entityName = entityName();
        EOEntity entity = entity(ec);
        if(entity.isAbstractEntity() && entity.subEntities().count() > 0) {
            for(Enumeration e = entity.subEntities().objectEnumerator(); e.hasMoreElements();) {
                EOEntity sub = (EOEntity)e.nextElement();
                if(sub.restrictingQualifier() != null) {
                    if(sub.restrictingQualifier().evaluateWithObject(dict)) {
                        return sub.name();
                    }
                } else {
                    if(sub.isAbstractEntity()) {
                        // do sth useful?
                    }
                }
            }
        }
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.