Rev 1679 | Rev 1719 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1675 | jmachado | 1 | package pt.estgp.estgweb.domain.dao.impl; |
2 | |||
1679 | jmachado | 3 | import org.hibernate.Criteria; |
1675 | jmachado | 4 | import org.hibernate.criterion.Order; |
5 | import pt.estgp.estgweb.domain.RepositoryDocumentImpl; |
||
6 | |||
7 | import java.util.List; |
||
8 | |||
9 | import static org.hibernate.criterion.Restrictions.eq; |
||
10 | |||
11 | /** |
||
12 | * @author Jorge Machado |
||
13 | * @date 28/Fev/2008 |
||
14 | * @time 2:51:06 |
||
15 | * @see pt.estgp.estgweb.domain.dao.impl |
||
16 | */ |
||
17 | public class RepositoryDocumentDaoImpl extends RepositoryDocumentDao |
||
18 | { |
||
19 | private RepositoryDocumentDaoImpl() |
||
20 | { |
||
21 | } |
||
22 | |||
23 | public static RepositoryDocumentDaoImpl getInstance() |
||
24 | { |
||
25 | if (myInstance == null) |
||
26 | myInstance = new RepositoryDocumentDaoImpl(); |
||
27 | return (RepositoryDocumentDaoImpl) myInstance; |
||
28 | } |
||
29 | |||
30 | |||
1679 | jmachado | 31 | public List<RepositoryDocumentImpl> findDocumentsSortPublishDateDesc(boolean onlyVisible,long collectionId) |
1675 | jmachado | 32 | { |
1679 | jmachado | 33 | return findDocuments(onlyVisible,collectionId,"publishDate","desc"); |
1675 | jmachado | 34 | } |
1679 | jmachado | 35 | public List<RepositoryDocumentImpl> findDocumentsSortPublishDateAsc(boolean onlyVisible,long collectionId) |
1675 | jmachado | 36 | { |
1679 | jmachado | 37 | return findDocuments(onlyVisible,collectionId,"publishDate","asc"); |
1675 | jmachado | 38 | } |
1679 | jmachado | 39 | public List<RepositoryDocumentImpl> findDocumentsSortTitleDesc(boolean onlyVisible,long collectionId) |
1675 | jmachado | 40 | { |
1679 | jmachado | 41 | return findDocuments(onlyVisible,collectionId,"title","desc"); |
1675 | jmachado | 42 | } |
1679 | jmachado | 43 | public List<RepositoryDocumentImpl> findDocumentsSortTitleAsc(boolean onlyVisible,long collectionId) |
1675 | jmachado | 44 | { |
1679 | jmachado | 45 | return findDocuments(onlyVisible,collectionId,"title","asc"); |
1675 | jmachado | 46 | } |
47 | |||
1679 | jmachado | 48 | public List<RepositoryDocumentImpl> findDocuments(boolean onlyVisible,long collectionId,1.5.0/docs/api/java/lang/String.html">String orderField, 1.5.0/docs/api/java/lang/String.html">String orderDirection) |
1675 | jmachado | 49 | { |
50 | 1.5.0/docs/api/java/lang/String.html">String orderFinalField = orderField == null ? "publishDate" : orderField; |
||
51 | Order order = orderDirection.equals("asc") ? Order.asc(orderFinalField) : Order.desc(orderFinalField); |
||
1679 | jmachado | 52 | Criteria c = createCriteria() |
1675 | jmachado | 53 | .add(eq("collection.id",collectionId)) |
54 | .addOrder(order) |
||
1679 | jmachado | 55 | .addOrder(Order.desc("saveDate")); |
56 | if(onlyVisible) |
||
57 | c.add(eq("visible",true)); |
||
58 | return c.list(); |
||
1675 | jmachado | 59 | } |
60 | |||
61 | |||
1711 | jmachado | 62 | public List<RepositoryDocumentImpl> findDocumentsByTitleAndCollection(1.5.0/docs/api/java/lang/String.html">String title, long colId) { |
63 | Criteria c = createCriteria() |
||
64 | .add(eq("collection.id",colId)) |
||
65 | .add(eq("title",title)); |
||
66 | return c.list(); |
||
67 | } |
||
1675 | jmachado | 68 | } |