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_NAME =
036 ResourceFinder.class.getName() + ".findByName";
037
038 public static final String FIND_BY_C_P =
039 ResourceFinder.class.getName() + ".findByC_P";
040
041 public static final String FIND_BY_N_S =
042 ResourceFinder.class.getName() + ".findByN_S";
043
044 public List<Resource> findByName(String name) throws SystemException {
045 Session session = null;
046
047 try {
048 session = openSession();
049
050 String sql = CustomSQLUtil.get(FIND_BY_NAME);
051
052 SQLQuery q = session.createSQLQuery(sql);
053
054 q.addEntity("Resource_", ResourceImpl.class);
055
056 QueryPos qPos = QueryPos.getInstance(q);
057
058 qPos.add(name);
059
060 return q.list(true);
061 }
062 catch (Exception e) {
063 throw new SystemException(e);
064 }
065 finally {
066 closeSession(session);
067 }
068 }
069
070 public List<Resource> findByC_P(long companyId, String primKey)
071 throws SystemException {
072
073 Session session = null;
074
075 try {
076 session = openSession();
077
078 String sql = CustomSQLUtil.get(FIND_BY_C_P);
079
080 SQLQuery q = session.createSQLQuery(sql);
081
082 q.addEntity("Resource_", ResourceImpl.class);
083
084 QueryPos qPos = QueryPos.getInstance(q);
085
086 qPos.add(companyId);
087 qPos.add(primKey);
088
089 return q.list(true);
090 }
091 catch (Exception e) {
092 throw new SystemException(e);
093 }
094 finally {
095 closeSession(session);
096 }
097 }
098
099 public List<Resource> findByN_S(String name, int scope)
100 throws SystemException {
101
102 Session session = null;
103
104 try {
105 session = openSession();
106
107 String sql = CustomSQLUtil.get(FIND_BY_N_S);
108
109 SQLQuery q = session.createSQLQuery(sql);
110
111 q.addEntity("Resource_", ResourceImpl.class);
112
113 QueryPos qPos = QueryPos.getInstance(q);
114
115 qPos.add(name);
116 qPos.add(scope);
117
118 return q.list(true);
119 }
120 catch (Exception e) {
121 throw new SystemException(e);
122 }
123 finally {
124 closeSession(session);
125 }
126 }
127
128 }