Examples of EODatabaseContext


Examples of com.webobjects.eoaccess.EODatabaseContext

     *          The variable bindings, wrapped in {@link ERXSQLBinding} objects
     *
     * @return batch iterator for the passed in query
     */
    public static ERXFetchSpecificationBatchIterator batchIteratorForObjectsWithSqlWithBindings( EOEditingContext ec, String entityName, String query, boolean refreshesCache, int batchSize, NSArray sortOrderings, ERXSQLBinding... bindings ) {
        EODatabaseContext databaseContext = databaseContextForEntityName(ec,entityName);
        EOEntity entity = EOUtilities.entityNamed(ec, entityName);

        if( entity.primaryKeyAttributes().count() > 1 ) {
            throw new RuntimeException("Multiple primary keys not supported.");
        }

        EOSQLExpression expression = databaseContext.adaptorContext().adaptor().expressionFactory().expressionForEntity( entity );
        expression.setStatement(processedQueryString(query, expression, bindings));

        EOFetchSpecification pkSpec = new EOFetchSpecification( entityName, null, null );
        pkSpec.setRefreshesRefetchedObjects(refreshesCache);
        pkSpec.setFetchesRawRows(true);
View Full Code Here

Examples of com.webobjects.eoaccess.EODatabaseContext

      if (!causedByRemoteUpdate) {
        Enumeration cosEnum = osc.cooperatingObjectStores().objectEnumerator();
        while (cosEnum.hasMoreElements()) {
          EOCooperatingObjectStore cos = (EOCooperatingObjectStore) cosEnum.nextElement();
          if (cos instanceof ERXDatabaseContext) {
            EODatabaseContext dbc = (EODatabaseContext) cos;
            ERXDatabase db = (ERXDatabase) dbc.database();
            NSArray cacheChanges = ERXObjectStoreCoordinatorSynchronizer.dequeueCacheChanges(db);
            if (cacheChanges != null) {
              _localCacheChanges.addObjectsFromArray(cacheChanges);
            }
          }
View Full Code Here

Examples of com.webobjects.eoaccess.EODatabaseContext

        EOGlobalID gid = (EOGlobalID) gids.nextElement();
        if (gid instanceof EOKeyGlobalID) {
          EOKeyGlobalID globalID = (EOKeyGlobalID) gid;
          String entityName = globalID.entityName();
          String key = entityName + "/" + System.identityHashCode(osc);
          EODatabaseContext dbc = (EODatabaseContext) dbcs.objectForKey(key);
          if (dbc == null) {
            dbc = ERXEOAccessUtilities.databaseContextForEntityNamed(osc, entityName);
            dbcs.setObjectForKey(dbc, key);
          }
          NSMutableArray snapshotsForEntity = (NSMutableArray) result.objectForKey(entityName);
          if (snapshotsForEntity == null) {
            snapshotsForEntity = new NSMutableArray();
            result.setObjectForKey(snapshotsForEntity, entityName);
          }
          synchronized (snapshotsForEntity) {
            Object o = dbc.snapshotForGlobalID(globalID);
            if (o != null) {
              snapshotsForEntity.addObject(o);
            }
          }
        }
View Full Code Here

Examples of com.webobjects.eoaccess.EODatabaseContext

     * @param i number of primary keys to generate
     * @return array of new primary keys
     */
    public NSArray newPrimaryKeys(EOEditingContext ec, int i) {
        EOEntity entity = entity(ec);
        EODatabaseContext dbc = EODatabaseContext.registeredDatabaseContextForModel(entity.model(), ec);
        dbc.lock();
        try {
          return dbc.availableChannel().adaptorChannel().primaryKeysForNewRowsWithEntity(i, entity);
        } finally {
          dbc.unlock();
        }
    }
View Full Code Here

Examples of com.webobjects.eoaccess.EODatabaseContext

     * @param relationshipName relationship name
     */
    public static void clearSnapshotForRelationshipNamed(EOEnterpriseObject eo, String relationshipName) {
        EOEditingContext ec = eo.editingContext();
        EOModel model = EOUtilities.entityForObject(ec, eo).model();
        EODatabaseContext dbc = EODatabaseContext.registeredDatabaseContextForModel(model, ec);
        EODatabase database = dbc.database();
        ERXEOControlUtilities.clearSnapshotForRelationshipNamedInDatabase(eo, relationshipName, database);
    }
View Full Code Here

Examples of com.webobjects.eoaccess.EODatabaseContext

    }

    // --- (3) Case of a fault and a snapshot exists to provide a count
    final EOGlobalID gid = ec.globalIDForObject(object);
    String modelName = entity.model().name();
    final EODatabaseContext dbc = EOUtilities.databaseContextForModelNamed(ec, modelName);

    NSArray toManySnapshot = ERXEOAccessUtilities.executeDatabaseContextOperation(dbc, 2,
        new DatabaseContextOperation<NSArray>() {
          public NSArray execute(EODatabaseContext databaseContext) throws Exception {
            // Search for and return the snapshot
            return dbc.snapshotForSourceGlobalID(gid, relationshipName, ec.fetchTimestamp());
          }
        });

    // Null means that a relationship snapshot array was not found in EODBCtx or EODB.
    if (toManySnapshot != null) {
View Full Code Here

Examples of com.webobjects.eoaccess.EODatabaseContext

     * @return the number of objects
     */
    public static Object _aggregateFunctionWithQualifierAndAggregateAttribute(EOEditingContext ec, String entityName, EOQualifier qualifier, EOAttribute aggregateAttribute) {
        EOEntity entity = ERXEOAccessUtilities.entityNamed(ec, entityName);
        EOModel model = entity.model();
        EODatabaseContext dbc = EODatabaseContext.registeredDatabaseContextForModel(model, ec);
        Object aggregateValue = null;
       
        dbc.lock();
        try {
            aggregateValue = __aggregateFunctionWithQualifierAndAggregateAttribute(dbc, ec, entityName, qualifier, aggregateAttribute);
        }
        catch (Exception localException) {
            if (dbc._isDroppedConnectionException(localException)) {
                try {
                    dbc.database().handleDroppedConnection();
                    aggregateValue = __aggregateFunctionWithQualifierAndAggregateAttribute(dbc, ec, entityName, qualifier, aggregateAttribute);
                }
                catch(Exception ex) {
                    throw NSForwardException._runtimeExceptionForThrowable(ex);
                }
            }
            else {
                throw NSForwardException._runtimeExceptionForThrowable(localException);
            }
        }
        finally {
            dbc.unlock();
        }
        return aggregateValue;
    }
View Full Code Here

Examples of com.webobjects.eoaccess.EODatabaseContext

     *    entity.
     */
    @SuppressWarnings("unchecked")
    public static NSDictionary<String, Object> newPrimaryKeyDictionaryForEntityNamed(EOEditingContext ec, String entityName) {
        EOEntity entity = ERXEOAccessUtilities.entityNamed(ec, entityName);
        EODatabaseContext dbContext = EODatabaseContext.registeredDatabaseContextForModel(entity.model(), ec);
        NSDictionary<String, Object> primaryKey = null;
        try {
            dbContext.lock();
           
            boolean willRetryAfterHandlingDroppedConnection = true;
            while (willRetryAfterHandlingDroppedConnection) {
              try {
                EOAdaptorChannel adaptorChannel = dbContext.availableChannel().adaptorChannel();
                if (!adaptorChannel.isOpen()) {
                    adaptorChannel.openChannel();
                }
                NSArray<NSDictionary<String, Object>> arr = adaptorChannel.primaryKeysForNewRowsWithEntity(1, entity);
                if (arr != null) {
                    primaryKey = arr.lastObject();
                } else {
                    log.warn("Could not get primary key array for entity: " + entityName);
                }
                willRetryAfterHandlingDroppedConnection = false;
              }
              catch (Exception localException) {
                if (willRetryAfterHandlingDroppedConnection &&
                    dbContext._isDroppedConnectionException(localException)) {
                      try {
                        dbContext.database().handleDroppedConnection();
                         
                      }
                      catch(Exception ex) {
                          throw NSForwardException._runtimeExceptionForThrowable(ex);
                      }
                  }
                  else {
                    throw NSForwardException._runtimeExceptionForThrowable(localException);
                  }
              }
            }
        } catch (Exception e) {
            log.error("Caught exception when generating primary key for entity: " + entityName, e);
            throw new NSForwardException(e);
        } finally {
            dbContext.unlock();
        }
        return primaryKey;
    }
View Full Code Here

Examples of com.webobjects.eoaccess.EODatabaseContext

        while (entitiesEnumerator.hasMoreElements()) {
            String entityName = (String)entitiesEnumerator.nextElement();
            if (! ERCNSnapshot.shouldSynchronizeEntity(entityName))   continue;

            EOEntity entity = EOModelGroup.defaultGroup().entityNamed(entityName);
            EODatabaseContext dbContext = ERCNNotificationCoordinator.databaseContextForEntityNamed(entityName, ec);
            EODatabase database = dbContext.database();
            NSArray snapshots = (NSArray)ercnSnapshot.shapshotsForUpdateGroupedByEntity().objectForKey(entityName);
            Enumeration snapshotsEnumerator = snapshots.objectEnumerator();
            while (snapshotsEnumerator.hasMoreElements()) {
                NSDictionary snapshot = (NSDictionary)snapshotsEnumerator.nextElement();
                if (NSLog.debug.isEnabled())
                    NSLog.debug.appendln(ERCNNotificationCoordinator.LOG_HEADER + "Snapshot: " + snapshot);
                if (snapshot != null) {
                    EOGlobalID globalID = entity.globalIDForRow(snapshot);
                    dbContext.lock();
                    database.forgetSnapshotForGlobalID(globalID);
                    database.recordSnapshotForGlobalID(snapshot, globalID);
                    dbContext.unlock();
                }
            }
        }
        ec.unlock();
    }
View Full Code Here

Examples of com.webobjects.eoaccess.EODatabaseContext

        while (e.hasMoreElements()) {
            EOKeyGlobalID globalID = (EOKeyGlobalID) e.nextElement();
            String entityName = globalID.entityName();

            if (shouldSynchronizeEntity(entityName)) {
                EODatabaseContext dbContext = ERCNNotificationCoordinator.databaseContextForEntityNamed(entityName, ec);
                NSMutableArray snapshotsForEntity = (NSMutableArray)result.objectForKey(entityName);
                if (snapshotsForEntity == null) {
                    snapshotsForEntity = new NSMutableArray();
                    result.setObjectForKey(snapshotsForEntity, entityName);
                }
                NSDictionary snapshot = dbContext.snapshotForGlobalID(globalID);
                if (snapshot != null) {
                    snapshotsForEntity.addObject(snapshot);
                    _entryCount++;
                }
            }
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.