Upload
maurice-zeijen
View
1.279
Download
4
Embed Size (px)
DESCRIPTION
Citation preview
Reusing existing data layer to persist multi-format data
streams
Agenda• Reusing your existing data layer• Persistence cartridge and Scribe• Examples:
o Using custom Data Access Objectso Using JPA / Hibernateo Using iBATIS
• Scribe feature details• Persistence cartridge feature details • Future improvements• Q&A
Reusing your existing data layer• Reuse entity POJO's within Smooks• Persistence logic stays within the data layer
o No code duplicationo Refactoring is easier
Persistence cartridge and ScribeSingle cartridge for multiple persistence solutions:• Custom Data Access Objects (DAOs)• JPA• Hibernate• iBatis (MyBatis)• Any persistence framework, if you write an adapter for it
(which is very easy)
Persistence cartridge and ScribeFramework abstraction via Scribe• Smooks subproject.• Abstracts persistence actions like inserting,
updating, deleting and querying. • Map persistence actions via annotations or by implementing
interfaces
Persistence cartridge and ScribeXML Configuration namespace:http://www.milyn.org/xsd/smooks/persistence-1.2.xsd
Namespace prefix: dao
Smooks visitor resources:• Locator• Inserter• Updater• Deleter• Flusher
ExamplesData structure:
Example: Using custom D.A.O.sOrder entity:
Example: Using custom D.A.O.sOrderLine entity:
Example: Using custom D.A.O.sProduct entity:
Example: Using custom D.A.O.sA DAO to store orders:
Example: Using custom D.A.O.sA DAO to locate products:
Example: Using custom D.A.O.sSmooks execution:
Example: Using custom D.A.O.sSmooks configuration part 1
Example: Using custom D.A.O.sSmooks configuration part 2
Example: Using JPA / HibernateSame data model and same entities as previous example:
Example: Using JPA / Hibernate
Example: Using JPA / HibernateProduct entity had an extra Named Query which can be used by the persistence cartridge.
Example: Using JPA / HibernateSmooks execution
Example: Using JPA / HibernateSmooks configuration part 1
Example: Using JPA / HibernateSmooks configuration part 2
Comparison to the previous example with the custom DAO:
Example: Using JPA / HibernateUsing a named query
Example: Using iBatis (MyBatis)Again the same data:
Example: Using iBatis (MyBatis)
Example: Using iBatis (MyBatis)iBatis query mapping configuration file
Example: Using iBatis (MyBatis)Smooks execution
Example: Using iBatis (MyBatis)Smooks config part 1
Example: Using iBatis (MyBatis)Smooks config part 2
Scribe feature details• Lookup parameters can be in a map (named) or in a
array (by position).• Multiple insert, update, delete, flush and lookup
methods possible per DAO. Each is named, by default with the method name.
• Multipe DAO Registers can be used in one Smooks instance. e.g. Combining Hibernate with DAOs. DAO name: {repo id}.{dao name}
• An insert or update DAO method doesn´t need to return an entity. The method must then be annotated with @ReturnsNoEntity.
Scribe feature details• DAO methods that require a query string are supported
via the @LookupByQuery annotation.
Persistence cartridge feature details• The locator parameter mapping supports:
o Value mappingo Wire mapping (mapping objects in the bean context)o Expression mapping
• When the locator has no result then an exception can be thrown or the value in the bean context can be nullified. See onNoResult attribute.
• The locator can force unique results.• The entity object resulting from an insert, update or delete
can be stored under a different bean context id.
Future improvements• Write decent documentation!!!• Creating a Injection cartridge
A Smooks Injection cartridge should make it possible to create a DaoRegister from within the Smooks configuration.
• Create a Transaction cartridgeShould make it possible to completely handle transactions within the Smooks configuration.
• Provider XML configuration next to annotations • Replace reflection with runtime code generation.
Q / A