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 @Override
051 public List<Resource> findByContainerResource(long codeId, long classNameId)
052 throws SystemException {
053
054 Session session = null;
055
056 try {
057 session = openSession();
058
059 String sql = CustomSQLUtil.get(FIND_BY_CONTAINER_RESOURCE);
060
061 if (classNameId != 0) {
062 sql = sql.concat(" WHERE Group_.classNameId = " + classNameId);
063 }
064
065 SQLQuery q = session.createSQLQuery(sql);
066
067 q.addEntity("Resource_", ResourceImpl.class);
068
069 QueryPos qPos = QueryPos.getInstance(q);
070
071 qPos.add(codeId);
072
073 return q.list(true);
074 }
075 catch (Exception e) {
076 throw new SystemException(e);
077 }
078 finally {
079 closeSession(session);
080 }
081 }
082
083 @Override
084 public List<Resource> findByName(String name) throws SystemException {
085 Session session = null;
086
087 try {
088 session = openSession();
089
090 String sql = CustomSQLUtil.get(FIND_BY_NAME);
091
092 SQLQuery q = session.createSQLQuery(sql);
093
094 q.addEntity("Resource_", ResourceImpl.class);
095
096 QueryPos qPos = QueryPos.getInstance(q);
097
098 qPos.add(name);
099
100 return q.list(true);
101 }
102 catch (Exception e) {
103 throw new SystemException(e);
104 }
105 finally {
106 closeSession(session);
107 }
108 }
109
110 @Override
111 public List<Resource> findByNoActions(long codeId, String actionId)
112 throws SystemException {
113
114 Session session = null;
115
116 try {
117 session = openSession();
118
119 String sql = CustomSQLUtil.get(FIND_BY_NO_ACTIONS);
120
121 SQLQuery q = session.createSQLQuery(sql);
122
123 q.addEntity("Resource_", ResourceImpl.class);
124
125 QueryPos qPos = QueryPos.getInstance(q);
126
127 qPos.add(actionId);
128 qPos.add(codeId);
129
130 return q.list(true);
131 }
132 catch (Exception e) {
133 throw new SystemException(e);
134 }
135 finally {
136 closeSession(session);
137 }
138 }
139
140 @Override
141 public List<Resource> findByC_P(long companyId, String primKey)
142 throws SystemException {
143
144 Session session = null;
145
146 try {
147 session = openSession();
148
149 String sql = CustomSQLUtil.get(FIND_BY_C_P);
150
151 SQLQuery q = session.createSQLQuery(sql);
152
153 q.addEntity("Resource_", ResourceImpl.class);
154
155 QueryPos qPos = QueryPos.getInstance(q);
156
157 qPos.add(companyId);
158 qPos.add(primKey);
159
160 return q.list(true);
161 }
162 catch (Exception e) {
163 throw new SystemException(e);
164 }
165 finally {
166 closeSession(session);
167 }
168 }
169
170 @Override
171 public List<Resource> findByN_S(String name, int scope)
172 throws SystemException {
173
174 Session session = null;
175
176 try {
177 session = openSession();
178
179 String sql = CustomSQLUtil.get(FIND_BY_N_S);
180
181 SQLQuery q = session.createSQLQuery(sql);
182
183 q.addEntity("Resource_", ResourceImpl.class);
184
185 QueryPos qPos = QueryPos.getInstance(q);
186
187 qPos.add(name);
188 qPos.add(scope);
189
190 return q.list(true);
191 }
192 catch (Exception e) {
193 throw new SystemException(e);
194 }
195 finally {
196 closeSession(session);
197 }
198 }
199
200 }