Examples of EOAdaptorChannel


Examples of com.webobjects.eoaccess.EOAdaptorChannel

            EODatabaseContext context = EOUtilities.databaseContextForModelNamed(ec, op.operation().entity().model().name());
            context.lock();
            adaptorOperationsLock.lock();
            try {
                EODatabaseChannel dchannel = context.availableChannel();
                EOAdaptorChannel achannel = dchannel.adaptorChannel();
                achannel.adaptorContext().beginTransaction();
                boolean wasOpen = achannel.isOpen();
                if (!wasOpen) {
                    achannel.openChannel();
                }
                for(int i = 0; i < ops.count(); i++) {
                    op = (ERXAdaptorOperationWrapper)ops.objectAtIndex(i);
                    try {
                        achannel.performAdaptorOperation(op.operation());
                    } catch(EOGeneralAdaptorException ex) {
                        log.error("Failed op " + i + ": " + ex + "\n" + op);
                        throw ex;
                    }
                }
                achannel.adaptorContext().commitTransaction();
                if (!wasOpen) {
                    achannel.closeChannel();
                }
            } finally {
                adaptorOperationsLock.unlock();
                context.unlock();
            }
View Full Code Here

Examples of com.webobjects.eoaccess.EOAdaptorChannel

        protected abstract int doPerform(EOAdaptorChannel channel);

        public int perform(EOEditingContext ec, String modelName) {
            boolean wasOpen = true;
            EOAdaptorChannel channel = null;
            int rows = 0;
            ec.lock();
            try {
                EODatabaseContext dbc = EOUtilities.databaseContextForModelNamed(ec, modelName);
                dbc.lock();
                try {
                    channel = dbc.availableChannel().adaptorChannel();
                    wasOpen = channel.isOpen();
                    if(!wasOpen) {
                        channel.openChannel();
                    }
                    channel.adaptorContext().beginTransaction();
                    try {
                        rows = doPerform(channel);
                        channel.adaptorContext().commitTransaction();
                    } catch(RuntimeException ex) {
                        channel.adaptorContext().rollbackTransaction();
                        throw ex;
                    }
                } finally {
                    if (!wasOpen && channel != null) {
                        channel.closeChannel();
                    }
                    dbc.unlock();
                }
            } finally {
                ec.unlock();
View Full Code Here

Examples of com.webobjects.eoaccess.EOAdaptorChannel

    // sql in a non-blocking fashion.
    public static void evaluateSQLWithEntity(EOEditingContext ec, EOEntity entity, String exp) {
        EODatabaseContext dbContext = EODatabaseContext.registeredDatabaseContextForModel(entity.model(), ec);
        dbContext.lock();
        try {
          EOAdaptorChannel adaptorChannel = dbContext.availableChannel().adaptorChannel();
          if (!adaptorChannel.isOpen()) {
            adaptorChannel.openChannel();
          }
          EOSQLExpressionFactory factory = adaptorChannel.adaptorContext().adaptor().expressionFactory();
      if (ERXEOAccessUtilities.log.isInfoEnabled()) {
        ERXEOAccessUtilities.log.info("Executing " + exp);
      }
          // If channel.evaluateExpression throws when committing, it won't close the JDBC transaction
          // Probably a bug in JDBCChannel, but we must take care of it
          boolean contextHadOpenTransaction = adaptorChannel.adaptorContext().hasOpenTransaction();
      try {
        adaptorChannel.evaluateExpression(factory.expressionForString(exp));       
      }
      catch (EOGeneralAdaptorException e) {
        if (adaptorChannel.adaptorContext().hasOpenTransaction() && ! contextHadOpenTransaction) {
          adaptorChannel.adaptorContext().rollbackTransaction();
        }
        throw e;
      }
        }
        finally {
View Full Code Here

Examples of com.webobjects.eoaccess.EOAdaptorChannel

        return results;
    }
   
    private static NSArray _rawRowsForSQLExpression(EODatabaseContext dbc, EOSQLExpression expression, NSArray<EOAttribute> attributes) {
        NSMutableArray results = null;
        EOAdaptorChannel channel = dbc.availableChannel().adaptorChannel();
       
        if (!channel.isOpen())
            channel.openChannel();
        // If channel.evaluateExpression throws when committing, it won't close the JDBC transaction
        // Probably a bug in JDBCChannel, but we must take care of it
        boolean contextHadOpenTransaction = channel.adaptorContext().hasOpenTransaction();
    try {
      channel.evaluateExpression(expression);      
    }
    catch (EOGeneralAdaptorException e) {
      if (channel.adaptorContext().hasOpenTransaction() && ! contextHadOpenTransaction) {
        channel.adaptorContext().rollbackTransaction();
      }
      throw e;
    }
       
        if (attributes == null) {
            channel.setAttributesToFetch(channel.describeResults());
        }
        else {
            channel.setAttributesToFetch(attributes);
        }
       
        try {
            results = new NSMutableArray();
            NSDictionary row;
            while ((row = channel.fetchRow()) != null)
                results.addObject(row);
        }
        catch (EOGeneralAdaptorException ex) {
            channel.cancelFetch();
            throw ex;
        }
        return results;
    }
View Full Code Here

Examples of com.webobjects.eoaccess.EOAdaptorChannel

      EOEntity entity = ERXEOAccessUtilities.entityNamed(ec, entityName);
      EODatabaseContext dbContext = EODatabaseContext.registeredDatabaseContextForModel(entity.model(), ec);
      NSDictionary primaryKey = null;
      dbContext.lock();
      try {
        EOAdaptorChannel adaptorChannel = dbContext.availableChannel().adaptorChannel();
        if (!adaptorChannel.isOpen()) {
          adaptorChannel.openChannel();
        }
        NSArray arr = adaptorChannel.primaryKeysForNewRowsWithEntity(1, entity);
        if (arr != null) {
          primaryKey = (NSDictionary) arr.lastObject();
        } else {
          log.warn("Could not get primary key for entity: " + entityName + " exception");
        }
View Full Code Here

Examples of com.webobjects.eoaccess.EOAdaptorChannel

                   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;
                         do {
                           destinationSnapshot = channel.fetchRow();
                           if (destinationSnapshot != null) {
                             EOGlobalID destinationGID = relationship.destinationEntity().globalIDForRow(destinationSnapshot);
                             newDestinationGIDs.addObject(destinationGID);
                           }
                         }
                         while (destinationSnapshot != null);
                       }
                       finally {
                         channel.cancelFetch();
                       }

                       NSArray objectsNotInDatabase = ERXArrayUtilities.arrayMinusArray(originalDestinationGIDs, newDestinationGIDs);
                       if (objectsNotInDatabase.count() > 0) {
                         mismatches.addObject(gid + "." + relationshipName + " has entries not in the database: " + objectsNotInDatabase);
View Full Code Here

Examples of com.webobjects.eoaccess.EOAdaptorChannel

     * @param operation the adaptor channel operation to perform
     */
    public static <T> T executeAdaptorChannelOperation(final EODatabaseContext databaseContext, final int maxAttempts, final AdaptorChannelOperation<T> operation) {
      return ERXEOAccessUtilities.executeDatabaseContextOperation(databaseContext, maxAttempts, new DatabaseContextOperation<T>() {
        public T execute(EODatabaseContext databaseContext) throws Exception {
              EOAdaptorChannel adaptorChannel = databaseContext.availableChannel().adaptorChannel();
              if (!adaptorChannel.isOpen()) {
                  adaptorChannel.openChannel();
              }
          return operation.execute(databaseContext, adaptorChannel);
        }
      });
    }
View Full Code Here

Examples of com.webobjects.eoaccess.EOAdaptorChannel

        // so we catch the case when we
        EODatabaseContext databaseContext = EOUtilities.databaseContextForModelNamed(ec, modelName);
        ERXSQLHelper helper = ERXSQLHelper.newSQLHelper(databaseContext);
        String sql = helper.createSchemaSQLForEntitiesInModelWithName(null, modelName);
        NSArray sqls = helper.splitSQLStatements(sql);
        EOAdaptorChannel channel = databaseContext.availableChannel().adaptorChannel();
        ERXJDBCUtilities.executeUpdateScript(channel, sql);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.