1
19
20 package com.liferay.portlet.tags.service.persistence;
21
22 import com.liferay.portal.SystemException;
23 import com.liferay.portal.kernel.dao.orm.QueryPos;
24 import com.liferay.portal.kernel.dao.orm.QueryUtil;
25 import com.liferay.portal.kernel.dao.orm.SQLQuery;
26 import com.liferay.portal.kernel.dao.orm.Session;
27 import com.liferay.portal.kernel.dao.orm.Type;
28 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
29 import com.liferay.util.dao.orm.CustomSQLUtil;
30
31 import java.util.Iterator;
32 import java.util.List;
33
34
40 public class TagsPropertyKeyFinderImpl
41 extends BasePersistenceImpl implements TagsPropertyKeyFinder {
42
43 public static String COUNT_BY_COMPANYID =
44 TagsPropertyKeyFinder.class.getName() + ".countByCompanyId";
45
46 public static String FIND_BY_COMPANYID =
47 TagsPropertyKeyFinder.class.getName() + ".findByCompanyId";
48
49 public int countByCompanyId(long companyId) throws SystemException {
50 Session session = null;
51
52 try {
53 session = openSession();
54
55 String sql = CustomSQLUtil.get(COUNT_BY_COMPANYID);
56
57 SQLQuery q = session.createSQLQuery(sql);
58
59 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
60
61 QueryPos qPos = QueryPos.getInstance(q);
62
63 qPos.add(companyId);
64
65 Iterator<Long> itr = q.list().iterator();
66
67 if (itr.hasNext()) {
68 Long count = itr.next();
69
70 if (count != null) {
71 return count.intValue();
72 }
73 }
74
75 return 0;
76 }
77 catch (Exception e) {
78 throw new SystemException(e);
79 }
80 finally {
81 closeSession(session);
82 }
83 }
84
85 public String[] findByCompanyId(long companyId) throws SystemException {
86 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
87 }
88
89 public String[] findByCompanyId(long companyId, int start, int end)
90 throws SystemException {
91
92 Session session = null;
93
94 try {
95 session = openSession();
96
97 String sql = CustomSQLUtil.get(FIND_BY_COMPANYID);
98
99 SQLQuery q = session.createSQLQuery(sql);
100
101 q.addScalar("propertyKey", Type.STRING);
102
103 QueryPos qPos = QueryPos.getInstance(q);
104
105 qPos.add(companyId);
106
107 List<String> list = (List<String>)QueryUtil.list(
108 q, getDialect(), start, end);
109
110 return list.toArray(new String[list.size()]);
111 }
112 catch (Exception e) {
113 throw new SystemException(e);
114 }
115 finally {
116 closeSession(session);
117 }
118 }
119
120 }