[LIB-9] Add functional for build image chess diagrams
[chesshog.git] / chesshog-db-etude / src / main / java / org / hedgecode / chess / domain / Author.java
1 /*
2  * Copyright (c) 2018. Developed by Hedgecode.
3  *
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
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.hedgecode.chess.domain;
18
19 import java.util.Date;
20
21 import javax.persistence.Column;
22 import javax.persistence.Entity;
23 import javax.persistence.GeneratedValue;
24 import javax.persistence.GenerationType;
25 import javax.persistence.Id;
26 import javax.persistence.NamedQueries;
27 import javax.persistence.NamedQuery;
28 import javax.persistence.Table;
29 import javax.persistence.Temporal;
30 import javax.persistence.TemporalType;
31
32 /**
33  *
34  *
35  * @author Dmitry Samoshin aka gotty
36  */
37 @Entity
38 @Table(
39         name = "authors"
40 )
41 @NamedQueries({
42         @NamedQuery(
43                 name = Author.FIND_ALL,
44                 query = "select a from Author a"
45         ),
46         @NamedQuery(
47                 name = Author.FIND_BY_ID,
48                 query = "select a from Author a where a.id = :id"
49         ),
50         @NamedQuery(
51                 name = Author.FIND_BY_NAME,
52                 query = "select a from Author a where a.name like :name"
53         ),
54         @NamedQuery(
55                 name = Author.FIND_BY_BIRTHDATE,
56                 query = "select a from Author a where a.birthdate = :birthdate"
57         )
58 })
59 public class Author extends DomainObject<Author> {
60
61     public static final String FIND_ALL = "Author.findAll";
62     public static final String FIND_BY_ID = "Author.findById";
63     public static final String FIND_BY_NAME = "Author.findByName";
64     public static final String FIND_BY_BIRTHDATE = "Author.findByBirthDate";
65
66     public static final String NAME_PARAMETER = "name";
67     public static final String BIRTHDATE_PARAMETER = "birthdate";
68
69     @Id
70     @Column(
71             name = "f_id"
72     )
73     @GeneratedValue(
74             strategy = GenerationType.AUTO
75     )
76     private Long id;
77
78     @Column(
79             name = "f_name", nullable = false
80     )
81     private String name;
82
83     @Column(
84             name = "f_birthdate"
85     )
86     @Temporal(
87             value = TemporalType.DATE
88     )
89     private Date birthdate;
90
91     @Column(
92             name = "f_deathdate"
93     )
94     @Temporal(
95             value = TemporalType.DATE
96     )
97     private Date deathdate;
98
99     @Column(
100             name = "f_biography"
101     )
102     private String biography;
103
104     @Column(
105             name = "f_comment"
106     )
107     private String comment;
108
109     public <TargetType> TargetType assemble(TargetType target, AuthorAdapter<TargetType> adapter) {
110         adapter.setId(target, id);
111         adapter.setName(target, name);
112         adapter.setBirthdate(target, birthdate);
113         adapter.setDeathdate(target, deathdate);
114         adapter.setBiography(target, biography);
115         adapter.setComment(target, comment);
116
117         return target;
118     }
119
120     @Override
121     public Long getId() {
122         return id;
123     }
124
125 }