@Override public Long getRecordId(final UUID objectId, final ObjectType objectType, final TenantContext tenantContext) { return nonEntityDao.retrieveRecordIdFromObject(objectId, objectType, cacheControllerDispatcher.getCacheController(CacheType.RECORD_ID)); } }
private Long getAccountRecordId(final UUID objectId, final ObjectType objectType) { return nonEntityDao.retrieveAccountRecordIdFromObject(objectId, objectType, cacheControllerDispatcher.getCacheController(CacheType.ACCOUNT_RECORD_ID)); }
@Override public SubscriptionBundle getSubscriptionBundle(final UUID bundleId, final TenantContext context) throws SubscriptionApiException { final Long accountRecordId = nonEntityDao.retrieveAccountRecordIdFromObject(bundleId, ObjectType.BUNDLE, cacheControllerDispatcher.getCacheController(CacheType.ACCOUNT_RECORD_ID)); final UUID accountId = nonEntityDao.retrieveIdFromObject(accountRecordId, ObjectType.ACCOUNT); final Optional<SubscriptionBundle> bundleOptional = Iterables.<SubscriptionBundle>tryFind(getSubscriptionBundlesForAccount(accountId, context), new Predicate<SubscriptionBundle>() { @Override public boolean apply(final SubscriptionBundle bundle) { return bundle.getId().equals(bundleId); } }); if (!bundleOptional.isPresent()) { throw new SubscriptionApiException(ErrorCode.SUB_GET_INVALID_BUNDLE_ID, bundleId); } else { return bundleOptional.get(); } }
public InternalCallContext createInternalCallContext(final UUID objectId, final ObjectType objectType, final String userName, final CallOrigin callOrigin, final UserType userType, @Nullable final UUID userToken, @Nullable final String reasonCode, @Nullable final String comment, final DateTime createdDate, final DateTime updatedDate) { final Long tenantRecordId = nonEntityDao.retrieveTenantRecordIdFromObject(objectId, objectType, cacheControllerDispatcher.getCacheController(CacheType.TENANT_RECORD_ID)); final Long accountRecordId = getAccountRecordId(objectId, objectType); return createInternalCallContext(tenantRecordId, accountRecordId, userName, callOrigin, userType, userToken, reasonCode, comment, createdDate, updatedDate); }
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)); } } }
private int getCacheSize() { final CacheController<Object, Object> cache = controlCacheDispatcher.getCacheController(CacheType.RECORD_ID); return cache != null ? cache.size() : 0; }
@Override public Subscription getSubscriptionForEntitlementId(final UUID entitlementId, final TenantContext context) throws SubscriptionApiException { final Long accountRecordId = nonEntityDao.retrieveAccountRecordIdFromObject(entitlementId, ObjectType.SUBSCRIPTION, cacheControllerDispatcher.getCacheController(CacheType.ACCOUNT_RECORD_ID)); final UUID accountId = nonEntityDao.retrieveIdFromObject(accountRecordId, ObjectType.ACCOUNT); // Retrieve entitlements final AccountEntitlements accountEntitlements; try { accountEntitlements = entitlementInternalApi.getAllEntitlementsForAccountId(accountId, context); } catch (EntitlementApiException e) { throw new SubscriptionApiException(e); } // Build subscriptions final Iterable<Subscription> accountSubscriptions = Iterables.<Subscription>concat(buildSubscriptionsFromEntitlements(accountEntitlements).values()); return Iterables.<Subscription>find(accountSubscriptions, new Predicate<Subscription>() { @Override public boolean apply(final Subscription subscription) { return subscription.getId().equals(entitlementId); } }); }
final ObjectType objectType = getObjectType(); final CacheType cacheType = cachableAnnotation.value(); final CacheController<Object, Object> cache = cacheControllerDispatcher.getCacheController(cacheType); Object result = null; if (cache != 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; }
private void insertAudits(final TableName tableName, final Long entityRecordId, final Long historyRecordId, final ChangeType changeType, final InternalCallContext contextMaybeWithoutAccountRecordId) { final TableName destinationTableName = Objects.firstNonNull(tableName.getHistoryTableName(), tableName); final EntityAudit audit = new EntityAudit(destinationTableName, historyRecordId, changeType, clock.getUTCNow()); final InternalCallContext context; // Populate the account record id when creating the account record if (TableName.ACCOUNT.equals(tableName) && ChangeType.INSERT.equals(changeType)) { context = new InternalCallContext(contextMaybeWithoutAccountRecordId, entityRecordId); } else { context = contextMaybeWithoutAccountRecordId; } sqlDao.insertAuditFromTransaction(audit, context); // We need to invalidate the caches. There is a small window of doom here where caches will be stale. // TODO Knowledge on how the key is constructed is also in AuditSqlDao if (tableName.getHistoryTableName() != null) { final CacheController<Object, Object> cacheController = cacheControllerDispatcher.getCacheController(CacheType.AUDIT_LOG_VIA_HISTORY); if (cacheController != null) { final String key = buildCacheKey(ImmutableMap.<Integer, Object>of(0, tableName.getHistoryTableName(), 1, tableName.getHistoryTableName(), 2, entityRecordId)); cacheController.remove(key); } } else { final CacheController<Object, Object> cacheController = cacheControllerDispatcher.getCacheController(CacheType.AUDIT_LOG); if (cacheController != null) { final String key = buildCacheKey(ImmutableMap.<Integer, Object>of(0, tableName, 1, entityRecordId)); cacheController.remove(key); } } }