1 | package com.ether.dao.instrument; |
---|
2 | |
---|
3 | import java.util.List; |
---|
4 | |
---|
5 | import org.hibernate.criterion.DetachedCriteria; |
---|
6 | import org.hibernate.criterion.Projections; |
---|
7 | import org.hibernate.criterion.Restrictions; |
---|
8 | import org.jetbrains.annotations.NotNull; |
---|
9 | import org.jetbrains.annotations.Nullable; |
---|
10 | |
---|
11 | import com.ether.PersistenceException; |
---|
12 | import com.ether.dao.DomainAccessObjectImpl; |
---|
13 | import com.ether.instrument.Instrument; |
---|
14 | import com.ether.instrument.InstrumentType; |
---|
15 | |
---|
16 | /** |
---|
17 | * @author vmipsl |
---|
18 | * @date 24 jan 2011 |
---|
19 | */ |
---|
20 | public class InstrumentDAOImpl extends DomainAccessObjectImpl<Instrument, Long> |
---|
21 | implements InstrumentDAO |
---|
22 | { |
---|
23 | protected InstrumentDAOImpl() { |
---|
24 | super(Instrument.class); |
---|
25 | } |
---|
26 | |
---|
27 | public Integer getNbInstruments() throws PersistenceException |
---|
28 | { |
---|
29 | final DetachedCriteria criteria = DetachedCriteria.forClass(Instrument.class) |
---|
30 | .setProjection(Projections.property("id")); |
---|
31 | |
---|
32 | return count(criteria); |
---|
33 | } |
---|
34 | |
---|
35 | @Nullable |
---|
36 | public List<Instrument> getInstrumentsByStationId( @NotNull final Long stationId ) throws PersistenceException |
---|
37 | { |
---|
38 | final DetachedCriteria criteria = DetachedCriteria.forClass(Instrument.class) |
---|
39 | .add(Restrictions.eq("station.id", stationId)); |
---|
40 | |
---|
41 | return selectAllByCriteria(Instrument.class, criteria); |
---|
42 | } |
---|
43 | |
---|
44 | @Nullable |
---|
45 | public List<Instrument> getInstrumentsByType( @NotNull final InstrumentType type ) throws PersistenceException |
---|
46 | { |
---|
47 | final DetachedCriteria criteria = DetachedCriteria.forClass(Instrument.class) |
---|
48 | .add(Restrictions.eq("type", type)); |
---|
49 | |
---|
50 | return selectAllByCriteria(Instrument.class, criteria); |
---|
51 | } |
---|
52 | } |
---|