Rev 1711 | Rev 1721 | 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; |
||
1719 | jmachado | 10 | import static org.hibernate.criterion.Restrictions.like; |
11 | import static org.hibernate.criterion.Restrictions.or; |
||
1675 | jmachado | 12 | |
13 | /** |
||
14 | * @author Jorge Machado |
||
15 | * @date 28/Fev/2008 |
||
16 | * @time 2:51:06 |
||
17 | * @see pt.estgp.estgweb.domain.dao.impl |
||
18 | */ |
||
19 | public class RepositoryDocumentDaoImpl extends RepositoryDocumentDao |
||
20 | { |
||
21 | private RepositoryDocumentDaoImpl() |
||
22 | { |
||
23 | } |
||
24 | |||
25 | public static RepositoryDocumentDaoImpl getInstance() |
||
26 | { |
||
27 | if (myInstance == null) |
||
28 | myInstance = new RepositoryDocumentDaoImpl(); |
||
29 | return (RepositoryDocumentDaoImpl) myInstance; |
||
30 | } |
||
31 | |||
32 | |||
1679 | jmachado | 33 | public List<RepositoryDocumentImpl> findDocumentsSortPublishDateDesc(boolean onlyVisible,long collectionId) |
1675 | jmachado | 34 | { |
1679 | jmachado | 35 | return findDocuments(onlyVisible,collectionId,"publishDate","desc"); |
1675 | jmachado | 36 | } |
1679 | jmachado | 37 | public List<RepositoryDocumentImpl> findDocumentsSortPublishDateAsc(boolean onlyVisible,long collectionId) |
1675 | jmachado | 38 | { |
1679 | jmachado | 39 | return findDocuments(onlyVisible,collectionId,"publishDate","asc"); |
1675 | jmachado | 40 | } |
1679 | jmachado | 41 | public List<RepositoryDocumentImpl> findDocumentsSortTitleDesc(boolean onlyVisible,long collectionId) |
1675 | jmachado | 42 | { |
1679 | jmachado | 43 | return findDocuments(onlyVisible,collectionId,"title","desc"); |
1675 | jmachado | 44 | } |
1679 | jmachado | 45 | public List<RepositoryDocumentImpl> findDocumentsSortTitleAsc(boolean onlyVisible,long collectionId) |
1675 | jmachado | 46 | { |
1679 | jmachado | 47 | return findDocuments(onlyVisible,collectionId,"title","asc"); |
1675 | jmachado | 48 | } |
49 | |||
1719 | jmachado | 50 | public List<RepositoryDocumentImpl> findDocumentsByTitle(1.5.0/docs/api/java/lang/String.html">String title) |
51 | { |
||
52 | Criteria c = createCriteria() |
||
53 | .createAlias("repositoryDocumentFiles", "rf") |
||
54 | .add(or(like("title", "%" + title.trim() + "%"), like("rf.title", "%" + title.trim() + "%"))); |
||
55 | return c.list(); |
||
56 | } |
||
1679 | jmachado | 57 | 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 | 58 | { |
59 | 1.5.0/docs/api/java/lang/String.html">String orderFinalField = orderField == null ? "publishDate" : orderField; |
||
60 | Order order = orderDirection.equals("asc") ? Order.asc(orderFinalField) : Order.desc(orderFinalField); |
||
1679 | jmachado | 61 | Criteria c = createCriteria() |
1675 | jmachado | 62 | .add(eq("collection.id",collectionId)) |
63 | .addOrder(order) |
||
1679 | jmachado | 64 | .addOrder(Order.desc("saveDate")); |
65 | if(onlyVisible) |
||
66 | c.add(eq("visible",true)); |
||
67 | return c.list(); |
||
1675 | jmachado | 68 | } |
69 | |||
70 | |||
1711 | jmachado | 71 | public List<RepositoryDocumentImpl> findDocumentsByTitleAndCollection(1.5.0/docs/api/java/lang/String.html">String title, long colId) { |
72 | Criteria c = createCriteria() |
||
73 | .add(eq("collection.id",colId)) |
||
74 | .add(eq("title",title)); |
||
75 | return c.list(); |
||
76 | } |
||
1675 | jmachado | 77 | } |