use of org.simpleflatmapper.test.beans.DbObject in project SimpleFlatMapper by arnaudroger.
the class SqlParameterSourceTest method testSource.
@Test
public void testSource() {
SqlParameterSourceFactory<DbObject> parameterSourceFactory = JdbcTemplateMapperFactory.newInstance().newSqlParameterSourceFactory(DbObject.class);
DbObject[] dbObjects = new DbObject[10];
for (int i = 0; i < dbObjects.length; i++) {
dbObjects[i] = new DbObject();
dbObjects[i].setId(i);
}
validate(parameterSourceFactory.newSqlParameterSources(dbObjects));
validate(parameterSourceFactory.newSqlParameterSources(Arrays.asList(dbObjects)));
}
use of org.simpleflatmapper.test.beans.DbObject in project SimpleFlatMapper by arnaudroger.
the class SqlParameterSourceTest method testConstantValue.
@Test
public void testConstantValue() {
SqlParameterSourceFactory<DbObject> parameterSourceFactory = JdbcTemplateMapperFactory.newInstance().addColumnProperty("id", new ConstantValueProperty<Long>(-3l, Long.class)).newSqlParameterSourceFactory(DbObject.class);
SqlParameterSource parameterSource = parameterSourceFactory.newSqlParameterSource(new DbObject());
assertEquals(-3l, parameterSource.getValue("id"));
}
use of org.simpleflatmapper.test.beans.DbObject in project SimpleFlatMapper by arnaudroger.
the class Sql2oIntegrationTest method testSql2O.
@Test
public void testSql2O() throws SQLException, ParseException {
Connection connection = DbHelper.objectDb();
try {
SingleConnectionDataSource scds = new SingleConnectionDataSource(connection, true);
Sql2o sql2o = new Sql2o(scds);
Query query = sql2o.open().createQuery(DbHelper.TEST_DB_OBJECT_QUERY);
query.setAutoDeriveColumnNames(true);
query.setResultSetHandlerFactoryBuilder(new SfmResultSetHandlerFactoryBuilder());
List<DbObject> dbObjects = query.executeAndFetch(DbObject.class);
assertEquals(1, dbObjects.size());
DbHelper.assertDbObjectMapping(dbObjects.get(0));
} finally {
connection.close();
}
}
use of org.simpleflatmapper.test.beans.DbObject in project SimpleFlatMapper by arnaudroger.
the class JdbcTemplateCrudTest method testCrud.
@Test
public void testCrud() throws SQLException {
JdbcTemplateCrud<DbObject, Long> objectCrud = JdbcTemplateMapperFactory.newInstance().<DbObject, Long>crud(DbObject.class, Long.class).to(template, "TEST_DB_OBJECT");
DbObject object = DbObject.newInstance();
assertNull(objectCrud.read(object.getId()));
// create
Long key = objectCrud.create(object, new CheckedConsumer<Long>() {
Long key;
@Override
public void accept(Long aLong) throws Exception {
key = aLong;
}
}).key;
assertNull(key);
key = object.getId();
// read
assertEquals(object, objectCrud.read(key));
object.setName("Udpdated");
// update
objectCrud.update(object);
assertEquals(object, objectCrud.read(key));
// delete
objectCrud.delete(key);
assertNull(objectCrud.read(key));
objectCrud.create(object);
assertEquals(object, objectCrud.read(key));
objectCrud.delete(key);
try {
objectCrud.createOrUpdate(object);
assertEquals(object, objectCrud.read(key));
} catch (UnsupportedOperationException e) {
}
}
use of org.simpleflatmapper.test.beans.DbObject in project SimpleFlatMapper by arnaudroger.
the class JdbcTemplateCrudTest method testWhere.
@Test
public void testWhere() throws SQLException {
JdbcTemplateCrud<DbObject, Long> objectCrud = JdbcTemplateMapperFactory.newInstance().<DbObject, Long>crud(DbObject.class, Long.class).to(template, "TEST_DB_OBJECT");
DbObject object = DbObject.newInstance();
ConnectedSelectQuery<DbObject, String> objectByName = objectCrud.where(" name = :name", String.class);
assertNull(objectByName.readFirst(object.getName()));
objectCrud.create(object);
assertEquals(object, objectByName.readFirst(object.getName()));
assertEquals(Arrays.asList(object), objectByName.read(object.getName(), new ListCollector<DbObject>()).getList());
}
Aggregations