Date post: | 28-May-2015 |
Category: |
Technology |
Upload: | stefan-schmidt |
View: | 2,792 times |
Download: | 2 times |
Chicago, October 19 - 22, 2010
New Persistence Features in Spring Roo 1.1 Stefan Schmidt
Agenda
• Spring Roo’s Approach to Persistence • Incremental Database Reverse Engineering • Apache Solr / Lucene Integration • Alternative Persistence Technologies
Spring Roo’s Approach to Persistence
Peristence Choices
• JPA2 for ORM – 4 choices of ORM providers
• Hibernate • EclipseLink • OpenJPA • DataNucleus (DN1 supported for GAE, DN2 used by VMforce)
• 12+ Database choices – constantly growning list of DBs to choose from – popular ones: MySQL, Postgres, HSQLDB (for dev)
• Switch out ORM and / or DB with a single command – persistence setup --provider HIBERNATE --database MYSQL
No DAOs?
• No DAO layer by default – Objections:
• testing • separation of concern • pluggable implementations • non JPA persistence • security authorizations • security auditing • finders • architectural reasons
Feature Extension Points
• Add-ons can contribute persistence feature extensions via ITDs – Finder add-on is a good example
• Every @RooEntity exposes the JPA entity manager – use for creating custom type-safe queries via Criteria API – getting access to the underlying ORM
Incremental Database Reverse Engineering
Alternatives to Roo’s Incremental DBRE
• Eclipse “JPA Entities from tables” wizard – Generates entities from a JDBC connection – Can be tailored to change generated type and field names – Does not handle tables with no primary keys
• JPA Implementation Tools
Limitations of Existing DBRE Tools
• Lack of incremental reverse engineering • Complex and long-winded wizard style interactions • Missing entity lifecycle management
– Application requires manual adjustment if the datamodel changes
Introducing Roo’s Incremental Database Reverse Engineering
• DBRE was the most requested feature for Spring Roo • Introspect relational databases such as Oracle, MySQL,
PostgreSQL and Microsoft SQL Server • Reverse engineer complex schemas into Java entities in
seconds • Creates and maintains relationships with JPA 2.0
annotations • Incrementally updates your domain model as your DB
schema changes
How does DBRE work?
• Uses the standard java.sql.DatabaseMetaData implementation of your JDK
• Connects to a live database using JDBC and creates entities from the database metadata obtained
• Similar to the output generated by the Eclipse wizard with all accepted defaults
Spring Roo DBRE Commands
• database introspect --schema <name> [--file <name>] – Displays database metadata in XML format in the Roo shell – Optional --file <file name> saves metadata to specified file – Provides a preview of the mappings used in the final model
Spring Roo DBRE Commands
• database reverse engineer [--schema <name>] [--package <name>] – Creates entities in the specified package – --schema and --package options required only for first time
run of command – Automatically generates type and field names from table
and column names – JPA-annotated fields and getters/setters saved in AspectJ
ITDs, eg Person_Roo_DbManaged.aj
Primary Keys
• Supports single and composite primary keys – Creates a separate primary key class for tables having more
than one primary key or no primary key (uses all fields for key)
– Annotates the primary key class with @Embeddable and the entity's id with @EmbeddedId
Entity Relationships
• Automatically creates and maintains bi-directional relationships: – @ManyToMany, many-valued associations with many-to-
many multiplicity – @OneToOne, single-valued associations to other entities
that have one-to-one multiplicity – @OneToMany, many-valued associations with one-to-many
multiplicity – @ManyToOne, single-valued associations to other entities
that have many-to-one multiplicity
DEMO Database Reverse Engineering Demo
Apache Solr / Lucene Integration
What is Apache Solr?
• Search server • Built upon Apache Lucene (Java) • Fast, very • Scalable, query load and collection size • Distributed search and index replication • Interoperable • Extensible
Solr Features
• Powerful full-text search • Hit highlighting • Faceted search • Spell checking • Dynamic clustering • Database integration • Rich document (e.g., Word, PDF) handling.
Interacting with Solr
• HTTP GET / POST • JSON / XML • SolrJ (embedded over HTTP) • Ruby: solr-ruby, RSolr • many others: python, PHP, solrsharp, XSLT • JMX monitoring available • Admin interface available
Configuring Solr
• schema.xml – Defines field types – Can drive more intelligent processing – Dynamic Fields enable on-the-fly addition of new fields – CopyField
• indexing a single field multiple ways • combining multiple fields into a single searchable field
– Many additional text analysis components • word splitting, • regex filters • sounds-like filters
Roo Solr Integration
• Roo Shell – solr setup install SolrJ driver in project pom.xml – solr add make individual type searchable – solr all make all JPA entities searchable
• @RooSolrSearchable type annotation • Hooks into JPA lifecycle
– @PostPersist – @PostUpdate – @PreDelete
• Uses SolrJ client
Entity Methods Introduced via Roo
• QueryResponse search(String queryString) • QueryResponse search(SolrQuery query) • @Async void indexPerson(Person person) • @Async void indexPeople(Collection<Person> people) • @Async deleteIndex(Owner owner) • solrServer is also accessible on target type.
DEMO Apache Solr
Alternative Persistence Technologies
Demand for Choice
• ROO-301: Choose between data access patterns – demand for repository and DAO pattern support
• 70+ votes in Spring Roo Jira, second most popular issue – Spring JDBC template – demand for iBatis support (ROO-452) – demand for NoSQL integration – demand for polyglot persistence
Hades Add-On
• Have you heard of Hades project? – Utility library to work with Data Access Objects
• implemented with Spring and JPA – Main goal is to ease the development and operation of a
data access layer in applications
• Installation in the Roo shell with a single command: – addon install --bundleSymbolicName org.synyx.hades.roo.addon – hades setup – hades repository --entity ~.domain.Person – more features planned (finders, DDD, etc)
DEMO Hades Add-On
Summary
• Roo has deep and rich persistence support • Roo’s Incremental DBRE feature is the next generation in
DBRE capabilities • Solr and Incremental DBRE offer devs a major
productivity boost • Alternative persistence technologies supported and
expanding