Your SlideShare is downloading. ×
0
Envers + Seam + JBoss: Why to use?
Envers + Seam + JBoss: Why to use?
Envers + Seam + JBoss: Why to use?
Envers + Seam + JBoss: Why to use?
Envers + Seam + JBoss: Why to use?
Envers + Seam + JBoss: Why to use?
Envers + Seam + JBoss: Why to use?
Envers + Seam + JBoss: Why to use?
Envers + Seam + JBoss: Why to use?
Envers + Seam + JBoss: Why to use?
Envers + Seam + JBoss: Why to use?
Envers + Seam + JBoss: Why to use?
Envers + Seam + JBoss: Why to use?
Envers + Seam + JBoss: Why to use?
Envers + Seam + JBoss: Why to use?
Envers + Seam + JBoss: Why to use?
Envers + Seam + JBoss: Why to use?
Envers + Seam + JBoss: Why to use?
Envers + Seam + JBoss: Why to use?
Envers + Seam + JBoss: Why to use?
Envers + Seam + JBoss: Why to use?
Envers + Seam + JBoss: Why to use?
Envers + Seam + JBoss: Why to use?
Envers + Seam + JBoss: Why to use?
Envers + Seam + JBoss: Why to use?
Envers + Seam + JBoss: Why to use?
Envers + Seam + JBoss: Why to use?
Envers + Seam + JBoss: Why to use?
Envers + Seam + JBoss: Why to use?
Envers + Seam + JBoss: Why to use?
Envers + Seam + JBoss: Why to use?
Envers + Seam + JBoss: Why to use?
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Envers + Seam + JBoss: Why to use?

775

Published on

My presentation on JUDCon Brazil 2013 - Santo Amaro, SP

My presentation on JUDCon Brazil 2013 - Santo Amaro, SP

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
775
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
12
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Envers + Seam + JBoss: Whyto use?Diogo Souza
  • 2. Envers + Seam + JBoss:Why to use?Better...
  • 3. The handshake
  • 4. Diogo SouzaSystems Analyst at Indra Companyhttp://3adiX.com.brhttp://diogosouza.com.br@diogo_souza_c
  • 5. Ah, the Envers!Once upon a time, in 2009…
  • 6. What they say about…“The Envers project aims to enableeasy auditing/versioning of persistentclasses […]”Ref: http://www.jboss.org/envers
  • 7. What they say about…“[…] All that you have to do isannotate your persistent class orsome of its properties, that you wantto audit, with @Audited. […]”Ref: http://www.jboss.org/envers
  • 8. What they say about…“[…] For each audited entity, a tablewill be created, which will hold thehistory of changes made to theentity. […]”Ref: http://www.jboss.org/envers
  • 9. And the best part…“[…] You can then retrieve and queryhistorical data without much effort.”Ref: http://www.jboss.org/envershttp://www.deviantart.com
  • 10. Some features: Auditing of all mappings defined bythe JPA specification Auditing of some Hibernatemappings, which extend JPA Logging data for each revision usinga "revision entity" Querying historical dataRef: http://www.jboss.org/envershttp://www.deviantart.com
  • 11. BasicallyEach transaction......One revisionINSERTUPDATEDELETE
  • 12. Where to use?Wherever you have Hibernate! Standalone JBoss AS Spring
  • 13. And how do we use in the past?<property name="hibernate.ejb.event.post-insert"value="org.hibernate.ejb.event.EJB3PostInsertEventListener,org.hibernate.envers.event.AuditEventListener" /><property name="hibernate.ejb.event.post-update"value="org.hibernate.ejb.event.EJB3PostUpdateEventListener,org.hibernate.envers.event.AuditEventListener" /><property name="hibernate.ejb.event.post-delete"value="org.hibernate.ejb.event.EJB3PostDeleteEventListener,org.hibernate.envers.event.AuditEventListener" /><property name="hibernate.ejb.event.pre-collection-update"value="org.hibernate.envers.event.AuditEventListener" /><property name="hibernate.ejb.event.pre-collection-remove"value="org.hibernate.envers.event.AuditEventListener" /><property name="hibernate.ejb.event.post-collection-recreate"value="org.hibernate.envers.event.AuditEventListener" />In persistence.xml or hibernate.cfg.xml
  • 14. And how to use?<!-- Add on classpath | Maven --><dependency><groupId>org.hibernate</groupId><artifactId>hibernate-envers</artifactId><version>4.x.Final</version></dependency>Requirements:Hibernate 3+Hibernate annotations
  • 15. Simple sample@Entitypublic class Adress {@Id@GeneratedValueprivate int id;@Auditedprivate String streetName;@Auditedprivate Long zipCode;@Audited@ManyToOneprivate State state;}
  • 16. The whole entity@Auditedpublic class Adress {@Id@GeneratedValueprivate int id;private String streetName;private Long zipCode;@ManyToOneprivate State state;}@Audited // Here too!public class State {@Id@GeneratedValueprivate int id;private String stateName;private Long population;}
  • 17. … without a field@Auditedpublic class Adress {@Id@GeneratedValueprivate int id;@NotAuditedprivate String streetName;private Long zipCode;@ManyToOneprivate State state;}
  • 18. Changing the entity tablename@Audited@AuditTable(“TB_ADRESS_AUDIT”)public class Adress {@Id@GeneratedValueprivate int id;@NotAuditedprivate String streetName;private Long zipCode;@ManyToOneprivate State state;}
  • 19. The database0 ADD1 MOD3 DELThe revisiondate!
  • 20. Querying for entities of aclass at a given revisionAuditQuery query =getAuditReader().createQuery().forEntitiesAtRevision(MyEntity.class,revisionNumber);
  • 21. Querying for revisions, atwhich entities of a given classchangedAuditQuery query =getAuditReader().createQuery().forRevisionsOfEntity(MyEntity.class,false, true);
  • 22. Querying for revisionsbetween revision datesAuditReader auditReader =AuditReaderFactory.get(entityManager);AuditQuery query = auditReader.createQuery().forRevisionsOfEntity(Punishment.class, false, true).add(AuditEntity.revisionProperty("timestamp").gt(timeStamp).lt(otherTimeStamp).add(AuditEntity.revisionType().eq(RevisionType.ADD));List<Object[]> revisions = query.getResultList();
  • 23. Configuration Properties// Prefixes and suffixesorg.hibernate.envers.audit_table_prefixorg.hibernate.envers.audit_table_suffix// Revision number and revision type fieldsorg.hibernate.envers.revision_field_nameorg.hibernate.envers.revision_type_field_name// Default schema usedorg.hibernate.envers.default_schema
  • 24. Demo Time!
  • 25. I am not responsible forany increases in thenumber of Brazilianpunishments...
  • 26. The guy!Adam WarskiRef: http://www.warski.org/blog/about/http://warski.org
  • 27. Good things! Easy! Data as always! Database schemadoesn’t change Minimal code changes Integration withHibernate/Red Hatrelated
  • 28. Not so good things! Dependency ofHibernate. Not compatible withHibernate-XML-Age. Extra table for eachtable.
  • 29. Story Time!
  • 30. References/Links www.jboss.org/envers http://docs.jboss.org/envers/docs/ http://www.warski.org/blog/
  • 31. Thanks! 

×