Download - New Persistence Features in Spring Roo 1.1
![Page 1: New Persistence Features in Spring Roo 1.1](https://reader033.vdocuments.site/reader033/viewer/2022052411/55660b5bd8b42aa6628b50ea/html5/thumbnails/1.jpg)
Chicago, October 19 - 22, 2010
New Persistence Features in Spring Roo 1.1 Stefan Schmidt
![Page 2: New Persistence Features in Spring Roo 1.1](https://reader033.vdocuments.site/reader033/viewer/2022052411/55660b5bd8b42aa6628b50ea/html5/thumbnails/2.jpg)
Agenda
• Spring Roo’s Approach to Persistence • Incremental Database Reverse Engineering • Apache Solr / Lucene Integration • Alternative Persistence Technologies
![Page 3: New Persistence Features in Spring Roo 1.1](https://reader033.vdocuments.site/reader033/viewer/2022052411/55660b5bd8b42aa6628b50ea/html5/thumbnails/3.jpg)
Spring Roo’s Approach to Persistence
![Page 4: New Persistence Features in Spring Roo 1.1](https://reader033.vdocuments.site/reader033/viewer/2022052411/55660b5bd8b42aa6628b50ea/html5/thumbnails/4.jpg)
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
![Page 5: New Persistence Features in Spring Roo 1.1](https://reader033.vdocuments.site/reader033/viewer/2022052411/55660b5bd8b42aa6628b50ea/html5/thumbnails/5.jpg)
No DAOs?
• No DAO layer by default – Objections:
• testing • separation of concern • pluggable implementations • non JPA persistence • security authorizations • security auditing • finders • architectural reasons
![Page 6: New Persistence Features in Spring Roo 1.1](https://reader033.vdocuments.site/reader033/viewer/2022052411/55660b5bd8b42aa6628b50ea/html5/thumbnails/6.jpg)
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
![Page 7: New Persistence Features in Spring Roo 1.1](https://reader033.vdocuments.site/reader033/viewer/2022052411/55660b5bd8b42aa6628b50ea/html5/thumbnails/7.jpg)
Incremental Database Reverse Engineering
![Page 8: New Persistence Features in Spring Roo 1.1](https://reader033.vdocuments.site/reader033/viewer/2022052411/55660b5bd8b42aa6628b50ea/html5/thumbnails/8.jpg)
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
![Page 9: New Persistence Features in Spring Roo 1.1](https://reader033.vdocuments.site/reader033/viewer/2022052411/55660b5bd8b42aa6628b50ea/html5/thumbnails/9.jpg)
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
![Page 10: New Persistence Features in Spring Roo 1.1](https://reader033.vdocuments.site/reader033/viewer/2022052411/55660b5bd8b42aa6628b50ea/html5/thumbnails/10.jpg)
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
![Page 11: New Persistence Features in Spring Roo 1.1](https://reader033.vdocuments.site/reader033/viewer/2022052411/55660b5bd8b42aa6628b50ea/html5/thumbnails/11.jpg)
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
![Page 12: New Persistence Features in Spring Roo 1.1](https://reader033.vdocuments.site/reader033/viewer/2022052411/55660b5bd8b42aa6628b50ea/html5/thumbnails/12.jpg)
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
![Page 13: New Persistence Features in Spring Roo 1.1](https://reader033.vdocuments.site/reader033/viewer/2022052411/55660b5bd8b42aa6628b50ea/html5/thumbnails/13.jpg)
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
![Page 14: New Persistence Features in Spring Roo 1.1](https://reader033.vdocuments.site/reader033/viewer/2022052411/55660b5bd8b42aa6628b50ea/html5/thumbnails/14.jpg)
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
![Page 15: New Persistence Features in Spring Roo 1.1](https://reader033.vdocuments.site/reader033/viewer/2022052411/55660b5bd8b42aa6628b50ea/html5/thumbnails/15.jpg)
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
![Page 16: New Persistence Features in Spring Roo 1.1](https://reader033.vdocuments.site/reader033/viewer/2022052411/55660b5bd8b42aa6628b50ea/html5/thumbnails/16.jpg)
DEMO Database Reverse Engineering Demo
![Page 17: New Persistence Features in Spring Roo 1.1](https://reader033.vdocuments.site/reader033/viewer/2022052411/55660b5bd8b42aa6628b50ea/html5/thumbnails/17.jpg)
Apache Solr / Lucene Integration
![Page 18: New Persistence Features in Spring Roo 1.1](https://reader033.vdocuments.site/reader033/viewer/2022052411/55660b5bd8b42aa6628b50ea/html5/thumbnails/18.jpg)
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
![Page 19: New Persistence Features in Spring Roo 1.1](https://reader033.vdocuments.site/reader033/viewer/2022052411/55660b5bd8b42aa6628b50ea/html5/thumbnails/19.jpg)
Solr Features
• Powerful full-text search • Hit highlighting • Faceted search • Spell checking • Dynamic clustering • Database integration • Rich document (e.g., Word, PDF) handling.
![Page 20: New Persistence Features in Spring Roo 1.1](https://reader033.vdocuments.site/reader033/viewer/2022052411/55660b5bd8b42aa6628b50ea/html5/thumbnails/20.jpg)
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
![Page 21: New Persistence Features in Spring Roo 1.1](https://reader033.vdocuments.site/reader033/viewer/2022052411/55660b5bd8b42aa6628b50ea/html5/thumbnails/21.jpg)
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
![Page 22: New Persistence Features in Spring Roo 1.1](https://reader033.vdocuments.site/reader033/viewer/2022052411/55660b5bd8b42aa6628b50ea/html5/thumbnails/22.jpg)
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
![Page 23: New Persistence Features in Spring Roo 1.1](https://reader033.vdocuments.site/reader033/viewer/2022052411/55660b5bd8b42aa6628b50ea/html5/thumbnails/23.jpg)
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.
![Page 24: New Persistence Features in Spring Roo 1.1](https://reader033.vdocuments.site/reader033/viewer/2022052411/55660b5bd8b42aa6628b50ea/html5/thumbnails/24.jpg)
DEMO Apache Solr
![Page 25: New Persistence Features in Spring Roo 1.1](https://reader033.vdocuments.site/reader033/viewer/2022052411/55660b5bd8b42aa6628b50ea/html5/thumbnails/25.jpg)
Alternative Persistence Technologies
![Page 26: New Persistence Features in Spring Roo 1.1](https://reader033.vdocuments.site/reader033/viewer/2022052411/55660b5bd8b42aa6628b50ea/html5/thumbnails/26.jpg)
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
![Page 27: New Persistence Features in Spring Roo 1.1](https://reader033.vdocuments.site/reader033/viewer/2022052411/55660b5bd8b42aa6628b50ea/html5/thumbnails/27.jpg)
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)
![Page 28: New Persistence Features in Spring Roo 1.1](https://reader033.vdocuments.site/reader033/viewer/2022052411/55660b5bd8b42aa6628b50ea/html5/thumbnails/28.jpg)
DEMO Hades Add-On
![Page 29: New Persistence Features in Spring Roo 1.1](https://reader033.vdocuments.site/reader033/viewer/2022052411/55660b5bd8b42aa6628b50ea/html5/thumbnails/29.jpg)
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