Search in sources :

Example 31 with DbObject

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

the class SqlParameterSourceTest method getDbObject.

protected DbObject getDbObject() {
    DbObject dbObject = new DbObject();
    dbObject.setId(12345);
    dbObject.setName("name");
    dbObject.setEmail("email");
    return dbObject;
}
Also used : DbObject(org.simpleflatmapper.test.beans.DbObject)

Example 32 with DbObject

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

the class SqlParameterSourceTest method testMapping.

protected void testMapping(SqlParameterSourceFactory<DbObject> sqlParameterSourceFactory) {
    DbObject dbObject = getDbObject();
    SqlParameterSource parameterSource = sqlParameterSourceFactory.newSqlParameterSource(dbObject);
    assertEquals(12345l, parameterSource.getValue("id"));
    assertEquals("name", parameterSource.getValue("name"));
    assertEquals("email", parameterSource.getValue("email"));
    assertEquals(Types.BIGINT, parameterSource.getSqlType("id"));
    assertEquals(Types.VARCHAR, parameterSource.getSqlType("name"));
    assertEquals(null, parameterSource.getTypeName("id"));
    assertEquals(null, parameterSource.getTypeName("name"));
}
Also used : SqlParameterSource(org.springframework.jdbc.core.namedparam.SqlParameterSource) DbObject(org.simpleflatmapper.test.beans.DbObject)

Example 33 with DbObject

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

the class JooqMapperTest method testCacheMapper.

@Test
@SuppressWarnings("unchecked")
public void testCacheMapper() {
    SfmRecordMapperProvider recordMapperProvider = new SfmRecordMapperProvider();
    RecordType rt = mock(RecordType.class);
    Field field1 = mock(Field.class);
    when(field1.getName()).thenReturn("id");
    when(field1.getType()).thenReturn(long.class);
    when(rt.size()).thenReturn(1);
    when(rt.fields()).thenReturn(new Field[] { field1 });
    JooqRecordMapperWrapper provider1 = (JooqRecordMapperWrapper) recordMapperProvider.<Record, DbObject>provide(rt, DbObject.class);
    JooqRecordMapperWrapper provider2 = (JooqRecordMapperWrapper) recordMapperProvider.<Record, DbObject>provide(rt, DbObject.class);
    assertSame(provider1.getMapper(), provider2.getMapper());
}
Also used : JooqRecordMapperWrapper(org.simpleflatmapper.jooq.JooqRecordMapperWrapper) DbObject(org.simpleflatmapper.test.beans.DbObject) SfmRecordMapperProvider(org.simpleflatmapper.jooq.SfmRecordMapperProvider) Test(org.junit.Test)

Example 34 with DbObject

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

the class JooqMapperTest method testMapperDbObject.

@Test
public void testMapperDbObject() throws Exception {
    Connection conn = DbHelper.objectDb();
    DSLContext dsl = DSL.using(new DefaultConfiguration().set(conn).set(SQLDialect.HSQLDB).set(new SfmRecordMapperProvider()));
    List<DbObject> list = dsl.select().from("TEST_DB_OBJECT").fetchInto(DbObject.class);
    assertEquals(2, list.size());
    DbHelper.assertDbObjectMapping(list.get(0));
}
Also used : DbObject(org.simpleflatmapper.test.beans.DbObject) SfmRecordMapperProvider(org.simpleflatmapper.jooq.SfmRecordMapperProvider) Connection(java.sql.Connection) DefaultConfiguration(org.jooq.impl.DefaultConfiguration) Test(org.junit.Test)

Example 35 with DbObject

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

the class JooqMapperTest method testIgnoreFields.

@Test
public void testIgnoreFields() throws Exception {
    Connection conn = DbHelper.objectDb();
    DSLContext dsl = DSL.using(new DefaultConfiguration().set(conn).set(SQLDialect.HSQLDB).set(SfmRecordMapperProviderFactory.newInstance().addAlias("id", "noId").ignorePropertyNotFound().newProvider()));
    List<DbObject> list = dsl.select().from("TEST_DB_OBJECT").fetchInto(DbObject.class);
    assertEquals(2, list.size());
    assertEquals(0, list.get(0).getId());
    list.get(0).setId(1);
    DbHelper.assertDbObjectMapping(list.get(0));
}
Also used : DbObject(org.simpleflatmapper.test.beans.DbObject) Connection(java.sql.Connection) DefaultConfiguration(org.jooq.impl.DefaultConfiguration) 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