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.SQLQuery;
28 import com.liferay.portal.kernel.dao.orm.Session;
29 import com.liferay.portal.kernel.dao.orm.Type;
30 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
31 import com.liferay.portlet.expando.model.ExpandoColumn;
32 import com.liferay.portlet.expando.model.impl.ExpandoColumnImpl;
33 import com.liferay.util.dao.orm.CustomSQLUtil;
34
35 import java.util.Iterator;
36 import java.util.List;
37
38
44 public class ExpandoColumnFinderImpl
45 extends BasePersistenceImpl implements ExpandoColumnFinder {
46
47 public static String COUNT_BY_TC_TN =
48 ExpandoColumnFinder.class.getName() + ".countByTC_TN";
49
50 public static String FIND_BY_TC_TN =
51 ExpandoColumnFinder.class.getName() + ".findByTC_TN";
52
53 public static String FIND_BY_TC_TN_CN =
54 ExpandoColumnFinder.class.getName() + ".findByTC_TN_CN";
55
56 public int countByTC_TN(long classNameId, String tableName)
57 throws SystemException {
58
59 Session session = null;
60
61 try {
62 session = openSession();
63
64 String sql = CustomSQLUtil.get(COUNT_BY_TC_TN);
65
66 SQLQuery q = session.createSQLQuery(sql);
67
68 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
69
70 QueryPos qPos = QueryPos.getInstance(q);
71
72 qPos.add(classNameId);
73 qPos.add(tableName);
74
75 Iterator<Long> itr = q.list().iterator();
76
77 if (itr.hasNext()) {
78 Long count = itr.next();
79
80 if (count != null) {
81 return count.intValue();
82 }
83 }
84
85 return 0;
86 }
87 catch (Exception e) {
88 throw new SystemException(e);
89 }
90 finally {
91 closeSession(session);
92 }
93 }
94
95 public List<ExpandoColumn> findByTC_TN(long classNameId, String tableName)
96 throws SystemException {
97
98 Session session = null;
99
100 try {
101 session = openSession();
102
103 String sql = CustomSQLUtil.get(FIND_BY_TC_TN);
104
105 SQLQuery q = session.createSQLQuery(sql);
106
107 q.addEntity("ExpandoColumn", ExpandoColumnImpl.class);
108
109 QueryPos qPos = QueryPos.getInstance(q);
110
111 qPos.add(classNameId);
112 qPos.add(tableName);
113
114 return q.list();
115 }
116 catch (Exception e) {
117 throw new SystemException(e);
118 }
119 finally {
120 closeSession(session);
121 }
122 }
123
124 public ExpandoColumn fetchByTC_TN_CN(
125 long classNameId, String tableName, String name)
126 throws SystemException {
127
128 Session session = null;
129
130 try {
131 session = openSession();
132
133 String sql = CustomSQLUtil.get(FIND_BY_TC_TN_CN);
134
135 SQLQuery q = session.createSQLQuery(sql);
136
137 q.addEntity("ExpandoColumn", ExpandoColumnImpl.class);
138
139 QueryPos qPos = QueryPos.getInstance(q);
140
141 qPos.add(classNameId);
142 qPos.add(tableName);
143 qPos.add(name);
144
145 return (ExpandoColumn)q.uniqueResult();
146 }
147 catch (Exception e) {
148 throw new SystemException(e);
149 }
150 finally {
151 closeSession(session);
152 }
153 }
154
155 }