001package ca.uhn.fhir.jpa.model.entity;
002
003/*-
004 * #%L
005 * HAPI FHIR JPA Model
006 * %%
007 * Copyright (C) 2014 - 2022 Smile CDR, Inc.
008 * %%
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 *
013 *      http://www.apache.org/licenses/LICENSE-2.0
014 *
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 * #L%
021 */
022
023import org.apache.commons.lang3.builder.EqualsBuilder;
024import org.apache.commons.lang3.builder.HashCodeBuilder;
025
026import javax.persistence.Column;
027import javax.persistence.Entity;
028import javax.persistence.GeneratedValue;
029import javax.persistence.GenerationType;
030import javax.persistence.Id;
031import javax.persistence.OneToMany;
032import javax.persistence.SequenceGenerator;
033import javax.persistence.Table;
034import javax.persistence.Temporal;
035import javax.persistence.TemporalType;
036import javax.persistence.UniqueConstraint;
037import javax.persistence.Version;
038import java.util.Date;
039import java.util.List;
040
041@Entity()
042@Table(name = "NPM_PACKAGE", uniqueConstraints = {
043        @UniqueConstraint(name = "IDX_PACK_ID", columnNames = "PACKAGE_ID")
044})
045public class NpmPackageEntity {
046
047        protected static final int PACKAGE_ID_LENGTH = 200;
048
049        @SequenceGenerator(name = "SEQ_NPM_PACK", sequenceName = "SEQ_NPM_PACK")
050        @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_NPM_PACK")
051        @Id
052        @Column(name = "PID")
053        private Long myId;
054        @Column(name = "PACKAGE_ID", length = PACKAGE_ID_LENGTH, nullable = false)
055        private String myPackageId;
056        @Column(name = "CUR_VERSION_ID", length = NpmPackageVersionEntity.VERSION_ID_LENGTH, nullable = true)
057        private String myCurrentVersionId;
058        @Temporal(TemporalType.TIMESTAMP)
059        @Version
060        @Column(name = "UPDATED_TIME", nullable = false)
061        private Date myVersion;
062        @Column(name = "PACKAGE_DESC", length = NpmPackageVersionEntity.VERSION_ID_LENGTH, nullable = true)
063        private String myDescription;
064        @OneToMany(mappedBy = "myPackage")
065        private List<NpmPackageVersionEntity> myVersions;
066
067        public String getDescription() {
068                return myDescription;
069        }
070
071        public void setDescription(String theDescription) {
072                myDescription = theDescription;
073        }
074
075        public String getPackageId() {
076                return myPackageId;
077        }
078
079        public void setPackageId(String thePackageId) {
080                myPackageId = thePackageId;
081        }
082
083        @Override
084        public boolean equals(Object theO) {
085                if (this == theO) {
086                        return true;
087                }
088
089                if (theO == null || getClass() != theO.getClass()) {
090                        return false;
091                }
092
093                NpmPackageEntity that = (NpmPackageEntity) theO;
094
095                return new EqualsBuilder()
096                        .append(myPackageId, that.myPackageId)
097                        .isEquals();
098        }
099
100        @Override
101        public int hashCode() {
102                return new HashCodeBuilder(17, 37)
103                        .append(myPackageId)
104                        .toHashCode();
105        }
106
107        public String getCurrentVersionId() {
108                return myCurrentVersionId;
109        }
110
111        public void setCurrentVersionId(String theCurrentVersionId) {
112                myCurrentVersionId = theCurrentVersionId;
113        }
114}