Search in sources :

Example 6 with TypeReference

use of org.simpleflatmapper.util.TypeReference in project SimpleFlatMapper by arnaudroger.

the class Issue486Test method testIssue.

// IFJAVA8_START
@Test
public void testIssue() throws SQLException {
    JdbcMapperBuilder<Issue486> builder = JdbcMapperFactory.newInstance().newBuilder(new TypeReference<Issue486>() {
    }.getType());
    JdbcMapper<Issue486> mapper = builder.addMapping("t", 1, Types.TIMESTAMP).mapper();
    Connection dbConnection = DbHelper.getDbConnection(DbHelper.TargetDB.POSTGRESQL);
    if (dbConnection == null)
        return;
    try {
        ResultSet rs = dbConnection.createStatement().executeQuery("SELECT CURRENT_TIMESTAMP");
        rs.next();
        Issue486 issue486 = mapper.map(rs);
        System.out.println("issue486 = " + issue486.t.get());
    } finally {
        dbConnection.close();
    }
}
Also used : Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) TypeReference(org.simpleflatmapper.util.TypeReference) Test(org.junit.Test)

Example 7 with TypeReference

use of org.simpleflatmapper.util.TypeReference in project SimpleFlatMapper by arnaudroger.

the class Issue486Test method testMIssue.

@Test
public void testMIssue() throws SQLException {
    JdbcMapperBuilder<NIssue486> builder = JdbcMapperFactory.newInstance().newBuilder(new TypeReference<NIssue486>() {
    }.getType());
    JdbcMapper<NIssue486> mapper = builder.addMapping("t", 1, Types.TIMESTAMP).mapper();
    Connection dbConnection = DbHelper.getDbConnection(DbHelper.TargetDB.POSTGRESQL);
    if (dbConnection == null)
        return;
    try {
        ResultSet rs = dbConnection.createStatement().executeQuery("SELECT CURRENT_TIMESTAMP");
        rs.next();
        NIssue486 issue486 = mapper.map(rs);
        System.out.println("issue486 = " + issue486.t);
    } finally {
        dbConnection.close();
    }
}
Also used : Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) TypeReference(org.simpleflatmapper.util.TypeReference) Test(org.junit.Test)

Example 8 with TypeReference

use of org.simpleflatmapper.util.TypeReference in project SimpleFlatMapper by arnaudroger.

the class JoolTupleTest method testMetaDataOnJoolTuple.

@Test
public void testMetaDataOnJoolTuple() throws Exception {
    // creates a new tuple allocated on the JVM heap
    System.out.println("super " + Tuple3.class.toString());
    for (Class<?> clazz : Tuple3.class.getInterfaces()) {
        System.out.println("I " + clazz.toString());
    }
    ClassMeta<Tuple3<Long, Integer, Short>> cm = ReflectionService.newInstance().getClassMeta(new TypeReference<Tuple3<Long, Integer, Short>>() {
    }.getType());
    final PropertyFinder<Tuple3<Long, Integer, Short>> propertyFinder = cm.newPropertyFinder(isValidPropertyMeta);
    final PropertyMeta<Tuple3<Long, Integer, Short>, Long> fieldA = propertyFinder.findProperty(new DefaultPropertyNameMatcher("elt0", 0, true, true), new Object[0]);
    final PropertyMeta<Tuple3<Long, Integer, Short>, Integer> fieldB = propertyFinder.findProperty(new DefaultPropertyNameMatcher("elt1", 0, true, true), new Object[0]);
    final PropertyMeta<Tuple3<Long, Integer, Short>, Short> fieldC = propertyFinder.findProperty(new DefaultPropertyNameMatcher("elt2", 0, true, true), new Object[0]);
    final PropertyMeta<Tuple3<Long, Integer, Short>, ?> fieldD = propertyFinder.findProperty(new DefaultPropertyNameMatcher("elt3", 0, true, true), new Object[0]);
    assertNotNull(fieldA);
    assertNotNull(fieldB);
    assertNotNull(fieldC);
    assertNull(fieldD);
    Tuple3<Long, Integer, Short> tuple = new Tuple3<Long, Integer, Short>(6l, 7, (short) 3);
    assertTrue(fieldA instanceof ConstructorPropertyMeta);
    assertTrue(fieldB instanceof ConstructorPropertyMeta);
    assertTrue(fieldC instanceof ConstructorPropertyMeta);
    Assert.assertEquals(6l, fieldA.getGetter().get(tuple).longValue());
    Assert.assertEquals(7, fieldB.getGetter().get(tuple).intValue());
    Assert.assertEquals(3, fieldC.getGetter().get(tuple).shortValue());
}
Also used : DefaultPropertyNameMatcher(org.simpleflatmapper.reflect.meta.DefaultPropertyNameMatcher) Tuple3(org.jooq.lambda.tuple.Tuple3) TypeReference(org.simpleflatmapper.util.TypeReference) ConstructorPropertyMeta(org.simpleflatmapper.reflect.meta.ConstructorPropertyMeta) Test(org.junit.Test)

Example 9 with TypeReference

use of org.simpleflatmapper.util.TypeReference in project SimpleFlatMapper by arnaudroger.

the class CsvWriterTest method testListOnSpecifiedColumn.

@Test
public void testListOnSpecifiedColumn() throws Exception {
    StringWriter sw = new StringWriter();
    CsvWriter.from(new TypeReference<List<String>>() {
    }).columns("etl0", "elt1", "elt2").to(sw).append(Arrays.asList("e11", "e12"));
    assertEquals("etl0,elt1,elt2\r\ne11,e12,\r\n", sw.toString());
}
Also used : StringWriter(java.io.StringWriter) TypeReference(org.simpleflatmapper.util.TypeReference) Test(org.junit.Test)

Example 10 with TypeReference

use of org.simpleflatmapper.util.TypeReference in project SimpleFlatMapper by arnaudroger.

the class CsvWriterTest method testFailOnListWithDefaultHeader.

@Test
public void testFailOnListWithDefaultHeader() throws Exception {
    try {
        CsvWriter.from(new TypeReference<List<String>>() {
        }).to(new StringWriter());
        fail();
    } catch (IllegalStateException e) {
    // expected
    }
}
Also used : StringWriter(java.io.StringWriter) TypeReference(org.simpleflatmapper.util.TypeReference) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)15 TypeReference (org.simpleflatmapper.util.TypeReference)15 List (java.util.List)5 StringReader (java.io.StringReader)3 DefaultPropertyNameMatcher (org.simpleflatmapper.reflect.meta.DefaultPropertyNameMatcher)3 PropertyMeta (org.simpleflatmapper.reflect.meta.PropertyMeta)3 StringWriter (java.io.StringWriter)2 Type (java.lang.reflect.Type)2 Connection (java.sql.Connection)2 ResultSet (java.sql.ResultSet)2 Tuple3 (org.jooq.lambda.tuple.Tuple3)2 DbObject (org.simpleflatmapper.test.beans.DbObject)2 Tuple3 (org.simpleflatmapper.tuple.Tuple3)2 Predicate (org.simpleflatmapper.util.Predicate)2 GenericArrayType (java.lang.reflect.GenericArrayType)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1