Package er.extensions.jdbc

Examples of er.extensions.jdbc.ERXSQLHelper


      dbc.lock();
      try {
        EOAdaptorChannel channel = dbc.availableChannel().adaptorChannel();
        if (eomodel.adaptorName().contains("JDBC")) {
          EOSynchronizationFactory syncFactory = (EOSynchronizationFactory) channel.adaptorContext().adaptor().synchronizationFactory();
          ERXSQLHelper helper = ERXSQLHelper.newSQLHelper(channel);
          NSDictionary options = helper.defaultOptionDictionary(true, dropTables);

          // Primary key support creation throws an unwanted exception
          // if
          // EO_PK_TABLE already
          // exists (e.g. in case of MySQL), so we add pk support in a
View Full Code Here


    }
    else {
      // we have hints, use them
     
      EOModel model = EOModelGroup.defaultGroup().entityNamed(spec.entityName()).model();
      ERXSQLHelper sqlHelper = ERXSQLHelper.newSQLHelper(ec, model.name());
      Object hint = spec.hints().valueForKey(EODatabaseContext.CustomQueryExpressionHintKey);
      String sql = sqlHelper.customQueryExpressionHintAsString(hint);
      sql = sqlHelper.limitExpressionForSQL(null, spec, sql, start, end);
     
      if (rawRowsForCustomQueries) {
        result = EOUtilities.rawRowsForSQL(ec, model.name(), sql, null);
      }
      else {
View Full Code Here

          throw NSForwardException._runtimeExceptionForThrowable(new IllegalArgumentException(SQLDUMP_FILE_NOT_WRITEABLE));
        }
        EOAdaptor adaptor = EOAdaptor.adaptorWithModel(eomodel);
        if (adaptor instanceof JDBCAdaptor) {
          JDBCAdaptor jdbc = (JDBCAdaptor) adaptor;
          ERXSQLHelper helper = ERXSQLHelper.newSQLHelper(jdbc);
          String sql = helper.createSchemaSQLForEntitiesInModelAndOptions(eomodel.entities(), eomodel, helper.defaultOptionDictionary(true, true));
          ERXFileUtilities.writeInputStreamToFile(new ByteArrayInputStream(sql.getBytes()), dumpFile);
          log.info("Wrote Schema SQL to " + dumpFile);
        }
      } catch (java.io.IOException e) {
        throw NSForwardException._runtimeExceptionForThrowable(e);
View Full Code Here

        EOEntity entity = ERXEOAccessUtilities.entityNamed(ec, spec.entityName());
        EOModel model = entity.model();
        EODatabaseContext dbc = EODatabaseContext.registeredDatabaseContextForModel(model, ec);
        dbc.lock();
        try {
          ERXSQLHelper sqlHelper = ERXSQLHelper.newSQLHelper(ec, model.name());
          expression = sqlHelper.sqlExpressionForFetchSpecification(ec, spec, start, end);
        }
        catch (Exception e) {
          throw NSForwardException._runtimeExceptionForThrowable(e);
      }
        finally {
View Full Code Here

    NSArray<String> tagNames = splitTagNames(tags);
    if (tagNames.count() == 0) {
      throw new IllegalArgumentException("No tags were passed in.");
    }

    ERXSQLHelper sqlHelper = ERXSQLHelper.newSQLHelper(_entity.model());

    EOQualifier qualifier = new ERXKey<ERTag>(_tagsRelationship.name()).append(ERTag.NAME).in(tagNames);
    if (additionalQualifier != null) {
      qualifier = ERXQ.and(qualifier, additionalQualifier);
    }
   
    EOFetchSpecification fetchSpec = new EOFetchSpecification(_entity.name(), qualifier, sortOrderings);

    EOSQLExpression sqlExpression = sqlHelper.sqlExpressionForFetchSpecification(editingContext, fetchSpec, 0, limit);
    sqlHelper.addGroupByClauseToExpression(editingContext, fetchSpec, sqlExpression);
    if (inclusion == ERTag.Inclusion.ALL) {
      sqlHelper.addHavingCountClauseToExpression(EOQualifier.QualifierOperatorEqual, tagNames.count(), sqlExpression);
    }

    NSArray<NSDictionary> rawRows = ERXEOAccessUtilities.rawRowsForSQLExpression(editingContext, _entity.model(), sqlExpression, sqlHelper.attributesToFetchForEntity(fetchSpec, _entity));
    NSArray<T> objs;
    objs = ERXEOControlUtilities.faultsForRawRowsFromEntity(editingContext, rawRows, _entity.name());
    objs = ERXEOControlUtilities.objectsForFaultWithSortOrderings(editingContext, objs, fetchSpec.sortOrderings());
    return objs;
  }
View Full Code Here

    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();
  if (additionalTagCountQualifier != null || additionalQualifier != null) {
    combinedAdditionalQualifier = ERXQ.and(additionalQualifier, additionalTagCountQualifier);
  }
  EOFetchSpecification fetchSpec = new EOFetchSpecification(_entity.name(), combinedAdditionalQualifier, null);
    EOSQLExpression sqlExpression = sqlHelper.sqlExpressionForFetchSpecification(editingContext, fetchSpec, 0, limit, fetchAttributes);
    NSMutableArray<EOAttribute> groupByAttributes = new NSMutableArray<EOAttribute>(tagNameAttribute);
    sqlHelper.addGroupByClauseToExpression(groupByAttributes, sqlExpression);
    if (selector != null) {
      sqlHelper.addHavingCountClauseToExpression(selector, count, sqlExpression);
    }
    if (limit > 0) {
      // MS: This is lame, but the dynamic attribute is not properly resolved
      // inside of EOSQLExpression because it's not actually part of the entity,
      // so you can't order-by one of these attributes.  So we just have to stick
      // it on the end and hope for the best.
      StringBuilder sqlBuffer = new StringBuilder(sqlExpression.statement());
      int orderByIndex = sqlHelper._orderByIndex(sqlExpression);
      sqlBuffer.insert(orderByIndex, " ORDER BY tagCount DESC");
      sqlExpression.setStatement(sqlBuffer.toString());
    }

    NSMutableDictionary<String, Integer> tagCounts = new NSMutableDictionary<String, Integer>();
View Full Code Here

    EOQualifier qualifier = new ERXKey<ERTag>(_tagsRelationship.name()).append(ERTag.NAME).in(tagNames);
    EOFetchSpecification fetchSpec = new EOFetchSpecification(_entity.name(), qualifier, null);
    fetchSpec.setUsesDistinct(true);

    ERXSQLHelper sqlHelper = ERXSQLHelper.newSQLHelper(_entity.model());
    EOSQLExpression sqlExpression = sqlHelper.sqlExpressionForFetchSpecification(editingContext, fetchSpec, 0, -1);
    sqlHelper.addGroupByClauseToExpression(editingContext, fetchSpec, sqlExpression);
    if (inclusion == ERTag.Inclusion.ALL) {
      sqlHelper.addHavingCountClauseToExpression(EOQualifier.QualifierOperatorEqual, tagNames.count(), sqlExpression);
    }

    int count = sqlHelper.rowCountForFetchSpecification(editingContext, fetchSpec);
    return count;
  }
View Full Code Here

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

    ERXSQLHelper sqlHelper = ERXSQLHelper.newSQLHelper(_entity.model());
    EOQualifier tagNameQualifier = new ERXKey<ERTag>(_tagsRelationship.name()).append(ERTag.NAME).in(tagNames);
    EOFetchSpecification fetchSpec = new EOFetchSpecification(_entity.name(), tagNameQualifier, null);
    EOSQLExpression sqlExpression = sqlHelper.sqlExpressionForFetchSpecification(editingContext, fetchSpec, 0, -1, fetchAttributes);
    NSMutableArray<EOAttribute> groupByAttributes = new NSMutableArray<EOAttribute>();
    groupByAttributes.addObjectsFromArray(pkAttrs);
    sqlHelper.addGroupByClauseToExpression(groupByAttributes, sqlExpression);
    sqlHelper.addHavingCountClauseToExpression(EOQualifier.QualifierOperatorEqual, tagNames.count(), sqlExpression);

    // MS: Sketchy, I know, but I don't know how to make it do the
    // join for me without also having the tag name field selected.  I'm sure it's
    // possible if I drop down and use lower level API's than
    // 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);
    NSMutableArray<EOAttribute> tagsGroupByAttributes = new NSMutableArray<EOAttribute>(new EOAttribute[] { tagNameAttribute, tagIDAttribute });
    sqlHelper.addGroupByClauseToExpression(tagsGroupByAttributes, tagsSqlExpression);

    // MS: This is lame, but the dynamic attribute is not properly resolved
    // inside of EOSQLExpression because it's not actually part of the entity,
    // so you can't order-by one of these attributes.  So we just have to stick
    // it on the end and hope for the best.
    tagsSqlExpression.setStatement(tagsSqlExpression.statement() + " ORDER BY tagCount DESC");

    for (EOAttribute attribute : _entity.primaryKeyAttributes()) {
      sqlHelper.removeSelectFromExpression(attribute, tagsSqlExpression);
      tagsFetchAttributes.removeObject(attribute);
    }

    NSMutableArray<String> relatedTagNames = new NSMutableArray<String>();
    NSArray<NSDictionary> tagsRawRows = ERXEOAccessUtilities.rawRowsForSQLExpression(editingContext, _entity.model(), tagsSqlExpression, tagsFetchAttributes);
View Full Code Here

    public void createTables(EOEditingContext ec, String modelName) throws SQLException {
        // AK: FIXME we should try with the DROP options enabled and re-try with the options disabled
        // so we catch the case when we
        EODatabaseContext databaseContext = EOUtilities.databaseContextForModelNamed(ec, modelName);
        ERXSQLHelper helper = ERXSQLHelper.newSQLHelper(databaseContext);
        String sql = helper.createSchemaSQLForEntitiesInModelWithName(null, modelName);
        NSArray sqls = helper.splitSQLStatements(sql);
        EOAdaptorChannel channel = databaseContext.availableChannel().adaptorChannel();
        ERXJDBCUtilities.executeUpdateScript(channel, sql);
    }
View Full Code Here

   * @param allowsNull if true, the column will allow null values
   * @return the new ERXMigrationColumn
   * @throws SQLException if the column cannot be created
   */
  public ERXMigrationColumn newLargeStringColumn(String name, boolean allowsNull) throws SQLException {
    ERXSQLHelper sqlHelper = ERXSQLHelper.newSQLHelper(_database.adaptorChannel());
    return newColumn(name, sqlHelper.varcharLargeJDBCType(), sqlHelper.varcharLargeColumnWidth(), 0, 0, allowsNull, null);
  }
View Full Code Here

TOP

Related Classes of er.extensions.jdbc.ERXSQLHelper

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.