Examples of EOSQLExpressionFactory


Examples of com.webobjects.eoaccess.EOSQLExpressionFactory

    }
   
    private static Object __aggregateFunctionWithQualifierAndAggregateAttribute(EODatabaseContext databaseContext, EOEditingContext ec, String entityName, EOQualifier qualifier, EOAttribute aggregateAttribute) {
        EOEntity entity = ERXEOAccessUtilities.entityNamed(ec, entityName);

        EOSQLExpressionFactory sqlFactory = databaseContext.adaptorContext().adaptor().expressionFactory();
        EOQualifier schemaBasedQualifier = entity.schemaBasedQualifier(qualifier);
        EOFetchSpecification fetchSpec = new EOFetchSpecification(entity.name(), schemaBasedQualifier, null);
        fetchSpec.setFetchesRawRows(true);

        if (sqlFactory == null) {
          /* if there is no expression factory we have no choice but to fetch */
          NSArray<?> array = ec.objectsWithFetchSpecification(fetchSpec);
          if (aggregateAttribute == EOEnterpriseObjectClazz.objectCountAttribute()) {
            return array.count();
          }
          if (aggregateAttribute.name().startsWith("p_objectCountUnique")) {
            String attributeName = aggregateAttribute.name().substring("p_objectCountUnique".length());
            return ERXArrayUtilities.arrayWithoutDuplicateKeyValue(array, attributeName).count();
          }
          throw new UnsupportedOperationException("Unable to perform aggregate function for attribute " + aggregateAttribute.name());
        }
       
        EOSQLExpression sqlExpr = sqlFactory.expressionForEntity(entity);
        sqlExpr.prepareSelectExpressionWithAttributes(new NSArray<EOAttribute>(aggregateAttribute), false, fetchSpec);

        EOAdaptorChannel adaptorChannel = databaseContext.availableChannel().adaptorChannel();
        if (!adaptorChannel.isOpen()) {
            adaptorChannel.openChannel();
View Full Code Here

Examples of com.webobjects.eoaccess.EOSQLExpressionFactory

        try {
          EOAdaptorChannel adaptorChannel = dbContext.availableChannel().adaptorChannel();
          if (!adaptorChannel.isOpen()) {
            adaptorChannel.openChannel();
          }
          EOSQLExpressionFactory factory = adaptorChannel.adaptorContext().adaptor().expressionFactory();
      if (ERXEOAccessUtilities.log.isInfoEnabled()) {
        ERXEOAccessUtilities.log.info("Executing " + exp);
      }
          // If channel.evaluateExpression throws when committing, it won't close the JDBC transaction
          // Probably a bug in JDBCChannel, but we must take care of it
          boolean contextHadOpenTransaction = adaptorChannel.adaptorContext().hasOpenTransaction();
      try {
        adaptorChannel.evaluateExpression(factory.expressionForString(exp));       
      }
      catch (EOGeneralAdaptorException e) {
        if (adaptorChannel.adaptorContext().hasOpenTransaction() && ! contextHadOpenTransaction) {
          adaptorChannel.adaptorContext().rollbackTransaction();
        }
View Full Code Here

Examples of com.webobjects.eoaccess.EOSQLExpressionFactory

    // Note you can't use:
    // EOAdaptor.adaptorWithModel(e.entity().model()).expressionFactory();
    // as this creates a
    //
    EODatabaseContext context = EODatabaseContext.registeredDatabaseContextForModel(entity.model(), EOObjectStoreCoordinator.defaultCoordinator());
    EOSQLExpressionFactory factory = context.database().adaptor().expressionFactory();

    NSArray subAttributes = destinationAttName != null ? new NSArray(entity.attributeNamed(destinationAttName)) : entity.primaryKeyAttributes();

    EOSQLExpression subExpression = factory.expressionForEntity(entity);

    // Arroz: Having this table identifier replacement causes serious
    // problems if you have more than a table being processed in the subquery. Disabling
    // it will apparently not cause problems, because t0 inside the subquery is not
    // the same t0 outside it.
View Full Code Here

Examples of com.webobjects.eoaccess.EOSQLExpressionFactory

           
            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());
View Full Code Here

Examples of com.webobjects.eoaccess.EOSQLExpressionFactory

  public EOSQLExpression sqlExpressionForFetchSpecification(EOEditingContext ec, EOFetchSpecification spec, long start, long end, NSArray<EOAttribute> attributes) {
    EOEntity entity = ERXEOAccessUtilities.entityNamed(ec, spec.entityName());
    EOModel model = entity.model();
    EODatabaseContext dbc = EOUtilities.databaseContextForModelNamed(ec, model.name());
    EOAdaptor adaptor = dbc.adaptorContext().adaptor();
    EOSQLExpressionFactory sqlFactory = adaptor.expressionFactory();
    spec = (EOFetchSpecification) spec.clone();

    EOQualifier qualifier = spec.qualifier();
    if (qualifier != null) {
      qualifier = EOQualifierSQLGeneration.Support._schemaBasedQualifierWithRootEntity(qualifier, entity);
    }
    if (qualifier != spec.qualifier()) {
      spec.setQualifier(qualifier);
    }
    if (spec.fetchLimit() > 0) {
      spec.setFetchLimit(0);
      spec.setPromptsAfterFetchLimit(false);
    }
    spec = ERXEOAccessUtilities.localizeFetchSpecification(ec, spec);
    if (attributes == null) {
      attributes = attributesToFetchForEntity(spec, entity);
    }
    EOSQLExpression sqlExpr = sqlFactory.selectStatementForAttributes(attributes, false, spec, entity);
    String sql = sqlExpr.statement();
    if (spec.hints() != null && !spec.hints().isEmpty() && spec.hints().valueForKey(EODatabaseContext.CustomQueryExpressionHintKey) != null) {
      Object hint = spec.hints().valueForKey(EODatabaseContext.CustomQueryExpressionHintKey);
      sql = customQueryExpressionHintAsString(hint);
    }
View Full Code Here

Examples of com.webobjects.eoaccess.EOSQLExpressionFactory

      }
      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

Examples of com.webobjects.eoaccess.EOSQLExpressionFactory

    public DatabaseSequence(EOEditingContext ec, String modelName, String name, long initialValue) {
      super(name, initialValue);
      EOModel model = ERXEOAccessUtilities.modelGroup(ec).modelNamed(modelName);
      _broker = ERXJDBCConnectionBroker.connectionBrokerForModel(model);
        _factory = new EOSQLExpressionFactory(EOAdaptor.adaptorWithModel(model));
      _lastValue = increasedMaxValue(0);
      _maxValue = _lastValue;
    }
View Full Code Here

Examples of com.webobjects.eoaccess.EOSQLExpressionFactory

            EOKeyGlobalID kgid = (EOKeyGlobalID)gid;
            gidString = "<" +  kgid.entityName() + ": [" ;
            EOEntity entity = ERXEOAccessUtilities.entityNamed(null, kgid.entityName());
            NSArray pks = entity.primaryKeyAttributes();
            NSArray values = kgid.keyValuesArray();
            EOSQLExpressionFactory expressionFactory = context.database().adaptor().expressionFactory();
            EOSQLExpression expression = null;
            if (expressionFactory != null) {
              expression = expressionFactory.expressionForEntity(entity);
            }
            for(int i = 0; i < pks.count(); i++) {
                Object value = values.objectAtIndex(i);
                EOAttribute attribute = (EOAttribute) pks.objectAtIndex(i);
                // ak: only Postgres seems to return reasonable values here...
View Full Code Here

Examples of com.webobjects.eoaccess.EOSQLExpressionFactory

   */
  public void testRawRowsForSQLExpressionEOEditingContextStringEOSQLExpression() {

    EOAdaptor adaptor = EOAdaptor.adaptorWithName(EOModelGroup.defaultGroup().modelNamed(ERXTestSuite.ERXTEST_MODEL).adaptorName());
    if (skipTestsForAdaptor.objectForKey(adaptor.name()).contains("testRawRowsForSQLExpressionEOEditingContextStringEOSQLExpression")) return;
    EOSQLExpressionFactory factory = new EOSQLExpressionFactory(adaptor);
    NSArray<EOEntity> entities = EOModelGroup.defaultGroup().modelNamed(ERXTestSuite.ERXTEST_MODEL).entities();
    NSMutableDictionary<String,Number> counts = new NSMutableDictionary<String,Number>();

    for (EOEntity entity : entities) {
      EOSQLExpression sqlExp = factory.selectStatementForAttributes(entity.attributes(),
                false,
                new EOFetchSpecification(entity.name(), null, null),
                entity);
      NSArray rows = ERXEOAccessUtilities.rawRowsForSQLExpression(ec, ERXTestSuite.ERXTEST_MODEL, sqlExp);

      counts.setObjectForKey(rows.size(), entity.name());
    }

    ERXTestUtilities.createCompanyAnd3Employees();

    NSMutableSet<String> hasMore = new NSMutableSet<String>();

    for (EOEntity entity : entities) {
      EOSQLExpression sqlExp = factory.selectStatementForAttributes(entity.attributes(),
                false,
                new EOFetchSpecification(entity.name(), null, null),
                entity);
      NSArray rows = ERXEOAccessUtilities.rawRowsForSQLExpression(ec, ERXTestSuite.ERXTEST_MODEL, sqlExp);

View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.