Package com.webobjects.eocontrol

Examples of com.webobjects.eocontrol.EOFetchSpecification


  }

  public ERXEnterpriseObject refetchObjectFromDBinEditingContext(EOEditingContext ec) {
    EOEntity entity = ERXEOAccessUtilities.entityNamed(ec, entityName());
    EOQualifier qual = entity.qualifierForPrimaryKey(primaryKeyDictionary(false));
    EOFetchSpecification fetchSpec = new EOFetchSpecification(entityName(), qual, null);
    fetchSpec.setRefreshesRefetchedObjects(true);
    NSArray results = ec.objectsWithFetchSpecification(fetchSpec);
    ERXEnterpriseObject freshObject = null;
    if (results.count() > 0) {
      freshObject = (ERXEnterpriseObject) results.objectAtIndex(0);
    }
View Full Code Here


    if (fetchSpec.prefetchingRelationshipKeyPaths().count() > 0) {
      EOEntity rootEntity = dbc.database().entityNamed(fetchSpec.entityName());
      EORelationship relationship = rootEntity.relationshipNamed(relationshipName);
      EOEntity destinationEntity = relationship.destinationEntity();
      if (relationship.isToManyToOne() && destinationEntity.isAbstractEntity() && fetchSpec.prefetchingRelationshipKeyPaths().containsObject(relationship.name())) {
        EOFetchSpecification newFetchSpec = (EOFetchSpecification) fetchSpec.clone();
        String inverseName = relationship.anyInverseRelationship().definition(); // from destination to intermediate
        EOQualifier singleTableRestrict = destinationEntity._singleTableRestrictingQualifier();
        EOQualifier migratedRestrict = EOQualifierSQLGeneration.Support._qualifierMigratedFromEntityRelationshipPath(singleTableRestrict, destinationEntity, inverseName);
        newFetchSpec.setQualifier(new EOAndQualifier(new NSArray(new Object[]{newFetchSpec.qualifier(),migratedRestrict})));
        fetchSpec = newFetchSpec;
      }
    }
    return fetchSpec;
  }
View Full Code Here

        EOSQLExpression expression = context.adaptorContext().adaptor().expressionFactory().expressionForEntity( entity );

        String proceccedQuery = processedQueryString(query, expression, bindings);
        expression.setStatement(proceccedQuery);

        EOFetchSpecification spec = new EOFetchSpecification( entityName, null, null );
        spec.setRefreshesRefetchedObjects(refreshesCache);
        if( fetchLimit != null ) {
            spec.setFetchLimit( fetchLimit );
        }
        spec.setHints( new NSDictionary( expression, EODatabaseContext.CustomQueryExpressionHintKey ) );

        return ec.objectsWithFetchSpecification(spec);
    }
View Full Code Here

        }

        EOSQLExpression expression = databaseContext.adaptorContext().adaptor().expressionFactory().expressionForEntity( entity );
        expression.setStatement(processedQueryString(query, expression, bindings));

        EOFetchSpecification pkSpec = new EOFetchSpecification( entityName, null, null );
        pkSpec.setRefreshesRefetchedObjects(refreshesCache);
        pkSpec.setFetchesRawRows(true);
        pkSpec.setRawRowKeyPaths(entity.primaryKeyAttributeNames());
        pkSpec.setHints( new NSDictionary( expression, EODatabaseContext.CustomQueryExpressionHintKey ) );

        NSArray pkDicts = ec.objectsWithFetchSpecification(pkSpec);
        NSMutableArray pks = new NSMutableArray();
        String pkAtttributeName = entity.primaryKeyAttributes().lastObject().name();

        for ( Enumeration rowEnumerator = pkDicts.objectEnumerator(); rowEnumerator.hasMoreElements(); ) {
            NSDictionary row = (NSDictionary) rowEnumerator.nextElement();
            pks.addObject( row.objectForKey( pkAtttributeName ));
        }

        EOFetchSpecification spec = new EOFetchSpecification(entityName, null, sortOrderings);
        spec.setRefreshesRefetchedObjects( refreshesCache );
        return new ERXFetchSpecificationBatchIterator( spec, pks, ec, batchSize);
    }
View Full Code Here

        EOEntity entity = EOUtilities.entityNamed(ec, entityName);

        EOSQLExpression expression = adaptorChannel.adaptorContext().adaptor().expressionFactory().expressionForEntity( entity );
        expression.setStatement( processedQueryString( query, expression, bindings ) );

        EOFetchSpecification spec = new EOFetchSpecification( entityName, null, null );
        spec.setFetchesRawRows(true);
        spec.setHints( new NSDictionary( expression, EODatabaseContext.CustomQueryExpressionHintKey ) );

        return ec.objectsWithFetchSpecification(spec);
    }
View Full Code Here

     * @see #setRefreshesRefetchedObjects(boolean)
     * @see EOFetchSpecification#refreshesRefetchedObjects()
     */
    @Override
    public EOFetchSpecification fetchSpecificationForFetch() {
        EOFetchSpecification spec = super.fetchSpecificationForFetch();
        spec.setRefreshesRefetchedObjects(refreshesRefetchedObjects());
        spec.setPrefetchingRelationshipKeyPaths(_prefetchingRelationshipKeyPaths);
        return spec;
    }
View Full Code Here

     * @see #setRefreshesRefetchedObjects(boolean)
     * @see EOFetchSpecification#refreshesRefetchedObjects()
     */
    @Override
    public EOFetchSpecification fetchSpecification() {
        EOFetchSpecification spec = super.fetchSpecification();
        spec.setRefreshesRefetchedObjects(refreshesRefetchedObjects());
        spec.setPrefetchingRelationshipKeyPaths(_prefetchingRelationshipKeyPaths);
        return spec;
    }
View Full Code Here

      EOQualifier q2 = new ERXBetweenQualifier("userCount", Long.valueOf(30), Long.valueOf(800));
      // EOQualifier q3 = new EOKeyValueQualifier("userCount", EOQualifier.QualifierOperatorEqual, Long.valueOf(82));
      //EOQualifier q3 = new EOKeyValueQualifier("userCount", EOQualifier.QualifierOperatorLessThan, Long.valueOf(82));
      EOQualifier q3 = new EOKeyValueQualifier("userCount", EOQualifier.QualifierOperatorLessThanOrEqualTo, Long.valueOf(802));
      EOQualifier qualifier = new EOAndQualifier(new NSArray<EOQualifier>(new EOQualifier[]{q1, q2, q3}));
      EOFetchSpecification fs = new EOFetchSpecification("LuceneAsset", qualifier, null);
      fs.setFetchLimit(5);
      fs.setSortOrderings(new NSArray(new EOSortOrdering("userCount", EOSortOrdering.CompareAscending)));
      Query query = ERLuceneAdaptorChannel.queryForQualifier(new EOKeyValueQualifier("userCount", EOQualifier.QualifierOperatorLessThanOrEqualTo, 802), EOUtilities.entityNamed(ec, "LuceneAsset"));
      fs.setHints(new NSDictionary(query, ERLuceneAdaptor.QUERY_HINTS));
      NSArray<EOEnterpriseObject> result = ec.objectsWithFetchSpecification(fs);
      log.info(result.count() + ": " + result.valueForKey("userCount"));
      for (EOEnterpriseObject eo : result) {
        log.info(result.count() + ": " + eo);
      }
View Full Code Here

  public static NSArray<Company> fetchAllCompanies(EOEditingContext editingContext, NSArray<EOSortOrdering> sortOrderings) {
    return _Company.fetchCompanies(editingContext, null, sortOrderings);
  }

  public static NSArray<Company> fetchCompanies(EOEditingContext editingContext, EOQualifier qualifier, NSArray<EOSortOrdering> sortOrderings) {
    EOFetchSpecification fetchSpec = new EOFetchSpecification(_Company.ENTITY_NAME, qualifier, sortOrderings);
    fetchSpec.setIsDeep(true);
    NSArray<Company> eoObjects = (NSArray<Company>)editingContext.objectsWithFetchSpecification(fetchSpec);
    return eoObjects;
  }
View Full Code Here

        return ERXStringUtilities.attributeValueFromString(attribute, stringValue, context().request().formValueEncoding(), new NSTimestampFormatter());
    }

    /** Retrieves and executes the fetch specification given in the request. */
    public EOFetchSpecification fetchSpecificationFromRequest(String entityName) {
      EOFetchSpecification fs = null;
      if(context().request().formValueKeys().containsObject(fetchSpecificationKey)) {
        String fsName = context().request().stringFormValueForKey(fetchSpecificationKey);
        if(ERXStringUtilities.stringIsNullOrEmpty(fsName)) {
          EOEntity rootEntity = ERXEOAccessUtilities.entityNamed(session().defaultEditingContext(), entityName);
         
          NSMutableArray qualifiers = new NSMutableArray();
          for(Enumeration e = context().request().formValueKeys().objectEnumerator(); e.hasMoreElements(); ) {
            String key = (String)e.nextElement();
            EOEntity entity = rootEntity;
            EOAttribute attribute = null;
            String attributeName = key;
            if(key.indexOf(".") > 0) {
              String path = ERXStringUtilities.keyPathWithoutLastProperty(key);
              attributeName = ERXStringUtilities.lastPropertyKeyInKeyPath(key);
              entity = ERXEOAccessUtilities.destinationEntityForKeyPath(rootEntity, path);
            }
            if(entity != null) {
              attribute = entity.attributeNamed(attributeName);
              if(attribute != null) {
                String stringValue = context().request().stringFormValueForKey(key);
                if(stringValue != null) {
                  Object value = null;
                  NSSelector selector = EOKeyValueQualifier.QualifierOperatorEqual;
                  if(stringValue.indexOf('*') >= 0) {
                    selector = EOKeyValueQualifier.QualifierOperatorCaseInsensitiveLike;
                  }
                  if(!NSKeyValueCoding.NullValue.toString().equals(stringValue)) {
                                    //AK: I still don't like this...in particular the new NSTimestampFormatter() which would be totally arbitrary...
                    value = qualifierValueForAttribute(attribute, stringValue);
                    if(value!=null) {
                        qualifiers.addObject(new EOKeyValueQualifier(key, selector, value));
                    }
                  } else {
                    qualifiers.addObject(new EOKeyValueQualifier(key, selector, value));
                  }
                }
              }
            }
          }
          EOQualifier qualifier = null;
          if(qualifiers.count() > 0) {
            qualifier = new EOAndQualifier(qualifiers);
          }
          fs = new EOFetchSpecification(entityName, qualifier, null);
         
          boolean usesDictinct = ERXValueUtilities.booleanValueWithDefault(context().request().stringFormValueForKey(usesDistinctKey), true);
          fs.setUsesDistinct(usesDictinct);
         
          int limit = ERXValueUtilities.intValueWithDefault(context().request().stringFormValueForKey(fetchLimitKey), 200);
          fs.setFetchLimit(limit);
        } else {
          fs = EOFetchSpecification.fetchSpecificationNamed(fsName, entityName);
          NSMutableDictionary bindings = new NSMutableDictionary();
          Enumeration e = fs.qualifier().bindingKeys().objectEnumerator();
          while(e.hasMoreElements()) {
            String key = (String)e.nextElement();
            String formValue = context().request().stringFormValueForKey(key);
            if(formValue != null) {
              bindings.setObjectForKey(formValue, key);
            }
          }
         
          if(bindings.count() > 0) {
            fs = fs.fetchSpecificationWithQualifierBindings(bindings);
          }
        }
      }
      return fs;
    }
View Full Code Here

TOP

Related Classes of com.webobjects.eocontrol.EOFetchSpecification

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.