Package com.webobjects.eocontrol

Examples of com.webobjects.eocontrol.EOEditingContext


    public String boxResults;

    public WOActionResults add() {

        EOEditingContext ec = session().defaultEditingContext();

        NSArray<String> lines = NSArray.componentsSeparatedByString(boxResults, "\n");

        NSMutableArray<String> resultLines = new NSMutableArray<String>();

        log.debug("boxResults lines # "+lines.size());
        for (String line : lines) {
            line = line.replace("[java]", "");
            line = line.trim();
            resultLines.add(line);
        }

        results = resultLines.componentsJoinedByString("<br/>\n");

        NSTimestamp created = new NSTimestamp();

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

        result.takeValueForKey(created, "whence");

        for (String line : resultLines) {

            NSArray<String> parts = NSArray.componentsSeparatedByString(line, " ");

            if (parts.size() == 3) {

                EOEnterpriseObject digest = EOUtilities.createAndInsertInstance(ec, "VersionDigest");

                digest.takeValueForKey(parts.get(0), "digest");
                digest.takeValueForKey(parts.get(2), "rname");
                digest.takeValueForKey(result, "result");
            }
        }

        ec.saveChanges();

        boxResults = null;
        return context().page();
    }
View Full Code Here


import er.extensions.eof.ERXEOControlUtilities;

public class Session extends ERXSession {

    public WOComponent newMovieWithPageConfiguration(String pageConfig) {
        EOEditingContext ec = ERXEC.newEditingContext();
        EOEnterpriseObject movie = ERXEOControlUtilities.createAndInsertObject(ec, "Movie");
        EditPageInterface epi = (EditPageInterface)D2W.factory().pageForConfigurationNamed(pageConfig, this);
        epi.setObject(movie);
        epi.setNextPage(context().page());
        return (WOComponent)epi;
View Full Code Here

        this.nextPage = nextPage;
        this.pickRelationshipName = pickRelationshipName;
    }
   
    public WOComponent nextPage(WOComponent sender) {
        EOEditingContext ec = eo.editingContext();
        ec.lock();
        try {
            NSArray selectedObjects;
            if(sender instanceof ERDPickPageInterface) {
              selectedObjects = ((ERDPickPageInterface)sender).selectedObjects();
            } else {
              selectedObjects = (NSArray)sender.valueForKeyPath("selectedObjects");
            }
            NSArray relatedObjects = (NSArray)eo.valueForKeyPath(relationshipName);
            for(Enumeration e = relatedObjects.immutableClone().objectEnumerator(); e.hasMoreElements(); ) {
                EOEnterpriseObject relatedObject = (EOEnterpriseObject)e.nextElement();
                EOEnterpriseObject pickedObject = (EOEnterpriseObject)relatedObject.valueForKey(pickRelationshipName);
                if(!selectedObjects.containsObject(pickedObject)) {
                    eo.removeObjectFromBothSidesOfRelationshipWithKey(relatedObject, relationshipName);
                    ec.deleteObject(relatedObject);
                }
            }
            NSArray pickedObjects = (NSArray)eo.valueForKeyPath(relationshipName +"." + pickRelationshipName +".@unique");
            EOEntity entity = ERXEOAccessUtilities.destinationEntityForKeyPath(ERXEOAccessUtilities.entityForEo(eo), relationshipName);
            for(Enumeration e = selectedObjects.objectEnumerator(); e.hasMoreElements(); ) {
                EOEnterpriseObject selectedObject = (EOEnterpriseObject)e.nextElement();
                if(!pickedObjects.containsObject(selectedObject)) {
                    EOEnterpriseObject relatedObject = ERXEOControlUtilities.createAndInsertObject(ec, entity.name());
                    relatedObject.addObjectToBothSidesOfRelationshipWithKey(selectedObject, pickRelationshipName);
                    eo.addObjectToBothSidesOfRelationshipWithKey(relatedObject, relationshipName);
                }
            }
        } finally {
            ec.unlock();
        }
       
        return nextPage;
    }
View Full Code Here

        }
        return (WOComponent)lpi;
    }

    private EODatabaseDataSource queryDatasource(String entityName) {
        EOEditingContext ec = session().defaultEditingContext();
        EODatabaseDataSource ds = new EODatabaseDataSource(ec, entityName);
        NSArray searchKeys = (NSArray) valueForBinding("searchKeys");
        if(searchKeys == null) {
            searchKeys = ERXEOControlUtilities.stringAttributeListForEntityNamed(ec, entityName);
        }
View Full Code Here

        WOApplication.application().sessionStore().checkInSessionForContext(context);
        context._setSession(null);
        ERXSession.setSession(null);
      }
      try {
        EOEditingContext editingContext = transaction.editingContext();
        try {
          for (Object record : transaction.records()) {
            WORequest recordRequest = (WORequest)record;
            setExecutingTransaction(transaction, context, recordRequest);
            recordRequest.removeHeadersForKey(ERXRestTransactionRequestAdaptor.CLIENT_ID_HEADER_KEY);
            recordRequest.removeHeadersForKey(ERXRestTransactionRequestAdaptor.SEQUENCE_ID_HEADER_KEY);
            recordRequest.removeHeadersForKey(ERXRestTransactionRequestAdaptor.TRANSACTION_HEADER_KEY);
           
            ERXRouteRequestHandler requestHandler = (ERXRouteRequestHandler)WOApplication.application().handlerForRequest(recordRequest);
            WOResponse response = requestHandler.handleRequest(recordRequest);
            if (response.status() < 200 || response.status() > 299) {
              throw new RuntimeException("Transaction failed: " + response.contentString());
            }
          }
          editingContext.saveChanges();
        }
        finally {
          transactionManager.removeTransaction(transaction);
          editingContext.dispose();
        }
      }
      finally {
        context.session();
      }
View Full Code Here

    public void indexAllObjects(EOEntity entity) {
        NSArray<ERIndex> incides = indicesForEntity(entity.name());
        if(incides.count() > 0) {
            long start = System.currentTimeMillis();
            int treshhold = 10;
            EOEditingContext ec = ERXEC.newEditingContext();
            ec.lock();
            try {
                EOFetchSpecification fs = new EOFetchSpecification(entity.name(), 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);
                    }
                    for(Enumeration i = incides.objectEnumerator(); i.hasMoreElements(); ) {
                        ERIndex index = (ERIndex) i.nextElement();
                        index.addObjectsToIndex(ec, objects);
                    }
                }
            } finally {
                ec.unlock();
            }
            log.info("Indexing " + entity.name() + " took: " + (System.currentTimeMillis() - start) + " ms");
        }
    }
View Full Code Here

        return (EOEnterpriseObject)valueForBinding("object");
    }
   
    public WOComponent newDirector() {
        // Could use a child context if we didn't want the talent to go to the database
        EOEditingContext ec = ERXEC.newEditingContext();
        EOEnterpriseObject director = ERXEOControlUtilities.createAndInsertObject(ec, "Talent");
       
        // Let's throw to a regular edit page
        EditPageInterface epi = (EditPageInterface)D2W.factory().pageForConfigurationNamed("EditTalent", session());
        epi.setObject(director);
View Full Code Here

    protected class AttributeTransactionHandler extends TransactionHandler {
       
        @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);

                    activeChanges.put(ec, transaction);
View Full Code Here

    /////////////////////////////////////////////////////////
    // Added by Max
    /////////////////////////////////////////////////////////

    public WOComponent newMovieWithPageConfiguration(String pageConfig) {
        EOEditingContext ec = ERXEC.newEditingContext();
        EOEnterpriseObject movie = ERXEOControlUtilities.createAndInsertObject(ec, "Movie");
        EditPageInterface epi = (EditPageInterface)D2W.factory().pageForConfigurationNamed(pageConfig,
                                                                                           session());
        epi.setObject(movie);
        epi.setNextPage(context().page());
View Full Code Here

        }
        EOFaulting fault = (EOFaulting)obj;
        if (fault.faultHandler() instanceof EOAccessArrayFaultHandler) {
            EOAccessArrayFaultHandler handler = (EOAccessArrayFaultHandler) fault.faultHandler();
            EOKeyGlobalID sourceGid = handler.sourceGlobalID();
            EOEditingContext ec = handler.editingContext();
            synchronized (cache) {
                NSDictionary entries = relationshipCacheEntriesForEntity(sourceGid.entityName(), handler.relationshipName());
                if(entries != null) {
                    NSArray gids = (NSArray) entries.objectForKey(sourceGid);
                    if(gids != null) {
                        NSMutableArray eos = new NSMutableArray(gids.count());
                        for (Enumeration enumerator = gids.objectEnumerator(); enumerator.hasMoreElements();) {
                            EOGlobalID gid = (EOGlobalID) enumerator.nextElement();
                            EOEnterpriseObject eo = ec.faultForGlobalID(gid, ec);
                            eos.addObject(eo);
                        }
                        EOFaultHandler.clearFault(obj);
                        ((NSMutableArray)fault).addObjectsFromArray(eos);
                        return true;
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.