@Override public Boolean recordsWithTrackingIdExist(final UUID subscriptionId, final String trackingId, final InternalTenantContext context) { return dbRouter.onDemand(false).recordsWithTrackingIdExist(subscriptionId, trackingId, context) != null; }
public List<DefaultColumnInfo> getColumnInfoList(@Nullable final String schemaName) { return dbRouter.onDemand(true).getSchemaInfo(schemaName); } }
@Override public void record(final Iterable<RolledUpUsageModelDao> usages, final InternalCallContext context) { dbRouter.onDemand(false).create(usages, context); }
@Override public Long retrieveHistoryTargetRecordId(@Nullable final Long recordId, final TableName tableName) { return dbRouter.onDemand(true).getHistoryTargetRecordId(recordId, tableName.getTableName()); }
@Override protected Session doReadSession(final Serializable sessionId) { // Shiro should not pass us a null sessionId, but be safe... if (sessionId == null) { return null; } final String sessionIdString = sessionId.toString(); final SessionModelDao sessionModelDao = dbRouter.onDemand(true).read(sessionIdString); if (sessionModelDao == null) { return null; } return toSession(sessionModelDao); }
private List<AuditLog> doGetAuditLogsForId(final TableName tableName, final UUID objectId, final AuditLevel auditLevel, final InternalTenantContext context) { final Long recordId = dbRouter.onDemand(true).getRecordIdFromObject(objectId.toString(), tableName.getTableName()); if (recordId == null) { return ImmutableList.<AuditLog>of(); } else { return getAuditLogsForRecordId(tableName, objectId, recordId, auditLevel, context); } }
@Override public Collection<Session> getActiveSessions() { final Collection<Session> cachedActiveSessions = super.getActiveSessions(); // To make sure the ValidatingSessionManager purges old sessions on disk final List<SessionModelDao> oldActiveSessionsOnDisk = dbRouter.onDemand(true).findOldActiveSessions(); final Collection<Session> activeSessions = new LinkedList<Session>(cachedActiveSessions); for (final SessionModelDao sessionModelDao : oldActiveSessionsOnDisk) { activeSessions.add(toSession(sessionModelDao)); } return activeSessions; }
@Override public List<AuditLogModelDao> compute(final String key, final CacheLoaderArgument cacheLoaderArgument) { final Object[] args = cacheLoaderArgument.getArgs(); final String tableName = (String) args[0]; final Long targetRecordId = (Long) args[1]; final InternalTenantContext internalTenantContext = (InternalTenantContext) args[2]; return dbRouter.onDemand(true).getAuditLogsForTargetRecordId(tableName, targetRecordId, internalTenantContext); } }
@Override protected void doDelete(final Session session) { dbRouter.onDemand(false).delete(new SessionModelDao(session)); }
@Override public Long doRetrieve(final ObjectType objectType) { final NonEntitySqlDao inTransactionNonEntitySqlDao = handle == null ? dbRouter.onDemand(true) : SqlObjectBuilder.attach(handle, NonEntitySqlDao.class); return inTransactionNonEntitySqlDao.getRecordIdFromObject(objectId.toString(), tableName.getTableName()); } }, objectId.toString(), objectType, tableName, cache);
@Override public UUID doRetrieve(final ObjectType objectType) { final NonEntitySqlDao inTransactionNonEntitySqlDao = handle == null ? dbRouter.onDemand(true) : SqlObjectBuilder.attach(handle, NonEntitySqlDao.class); return inTransactionNonEntitySqlDao.getIdFromObject(recordId, tableName.getTableName()); } }, String.valueOf(recordId), objectType, tableName, cache);
@Override protected void doUpdate(final Session session) { if (shouldUpdateSession(session)) { dbRouter.onDemand(false).update(new SessionModelDao(session)); } }
@Override public List<RolledUpUsageModelDao> getRawUsageForAccount(final LocalDate startDate, final LocalDate endDate, final InternalTenantContext context) { return dbRouter.onDemand(true).getRawUsageForAccount(startDate.toDate(), endDate.toDate(), context); } }
@Override protected Serializable doCreate(final Session session) { final UUID sessionId = UUIDs.randomUUID(); // See SessionModelDao#toSimpleSession for why we use toString() final String sessionIdAsString = sessionId.toString(); assignSessionId(session, sessionIdAsString); dbRouter.onDemand(false).create(new SessionModelDao(session)); // Make sure to return a String here as well, or Shiro will cache the Session with a UUID key // while it is expecting String return sessionIdAsString; }
@Override public List<RolledUpUsageModelDao> getAllUsageForSubscription(final UUID subscriptionId, final LocalDate startDate, final LocalDate endDate, final InternalTenantContext context) { return dbRouter.onDemand(true).getAllUsageForSubscription(subscriptionId, startDate.toDate(), endDate.toDate(), context); }
@Override public List<RolledUpUsageModelDao> getUsageForSubscription(final UUID subscriptionId, final LocalDate startDate, final LocalDate endDate, final String unitType, final InternalTenantContext context) { return dbRouter.onDemand(true).getUsageForSubscription(subscriptionId, startDate.toDate(), endDate.toDate(), unitType, context); }
@Override public Long doRetrieve(final ObjectType objectType) { final NonEntitySqlDao inTransactionNonEntitySqlDao = handle == null ? dbRouter.onDemand(true) : SqlObjectBuilder.attach(handle, NonEntitySqlDao.class); switch (tableName) { case TENANT: // Explicit cast to Long to avoid NPE (unboxing to long) return objectId == null ? (Long) 0L : inTransactionNonEntitySqlDao.getTenantRecordIdFromTenant(objectIdOrNull); default: return inTransactionNonEntitySqlDao.getTenantRecordIdFromObjectOtherThanTenant(objectIdOrNull, tableName.getTableName()); } } }, objectIdOrNull, objectType, tableName, cache);
private List<AuditLog> doGetAuditLogsViaHistoryForId(final TableName tableName, final UUID objectId, final AuditLevel auditLevel, final InternalTenantContext context) { final TableName historyTableName = tableName.getHistoryTableName(); if (historyTableName == null) { throw new IllegalStateException("History table shouldn't be null for " + tableName); } final Long targetRecordId = dbRouter.onDemand(true).getRecordIdFromObject(objectId.toString(), tableName.getTableName()); final List<AuditLog> allAuditLogs = transactionalSqlDao.execute(true, new EntitySqlDaoTransactionWrapper<List<AuditLog>>() { @Override public List<AuditLog> inTransaction(final EntitySqlDaoWrapperFactory entitySqlDaoWrapperFactory) throws Exception { final List<AuditLogModelDao> auditLogsViaHistoryForTargetRecordId = entitySqlDaoWrapperFactory.become(EntitySqlDao.class).getAuditLogsViaHistoryForTargetRecordId(historyTableName.name(), historyTableName.getTableName().toLowerCase(), targetRecordId, context); return buildAuditLogsFromModelDao(auditLogsViaHistoryForTargetRecordId, tableName.getObjectType(), objectId); } }); return filterAuditLogs(auditLevel, allAuditLogs); }
@Override public Long doRetrieve(final ObjectType objectType) { final NonEntitySqlDao inTransactionNonEntitySqlDao = handle == null ? dbRouter.onDemand(true) : SqlObjectBuilder.attach(handle, NonEntitySqlDao.class); switch (tableName) { case TENANT: case TAG_DEFINITIONS: case TAG_DEFINITION_HISTORY: return null; case ACCOUNT: return inTransactionNonEntitySqlDao.getAccountRecordIdFromAccount(objectIdOrNull); default: return inTransactionNonEntitySqlDao.getAccountRecordIdFromObjectOtherThanAccount(objectIdOrNull, tableName.getTableName()); } } }, objectIdOrNull, objectType, tableName, cache);
@Override public DefaultAccountAuditLogs getAuditLogsForAccountRecordId(final AuditLevel auditLevel, final InternalTenantContext context) { final UUID accountId = dbRouter.onDemand(true).getIdFromObject(context.getAccountRecordId(), TableName.ACCOUNT.getTableName()); // Lazy evaluate records to minimize the memory footprint (these can yield a lot of results) // We usually always want to wrap our queries in an EntitySqlDaoTransactionWrapper... except here. // Since we want to stream the results out, we don't want to auto-commit when this method returns. final EntitySqlDao auditSqlDao = transactionalSqlDao.onDemandForStreamingResults(EntitySqlDao.class); final Iterator<AuditLogModelDao> auditLogsForAccountRecordId = auditSqlDao.getAuditLogsForAccountRecordId(context); final Iterator<AuditLog> allAuditLogs = buildAuditLogsFromModelDao(auditLogsForAccountRecordId, context); return new DefaultAccountAuditLogs(accountId, auditLevel, allAuditLogs); }