/** Verifies that the object was merged to the cache, and written to the database correctly. */
 public static void verifyObjectInCacheAndDatabase(Object writtenObject, String persistenceUnit) {
   AbstractSession dbs = getDatabaseSession(persistenceUnit);
   Object readObject = dbs.readObject(writtenObject);
   if (!dbs.compareObjects(readObject, writtenObject)) {
     fail(
         "Object from cache: "
             + readObject
             + " does not match object that was written: "
             + writtenObject
             + ". See log (on finest) for what did not match.");
   }
   dbs.getIdentityMapAccessor().initializeAllIdentityMaps();
   readObject = dbs.readObject(writtenObject);
   if (!dbs.compareObjects(readObject, writtenObject)) {
     fail(
         "Object from database: "
             + readObject
             + " does not match object that was written: "
             + writtenObject
             + ". See log (on finest) for what did not match.");
   }
 }
コード例 #2
0
  /**
   * INTERNAL: The cache check is done before the prepare as a hit will not require the work to be
   * done.
   */
  protected Object checkEarlyReturnImpl(AbstractSession session, AbstractRecord translationRow) {
    // Check for in-memory only query.
    if (shouldCheckCacheOnly()) {
      // assert !isReportQuery();
      if (shouldUseWrapperPolicy()) {
        getContainerPolicy().setElementDescriptor(this.descriptor);
      }

      // PERF: Fixed to not query each unit of work cache (is not conforming),
      // avoid hashtable and primary key indexing.
      // At some point we may need to support some kind of in-memory with conforming option,
      // but we do not currently allow this.
      AbstractSession rootSession = session;
      while (rootSession.isUnitOfWork()) {
        rootSession = ((UnitOfWorkImpl) rootSession).getParent();
      }
      Vector allCachedVector =
          rootSession
              .getIdentityMapAccessor()
              .getAllFromIdentityMap(
                  getSelectionCriteria(),
                  getReferenceClass(),
                  translationRow,
                  getInMemoryQueryIndirectionPolicyState(),
                  false);

      // Must ensure that all of the objects returned are correctly registered in the unit of work.
      if (session.isUnitOfWork()) {
        allCachedVector = ((UnitOfWorkImpl) session).registerAllObjects(allCachedVector);
      }

      return getContainerPolicy().buildContainerFromVector(allCachedVector, session);
    } else {
      return null;
    }
  }