001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.kernel.dao.orm.QueryPos;
018 import com.liferay.portal.kernel.dao.orm.SQLQuery;
019 import com.liferay.portal.kernel.dao.orm.Session;
020 import com.liferay.portal.kernel.exception.SystemException;
021 import com.liferay.portal.model.Resource;
022 import com.liferay.portal.model.impl.ResourceImpl;
023 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
024 import com.liferay.util.dao.orm.CustomSQLUtil;
025
026 import java.util.List;
027
028
032 public class ResourceFinderImpl
033 extends BasePersistenceImpl<Resource> implements ResourceFinder {
034
035 public static final String FIND_BY_CONTAINER_RESOURCE =
036 ResourceFinder.class.getName() + ".findByContainerResource";
037
038 public static final String FIND_BY_NAME =
039 ResourceFinder.class.getName() + ".findByName";
040
041 public static final String FIND_BY_NO_ACTIONS =
042 ResourceFinder.class.getName() + ".findByNoActions";
043
044 public static final String FIND_BY_C_P =
045 ResourceFinder.class.getName() + ".findByC_P";
046
047 public static final String FIND_BY_N_S =
048 ResourceFinder.class.getName() + ".findByN_S";
049
050 public List<Resource> findByContainerResource(long codeId, long classNameId)
051 throws SystemException {
052
053 Session session = null;
054
055 try {
056 session = openSession();
057
058 String sql = CustomSQLUtil.get(FIND_BY_CONTAINER_RESOURCE);
059
060 if (classNameId != 0) {
061 sql = sql.concat(" WHERE Group_.classNameId = " + classNameId);
062 }
063
064 SQLQuery q = session.createSQLQuery(sql);
065
066 q.addEntity("Resource_", ResourceImpl.class);
067
068 QueryPos qPos = QueryPos.getInstance(q);
069
070 qPos.add(codeId);
071
072 return q.list(true);
073 }
074 catch (Exception e) {
075 throw new SystemException(e);
076 }
077 finally {
078 closeSession(session);
079 }
080 }
081
082 public List<Resource> findByName(String name) throws SystemException {
083 Session session = null;
084
085 try {
086 session = openSession();
087
088 String sql = CustomSQLUtil.get(FIND_BY_NAME);
089
090 SQLQuery q = session.createSQLQuery(sql);
091
092 q.addEntity("Resource_", ResourceImpl.class);
093
094 QueryPos qPos = QueryPos.getInstance(q);
095
096 qPos.add(name);
097
098 return q.list(true);
099 }
100 catch (Exception e) {
101 throw new SystemException(e);
102 }
103 finally {
104 closeSession(session);
105 }
106 }
107
108 public List<Resource> findByNoActions(long codeId, String actionId)
109 throws SystemException {
110
111 Session session = null;
112
113 try {
114 session = openSession();
115
116 String sql = CustomSQLUtil.get(FIND_BY_NO_ACTIONS);
117
118 SQLQuery q = session.createSQLQuery(sql);
119
120 q.addEntity("Resource_", ResourceImpl.class);
121
122 QueryPos qPos = QueryPos.getInstance(q);
123
124 qPos.add(actionId);
125 qPos.add(codeId);
126
127 return q.list(true);
128 }
129 catch (Exception e) {
130 throw new SystemException(e);
131 }
132 finally {
133 closeSession(session);
134 }
135 }
136
137 public List<Resource> findByC_P(long companyId, String primKey)
138 throws SystemException {
139
140 Session session = null;
141
142 try {
143 session = openSession();
144
145 String sql = CustomSQLUtil.get(FIND_BY_C_P);
146
147 SQLQuery q = session.createSQLQuery(sql);
148
149 q.addEntity("Resource_", ResourceImpl.class);
150
151 QueryPos qPos = QueryPos.getInstance(q);
152
153 qPos.add(companyId);
154 qPos.add(primKey);
155
156 return q.list(true);
157 }
158 catch (Exception e) {
159 throw new SystemException(e);
160 }
161 finally {
162 closeSession(session);
163 }
164 }
165
166 public List<Resource> findByN_S(String name, int scope)
167 throws SystemException {
168
169 Session session = null;
170
171 try {
172 session = openSession();
173
174 String sql = CustomSQLUtil.get(FIND_BY_N_S);
175
176 SQLQuery q = session.createSQLQuery(sql);
177
178 q.addEntity("Resource_", ResourceImpl.class);
179
180 QueryPos qPos = QueryPos.getInstance(q);
181
182 qPos.add(name);
183 qPos.add(scope);
184
185 return q.list(true);
186 }
187 catch (Exception e) {
188 throw new SystemException(e);
189 }
190 finally {
191 closeSession(session);
192 }
193 }
194
195 }