001/*
002 * #%L
003 * HAPI FHIR JPA Server
004 * %%
005 * Copyright (C) 2014 - 2023 Smile CDR, Inc.
006 * %%
007 * Licensed under the Apache License, Version 2.0 (the "License");
008 * you may not use this file except in compliance with the License.
009 * You may obtain a copy of the License at
010 *
011 *      http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 * #L%
019 */
020package ca.uhn.fhir.jpa.entity;
021
022import org.apache.commons.lang3.Validate;
023import org.apache.commons.lang3.builder.ToStringBuilder;
024
025import java.io.Serializable;
026import javax.persistence.*;
027
028@Entity
029@Table(
030                name = "HFJ_SEARCH_RESULT",
031                uniqueConstraints = {
032                        @UniqueConstraint(
033                                        name = "IDX_SEARCHRES_ORDER",
034                                        columnNames = {"SEARCH_PID", "SEARCH_ORDER"})
035                })
036public class SearchResult implements Serializable {
037
038        private static final long serialVersionUID = 1L;
039
040        @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_SEARCH_RES")
041        @SequenceGenerator(name = "SEQ_SEARCH_RES", sequenceName = "SEQ_SEARCH_RES")
042        @Id
043        @Column(name = "PID")
044        private Long myId;
045
046        @Column(name = "SEARCH_ORDER", nullable = false, insertable = true, updatable = false)
047        private int myOrder;
048
049        @Column(name = "RESOURCE_PID", insertable = true, updatable = false, nullable = false)
050        private Long myResourcePid;
051
052        @Column(name = "SEARCH_PID", insertable = true, updatable = false, nullable = false)
053        private Long mySearchPid;
054
055        /**
056         * Constructor
057         */
058        public SearchResult() {
059                // nothing
060        }
061
062        /**
063         * Constructor
064         */
065        public SearchResult(Search theSearch) {
066                Validate.notNull(theSearch.getId());
067                mySearchPid = theSearch.getId();
068        }
069
070        @Override
071        public String toString() {
072                return new ToStringBuilder(this)
073                                .append("search", mySearchPid)
074                                .append("order", myOrder)
075                                .append("resourcePid", myResourcePid)
076                                .toString();
077        }
078
079        @Override
080        public boolean equals(Object theObj) {
081                if (!(theObj instanceof SearchResult)) {
082                        return false;
083                }
084                return myResourcePid.equals(((SearchResult) theObj).myResourcePid);
085        }
086
087        public int getOrder() {
088                return myOrder;
089        }
090
091        public void setOrder(int theOrder) {
092                myOrder = theOrder;
093        }
094
095        public Long getResourcePid() {
096                return myResourcePid;
097        }
098
099        public SearchResult setResourcePid(Long theResourcePid) {
100                myResourcePid = theResourcePid;
101                return this;
102        }
103
104        @Override
105        public int hashCode() {
106                return myResourcePid.hashCode();
107        }
108}