Simple Flat Mapper (SFM) v1.5.0
The maven groupId has changed to org.simpleflatmapper
SFM provides fast and easy to use mapper for
It also provides one of the fastest csv parser available See CsvParserComparaison fork.
The API is lambda friendly and the java 8 jars expose the mapped in form of Stream.
SFM focuses on simplicity of use and performance. Current ORM Mapping solution are intrusive and/or quite slow - can easily double your retrieval time in prod like setups, and Hibernate cache won't save you either because it still needs to inflate the object from a tuple.
SFM is a library and does not force a framework on you it plugs on top of jdbc, jooq, java io, spring jdbc.
SFM makes also the assumption that it should be able to figure out the mapping rule without you being explicit about it. Object will most of the time match the structure of a query or a csv. But it still allow you to customized the mapping definition. More details.
SFM also supports Constructor injection and respect the semantic of final fields.
The Jdbc Mapper is the fastest on the market. Adding a maximum of 5% over pure jdbc on a query to a local Mysql. The next fastest would be Roma that add between 10 and 15%. MyBatis and Hibernate adds more that 70% climbing quickly to 150% for bigger queries.
The Csv Mapper is about 30% faster than jackson-csv.
The Jooq integration give you a mapping to object for almost no cost.
The binaries are available in maven central. There is a build for
<dependency>
<groupId>org.simpleflatmapper</groupId>
<artifactId>simpleFlatMapper</artifactId>
<version>1.5.0</version>
</dependency>
<dependency>
<groupId>org.simpleflatmapper</groupId>
<artifactId>simpleFlatMapper</artifactId>
<version>1.5.0</version>
<classifier>jdk17</classifier>
</dependency>
<dependency>
<groupId>org.simpleflatmapper</groupId>
<artifactId>simpleFlatMapper</artifactId>
<version>1.5.0</version>
<classifier>jdk16</classifier>
</dependency>
The mapper are all thread safe, and it is recommended to instantiate one per class to map as most of the work is done on instantiation.
Those samples show how to build a list from the forEach method. These is not the recommended way of processing the stream of data. As much as you can you would need to define your own RowHandler and do the work in there.
public class MyDao {
JdbcMapper<MyObject> mapper = JdbcMapperFactory.newInstance().newMapper(MyObject.class);
public List<MyObject> findAll() throws SQLException {
try (Connection conn = getConnection();
PreparedStatement ps = conn.prepareStatement("select * from my_table");
ResultSet rs = ps.executeQuery();) {
return mapper.stream(rs).collect(Collectors.toList());
}
}
}
CsvParser
.separator('\t')
.mapTo(String.class, Date.class, MyObject.class)
.stream(reader)
.forEach(System.out::println);
The build is using Maven.
git clone https://github.com/arnaudroger/SimpleFlatMapper.git
cd SimpleFlatMapper
mvn install