SlideShare uma empresa Scribd logo
1 de 18
Baixar para ler offline
HIBERNATE
                                       ENVERS


       SOLUÇÃO PARA AUDITORIA DE OBJETOS PERSISTENTES




terça-feira, 21 de fevereiro de 12
AGENDA
• INTRODUÇÃO

• ESTRUTURA

• POR              QUE ARMAZENAR RASTRO ?

• EXEMPLO                            BÁSICO

• NECESSIDADE ATUAL                            (SPO)




terça-feira, 21 de fevereiro de 12
INTRODUÇÃO


    •O           QUE É O ENVERS

    • COMO                           SURGIU

    • COMO                           ELE ESTÁ

    • COMO                           ELE PODE NOS AJUDAR



terça-feira, 21 de fevereiro de 12
POR ARMAZENAR RASTRO?




terça-feira, 21 de fevereiro de 12
O PROBLEMA



    • Armazenar                      log em um ambiente distribuído e centrlizado




terça-feira, 21 de fevereiro de 12
CAUSAS



    • Latência                       extrema na execução de transações.

          • Marshall                  e Unmarshall de objetos




terça-feira, 21 de fevereiro de 12
SOLUÇÕES



    • ????????????????




terça-feira, 21 de fevereiro de 12
O BÁSICO
                                      POREM, FUNCIONAL




terça-feira, 21 de fevereiro de 12
MODELO ESTRUTURAL


                                                     ENVERS



                                     ANNOTATION
                                        @Audited
                                      @RevisionEntity
                                      RevisionListener
terça-feira, 21 de fevereiro de 12
EXEMPLOS




terça-feira, 21 de fevereiro de 12
EXEMPLOS
                                                                                 @Entity
  @Entity                                                                        @RevisionEntity(EnversRevisionListener.class)
  @Table(name = "ecm_address") //renomeado para suportar a mudanca no ER         @Table(name = "ecm_login_rev_entity")
  @AttributeOverride(name = "id", column = @Column(name = "addressId"))          public class LoginRevEntity {
  @Audited                                                                       	
  public class Address extends AbstractEntity {                                  	    @Id
                                                                                 	    @GeneratedValue(strategy = GenerationType.IDENTITY)
  	       private   String rua;                                                  	    @RevisionNumber
  	       private   String bairro;                                               	    private Long id;
  	       private   String CEP;                                                  	
  	       private   String complemento;                                          	    private String usuario;
  	       private   String pontoReferencia;                                      	
  	       private   Boolean entrega;                                             	    @RevisionTimestamp
                                                                                 	    private long timestamp;



      public class EnversRevisionListener implements RevisionListener {

      	    @Override
      	    public void newRevision(Object revisionEntity) {
      	    	    Map<String,Object> session = ActionContext.getContext().getSession();
      	    	
      	    	    if(session != null) {
      	    	    	      ApplicationUserElementSession userSession = (ApplicationUserElementSession) session.get(Constants.APPLICATION_USER_SESSION);
      	    	    	      LoginRevEntity exampleRevEntity = (LoginRevEntity) revisionEntity;
      	    	         exampleRevEntity.setTimestamp(new Date().getTime());
      	    	         if(userSession != null) {
      	    	         	 User userAutenticated = userSession.getUserAutenticate();
      	    	         	 exampleRevEntity.setUsuario(userAutenticated.getLogin());
      	    	         }
      	    	         else {
      	    	         	 exampleRevEntity.setUsuario("new_user");
      	    	         }
      	    	    }
      	    }
      	
      }



terça-feira, 21 de fevereiro de 12
CONSULTAS
                                     CONCEITO DE REVISÕES




terça-feira, 21 de fevereiro de 12
CONSULTAS
    •    Entidades em revisão

    •    Revisões sobre entidades

    •    Elementos inspirados por consultas com estilos Criteria

    •    Impossibilidade de realizar consultas com recursos JPA

          •    Conhecendo o modelo, podemos utilizar SQL para gerar relatórios

   auditReader.createQuery()
    .forRevisionsOfEntity(Person.class, false, true)
    .addProjection(AuditEntity.revisionNumber().count())
    .add(AuditEntity.id().eq(person.getId()))
    .getSingleResult()

terça-feira, 21 de fevereiro de 12
NA
                                     PRÁTICA



terça-feira, 21 de fevereiro de 12
Performance
           DESEMPENHO
        Must be slower than without auditing:
    •    Um INSERT para cada entidade modificada
           1 insert for each modified entity
    •    Um INSERT para cara transação
           1 insert for each transaction

                             MySQL 5.1.30       5000                1000             5000
                               (InnoDB)        inserts          complex inserts     updates


                                Not audited    6.307s                     6.622s    8.487s



                                     Audited   9.807s                     12.758s   11.444s



                                 Difference    x 1.55                     x 1.92    x 1.34

            42                                           www.devoxx.com


terça-feira, 21 de fevereiro de 12                                                            42
COMO FICARIA NO SPO ??
                       - Interface de administração
                         * Propriedades do sistema
                         * Dados de auditoria




terça-feira, 21 de fevereiro de 12
CONCLUSÕES

    • SOLUÇÕES                       DE AUDITORIA EM BASE DE DADOS LOCAIS

          •+          desempenho

          •+          flexibilidade

          •+          controle

          •-       XML/SOAP



terça-feira, 21 de fevereiro de 12
REFERÊNCIAS


    •    JBoss Comunity - Envers Documentation: http://www.jboss.org/envers

    •    Adam Warski Blog - Criador do Envers: http://www.warski.org/blog/

    •    Textos explicativos: www.nelsonalone.com.br




terça-feira, 21 de fevereiro de 12

Mais conteúdo relacionado

Destaque

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Destaque (20)

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 

Envers

  • 1. HIBERNATE ENVERS SOLUÇÃO PARA AUDITORIA DE OBJETOS PERSISTENTES terça-feira, 21 de fevereiro de 12
  • 2. AGENDA • INTRODUÇÃO • ESTRUTURA • POR QUE ARMAZENAR RASTRO ? • EXEMPLO BÁSICO • NECESSIDADE ATUAL (SPO) terça-feira, 21 de fevereiro de 12
  • 3. INTRODUÇÃO •O QUE É O ENVERS • COMO SURGIU • COMO ELE ESTÁ • COMO ELE PODE NOS AJUDAR terça-feira, 21 de fevereiro de 12
  • 4. POR ARMAZENAR RASTRO? terça-feira, 21 de fevereiro de 12
  • 5. O PROBLEMA • Armazenar log em um ambiente distribuído e centrlizado terça-feira, 21 de fevereiro de 12
  • 6. CAUSAS • Latência extrema na execução de transações. • Marshall e Unmarshall de objetos terça-feira, 21 de fevereiro de 12
  • 7. SOLUÇÕES • ???????????????? terça-feira, 21 de fevereiro de 12
  • 8. O BÁSICO POREM, FUNCIONAL terça-feira, 21 de fevereiro de 12
  • 9. MODELO ESTRUTURAL ENVERS ANNOTATION @Audited @RevisionEntity RevisionListener terça-feira, 21 de fevereiro de 12
  • 10. EXEMPLOS terça-feira, 21 de fevereiro de 12
  • 11. EXEMPLOS @Entity @Entity @RevisionEntity(EnversRevisionListener.class) @Table(name = "ecm_address") //renomeado para suportar a mudanca no ER @Table(name = "ecm_login_rev_entity") @AttributeOverride(name = "id", column = @Column(name = "addressId")) public class LoginRevEntity { @Audited public class Address extends AbstractEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private String rua; @RevisionNumber private String bairro; private Long id; private String CEP; private String complemento; private String usuario; private String pontoReferencia; private Boolean entrega; @RevisionTimestamp private long timestamp; public class EnversRevisionListener implements RevisionListener { @Override public void newRevision(Object revisionEntity) { Map<String,Object> session = ActionContext.getContext().getSession(); if(session != null) { ApplicationUserElementSession userSession = (ApplicationUserElementSession) session.get(Constants.APPLICATION_USER_SESSION); LoginRevEntity exampleRevEntity = (LoginRevEntity) revisionEntity; exampleRevEntity.setTimestamp(new Date().getTime()); if(userSession != null) { User userAutenticated = userSession.getUserAutenticate(); exampleRevEntity.setUsuario(userAutenticated.getLogin()); } else { exampleRevEntity.setUsuario("new_user"); } } } } terça-feira, 21 de fevereiro de 12
  • 12. CONSULTAS CONCEITO DE REVISÕES terça-feira, 21 de fevereiro de 12
  • 13. CONSULTAS • Entidades em revisão • Revisões sobre entidades • Elementos inspirados por consultas com estilos Criteria • Impossibilidade de realizar consultas com recursos JPA • Conhecendo o modelo, podemos utilizar SQL para gerar relatórios auditReader.createQuery() .forRevisionsOfEntity(Person.class, false, true) .addProjection(AuditEntity.revisionNumber().count()) .add(AuditEntity.id().eq(person.getId())) .getSingleResult() terça-feira, 21 de fevereiro de 12
  • 14. NA PRÁTICA terça-feira, 21 de fevereiro de 12
  • 15. Performance DESEMPENHO Must be slower than without auditing: • Um INSERT para cada entidade modificada 1 insert for each modified entity • Um INSERT para cara transação 1 insert for each transaction MySQL 5.1.30 5000 1000 5000 (InnoDB) inserts complex inserts updates Not audited 6.307s 6.622s 8.487s Audited 9.807s 12.758s 11.444s Difference x 1.55 x 1.92 x 1.34 42 www.devoxx.com terça-feira, 21 de fevereiro de 12 42
  • 16. COMO FICARIA NO SPO ?? - Interface de administração * Propriedades do sistema * Dados de auditoria terça-feira, 21 de fevereiro de 12
  • 17. CONCLUSÕES • SOLUÇÕES DE AUDITORIA EM BASE DE DADOS LOCAIS •+ desempenho •+ flexibilidade •+ controle •- XML/SOAP terça-feira, 21 de fevereiro de 12
  • 18. REFERÊNCIAS • JBoss Comunity - Envers Documentation: http://www.jboss.org/envers • Adam Warski Blog - Criador do Envers: http://www.warski.org/blog/ • Textos explicativos: www.nelsonalone.com.br terça-feira, 21 de fevereiro de 12