2  * ============LICENSE_START=======================================================
 
   3  * feature-session-persistence
 
   4  * ================================================================================
 
   5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 
   6  * ================================================================================
 
   7  * Licensed under the Apache License, Version 2.0 (the "License");
 
   8  * you may not use this file except in compliance with the License.
 
   9  * You may obtain a copy of the License at
 
  11  *      http://www.apache.org/licenses/LICENSE-2.0
 
  13  * Unless required by applicable law or agreed to in writing, software
 
  14  * distributed under the License is distributed on an "AS IS" BASIS,
 
  15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  16  * See the License for the specific language governing permissions and
 
  17  * limitations under the License.
 
  18  * ============LICENSE_END=========================================================
 
  21 package org.onap.policy.drools.persistence;
 
  23 import java.io.Serializable;
 
  24 import java.util.Date;
 
  26 import javax.persistence.Column;
 
  27 import javax.persistence.Entity;
 
  28 import javax.persistence.Id;
 
  29 import javax.persistence.PrePersist;
 
  30 import javax.persistence.PreUpdate;
 
  31 import javax.persistence.Temporal;
 
  32 import javax.persistence.TemporalType;
 
  35 public class DroolsSessionEntity implements Serializable, DroolsSession {
 
  37         private static final long serialVersionUID = -5495057038819948709L;
 
  40         @Column(name="sessionName", nullable=false)
 
  41         private String sessionName = "-1";
 
  43         @Column(name="sessionId", nullable=false)
 
  44         private long sessionId = -1L;
 
  46         @Temporal(TemporalType.TIMESTAMP)
 
  47         @Column(name="createdDate", nullable=false)
 
  48         private Date createdDate;
 
  50         @Temporal(TemporalType.TIMESTAMP)
 
  51         @Column(name="updatedDate", nullable=false)
 
  52         private Date updatedDate;
 
  55         public DroolsSessionEntity() {
 
  59         public DroolsSessionEntity(String sessionName,
 
  61                 this.sessionName = sessionName;
 
  62                 this.sessionId = sessionId;
 
  67         public void     prePersist() {
 
  68                 this.createdDate = new Date();
 
  69                 this.updatedDate = new Date();
 
  73         public void preUpdate() {
 
  74                 this.updatedDate = new Date();
 
  78         public String getSessionName() {
 
  82         public void setSessionName(String sessionName) {
 
  83                 this.sessionName = sessionName;
 
  86         public long getSessionId() {
 
  91         public void setSessionId(long sessionId) {
 
  92                 this.sessionId = sessionId;
 
  96         public Date getCreatedDate() {
 
 101         public void setCreatedDate(Date createdDate) {
 
 102                 this.createdDate = createdDate;
 
 106         public Date getUpdatedDate() {
 
 111         public void setUpdatedDate(Date updatedDate) {
 
 112                 this.updatedDate = updatedDate;
 
 117         public boolean equals(Object other){
 
 118                 if(other instanceof DroolsSession){
 
 119                         DroolsSession p = (DroolsSession) other;
 
 120                         return this.getSessionName().equals(p.getSessionName());
 
 127         public int hashCode() {
 
 128                 final int prime = 31;
 
 130                 result = prime * result + getSessionName().hashCode();
 
 135         public String toString() {
 
 136                 return "{name=" + getSessionName()
 
 137                                 + ", id=" + getSessionId() + "}";