/* * Copyright (c) 2018. Developed by Hedgecode. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.hedgecode.chess.domain; import java.math.BigInteger; import java.util.Date; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.Lob; import javax.persistence.ManyToOne; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.persistence.Transient; import org.hedgecode.chess.position.Position; /** * * * @author Dmitry Samoshin aka gotty */ @Entity @Table( name = "etudes" ) @NamedQueries({ @NamedQuery( name = Etude.FIND_ALL, query = "select e from Etude e" ), @NamedQuery( name = Etude.FIND_BY_ID, query = "select e from Etude e where e.id = :id" ), @NamedQuery( name = Etude.FIND_BY_HASH, query = "select e from Etude e where e.hash = :hash" ), @NamedQuery( name = Etude.FIND_BY_TYPE, query = "select e from Etude e where e.etudeType = :etudeType" ), @NamedQuery( name = Etude.FIND_BY_AUTHOR, query = "select e from Etude e where e.author = :author" ), @NamedQuery( name = Etude.FIND_BY_BLOB, query = "select e from Etude e where e.blob = :blob" ) }) public class Etude extends DomainObject { public static final String FIND_ALL = "Etude.findAll"; public static final String FIND_BY_ID = "Etude.findById"; public static final String FIND_BY_HASH = "Etude.findByHash"; public static final String FIND_BY_TYPE = "Etude.findByType"; public static final String FIND_BY_AUTHOR = "Etude.findByAuthor"; public static final String FIND_BY_BLOB = "Etude.findByBlob"; public static final String HASH_PARAMETER = "hash"; public static final String TYPE_PARAMETER = "type"; public static final String AUTHOR_PARAMETER = "author"; public static final String BLOB_PARAMETER = "blob"; @Id @Column( name = "f_id" ) @GeneratedValue( strategy = GenerationType.AUTO ) private Long id; @Column( name = "f_hash", nullable = false ) private BigInteger hash; @Column( name = "f_name" ) private String name; @ManyToOne( fetch = FetchType.LAZY ) @JoinColumn( name = "f_type", nullable = false ) private EtudeType etudeType; @ManyToOne( fetch = FetchType.LAZY ) @JoinColumn( name = "f_author" ) private Author author; @Column( name = "f_author_name" ) private String authorName; @Column( name = "f_fen", nullable = false ) private String fen; @Column( name = "f_pgn" ) private String pgn; @Lob @Column( name = "f_blob", length = 32, nullable = false ) private byte[] blob; @Column( name = "f_date" ) @Temporal( value = TemporalType.DATE ) private Date date; @Column( name = "f_description" ) private String description; @Transient private Position position; public Etude() { } public Etude(Position position) { this.position = position; } public TargetType assemble(TargetType target, EtudeAdapter adapter) { adapter.setId(target, id); adapter.setHash(target, hash); adapter.setEtudeType(target, etudeType); adapter.setAuthor(target, author); adapter.setAuthorName(target, authorName); adapter.setFen(target, fen); adapter.setPgn(target, pgn); adapter.setBlob(target, blob); adapter.setDate(target, date); adapter.setDescription(target, description); return target; } private void assignFromPosition() { } private void assignFromPGN() { } public Position getPosition() { return position; } @Override public Long getId() { return id; } }