Package com.webobjects.eoaccess

Examples of com.webobjects.eoaccess.EOAttribute


            : NSArray.componentsSeparatedByString( value, AttributeValueSeparator )
        int attrCount = pkAttributeNames.count();
        NSMutableDictionary result = new NSMutableDictionary( attrCount );
        for( int i = 0; i < attrCount; i++ ) {
            String currentAttributeName = (String)pkAttributeNames.objectAtIndex( i );
            EOAttribute currentAttribute = entity.attributeNamed( currentAttributeName );
            Object currentValue = values.objectAtIndex( i );
            switch ( currentAttribute.adaptorValueType() ) {
                case 3:
                    NSTimestampFormatter tsf = new NSTimestampFormatter();
                    try {
                        currentValue = tsf.parseObject( (String) currentValue );   
                    } catch( java.text.ParseException ex ) {
                        log.error( "Error while trying to parse: "+currentValue );
                        throw new NSForwardException( ex );
                    }
                    case 1:
                        if( currentAttribute.valueFactoryMethodName() != null ) {
                            currentValue = currentAttribute.newValueForString( (String) currentValue );
                        }
                    case 0:
                        currentValue = new java.math.BigDecimal( (String) currentValue );
            }
            result.setObjectForKey( currentValue, currentAttributeName );
View Full Code Here


            boolean validIndex = false;
            localBuf.append("create index " + indexName + " on " + entity.externalName() + "(");
            for (Enumeration<String> attributes = NSArray.componentsSeparatedByString(attributeNames, ",").objectEnumerator(); attributes.hasMoreElements();) {
              String attributeName = attributes.nextElement();
              attributeName = attributeName.trim();
              EOAttribute attribute = entity.attributeNamed(attributeName);
              if (attribute == null) {
                attribute = ERXEOAccessUtilities.attributeWithColumnNameFromEntity(attributeName, entity);
              }
              if (attribute != null && externalTypesToIgnore.indexOfObject(attribute.externalType()) != NSArray.NotFound) {
                continue;
              }
              validIndex = true;
              String columnName = attribute == null ? attributeName : attribute.columnName();
              columnBuf.append(columnName);
              if (attributes.hasMoreElements()) {
                columnBuf.append(", ");
              }
            }
            if (validIndex) {
              String l = columnBuf.toString();
              if (l.endsWith(", ")) {
                l = l.substring(0, l.length() - 2);
              }
              if (usedColumns.indexOfObject(l) == NSArray.NotFound) {
                buf.append(localBuf).append(l);
                usedColumns.addObject(l);
                buf.append(')').append(commandSeparator).append(lineSeparator);
              }
            }
          }
        }
        else if (key.equals("additionalIndexes")) {
          // this is a space separated list of column or attribute
          // names
          String value = (String) d.objectForKey(key);
          for (Enumeration indexes = NSArray.componentsSeparatedByString(value, " ").objectEnumerator(); indexes.hasMoreElements();) {
            String indexValues = (String) indexes.nextElement();
            if (ERXStringUtilities.stringIsNullOrEmpty(indexValues)) {
              continue;
            }

            // this might be a comma separate list
            String indexName = "c" + System.currentTimeMillis() + new NSTimestamp().getNanos();
            String newIndexName = i == 0 ? indexName : indexName + "_" + i;
            if (oldIndexName == null) {
              oldIndexName = indexName;
            }
            else if (oldIndexName.equals(newIndexName)) {
              indexName += "_" + ++i;
            }
            else {
              i = 0;
            }
            oldIndexName = indexName;

            StringBuffer localBuf = new StringBuffer();
            StringBuffer columnBuf = new StringBuffer();
            boolean validIndex = false;
            localBuf.append("create index " + indexName + " on " + entity.externalName() + "(");
            for (Enumeration e = NSArray.componentsSeparatedByString(indexValues, ",").objectEnumerator(); e.hasMoreElements();) {
              String attributeName = (String) e.nextElement();
              attributeName = attributeName.trim();
              EOAttribute attribute = entity.attributeNamed(attributeName);

              if (attribute == null) {
                attribute = ERXEOAccessUtilities.attributeWithColumnNameFromEntity(attributeName, entity);
              }
              if (attribute != null && externalTypesToIgnore.indexOfObject(attribute.externalType()) != NSArray.NotFound) {
                continue;
              }
              validIndex = true;

              String columnName = attribute == null ? attributeName : attribute.columnName();
              columnBuf.append(columnName);
              if (e.hasMoreElements()) {
                columnBuf.append(", ");
              }
            }
View Full Code Here

        String externalName = entity.externalName();
        if (externalName != null) {
          // If you have a parent entity and that parent entity shares your table name, then you're single table inheritance
          boolean singleTableInheritance = (parentEntity != null && 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

    if (valueArray.count() == 0) {
      return "0=1";
    }
    StringBuilder sb = new StringBuilder();
    NSArray attributePath = ERXEOAccessUtilities.attributePathForKeyPath(e.entity(), key);
    EOAttribute attribute = (EOAttribute) attributePath.lastObject();
    String sqlName;
    if (attributePath.count() > 1) {
      sqlName = e.sqlStringForAttributePath(attributePath);
    }
    else {
View Full Code Here

   */
  public EOEntity _newEntity() {
    EOEntity entity = _blankEntity();
    NSMutableArray<EOAttribute> primaryKeyAttributes = new NSMutableArray<EOAttribute>();
    for (ERXMigrationColumn column : _columns) {
      EOAttribute attribute = column._newAttribute(entity);
      if (column.isPrimaryKey()) {
        primaryKeyAttributes.addObject(attribute);
      }
    }
    entity.setPrimaryKeyAttributes(primaryKeyAttributes);
View Full Code Here

      throw new IllegalArgumentException("The number of source columns must match the number of destination columns.");
    }
    EOEntity sourceEntity = sourceColumns[0].table()._blankEntity();
    EOEntity destinationEntity = destinationColumns[0].table()._blankEntity();
    for (int columnNum = 0; columnNum < sourceColumns.length; columnNum ++) {
      EOAttribute sourceAttribute = sourceColumns[columnNum]._newAttribute(sourceEntity);
      sourceAttributes.addObject(sourceAttribute);
      EOAttribute destinationAttribute = destinationColumns[columnNum]._newAttribute(destinationEntity);
      destinationAttributes.addObject(destinationAttribute);
    }
    destinationEntity.setPrimaryKeyAttributes(destinationAttributes);

    EORelationship relationship = new EORelationship();
View Full Code Here

  public NSArray<EOSQLExpression> _setPrimaryKeyExpressions(ERXMigrationColumn... columns) {
    EOSchemaGeneration schemaGeneration = _database.synchronizationFactory();
    EOEntity entity = columns[0].table()._blankEntity();
    NSMutableArray<EOAttribute> attributes = new NSMutableArray<EOAttribute>();
    for (ERXMigrationColumn column : columns) {
      EOAttribute attribute = column._newAttribute(entity);
      attributes.addObject(attribute);
    }
    entity.setPrimaryKeyAttributes(attributes);
    NSArray<EOSQLExpression> expressions = schemaGeneration.primaryKeyConstraintStatementsForEntityGroup(new NSArray<EOEntity>(entity));
    ERXMigrationDatabase._ensureNotEmpty(expressions, "add primary key", true);
View Full Code Here

  public NSArray<EOSQLExpression> _dropPrimaryKeyExpressions(ERXMigrationColumn... columns) {
    EOSchemaGeneration schemaGeneration = _database.synchronizationFactory();
    EOEntity entity = columns[0].table()._blankEntity();
    NSMutableArray<EOAttribute> attributes = new NSMutableArray<EOAttribute>();
    for (ERXMigrationColumn column : columns) {
      EOAttribute attribute = column._newAttribute(entity);
      attributes.addObject(attribute);
    }
    entity.setPrimaryKeyAttributes(attributes);
    NSArray<EOSQLExpression> expressions = schemaGeneration.dropPrimaryKeySupportStatementsForEntityGroup(new NSArray<EOEntity>(entity));
    ERXMigrationDatabase._ensureNotEmpty(expressions, "drop primary key", true);
View Full Code Here

     * the object.
     * @return EOAttribute corresponding to the propertyKey
     *    and entity.
     */
    public EOAttribute attribute() {
        EOAttribute attribute = null;
        if (eoObject() != null) {
            EOEntity entity = EOUtilities.entityForObject(eoObject().editingContext(), eoObject());
            attribute = entity != null ? entity.attributeNamed(propertyKey()) : null;
        }
        return attribute;
View Full Code Here

                NSArray<String> definitionKeys=NSArray.componentsSeparatedByString(definitionKeyPath,".");
                EOEntity lastStopEntity=targetRelationship.entity();
                EORelationship firstHopRelationship= lastStopEntity.relationshipNamed(definitionKeys.objectAtIndex(0));
                EOEntity endOfFirstHopEntity= firstHopRelationship.destinationEntity();
                EOJoin join= firstHopRelationship.joins().objectAtIndex(0); // assumes 1 join
                EOAttribute sourceAttribute=join.sourceAttribute();
                EOAttribute targetAttribute=join.destinationAttribute();
                EORelationship secondHopRelationship=endOfFirstHopEntity.relationshipNamed(definitionKeys.objectAtIndex(1));
                join= secondHopRelationship.joins().objectAtIndex(0); // assumes 1 join
                EOAttribute secondHopSourceAttribute=join.sourceAttribute();

                NSMutableArray<String> lastStopPKeyPath = toManyKeys.mutableClone();
                lastStopPKeyPath.removeLastObject();
                lastStopPKeyPath.addObject(firstHopRelationship.name());
                lastStopPKeyPath.addObject(targetAttribute.name());
                String firstHopRelationshipKeyPath=lastStopPKeyPath.componentsJoinedByString(".");
                result.append(e.sqlStringForAttributeNamed(firstHopRelationshipKeyPath));
                result.append(" IN ( SELECT ");

                result.append(lastStopEntity.externalName());
                result.append('.');
                result.append(lastStopEntity.primaryKeyAttributes().objectAtIndex(0).columnName());

                result.append(" FROM ");

                result.append(lastStopEntity.externalName());
                result.append(',');

                lastStopPKeyPath.removeLastObject();
                String tableAliasForJoinTable=(String)e.aliasesByRelationshipPath().
                    objectForKey(lastStopPKeyPath.componentsJoinedByString("."));//"j"; //+random#
                result.append(endOfFirstHopEntity.externalName());
                result.append(' ');
                result.append(tableAliasForJoinTable);

                result.append(" WHERE ");

                appendColumnForAttributeToStringBuilder(sourceAttribute, result);
                result.append('=');
                result.append(e.sqlStringForAttributeNamed(firstHopRelationshipKeyPath));
               
                if(qualifier.elements() != null) {
                    NSArray pKeys=ERXEOAccessUtilities.primaryKeysForObjects(qualifier.elements());
                    result.append(" AND ");
                   
                    result.append(tableAliasForJoinTable);
                    result.append('.');
                    result.append(secondHopSourceAttribute.columnName());
                   
                    result.append(" IN (");
                    EOAttribute pk = targetEntity.primaryKeyAttributes().lastObject();
                    for(int i = 0; i < pKeys.count(); i++) {
                       
                        Object key = pKeys.objectAtIndex(i);
                        String keyString = e.formatValueForAttribute(key, pk);
                        //AK: default is is broken
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.