1
14
15 package com.liferay.portlet.tags.service.persistence;
16
17 import com.liferay.portal.SystemException;
18 import com.liferay.portal.kernel.dao.orm.QueryPos;
19 import com.liferay.portal.kernel.dao.orm.QueryUtil;
20 import com.liferay.portal.kernel.dao.orm.SQLQuery;
21 import com.liferay.portal.kernel.dao.orm.Session;
22 import com.liferay.portal.kernel.dao.orm.Type;
23 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
24 import com.liferay.portlet.tags.model.TagsProperty;
25 import com.liferay.portlet.tags.model.impl.TagsPropertyImpl;
26 import com.liferay.util.dao.orm.CustomSQLUtil;
27
28 import java.util.ArrayList;
29 import java.util.Iterator;
30 import java.util.List;
31
32
37 public class TagsPropertyFinderImpl
38 extends BasePersistenceImpl<TagsProperty> implements TagsPropertyFinder {
39
40 public static String COUNT_BY_G_K =
41 TagsPropertyFinder.class.getName() + ".countByG_K";
42
43 public static String FIND_BY_G_K =
44 TagsPropertyFinder.class.getName() + ".findByG_K";
45
46 public int countByG_K(long groupId, String key) throws SystemException {
47 Session session = null;
48
49 try {
50 session = openSession();
51
52 String sql = CustomSQLUtil.get(COUNT_BY_G_K);
53
54 SQLQuery q = session.createSQLQuery(sql);
55
56 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
57
58 QueryPos qPos = QueryPos.getInstance(q);
59
60 qPos.add(groupId);
61 qPos.add(key);
62
63 Iterator<Long> itr = q.list().iterator();
64
65 if (itr.hasNext()) {
66 Long count = itr.next();
67
68 if (count != null) {
69 return count.intValue();
70 }
71 }
72
73 return 0;
74 }
75 catch (Exception e) {
76 throw new SystemException(e);
77 }
78 finally {
79 closeSession(session);
80 }
81 }
82
83 public List<TagsProperty> findByG_K(long groupId, String key)
84 throws SystemException {
85
86 return findByG_K(groupId, key, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
87 }
88
89 public List<TagsProperty> findByG_K(
90 long groupId, String key, int start, int end)
91 throws SystemException {
92
93 Session session = null;
94
95 try {
96 session = openSession();
97
98 String sql = CustomSQLUtil.get(FIND_BY_G_K);
99
100 SQLQuery q = session.createSQLQuery(sql);
101
102 q.addScalar("propertyValue", Type.STRING);
103
104 QueryPos qPos = QueryPos.getInstance(q);
105
106 qPos.add(groupId);
107 qPos.add(key);
108
109 List<TagsProperty> properties = new ArrayList<TagsProperty>();
110
111 Iterator<String> itr = (Iterator<String>)QueryUtil.iterate(
112 q, getDialect(), start, end);
113
114 while (itr.hasNext()) {
115 String value = itr.next();
116
117 TagsProperty property = new TagsPropertyImpl();
118
119 property.setKey(key);
120 property.setValue(value);
121
122 properties.add(property);
123 }
124
125 return properties;
126 }
127 catch (Exception e) {
128 throw new SystemException(e);
129 }
130 finally {
131 closeSession(session);
132 }
133 }
134
135 }