33
Reusing existing data layer to persist multi- format data streams

Reusing existing data_layer_to_persist_multi_f

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Reusing existing data_layer_to_persist_multi_f

Reusing existing data layer to persist multi-format data

streams

Page 2: Reusing existing data_layer_to_persist_multi_f

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

Page 3: Reusing existing data_layer_to_persist_multi_f

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

Page 4: Reusing existing data_layer_to_persist_multi_f

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)

Page 5: Reusing existing data_layer_to_persist_multi_f

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

Page 6: Reusing existing data_layer_to_persist_multi_f

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

Page 7: Reusing existing data_layer_to_persist_multi_f

ExamplesData structure:

Page 8: Reusing existing data_layer_to_persist_multi_f

Example: Using custom D.A.O.sOrder entity:

Page 9: Reusing existing data_layer_to_persist_multi_f

Example: Using custom D.A.O.sOrderLine entity:

Page 10: Reusing existing data_layer_to_persist_multi_f

Example: Using custom D.A.O.sProduct entity:

Page 11: Reusing existing data_layer_to_persist_multi_f

Example: Using custom D.A.O.sA DAO to store orders:

Page 12: Reusing existing data_layer_to_persist_multi_f

Example: Using custom D.A.O.sA DAO to locate products:

Page 13: Reusing existing data_layer_to_persist_multi_f

Example: Using custom D.A.O.sSmooks execution:

Page 14: Reusing existing data_layer_to_persist_multi_f

Example: Using custom D.A.O.sSmooks configuration part 1

Page 15: Reusing existing data_layer_to_persist_multi_f

Example: Using custom D.A.O.sSmooks configuration part 2

Page 16: Reusing existing data_layer_to_persist_multi_f

Example: Using JPA / HibernateSame data model and same entities as previous example:

Page 17: Reusing existing data_layer_to_persist_multi_f

Example: Using JPA / Hibernate

Page 18: Reusing existing data_layer_to_persist_multi_f

Example: Using JPA / HibernateProduct entity had an extra Named Query which can be used by the persistence cartridge.

Page 19: Reusing existing data_layer_to_persist_multi_f

Example: Using JPA / HibernateSmooks execution

Page 20: Reusing existing data_layer_to_persist_multi_f

Example: Using JPA / HibernateSmooks configuration part 1

Page 21: Reusing existing data_layer_to_persist_multi_f

Example: Using JPA / HibernateSmooks configuration part 2

Comparison to the previous example with the custom DAO:

Page 22: Reusing existing data_layer_to_persist_multi_f

Example: Using JPA / HibernateUsing a named query

Page 23: Reusing existing data_layer_to_persist_multi_f

Example: Using iBatis (MyBatis)Again the same data:

Page 24: Reusing existing data_layer_to_persist_multi_f

Example: Using iBatis (MyBatis)

Page 25: Reusing existing data_layer_to_persist_multi_f

Example: Using iBatis (MyBatis)iBatis query mapping configuration file

Page 26: Reusing existing data_layer_to_persist_multi_f

Example: Using iBatis (MyBatis)Smooks execution

Page 27: Reusing existing data_layer_to_persist_multi_f

Example: Using iBatis (MyBatis)Smooks config part 1

Page 28: Reusing existing data_layer_to_persist_multi_f

Example: Using iBatis (MyBatis)Smooks config part 2

Page 29: Reusing existing data_layer_to_persist_multi_f

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.

Page 30: Reusing existing data_layer_to_persist_multi_f

Scribe feature details• DAO methods that require a query string are supported

via the @LookupByQuery annotation.

Page 31: Reusing existing data_layer_to_persist_multi_f

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.

Page 32: Reusing existing data_layer_to_persist_multi_f

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.

Page 33: Reusing existing data_layer_to_persist_multi_f

Q / A