Generic DAOs With Hades

Post on 24-Jan-2015

3.525 views 3 download

description

Slides from the talk on the open source project Hades - http://hades.synyx.org

Transcript of Generic DAOs With Hades

HadesOliver Gierke - Synyx GmbH & Co. KG

„Simple things should be simple, complex things should be possible.“Alan Kay

www.devoxx.com

Speaker

■ Oliver Gierke - gierke@synyx.de

■ Software Architect @ Synyx GmbH & Co. KG

■ JavaEE, Spring (beyond the obvious)

■ Financial industry, automotive

■ Hades project lead

■ olivergierke

Java Persistence API

www.devoxx.com

GenericDao

GenericJpaDao

CRUD

www.devoxx.com

Demo I

Query methods

www.devoxx.com

1. Create interface2. Declare methods3. Tune queries

Derive

User findByUsername( String username);

Named Query

@NamedQuery(name=“User.findByLastname“ query=“...“)

List<User> findByLastname(...);

@Query

@Query(„from User u where ...“)List<User> findByLastname(...);

www.devoxx.com

Demo II

PaginationSorting

@Query(„from User u where u.lastname = ?“)Page<User> findByLastname( String lastname, Pageable pageable);

@Param(„name“)

@Query(„from User u where u.lastname = :lastname or u.firstname = :firstname“)

List<User> findByLastOrFirstname(@Param(„lastname“) String lname,@Param(„firstname“) String fname)

@Modifying

@Modifying@Query(„...“)int undefaultAllBut(Role role);

Spring integration

<hades:dao-config base-package=“foo.**.dao“ />

Spring IDE Plugin

Custom DAO code

www.devoxx.com

Demo III

Additionalsupport

Auditing

Created? Modified?Who? When?

Domain base classes

Questions?

WTF

www.devoxx.com

Meta stuff

■ Current version: 1.0 (stable 1.1-snapshot)

■ Apache license 2.0

■ http://hades.synyx.org