@Override public Long retrieveLastHistoryRecordIdFromTransaction(@Nullable final Long targetRecordId, final TableName tableName, final NonEntitySqlDao transactional) { // There is no caching here because the value returned changes as we add more history records, and so we would need some cache invalidation return transactional.getLastHistoryRecordId(targetRecordId, tableName.getTableName()); }
@Override public Long retrieveHistoryTargetRecordId(@Nullable final Long recordId, final TableName tableName) { return dbRouter.onDemand(true).getHistoryTargetRecordId(recordId, tableName.getTableName()); }
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 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 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); } });
@Override public List<AuditLogWithHistory> inTransaction(final EntitySqlDaoWrapperFactory entitySqlDaoWrapperFactory) throws Exception { final Long targetRecordId = dbRouter.onDemand(true).getRecordIdFromObject(objectId.toString(), tableName.getTableName()); final List<EntityHistoryModelDao> objectHistory = transactional.getHistoryForTargetRecordId(true, targetRecordId, context); return ImmutableList.<AuditLogWithHistory>copyOf(Collections2.transform(entitySqlDaoWrapperFactory.become(EntitySqlDao.class).getAuditLogsViaHistoryForTargetRecordId(historyTableName.name(), historyTableName.getTableName().toLowerCase(), targetRecordId, context), new Function<AuditLogModelDao, AuditLogWithHistory>() { @Override public AuditLogWithHistory apply(final AuditLogModelDao inputAuditLog) { EntityHistoryModelDao historyEntity = null; if (objectHistory != null) { for (final EntityHistoryModelDao history : objectHistory) { if (history.getHistoryRecordId().equals(inputAuditLog.getTargetRecordId())) { historyEntity = history; break; } } } return new DefaultAuditLogWithHistory((historyEntity == null ? null : historyEntity.getEntity()), inputAuditLog, tableName.getObjectType(), objectId); } })); } });
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: // 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);
final String tableName = columnsForTable.get(0).getTableName(); if (TableName.ACCOUNT.getTableName().equals(tableName)) { tableType = TableType.KB_ACCOUNT; } else if (TableName.ACCOUNT_HISTORY.getTableName().equals(tableName)) { tableType = TableType.KB_ACCOUNT_HISTORY;
@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);
final Iterable<RecordIdIdMappings> mappings = nonEntitySqlDao.getHistoryRecordIdIdMappingsForAccountsTable(originalTableNameForHistoryTableName.getTableName(), input.getTableName().getTableName(), tenantContext); historyRecordIdIdsCache.put(originalTableNameForHistoryTableName, RecordIdIdMappings.toMap(mappings)); } else if (TableName.TAG_DEFINITIONS.equals(originalTableNameForHistoryTableName)) { final Iterable<RecordIdIdMappings> mappings = nonEntitySqlDao.getHistoryRecordIdIdMappingsForTablesWithoutAccountRecordId(originalTableNameForHistoryTableName.getTableName(), input.getTableName().getTableName(), tenantContext); historyRecordIdIdsCache.put(originalTableNameForHistoryTableName, RecordIdIdMappings.toMap(mappings)); } else { final Iterable<RecordIdIdMappings> mappings = nonEntitySqlDao.getHistoryRecordIdIdMappings(originalTableNameForHistoryTableName.getTableName(), input.getTableName().getTableName(), tenantContext); historyRecordIdIdsCache.put(originalTableNameForHistoryTableName, RecordIdIdMappings.toMap(mappings)); final Iterable<RecordIdIdMappings> mappings = nonEntitySqlDao.getRecordIdIdMappings(input.getTableName().getTableName(), tenantContext); recordIdIdsCache.put(input.getTableName(), RecordIdIdMappings.toMap(mappings));
@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); }
@Override public DefaultAccountAuditLogsForObjectType getAuditLogsForAccountRecordId(final TableName tableName, final AuditLevel auditLevel, final InternalTenantContext context) { final String actualTableName; if (tableName.hasHistoryTable()) { actualTableName = tableName.getHistoryTableName().name(); // upper cased } else { actualTableName = tableName.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> auditLogsForTableNameAndAccountRecordId = auditSqlDao.getAuditLogsForTableNameAndAccountRecordId(actualTableName, context); final Iterator<AuditLog> allAuditLogs = buildAuditLogsFromModelDao(auditLogsForTableNameAndAccountRecordId, context); return new DefaultAccountAuditLogsForObjectType(auditLevel, allAuditLogs); }
@Override public Long retrieveLastHistoryRecordIdFromTransaction(@Nullable final Long targetRecordId, final TableName tableName, final NonEntitySqlDao transactional) { // There is no caching here because the value returned changes as we add more history records, and so we would need some cache invalidation return transactional.getLastHistoryRecordId(targetRecordId, tableName.getTableName()); }
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 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 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);
@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); }