1
22
23 package com.liferay.portlet.tags.service.persistence;
24
25 import com.liferay.portal.SystemException;
26 import com.liferay.portal.spring.hibernate.CustomSQLUtil;
27 import com.liferay.portal.spring.hibernate.HibernateUtil;
28 import com.liferay.portlet.tags.model.TagsProperty;
29 import com.liferay.portlet.tags.model.impl.TagsPropertyImpl;
30 import com.liferay.util.dao.hibernate.QueryPos;
31 import com.liferay.util.dao.hibernate.QueryUtil;
32
33 import java.util.ArrayList;
34 import java.util.Iterator;
35 import java.util.List;
36
37 import org.hibernate.Hibernate;
38 import org.hibernate.SQLQuery;
39 import org.hibernate.Session;
40
41
47 public class TagsPropertyFinder {
48
49 public static String COUNT_BY_C_K =
50 TagsPropertyFinder.class.getName() + ".countByC_K";
51
52 public static String FIND_BY_C_K =
53 TagsPropertyFinder.class.getName() + ".findByC_K";
54
55 public static int countByC_K(long companyId, String key)
56 throws SystemException {
57
58 Session session = null;
59
60 try {
61 session = HibernateUtil.openSession();
62
63 String sql = CustomSQLUtil.get(COUNT_BY_C_K);
64
65 SQLQuery q = session.createSQLQuery(sql);
66
67 q.addScalar(HibernateUtil.getCountColumnName(), Hibernate.LONG);
68
69 QueryPos qPos = QueryPos.getInstance(q);
70
71 qPos.add(companyId);
72 qPos.add(key);
73
74 Iterator itr = q.list().iterator();
75
76 if (itr.hasNext()) {
77 Long count = (Long)itr.next();
78
79 if (count != null) {
80 return count.intValue();
81 }
82 }
83
84 return 0;
85 }
86 catch (Exception e) {
87 throw new SystemException(e);
88 }
89 finally {
90 HibernateUtil.closeSession(session);
91 }
92 }
93
94 public static List findByC_K(long companyId, String key)
95 throws SystemException {
96
97 return findByC_K(companyId, key, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
98 }
99
100 public static List findByC_K(
101 long companyId, String key, int begin, int end)
102 throws SystemException {
103
104 Session session = null;
105
106 try {
107 session = HibernateUtil.openSession();
108
109 String sql = CustomSQLUtil.get(FIND_BY_C_K);
110
111 SQLQuery q = session.createSQLQuery(sql);
112
113 q.addScalar("propertyValue", Hibernate.STRING);
114
115 QueryPos qPos = QueryPos.getInstance(q);
116
117 qPos.add(companyId);
118 qPos.add(key);
119
120 List list = new ArrayList();
121
122 Iterator itr = QueryUtil.iterate(
123 q, HibernateUtil.getDialect(), begin, end);
124
125 while (itr.hasNext()) {
126 String value = (String)itr.next();
127
128 TagsProperty property = new TagsPropertyImpl();
129
130 property.setKey(key);
131 property.setValue(value);
132
133 list.add(property);
134 }
135
136 return list;
137 }
138 catch (Exception e) {
139 throw new SystemException(e);
140 }
141 finally {
142 HibernateUtil.closeSession(session);
143 }
144 }
145
146 }