Package com.webobjects.eoaccess

Examples of com.webobjects.eoaccess.EOAttribute


    boolean numericPKs = false;
    if (classDescription instanceof EOEntityClassDescription) {
      EOEntity entity = ((EOEntityClassDescription)classDescription).entity();
      NSArray primaryKeyAttributes = entity.primaryKeyAttributes();
      if (primaryKeyAttributes.count() == 1) {
        EOAttribute primaryKeyAttribute = (EOAttribute) primaryKeyAttributes.objectAtIndex(0);
        Class primaryKeyClass = _NSUtilities.classWithName(primaryKeyAttribute.className());
        numericPKs = primaryKeyClass != null && Number.class.isAssignableFrom(primaryKeyClass);
      }
    }
    return numericPKs;
  }
View Full Code Here


    }
    for (EOModel model : (NSArray<EOModel>)models()) {
      for (EOEntity entity : (NSArray<EOEntity>)model.entities()) {
        for (EORelationship relationship : (NSArray<EORelationship>)entity.relationships()) {
          for (EOJoin join : (NSArray<EOJoin>)relationship.joins()) {
            EOAttribute sourceAttribute = join.sourceAttribute();
            EOAttribute destinationAttribute = join.destinationAttribute();
            if (sourceAttribute != null && destinationAttribute != null) {
              if (ObjectUtils.notEqual(sourceAttribute.className(), destinationAttribute.className()) || ObjectUtils.notEqual(sourceAttribute.valueType(), destinationAttribute.valueType())) {
                if (!ERXProperties.booleanForKey("er.extensions.ERXModelGroup." + sourceAttribute.entity().name() + "." + sourceAttribute.name() + ".ignoreTypeMismatch")) {
                  throw new RuntimeException("The attribute " + sourceAttribute.name() + " in " + sourceAttribute.entity().name() + " (" + sourceAttribute.className() + ", " + sourceAttribute.valueType() + ") is a foreign key to " + destinationAttribute.name() + " in " + destinationAttribute.entity().name() + " (" + destinationAttribute.className() + ", " + destinationAttribute.valueType() + ") but their class names or value types do not match.  If this is actually OK, you can set er.extensions.ERXModelGroup." + sourceAttribute.entity().name() + "." + sourceAttribute.name() + ".ignoreTypeMismatch=true in your Properties file.");
                }
              }
            }
          }
        }
View Full Code Here

   */
  protected void preloadERXConstantClassesForModel(EOModel model) {
    for (Enumeration entitiesEnum = model.entities().objectEnumerator(); entitiesEnum.hasMoreElements();) {
      EOEntity entity = (EOEntity) entitiesEnum.nextElement();
      for (Enumeration attributesEnum = entity.attributes().objectEnumerator(); attributesEnum.hasMoreElements();) {
        EOAttribute attribute = (EOAttribute) attributesEnum.nextElement();
        NSDictionary attributeUserInfo = attribute.userInfo();
        if (attributeUserInfo != null) {
          String constantClassName = (String)attributeUserInfo.objectForKey("ERXConstantClassName");
          if (constantClassName != null) {
            boolean constantClassFound = true;
            try {
              Class.forName(constantClassName);
            }
            catch (ClassNotFoundException e) {
              int lastDotIndex = constantClassName.lastIndexOf('.');
              if (lastDotIndex != -1) {
                String innerClassName = constantClassName.substring(0, lastDotIndex) + "$" + constantClassName.substring(lastDotIndex + 1);
                try {
                  Class.forName(innerClassName);
                }
                catch (ClassNotFoundException e2) {
                  constantClassFound = false;
                }
              }
              else {
                constantClassFound = false;
              }
            }
            if (!constantClassFound) {
              throw new IllegalArgumentException(attribute.name() + " specified an ERXConstantClass of '" + constantClassName + "', which could not be found.");
            }
          }
        }
      }
    }
View Full Code Here

        if (externalName != null) {
          entity.setExternalName(externalName);
        }
       
        for (Enumeration attributesEnum = entity.attributes().objectEnumerator(); attributesEnum.hasMoreElements();) {
          EOAttribute attribute = (EOAttribute) attributesEnum.nextElement();
         
          String attributeColumnName = ERXProperties.stringForKey("er.extensions.ERXModelGroup." + entity.name() + "." + attribute.name() + ".columnName");
          if (attributeColumnName != null) {
            attribute.setColumnName(attributeColumnName);
          }
        }
      }
    }   
  }
View Full Code Here

              log.debug("Flattening " + model.name() + " using the prototype " + prototypeEntity.name());
            }
            for (Enumeration entitiesEnum = model.entities().objectEnumerator(); entitiesEnum.hasMoreElements();) {
              EOEntity entity = (EOEntity) entitiesEnum.nextElement();
              for (Enumeration attributesEnum = entity.attributes().objectEnumerator(); attributesEnum.hasMoreElements();) {
                EOAttribute attribute = (EOAttribute) attributesEnum.nextElement();
                if (!attribute.isFlattened()) {
                  String prototypeAttributeName = attribute.prototypeName();
                  if (prototypeAttributeName == null) {
                    if (attribute.externalType() == null) {
                      log.warn(model.name() + "/" + entity.name() + "/" + attribute.name() + " does not have a prototype attribute name.  This can occur if the model cannot resolve ANY prototypes when loaded.  There must be a stub prototype for the model to load with that can then be replaced with the appropriate database-specific model.");
                    }
                  }
                  else {
                    EOAttribute prototypeAttribute = prototypeEntity.attributeNamed(prototypeAttributeName);
                    if (prototypeAttribute == null) {
                      log.warn(model.name() + "/" + entity.name() + "/" + attribute.name() + " references a prototype attribute named " + prototypeAttributeName + " that does not exist in " + prototypeEntity.name() + ".");
                    }
                    else if (attribute.prototype().entity() == prototypeEntity) {
                      if (log.isDebugEnabled()) {
                        log.debug("Skipping " + model.name() + "/" + entity.name() + "/" + attribute.name() + " because it is already prototyped by the correct entity.");
                      }
                    }
                    else {
                      flattenPrototypeAttribute(prototypeAttribute, attribute);
                      if (log.isDebugEnabled()) {
                        log.debug("Flattening " + model.name() + "/" + entity.name() + "/" + attribute.name() + " with the prototype attribute " + prototypeAttribute.entity().model().name() + "/" + prototypeAttribute.entity().name() + "/" + prototypeAttribute.name());
                      }
                    }
                  }
                }
                else {
View Full Code Here

    public void init(GSVModel model, EOEntity eoentity) {
  NSArray myattributes = attributes().immutableClone();
  for ( Enumeration e = myattributes.objectEnumerator(); e.hasMoreElements();) {
      GSVAttribute attribute = (GSVAttribute)e.nextElement();
      //NSLog.debug.appendln("checking attribute"+eoentity.name()+"."+attribute.name());
      EOAttribute a = eoentity.attributeNamed(attribute.name());
      EORelationship p = eoentity.relationshipNamed(attribute.name());
     
      if (a == null) {
    NSLog.out.appendln("attribute "+attribute.name() + " does not exist in entity " + name() + " (anymore?), deleted from Valididy model");
    removeAttribute(attribute);
View Full Code Here

    public Format valueFormatter() {
        Format f = null;
        EORelationship rel = (EORelationship) valueForKeyPath("d2wContext.smartRelationship");
        EOEntity destEnt = rel.destinationEntity();
        EOAttribute searchAttr = destEnt.attributeNamed(keyWhenRelationship());
        if(searchAttr != null) {
            String className = searchAttr.className();
            if(className.equals("java.lang.Number"))
                f = new NSNumberFormatter("0");
            if(className.equals("java.lang.BigDecimal"))
                f = new NSNumberFormatter("$#,##0.00;-$#,##0.00");
            if(className.equals("com.webobjects.foundation.NSTimestamp"))
View Full Code Here

     * @return cloned attribute
     */
    protected EOAttribute cloneAttribute(EOEntity entity, EOAttribute attribute, String newName) {
      // NOTE: order is important here. To add the prototype,
      // we need it in the entity and we need a name to add it there
      EOAttribute copy = new EOAttribute();
      copy.setName(newName);
      entity.addAttribute(copy);
      copy.setPrototype(attribute.prototype());
      copy.setColumnName(attribute.columnName());
      copy.setExternalType(attribute.externalType());
      copy.setValueType(attribute.valueType());
      copy.setPrecision(attribute.precision());
      copy.setAllowsNull(attribute.allowsNull());
      copy.setClassName(attribute.className());
      copy.setWidth(attribute.width());
      copy.setScale(attribute.scale());
      copy.setExternalType(attribute.externalType());
      return copy;
    }
View Full Code Here

        attributesUsedForLocking = NSArray.EmptyArray;
      NSMutableArray mutableClassProperties = classProperties.mutableClone();
      NSMutableArray mutableAttributesUsedForLocking = attributesUsedForLocking.mutableClone();
      if (attributes != null) {
        for (Enumeration e = attributes.objectEnumerator(); e.hasMoreElements();) {
          EOAttribute attribute = (EOAttribute) e.nextElement();
          boolean isClassProperty = classProperties.containsObject(attribute);
          boolean isUsedForLocking = attributesUsedForLocking.containsObject(attribute);
          Object languagesObject = attribute.userInfo() != null ? attribute.userInfo().objectForKey(LANGUAGES_KEY) : null;
          if (languagesObject != null && !(languagesObject instanceof NSArray)) {
            languagesObject = entity.model().userInfo() != null ? entity.model().userInfo().objectForKey(LANGUAGES_KEY) : null;
            if(languagesObject == null) {
              languagesObject = ERXProperties.arrayForKey(LANGUAGES_KEY);
            }
          }
          NSArray languages = (languagesObject != null ? (NSArray) languagesObject : NSArray.EmptyArray);
          if (languages.count() > 0) {
            String name = attribute.name();
            String columnName = attribute.columnName();
            NSMutableDictionary attributeUserInfo = new NSMutableDictionary();
            if(attribute.userInfo() != null) {
              attributeUserInfo.addEntriesFromDictionary(attribute.userInfo());
            }
            attributeUserInfo.setObjectForKey(languages, LANGUAGES_KEY);
            for (int i = 0; i < languages.count(); i++) {
              String language = (String) languages.objectAtIndex(i);
              String newName = name + "_" + language;
              // columnName = columnName.replaceAll("_(\\w)$", "_" + language);
              EOAttribute copy = cloneAttribute(entity, attribute, newName);

              String newColumnName = columnName + "_" + language;
              copy.setColumnName(newColumnName);

              if (isClassProperty) {
                mutableClassProperties.addObject(copy);
              }
              if (isUsedForLocking) {
                mutableAttributesUsedForLocking.addObject(copy);
              }
              copy.setUserInfo(attributeUserInfo.mutableClone());
            }
            entity.removeAttribute(attribute);
            mutableClassProperties.removeObject(attribute);
            mutableAttributesUsedForLocking.removeObject(attribute);
          }
View Full Code Here

  protected void processQualifier(EOEntity entity, EOQualifier qualifier, StringBuffer urlBuffer, NSMutableDictionary<String, Object> attributesFromQualifier) {
    if (qualifier instanceof EOKeyValueQualifier) {
      EOKeyValueQualifier eokvq = (EOKeyValueQualifier) qualifier;
      String key = eokvq.key();
      Object value = eokvq.value();
      EOAttribute keyAttribute = entity.attributeNamed(key);
      if (entity.primaryKeyAttributes().containsObject(keyAttribute)) {
        urlBuffer.append("/");
        urlBuffer.append(value);
      }
      else {
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.