2 * Copyright (c) 2018. Developed by Hedgecode.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.hedgecode.chess.domain;
19 import java.math.BigInteger;
20 import java.util.Date;
22 import javax.persistence.Column;
23 import javax.persistence.Entity;
24 import javax.persistence.FetchType;
25 import javax.persistence.GeneratedValue;
26 import javax.persistence.GenerationType;
27 import javax.persistence.Id;
28 import javax.persistence.JoinColumn;
29 import javax.persistence.Lob;
30 import javax.persistence.ManyToOne;
31 import javax.persistence.NamedQueries;
32 import javax.persistence.NamedQuery;
33 import javax.persistence.Table;
34 import javax.persistence.Temporal;
35 import javax.persistence.TemporalType;
36 import javax.persistence.Transient;
38 import org.hedgecode.chess.position.Position;
43 * @author Dmitry Samoshin aka gotty
51 name = Etude.FIND_ALL,
52 query = "select e from Etude e"
55 name = Etude.FIND_BY_ID,
56 query = "select e from Etude e where e.id = :id"
59 name = Etude.FIND_BY_HASH,
60 query = "select e from Etude e where e.hash = :hash"
63 name = Etude.FIND_BY_TYPE,
64 query = "select e from Etude e where e.etudeType = :etudeType"
67 name = Etude.FIND_BY_AUTHOR,
68 query = "select e from Etude e where e.author = :author"
71 name = Etude.FIND_BY_BLOB,
72 query = "select e from Etude e where e.blob = :blob"
75 public class Etude extends DomainObject<Etude> {
77 public static final String FIND_ALL = "Etude.findAll";
78 public static final String FIND_BY_ID = "Etude.findById";
79 public static final String FIND_BY_HASH = "Etude.findByHash";
80 public static final String FIND_BY_TYPE = "Etude.findByType";
81 public static final String FIND_BY_AUTHOR = "Etude.findByAuthor";
82 public static final String FIND_BY_BLOB = "Etude.findByBlob";
84 public static final String HASH_PARAMETER = "hash";
85 public static final String TYPE_PARAMETER = "type";
86 public static final String AUTHOR_PARAMETER = "author";
87 public static final String BLOB_PARAMETER = "blob";
94 strategy = GenerationType.AUTO
99 name = "f_hash", nullable = false
101 private BigInteger hash;
109 fetch = FetchType.LAZY
112 name = "f_type", nullable = false
114 private EtudeType etudeType;
117 fetch = FetchType.LAZY
122 private Author author;
125 name = "f_author_name"
127 private String authorName;
130 name = "f_fen", nullable = false
141 name = "f_blob", length = 32, nullable = false
149 value = TemporalType.DATE
154 name = "f_description"
156 private String description;
161 private Position position;
166 public Etude(Position position) {
167 this.position = position;
170 public <TargetType> TargetType assemble(TargetType target, EtudeAdapter<TargetType> adapter) {
171 adapter.setId(target, id);
172 adapter.setHash(target, hash);
173 adapter.setEtudeType(target, etudeType);
174 adapter.setAuthor(target, author);
175 adapter.setAuthorName(target, authorName);
176 adapter.setFen(target, fen);
177 adapter.setPgn(target, pgn);
178 adapter.setBlob(target, blob);
179 adapter.setDate(target, date);
180 adapter.setDescription(target, description);
188 private void assignFromPosition() {
192 private void assignFromPGN() {
196 public Position getPosition() {
201 public Long getId() {