📄 rdbmcachedentityinvalidationstore.java
字号:
return newInstance(entityType, key, dt, cacheID);}/** * @return org.jasig.portal.concurrency.caching.CachedEntityInvalidation */private CachedEntityInvalidation newInstance (Class type, String key, Date expiration, int cacheID){ return new CachedEntityInvalidation(type, key, expiration, cacheID);}/** * Add the invalid entity to the underlying store. * @param ent org.jasig.portal.concurrency.caching.CachedEntityInvalidation * @param conn java.sql.Connection */private void primAdd(CachedEntityInvalidation ent, Connection conn)throws SQLException, CachingException{ Integer typeID = EntityTypes.getEntityTypeID(ent.getType()); String key = ent.getKey(); Timestamp ts = new Timestamp(ent.getInvalidationTime().getTime()); int cacheID = ent.getCacheID(); try { RDBMServices.PreparedStatement ps = new RDBMServices.PreparedStatement(conn, getAddSql()); try { ps.setInt(1, typeID.intValue()); // entity type ps.setString(2, key); // entity key ps.setTimestamp(3, ts); // invalidation time ps.setInt(4, cacheID); // entity cache ID log.debug( "RDBMInvalidCacheableEntityStore.primAdd(): " + ps + " ( " + typeID.intValue() + ", " + key + ", " + ts + " )"); int rc = ps.executeUpdate(); if ( rc != 1 ) { String errString = "Problem adding " + ent; log.error( errString); throw new CachingException(errString); } } finally { if ( ps != null ) ps.close(); } } catch (java.sql.SQLException sqle) { log.error(sqle, sqle); throw sqle; }}/** * Delete invalid entities from the underlying store whose invalidation is * before <code>invalidation</code>. * * @param expiration java.util.Date * @param conn Connection */private void primDeleteBefore(Date expiration, Connection conn)throws CachingException, SQLException{ Timestamp ts = new Timestamp(expiration.getTime()); try { RDBMServices.PreparedStatement ps = new RDBMServices.PreparedStatement(conn, getDeleteInvalidationsSql()); try { ps.setTimestamp(1, ts); log.debug( "RDBMInvalidCacheableEntityStore.primDeleteBefore(): " + ps + " (" + ts + ")"); int rc = ps.executeUpdate(); log.debug("Rows deleted: " + rc); } finally { if ( ps != null ) ps.close(); } } catch (java.sql.SQLException sqle) { log.error(sqle, sqle); throw sqle; }} /** * Retrieve CachedEntityInvalidations from the underlying store. * @param sql String - the sql string used to select the entity lock rows. * @param conn Connection * @exception CachingException - wraps an Exception specific to the store. */private CachedEntityInvalidation[] primSelect(String sql, Connection conn) throws CachingException{ Statement stmnt = null; ResultSet rs = null; List entities = new ArrayList(); log.debug("RDBMInvalidCacheableEntityStore.primSelect(): " + sql); try { stmnt = conn.createStatement(); try { rs = stmnt.executeQuery(sql); try { while ( rs.next() ) { entities.add(instanceFromResultSet(rs)); } } finally { rs.close(); } } finally { stmnt.close(); } } catch (SQLException sqle) { log.error(sqle, sqle); throw new CachingException("Problem retrieving Invalid Entities " + sqle.getMessage()); } return ((CachedEntityInvalidation[])entities.toArray(new CachedEntityInvalidation[entities.size()]));}/** * Updates the invalid enity's <code>expiration</code> in the underlying store. * @param ent org.jasig.portal.concurrency.caching.CachedEntityInvalidation * @param conn Connection */private void primUpdate(CachedEntityInvalidation ent, Connection conn)throws SQLException, CachingException{ Integer typeID = EntityTypes.getEntityTypeID(ent.getType()); String key = ent.getKey(); java.sql.Timestamp ts = new java.sql.Timestamp(ent.getInvalidationTime().getTime()); int cacheID = ent.getCacheID(); try { RDBMServices.PreparedStatement ps = new RDBMServices.PreparedStatement(conn, getUpdateSql()); try { ps.setTimestamp(1, ts); // updated invalidation ps.setInt(2, cacheID); // updated entity cache ID ps.setInt(3, typeID.intValue()); // entity type ps.setString(4, key); // entity key log.debug( "RDBMInvalidCacheableEntityStore.primUpdate(): " + ps + " ( " + typeID.intValue() + ", " + key + ", " + ts + " )"); int rc = ps.executeUpdate(); if ( rc != 1 ) { String errString = "Problem updating " + ent; log.error( errString); throw new CachingException(errString); } } finally { if ( ps != null ) ps.close(); } } catch (java.sql.SQLException sqle) { log.error(sqle, sqle); throw sqle; }} /** * Retrieve CachedEntityInvalidation from the underlying store. Any or all of * the parameters may be null. * @param entityType Class * @param entityKey String * @param invalidation Date * @param conn Connection * @exception CachingException - wraps an Exception specific to the store. */private CachedEntityInvalidation[] select (Class entityType, String entityKey, Date invalidation, Integer cacheID, Connection conn)throws CachingException{ StringBuffer sqlQuery = new StringBuffer( getSelectSql() + " WHERE 1 = 1"); if ( entityType != null ) { Integer typeID = EntityTypes.getEntityTypeID(entityType); sqlQuery.append(" AND " + ENTITY_TYPE_COLUMN + EQ + typeID); } if ( entityKey != null ) { sqlQuery.append(" AND " + ENTITY_KEY_COLUMN + EQ + sqlQuote(entityKey)); } if ( invalidation != null ) { Timestamp ts = new Timestamp(invalidation.getTime()); sqlQuery.append(" AND " + INVALIDATION_TIME_COLUMN + EQ + printTimestamp(ts)); } if ( cacheID != null ) { sqlQuery.append(" AND " + ENTITY_CACHE_ID_COLUMN + EQ + cacheID); } return primSelect(sqlQuery.toString(), conn);} /** * Retrieve CachedEntityInvalidations from the underlying store. Any or all * of the parameters may be null. * @param entityType Class * @param entityKey String * @param invalidation Date * @param cacheID Integer - the cache ID we do NOT want to retrieve. * @param conn Connection * @exception CachingException - wraps an Exception specific to the store. */private CachedEntityInvalidation[] selectAfter (Class entityType, String entityKey, Date invalidation, Integer cacheID, Connection conn)throws CachingException{ StringBuffer sqlQuery = new StringBuffer( getSelectSql() + " WHERE 1 = 1"); if ( entityType != null ) { Integer typeID = EntityTypes.getEntityTypeID(entityType); sqlQuery.append(" AND " + ENTITY_TYPE_COLUMN + EQ + typeID); } if ( entityKey != null ) { sqlQuery.append(" AND " + ENTITY_KEY_COLUMN + EQ + sqlQuote(entityKey)); } if ( invalidation != null ) { Timestamp ts = new Timestamp(invalidation.getTime()); sqlQuery.append(" AND " + INVALIDATION_TIME_COLUMN + GT + printTimestamp(ts)); } if ( cacheID != null ) { sqlQuery.append(" AND " + ENTITY_CACHE_ID_COLUMN + NE + cacheID); } return primSelect(sqlQuery.toString(), conn);}/** * @return org.jasig.portal.concurrency.caching.RDBMCachedEntityInvalidationStore */public static synchronized RDBMCachedEntityInvalidationStore singleton()throws CachingException{ if ( singleton == null ) { singleton = new RDBMCachedEntityInvalidationStore(); } return singleton;}/** * @return java.lang.String */private static java.lang.String sqlQuote(Object o){ return QUOTE + o + QUOTE;}/** * @return long */private static long getTimestampMillis(Timestamp ts){ if ( timestampHasMillis ) { return ts.getTime(); } else { return (ts.getTime() + ts.getNanos() / 1000000); }}/** * Clear invalidations more than 1 hour old. */private void initialize() throws CachingException{ Date anHourAgo = new Date( System.currentTimeMillis() - 60 * 60 * 1000 ); deleteBefore(anHourAgo); Date testDate = new Date(); Timestamp testTimestamp = new Timestamp(testDate.getTime()); timestampHasMillis = (testDate.getTime() == testTimestamp.getTime());}/** * @return java.lang.String */private static java.lang.String printTimestamp(Timestamp ts){ return RDBMServices.sqlTimeStamp(getTimestampMillis(ts));}}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -