/** * Attempt to save some of the cost associated with getting a fresh connection. * Assume the DatabaseDriver has been cached, if appropriate. * Note: Connections that are participating in transactions will not be refreshd.^M */ protected void reconnect(AbstractSession session) throws DatabaseException { session.log(SessionLog.FINEST, SessionLog.CONNECTION, "reconnecting_to_external_connection_pool"); session.startOperationProfile(SessionProfiler.CONNECT); connect(getLogin()); session.endOperationProfile(SessionProfiler.CONNECT); }
/** * INTERNAL: * Closes a PreparedStatment (which is supposed to close it's current resultSet). * Factored out to simplify coding and handle exceptions. */ public void closeStatement(Statement statement, AbstractSession session) throws SQLException { if (statement == null) { decrementCallCount(); return; } try { session.startOperationProfile(SessionProfiler.STATEMENT_EXECUTE); statement.close(); } finally { session.endOperationProfile(SessionProfiler.STATEMENT_EXECUTE); decrementCallCount(); // If this is the cached dynamic statement, release it. if (statement == this.dynamicStatement) { this.dynamicStatement = null; // The dynamic statement is cached and only closed on disconnect. setIsDynamicStatementInUse(false); } } }
/** * PUBLIC: * <p> * Log a throwable with level and category. * </p><p> * * @param level the log request level value * </p><p> * @param category the string representation of a TopLink category. * </p><p> * @param throwable a Throwable * </p> */ public void logThrowable(int level, String category, Throwable throwable) { // Must not create the log if not logging as is a performance issue. if (shouldLog(level, category)) { startOperationProfile(SessionProfiler.Logging); log(new SessionLogEntry(this, level, category, throwable)); endOperationProfile(SessionProfiler.Logging); } }
/** * INTERNAL: * <p> * Log a message with level, category, parameters and accessor. shouldTranslate determines if the message needs to be translated. * </p><p> * * @param level the log request level value * </p><p> * @param message the string message * </p><p> * @param params array of parameters to the message * </p><p> * @param accessor the connection that generated the log entry * </p><p> * @param category the string representation of a TopLink category. * </p><p> * @param shouldTranslate true if the message needs to be translated. * </p> */ public void log(int level, String category, String message, Object[] params, Accessor accessor, boolean shouldTranslate) { if (shouldLog(level, category)) { startOperationProfile(SessionProfiler.Logging); log(new SessionLogEntry(level, category, this, message, params, accessor, shouldTranslate)); endOperationProfile(SessionProfiler.Logging); } }
/** * INTERNAL: * <p> * Log a message with level, parameters and accessor. shouldTranslate determines if the message needs to be translated. * </p><p> * * @param level the log request level value * </p><p> * @param message the string message * </p><p> * @param params array of parameters to the message * </p><p> * @param accessor the connection that generated the log entry * </p><p> * @param shouldTranslate true if the message needs to be translated. * </p> */ public void log(int level, String message, Object[] params, Accessor accessor, boolean shouldTranslate) { if (shouldLog(level, null)) { startOperationProfile(SessionProfiler.Logging); log(new SessionLogEntry(level, this, message, params, accessor, shouldTranslate)); endOperationProfile(SessionProfiler.Logging); } }
/** * Execute the statement. */ protected ResultSet executeSelect(DatabaseCall call, Statement statement, AbstractSession session) throws SQLException { ResultSet resultSet; session.startOperationProfile(SessionProfiler.STATEMENT_EXECUTE); try { if (call.isDynamicCall(session)) { resultSet = statement.executeQuery(call.getSQLString()); } else { resultSet = ((PreparedStatement)statement).executeQuery(); } } finally { session.endOperationProfile(SessionProfiler.STATEMENT_EXECUTE); } // Allow for procs with outputs to be raised as events for error handling. if (call.shouldBuildOutputRow()) { AbstractRecord outputRow = buildOutputRow((CallableStatement)statement, call, session); call.getQuery().setProperty("output", outputRow); session.getEventManager().outputParametersDetected(outputRow, call); } return resultSet; }
public boolean containsKey(Vector key, Class theClass, ClassDescriptor descriptor) { // Check for null, contains causes null pointer. for (int index = 0; index < key.size(); index++) { if (key.elementAt(index) == null) { return false; } } IdentityMap map = getIdentityMap(descriptor); boolean contains; if (isCacheAccessPreCheckRequired()) { getSession().startOperationProfile(SessionProfiler.CACHE); acquireReadLock(); try { contains = map.containsKey(key); } finally { releaseReadLock(); getSession().endOperationProfile(SessionProfiler.CACHE); } } else { contains = map.containsKey(key); } return contains; }
/** * Disconnect from the datasource. */ public void disconnect(AbstractSession session) throws DatabaseException { session.log(SessionLog.CONFIG, SessionLog.CONNECTION, "disconnect", (Object[])null, this); if (getDatasourceConnection() == null) { return; } session.incrementProfile(SessionProfiler.TlDisconnects); session.startOperationProfile(SessionProfiler.CONNECT); closeDatasourceConnection(); setDatasourceConnection(null); setIsInTransaction(false); session.endOperationProfile(SessionProfiler.CONNECT); }
/** * Provides access for setting a concurrency lock on an IdentityMap. * @see IdentityMap#aquire */ public void acquireReadLock() { getSession().startOperationProfile(SessionProfiler.CACHE); if (getSession().getDatasourceLogin().shouldSynchronizedReadOnWrite()) { getCacheMutex().acquireReadLock(); } getSession().endOperationProfile(SessionProfiler.CACHE); }
/** * Begin a transaction on the database. If not using managed transaction begin a local transaction. */ public void beginTransaction(AbstractSession session) throws DatabaseException { if (usesExternalTransactionController()) { setIsInTransaction(true); return; } session.log(SessionLog.FINER, SessionLog.TRANSACTION, "begin_transaction", (Object[])null, this); try { session.startOperationProfile(SessionProfiler.TRANSACTION); incrementCallCount(session); basicBeginTransaction(session); setIsInTransaction(true); } finally { decrementCallCount(); session.endOperationProfile(SessionProfiler.TRANSACTION); } }
/** * Retrieve the write lock value of the cache key associated with the given primary key, */ public Object getWriteLockValue(Vector primaryKey, Class domainClass, ClassDescriptor descriptor) { IdentityMap map = getIdentityMap(descriptor); Object value; if (isCacheAccessPreCheckRequired()) { getSession().startOperationProfile(SessionProfiler.CACHE); acquireReadLock(); try { value = map.getWriteLockValue(primaryKey); } finally { releaseReadLock(); } getSession().endOperationProfile(SessionProfiler.CACHE); } else { value = map.getWriteLockValue(primaryKey); } return value; }
/** * Remove the object from the object cache. */ public Object removeFromIdentityMap(Vector key, Class domainClass, ClassDescriptor descriptor) { IdentityMap map = getIdentityMap(descriptor); Object value; if (isCacheAccessPreCheckRequired()) { getSession().startOperationProfile(SessionProfiler.CACHE); // This is atomic so considered a read lock. acquireReadLock(); try { value = map.remove(key); } finally { releaseReadLock(); } getSession().endOperationProfile(SessionProfiler.CACHE); } else { value = map.remove(key); } return value; }
/** * INTERNAL: * Find the cachekey for the provided primary key and place a readlock on it. * This will allow multiple users to read the same object but prevent writes to * the object while the read lock is held. * If no readlock can be acquired then do not wait but return null. */ public CacheKey acquireReadLockOnCacheKeyNoWait(Vector primaryKey, Class domainClass, ClassDescriptor descriptor) { CacheKey cacheKey = null; if (isCacheAccessPreCheckRequired()) { getSession().startOperationProfile(SessionProfiler.CACHE); acquireReadLock(); try { cacheKey = getIdentityMap(descriptor).acquireReadLockOnCacheKeyNoWait(primaryKey); } finally { releaseReadLock(); } getSession().endOperationProfile(SessionProfiler.CACHE); } else { cacheKey = getIdentityMap(descriptor).acquireReadLockOnCacheKeyNoWait(primaryKey); } return cacheKey; }
/** * Provides access for setting a deferred lock on an object in the IdentityMap. */ public CacheKey acquireDeferredLock(Vector primaryKey, Class domainClass, ClassDescriptor descriptor) { CacheKey cacheKey = null; if (isCacheAccessPreCheckRequired()) { getSession().startOperationProfile(SessionProfiler.CACHE); acquireReadLock(); try { cacheKey = getIdentityMap(descriptor).acquireDeferredLock(primaryKey); } finally { releaseReadLock(); } getSession().endOperationProfile(SessionProfiler.CACHE); } else { cacheKey = getIdentityMap(descriptor).acquireDeferredLock(primaryKey); } return cacheKey; }
/** * Provides access for setting a concurrency lock on an object in the IdentityMap. * called with true from the merge process, if true then the refresh will not refresh the object * @see IdentityMap#aquire */ public CacheKey acquireLock(Vector primaryKey, Class domainClass, boolean forMerge, ClassDescriptor descriptor) { CacheKey cacheKey = null; if (isCacheAccessPreCheckRequired()) { getSession().startOperationProfile(SessionProfiler.CACHE); acquireReadLock(); try { cacheKey = getIdentityMap(descriptor).acquireLock(primaryKey, forMerge); } finally { releaseReadLock(); } getSession().endOperationProfile(SessionProfiler.CACHE); } else { cacheKey = getIdentityMap(descriptor).acquireLock(primaryKey, forMerge); } return cacheKey; }
/** * Provides access for setting a concurrency lock on an object in the IdentityMap. * called with true from the merge process, if true then the refresh will not refresh the object * @see IdentityMap#aquire */ public CacheKey acquireLockNoWait(Vector primaryKey, Class domainClass, boolean forMerge, ClassDescriptor descriptor) { CacheKey cacheKey = null; if (isCacheAccessPreCheckRequired()) { getSession().startOperationProfile(SessionProfiler.CACHE); acquireReadLock(); try { cacheKey = getIdentityMap(descriptor).acquireLockNoWait(primaryKey, forMerge); } finally { releaseReadLock(); } getSession().endOperationProfile(SessionProfiler.CACHE); } else { cacheKey = getIdentityMap(descriptor).acquireLockNoWait(primaryKey, forMerge); } return cacheKey; }
/** * INTERNAL: * Find the cachekey for the provided primary key and place a readlock on it. * This will allow multiple users to read the same object but prevent writes to * the object while the read lock is held. */ public CacheKey acquireReadLockOnCacheKey(Vector primaryKey, Class domainClass, ClassDescriptor descriptor) { CacheKey cacheKey = null; if (isCacheAccessPreCheckRequired()) { getSession().startOperationProfile(SessionProfiler.CACHE); acquireReadLock(); try { cacheKey = getIdentityMap(descriptor).acquireReadLockOnCacheKey(primaryKey); } finally { releaseReadLock(); } getSession().endOperationProfile(SessionProfiler.CACHE); } else { cacheKey = getIdentityMap(descriptor).acquireReadLockOnCacheKey(primaryKey); } return cacheKey; }
/** * Update the wrapper object the cache key associated with the given primary key, * this is used for EJB. */ public void setWrapper(Vector primaryKey, Class theClass, Object wrapper) { ClassDescriptor descriptor = getSession().getDescriptor(theClass); IdentityMap map = getIdentityMap(descriptor); if (isCacheAccessPreCheckRequired()) { getSession().startOperationProfile(SessionProfiler.CACHE); // This is atomic so considered a read lock. acquireReadLock(); try { map.setWrapper(primaryKey, wrapper); } finally { releaseReadLock(); } getSession().endOperationProfile(SessionProfiler.CACHE); } else { map.setWrapper(primaryKey, wrapper); } }
/** * Update the write lock value of the cache key associated with the given primary key, */ public void setWriteLockValue(Vector primaryKey, Class theClass, Object writeLockValue) { ClassDescriptor descriptor = getSession().getDescriptor(theClass); IdentityMap map = getIdentityMap(descriptor); if (isCacheAccessPreCheckRequired()) { getSession().startOperationProfile(SessionProfiler.CACHE); // This is atomic so considered a read lock. acquireReadLock(); try { map.setWriteLockValue(primaryKey, writeLockValue); } finally { releaseReadLock(); } getSession().endOperationProfile(SessionProfiler.CACHE); } else { map.setWriteLockValue(primaryKey, writeLockValue); } }
/** * Get the wrapper object from the cache key associated with the given primary key, * this is used for EJB. */ public Object getWrapper(Vector primaryKey, Class theClass) { ClassDescriptor descriptor = getSession().getDescriptor(theClass); IdentityMap map = getIdentityMap(descriptor); Object wrapper; if (isCacheAccessPreCheckRequired()) { getSession().startOperationProfile(SessionProfiler.CACHE); acquireReadLock(); try { wrapper = map.getWrapper(primaryKey); } finally { releaseReadLock(); } getSession().endOperationProfile(SessionProfiler.CACHE); } else { wrapper = map.getWrapper(primaryKey); } return wrapper; }