001/*
002 * #%L
003 * HAPI FHIR JPA Server
004 * %%
005 * Copyright (C) 2014 - 2024 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 jakarta.persistence.Column;
023import jakarta.persistence.Entity;
024import jakarta.persistence.GeneratedValue;
025import jakarta.persistence.GenerationType;
026import jakarta.persistence.Id;
027import jakarta.persistence.SequenceGenerator;
028import jakarta.persistence.Table;
029import jakarta.persistence.UniqueConstraint;
030import org.apache.commons.lang3.Validate;
031import org.apache.commons.lang3.builder.ToStringBuilder;
032
033import java.io.Serializable;
034
035@Entity
036@Table(
037                name = "HFJ_SEARCH_RESULT",
038                uniqueConstraints = {
039                        @UniqueConstraint(
040                                        name = "IDX_SEARCHRES_ORDER",
041                                        columnNames = {"SEARCH_PID", "SEARCH_ORDER"})
042                })
043public class SearchResult implements Serializable {
044
045        private static final long serialVersionUID = 1L;
046
047        @Deprecated(since = "6.10", forRemoval = true) // migrating to composite PK on searchPid,Order
048        @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_SEARCH_RES")
049        @SequenceGenerator(name = "SEQ_SEARCH_RES", sequenceName = "SEQ_SEARCH_RES")
050        @Id
051        @Column(name = "PID")
052        private Long myId;
053
054        @Column(name = "SEARCH_PID", insertable = true, updatable = false, nullable = false)
055        private Long mySearchPid;
056
057        @Column(name = "SEARCH_ORDER", insertable = true, updatable = false, nullable = false)
058        private int myOrder;
059
060        @Column(name = "RESOURCE_PID", insertable = true, updatable = false, nullable = false)
061        private Long myResourcePid;
062
063        /**
064         * Constructor
065         */
066        public SearchResult() {
067                // nothing
068        }
069
070        /**
071         * Constructor
072         */
073        public SearchResult(Search theSearch) {
074                Validate.notNull(theSearch.getId());
075                mySearchPid = theSearch.getId();
076        }
077
078        @Override
079        public String toString() {
080                return new ToStringBuilder(this)
081                                .append("search", mySearchPid)
082                                .append("order", myOrder)
083                                .append("resourcePid", myResourcePid)
084                                .toString();
085        }
086
087        @Override
088        public boolean equals(Object theObj) {
089                if (!(theObj instanceof SearchResult)) {
090                        return false;
091                }
092                return myResourcePid.equals(((SearchResult) theObj).myResourcePid);
093        }
094
095        public int getOrder() {
096                return myOrder;
097        }
098
099        public void setOrder(int theOrder) {
100                myOrder = theOrder;
101        }
102
103        public Long getResourcePid() {
104                return myResourcePid;
105        }
106
107        public SearchResult setResourcePid(Long theResourcePid) {
108                myResourcePid = theResourcePid;
109                return this;
110        }
111
112        @Override
113        public int hashCode() {
114                return myResourcePid.hashCode();
115        }
116}