Examples of EODatabaseContext


Examples of com.webobjects.eoaccess.EODatabaseContext

      for (Enumeration entityNames = changesByEntity.allKeys().objectEnumerator(); entityNames.hasMoreElements();) {
        String entityName = (String) entityNames.nextElement();
        String key = entityName + "/" + System.identityHashCode(osc);
        EOEntity entity = modelGroup.entityNamed(entityName);
        NSArray snapshots = (NSArray) changesByEntity.objectForKey(entityName);
        EODatabaseContext dbc = (EODatabaseContext) dbcs.objectForKey(key);
        if (dbc == null) {
          dbc = ERXEOAccessUtilities.databaseContextForEntityNamed(osc, entityName);
          dbcs.setObjectForKey(dbc, key);
        }
        EODatabase database = dbc.database();
        NSMutableDictionary snapshotsByGlobalID = new NSMutableDictionary();
        for (Enumeration snapshotsEnumerator = snapshots.objectEnumerator(); snapshotsEnumerator.hasMoreElements();) {
          NSDictionary snapshot = (NSDictionary) snapshotsEnumerator.nextElement();
          EOGlobalID globalID = entity.globalIDForRow(snapshot);
          snapshotsByGlobalID.setObjectForKey(snapshot, globalID);
        }
        if (snapshotsByGlobalID.count() > 0) {
          dbc.lock();
          try {
            processor.processSnapshots(dbc, database, snapshotsByGlobalID, settings);
          }
          finally {
            dbc.unlock();
          }
        }
      }
    }
View Full Code Here

Examples of com.webobjects.eoaccess.EODatabaseContext

        EOObjectStoreCoordinator osc = (EOObjectStoreCoordinator) oscs.nextElement();
        Enumeration cacheChangeEnum = remoteChange.remoteCacheChanges().objectEnumerator();
        while (cacheChangeEnum.hasMoreElements()) {
          ERXDatabase.CacheChange cacheChange = (ERXDatabase.CacheChange) cacheChangeEnum.nextElement();
          EOKeyGlobalID gid = (EOKeyGlobalID) cacheChange.gid();
          EODatabaseContext dbc = ERXEOAccessUtilities.databaseContextForEntityNamed(osc, gid.entityName());
          EODatabase database = dbc.database();
          dbc.lock();
          try {
            if (cacheChange instanceof ERXDatabase.SnapshotInserted) {
              _insertCacheChangeProcessor.processCacheChange(dbc, database, cacheChange);
            }
            else if (cacheChange instanceof ERXDatabase.SnapshotUpdated) {
              _updateCacheChangeProcessor.processCacheChange(dbc, database, cacheChange);
            }
            else if (cacheChange instanceof ERXDatabase.SnapshotDeleted) {
              _deleteCacheChangeProcessor.processCacheChange(dbc, database, cacheChange);
            }
            else if (cacheChange instanceof ERXDatabase.ToManySnapshotUpdated) {
              _toManyUpdateCacheChangeProcessor.processCacheChange(dbc, database, cacheChange);
            }
          }
          finally {
            dbc.unlock();
          }
        }
      }
    }
View Full Code Here

Examples of com.webobjects.eoaccess.EODatabaseContext

     * to a new instance of ERXAdaptorChannelDelegate.
     * @param n
     */
  static public void dataBaseChannelNeeded(NSNotification n) {
    if (ERXProperties.booleanForKeyWithDefault("er.extensions.ERXAdaptorChannelDelegate.enabled", false)) {
      EODatabaseContext context = (EODatabaseContext) n.object();
      EODatabaseChannel channel = new EODatabaseChannel(context);
      context.registerChannel(channel);
      channel.adaptorChannel().setDelegate(new ERXAdaptorChannelDelegate());
    }
  }
View Full Code Here

Examples of com.webobjects.eoaccess.EODatabaseContext

        ec.lock();
        try {
            // FIXME use the entityName information from each EOAdaptorOperation to get the correct
            // database context, this implementation here only works if all EOModels use the same database
            ERXAdaptorOperationWrapper op = (ERXAdaptorOperationWrapper) ops.lastObject();
            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();
            }
        } finally {
            ec.unlock();
        }
    }
View Full Code Here

Examples of com.webobjects.eoaccess.EODatabaseContext

            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();
            }
            return rows;
View Full Code Here

Examples of com.webobjects.eoaccess.EODatabaseContext

    // ENHANCEME: Need a non-oracle specific way of doing this. Should poke
    // around at
    //    the adaptor level and see if we can't find something better.
    @Deprecated
    public static Number getNextValFromSequenceNamed(EOEditingContext ec, String modelName, String sequenceName) {
      EODatabaseContext dbContext = EOUtilities.databaseContextForModelNamed(ec, modelName);
      return ERXSQLHelper.newSQLHelper(dbContext).getNextValFromSequenceNamed(ec, modelName, sequenceName);
    }
View Full Code Here

Examples of com.webobjects.eoaccess.EODatabaseContext

    // ENHANCEME: Should support the use of bindings
    // ENHANCEME: Could also support the option of using a seperate EOF stack so
    // as to execute
    // 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 {
          dbContext.unlock();
        }
    }
View Full Code Here

Examples of com.webobjects.eoaccess.EODatabaseContext

     *
     * @return array of dictionaries
     */
    public static NSArray rawRowsForSQLExpression(EOEditingContext ec, EOModel model, EOSQLExpression expression, NSArray<EOAttribute> attributes) {
        NSArray results = NSArray.EmptyArray;
        EODatabaseContext dbc = EODatabaseContext.registeredDatabaseContextForModel(model, ec);
       
        dbc.lock();
        try {
            results = _rawRowsForSQLExpression(dbc, expression, attributes);
        }
        catch (Exception localException) {
            if (dbc._isDroppedConnectionException(localException)) {
                try {
                    dbc.database().handleDroppedConnection();
                    results = _rawRowsForSQLExpression(dbc, expression, attributes);
                }
                catch(Exception ex) {
                    throw NSForwardException._runtimeExceptionForThrowable(ex);
                }
            }
            else {
              throw NSForwardException._runtimeExceptionForThrowable(localException);
            }
        }
        finally {
            dbc.unlock();
        }
        return results;
    }
View Full Code Here

Examples of com.webobjects.eoaccess.EODatabaseContext

     */
    public static EOSQLExpression sqlExpressionForFetchSpecification(EOEditingContext ec, EOFetchSpecification spec, long start, long end) {
      EOSQLExpression expression = null;
        EOEntity entity = ERXEOAccessUtilities.entityNamed(ec, spec.entityName());
        EOModel model = entity.model();
        EODatabaseContext dbc = EODatabaseContext.registeredDatabaseContextForModel(model, ec);
        dbc.lock();
        try {
          ERXSQLHelper sqlHelper = ERXSQLHelper.newSQLHelper(ec, model.name());
          expression = sqlHelper.sqlExpressionForFetchSpecification(ec, spec, start, end);
        }
        catch (Exception e) {
          throw NSForwardException._runtimeExceptionForThrowable(e);
      }
        finally {
          dbc.unlock();
        }
       
        return expression;
    }
View Full Code Here

Examples of com.webobjects.eoaccess.EODatabaseContext

        if (entity == null)
            throw new java.lang.IllegalStateException("entity could not be found for name \""+spec.entityName()+"\". Checked EOModelGroup for loaded models.");

      EOModel model = entity.model();

      EODatabaseContext dbc = EODatabaseContext.registeredDatabaseContextForModel(model, ec);
      int results = 0;

      dbc.lock();
      try {
        results = ERXSQLHelper.newSQLHelper(ec, model.name()).rowCountForFetchSpecification(ec, spec);
      }
      catch (Exception localException) {
        if (dbc._isDroppedConnectionException(localException)) {
          try {
            dbc.database().handleDroppedConnection();
            results = ERXSQLHelper.newSQLHelper(ec, model.name()).rowCountForFetchSpecification(ec, spec);
          }
          catch (Exception ex) {
            throw NSForwardException._runtimeExceptionForThrowable(ex);
          }
        }
        else {
          throw NSForwardException._runtimeExceptionForThrowable(localException);
        }
      }
      finally {
        dbc.unlock();
      }

      return results;
    }
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.