Package com.webobjects.eocontrol

Examples of com.webobjects.eocontrol.EOFetchSpecification


     *     specification
     * @return number of objects matching the given fetch  specification and
     *     bindings
     */
    public Number objectCountWithFetchSpecificationAndBindings(EOEditingContext ec, String fetchSpecName,  NSDictionary bindings) {
        EOFetchSpecification unboundFetchSpec;
        EOFetchSpecification boundFetchSpec;

        unboundFetchSpec = fetchSpecificationNamed(ec, fetchSpecName);
        if (unboundFetchSpec == null) {
            return null;
        }
        boundFetchSpec = unboundFetchSpec.fetchSpecificationWithQualifierBindings(bindings);
        return objectCountWithQualifier(ec, boundFetchSpec.qualifier());
    }
View Full Code Here


     *     a given qualifier and sort orderings.
     */
    // FIXME: The ec parameter is not needed, nor used.
    public EOFetchSpecification primaryKeyFetchSpecificationForEntity(EOEditingContext ec, EOQualifier eoqualifier, NSArray sortOrderings, NSArray additionalKeys) {
        String entityName = entityName();
        EOFetchSpecification fs = new EOFetchSpecification(entityName, eoqualifier, sortOrderings);
        fs.setFetchesRawRows(true);
        EOEntity entity = entity(ec);
        NSMutableArray keys = new NSMutableArray(entity.primaryKeyAttributeNames());
        if(additionalKeys != null) {
            keys.addObjectsFromArray(additionalKeys);
        }
        if(entity.restrictingQualifier() != null) {
            NSArray restrict = entity.restrictingQualifier().allQualifierKeys().allObjects();
            keys.addObjectsFromArray(restrict);
        }
        if(entity.isAbstractEntity()) {
            NSArray restrict = (NSArray)entity.subEntities().valueForKeyPath("restrictingQualifier.allQualifierKeys.allObjects.@flatten.@unique");
            keys.addObjectsFromArray(restrict);
        }
        fs.setRawRowKeyPaths(keys);
        return fs;
    }
View Full Code Here

     * @param eoqualifier to restrict matching primary keys
     * @param sortOrderings array of sort orders to sort result set
     * @return array of primary keys matching a given qualifier
     */
    public NSArray primaryKeysMatchingQualifier(EOEditingContext ec, EOQualifier eoqualifier, NSArray sortOrderings) {
        EOFetchSpecification fs = primaryKeyFetchSpecificationForEntity(ec, eoqualifier, sortOrderings, null);
        //NSArray nsarray = EOUtilities.rawRowsForQualifierFormat(ec, fs.qualifier(), );
        NSArray nsarray = ec.objectsWithFetchSpecification(fs);
        return nsarray;
    }
View Full Code Here

        // EOModelGroup.defaultGroup().addModel(aModel);
        EOQualifier aPathQualifier = new EOKeyValueQualifier("parent", EOQualifier.QualifierOperatorEqual, args.length > 0 ? args[0] : System.getProperty("user.home"));
        EOQualifier aNameQualifier = new EOKeyValueQualifier("name", (EOQualifier.QualifierOperatorCaseInsensitiveLike), "*M*");
        EOQualifier aNotQualifier = new EONotQualifier(aNameQualifier);
        EOQualifier aQualifier = new EOAndQualifier(new NSArray(new Object[] { aPathQualifier, aNotQualifier }));
        EOFetchSpecification aFetchSpecification = new EOFetchSpecification("FSDirectory", aQualifier, null);
        EOEditingContext anEditingContext = new EOEditingContext();
        NSArray someObjects = anEditingContext.objectsWithFetchSpecification(aFetchSpecification);

        System.out.println("Fetch result for '" + aQualifier + "': " + someObjects.valueForKey("name"));

View Full Code Here

        EODataSource ds = dataSource();
        if (ds == null || !(ds instanceof EODatabaseDataSource)) {
            ds = new EODatabaseDataSource(session().defaultEditingContext(), entity().name());
            setDataSource(ds);
        }
        EOFetchSpecification fs = queryFetchSpecification();
        if (fs == null) {
            fs = ((EODatabaseDataSource) ds).fetchSpecification();
            fs.setQualifier(qualifier());
            fs.setIsDeep(isDeep());
            fs.setUsesDistinct(usesDistinct());
            fs.setRefreshesRefetchedObjects(refreshRefetchedObjects());
        } else {
            ((EODatabaseDataSource) ds).setFetchSpecification(fs);
        }
        int limit = fetchLimit();
        if (limit != 0)
            fs.setFetchLimit(limit);
        NSArray prefetchingRelationshipKeyPaths = prefetchingRelationshipKeyPaths();
        if (prefetchingRelationshipKeyPaths != null && prefetchingRelationshipKeyPaths().count() > 0) {
            fs.setPrefetchingRelationshipKeyPaths(prefetchingRelationshipKeyPaths);
        }
        return ds;
    }
View Full Code Here

    public NSArray objectsForEntity(EOEntity entity, ERXRestContext context) throws ERXRestException, ERXRestSecurityException {
      NSArray objects = NSArray.EmptyArray;
       
      int start = ERXValueUtilities.intValue(valueForKey("start", null, context, null, 0));
        EOFetchSpecification fs = new ERXFetchSpecification<EOEnterpriseObject>(entity.name(), null, null);
       
        int fetchLimit = ERXValueUtilities.intValue(valueForKey("max", "fetchLimit", context, d2wContext(), 0));
      int hardLimit = ERXValueUtilities.intValue(valueForKey("fetchLimit", null, d2wContext(), null, 0));
      if(hardLimit > fetchLimit) {
        fetchLimit = hardLimit;
      }
        fs.setFetchLimit(fetchLimit);
       
        boolean isDeep = ERXValueUtilities.booleanValue(valueForKey("deep", "isDeep", context, d2wContext(), Boolean.TRUE));
        fs.setIsDeep(isDeep);
          
        boolean isDistinct = ERXValueUtilities.booleanValue(valueForKey("distinct", "usesDistinct", context, d2wContext(), Boolean.FALSE));
        fs.setUsesDistinct(isDistinct);
          
        // sorting
        NSArray sortOrderings = ERDirectToWeb.sortOrderings(d2wContext());
        fs.setSortOrderings(sortOrderings);
       
        NSArray keyPaths = (NSArray) d2wContext().valueForKey("prefetchingRelationshipKeyPaths");
        fs.setPrefetchingRelationshipKeyPaths(keyPaths);
    
       
        if(start == 0) {
          objects = context.editingContext().objectsWithFetchSpecification(fs);
        } else {
          objects = ERXEOControlUtilities.objectsInRange(context.editingContext(), fs, start, start+fs.fetchLimit());
        }
        return objects;
    }
View Full Code Here

    }

    public WOComponent showList() {
        ListPageInterface nextPage = (ListPageInterface) D2W.factory().pageForConfigurationNamed("ListAjaxBug", session());
        EODatabaseDataSource ds = new EODatabaseDataSource(session().defaultEditingContext(), "Bug");
        ds.setFetchSpecification(new EOFetchSpecification("Bug", null, null));
        ds.fetchSpecification().setFetchLimit(5);
        nextPage.setDataSource(ds);
        return (WOComponent) nextPage;
    }
View Full Code Here

        ec.refaultObject(eo);
        // NOTE AK: I think we can just return the object here,
        // as the next time it is accessed the fault will get
        NSArray primaryKeyAttributes = entity.primaryKeyAttributes();
        EOQualifier qualifier = ERXEOAccessUtilities.qualifierFromAttributes(primaryKeyAttributes, dbSnapshot);
        EOFetchSpecification fs = new EOFetchSpecification(entityName, qualifier, null);
        fs.setRefreshesRefetchedObjects(true);
        NSArray objs = ec.objectsWithFetchSpecification(fs);
        eo = null;
        if (objs.count() == 1) {
            eo = (EOEnterpriseObject) objs.objectAtIndex(0);
            if (log.isDebugEnabled()) {
View Full Code Here

                 String entityName = keyGID.entityName();
                 EOEntity entity = modelGroup.entityNamed(entityName);
                 NSDictionary snapshot = database.snapshotForGlobalID(gid);
                 if (snapshot != null) {
                   EOQualifier gidQualifier = entity.qualifierForPrimaryKey(entity.primaryKeyForGlobalID(gid));
                   EOFetchSpecification gidFetchSpec = new EOFetchSpecification(entityName, gidQualifier, null);

                   NSMutableDictionary databaseSnapshotClone;
                   NSMutableDictionary memorySnapshotClone = snapshot.mutableClone();
                   EOAdaptorChannel channel = databaseContext.availableChannel().adaptorChannel();
                   channel.openChannel();
                   channel.selectAttributes(entity.attributesToFetch(), gidFetchSpec, false, entity);
                   try {
                     databaseSnapshotClone = channel.fetchRow().mutableClone();
                   }
                   finally {
                     channel.cancelFetch();
                   }
                   // gidFetchSpec.setRefreshesRefetchedObjects(true);
                   // NSArray databaseEOs = editingContext.objectsWithFetchSpecification(gidFetchSpec);
                   if (databaseSnapshotClone == null) {
                     mismatches.addObject(gid + " was deleted in the database, but the snapshot still exists: " + memorySnapshotClone);
                   }
                   else {
                     // NSMutableDictionary refreshedSnapshotClone =
                     // database.snapshotForGlobalID(gid).mutableClone();
                     ERXDictionaryUtilities.removeMatchingEntries(memorySnapshotClone, databaseSnapshotClone);
                     if (databaseSnapshotClone.count() > 0 || memorySnapshotClone.count() > 0) {
                       mismatches.addObject(gid + " doesn't match the database: original = " + memorySnapshotClone + "; database = " + databaseSnapshotClone);
                     }
                     eo = (EOEnterpriseObject) editingContext.objectsWithFetchSpecification(gidFetchSpec).objectAtIndex(0);
                   }
                 }

                 if (eo != null) {
                   Enumeration relationshipsEnum = entity.relationships().objectEnumerator();
                   while (relationshipsEnum.hasMoreElements()) {
                     EORelationship relationship = (EORelationship) relationshipsEnum.nextElement();
                     String relationshipName = relationship.name();
                     NSArray originalDestinationGIDs = database.snapshotForSourceGlobalID(keyGID, relationshipName);
                     if (originalDestinationGIDs != null) {
                       NSMutableArray newDestinationGIDs = new NSMutableArray();
                       EOQualifier qualifier = relationship.qualifierWithSourceRow(database.snapshotForGlobalID(keyGID));
                       EOFetchSpecification relationshipFetchSpec = new EOFetchSpecification(entityName, qualifier, null);
                       EOAdaptorChannel channel = databaseContext.availableChannel().adaptorChannel();
                       channel.openChannel();
                       try {
                         channel.selectAttributes(relationship.destinationEntity().attributesToFetch(), relationshipFetchSpec, false, relationship.destinationEntity());
                         NSDictionary destinationSnapshot = null;
View Full Code Here

    }


    public void getObjects(){
        EODatabaseDataSource ds = new EODatabaseDataSource(defaultEditingContext(), "Movie");
        EOFetchSpecification fs = ds.fetchSpecification();
        fs.setPrefetchingRelationshipKeyPaths(new NSArray("studio"));
        _objects = ds.fetchObjects();
        System.out.println("getRawRows: objects: "+ _objects.count());
    }
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.