Search in sources :

Example 36 with DbObject

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

the class SfmBindTest method checkObjectInserted.

public void checkObjectInserted(SfmBindExample attach, Handle handle, DbObject dbObject) {
    DbObject o = attach.selectOne(dbObject.getId());
    assertEquals(dbObject, o);
}
Also used : DbObject(org.simpleflatmapper.test.beans.DbObject)

Example 37 with DbObject

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

the class SettableDataMapperTest method checkObjectInserted.

protected void checkObjectInserted(Session session, int i) {
    if (session == null)
        throw new NullPointerException();
    DbObject object = dbObjects.get(i);
    if (object == null)
        throw new NullPointerException();
    DatastaxMapper<DbObject> dbObjectDatastaxMapper = DatastaxMapperFactory.newInstance().mapTo(DbObject.class);
    PreparedStatement preparedStatement = session.prepare("select * from dbobjects where id = ?");
    if (preparedStatement == null)
        throw new NullPointerException();
    System.out.println("preparedStatement = " + preparedStatement);
    System.out.println("object = " + object);
    System.out.println("object.getId() = " + object.getId());
    try {
        BoundStatement boundStatement = preparedStatement.bind(object.getId());
        ResultSet execute = session.execute(boundStatement);
        DbObject actual = dbObjectDatastaxMapper.iterator(execute).next();
        assertEquals(object, actual);
    } catch (NullPointerException e) {
        e.printStackTrace(System.out);
        throw e;
    }
}
Also used : DbObject(org.simpleflatmapper.test.beans.DbObject)

Example 38 with DbObject

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

the class CsvWriterBuilderTest method testWriteCsvOnDbObject.

@Test
public void testWriteCsvOnDbObject() throws Exception {
    MapperConfig<CsvColumnKey, FieldMapperColumnDefinition<CsvColumnKey>> config = MapperConfig.<CsvColumnKey>fieldMapperConfig();
    CsvWriterBuilder<DbObject> builder = CsvWriterBuilder.newBuilder(DbObject.class);
    Mapper<DbObject, Appendable> mapper = builder.addColumn("id").addColumn("name").addColumn("email").addColumn("creation_time", new DateFormatProperty("dd/MM/yyyy HH:mm:ss")).addColumn("type_ordinal", new EnumOrdinalFormatProperty()).addColumn("type_name").mapper();
    DbObject dbObject = CsvWriterTest.newDbObject();
    assertEquals("13,name,email,06/06/2015 17:46:23,1,type3\r\n", mapper.map(dbObject).toString());
    dbObject.setEmail("email,e\" ");
    assertEquals("13,name,\"email,e\"\" \",06/06/2015 17:46:23,1,type3\r\n", mapper.map(dbObject).toString());
}
Also used : FieldMapperColumnDefinition(org.simpleflatmapper.map.property.FieldMapperColumnDefinition) DbObject(org.simpleflatmapper.test.beans.DbObject) CsvColumnKey(org.simpleflatmapper.csv.CsvColumnKey) EnumOrdinalFormatProperty(org.simpleflatmapper.map.property.EnumOrdinalFormatProperty) DateFormatProperty(org.simpleflatmapper.map.property.DateFormatProperty) Test(org.junit.Test)

Example 39 with DbObject

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

the class CsvWriterTest method newDbObject.

public static DbObject newDbObject() throws ParseException {
    DbObject dbObject = new DbObject();
    dbObject.setId(13);
    dbObject.setEmail("email");
    dbObject.setName("name");
    dbObject.setCreationTime(new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").parse("06/06/2015 17:46:23"));
    dbObject.setTypeOrdinal(DbObject.Type.type2);
    dbObject.setTypeName(DbObject.Type.type3);
    return dbObject;
}
Also used : DbObject(org.simpleflatmapper.test.beans.DbObject) SimpleDateFormat(java.text.SimpleDateFormat)

Example 40 with DbObject

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

the class CsvWriterTest method testWriterWithOneManualColumnWithFormat.

@Test
public void testWriterWithOneManualColumnWithFormat() throws Exception {
    StringWriter sw = new StringWriter();
    final CsvWriter.CsvWriterDSL<DbObject> dbObjectCsvWriterDSL = CsvWriter.from(DbObject.class).skipHeaders();
    final CsvWriter<DbObject> to = dbObjectCsvWriterDSL.column("creation_time", new SimpleDateFormat("yyyyMMdd")).to(sw);
    to.append(newDbObject());
    assertEquals("20150606\r\n", sw.toString());
}
Also used : StringWriter(java.io.StringWriter) CsvWriter(org.simpleflatmapper.csv.CsvWriter) DbObject(org.simpleflatmapper.test.beans.DbObject) SimpleDateFormat(java.text.SimpleDateFormat) 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