adf4b132c22102c2153a6f8f1ff7e824f64b8142
[chesshog.git] / chesshog-db-etude / src / main / java / org / hedgecode / chess / service / jpa / JpaEtudeTypeService.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.service.jpa;
18
19 import java.util.List;
20
21 import javax.persistence.Query;
22
23 import org.hedgecode.chess.domain.EtudeType;
24 import org.hedgecode.chess.service.EtudeTypeService;
25
26 /**
27  *
28  *
29  * @author Dmitry Samoshin aka gotty
30  */
31 public class JpaEtudeTypeService extends JpaDomainService<EtudeType> implements EtudeTypeService {
32
33     private static final long DEFAULT_ID = 1;
34
35     @Override
36     @SuppressWarnings(
37             "unchecked"
38     )
39     public List<EtudeType> findAll() {
40         return getEntityManager().createNamedQuery(
41                 EtudeType.FIND_ALL
42         ).getResultList();
43     }
44
45     @Override
46     @SuppressWarnings(
47             "unchecked"
48     )
49     public EtudeType findById(Long id) {
50         Query query = getEntityManager().createNamedQuery(
51                 EtudeType.FIND_BY_ID
52         );
53         query.setParameter(EtudeType.ID_PROPERTY, id);
54         return (EtudeType) query.getSingleResult();
55     }
56
57     @Override
58     @SuppressWarnings(
59             "unchecked"
60     )
61     public EtudeType findByBrief(String brief) {
62         Query query = getEntityManager().createNamedQuery(
63                 EtudeType.FIND_BY_BRIEF
64         );
65         query.setParameter(EtudeType.BRIEF_PROPERTY, brief);
66         return (EtudeType) query.getSingleResult();
67     }
68
69     @Override
70     @SuppressWarnings(
71             "unchecked"
72     )
73     public EtudeType findDefault() {
74         return findById(
75                 DEFAULT_ID
76         );
77     }
78
79 }