arnaudroger / SimpleFlatMapper

Fast and Easy mapping from database and csv to POJO. A java micro ORM, lightweight alternative to iBatis and Hibernate. Fast Csv Parser and Csv Mapper
http://simpleflatmapper.org
MIT License
440 stars 76 forks source link

What are the advantage to use SFM with sql2o? #650

Closed Marco-Sulla closed 5 years ago

Marco-Sulla commented 5 years ago

I read your page about the integration with sql2o, but I didn't understand the advantages.

For what I know sql2o do support inner objects, and I don't understand what you mean with factory and joins.

Can someone explain me?

arnaudroger commented 5 years ago

well there might not be for you but to list a few thing

  1. faster than sql2o mapper https://github.com/arnaudroger/SimpleFlatMapper/wiki/Jdbc-Performance-Local-Mysql
  2. supports http://immutables.github.io/, builder pattern
  3. support inheritance via discriminator https://simpleflatmapper.org/0205-inheritance-discriminator.html
  4. partial support for eclipse collection and google immutable list
  5. can map a X to many to a Foo with a List see for example https://arnaudroger.github.io/blog/2017/06/13/jdbc-template-one-to-many.html

see my comments also on https://github.com/aaberg/sql2o/issues/318 and https://github.com/aaberg/sql2o/issues/188

simpleflatmapper focus mainly on the mapping so that's what it try to be good at.

Marco-Sulla commented 5 years ago
  1. But I simple have to add query.setResultSetHandlerFactoryBuilder(new SfmResultSetHandlerFactoryBuilder()) to have this boost? 1.1 query.setAutoDeriveColumnNames(true) is required? 1.2 can't I set SfmResultSetHandlerFactoryBuilder globally?

  2. what's the advantage over a good old constructor(s)?

  3. cool. Can I set only one discriminator for each JdbcMapper? Or, can I add more than one JdbcMapper to SfmResultSetHandlerFactoryBuilder?

  4. Eclipse Collections seems cool. How can instruct SMF to use them? By default sql2o returns an ArrayList, a lazy ResultSetIterable, or a List<Map<String, Object>>.

  5. I don't like joins. I prefer to get the model Foo with the FooRepository, get List<Bar> with BarRepository and then in service put them togheter in FooAggregator, that contains Foo and List<Bar>. See as an example my code generator for sql2o.

arnaudroger commented 5 years ago

1 - yes not the most convenient to integrate with sql2o, not much I can do... 2 - not my call to make :) 3 - will need to see the use case, I don't personnaly use sql2o 4 - ec is for inside your objects not as the return List from sql2o, it will map to an EC List if the type is an ECList 5 - N+1 ?

arnaudroger commented 5 years ago

on 3 - you can specify multiple inheritance module on the factory, or you can create a mapper factory per class from the api

Marco-Sulla commented 5 years ago

1.1 - AutoDeriveColumnNames could be a problem. Why is required? 5 - ???

arnaudroger commented 5 years ago

currently when AutoDeriveColumnNames is set to false it expect an exact match of the property name and column name. I believe that it was to aligne the behavior to sql2o. it's something that could be changed

Marco-Sulla commented 5 years ago

I created a pull request for setting ResultSetHandlerFactoryBuilder globally.

If it will be not accepted I think we'll never adopt SMF, it's too much an effort to set it for every query :)

arnaudroger commented 5 years ago

@MarcoSulla that's fair enough, I don't really if sql2o is moving much these days though. library should paid for themselves, if there is no strong need to use sfm over the sql2o one the it's fair enough to not use it specially if it's painful to do so

arnaudroger commented 5 years ago

I tend to use jOOQ myself and it's pretty easy to integrate with. have you had a look at jdbi? it's quite active.

Marco-Sulla commented 5 years ago

jOOQ does not use SQL, I prefer to use plain old simple SQL. Furthermore I can't convince my collegues to rewrite all their queries...

I used jdbi, it's more complicated to use and offers no much more functionality than sql2o (or maybe I don't know it well)

Marco-Sulla commented 5 years ago

Excuse me if I bother again, but are you sure that SFM + sql2o is faster than sql2o alone? sql2o uses Unsafe to create and populate models. It seems the faster way to map the model.

I read your benchmarks, but it seems a comparison of DB driver performance, not a comparison with db driver alone and DB driver + SFM.

arnaudroger commented 5 years ago

And generate byte code that will call the constructor with results et call- not directly but c2 should eventually make it equivalent. Using unsafe might or might not be more efficient. Does it have any effect on c2 capacity to do escape analysis? I don’t know. Are the unsafe call in a loop?What happen when unsafe is not there anymore?

My feeling is that the byte code gen would be faster but there is only one way to find out.

Marco-Sulla commented 5 years ago

Well, I have no time to benchmark it. I think you should add some real benchmarks, benchmarks that confront db driver alone and db driver + SMF. And you should use Oracle. There's a free version of it.

arnaudroger commented 5 years ago

some real benchmark? as oppose to the one currently what would you actually do differently? well when I have time and I actually now what you mean, and it's the most important think to do on that project I might. against Oracle probably not....

Marco-Sulla commented 5 years ago

as oppose to the one currently what would you actually do differently?

Well, I'll simply do the same tests, but with and without SMF.

against Oracle probably not....

Why not? I hate Oracle and Oracle DB, but we must admit it's the most performant relational db. If you don't want Oracle, you can use Postgres, but please, not MySQL...