Package com.webobjects.eoaccess

Examples of com.webobjects.eoaccess.EOAttribute


      NodeList rowElements = document.getElementsByTagName(singularName(entity));
      for (int rowNum = 0; rowNum < rowElements.getLength(); rowNum++) {
        NSMutableDictionary<String, Object> row = new NSMutableDictionary<String, Object>();
        Element rowElement = (Element) rowElements.item(rowNum);
        for (int attributeNum = 0; attributeNum < attributesToFetch.count(); attributeNum++) {
          EOAttribute attribute = (EOAttribute) attributesToFetch.objectAtIndex(attributeNum);
          String columnName = attribute.columnName();
          NodeList attributeElements = rowElement.getElementsByTagName(columnName);

          Object value;
          if (attributeElements.getLength() == 0) {
            if (rowElement.hasAttribute(columnName)) {
              Attr columnAttribute = rowElement.getAttributeNode(columnName);
              value = convertValue(columnAttribute.getValue(), attribute);
            }
            else {
              value = null;
            }
          }
          else if (attributeElements.getLength() > 1) {
            throw new EOGeneralAdaptorException("There was more than one column named '" + columnName + "'.");
          }
          else {
            Element attributeElement = (Element) attributeElements.item(0);
            if ("true".equals(attributeElement.getAttribute("nil"))) {
              value = null;
            }
            else {
              String strValue = textValue(attributeElement);
              if (attributeElement.hasAttribute("type")) {
                String type = attributeElement.getAttribute("type");
                if ("bigit".equals(type)) {
                  value = new BigDecimal(strValue);
                }
                else if ("boolean".equals(type)) {
                  value = Boolean.parseBoolean(strValue);
                }
                else if ("datetime".equals(type)) {
                  value = ERRESTAdaptorChannel.restDateFormat.parseObject(strValue);
                }
                else if ("double".equals(type)) {
                  value = Double.parseDouble(strValue);
                }
                else if ("float".equals(type)) {
                  value = Float.parseFloat(strValue);
                }
                else if ("integer".equals(type)) {
                  value = Integer.parseInt(strValue);
                }
                else if ("short".equals(type)) {
                  value = Short.parseShort(strValue);
                }
                else {
                  throw new IllegalArgumentException("Unknown type '" + type + "'.");
                }
              }
              else {
                value = convertValue(strValue, attribute);
              }
            }
          }

          if (value != null) {
            row.setObjectForKey(value, attribute.name());
          }
        }

        // Just in case you qualified against attributes that ended up not
        // being returned in the results, we augment the resulting row
        // with the key-value pairs from your qualifier.
        if (attributesFromQualifier.count() > 0) {
          for (String qualifierAttributeName : attributesFromQualifier.allKeys()) {
            if (!row.containsKey(qualifierAttributeName)) {
              EOAttribute qualifierAttribute = entity.attributeNamed(qualifierAttributeName);
              if (qualifierAttribute != null && attributesToFetch.containsObject(qualifierAttribute)) {
                row.setObjectForKey(attributesFromQualifier.objectForKey(qualifierAttributeName), qualifierAttributeName);
              }
            }
          }
View Full Code Here


        private EOEnterpriseObject decodeEO(NSDictionary dictionary) {
            String entityName = (String)dictionary.objectForKey(SerializationKeys.EntityName);
            String pk = (String)dictionary.objectForKey(SerializationKeys.PrimaryKey);
            EOEntity entity = ERXEOAccessUtilities.entityNamed(null, entityName);
            EOAttribute primaryKeyAttribute;
            EOEnterpriseObject eo = null;
            if (entity != null) {
                primaryKeyAttribute = ERXArrayUtilities.firstObject(entity.primaryKeyAttributes());
                Object primaryKeyObject = pk;
                if (log.isDebugEnabled()) log.debug("decodeEO with dict: " + dictionary);

                if (primaryKeyAttribute != null && !String.class.getName().equals(primaryKeyAttribute.className())) {
                    primaryKeyObject = ERXStringUtilities.integerWithString(pk);
                }

                try {
                    if (isDictionaryAnEncodedSharedEO(dictionary)) {
View Full Code Here

      // Register this object right away to handle circular relationships
      copiedObjects.setObjectForKey(copy, Utility.globalIDForObject(source));

      for (EOProperty property : entity.classProperties()) {
        if (property instanceof EOAttribute) {
          EOAttribute attribute = (EOAttribute) property;
          if (exposedPKAndFKAttributes(source).containsObject(attribute)) {
            copy.takeStoredValueForKey(null, attribute.name());
          }
          else {
            Utility.modelCopyAttribute(source, copy, attribute);
          }
        }
View Full Code Here

     *         UserInfo dictionary in the EOModel
     */
    public static CopyType copyType(EOProperty property) {
      CopyType copyType;
      if (property instanceof EOAttribute) {
        EOAttribute attribute = (EOAttribute) property;
        @SuppressWarnings("unchecked")
        NSDictionary<String, Object> userInfo = attribute.userInfo();
        copyType = Utility.copyType(attribute, userInfo);
      }
      else {
        EORelationship relationship = (EORelationship) property;
        NSDictionary<String, Object> userInfo = relationship.userInfo();
View Full Code Here

        EOEntity entity = ERXEOAccessUtilities.entityNamed(ec, entityName);
        if (entity == null) {
          throw new IllegalStateException("Unable find entity named: " + entityName);
        }

        EOAttribute attribute = entity.attributeNamed(attributeName);
        if (attribute == null) {
          throw new IllegalStateException("Unable find attribute named: " + attributeName + " for entity: " + entityName);
        }

        EOAttribute aggregate = new EOAttribute();
        if (aggregateName != null) {
          aggregate.setName(aggregateName);
          aggregate.setColumnName(aggregateName);
        } else {
          aggregate.setName("p_object" + function + "Attribute");
          aggregate.setColumnName("p_object" + function + "Attribute");
        }
        aggregate.setClassName(valueClass.getName());
        if (valueType != null) {
          aggregate.setValueType(valueType);
        } else {
          aggregate.setValueType(attribute.valueType());
        }
       
        // MS: This "t0." is totally wrong, but it is required. It should be dynamically
        // generated, but this function doesn't have an EOSQLExpression to operate on
        if (entityTableAlias == null) {
          entityTableAlias = "t0";
        }
        aggregate.setReadFormat(ERXSQLHelper.newSQLHelper(entity.model()).readFormatForAggregateFunction(function, entityTableAlias + "." + attribute.columnName(), aggregateName, usesDistinct));
        return aggregate;
    }
View Full Code Here

        return false;
    }

    public static EOAttribute attributeWithColumnNameFromEntity(String columnName, EOEntity entity) {
        for (Enumeration e = entity.attributes().objectEnumerator(); e.hasMoreElements();) {
            EOAttribute att = (EOAttribute)e.nextElement();
            if (columnName.equalsIgnoreCase(att.columnName())) {
                return att;
            }
        }
        return null;
    }
View Full Code Here

        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);
            result.addObject(value);
          }
View Full Code Here

            }
            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);
            }
View Full Code Here

        NSArray attributes = entity.attributes();
        NSArray cpNames = entity.classPropertyNames();

        if (includeAttributes) {
          for (int i = attributes.count(); i-- > 0;) {
              EOAttribute att = (EOAttribute) attributes.objectAtIndex(i);
              String name = att.name();
              if (cpNames.containsObject(name) && !parentAttributeNames.containsObject(name)) {
                  ret.addObject(att);
              }
          }
        }
View Full Code Here

        String externalName = entity.externalName();
        if (externalName != null && parentEntity != null) {
          // If you have a parent entity and that parent entity shares your table name, then you're single table inheritance
          boolean singleTableInheritance = externalName.equals(parentEntity.externalName());
          if (singleTableInheritance) {
            EOAttribute parentAttribute = parentEntity.attributeNamed(attribute.name());
            if (parentAttribute == null) {
              // If this attribute is new in the subclass, you have to allow nulls
              shouldAllowNull = true;
            }
          }
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.