1
22
23 package com.liferay.portlet.expando.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.expando.model.ExpandoValue;
29 import com.liferay.portlet.expando.model.impl.ExpandoValueImpl;
30 import com.liferay.util.dao.hibernate.QueryPos;
31 import com.liferay.util.dao.hibernate.QueryUtil;
32
33 import java.util.Iterator;
34 import java.util.List;
35
36 import org.hibernate.Hibernate;
37 import org.hibernate.SQLQuery;
38 import org.hibernate.Session;
39
40
46 public class ExpandoValueFinderImpl implements ExpandoValueFinder {
47
48 public static String COUNT_BY_TC_TN_CN =
49 ExpandoValueFinder.class.getName() + ".countByTC_TN_CN";
50
51 public static String FIND_BY_TC_TN_CN =
52 ExpandoValueFinder.class.getName() + ".findByTC_TN_CN";
53
54 public static String FIND_BY_TC_TN_CN_R =
55 ExpandoValueFinder.class.getName() + ".findByTC_TN_CN_R";
56
57 public int countByTC_TN_CN(
58 long classNameId, String tableName, String columnName)
59 throws SystemException {
60
61 Session session = null;
62
63 try {
64 session = HibernateUtil.openSession();
65
66 String sql = CustomSQLUtil.get(COUNT_BY_TC_TN_CN);
67
68 SQLQuery q = session.createSQLQuery(sql);
69
70 q.addScalar(HibernateUtil.getCountColumnName(), Hibernate.LONG);
71
72 QueryPos qPos = QueryPos.getInstance(q);
73
74 qPos.add(classNameId);
75 qPos.add(tableName);
76 qPos.add(columnName);
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 HibernateUtil.closeSession(session);
95 }
96 }
97
98 public List<ExpandoValue> findByTC_TN_CN(
99 long classNameId, String tableName, String columnName, int begin,
100 int end)
101 throws SystemException {
102
103 Session session = null;
104
105 try {
106 session = HibernateUtil.openSession();
107
108 String sql = CustomSQLUtil.get(FIND_BY_TC_TN_CN);
109
110 SQLQuery q = session.createSQLQuery(sql);
111
112 q.addEntity("ExpandoValue", ExpandoValueImpl.class);
113
114 QueryPos qPos = QueryPos.getInstance(q);
115
116 qPos.add(classNameId);
117 qPos.add(tableName);
118 qPos.add(columnName);
119
120 return (List<ExpandoValue>)QueryUtil.list(
121 q, HibernateUtil.getDialect(), begin, end);
122 }
123 catch (Exception e) {
124 throw new SystemException(e);
125 }
126 finally {
127 HibernateUtil.closeSession(session);
128 }
129 }
130
131 public ExpandoValue findByTC_TN_N(
132 long classNameId, String tableName, String columnName, long rowId)
133 throws SystemException {
134
135 Session session = null;
136
137 try {
138 session = HibernateUtil.openSession();
139
140 String sql = CustomSQLUtil.get(FIND_BY_TC_TN_CN_R);
141
142 SQLQuery q = session.createSQLQuery(sql);
143
144 q.addEntity("ExpandoValue", ExpandoValueImpl.class);
145
146 QueryPos qPos = QueryPos.getInstance(q);
147
148 qPos.add(classNameId);
149 qPos.add(tableName);
150 qPos.add(columnName);
151 qPos.add(rowId);
152
153 return (ExpandoValue)q.uniqueResult();
154 }
155 catch (Exception e) {
156 throw new SystemException(e);
157 }
158 finally {
159 HibernateUtil.closeSession(session);
160 }
161 }
162
163 }