Package com.webobjects.eocontrol

Examples of com.webobjects.eocontrol.EOEditingContext


    }

  @Override
    public EditPageInterface editPageForNewObjectWithConfigurationNamed(String configurationName, WOSession session) {
        EditPageInterface epi = (EditPageInterface) pageForConfigurationNamed(configurationName, session);
        EOEditingContext peerContext = ERXEC.newEditingContext(session.defaultEditingContext().parentObjectStore());
        D2WContext d2wcontext = ((D2WPage) epi).d2wContext();
        EOEnterpriseObject newObject = _newObjectWithEntity(d2wcontext.entity(), peerContext);
        epi.setObject(newObject);
        peerContext.hasChanges();
        return epi;
    }
View Full Code Here


    }
    return D2W.factory().defaultPage(session());
  }

  public WOActionResults eofQueryAction() throws IOException {
    EOEditingContext ec = ERXEC.newEditingContext();
    ec.lock();
    try {
      EOQualifier q1 = new EOKeyValueQualifier("contents", EOQualifier.QualifierOperatorLike, "suspend*");
      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);
      }
    } finally {
      ec.unlock();
    }
    return D2W.factory().defaultPage(session());
  }
View Full Code Here

    }
    return D2W.factory().defaultPage(session());
  }

  public WOActionResults createAction() {
    EOEditingContext ec = ERXEC.newEditingContext();
    ec.lock();
    try {
      Random random = new Random(12);
      for (int i = 0; i < 100; i++) {
        EOEnterpriseObject eo = EOUtilities.createAndInsertInstance(ec, "LuceneAsset");
        eo.takeValueForKey(new NSTimestamp().timestampByAddingGregorianUnits(0, 0, -random.nextInt(2500), 0, 0, 0), "creationDate");
        eo.takeValueForKey(ERXLoremIpsumGenerator.randomSentence(), "contents");
        eo.takeValueForKey(random.nextDouble(), "price");
        eo.takeValueForKey(Long.valueOf(random.nextInt(2500)), "userCount");
      }
      ec.saveChanges();
    } finally {
      ec.unlock();
    }
    return pageWithName(Main.class.getName());
  }
View Full Code Here

    }
   
    public void deleteCompany() {
      System.out.println("deleteCompany: " + companyToEdit.name());
      try {
        EOEditingContext ec = companyToEdit.editingContext();
        companyToEdit.editingContext().revert();
        companyToEdit.editingContext().deleteObject(companyToEdit);
        companyToEdit.editingContext().saveChanges();
          companies = new NSMutableArray<Company>(Company.fetchAllCompanies(ec, ERXS.ascs(Company.NAME_KEY)));
          AjaxModalDialog.close(context());
View Full Code Here

     * @author ak
     */
    public static class Observer {
       
        public void editingContextWillSaveChanges(NSNotification n) {
            EOEditingContext ec = (EOEditingContext) n.object();
                    boolean isNestedEditingContext = (ec.parentObjectStore() instanceof EOEditingContext);

                    ec.processRecentChanges(); // need to do this to make sure the updated objects list is current

            if (ec.hasChanges()) {
                NSNotificationCenter.defaultCenter().postNotification(ERXExtensions.objectsWillChangeInEditingContext, ec);
                // we don't need to lock ec because we can assume that we're locked
                // before this method is called, but we do need to lock our parent

                if (isNestedEditingContext) {
                    EOEditingContext parentEC = (EOEditingContext) ec.parentObjectStore();

                    parentEC.lock();

                    try {
                        if (ec.deletedObjects().count() > 0) {
                            final NSArray deletedObjectsToFlushInParent = ERXEOControlUtilities.localInstancesOfObjects(parentEC, ec.deletedObjects());

                            if (log.isDebugEnabled()) {
                                log.debug("saveChanges: before save to child context " + ec
                                        + ", need to flush caches on deleted objects in parent context " + parentEC + ": "
                                        + deletedObjectsToFlushInParent);
                            }
                            ERXEnterpriseObject.FlushCachesProcessor.perform(parentEC, deletedObjectsToFlushInParent);
                        }

                    } finally {
                        parentEC.unlock();
                    }
                }
                ERXEnterpriseObject.WillUpdateProcessor.perform(ec, ec.updatedObjects());
                ERXEnterpriseObject.WillDeleteProcessor.perform(ec, ec.deletedObjects());
                ERXEnterpriseObject.WillInsertProcessor.perform(ec, ec.insertedObjects());
View Full Code Here

                }
            }
       }

        public void editingContextDidSaveChanges(NSNotification n) {
            EOEditingContext ec = (EOEditingContext) n.object();
            final boolean isNestedEditingContext = (ec.parentObjectStore() instanceof EOEditingContext);
           
            NSArray insertedObjects = (NSArray)n.userInfo().objectForKey("inserted");
            NSArray updatedObjects = (NSArray)n.userInfo().objectForKey("updated");
            NSArray deletedObjects = (NSArray)n.userInfo().objectForKey("deleted");
           
            ERXEnterpriseObject.DidUpdateProcessor.perform(ec, updatedObjects);
            ERXEnterpriseObject.DidDeleteProcessor.perform(ec, deletedObjects);
            ERXEnterpriseObject.DidInsertProcessor.perform(ec, insertedObjects);

            if ( isNestedEditingContext ) {
                // we can assume insertedObjectGIDs and updatedObjectGIDs are non null.  if we execute this branch, they're at
                // least empty arrays.
                final EOEditingContext parentEC = (EOEditingContext)ec.parentObjectStore();

                if (insertedObjects.count() > 0 || updatedObjects.count() > 0) {
                    NSMutableArray flushableObjects = new NSMutableArray();
                    flushableObjects.addObjectsFromArray(insertedObjects);
                    flushableObjects.addObjectsFromArray(updatedObjects);

                    parentEC.lock();
                    try {
                        final NSArray flushableObjectsInParent = ERXEOControlUtilities.localInstancesOfObjects(parentEC, flushableObjects);

                        if ( log.isDebugEnabled() ) {
                            log.debug("saveChanges: before save to child context " + ec +
                                    ", need to flush caches on objects in parent context " + parentEC + ": " + flushableObjectsInParent);
                        }

                        ERXEnterpriseObject.FlushCachesProcessor.perform(parentEC, flushableObjectsInParent);
                    } finally {
                        parentEC.unlock();
                    }
                }
            }
        }
View Full Code Here

    public EOEnterpriseObject browserItem;
    public NSArray browserSelections;
    public String sortedObjects;

    public void setMasterObjectAndRelationshipKey(EOEnterpriseObject eo, String relationshipKey) {
      EOEditingContext ec = ERXEC.newEditingContext(eo.editingContext(), false)// a non-validating context
        EOEnterpriseObject newObject=EOUtilities.localInstanceOfObject(ec,eo);
        setObject(newObject);
        _relationshipKey = relationshipKey;

        if (!object().isToManyKey(relationshipKey))
View Full Code Here

        }
        return null;
    }

    protected void prepareEditPage(D2WContext context, EditPageInterface epi, String entityName) {
        EOEditingContext ec = newEditingContext();
        EOEnterpriseObject eo = null;

        ec.lock();
        try {
            if(context.dynamicPage().startsWith(createPrefix) || primaryKeyFromRequest(ec, entityName) == null) {
                eo = EOUtilities.createAndInsertInstance(ec,entityName);
            } else {
                eo = ERXEOControlUtilities.objectWithPrimaryKeyValue(ec, entityName, primaryKeyFromRequest(ec, entityName), null);
            }
        } finally {
            ec.unlock();
        }
        epi.setObject(eo);
        epi.setNextPage(previousPageFromRequest());
    }
View Full Code Here

        epi.setObject(eo);
        epi.setNextPage(previousPageFromRequest());
    }

    protected void prepareInspectPage(D2WContext context, InspectPageInterface ipi, String entityName) {
        EOEditingContext ec = session().defaultEditingContext();
        EOEnterpriseObject eo = null;

        ec.lock();
        try {
            eo = EOUtilities.objectWithPrimaryKey(ec, entityName, primaryKeyFromRequest(ec, entityName));
        } finally {
            ec.unlock();
        }
        ipi.setObject(eo);
        ipi.setNextPage(previousPageFromRequest());
    }
View Full Code Here

                ((ERD2WQueryPage)qpi).setFetchSpecification(fs);
        }
    }
   
    protected void prepareEditRelationshipPage(D2WContext context, EditRelationshipPageInterface erpi, String entityName) {
      EOEditingContext ec = ERXEC.newEditingContext(session().defaultEditingContext().parentObjectStore());
      String keypath = keyPathFromRequest();
      String masterEntityName = ERXStringUtilities.firstPropertyKeyInKeyPath(keypath);
      String relationshipKey = ERXStringUtilities.keyPathWithoutFirstProperty(keypath);
      NSDictionary pk = primaryKeyFromRequest(ec, masterEntityName);
      EOEnterpriseObject masterObject = ERXEOControlUtilities.objectWithPrimaryKeyValue(ec, masterEntityName, pk, null);
View Full Code Here

TOP

Related Classes of com.webobjects.eocontrol.EOEditingContext

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.