@Inject public AuditLogViaHistoryCacheLoader(@Named(MAIN_RO_IDBI_NAMED) final IDBI roDbi) { super(); this.roAuditSqlDao = roDbi.onDemand(AuditSqlDao.class); }
@Test(groups = "slow") public void testInheritQueries() throws Exception { final KombuchaSqlDao dao = dbi.onDemand(KombuchaSqlDao.class); // Verify non inherited template Assert.assertTrue(dao.isItTimeForKombucha()); // Verify inherited templates Assert.assertFalse(dao.getAll(internalCallContext).hasNext()); } }
@Test(groups = "slow", description = "Test Pagination: basic SqlDAO and DAO calls") public void testTagDefinitionsPagination() throws Exception { final TagDefinitionSqlDao tagDefinitionSqlDao = dbi.onDemand(TagDefinitionSqlDao.class);
dbi.onDemand(BundleSqlDao.class).renameBundleExternalKey(externalKey, "foo", internalCallContext); final List<SubscriptionBaseBundle> result4 = dao.getSubscriptionBundlesForKey(externalKey, internalCallContext); assertEquals(result4.size(), 2);
@Test(groups = "slow", description = "Test Account creation with same External Key in different tenants") public void testCreateAccountWithSameExternalKeyInDifferentTenants() throws Exception { final AccountData accountData = createAccountData(); final Account account1 = accountUserApi.createAccount(accountData, callContext); try { // Same tenant accountUserApi.createAccount(accountData, callContext); Assert.fail(); } catch (final AccountApiException e) { assertEquals(e.getCode(), ErrorCode.ACCOUNT_ALREADY_EXISTS.getCode()); } final TenantSqlDao tenantSqlDao = dbi.onDemand(TenantSqlDao.class); final TenantModelDao tenant2 = new TenantModelDao(); tenantSqlDao.create(tenant2, internalCallContext); final CallContext callContext2 = new DefaultCallContext(account1.getId(), tenant2.getId(), callContext.getUserName(), callContext.getCallOrigin(), callContext.getUserType(), callContext.getUserToken(), clock); final Account account2 = accountUserApi.createAccount(accountData, callContext2); Assert.assertEquals(account1.getExternalKey(), account2.getExternalKey()); Assert.assertNotEquals(account1.getId(), account2.getId()); } }
@Override public T get() { return (T) dbi.onDemand(clazz); } }
@Inject public AuditLogViaHistoryCacheLoader(@Named(MAIN_RO_IDBI_NAMED) final IDBI roDbi) { super(); this.roAuditSqlDao = roDbi.onDemand(AuditSqlDao.class); }
@Inject public DefaultAuditDao(final IDBI dbi, final Clock clock, final CacheControllerDispatcher cacheControllerDispatcher, final NonEntityDao nonEntityDao) { this.nonEntitySqlDao = dbi.onDemand(NonEntitySqlDao.class); this.transactionalSqlDao = new EntitySqlDaoTransactionalJdbiWrapper(dbi, clock, cacheControllerDispatcher, nonEntityDao); }
@Inject public TimelineAggregator(final IDBI dbi, final TimelineDao timelineDao, final TimelineCoder timelineCoder, final SampleCoder sampleCoder, final MeterConfig config, final InternalCallContextFactory internalCallContextFactory) { this.dbi = dbi; this.timelineDao = timelineDao; this.timelineCoder = timelineCoder; this.sampleCoder = sampleCoder; this.config = config; this.aggregatorSqlDao = dbi.onDemand(TimelineAggregatorSqlDao.class); this.timelineChunkMapper = new TimelineChunkMapper(); this.internalCallContextFactory = internalCallContextFactory; }
@Override public <SqlObjectType> SqlObjectType onDemand(final Class<SqlObjectType> sqlObjectType) { if (delegate == null) { throw new IllegalStateException("No delegate has been set!"); } return wrapping ? SqlObjectBuilder.onDemand(this, sqlObjectType) : delegate.onDemand(sqlObjectType); }
@Inject public JDBCSessionDao(final IDBI dbi) { if (dbi instanceof DBI) { // TODO PIERRE Move to DBIProvider, once it's in util ((DBI) dbi).registerMapper(new LowerToCamelBeanMapperFactory(SessionModelDao.class)); } this.jdbcSessionSqlDao = dbi.onDemand(JDBCSessionSqlDao.class); }
/** * @param entitySqlDaoTransactionWrapper transaction to execute * @param <ReturnType> object type to return from the transaction * @return result from the transaction fo type ReturnType */ public <ReturnType> ReturnType execute(final EntitySqlDaoTransactionWrapper<ReturnType> entitySqlDaoTransactionWrapper) { final EntitySqlDao<EntityModelDao<Entity>, Entity> entitySqlDao = dbi.onDemand(InitialEntitySqlDao.class); return entitySqlDao.inTransaction(TransactionIsolationLevel.READ_COMMITTED, new JdbiTransaction<ReturnType, EntityModelDao<Entity>, Entity>(entitySqlDaoTransactionWrapper)); }
private long createTable(String name) { return dbi.onDemand(MetadataDao.class).insertTable("test", name, false, false, null, 0); }
@BeforeMethod public void setup() { dbi = new DBI("jdbc:h2:mem:test" + System.nanoTime()); dummyHandle = dbi.open(); dao = dbi.onDemand(TestingShardDao.class); createTablesWithRetry(dbi); }
@BeforeMethod public void setup() { IDBI dbi = new DBI("jdbc:h2:mem:test" + System.nanoTime()); dummyHandle = dbi.open(); dao = dbi.onDemand(MetadataDao.class); createTablesWithRetry(dbi); }
@Test(groups = "slow") public void testInheritQueries() throws Exception { final KombuchaSqlDao dao = dbi.onDemand(KombuchaSqlDao.class); // Verify non inherited template Assert.assertEquals(dao.isIsTimeForKombucha(), clock.getUTCNow().getHourOfDay() == 17); // Verify inherited templates Assert.assertFalse(dao.getAll(internalCallContext).hasNext()); } }