View Javadoc
1   /*
2    * This file is part of ***  M y C o R e  ***
3    * See http://www.mycore.de/ for details.
4    *
5    * MyCoRe is free software: you can redistribute it and/or modify
6    * it under the terms of the GNU General Public License as published by
7    * the Free Software Foundation, either version 3 of the License, or
8    * (at your option) any later version.
9    *
10   * MyCoRe is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License
16   * along with MyCoRe.  If not, see <http://www.gnu.org/licenses/>.
17   */
18  
19  package org.mycore.backend.jpa.links;
20  
21  import jakarta.persistence.Basic;
22  import jakarta.persistence.Column;
23  import jakarta.persistence.EmbeddedId;
24  import jakarta.persistence.Entity;
25  import jakarta.persistence.Index;
26  import jakarta.persistence.NamedQueries;
27  import jakarta.persistence.NamedQuery;
28  import jakarta.persistence.Table;
29  import jakarta.persistence.Transient;
30  
31  /**
32   * This class implement the data sructure of the MCRLinkHref table.
33   *
34   * @author Heiko Helmbrecht
35   * @author Jens Kupferschmidt
36   * @version $Revision$ $Date$
37   */
38  @Entity
39  @Table(indexes = {
40      @Index(name = "LinkFrom", columnList = "MCRFROM, MCRTYPE"),
41      @Index(name = "LinkTo", columnList = "MCRTO, MCRTYPE"),
42  })
43  @NamedQueries({
44      @NamedQuery(name = "MCRLINKHREF.getDestinations",
45          query = "SELECT key.mcrto FROM MCRLINKHREF WHERE key.mcrfrom=:from"),
46      @NamedQuery(name = "MCRLINKHREF.getDestinationsWithType",
47          query = "SELECT key.mcrto FROM MCRLINKHREF WHERE key.mcrfrom=:from AND key.mcrtype=:type"),
48      @NamedQuery(name = "MCRLINKHREF.getSources", query = "SELECT key.mcrfrom FROM MCRLINKHREF WHERE key.mcrto=:to"),
49      @NamedQuery(name = "MCRLINKHREF.getSourcesWithType",
50          query = "SELECT key.mcrfrom FROM MCRLINKHREF WHERE key.mcrto=:to AND key.mcrtype=:type"),
51      @NamedQuery(name = "MCRLINKHREF.group",
52          query = "SELECT count(key.mcrfrom), key.mcrto FROM MCRLINKHREF WHERE key.mcrto like :like GROUP BY key.mcrto")
53  })
54  public class MCRLINKHREF {
55      private MCRLINKHREFPK key;
56  
57      private String attr;
58  
59      /**
60       * The constructor of the class MCRLINKHREF
61       */
62      public MCRLINKHREF() {
63          key = new MCRLINKHREFPK();
64          attr = "";
65      }
66  
67      /**
68       * The constructor of the class MCRLINKHREF
69       *
70       * @param from
71       *            The link source
72       * @param to
73       *            The link target
74       * @param type
75       *            The type of the link (defined by using of this class)
76       * @param attr
77       *            The optional attribute of the link (defined by using of this
78       *            class)
79       */
80      public MCRLINKHREF(String from, String to, String type, String attr) {
81          key = new MCRLINKHREFPK();
82          key.setMcrfrom(from);
83          key.setMcrto(to);
84          key.setMcrtype(type);
85          if (attr != null) {
86              this.attr = attr;
87          }
88      }
89  
90      /**
91       * This method returns the primary key.
92       *
93       * @return returns the primary key as class MCRLINKHREFPK.
94       */
95      @EmbeddedId
96      public MCRLINKHREFPK getKey() {
97          return key;
98      }
99  
100     /**
101      * This method set the primary key.
102      *
103      * @param key
104      *            the primary key as instance of the class MCRLINKHREFPK
105      */
106     public void setKey(MCRLINKHREFPK key) {
107         this.key = key;
108     }
109 
110     /**
111      * Get the from value.
112      *
113      * @return the from value as a String.
114      */
115     @Transient
116     public String getMcrfrom() {
117         return key.getMcrfrom();
118     }
119 
120     /**
121      * Set the from value.
122      *
123      * @param mcrfrom
124      *            the from value as a string
125      */
126     public void setMcrfrom(String mcrfrom) {
127         key.setMcrfrom(mcrfrom);
128     }
129 
130     /**
131      * Get the to value.
132      *
133      * @return the to value as a String.
134      */
135     @Transient
136     public String getMcrto() {
137         return key.getMcrto();
138     }
139 
140     /**
141      * Set the to value.
142      *
143      * @param mcrto
144      *            the to value as a string
145      */
146     public void setMcrto(String mcrto) {
147         key.setMcrto(mcrto);
148     }
149 
150     /**
151      * Get the type value.
152      *
153      * @return the type value as a String.
154      */
155     @Transient
156     public String getMcrtype() {
157         return key.getMcrtype();
158     }
159 
160     /**
161      * Set the type value.
162      *
163      * @param mcrtype
164      *            the type value as a string
165      */
166     public void setMcrtype(String mcrtype) {
167         key.setMcrtype(mcrtype);
168     }
169 
170     /**
171      * Get the attribute value.
172      *
173      * @return the attr value as a String.
174      */
175     @Basic
176     @Column(length = 194, name = "MCRATTR")
177     public String getMcrattr() {
178         return attr;
179     }
180 
181     /**
182      * Set the attr value.
183      *
184      * @param mcrattr
185      *            the attr value as a string
186      */
187     public void setMcrattr(String mcrattr) {
188         if (mcrattr == null) {
189             return;
190         }
191         attr = mcrattr;
192     }
193 }