Package com.webobjects.eoaccess

Examples of com.webobjects.eoaccess.EORelationship


            String entityName = (String) e.nextElement();
            NSArray objects = (NSArray) objectsByEntity.objectForKey(entityName);
            EOEntity entity = ERXEOAccessUtilities.entityNamed(ec, entityName);
            for (Enumeration keyPaths = prefetchingKeypaths.objectEnumerator(); keyPaths.hasMoreElements();) {
              String keypath = (String) keyPaths.nextElement();
              EORelationship relationship = entity.relationshipNamed(keypath);
              EODatabaseContext dbc = ERXEOAccessUtilities.databaseContextForEntityNamed((EOObjectStoreCoordinator) ec.rootObjectStore(), entityName);
              dbc.lock();
              try {
                dbc.batchFetchRelationship(relationship, objects, ec);
              } finally {
View Full Code Here


                from=(EOEnterpriseObject)from.valueForKeyPath(partialKeyPath);
                keyPath=ERXStringUtilities.lastPropertyKeyInKeyPath(keyPath);
            }
            //if the key is not a keyPath we can check if the key is actually a relationship
            EOEntity e=ERXEOAccessUtilities.entityNamed(from.editingContext(), from.entityName());
            EORelationship r=e.relationshipNamed(keyPath);
            if (r!=null) //if the key correspond to a relationship
                from.addObjectToBothSidesOfRelationshipWithKey(to, keyPath);
            else
                from.takeValueForKeyPath(to,keyPath);
        }
View Full Code Here

        if (entity!=null && lastKey!=null) {
            EOAttribute a=entity.attributeNamed(lastKey);
            NSDictionary userInfo=null;
            if (a!=null) userInfo=a.userInfo();
            else {
                EORelationship r=entity.relationshipNamed(lastKey);
                if (r!=null) userInfo=r.userInfo();
            }
            result= (String)(userInfo!=null ? userInfo.valueForKey("unit") : null);
        }
        return result;
    }
View Full Code Here

              }
            }

            Enumeration partialRelationships = partialExtensionEntity.relationships().objectEnumerator();
            while (partialRelationships.hasMoreElements()) {
              EORelationship partialRelationship = (EORelationship) partialRelationships.nextElement();
              if (partialEntity.relationshipNamed(partialRelationship.name()) == null) {
                NSMutableDictionary<String, Object> relationshipPropertyList = new NSMutableDictionary<String, Object>();
                partialRelationship.encodeIntoPropertyList(relationshipPropertyList);

                EORelationship primaryRelationship = new EORelationship(relationshipPropertyList, partialEntity);
                primaryRelationship.awakeWithPropertyList(relationshipPropertyList);
                partialEntity.addRelationship(primaryRelationship);
              }
              else {
                ERXModelGroup.log.debug("Skipping partial relationship " + partialExtensionEntity.name() + "." + partialRelationship.name() + " because " + partialEntity.name() + " already has a relationship of the same name.");
              }
View Full Code Here

  protected void convertEntityPartialReferences(EOEntity entity, NSMutableDictionary<EOEntity, EOEntity> baseForPartial, NSMutableSet<EOEntity> convertedEntities) {
    if (!convertedEntities.containsObject(entity)) {
      convertedEntities.addObject(entity);
      Enumeration relationships = entity.relationships().immutableClone().objectEnumerator();
      while (relationships.hasMoreElements()) {
        EORelationship relationship = (EORelationship) relationships.nextElement();
        convertRelationshipPartialReferences(entity, relationship, baseForPartial, convertedEntities);
      }
    }
  }
View Full Code Here

     
      NSMutableDictionary<String, Object> relationshipPropertyList = new NSMutableDictionary<String, Object>();
      relationship.encodeIntoPropertyList(relationshipPropertyList);
      relationshipPropertyList.setObjectForKey(baseEntity.name(), "destination");
     
      EORelationship primaryRelationship = new EORelationship(relationshipPropertyList, entity);
      primaryRelationship.awakeWithPropertyList(relationshipPropertyList);
      // MS: This looks silly, but 5.4 has a bug where the relationship dictionary isn't necessarily initialized at this point, so we want to force it to load
      entity.relationshipNamed(relationship.name());
      entity.removeRelationship(relationship);
      entity.addRelationship(primaryRelationship);
    }
View Full Code Here

      for (Enumeration enumerator = entityGroup.objectEnumerator(); enumerator.hasMoreElements(); ) {
        EOEntity entity = (EOEntity)enumerator.nextElement();
        String tableName = entity.externalName();
        if( (tableName != null) && ( ! "".equals(tableName) ) ) {
          for (Enumeration relationshipEnumerator = entity.relationships().objectEnumerator(); relationshipEnumerator.hasMoreElements(); ) {
            EORelationship relationship = (EORelationship)relationshipEnumerator.nextElement();
            if( ! relationship.isFlattened() ) {
              NSArray destinationAttributes = relationship.destinationAttributes();
             
              // First exclude all the destination entity primary keys
              for (Enumeration attributeEnumerator = relationship.destinationEntity().primaryKeyAttributes().objectEnumerator(); attributeEnumerator.hasMoreElements(); ) {
                EOAttribute attribute = (EOAttribute)attributeEnumerator.nextElement();
                columnNameDictionary.setObjectForKey(attribute.columnName(), relationship.destinationEntity().externalName() + "." + attribute.columnName());
              }
              // Then deal with our end of things
              for (Enumeration attributeEnumerator = relationship.sourceAttributes().objectEnumerator(); attributeEnumerator.hasMoreElements(); ) {
                EOAttribute attribute = (EOAttribute)attributeEnumerator.nextElement();
                if( (! this.isSinglePrimaryKeyAttribute(attribute)) && (columnNameDictionary.objectForKey(tableName + "." + attribute.columnName()) != null) ) {
                  columnNameDictionary.setObjectForKey(attribute.columnName(), tableName + "." + attribute.columnName());
                  EOSQLExpression expression = this._expressionForString("create index " + tableName + " " + attribute.columnName());
                  if(expression != null) primaryKeyConstraintExpressions.addObject( expression );
                }
              }
              // Then deal with the other side
              if(entity.model() == relationship.destinationEntity().model()) {
                for (Enumeration attributeEnumerator = relationship.destinationAttributes().objectEnumerator(); attributeEnumerator.hasMoreElements(); ) {
                  EOAttribute attribute = (EOAttribute)attributeEnumerator.nextElement();
                  String destinationTableName = relationship.destinationEntity().externalName();
                  if( (destinationTableName != null) && ( ! "".equals(destinationTableName) ) ) {
                    if( (! this.isSinglePrimaryKeyAttribute(attribute)) && (columnNameDictionary.objectForKey(destinationTableName + "." + attribute.columnName()) != null) ) {
                      columnNameDictionary.setObjectForKey(attribute.columnName(), destinationTableName + "." + attribute.columnName());
                      EOSQLExpression expression = this._expressionForString("create index " + destinationTableName + " " + attribute.columnName());
                      if(expression != null) primaryKeyConstraintExpressions.addObject( expression );
                    }
                    if( (! relationship.isCompound() ) && (relationship.sourceAttributes().count() == 1) && (relationship.destinationAttributes().count() == 1) ) {
                      String semantics;
                      switch(relationship.joinSemantic()) {
                        case EORelationship.FullOuterJoin: // '\001'
                        case EORelationship.LeftOuterJoin: // '\002'
                        case EORelationship.RightOuterJoin: // '\003'
                          semantics = "*";
                          break;
                         
                        default:
                          semantics = "=";
                          break;
                      }
                      String sourceColumn = ((EOAttribute)relationship.sourceAttributes().objectAtIndex(0)).columnName();
                      String destinationColumn = ((EOAttribute)relationship.destinationAttributes().objectAtIndex(0)).columnName();
                      EOSQLExpression expression = this._expressionForString("delete from _SYS_RELATIONSHIP where relationshipName = '" + relationship.name() + "' and source_table = '" + tableName + "' ");
                      if(expression != null) primaryKeyConstraintExpressions.addObject( expression );
                      expression = this._expressionForString("insert into _SYS_RELATIONSHIP (relationshipName, source_table, source_column, dest_table, dest_column, operator, one_to_many) values ('" + relationship.name() + "','" + tableName + "','" + sourceColumn + "','" + destinationTableName + "','" + destinationColumn + "','" + semantics + "'," + (relationship.isToMany() ? 1 : 0) + ")");
                      if(expression != null) primaryKeyConstraintExpressions.addObject( expression );
                    }
                  }
                }
              }
View Full Code Here

      NSArray k;
      EOEntity rightEntity;
      EOEntity leftEntity;
      String relationshipKey = null;
      EORelationship r;

      if (leftAlias.equals("t0")) {
        leftEntity = entity();
      }
      else {
        k = aliasesByRelationshipPath().allKeysForObject(leftAlias);
        relationshipKey = k.count() > 0 ? (String) k.lastObject() : "";
        leftEntity = entityForKeyPath(relationshipKey);
      }

      if (rightAlias.equals("t0")) {
        rightEntity = entity();
      }
      else {
        k = aliasesByRelationshipPath().allKeysForObject(rightAlias);
        relationshipKey = k.count() > 0 ? (String) k.lastObject() : "";
        rightEntity = entityForKeyPath(relationshipKey);
      }

      int dotIndex = relationshipKey.indexOf(".");
      relationshipKey = dotIndex == -1 ? relationshipKey : relationshipKey.substring(relationshipKey.lastIndexOf(".") + 1);
      r = rightEntity.anyRelationshipNamed(relationshipKey);

      // fix from Michael Müller for the case Foo.fooBars.bar has a Bar.foo relationship (instead of Bar.foos)
      if (r == null || r.destinationEntity() != leftEntity) {
        r = leftEntity.anyRelationshipNamed(relationshipKey);
      }

      String rightTable = rightEntity.valueForSQLExpression(this);
      String leftTable = leftEntity.valueForSQLExpression(this);
      JoinClause jc = new JoinClause();

      jc.setTable1(leftTable, leftAlias);
      jc.table2 = rightTable + " " + rightAlias;

      switch (semantic) {
      case EORelationship.LeftOuterJoin:
        jc.op = " LEFT OUTER JOIN ";
        break;
      case EORelationship.RightOuterJoin:
        jc.op = " RIGHT OUTER JOIN ";
        break;
      case EORelationship.FullOuterJoin:
        jc.op = " FULL OUTER JOIN ";
        break;
      case EORelationship.InnerJoin:
        jc.op = " INNER JOIN ";
        break;
      }

      NSArray joins = r.joins();
      int joinsCount = joins.count();
      NSMutableArray joinStrings = new NSMutableArray(joinsCount);
      for (int i = 0; i < joinsCount; i++) {
        EOJoin currentJoin = (EOJoin) joins.objectAtIndex(i);
        String left = leftAlias + "." + sqlStringForSchemaObjectName(currentJoin.sourceAttribute().columnName());
View Full Code Here

      NSArray keys = NSArray.componentsSeparatedByString(keyPath, ".");
      EOEntity ent = entity();

      for (int i = 0; i < keys.count(); i++) {
        String k = (String) keys.objectAtIndex(i);
        EORelationship rel = ent.anyRelationshipNamed(k);
        if (rel == null) {
          // it may be an attribute
          if (ent.anyAttributeNamed(k) != null) {
            break;
          }
          throw new IllegalArgumentException("relationship " + keyPath + " generated null");
        }
        ent = rel.destinationEntity();
      }
      return ent;
    }
View Full Code Here

      NSArray<String> k;
      EOEntity rightEntity;
      EOEntity leftEntity;
      String relationshipKey = null;
      EORelationship r;

      if (leftAlias.equals("t0")) {
        leftEntity = entity();
      } else {
        k = aliasesByRelationshipPath().allKeysForObject(leftAlias);
        relationshipKey = k.count() > 0 ? (String) k.lastObject() : "";
        leftEntity = entityForKeyPath(relationshipKey);
      }

      if (rightAlias.equals("t0")) {
        rightEntity = entity();
      } else {
        k = aliasesByRelationshipPath().allKeysForObject(rightAlias);
        relationshipKey = k.count() > 0 ? (String) k.lastObject() : "";
        rightEntity = entityForKeyPath(relationshipKey);
      }
      int dotIndex = relationshipKey.indexOf(".");
      relationshipKey = dotIndex == -1 ? relationshipKey : relationshipKey.substring(relationshipKey.lastIndexOf(".") + 1);
      r = rightEntity.anyRelationshipNamed(relationshipKey);
      // fix from Michael Müller for the case Foo.fooBars.bar has a
      // Bar.foo relationship (instead of Bar.foos)
      if (r == null || r.destinationEntity() != leftEntity) {
        r = leftEntity.anyRelationshipNamed(relationshipKey);
      }
      // timc 2006-02-26 IMPORTANT or quotes are ignored and mixed case
      // field names won't work
      String rightTable;
      String leftTable;
      if (CONFIG.ENABLE_IDENTIFIER_QUOTING) {
        rightTable = rightEntity.valueForSQLExpression(this);
        leftTable = leftEntity.valueForSQLExpression(this);
      } else {
        rightTable = rightEntity.externalName();
        leftTable = leftEntity.externalName();
      }

      // We need the numeric table by removing the leading 't' or 'T' from the table alias
      int leftTableID = Integer.parseInt(leftAlias.substring(1));
     
      // Compute left and right table references
      String leftTableNameAndAlias = leftTable + " " + leftAlias;
      String rightTableNameAndAlias = rightTable + " " + rightAlias;

      // COmpute joinOperation
      String joinOperation = null;
      switch (semantic) {
      case EORelationship.LeftOuterJoin:
        // LEFT OUTER JOIN and LEFT JOIN are equivalent in MySQL
        joinOperation = " LEFT JOIN ";
        break;
      case EORelationship.RightOuterJoin:
        // RIGHT OUTER JOIN and RIGHT JOIN are equivalent in MySQL
        joinOperation = " RIGHT JOIN ";
        break;
      case EORelationship.FullOuterJoin:
        throw new IllegalArgumentException("Unfortunately MySQL does not support FULL OUTER JOIN that is specified for " + leftName + " joining " + rightName + "!");
        //jc.op = " FULL OUTER JOIN ";
        //break;
      case EORelationship.InnerJoin:
        // INNER JOIN and JOIN are equivalent in MySQL
        joinOperation = " JOIN ";
        break;
      }

      // Compute joinCondition
      NSArray<EOJoin> joins = r.joins();
      int joinsCount = joins.count();
      NSMutableArray<String> joinStrings = new NSMutableArray<String>(joinsCount);
      for (int i = 0; i < joinsCount; i++) {
        EOJoin currentJoin = joins.objectAtIndex(i);
        String left;
View Full Code Here

TOP

Related Classes of com.webobjects.eoaccess.EORelationship

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.