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();
}
}
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();
}
}
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());
}
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());
}
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
}
}
Aggregations