Examples of EODatabaseContext


Examples of com.webobjects.eoaccess.EODatabaseContext

   *         tables
     *
     * @see er.extensions.jdbc.ERXSQLHelper#createSchemaSQLForEntitiesInModelWithNameAndOptions(NSArray, String, NSDictionary)
     */
    public static String createSchemaSQLForEntitiesInModelWithNameAndOptionsForOracle9(NSArray entities, String modelName, NSDictionary optionsCreate) {
        EODatabaseContext dc = EOUtilities.databaseContextForModelNamed(ERXEC.newEditingContext(), modelName);
        return ERXSQLHelper.newSQLHelper(dc).createSchemaSQLForEntitiesInModelWithNameAndOptions(entities, modelName, optionsCreate);
    }
View Full Code Here

Examples of com.webobjects.eoaccess.EODatabaseContext

     *         tables
     * @deprecated
     */
    @Deprecated
    public static String createSchemaSQLForEntitiesInModelWithNameAndOptions(NSArray entities, String modelName, NSDictionary optionsCreate) {
        EODatabaseContext dc = EOUtilities.databaseContextForModelNamed(ERXEC.newEditingContext(), modelName);
        return ERXSQLHelper.newSQLHelper(dc).createSchemaSQLForEntitiesInModelWithNameAndOptions(entities, modelName, optionsCreate);
    }
View Full Code Here

Examples of com.webobjects.eoaccess.EODatabaseContext

     *         tables
     * @deprecated
     */
    @Deprecated
    public static String createSchemaSQLForEntitiesInModelWithName(NSArray entities, String modelName) {
      EODatabaseContext databaseContext = EOUtilities.databaseContextForModelNamed(ERXEC.newEditingContext(), modelName);
      return ERXSQLHelper.newSQLHelper(databaseContext).createSchemaSQLForEntitiesInModelWithName(entities, modelName);
    }
View Full Code Here

Examples of com.webobjects.eoaccess.EODatabaseContext

        EOEditingContext ec = eo.editingContext();
        EOEntity entity = ERXEOAccessUtilities.entityNamed(ec, entityName);
        EORelationship relationship = entity.relationshipNamed(relKey);
        if(relationship.sourceAttributes().count() == 1) {
          EOAttribute attribute = relationship.sourceAttributes().lastObject();
          EODatabaseContext context = EOUtilities.databaseContextForModelNamed(ec, entity.model().name());
          String name = attribute.name();
          for (Enumeration e = eos.objectEnumerator(); e.hasMoreElements();) {
            EOEnterpriseObject target = (EOEnterpriseObject) e.nextElement();
            Object value = (context.snapshotForGlobalID(ec.globalIDForObject(target))).valueForKey(name);
            result.addObject(value);
          }
        } else {
          throw new IllegalArgumentException("Has more than one relationship attribute: " + relKey);
        }
View Full Code Here

Examples of com.webobjects.eoaccess.EODatabaseContext

     *            name of the entity to generate the primary key dictionary for.
     * @return a dictionary containing a new primary key for the given entity.
     */
    public static NSDictionary primaryKeyDictionaryForEntity(EOEditingContext ec, String entityName) {
      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");
        }
      } catch (Exception e) {
        log.error("Caught exception when generating primary key for entity: " + entityName + " exception: " + e, e);
      } finally {
        dbContext.unlock();
      }
      return primaryKey;
    }
View Full Code Here

Examples of com.webobjects.eoaccess.EODatabaseContext

     * @return the eo's database context
     */
    public static EODatabaseContext databaseContextForObject(EOEnterpriseObject eo) {
        EOEditingContext editingContext = eo.editingContext();
        EOObjectStoreCoordinator osc = (EOObjectStoreCoordinator) editingContext.rootObjectStore();
        EODatabaseContext databaseContext = (EODatabaseContext) osc.objectStoreForObject(eo);
        return databaseContext;
    }
View Full Code Here

Examples of com.webobjects.eoaccess.EODatabaseContext

     * @param osc the object store coordinator
     * @return database context
     */
    public static EODatabaseContext databaseContextForEntityNamed(EOObjectStoreCoordinator osc, String entityName) {
        EOModel model = EOModelGroup.modelGroupForObjectStoreCoordinator(osc).entityNamed(entityName).model();
        EODatabaseContext dbc = EODatabaseContext.registeredDatabaseContextForModel(model, osc);
        return dbc;
    }
View Full Code Here

Examples of com.webobjects.eoaccess.EODatabaseContext

     EOEditingContext editingContext = ERXEC.newEditingContext();
     EOModelGroup modelGroup = EOModelGroup.defaultGroup();
     Enumeration modelsEnum = modelGroup.models().objectEnumerator();
     while (modelsEnum.hasMoreElements()) {
       EOModel model = (EOModel) modelsEnum.nextElement();
       EODatabaseContext databaseContext = null;
       try {
         databaseContext = EODatabaseContext.registeredDatabaseContextForModel(model, editingContext);
       }
       catch (IllegalStateException e) {
         log.warn("Model " + model.name() + " failed: " + e.getMessage());
       }
       if (databaseContext != null) {
         databaseContext.lock();
         try {
           EODatabase database = databaseContext.database();
           if (!verifiedDatabases.containsObject(database)) {
             Enumeration gidEnum = database.snapshots().keyEnumerator();
             while (gidEnum.hasMoreElements()) {
               EOGlobalID gid = (EOGlobalID) gidEnum.nextElement();
               if (gid instanceof EOKeyGlobalID) {
                 EOEnterpriseObject eo = null;
                 EOKeyGlobalID keyGID = (EOKeyGlobalID) gid;
                 String entityName = keyGID.entityName();
                 EOEntity entity = modelGroup.entityNamed(entityName);
                 NSDictionary snapshot = database.snapshotForGlobalID(gid);
                 if (snapshot != null) {
                   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);
                       }
                       NSArray objectsNotInMemory = ERXArrayUtilities.arrayMinusArray(newDestinationGIDs, originalDestinationGIDs);
                       if (objectsNotInMemory.count() > 0) {
                         mismatches.addObject(gid + "." + relationshipName + " is missing entries in the database: " + objectsNotInMemory);
                       }
                     }
                   }
                 }
               }
             }
             verifiedDatabases.addObject(database);
           }
         }
         finally {
           databaseContext.unlock();
         }
       }
     }
     return mismatches;
   }
View Full Code Here

Examples of com.webobjects.eoaccess.EODatabaseContext

     * @param maxAttempts the maximum number of times to reattempt the operation before failing
     * @param operation the adaptor channel operation to perform
     */
    public static <T> T executeAdaptorChannelOperation(final String modelName, final int maxAttempts, final AdaptorChannelOperation<T> operation) {
    EOEditingContext editingContext = ERXEC.newEditingContext();
    EODatabaseContext databaseContext;
    try {
      databaseContext = EOUtilities.databaseContextForModelNamed(editingContext, modelName);
    }
    finally {
      editingContext.dispose();
View Full Code Here

Examples of com.webobjects.eoaccess.EODatabaseContext

   * @throws SQLException if the update script fails
   */
  @SuppressWarnings("unchecked")
  public static void upgrade(EOEditingContext editingContext, EOAdaptorChannel channel, EOModel model, String entityName, String tagsRelationshipName, String tagEntityName) throws SQLException {
    EOEntity joinEntity = ERTaggableEntity.registerTaggable(model.entityNamed(entityName), tagsRelationshipName, model.modelGroup().entityNamed(tagEntityName), null);
    EODatabaseContext databaseContext = EODatabaseContext.registeredDatabaseContextForModel(model, editingContext);
    EOSchemaGeneration generation = databaseContext.adaptorContext().adaptor().synchronizationFactory();
    NSArray<EOSQLExpression> createTableStatements = generation.createTableStatementsForEntityGroup(new NSArray<EOEntity>(joinEntity));
    ERXJDBCUtilities.executeUpdateScript(channel, ERXMigrationDatabase._stringsForExpressions(createTableStatements));
  }
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.