All you need to do is instantiate a mapper via the JdbcMapperFactory.
The JdbcMapper should be instantiated only once as it does a lot of reflection work on instantiation.
It is thread-safe and can be called from multiple threads without synchronisation.
you can then get a Stream of MyObject from the ResultSet, the mapping will be done using the ResultSetMetaData.
If you are not happy with the way the mapper get the value from the result set you can provide your own Getter<ResultSet, P> either on the factory attached to the column name or on the builder for a static mapping.
The mapper does not close the result set, it is still your responsibility to close the used resource.
By default, if an exception is thrown during the building of the mapper, the mapping or the for each loop the error is rethrown. It is possible to provide your own handler error that will override that behaviour.
Field Mapping Error
Mapper Builder Error
Row Error Handler
Crud on mapped object
It is now possible to create a Crud object from the metadata in the database.
You will need to provide
the target object type - needs to match the table
the key type - needs to match the primary keys of the table
a connection to the db
the table name the object is mapped too.
It uses the metadata to detect the primary key and generated keys.
it is possible to get a callback with the value of the generated key.
Because there are no available names from the PreparedStatement parameter metadata we can only builder a PreparedStatement mapper manually by adding the column name in order.
The NamedQuery is there to solve that by using named parameter - :name in place of ?. If the ? placeholder is used then it will try to extrapolate the name, that should work fine for inserts and updates. But it’s not guaranteed to work perfectly on a complex select query for which it’s better to use a named parameter.
The QueryPreparer is created from a NamedQuery.
It is important to note that there now type information available when creating the preparer. For most
mapping it is not an issue, but for some like Enum it will matter.
You can specify the type in the mapper factory by adding a SqlTypeColumnProperty