daily pastebin goal
68%
SHARE
TWEET

Untitled

a guest Mar 24th, 2019 426 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package org.codingisthinking.eventstore.hibernate;
  2.  
  3. import javax.persistence.*;
  4. import java.sql.Timestamp;
  5. import java.time.Instant;
  6. import java.util.UUID;
  7.  
  8. @Entity
  9. public class EventStore {
  10.     @Id
  11.     protected UUID id;
  12.     protected UUID aggregateId;
  13.     protected String aggregateType;
  14.     protected String payLoad;
  15.     protected int version;
  16.  
  17.     @Basic
  18.     protected Timestamp createdAt;
  19.  
  20.     public EventStore() {
  21.         this.id = UUID.randomUUID();
  22.         this.version = 1;
  23.     }
  24.  
  25.     public EventStore(UUID id, UUID aggregateId, String aggregateType, String payLoad, int version) {
  26.         this.id = id;
  27.         this.aggregateId = aggregateId;
  28.         this.aggregateType = aggregateType;
  29.         this.payLoad = payLoad;
  30.         this.version = version;
  31.     }
  32.  
  33.     public UUID getId() {
  34.         return id;
  35.     }
  36.  
  37.     public UUID getAggregateId() {
  38.         return aggregateId;
  39.     }
  40.  
  41.     public String getAggregateType() {
  42.         return aggregateType;
  43.     }
  44.  
  45.     public String getPayLoad() {
  46.         return payLoad;
  47.     }
  48.  
  49.     public String getCreatedAt() {
  50.         if (createdAt != null) {
  51.             return createdAt.toString();
  52.         }
  53.  
  54.         return createdAt.toString();
  55.     }
  56.  
  57.     public int getVersion() {
  58.         return version;
  59.     }
  60.  
  61.     public void setVersion(int version) {
  62.         this.version = version;
  63.     }
  64.  
  65.     @PrePersist
  66.     public void prePersist() {
  67.         this.createdAt = Timestamp.from(Instant.now());
  68.     }
  69. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top