View Javadoc
1   /* 
2   * Copyright (C) 2003-2015 eXo Platform SAS.
3   *
4   * This program is free software: you can redistribute it and/or modify
5   * it under the terms of the GNU Lesser General Public License as published by
6   * the Free Software Foundation, either version 3 of the License, or
7   * (at your option) any later version.
8   *
9   * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this program. If not, see http://www.gnu.org/licenses/ .
16  */
17  package org.exoplatform.commons.search.domain;
18  
19  import org.exoplatform.commons.api.persistence.ExoEntity;
20  
21  import javax.persistence.*;
22  import java.io.Serializable;
23  import java.util.Date;
24  
25  /**
26   * Created by The eXo Platform SAS
27   * Author : Thibault Clement
28   * tclement@exoplatform.com
29   * 7/22/15
30   */
31  @Entity
32  @ExoEntity
33  @Table(name = "ES_INDEXING_QUEUE")
34  @NamedQueries({
35      @NamedQuery(name = "IndexingOperation.deleteAllIndexingOperationsHavingIdLessThanOrEqual",
36          query = "DELETE FROM IndexingOperation q WHERE q.id <= :id"),
37      @NamedQuery(name = "IndexingOperation.deleteAllByEntityType",
38          query = "DELETE FROM IndexingOperation q WHERE q.entityType = :entityType"),
39      @NamedQuery(name = "IndexingOperation.findAll",
40          query = "SELECT q FROM IndexingOperation q ORDER BY q.id")
41  })
42  public class IndexingOperation implements Serializable {
43  
44    @Id
45    @SequenceGenerator(name="SEQ_ES_INDEXING_QUEUE_ID", sequenceName="SEQ_ES_INDEXING_QUEUE_ID")
46    @GeneratedValue(strategy=GenerationType.AUTO, generator="SEQ_ES_INDEXING_QUEUE_ID")
47    @Column(name = "OPERATION_ID")
48    private Long id;
49  
50    @Column(name = "ENTITY_TYPE")
51    private String entityType;
52  
53    @Column(name = "ENTITY_ID")
54    private String entityId;
55  
56    @Column(name = "OPERATION_TYPE")
57    private String operation;
58  
59    //The timestamp is managed by the DB and cannot be set or get
60    //It's only use for querying timestamp based indexing operations
61    @Temporal(TemporalType.TIMESTAMP)
62    @Column(name = "OPERATION_TIMESTAMP", insertable = false, updatable = false)
63    private Date timestamp;
64  
65    public IndexingOperation() {
66    }
67  
68    public IndexingOperation(String entityId, String entityType, OperationType operation) {
69      this.entityId = entityId;
70      this.entityType = entityType;
71      this.setOperation(operation);
72    }
73  
74    public Long getId() {
75      return id;
76    }
77  
78    public void setId(Long id) {
79      this.id = id;
80    }
81  
82    public String getEntityId() {
83      return entityId;
84    }
85  
86    public void setEntityId(String entityId) {
87      this.entityId = entityId;
88    }
89  
90    public String getEntityType() {
91      return entityType;
92    }
93  
94    public void setEntityType(String entityType) {
95      this.entityType = entityType;
96    }
97  
98    public OperationType getOperation() {
99      return this.operation==null?null:OperationType.getById(this.operation);
100   }
101 
102   public void setOperation(OperationType operation) {
103     this.operation = operation==null?null:operation.getOperationId();
104   }
105 
106   @Override
107   public boolean equals(Object o) {
108     if (this == o) return true;
109     if (o == null || getClass() != o.getClass()) return false;
110 
111     IndexingOperation that = (IndexingOperation) o;
112 
113     if (entityId != null ? !entityId.equals(that.entityId) : that.entityId != null) return false;
114     if (entityType != null ? !entityType.equals(that.entityType) : that.entityType != null) return false;
115     if (id != null ? !id.equals(that.id) : that.id != null) return false;
116     if (operation != null ? !operation.equals(that.operation) : that.operation != null) return false;
117 
118     return true;
119   }
120 
121   @Override
122   public int hashCode() {
123     int result = id != null ? id.hashCode() : 0;
124     result = 31 * result + (entityType != null ? entityType.hashCode() : 0);
125     result = 31 * result + (entityId != null ? entityId.hashCode() : 0);
126     result = 31 * result + (operation != null ? operation.hashCode() : 0);
127     return result;
128   }
129 }
130