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.service.jpa;
19 import java.math.BigInteger;
20 import java.util.List;
22 import javax.persistence.Query;
24 import org.hedgecode.chess.domain.Author;
25 import org.hedgecode.chess.domain.Etude;
26 import org.hedgecode.chess.domain.EtudeType;
27 import org.hedgecode.chess.service.EtudeService;
32 * @author Dmitry Samoshin aka gotty
34 public class JpaEtudeService extends JpaDomainService<Etude> implements EtudeService {
40 public List<Etude> findAll() {
41 return getEntityManager().createNamedQuery(
50 public Etude findById(Long id) {
51 Query query = getEntityManager().createNamedQuery(
54 query.setParameter(Etude.ID_PARAMETER, id);
55 return (Etude) query.getSingleResult();
62 public List<Etude> findByHash(BigInteger hash) {
63 Query query = getEntityManager().createNamedQuery(
66 query.setParameter(Etude.HASH_PARAMETER, hash);
67 return query.getResultList();
74 public List<Etude> findByType(EtudeType etudeType) {
75 Query query = getEntityManager().createNamedQuery(
78 query.setParameter(Etude.TYPE_PARAMETER, etudeType);
79 return query.getResultList();
86 public List<Etude> findByAuthor(Author author) {
87 Query query = getEntityManager().createNamedQuery(
90 query.setParameter(Etude.AUTHOR_PARAMETER, author);
91 return query.getResultList();
98 public List<Etude> findByBlob(byte[] blob) {
99 Query query = getEntityManager().createNamedQuery(
102 query.setParameter(Etude.BLOB_PARAMETER, blob);
103 return query.getResultList();