Package com.webobjects.eoaccess

Examples of com.webobjects.eoaccess.EOSQLExpression


        boolean usesDistinct = spec.usesDistinct();
        spec = new EOFetchSpecification(spec.entityName(), spec.qualifier(), null);
        spec.setUsesDistinct(usesDistinct);
      }

      EOSQLExpression sqlExpression = sqlExpressionForFetchSpecification(ec, spec, 0, -1);
      String statement = sqlExpression.statement();
      String listString = sqlExpression.listString();

      String countExpression;
      if (spec.usesDistinct()) {
        countExpression = sqlForCountDistinct(entity);
      } else {
        countExpression = "count(*) ";
      }
      statement = statement.replace(listString, countExpression);
      sqlExpression.setStatement(statement);
      sql = statement;
      result = ERXEOAccessUtilities.rawRowsForSQLExpression(ec, model.name(), sqlExpression);
    }
    else {
      // we have hints
View Full Code Here


          NSArray expressions = super.primaryKeyConstraintStatementsForEntityGroup(entityGroup);
          if( (expressions != null) && (expressions.count() > 0) ) primaryKeyConstraintExpressions.addObjectsFromArray(expressions);
          for (Enumeration attributeEnumerator = primaryKeyAttributes.objectEnumerator(); attributeEnumerator.hasMoreElements(); ) {
            String columnName = ((EOAttribute)attributeEnumerator.nextElement()).columnName();
            columnNameDictionary.setObjectForKey(columnName, entity.externalName() + "." + columnName);
            EOSQLExpression expression = this._expressionForString("create " + ( singlePrimaryKey ? "unique" : "" ) + " index " + entity.externalName() + " " + columnName);
            if(expression != null) primaryKeyConstraintExpressions.addObject( expression );
          }
        }
      }
     
      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

    public NSArray statementsToImplementPrimaryKeyConstraintsOnEntityGroups(NSArray entityGroups, EOSchemaSynchronizationModelChanges changes, EOSchemaGenerationOptions options) {
      NSArray primaryKeyExpressions = this.primaryKeyConstraintStatementsForEntityGroups(entityGroups);
      NSMutableArray createStatements = new NSMutableArray();
      NSMutableArray otherStatements = new NSMutableArray();
      for (Enumeration enumerator = primaryKeyExpressions.objectEnumerator(); enumerator.hasMoreElements(); ) {
        EOSQLExpression expression = (EOSQLExpression)enumerator.nextElement();
        String statement = expression.statement();
        if(statement.startsWith("create")) {
          createStatements.addObject(expression);
        } else if( ! statement.startsWith("delete from _SYS_RELATIONSHIP") ) {
          otherStatements.addObject(expression);
        }
View Full Code Here

        NSDictionary dictionary = entity.userInfo();
        if (dictionary.valueForKey("Restrict") != null && ((String) dictionary.valueForKey("Restrict")).equals("true"))
          dropType = " RESTRICT";
      }

      EOSQLExpression expression = _expressionForString("DROP TABLE " + quoteTableName(entity.externalName()) + dropType);

      return new NSArray<EOSQLExpression>(expression);
    }
View Full Code Here

    /**
     * <span class="ja">エンティティ・グループの SQL を生成します</span>
     */
    @Override
    public NSArray<EOSQLExpression> createTableStatementsForEntityGroup(NSArray<EOEntity> entityGroup) {
      EOSQLExpression eosqlexpression = null;
      EOEntity eoentity = null;
      NSMutableArray<String> nsmutablearray = new NSMutableArray<String>();
      int j = entityGroup != null ? entityGroup.count() : 0;

      if (j == 0)
        return NSArray.emptyArray();

      // 出力バッファーを準備
      StringBuilder columns = new StringBuilder();
     
      // エンティティの出力開始
      eosqlexpression = _expressionForEntity(entityGroup.objectAtIndex(0));

      // 各エンティティをループで回す
      for (int i = 0; i < j; i++) {
        eoentity = entityGroup.objectAtIndex(i);
        NSArray nsarray1 = eoentity.attributes();
        int l = nsarray1 != null ? nsarray1.count() : 0;

        for (int k = 0; k < l; k++) {
          EOAttribute eoattribute = (EOAttribute) nsarray1.objectAtIndex(k);
          String column = eoattribute.columnName();

          if (!eoattribute.isDerived() && !eoattribute.isFlattened() && column != null && column.length() > 0 && nsmutablearray.indexOfObject(column) == NSArray.NotFound) {

            if (columns.length() > 0) {
              columns.append(',');
              columns.append('\n');
              columns.append('\t');
            }

            columns.append(addCreateClauseForAttribute(eoattribute));
            nsmutablearray.addObject(column);
          }
        }
      }

      StringBuilder sql = new StringBuilder();
      sql.append("CREATE TABLE ");
      sql.append(quoteTableName(eoentity.externalName()));
      sql.append(" (\n\t");
      sql.append(columns.toString());
      sql.append("\n)");

      eosqlexpression.setStatement(sql.toString());

      return new NSArray<EOSQLExpression>(eosqlexpression);
    }
View Full Code Here

    }

    @Override
    public NSArray<EOSQLExpression> createIndexStatementsForEntityGroup(NSArray<EOEntity> entityGroup) {
      NSMutableArray<EOSQLExpression> result = new NSMutableArray<EOSQLExpression>();
      EOSQLExpression eosqlexpression = null;
      EOEntity eoentity = null;
      int j = entityGroup != null ? entityGroup.count() : 0;

      if (j == 0)
        return NSArray.emptyArray();

      eosqlexpression = _expressionForEntity(entityGroup.objectAtIndex(0));

      for (int i = 0; i < j; i++) {
        eoentity = entityGroup.objectAtIndex(i);
        NSDictionary dictionary = eoentity.userInfo();

        if (dictionary != null && dictionary.valueForKey("Index") != null) {
          dictionary = (NSDictionary) dictionary.valueForKey("Index");
          java.util.Enumeration e = dictionary.keyEnumerator();

          while (e.hasMoreElements()) {
            eosqlexpression.setStatement((String) dictionary.objectForKey(e.nextElement()));
            result.addObject(eosqlexpression);
          }
        }
      }
      return result;
View Full Code Here

    /**
     * <span class="ja">1つのアトリビュートの SQL を生成します </span>
     */
    public StringBuilder addCreateClauseForAttribute(EOAttribute eoattribute) {
      EOSQLExpression expression = _expressionForEntity(eoattribute.entity());
      expression.addCreateClauseForAttribute(eoattribute);
      return new StringBuilder(expression.listString());
    }
View Full Code Here

      expression.addCreateClauseForAttribute(eoattribute);
      return new StringBuilder(expression.listString());
    }

    public String columnTypeStringForAttribute(EOAttribute eoattribute) {
      EOSQLExpression expression = _expressionForEntity(eoattribute.entity());
      return expression.columnTypeStringForAttribute(eoattribute);
    }
View Full Code Here

    }

    sql.append(')');

    boolean pksGenerated = false;
    EOSQLExpression eosqlexpression = expressionFactory().expressionForString(sql.toString());
    EOAdaptorContext adaptorContext = jdbcchannel.adaptorContext();
    adaptorContext.transactionDidBegin();
    jdbcchannel.evaluateExpression(eosqlexpression);
    if (jdbcchannel._errorEvaluateExpression()) {
      adaptorContext.transactionDidRollback();
View Full Code Here

      EOQualifier qualifier = entity.restrictingQualifier();
      if (qualifier != null) {
        EOAdaptor adaptor = EOAdaptor.adaptorWithName("JDBC");
        adaptor.setConnectionDictionary(_sourceDictionary);
        EOSQLExpressionFactory factory = adaptor.expressionFactory();
        EOSQLExpression sqlExpression = factory.createExpression(entity);
        String sqlString = EOQualifierSQLGeneration.Support._sqlStringForSQLExpression(qualifier, sqlExpression);
        selectBuf.append(" where ").append(sqlString);
      }
      selectBuf.append(';');
      String sql = selectBuf.toString();
View Full Code Here

TOP

Related Classes of com.webobjects.eoaccess.EOSQLExpression

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.