1
22
23 package com.liferay.portlet.expando.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.portlet.expando.model.ExpandoRow;
33 import com.liferay.portlet.expando.model.impl.ExpandoRowImpl;
34 import com.liferay.util.dao.orm.CustomSQLUtil;
35
36 import java.util.Iterator;
37 import java.util.List;
38
39
45 public class ExpandoRowFinderImpl
46 extends BasePersistenceImpl implements ExpandoRowFinder {
47
48 public static String COUNT_BY_TC_TC_TN =
49 ExpandoRowFinder.class.getName() + ".countByTC_TC_TN";
50
51 public static String FIND_BY_TC_TC_TN =
52 ExpandoRowFinder.class.getName() + ".findByTC_TC_TN";
53
54 public static String FIND_BY_TC_TC_TN_C =
55 ExpandoRowFinder.class.getName() + ".findByTC_TC_TN_C";
56
57 public int countByTC_TC_TN(
58 long companyId, long classNameId, String tableName)
59 throws SystemException {
60
61 Session session = null;
62
63 try {
64 session = openSession();
65
66 String sql = CustomSQLUtil.get(COUNT_BY_TC_TC_TN);
67
68 SQLQuery q = session.createSQLQuery(sql);
69
70 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
71
72 QueryPos qPos = QueryPos.getInstance(q);
73
74 qPos.add(companyId);
75 qPos.add(classNameId);
76 qPos.add(tableName);
77
78 Iterator<Long> itr = q.list().iterator();
79
80 if (itr.hasNext()) {
81 Long count = itr.next();
82
83 if (count != null) {
84 return count.intValue();
85 }
86 }
87
88 return 0;
89 }
90 catch (Exception e) {
91 throw new SystemException(e);
92 }
93 finally {
94 closeSession(session);
95 }
96 }
97
98 public List<ExpandoRow> findByTC_TC_TN(
99 long companyId, long classNameId, String tableName, int start,
100 int end)
101 throws SystemException {
102
103 Session session = null;
104
105 try {
106 session = openSession();
107
108 String sql = CustomSQLUtil.get(FIND_BY_TC_TC_TN);
109
110 SQLQuery q = session.createSQLQuery(sql);
111
112 q.addEntity("ExpandoRow", ExpandoRowImpl.class);
113
114 QueryPos qPos = QueryPos.getInstance(q);
115
116 qPos.add(companyId);
117 qPos.add(classNameId);
118 qPos.add(tableName);
119
120 return (List<ExpandoRow>)QueryUtil.list(
121 q, getDialect(), start, end);
122 }
123 catch (Exception e) {
124 throw new SystemException(e);
125 }
126 finally {
127 closeSession(session);
128 }
129 }
130
131 public ExpandoRow fetchByTC_TC_TN_C(
132 long companyId, long classNameId, String tableName, long classPK)
133 throws SystemException {
134
135 Session session = null;
136
137 try {
138 session = openSession();
139
140 String sql = CustomSQLUtil.get(FIND_BY_TC_TC_TN_C);
141
142 SQLQuery q = session.createSQLQuery(sql);
143
144 q.addEntity("ExpandoRow", ExpandoRowImpl.class);
145
146 QueryPos qPos = QueryPos.getInstance(q);
147
148 qPos.add(companyId);
149 qPos.add(classNameId);
150 qPos.add(tableName);
151 qPos.add(classPK);
152
153 return (ExpandoRow)q.uniqueResult();
154 }
155 catch (Exception e) {
156 throw new SystemException(e);
157 }
158 finally {
159 closeSession(session);
160 }
161 }
162
163 }