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