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