Package com.webobjects.eoaccess

Examples of com.webobjects.eoaccess.EOAttribute


            statement.append(constraintName);
            statement.append(" PRIMARY KEY (");
            NSArray<EOAttribute> priKeyAttributes = entity.primaryKeyAttributes();
            int priKeyAttributeCount = priKeyAttributes.count();
            for (int j = 0; j < priKeyAttributeCount; j++) {
                EOAttribute priKeyAttribute = priKeyAttributes.objectAtIndex(j);
                String attributeName = result.sqlStringForAttribute(priKeyAttribute);
                statement.append(attributeName);
                if (j < priKeyAttributeCount - 1) {
                    statement.append(", ");
                } else {
View Full Code Here


        NSMutableSet<String> sequenceNames = new NSMutableSet<String>();
        NSMutableArray<EOSQLExpression> results = new NSMutableArray<EOSQLExpression>();
        for (EOEntity entity : entityGroup) {
            NSArray<EOAttribute> priKeyAttributes = entity.primaryKeyAttributes();
            if (priKeyAttributes.count() == 1) {
                EOAttribute priKeyAttribute = priKeyAttributes.objectAtIndex(0);
               
                // Q: Don't create a sequence for non number primary keys
                if (priKeyAttribute.adaptorValueType() != EOAttribute.AdaptorNumberType) {
                  continue;
                }

                String sequenceName = PostgresqlPlugIn._sequenceNameForEntity(entity);
                if (!sequenceNames.containsObject(sequenceName)) {
View Full Code Here

      return statements;
    }

    @Override
    public NSArray<EOSQLExpression> statementsToConvertColumnType(String columnName, String tableName, ColumnTypes oldType, ColumnTypes newType, NSDictionary options) {
      EOAttribute attr = new EOAttribute();
      attr.setName(columnName);
      attr.setColumnName(columnName);
      attr.setExternalType(newType.name());
      attr.setScale(newType.scale());
      attr.setPrecision(newType.precision());
      attr.setWidth(newType.width());

      String usingClause = "";
      String columnTypeString = columnTypeStringForAttribute(attr);
      if (options != null) {
        String usingExpression = (String) options.objectForKey(PostgresqlSynchronizationFactory.USING_KEY);
View Full Code Here

      joinToItemRelationship.setIsMandatory(true);
      joinToItemRelationship.setToMany(false);
      joinToItemRelationship.setJoinSemantic(EORelationship.InnerJoin);
      joinEntity.addRelationship(joinToItemRelationship);
      for (EOAttribute itemPrimaryKey : entity.primaryKeyAttributes()) {
        EOAttribute itemFKAttribute = new EOAttribute();
        itemFKAttribute.setExternalType(itemPrimaryKey.externalType());
        itemFKAttribute.setValueType(itemPrimaryKey.valueType());
        itemFKAttribute.setName("item_" + itemPrimaryKey.name());
        itemFKAttribute.setColumnName("item_" + itemPrimaryKey.columnName());
        itemFKAttribute.setClassName(itemPrimaryKey.className());
        itemFKAttribute.setWidth(itemPrimaryKey.width());
        itemFKAttribute.setPrecision(itemPrimaryKey.precision());
        itemFKAttribute.setScale(itemPrimaryKey.scale());
        itemFKAttribute.setAllowsNull(false);
        joinEntity.addAttribute(itemFKAttribute);

        EOJoin join = new EOJoin(itemFKAttribute, itemPrimaryKey);
        joinToItemRelationship.addJoin(join);
      }

      EORelationship joinToTagRelationship = new EORelationship();
      joinToTagRelationship.setName(tagEntity.name());
      joinToTagRelationship.setIsMandatory(true);
      joinToTagRelationship.setToMany(false);
      joinToTagRelationship.setJoinSemantic(EORelationship.InnerJoin);
      joinEntity.addRelationship(joinToTagRelationship);
      for (EOAttribute tagPrimaryKey : tagEntity.primaryKeyAttributes()) {
        EOAttribute tagFKAttribute = new EOAttribute();
        tagFKAttribute.setExternalType(tagPrimaryKey.externalType());
        tagFKAttribute.setValueType(tagPrimaryKey.valueType());
        tagFKAttribute.setName("tag_" + tagPrimaryKey.name());
        tagFKAttribute.setColumnName("tag_" + tagPrimaryKey.columnName());
        tagFKAttribute.setClassName(tagPrimaryKey.className());
        tagFKAttribute.setWidth(tagPrimaryKey.width());
        tagFKAttribute.setPrecision(tagPrimaryKey.precision());
        tagFKAttribute.setScale(tagPrimaryKey.scale());
        tagFKAttribute.setAllowsNull(false);
        joinEntity.addAttribute(tagFKAttribute);

        joinToTagRelationship.addJoin(new EOJoin(tagFKAttribute, tagPrimaryKey));
      }
View Full Code Here

    NSMutableArray<EOAttribute> fetchAttributes = new NSMutableArray<EOAttribute>();
    ERXEOAttribute tagNameAttribute = new ERXEOAttribute(_entity, _tagsRelationship.name() + "." + ERTag.NAME_KEY);
    tagNameAttribute.setName("tagName");
    fetchAttributes.addObject(tagNameAttribute);

    EOAttribute countAttribute = ERXEOAccessUtilities.createAggregateAttribute(editingContext, "COUNT", ERTag.NAME_KEY, _tagEntity.name(), Number.class, "i", "tagCount", "t2");
    fetchAttributes.addObject(countAttribute);

    ERXSQLHelper sqlHelper = ERXSQLHelper.newSQLHelper(_entity.model());
  EOQualifier combinedAdditionalQualifier = null;
  EOQualifier additionalTagCountQualifier = additionalTagCountQualifier();
View Full Code Here

    // sqlExpr.selectStatementForAttributes.
    sqlHelper.removeSelectFromExpression(tagNameAttribute, sqlExpression);

    NSMutableArray<Object> itemPrimaryKeys = new NSMutableArray<Object>();
    NSArray<NSDictionary> rawRows = ERXEOAccessUtilities.rawRowsForSQLExpression(editingContext, _entity.model(), sqlExpression, pkAttrs);
    EOAttribute pkAttr = pkAttrs.objectAtIndex(0);
    for (NSDictionary rawRow : rawRows) {
      Object pk = rawRow.objectForKey(pkAttr.name());
      itemPrimaryKeys.addObject(pk);
    }

    NSMutableArray<EOAttribute> tagsFetchAttributes = new NSMutableArray<EOAttribute>();
    // MS: We put this in just because we want to force it to do the join ... We have to
    // pull them out later.
    tagsFetchAttributes.addObjectsFromArray(_entity.primaryKeyAttributes());

    ERXEOAttribute tagIDAttribute = new ERXEOAttribute(_entity, _tagsRelationship.name() + ".id");
    tagIDAttribute.setName("id");
    tagsFetchAttributes.addObject(tagIDAttribute);
    tagsFetchAttributes.addObject(tagNameAttribute);

    EOAttribute countAttribute = ERXEOAccessUtilities.createAggregateAttribute(editingContext, "COUNT", ERTag.NAME_KEY, _tagEntity.name(), Number.class, "i", "tagCount", "t2");
    tagsFetchAttributes.addObject(countAttribute);

    EOQualifier idQualifier = new ERXKey<Object>("id").in(itemPrimaryKeys);
    EOFetchSpecification tagsFetchSpec = new EOFetchSpecification(_entity.name(), idQualifier, null);
    EOSQLExpression tagsSqlExpression = sqlHelper.sqlExpressionForFetchSpecification(editingContext, tagsFetchSpec, 0, -1, tagsFetchAttributes);
View Full Code Here

      EOEntity dbUpdaterEntity = new EOEntity();
      dbUpdaterEntity.setExternalName(migrationTableName(adaptor));
      dbUpdaterEntity.setName(migrationTableName(adaptor));
      dbUpdaterModel.addEntity(dbUpdaterEntity);

      EOAttribute modelNameAttribute = new EOAttribute();
      if (isWonderPrototype) {
        modelNameAttribute.setExternalType(prototypeEntity.attributeNamed("varchar100").externalType());
      }
      else {
        modelNameAttribute.setExternalType(ERXSQLHelper.newSQLHelper(adaptor).externalTypeForJDBCType(adaptor, Types.VARCHAR));
      }
      modelNameAttribute.setName("modelName");
      modelNameAttribute.setColumnName("modelname");
      modelNameAttribute.setClassName("java.lang.String");
      modelNameAttribute.setWidth(100);
      modelNameAttribute.setAllowsNull(false);
      dbUpdaterEntity.addAttribute(modelNameAttribute);
      dbUpdaterEntity.setPrimaryKeyAttributes(new NSArray<EOAttribute>(modelNameAttribute));

      EOAttribute versionAttribute = new EOAttribute();
      if (isWonderPrototype) {
        versionAttribute.setExternalType(prototypeEntity.attributeNamed("intNumber").externalType());
      }
      else {
        versionAttribute.setExternalType(ERXSQLHelper.newSQLHelper(adaptor).externalTypeForJDBCType(adaptor, Types.INTEGER));
      }
      versionAttribute.setName("version");
      versionAttribute.setColumnName("version");
      versionAttribute.setClassName("java.lang.Number");
      versionAttribute.setValueType("i");
      versionAttribute.setAllowsNull(false);
      dbUpdaterEntity.addAttribute(versionAttribute);

      EOAttribute updateLockAttribute = new EOAttribute();
      if (isWonderPrototype) {
        updateLockAttribute.setExternalType(prototypeEntity.attributeNamed("intNumber").externalType());
      }
      else {
        updateLockAttribute.setExternalType(ERXSQLHelper.newSQLHelper(adaptor).externalTypeForJDBCType(adaptor, Types.INTEGER));
      }
      updateLockAttribute.setName("updateLock");
      updateLockAttribute.setColumnName("updatelock");
      updateLockAttribute.setClassName("java.lang.Number");
      updateLockAttribute.setValueType("i");
      updateLockAttribute.setAllowsNull(false);
      dbUpdaterEntity.addAttribute(updateLockAttribute);

      EOAttribute lockOwnerAttribute = new EOAttribute();
      if (isWonderPrototype) {
        lockOwnerAttribute.setExternalType(prototypeEntity.attributeNamed("varchar100").externalType());
      }
      else {
        lockOwnerAttribute.setExternalType(ERXSQLHelper.newSQLHelper(adaptor).externalTypeForJDBCType(adaptor, Types.VARCHAR));
      }
      lockOwnerAttribute.setName("lockOwner");
      lockOwnerAttribute.setColumnName("lockowner");
      lockOwnerAttribute.setClassName("java.lang.String");
      lockOwnerAttribute.setWidth(100);
      lockOwnerAttribute.setAllowsNull(true);
      dbUpdaterEntity.addAttribute(lockOwnerAttribute);

      _lastUpdatedModel = model;
      _dbUpdaterModelCache = dbUpdaterModel;
    }
View Full Code Here

  public String sqlStringForSQLExpression(EOSQLExpression e) {
    StringBuilder sb = new StringBuilder();
    if (attributeName != null)
      sb.append(e.sqlStringForAttributeNamed(attributeName));
    else {
      EOAttribute pk = e.entity().primaryKeyAttributes().lastObject();
      sb.append(e.sqlStringForAttribute(pk));
    }
    sb.append(" IN ( ");
    EOEntity entity = entityName == null ? e.entity() : e.entity().model().modelGroup().entityNamed(entityName);
View Full Code Here

            }

            String srcEntityForeignKey = null;
            NSArray<EOAttribute> sourceAttributes = relationship.sourceAttributes();
            if (sourceAttributes != null && sourceAttributes.count() > 0) {
                EOAttribute fk = sourceAttributes.lastObject();
                srcEntityForeignKey = expression.sqlStringForAttribute(fk);
            } else {
              // (AR) could not find relationship from source object into "exists" clause, use primary key then instead
                EOAttribute pk = srcEntity.primaryKeyAttributes().lastObject();
                srcEntityForeignKey = expression.sqlStringForAttribute(pk);
            }
           
            EOJoin parentChildJoin = ERXArrayUtilities.firstObject(relationship.joins());
            String destEntityForeignKey = "." + expression.sqlStringForSchemaObjectName(parentChildJoin.destinationAttribute().columnName());
           
            EOQualifier qual = EOQualifierSQLGeneration.Support._schemaBasedQualifierWithRootEntity(subqualifier, destEntity);
            EOFetchSpecification fetchSpecification = new EOFetchSpecification(destEntity.name(), qual, null, false, true, null);

            EODatabaseContext context = EODatabaseContext.registeredDatabaseContextForModel(destEntity.model(), EOObjectStoreCoordinator.defaultCoordinator());
            EOSQLExpressionFactory factory = context.database().adaptor().expressionFactory();

            EOSQLExpression subExpression = factory.expressionForEntity(destEntity);
            subExpression.setUseAliases(true);
            subExpression.prepareSelectExpressionWithAttributes(destEntity.primaryKeyAttributes(), false, fetchSpecification);

            for (Enumeration bindEnumeration = subExpression.bindVariableDictionaries().objectEnumerator(); bindEnumeration.hasMoreElements();) {
                expression.addBindVariableDictionary((NSDictionary)bindEnumeration.nextElement());
            }

            String subExprStr = subExpression.statement();

        Matcher matcher = PATTERN.matcher(subExprStr);
        if (matcher.find()) {
          subExprStr = matcher.replaceAll("$1" + EXISTS_ALIAS + "$3$4");
        }
       
            StringBuffer sb = new StringBuffer();
            if (existsQualifier.usesInQualInstead()) {
              // (AR) Write the IN clause
                sb.append(srcEntityForeignKey);
                sb.append(" IN ( ");
               
                // (AR) Rewrite first SELECT part of subExprStr
                EOAttribute destPK = destEntity.primaryKeyAttributes().lastObject();
                String destEntityPrimaryKey = expression.sqlStringForAttribute(destPK);
                int indexOfFirstPeriod = destEntityPrimaryKey.indexOf(".");
                destEntityPrimaryKey = destEntityPrimaryKey.substring(indexOfFirstPeriod);
                subExprStr = StringUtils.replaceOnce(
                    subExprStr,
View Full Code Here

         */
        private String sqlStringForAttributeNamedInExpression(String name, EOSQLExpression expression) {
            NSArray<String> pieces = NSArray.componentsSeparatedByString(name, ".");
            EOEntity entity = expression.entity();
            EORelationship rel;
            EOAttribute att;
            NSMutableArray<EOProperty> path = new NSMutableArray<EOProperty>();
            int numPieces = pieces.count();

            if (numPieces == 1 && null == entity.anyRelationshipNamed(name)) {
                att = entity.anyAttributeNamed(name);
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.