Package com.webobjects.eocontrol

Examples of com.webobjects.eocontrol.EOEditingContext


   
    /**
     * Returns true if the EC has "real" changes (processRecentChanges was called)
   */
    public boolean hasActualChanges() {
        EOEditingContext ec = editingContext();
        boolean hasChanges = ec.hasChanges();
        if(hasChanges) {
            hasChanges  = ec.insertedObjects().count() > 0;
            hasChanges |= ec.updatedObjects().count() > 0 && ((NSArray)ec.updatedObjects().valueForKeyPath("changesFromCommittedSnapshot.allValues.@flatten")).count() > 0;
            hasChanges |= ec.deletedObjects().count() > 0;
        }
        return hasChanges;
    }
View Full Code Here


        clear();
        for (Enumeration names = entities().objectEnumerator(); names.hasMoreElements();) {
            String entityName = (String) names.nextElement();
            long start = System.currentTimeMillis();
            int treshhold = 10;
            EOEditingContext ec = ERXEC.newEditingContext();
            ec.lock();
            try {
                EOFetchSpecification fs = new EOFetchSpecification(entityName, null, null);
                ERXFetchSpecificationBatchIterator iterator = new ERXFetchSpecificationBatchIterator(fs);
                iterator.setEditingContext(ec);
                while (iterator.hasNextBatch()) {
                    NSArray objects = iterator.nextBatch();
                    if (iterator.currentBatchIndex() % treshhold == 0) {
                        ec.unlock();
                        // ec.dispose();
                        ec = ERXEC.newEditingContext();
                        ec.lock();
                        iterator.setEditingContext(ec);
                    }
                    NSArray<Document> documents = addedDocumentsForObjects(objects);
                    Transaction transaction = new Transaction(ec);
                    handler().addObjectsToIndex(transaction, objects);
                }
            } finally {
                ec.unlock();
            }
            log.info("Indexing " + entityName + " took: " + (System.currentTimeMillis() - start) + " ms");
        }
    }
View Full Code Here

            }
        }

        @Override
    public void _handleChanges(NSNotification n) {
            EOEditingContext ec = (EOEditingContext) n.object();
            if (ec.parentObjectStore() == ec.rootObjectStore()) {

                String notificationName = n.name();
                if (notificationName.equals(ERXEC.EditingContextWillSaveChangesNotification)) {
                    ec.processRecentChanges();
                    NSArray inserted = ec.insertedObjects();
                    NSArray updated = ec.updatedObjects();
                    updated = ERXArrayUtilities.arrayMinusArray(updated, inserted);
                    NSArray deleted = ec.deletedObjects();

                    Transaction transaction = new Transaction(ec);

                    NSMutableSet<EOEnterpriseObject> deletedHandledObjects = new NSMutableSet<EOEnterpriseObject>();
                    NSMutableSet<EOEnterpriseObject> addedHandledObjects = new NSMutableSet<EOEnterpriseObject>();
View Full Code Here

        private final NSMutableSet<String> _warned = new NSMutableSet();

        protected NSArray indexableObjectsForObject(String type, EOEnterpriseObject object) {
            ERXGenericRecord eo = (ERXGenericRecord) object;
            EOEditingContext ec = eo.editingContext();
            NSMutableSet<EOEnterpriseObject> result = new NSMutableSet();
            String entityName = eo.entityName();
            ConfigurationEntry config = _configuration.entryForKey(entityName);
            if (config != null) {
                if (!config.active) {
                    for (Enumeration e1 = config.notificationKeys.objectEnumerator(); e1.hasMoreElements();) {
                        String key = (String) e1.nextElement();
                        Object value = null;

                        if (type.equals(EOEditingContext.DeletedKey)) {
                            value = ec.committedSnapshotForObject(eo);
                        }

                        EOEntity source = ERXEOAccessUtilities.entityForEo(eo);

                        if (source.classPropertyNames().containsObject(key)) {
                            value = eo.valueForKey(key);
                        } else {
                            if (eo.isNewObject()) {
                                if (!_warned.containsObject(entityName)) {
                                    log.error("We currently don't support unsaved related objects for this entity: " + entityName);
                                    _warned.addObject(entityName);
                                }
                            } else {
                                EORelationship rel = source.anyRelationshipNamed(key);
                                EOKeyGlobalID sourceGlobalID = (EOKeyGlobalID) ec.globalIDForObject(eo);
                                // AK: I wish I could, but when a relationship
                                // is
                                // not a class prop, there's nothing we can do.
                                // value =
                                // ec.arrayFaultWithSourceGlobalID(sourceGlobalID,
                                // rel.name(), ec);
                                EOFetchSpecification fs = new EOFetchSpecification(rel.destinationEntity().name(), null, null);
                                NSMutableArray<EOQualifier> qualifiers = new NSMutableArray(rel.joins().count());
                                NSDictionary pk = source.primaryKeyForGlobalID(sourceGlobalID);
                                for (Iterator iterator = rel.joins().iterator(); iterator.hasNext();) {
                                    EOJoin join = (EOJoin) iterator.next();
                                    Object pkValue = pk.objectForKey(join.sourceAttribute().name());
                                    EOKeyValueQualifier qualifier = new EOKeyValueQualifier(join.destinationAttribute().name(), EOQualifier.QualifierOperatorEqual, pkValue);
                                    qualifiers.addObject(qualifier);
                                }
                                fs.setQualifier(qualifiers.count() == 1 ? qualifiers.lastObject() : new EOAndQualifier(qualifiers));
                                value = ec.objectsWithFetchSpecification(fs);
                            }
                        }
                        if (value != null) {
                            NSArray<EOEnterpriseObject> eos = (value instanceof EOEnterpriseObject ? new NSArray(value) : (NSArray) value);
                            for (EOEnterpriseObject target : eos) {
View Full Code Here

    }

    @Override
    public void awake() {

        EOEditingContext ec = ERXEC.newEditingContext();

        EOEnterpriseObject result = EOUtilities.createAndInsertInstance(ec, "Result");

        NSDictionary<String,NSArray<Object>> values = context().request().formValues();

        for (String key : values.allKeys()) {

            if (key.equals("when")) {
                String when = values.objectForKey(key).get(0).toString();
                result.takeValueForKey(when, "whence");
            }

            if (key.equals("timezone")) {
                String when = values.objectForKey(key).get(0).toString();
                result.takeValueForKey(when, "timeZone");
            }

            if (key.equals("duration")) {
                Number duration = Long.valueOf(values.objectForKey(key).get(0).toString());
                result.takeValueForKey(duration, "duration");
            }

            if (key.equals("email")) {
                String email = values.objectForKey(key).get(0).toString();
                result.takeValueForKey(email, "email");
            }

            if (key.startsWith("env")) {
                String env = values.objectForKey(key).get(0).toString();
                NSArray<EOEnterpriseObject> found = EOUtilities.objectsMatchingKeyAndValue(ec, "Environment", "info", env);
                EOEnterpriseObject eo;
                if (found == null || found.size() == 0) {
                    eo = EOUtilities.createAndInsertInstance(ec, "Environment");
                    eo.takeValueForKey(env, "info");
                } else {
                    eo = found.get(0);
                }
                result.addObjectToBothSidesOfRelationshipWithKey(eo, "environments");
            }

            if (key.startsWith("vers")) {
                NSArray<String> parts = NSArray.componentsSeparatedByString(values.objectForKey(key).get(0).toString(), " ");
                EOEnterpriseObject eo = EOUtilities.createAndInsertInstance(ec, "VersionDigest");
                eo.takeValueForKey(parts.get(1), "rname");
                eo.takeValueForKey(parts.get(0), "digest");
                result.addObjectToBothSidesOfRelationshipWithKey(eo, "digests");
            }

            if (key.startsWith("fail")) {
                String message = values.objectForKey(key).get(0).toString();
                EOEnterpriseObject eo = EOUtilities.createAndInsertInstance(ec, "Failure");
                eo.takeValueForKey(message, "message");
                result.addObjectToBothSidesOfRelationshipWithKey(eo, "failures");
            }
        }

        ec.saveChanges();
        log.debug("Ok!");
    }
View Full Code Here

  public WOActionResults confirmAction() {
    session().logout();

    WOActionResults nextPage;
    EOEditingContext editingContext = ERXEC.newEditingContext();
    String confirmationCode = request().stringFormValueForKey(SPUtilities.CONFIRMATION_CODE_KEY);
    if (confirmationCode == null || confirmationCode.trim().length() == 0) {
      session().errors().addNotice("You must provide a confirmation code to validate your membership.");
      nextPage = pageWithName(Main.class);
    } else {
View Full Code Here

  public WOActionResults resetPasswordAction() {
    session().logout();
   
    WOActionResults nextPage;
    EOEditingContext editingContext = ERXEC.newEditingContext();
    String resetPasswordCode = request().stringFormValueForKey(SPUtilities.RESET_PASSWORD_CODE_KEY);
    if (resetPasswordCode == null || resetPasswordCode.trim().length() == 0) {
      session().errors().addNotice("You must provide a reset code to change your password.");
      nextPage = pageWithName(Main.class);
    } else {
View Full Code Here

    @Override
    public Object fire(D2WContext c) {
        Object result = null;
        Object value = value();
        EOEditingContext ec = (EOEditingContext)c.valueForKey("session.defaultEditingContext");

        log.info("fire with value: " + value);
        if(log.isDebugEnabled()) {
            log.debug("fire with value: " + value);
        }
View Full Code Here

      mail.setToAddresses(new NSArray<String>(person.emailAddress()));
      mail.setDelegate(delegate);
      mail.sendMail();
      sentEmail = true;
    } catch (Exception e) {
      EOEditingContext editingContext = ERXEC.newEditingContext();
      try {
        person.localInstanceIn(editingContext).setEmailDeliveryFailure(Boolean.TRUE);
        editingContext.saveChanges();
      } finally {
        editingContext.unlock();
      }
      editingContext.dispose();
      SPUtilities.log.error("Failed to send email to '" + person.emailAddress() + "'.", e);
      errorNoticeList.addNotice("Failed to send email: " + e.getMessage());
    }
    return sentEmail;
  }
View Full Code Here

        _followPage = nextPage;
    }

    public WOComponent nextPage(WOComponent sender) {
        if (_object != null && _object.editingContext() != null) {
            EOEditingContext editingContext = _object.editingContext();
            NSValidation.ValidationException exception = null;
            try {
                if (_dataSource != null) _dataSource.deleteObject(_object);
                if (editingContext instanceof EOSharedEditingContext) {
                    //fault the eo into another ec, one cannot delete objects
                    // in an shared editing context
                    EOEditingContext ec = ERXEC.newEditingContext();
                    ec.lock();
                    try {
                        ec.setSharedEditingContext(null);
                        EOEnterpriseObject object = EOUtilities.localInstanceOfObject(ec, _object);
                        ec.deleteObject(object);
                        ec.saveChanges();
                    } finally {
                        ec.unlock();
                        ec.dispose();
                    }
                } else {
                  //Place the EO into a nested ec and try to delete there
                  //to prevent the appearance of a successful delete if
                  //validation fails.
                  EOEnterpriseObject eo = ERXEOControlUtilities.editableInstanceOfObject(_object, true);
                  EOEditingContext childEC = eo.editingContext();
                  childEC.deleteObject(eo);
                  childEC.saveChanges();
                 
                    if (ERXEOControlUtilities.isNewObject(_object)) {
                        // This is necessary to force state synching, e.g., for display groups, etc.
                        editingContext.processRecentChanges();
                    } else {
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.