@Override public CacheEventListener createCacheEventListener(final Properties properties) { return new ExpirationListener(); }
@Override public EhCacheBasedCacheController<Object, Object> apply(final CacheLoader input) { return new EhCacheBasedCacheController<Object, Object>(cache); } });
public static CacheType findByName(final String input) { for (final CacheType cacheType : CacheType.values()) { if (cacheType.cacheName.equals(input)) { return cacheType; } } return null; } }
private Long retrieveRecordIdFromCache(UUID tagId) { final CacheController<Object, Object> cache = controlCacheDispatcher.getCacheController(CacheType.RECORD_ID); Object result = null; if (cache != null) { // Keys are upper cased by convention result = cache.get(tagId.toString().toUpperCase(), new CacheLoaderArgument(ObjectType.TAG)); } return (Long) result; }
@Override public Long getRecordId(final UUID objectId, final ObjectType objectType, final TenantContext tenantContext) { return nonEntityDao.retrieveRecordIdFromObject(objectId, objectType, cacheControllerDispatcher.getCacheController(CacheType.RECORD_ID)); } }
private int getCacheSize() { final CacheController<Object, Object> cache = controlCacheDispatcher.getCacheController(CacheType.RECORD_ID); return cache != null ? cache.size() : 0; }
private Long withCaching(final OperationRetrieval<Long> op, @Nullable final UUID objectId, final ObjectType objectType, @Nullable final CacheController<Object, Object> cache) { if (objectId == null) { return null; } if (cache != null) { return (Long) cache.get(objectId.toString(), new CacheLoaderArgument(objectType)); } return op.doRetrieve(objectId, objectType); } }
@Override public CacheControllerDispatcher get() { final Map<CacheType, CacheController<Object, Object>> cacheControllers = new LinkedHashMap<CacheType, CacheController<Object, Object>>(); for (final String cacheName : cacheManager.getCacheNames()) { final CacheType cacheType = CacheType.findByName(cacheName); final Collection<EhCacheBasedCacheController<Object, Object>> cacheControllersForCacheName = getCacheControllersForCacheName(cacheName); // EhCache supports multiple cache loaders per type, but not Kill Bill - take the first one if (cacheControllersForCacheName.size() > 0) { final EhCacheBasedCacheController<Object, Object> ehCacheBasedCacheController = cacheControllersForCacheName.iterator().next(); cacheControllers.put(cacheType, ehCacheBasedCacheController); } } return new CacheControllerDispatcher(cacheControllers); }
@SqlQuery @Cachable(CacheType.AUDIT_LOG) public List<AuditLogModelDao> getAuditLogsForTargetRecordId(@CachableKey(1) @Bind("tableName") final String tableName, @CachableKey(2) @Bind("targetRecordId") final long targetRecordId, @BindBean final InternalTenantContext context);
@Override public Object load(final Object key, final Object argument) throws CacheException { checkCacheLoaderStatus(); if (!(key instanceof String)) { throw new IllegalArgumentException("Unexpected key type of " + key.getClass().getName()); } if (!(argument instanceof CacheLoaderArgument)) { throw new IllegalArgumentException("Unexpected key type of " + argument.getClass().getName()); } final String objectId = (String) key; final ObjectType objectType = ((CacheLoaderArgument) argument).getObjectType(); return nonEntityDao.retrieveRecordIdFromObject(UUID.fromString(objectId), objectType, null); } }
@Override public Object load(final Object key, final Object argument) { checkCacheLoaderStatus(); if (!(key instanceof String)) { throw new IllegalArgumentException("Unexpected key type of " + key.getClass().getName()); } if (!(argument instanceof CacheLoaderArgument)) { throw new IllegalArgumentException("Unexpected key type of " + argument.getClass().getName()); } final Object[] args = ((CacheLoaderArgument) argument).getArgs(); final String tableName = (String) args[0]; final Long targetRecordId = (Long) args[1]; final InternalTenantContext internalTenantContext = (InternalTenantContext) args[2]; return auditSqlDao.getAuditLogsForTargetRecordId(tableName, targetRecordId, internalTenantContext); } }
@Override public Object load(final Object key, final Object argument) { checkCacheLoaderStatus(); if (!(key instanceof String)) { throw new IllegalArgumentException("Unexpected key type of " + key.getClass().getName()); } if (!(argument instanceof CacheLoaderArgument)) { throw new IllegalArgumentException("Unexpected key type of " + argument.getClass().getName()); } final String objectId = (String) key; final ObjectType objectType = ((CacheLoaderArgument) argument).getObjectType(); return nonEntityDao.retrieveTenantRecordIdFromObject(UUID.fromString(objectId), objectType, null); } }
@Override public Object load(final Object key, final Object argument) { checkCacheLoaderStatus(); if (!(key instanceof String)) { throw new IllegalArgumentException("Unexpected key type of " + key.getClass().getName()); } if (!(argument instanceof CacheLoaderArgument)) { throw new IllegalArgumentException("Unexpected key type of " + argument.getClass().getName()); } final String objectId = (String) key; final ObjectType objectType = ((CacheLoaderArgument) argument).getObjectType(); return nonEntityDao.retrieveAccountRecordIdFromObject(UUID.fromString(objectId), objectType, null); } }
@Override public Object load(final Object key, final Object argument) { checkCacheLoaderStatus(); if (!(key instanceof String)) { throw new IllegalArgumentException("Unexpected key type of " + key.getClass().getName()); } if (!(argument instanceof CacheLoaderArgument)) { throw new IllegalArgumentException("Unexpected key type of " + argument.getClass().getName()); } final Object[] args = ((CacheLoaderArgument) argument).getArgs(); final String tableName = (String) args[0]; final String historyTableName = (String) args[1]; final Long targetRecordId = (Long) args[2]; final InternalTenantContext internalTenantContext = (InternalTenantContext) args[3]; return auditSqlDao.getAuditLogsViaHistoryForTargetRecordId(tableName, historyTableName, targetRecordId, internalTenantContext); } }
public void clearAll() { for (final CacheController<Object, Object> cacheController : caches.values()) { cacheController.removeAll(); } } }
protected void checkCacheLoaderStatus() { if (getStatus() != Status.STATUS_ALIVE) { throw new CacheException("CacheLoader is not available!"); } } }
private Long getAccountRecordId(final UUID objectId, final ObjectType objectType) { return nonEntityDao.retrieveAccountRecordIdFromObject(objectId, objectType, cacheControllerDispatcher.getCacheController(CacheType.ACCOUNT_RECORD_ID)); }
@SqlQuery @Cachable(CacheType.AUDIT_LOG_VIA_HISTORY) public List<AuditLogModelDao> getAuditLogsViaHistoryForTargetRecordId(@CachableKey(1) @Bind("tableName") final String historyTableName, /* Uppercased - used to find entries in audit_log table */ @CachableKey(2) @Define("historyTableName") final String actualHistoryTableName, /* Actual table name, used in the inner join query */ @CachableKey(3) @Bind("targetRecordId") final long targetRecordId, @BindBean final InternalTenantContext context); }
private Long getTenantRecordId(final TenantContext context) { // Default to single default tenant (e.g. single tenant mode) // TODO Extract this convention (e.g. BusinessAnalyticsBase needs to know about it) if (context.getTenantId() == null) { return INTERNAL_TENANT_RECORD_ID; } else { return nonEntityDao.retrieveTenantRecordIdFromObject(context.getTenantId(), ObjectType.TENANT, cacheControllerDispatcher.getCacheController(CacheType.TENANT_RECORD_ID)); } } }
@SqlQuery @Cachable(CacheType.RECORD_ID) public Long getRecordId(@CachableKey(1) @Bind("id") final String id, @BindBean final InternalTenantContext context);