Skip to content
Arnaud Roger edited this page Jan 7, 2016 · 9 revisions

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.

Crud<DbObject, Long> crud = 
    JdbcMapperFactory
        .newInstance()
        .crud(DbObject.class, Long.class)
        .table(connection, "mytable");

crud.create(connection, object);
crud.read  (connection, object.getId());
crud.update(connection, object);
crud.delete(connection, object.getId());

crud.createOrUpdate(connection, object);

List<DbObject> objects = ...;
List<Long> keys = ...;

crud.create(connection, objects);
crud.read  (connection, keys, new ListCollectorHandler<>()).getList();
crud.update(connection, objects);
crud.delete(connection, keys);

crud.createOrUpdate(connection, objects);

Generated keys

it is possible to get a callback with the value of the generated key.

crud.create(connection, object, (key) -> object.setId(key));

see CrudTest for more samples

Clone this wiki locally