Package com.webobjects.eoaccess

Examples of com.webobjects.eoaccess.EOAttribute


      entity = new EOEntity();
      entity.setName(entityName);
      keys = (keys == null ? fieldNamesFromClass(clazz) : keys);
      for (Enumeration iter = keys.objectEnumerator(); iter.hasMoreElements();) {
        String name = (String) iter.nextElement();
        EOAttribute attribute = new EOAttribute();
        attribute.setName(name);
        Method m = methodForName(clazz, name);
        if(m != null) {
          attribute.setClassName(m.getReturnType().getName());
        } else {
          Field f = fieldForName(clazz, name);
          if(f != null) {
            String type = f.getType().getName();
            if("boolean".equals(type)) {
              type = "java.lang.Boolean";
            } else if("int".equals(type)) {
              type = "java.lang.Number";
            } else if("long".equals(type)) {
              type = "java.lang.Number";
            } else if("short".equals(type)) {
              type = "java.lang.Number";
            }

            attribute.setClassName(type);
          }
        }
        entity.addAttribute(attribute);
      }
      classDescription = new EOEntityClassDescription(entity);
View Full Code Here


    return selector.equals(EOSortOrdering.CompareCaseInsensitiveAscending) || selector.equals(EOSortOrdering.CompareCaseInsensitiveDescending);
  }

  public int compare(Ersatz u1, Ersatz u2) {
    for (EOSortOrdering so : sortOrdering) {
      EOAttribute att = entity.attributeNamed(so.key());
      T c1 = (T) u1.get(att);
      T c2 = (T) u2.get(att);
      final int result;
     
      if (c2 == null) {
View Full Code Here

      // it's a plain attribute value comparison
      return new Comparison(rels, entity.attributeNamed(last), operator, value);
    } else {
      // it's a relationship value comparison, let's represent it as attribute comparison
      EORelationship lastRel = entity.relationshipNamed(last);
      EOAttribute srcAtt = asOne(lastRel.sourceAttributes());
      EOAttribute dstAtt = asOne(lastRel.destinationAttributes());
     
      rels.add(lastRel);
      if (value != null) {
        value = ((NSKeyValueCoding) value).valueForKey(dstAtt.name());
      }
      return new Comparison(rels, srcAtt, operator, value);
    }
  }
View Full Code Here

 
 

  protected static void validateEntity(EOEntity entity) throws UnsupportedEntityException {
    NSArray<EOAttribute> pks = entity.primaryKeyAttributes();
    EOAttribute pk;
   
    if (pks.size() != 1) {
      throw new UnsupportedEntityException("Entity " + entity.name() + " must have one primary key attribute");
    } else {
      pk = pks.get(0);
    }
   
    if (entity.classPropertyNames().contains(pk.name())) {
//      if (! pk.isReadOnly()) {
//        // primary key values are assigned node id values therefore shouldn't be possible to overwrite them
//        throw new UnsupportedEntityException("Primary key " + entity.name() + "." + pk.name() + " can only be read only when it's a class property");
//      }
      log.warn("Primary key " + entity.name() + "." + pk.name() + " is class property. Its value shouldn't be set manually.");
    }
   
    try {
      Class<?> valueType;
     
     
      // check primary key type
      valueType = Class.forName(pk.valueTypeClassName());
      if (! Integer.class.equals(valueType) && ! Long.class.equals(valueType)) {
        throw new UnsupportedEntityException("Primary key " + entity.name() + "." + pk.name() + " value type must be integer or long type");
      }
    } catch (ClassNotFoundException e) {
      throw new RuntimeException(e);
    }
  }
View Full Code Here

      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

     * fetch specification will return.
     * @return eo count attribute
     */
    protected static EOAttribute objectCountAttribute() {
        if ( _objectCountAttribute == null ) {
            _objectCountAttribute = new EOAttribute();

            _objectCountAttribute.setName("p_objectCountAttribute");
            _objectCountAttribute.setColumnName("p_objectCountAttribute");
            _objectCountAttribute.setClassName("java.lang.Number");
            _objectCountAttribute.setValueType("i");
View Full Code Here

    /**
     * @param foo
     */
    protected static EOAttribute objectCountUniqueAttribute(EOAttribute foo) {
        EOAttribute tmp = new EOAttribute();

        tmp.setName("p_objectCountUnique"+foo.name());
        tmp.setColumnName("p_objectCountUnique"+foo.name());
        tmp.setClassName("java.lang.Number");
        tmp.setValueType("i");
        tmp.setReadFormat("count( distinct t0."+foo.columnName()+")");
        return tmp;
    }
View Full Code Here

   *            the entity to resolve the keypath on
   * @return the ERXKey.Type for the given keypath, or null if there is no matching key
   */
  public static ERXKey.Type typeForKeyInEntity(String key, EOEntity entity) {
    ERXKey.Type type;
    EOAttribute attribute = entity._attributeForPath(key);
    if (attribute != null) {
      type = ERXKey.Type.Attribute;
    }
    else {
      EORelationship relationship = entity._relationshipForPath(key);
View Full Code Here

        if (null == value) {
            if (d2wContext.valueForKey(ValidationKeys.MinimumInputValue) != null) {
                throw ERXValidationFactory.defaultFactory().createCustomException(null, key, value, "QueryValueRequired");
            }
        } else {
            EOAttribute attribute = d2wContext.attribute();
            String valueType = attribute.valueType();

            if ("s".equals(valueType) || "i".equals(valueType) || "l".equals(valueType)) { // Short or Integer or Long
                long longValue = value.longValue();
                if (hasValidationDefinitionForKey(ValidationKeys.MinimumInputValue)) {
                    Long minimumValue = ERXValueUtilities.longValue(d2wContext().valueForKey(ValidationKeys.MinimumInputValue));
View Full Code Here

            if (null == value && !ERXValueUtilities.booleanValueWithDefault(d2wContext.valueForKey(ValidationKeys.AllowsEmptyQueryValue), true)) {
                throw ERXValidationFactory.defaultFactory().createCustomException(null, propertyKey, value, "QueryValueRequired");
            }

            EOAttribute attribute = null;
            if (ERXValueUtilities.booleanValue(d2wContext.valueForKey("isAttribute"))) {
                attribute = d2wContext.attribute();
            } 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) {
                String valueClassName = attribute.className();
                if (String.class.getName().equals(valueClassName) && value instanceof String) {
                    validateStringValueForKey((String)value, propertyKey);
                } else if (Number.class.getName().equals(valueClassName) || BigDecimal.class.getName().equals(valueClassName)) {
                    validateNumericValueForKey((Number)value, propertyKey);
                }
View Full Code Here

TOP

Related Classes of com.webobjects.eoaccess.EOAttribute

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.