@Override public Argument build(final Class<?> expectedType, final LocalDate value, final StatementContext ctx) { return new LocalDateArgument(value); }
@Override public Argument build(final Class<?> expectedType, final DateTimeZone value, final StatementContext ctx) { return new DateTimeZoneArgument(value); }
@Override public Argument build(final Class<?> expectedType, final DateTime value, final StatementContext ctx) { return new DateTimeArgument(value); }
protected void setDefaultArgumentFactorySet() { argumentFactorySet.add(new UUIDArgumentFactory()); argumentFactorySet.add(new DateTimeZoneArgumentFactory()); argumentFactorySet.add(new DateTimeArgumentFactory()); argumentFactorySet.add(new LocalDateArgumentFactory()); }
@Test(groups = "slow") public void testWithArgument() throws Exception { dbi.registerArgumentFactory(new UUIDArgumentFactory()); final SomethingSqlDao somethingSqlDao = dbi.onDemand(SomethingSqlDao.class); final UUID idPierre = UUID.randomUUID(); somethingSqlDao.create(1, "pierre", idPierre); final UUID idStephane = UUID.randomUUID(); somethingSqlDao.create(2, "stephane", idStephane); final String idStringPierre = somethingSqlDao.getUniqueId(1); Assert.assertEquals(idStringPierre, idPierre.toString()); final String idStringStephane = somethingSqlDao.getUniqueId(2); Assert.assertEquals(idStringStephane, idStephane.toString()); }
@Test(groups = "slow") public void testWithArgument() throws Exception { dbi.registerArgumentFactory(new DateTimeArgumentFactory()); final SomethingSqlDao somethingSqlDao = dbi.onDemand(SomethingSqlDao.class); final DateTime dateTimePierre = new DateTime(2012, 10, 5, 8, 10, DateTimeZone.UTC); somethingSqlDao.create(1, "pierre", dateTimePierre); final DateTime dateTimeStephane = new DateTime(2009, 3, 1, 0, 1, DateTimeZone.UTC); somethingSqlDao.create(2, "stephane", dateTimeStephane); final Timestamp datePierre = somethingSqlDao.getCreatedDt(1); Assert.assertEquals(datePierre.getTime(), dateTimePierre.getMillis()); final Timestamp dateStephane = somethingSqlDao.getCreatedDt(2); Assert.assertEquals(dateStephane.getTime(), dateTimeStephane.getMillis()); }
@Test(groups = "slow") public void testWithArgument() throws Exception { dbi.registerArgumentFactory(new DateTimeZoneArgumentFactory()); final SomethingSqlDao somethingSqlDao = dbi.onDemand(SomethingSqlDao.class); final DateTimeZone dateTimeZonePierre = DateTimeZone.UTC; somethingSqlDao.create(1, "pierre", dateTimeZonePierre); final DateTimeZone dateTimeZoneStephane = DateTimeZone.forID("Europe/London"); somethingSqlDao.create(2, "stephane", dateTimeZoneStephane); final String tzStringPierre = somethingSqlDao.getCreatedTZ(1); Assert.assertEquals(tzStringPierre, dateTimeZonePierre.toString()); final String tzStringStephane = somethingSqlDao.getCreatedTZ(2); Assert.assertEquals(tzStringStephane, dateTimeZoneStephane.toString()); }
@Test(groups = "slow") public void testWithArgument() throws Exception { dbi.registerArgumentFactory(new LocalDateArgumentFactory()); final SomethingSqlDao somethingSqlDao = dbi.onDemand(SomethingSqlDao.class); final LocalDate localDatePierre = new LocalDate(2012, 5, 12); somethingSqlDao.create(1, "pierre", localDatePierre); final LocalDate localDateStephane = new LocalDate(2009, 3, 9); somethingSqlDao.create(2, "stephane", localDateStephane); final String localDateStringPierre = somethingSqlDao.getCreatedDt(1); Assert.assertEquals(localDateStringPierre, localDatePierre.toString()); final String localDateStringStephane = somethingSqlDao.getCreatedDt(2); Assert.assertEquals(localDateStringStephane, localDateStephane.toString()); }
dbi.registerArgumentFactory(new DateTimeArgumentFactory());
final DatabaseFactory factory = new DatabaseFactory(environment); final Database db = factory.build(configuration.getDatabaseConfiguration(), "sqlserver"); db.registerArgumentFactory(new UUIDArgumentFactory());
@Test(groups = "slow") public void testWithArgument() throws Exception { final SomethingSqlDao somethingSqlDao = dbi.onDemand(SomethingSqlDao.class); final Bier bierPierre = Bier.ipa; somethingSqlDao.create(1, "pierre", bierPierre); final Bier bierStephane = Bier.hefeweizen; somethingSqlDao.create(2, "stephane", bierStephane); final String bierStringPierre = somethingSqlDao.getBier(1); Assert.assertEquals(bierStringPierre, bierPierre.toString()); final String bierStringStephane = somethingSqlDao.getBier(2); Assert.assertEquals(bierStringStephane, bierStephane.toString()); }
@Override public Argument build(final Class<?> expectedType, final UUID value, final StatementContext ctx) { return new UUIDArgument(value); }
@BeforeMethod(groups = "slow") public void cleanupDb() throws Exception { cleanupDb("drop table if exists something;\n" + "create table something (id int primary key, name varchar(100), created_dt datetime)"); }
@BeforeMethod(groups = "slow") public void cleanupDb() throws Exception { cleanupDb("drop table if exists something;\n" + "create table something (id int primary key, name varchar(100), created_dt varchar(100))"); }
@BeforeMethod(groups = "slow") public void cleanupDb() throws Exception { cleanupDb("drop table if exists something;\n" + "create table something (id int primary key, name varchar(100), unique_id varchar(100))"); }
@BeforeMethod(groups = "slow") public void cleanupDb() throws Exception { cleanupDb("drop table if exists something;\n" + "create table something (id int primary key, name varchar(100), bier varchar(100))"); }
@BeforeMethod(groups = "slow") public void cleanupDb() throws Exception { cleanupDb("drop table if exists something;\n" + "create table something (id int primary key, name varchar(100), created_tz varchar(100))"); }
@Test(groups = "slow") public void testWithoutArgument() throws IOException { final SomethingSqlDao somethingSqlDao = dbi.onDemand(SomethingSqlDao.class); try { somethingSqlDao.create(1, "pierre", DateTimeZone.UTC); Assert.fail(); } catch (final UnableToExecuteStatementException e) { Assert.assertTrue(e.getCause() instanceof JdbcSQLException); } }
@Test(groups = "slow") public void testWithoutArgument() throws IOException { final SomethingSqlDao somethingSqlDao = dbi.onDemand(SomethingSqlDao.class); try { somethingSqlDao.create(1, "pierre", new DateTime(DateTimeZone.UTC)); Assert.fail(); } catch (final UnableToExecuteStatementException e) { Assert.assertTrue(e.getCause() instanceof JdbcSQLException); } }
@VisibleForTesting public static void setupDBI(final DBI dbi) { dbi.registerArgumentFactory(new UUIDArgumentFactory()); dbi.registerArgumentFactory(new DateTimeZoneArgumentFactory()); dbi.registerArgumentFactory(new DateTimeArgumentFactory()); dbi.registerArgumentFactory(new LocalDateArgumentFactory()); dbi.registerMapper(new UUIDMapper()); dbi.registerMapper(new LowerToCamelBeanMapperFactory(BusEventModelDao.class)); dbi.registerMapper(new LowerToCamelBeanMapperFactory(NotificationEventModelDao.class)); }