in commons-jcs3-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/JDBCDiskCache.java [560:618]
protected int deleteExpired()
{
int deleted = 0;
try (Connection con = getDataSource().getConnection())
{
// The shrinker thread might kick in before the table is created
// So check if the table exists first
final DatabaseMetaData dmd = con.getMetaData();
final ResultSet result = dmd.getTables(null, null,
getJdbcDiskCacheAttributes().getTableName(), null);
if (result.next())
{
getTableState().setState( TableState.DELETE_RUNNING );
final long now = System.currentTimeMillis() / 1000;
final String sql = String.format("delete from %s where IS_ETERNAL = ? and REGION = ?"
+ " and ? > SYSTEM_EXPIRE_TIME_SECONDS", getJdbcDiskCacheAttributes().getTableName());
try (PreparedStatement psDelete = con.prepareStatement( sql ))
{
psDelete.setString( 1, "F" );
psDelete.setString( 2, this.getCacheName() );
psDelete.setLong( 3, now );
setAlive(true);
deleted = psDelete.executeUpdate();
}
catch ( final SQLException e )
{
log.error( "Problem creating statement.", e );
setAlive(false);
}
logApplicationEvent( getAuxiliaryCacheAttributes().getName(), "deleteExpired",
"Deleted expired elements. URL: " + getDiskLocation() );
}
else
{
log.warn( "Trying to shrink non-existing table [{0}]",
getJdbcDiskCacheAttributes().getTableName() );
}
}
catch ( final SQLException e )
{
logError( getAuxiliaryCacheAttributes().getName(), "deleteExpired",
e.getMessage() + " URL: " + getDiskLocation() );
log.error( "Problem removing expired elements from the table.", e );
reset();
}
finally
{
getTableState().setState( TableState.FREE );
}
return deleted;
}