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_TC_TN =
48 ExpandoColumnFinder.class.getName() + ".countByTC_TC_TN";
49
50 public static String FIND_BY_TC_TC_TN =
51 ExpandoColumnFinder.class.getName() + ".findByTC_TC_TN";
52
53 public static String FIND_BY_TC_TC_TN_CN =
54 ExpandoColumnFinder.class.getName() + ".findByTC_TC_TN_CN";
55
56 public int countByTC_TC_TN(
57 long companyId, long classNameId, String tableName)
58 throws SystemException {
59
60 Session session = null;
61
62 try {
63 session = openSession();
64
65 String sql = CustomSQLUtil.get(COUNT_BY_TC_TC_TN);
66
67 SQLQuery q = session.createSQLQuery(sql);
68
69 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
70
71 QueryPos qPos = QueryPos.getInstance(q);
72
73 qPos.add(companyId);
74 qPos.add(classNameId);
75 qPos.add(tableName);
76
77 Iterator<Long> itr = q.list().iterator();
78
79 if (itr.hasNext()) {
80 Long count = itr.next();
81
82 if (count != null) {
83 return count.intValue();
84 }
85 }
86
87 return 0;
88 }
89 catch (Exception e) {
90 throw new SystemException(e);
91 }
92 finally {
93 closeSession(session);
94 }
95 }
96
97 public List<ExpandoColumn> findByTC_TC_TN(
98 long companyId, long classNameId, String tableName)
99 throws SystemException {
100
101 Session session = null;
102
103 try {
104 session = openSession();
105
106 String sql = CustomSQLUtil.get(FIND_BY_TC_TC_TN);
107
108 SQLQuery q = session.createSQLQuery(sql);
109
110 q.addEntity("ExpandoColumn", ExpandoColumnImpl.class);
111
112 QueryPos qPos = QueryPos.getInstance(q);
113
114 qPos.add(companyId);
115 qPos.add(classNameId);
116 qPos.add(tableName);
117
118 return q.list();
119 }
120 catch (Exception e) {
121 throw new SystemException(e);
122 }
123 finally {
124 closeSession(session);
125 }
126 }
127
128 public ExpandoColumn fetchByTC_TC_TN_CN(
129 long companyId, long classNameId, String tableName, String name)
130 throws SystemException {
131
132 Session session = null;
133
134 try {
135 session = openSession();
136
137 String sql = CustomSQLUtil.get(FIND_BY_TC_TC_TN_CN);
138
139 SQLQuery q = session.createSQLQuery(sql);
140
141 q.addEntity("ExpandoColumn", ExpandoColumnImpl.class);
142
143 QueryPos qPos = QueryPos.getInstance(q);
144
145 qPos.add(companyId);
146 qPos.add(classNameId);
147 qPos.add(tableName);
148 qPos.add(name);
149
150 return (ExpandoColumn)q.uniqueResult();
151 }
152 catch (Exception e) {
153 throw new SystemException(e);
154 }
155 finally {
156 closeSession(session);
157 }
158 }
159
160 }