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.*;
023import org.apache.commons.lang3.Validate;
024import org.apache.commons.lang3.builder.ToStringBuilder;
025
026import java.io.Serializable;
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        @Deprecated(since = "6.10", forRemoval = true) // migrating to composite PK on searchPid,Order
041        @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_SEARCH_RES")
042        @SequenceGenerator(name = "SEQ_SEARCH_RES", sequenceName = "SEQ_SEARCH_RES")
043        @Id
044        @Column(name = "PID")
045        private Long myId;
046
047        @Column(name = "SEARCH_PID", insertable = true, updatable = false, nullable = false)
048        private Long mySearchPid;
049
050        @Column(name = "SEARCH_ORDER", insertable = true, updatable = false, nullable = false)
051        private int myOrder;
052
053        @Column(name = "RESOURCE_PID", insertable = true, updatable = false, nullable = false)
054        private Long myResourcePid;
055
056        /**
057         * Constructor
058         */
059        public SearchResult() {
060                // nothing
061        }
062
063        /**
064         * Constructor
065         */
066        public SearchResult(Search theSearch) {
067                Validate.notNull(theSearch.getId());
068                mySearchPid = theSearch.getId();
069        }
070
071        @Override
072        public String toString() {
073                return new ToStringBuilder(this)
074                                .append("search", mySearchPid)
075                                .append("order", myOrder)
076                                .append("resourcePid", myResourcePid)
077                                .toString();
078        }
079
080        @Override
081        public boolean equals(Object theObj) {
082                if (!(theObj instanceof SearchResult)) {
083                        return false;
084                }
085                return myResourcePid.equals(((SearchResult) theObj).myResourcePid);
086        }
087
088        public int getOrder() {
089                return myOrder;
090        }
091
092        public void setOrder(int theOrder) {
093                myOrder = theOrder;
094        }
095
096        public Long getResourcePid() {
097                return myResourcePid;
098        }
099
100        public SearchResult setResourcePid(Long theResourcePid) {
101                myResourcePid = theResourcePid;
102                return this;
103        }
104
105        @Override
106        public int hashCode() {
107                return myResourcePid.hashCode();
108        }
109}