1
22
23 package com.liferay.portal.service.persistence;
24
25 import com.liferay.portal.kernel.util.GetterUtil;
26 import com.liferay.portal.kernel.util.Validator;
27 import com.liferay.portal.model.ModelListener;
28 import com.liferay.portal.util.PropsUtil;
29
30 import org.apache.commons.logging.Log;
31 import org.apache.commons.logging.LogFactory;
32
33
39 public class ClassNameUtil {
40 public static com.liferay.portal.model.ClassName create(long classNameId) {
41 return getPersistence().create(classNameId);
42 }
43
44 public static com.liferay.portal.model.ClassName remove(long classNameId)
45 throws com.liferay.portal.SystemException,
46 com.liferay.portal.NoSuchClassNameException {
47 ModelListener listener = _getListener();
48
49 if (listener != null) {
50 listener.onBeforeRemove(findByPrimaryKey(classNameId));
51 }
52
53 com.liferay.portal.model.ClassName className = getPersistence().remove(classNameId);
54
55 if (listener != null) {
56 listener.onAfterRemove(className);
57 }
58
59 return className;
60 }
61
62 public static com.liferay.portal.model.ClassName remove(
63 com.liferay.portal.model.ClassName className)
64 throws com.liferay.portal.SystemException {
65 ModelListener listener = _getListener();
66
67 if (listener != null) {
68 listener.onBeforeRemove(className);
69 }
70
71 className = getPersistence().remove(className);
72
73 if (listener != null) {
74 listener.onAfterRemove(className);
75 }
76
77 return className;
78 }
79
80 public static com.liferay.portal.model.ClassName update(
81 com.liferay.portal.model.ClassName className)
82 throws com.liferay.portal.SystemException {
83 ModelListener listener = _getListener();
84 boolean isNew = className.isNew();
85
86 if (listener != null) {
87 if (isNew) {
88 listener.onBeforeCreate(className);
89 }
90 else {
91 listener.onBeforeUpdate(className);
92 }
93 }
94
95 className = getPersistence().update(className);
96
97 if (listener != null) {
98 if (isNew) {
99 listener.onAfterCreate(className);
100 }
101 else {
102 listener.onAfterUpdate(className);
103 }
104 }
105
106 return className;
107 }
108
109 public static com.liferay.portal.model.ClassName update(
110 com.liferay.portal.model.ClassName className, boolean merge)
111 throws com.liferay.portal.SystemException {
112 ModelListener listener = _getListener();
113 boolean isNew = className.isNew();
114
115 if (listener != null) {
116 if (isNew) {
117 listener.onBeforeCreate(className);
118 }
119 else {
120 listener.onBeforeUpdate(className);
121 }
122 }
123
124 className = getPersistence().update(className, merge);
125
126 if (listener != null) {
127 if (isNew) {
128 listener.onAfterCreate(className);
129 }
130 else {
131 listener.onAfterUpdate(className);
132 }
133 }
134
135 return className;
136 }
137
138 public static com.liferay.portal.model.ClassName findByPrimaryKey(
139 long classNameId)
140 throws com.liferay.portal.SystemException,
141 com.liferay.portal.NoSuchClassNameException {
142 return getPersistence().findByPrimaryKey(classNameId);
143 }
144
145 public static com.liferay.portal.model.ClassName fetchByPrimaryKey(
146 long classNameId) throws com.liferay.portal.SystemException {
147 return getPersistence().fetchByPrimaryKey(classNameId);
148 }
149
150 public static com.liferay.portal.model.ClassName findByValue(
151 java.lang.String value)
152 throws com.liferay.portal.SystemException,
153 com.liferay.portal.NoSuchClassNameException {
154 return getPersistence().findByValue(value);
155 }
156
157 public static com.liferay.portal.model.ClassName fetchByValue(
158 java.lang.String value) throws com.liferay.portal.SystemException {
159 return getPersistence().fetchByValue(value);
160 }
161
162 public static java.util.List findWithDynamicQuery(
163 com.liferay.portal.kernel.dao.DynamicQueryInitializer queryInitializer)
164 throws com.liferay.portal.SystemException {
165 return getPersistence().findWithDynamicQuery(queryInitializer);
166 }
167
168 public static java.util.List findWithDynamicQuery(
169 com.liferay.portal.kernel.dao.DynamicQueryInitializer queryInitializer,
170 int begin, int end) throws com.liferay.portal.SystemException {
171 return getPersistence().findWithDynamicQuery(queryInitializer, begin,
172 end);
173 }
174
175 public static java.util.List findAll()
176 throws com.liferay.portal.SystemException {
177 return getPersistence().findAll();
178 }
179
180 public static java.util.List findAll(int begin, int end)
181 throws com.liferay.portal.SystemException {
182 return getPersistence().findAll(begin, end);
183 }
184
185 public static java.util.List findAll(int begin, int end,
186 com.liferay.portal.kernel.util.OrderByComparator obc)
187 throws com.liferay.portal.SystemException {
188 return getPersistence().findAll(begin, end, obc);
189 }
190
191 public static void removeByValue(java.lang.String value)
192 throws com.liferay.portal.SystemException,
193 com.liferay.portal.NoSuchClassNameException {
194 getPersistence().removeByValue(value);
195 }
196
197 public static void removeAll() throws com.liferay.portal.SystemException {
198 getPersistence().removeAll();
199 }
200
201 public static int countByValue(java.lang.String value)
202 throws com.liferay.portal.SystemException {
203 return getPersistence().countByValue(value);
204 }
205
206 public static int countAll() throws com.liferay.portal.SystemException {
207 return getPersistence().countAll();
208 }
209
210 public static ClassNamePersistence getPersistence() {
211 return _getUtil()._persistence;
212 }
213
214 public void setPersistence(ClassNamePersistence persistence) {
215 _persistence = persistence;
216 }
217
218 private static ClassNameUtil _getUtil() {
219 if (_util == null) {
220 _util = (ClassNameUtil)com.liferay.portal.kernel.bean.BeanLocatorUtil.locate(_UTIL);
221 }
222
223 return _util;
224 }
225
226 private static ModelListener _getListener() {
227 if (Validator.isNotNull(_LISTENER)) {
228 try {
229 return (ModelListener)Class.forName(_LISTENER).newInstance();
230 }
231 catch (Exception e) {
232 _log.error(e);
233 }
234 }
235
236 return null;
237 }
238
239 private static final String _UTIL = ClassNameUtil.class.getName();
240 private static final String _LISTENER = GetterUtil.getString(PropsUtil.get(
241 "value.object.listener.com.liferay.portal.model.ClassName"));
242 private static Log _log = LogFactory.getLog(ClassNameUtil.class);
243 private static ClassNameUtil _util;
244 private ClassNamePersistence _persistence;
245 }