Search in sources :

Example 81 with DbObject

use of org.simpleflatmapper.test.beans.DbObject in project SimpleFlatMapper by arnaudroger.

the class RowMapperFactoryTest method testMapToDbObject.

@Test
public void testMapToDbObject() throws Exception {
    Jdbi dbi = Jdbi.create(DbHelper.getHsqlDataSource());
    dbi.installPlugins();
    Handle handle = dbi.open();
    try {
        DbObject dbObject = handle.createQuery(DbHelper.TEST_DB_OBJECT_QUERY).mapTo(DbObject.class).findFirst().get();
        DbHelper.assertDbObjectMapping(dbObject);
    } finally {
        handle.close();
    }
}
Also used : Jdbi(org.jdbi.v3.core.Jdbi) DbObject(org.simpleflatmapper.test.beans.DbObject) Handle(org.jdbi.v3.core.Handle) Test(org.junit.Test)

Example 82 with DbObject

use of org.simpleflatmapper.test.beans.DbObject in project SimpleFlatMapper by arnaudroger.

the class SheetMapperBuilderTest method testMapDbObjectFromRow.

@Test
public void testMapDbObjectFromRow() {
    SheetMapperBuilder<DbObject> builder = SheetMapperFactory.newInstance().newBuilder(DbObject.class);
    builder.addMapping("id").addMapping("name").addMapping("email").addMapping("creation_time").addMapping("type_ordinal").addMapping("type_name");
    RowMapper<DbObject> mapper = builder.mapper();
    final DbObject dbObject = mapper.map(row);
    assertEquals(13, dbObject.getId());
    assertEquals("name", dbObject.getName());
    assertEquals("email", dbObject.getEmail());
    assertTrue(Math.abs(now.getTime() - dbObject.getCreationTime().getTime()) < 1000);
    assertEquals(DbObject.Type.type2, dbObject.getTypeOrdinal());
    assertEquals(DbObject.Type.type3, dbObject.getTypeName());
}
Also used : DbObject(org.simpleflatmapper.test.beans.DbObject) Test(org.junit.Test)

Example 83 with DbObject

use of org.simpleflatmapper.test.beans.DbObject in project SimpleFlatMapper by arnaudroger.

the class QueryDSLTest method testMappingProjection.

@Test
public void testMappingProjection() throws Exception {
    Connection conn = DbHelper.objectDb();
    SQLQuery sqlquery = new SQLQuery(conn, new HSQLDBTemplates());
    try {
        List<DbObject> list = sqlquery.from(qTestDbObject).where(qTestDbObject.id.eq(1l)).list(new QueryDslMappingProjection<DbObject>(DbObject.class, qTestDbObject.id, qTestDbObject.name, qTestDbObject.email, qTestDbObject.creationTime, qTestDbObject.typeName, qTestDbObject.typeOrdinal));
        assertEquals(1, list.size());
        DbHelper.assertDbObjectMapping(list.get(0));
    } finally {
        conn.close();
    }
}
Also used : DbObject(org.simpleflatmapper.test.beans.DbObject) Connection(java.sql.Connection) HSQLDBTemplates(com.mysema.query.sql.HSQLDBTemplates) SQLQuery(com.mysema.query.sql.SQLQuery) Test(org.junit.Test)

Aggregations

DbObject (org.simpleflatmapper.test.beans.DbObject)83 Test (org.junit.Test)75 Connection (java.sql.Connection)27 PreparedStatement (java.sql.PreparedStatement)16 ResultSet (java.sql.ResultSet)14 SQLException (java.sql.SQLException)10 CheckedConsumer (org.simpleflatmapper.util.CheckedConsumer)10 ArrayList (java.util.ArrayList)9 MappingException (org.simpleflatmapper.map.MappingException)6 DbFinalObject (org.simpleflatmapper.test.beans.DbFinalObject)6 Type (java.lang.reflect.Type)5 ParseException (java.text.ParseException)5 JdbcMapperFactory (org.simpleflatmapper.jdbc.JdbcMapperFactory)5 StringReader (java.io.StringReader)4 JdbcColumnKey (org.simpleflatmapper.jdbc.JdbcColumnKey)4 DbPartialFinalObject (org.simpleflatmapper.test.beans.DbPartialFinalObject)4 Statement (java.sql.Statement)3 MapperBuilderErrorHandler (org.simpleflatmapper.map.MapperBuilderErrorHandler)3 FieldMapperColumnDefinition (org.simpleflatmapper.map.property.FieldMapperColumnDefinition)3 ListCollector (org.simpleflatmapper.util.ListCollector)3