001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.base;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.kernel.bean.BeanReference;
020    import com.liferay.portal.kernel.bean.IdentifiableBean;
021    import com.liferay.portal.kernel.dao.db.DB;
022    import com.liferay.portal.kernel.dao.db.DBFactoryUtil;
023    import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
024    import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
025    import com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery;
026    import com.liferay.portal.kernel.dao.orm.DefaultActionableDynamicQuery;
027    import com.liferay.portal.kernel.dao.orm.DynamicQuery;
028    import com.liferay.portal.kernel.dao.orm.DynamicQueryFactoryUtil;
029    import com.liferay.portal.kernel.dao.orm.Projection;
030    import com.liferay.portal.kernel.exception.PortalException;
031    import com.liferay.portal.kernel.exception.SystemException;
032    import com.liferay.portal.kernel.search.Indexable;
033    import com.liferay.portal.kernel.search.IndexableType;
034    import com.liferay.portal.kernel.util.OrderByComparator;
035    import com.liferay.portal.model.Account;
036    import com.liferay.portal.model.PersistedModel;
037    import com.liferay.portal.service.AccountLocalService;
038    import com.liferay.portal.service.BaseLocalServiceImpl;
039    import com.liferay.portal.service.PersistedModelLocalServiceRegistry;
040    import com.liferay.portal.service.persistence.AccountPersistence;
041    import com.liferay.portal.util.PortalUtil;
042    
043    import java.io.Serializable;
044    
045    import java.util.List;
046    
047    import javax.sql.DataSource;
048    
049    /**
050     * Provides the base implementation for the account local service.
051     *
052     * <p>
053     * This implementation exists only as a container for the default service methods generated by ServiceBuilder. All custom service methods should be put in {@link com.liferay.portal.service.impl.AccountLocalServiceImpl}.
054     * </p>
055     *
056     * @author Brian Wing Shun Chan
057     * @see com.liferay.portal.service.impl.AccountLocalServiceImpl
058     * @see com.liferay.portal.service.AccountLocalServiceUtil
059     * @generated
060     */
061    @ProviderType
062    public abstract class AccountLocalServiceBaseImpl extends BaseLocalServiceImpl
063            implements AccountLocalService, IdentifiableBean {
064            /*
065             * NOTE FOR DEVELOPERS:
066             *
067             * Never modify or reference this class directly. Always use {@link com.liferay.portal.service.AccountLocalServiceUtil} to access the account local service.
068             */
069    
070            /**
071             * Adds the account to the database. Also notifies the appropriate model listeners.
072             *
073             * @param account the account
074             * @return the account that was added
075             */
076            @Indexable(type = IndexableType.REINDEX)
077            @Override
078            public Account addAccount(Account account) {
079                    account.setNew(true);
080    
081                    return accountPersistence.update(account);
082            }
083    
084            /**
085             * Creates a new account with the primary key. Does not add the account to the database.
086             *
087             * @param accountId the primary key for the new account
088             * @return the new account
089             */
090            @Override
091            public Account createAccount(long accountId) {
092                    return accountPersistence.create(accountId);
093            }
094    
095            /**
096             * Deletes the account with the primary key from the database. Also notifies the appropriate model listeners.
097             *
098             * @param accountId the primary key of the account
099             * @return the account that was removed
100             * @throws PortalException if a account with the primary key could not be found
101             */
102            @Indexable(type = IndexableType.DELETE)
103            @Override
104            public Account deleteAccount(long accountId) throws PortalException {
105                    return accountPersistence.remove(accountId);
106            }
107    
108            /**
109             * Deletes the account from the database. Also notifies the appropriate model listeners.
110             *
111             * @param account the account
112             * @return the account that was removed
113             */
114            @Indexable(type = IndexableType.DELETE)
115            @Override
116            public Account deleteAccount(Account account) {
117                    return accountPersistence.remove(account);
118            }
119    
120            @Override
121            public DynamicQuery dynamicQuery() {
122                    Class<?> clazz = getClass();
123    
124                    return DynamicQueryFactoryUtil.forClass(Account.class,
125                            clazz.getClassLoader());
126            }
127    
128            /**
129             * Performs a dynamic query on the database and returns the matching rows.
130             *
131             * @param dynamicQuery the dynamic query
132             * @return the matching rows
133             */
134            @Override
135            public <T> List<T> dynamicQuery(DynamicQuery dynamicQuery) {
136                    return accountPersistence.findWithDynamicQuery(dynamicQuery);
137            }
138    
139            /**
140             * Performs a dynamic query on the database and returns a range of the matching rows.
141             *
142             * <p>
143             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.AccountModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
144             * </p>
145             *
146             * @param dynamicQuery the dynamic query
147             * @param start the lower bound of the range of model instances
148             * @param end the upper bound of the range of model instances (not inclusive)
149             * @return the range of matching rows
150             */
151            @Override
152            public <T> List<T> dynamicQuery(DynamicQuery dynamicQuery, int start,
153                    int end) {
154                    return accountPersistence.findWithDynamicQuery(dynamicQuery, start, end);
155            }
156    
157            /**
158             * Performs a dynamic query on the database and returns an ordered range of the matching rows.
159             *
160             * <p>
161             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.AccountModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
162             * </p>
163             *
164             * @param dynamicQuery the dynamic query
165             * @param start the lower bound of the range of model instances
166             * @param end the upper bound of the range of model instances (not inclusive)
167             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
168             * @return the ordered range of matching rows
169             */
170            @Override
171            public <T> List<T> dynamicQuery(DynamicQuery dynamicQuery, int start,
172                    int end, OrderByComparator<T> orderByComparator) {
173                    return accountPersistence.findWithDynamicQuery(dynamicQuery, start,
174                            end, orderByComparator);
175            }
176    
177            /**
178             * Returns the number of rows matching the dynamic query.
179             *
180             * @param dynamicQuery the dynamic query
181             * @return the number of rows matching the dynamic query
182             */
183            @Override
184            public long dynamicQueryCount(DynamicQuery dynamicQuery) {
185                    return accountPersistence.countWithDynamicQuery(dynamicQuery);
186            }
187    
188            /**
189             * Returns the number of rows matching the dynamic query.
190             *
191             * @param dynamicQuery the dynamic query
192             * @param projection the projection to apply to the query
193             * @return the number of rows matching the dynamic query
194             */
195            @Override
196            public long dynamicQueryCount(DynamicQuery dynamicQuery,
197                    Projection projection) {
198                    return accountPersistence.countWithDynamicQuery(dynamicQuery, projection);
199            }
200    
201            @Override
202            public Account fetchAccount(long accountId) {
203                    return accountPersistence.fetchByPrimaryKey(accountId);
204            }
205    
206            /**
207             * Returns the account with the primary key.
208             *
209             * @param accountId the primary key of the account
210             * @return the account
211             * @throws PortalException if a account with the primary key could not be found
212             */
213            @Override
214            public Account getAccount(long accountId) throws PortalException {
215                    return accountPersistence.findByPrimaryKey(accountId);
216            }
217    
218            @Override
219            public ActionableDynamicQuery getActionableDynamicQuery() {
220                    ActionableDynamicQuery actionableDynamicQuery = new DefaultActionableDynamicQuery();
221    
222                    actionableDynamicQuery.setBaseLocalService(com.liferay.portal.service.AccountLocalServiceUtil.getService());
223                    actionableDynamicQuery.setClass(Account.class);
224                    actionableDynamicQuery.setClassLoader(getClassLoader());
225    
226                    actionableDynamicQuery.setPrimaryKeyPropertyName("accountId");
227    
228                    return actionableDynamicQuery;
229            }
230    
231            protected void initActionableDynamicQuery(
232                    ActionableDynamicQuery actionableDynamicQuery) {
233                    actionableDynamicQuery.setBaseLocalService(com.liferay.portal.service.AccountLocalServiceUtil.getService());
234                    actionableDynamicQuery.setClass(Account.class);
235                    actionableDynamicQuery.setClassLoader(getClassLoader());
236    
237                    actionableDynamicQuery.setPrimaryKeyPropertyName("accountId");
238            }
239    
240            /**
241             * @throws PortalException
242             */
243            @Override
244            public PersistedModel deletePersistedModel(PersistedModel persistedModel)
245                    throws PortalException {
246                    return accountLocalService.deleteAccount((Account)persistedModel);
247            }
248    
249            @Override
250            public PersistedModel getPersistedModel(Serializable primaryKeyObj)
251                    throws PortalException {
252                    return accountPersistence.findByPrimaryKey(primaryKeyObj);
253            }
254    
255            /**
256             * Returns a range of all the accounts.
257             *
258             * <p>
259             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.AccountModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
260             * </p>
261             *
262             * @param start the lower bound of the range of accounts
263             * @param end the upper bound of the range of accounts (not inclusive)
264             * @return the range of accounts
265             */
266            @Override
267            public List<Account> getAccounts(int start, int end) {
268                    return accountPersistence.findAll(start, end);
269            }
270    
271            /**
272             * Returns the number of accounts.
273             *
274             * @return the number of accounts
275             */
276            @Override
277            public int getAccountsCount() {
278                    return accountPersistence.countAll();
279            }
280    
281            /**
282             * Updates the account in the database or adds it if it does not yet exist. Also notifies the appropriate model listeners.
283             *
284             * @param account the account
285             * @return the account that was updated
286             */
287            @Indexable(type = IndexableType.REINDEX)
288            @Override
289            public Account updateAccount(Account account) {
290                    return accountPersistence.update(account);
291            }
292    
293            /**
294             * Returns the account local service.
295             *
296             * @return the account local service
297             */
298            public com.liferay.portal.service.AccountLocalService getAccountLocalService() {
299                    return accountLocalService;
300            }
301    
302            /**
303             * Sets the account local service.
304             *
305             * @param accountLocalService the account local service
306             */
307            public void setAccountLocalService(
308                    com.liferay.portal.service.AccountLocalService accountLocalService) {
309                    this.accountLocalService = accountLocalService;
310            }
311    
312            /**
313             * Returns the account remote service.
314             *
315             * @return the account remote service
316             */
317            public com.liferay.portal.service.AccountService getAccountService() {
318                    return accountService;
319            }
320    
321            /**
322             * Sets the account remote service.
323             *
324             * @param accountService the account remote service
325             */
326            public void setAccountService(
327                    com.liferay.portal.service.AccountService accountService) {
328                    this.accountService = accountService;
329            }
330    
331            /**
332             * Returns the account persistence.
333             *
334             * @return the account persistence
335             */
336            public AccountPersistence getAccountPersistence() {
337                    return accountPersistence;
338            }
339    
340            /**
341             * Sets the account persistence.
342             *
343             * @param accountPersistence the account persistence
344             */
345            public void setAccountPersistence(AccountPersistence accountPersistence) {
346                    this.accountPersistence = accountPersistence;
347            }
348    
349            /**
350             * Returns the counter local service.
351             *
352             * @return the counter local service
353             */
354            public com.liferay.counter.service.CounterLocalService getCounterLocalService() {
355                    return counterLocalService;
356            }
357    
358            /**
359             * Sets the counter local service.
360             *
361             * @param counterLocalService the counter local service
362             */
363            public void setCounterLocalService(
364                    com.liferay.counter.service.CounterLocalService counterLocalService) {
365                    this.counterLocalService = counterLocalService;
366            }
367    
368            public void afterPropertiesSet() {
369                    persistedModelLocalServiceRegistry.register("com.liferay.portal.model.Account",
370                            accountLocalService);
371            }
372    
373            public void destroy() {
374                    persistedModelLocalServiceRegistry.unregister(
375                            "com.liferay.portal.model.Account");
376            }
377    
378            /**
379             * Returns the Spring bean ID for this bean.
380             *
381             * @return the Spring bean ID for this bean
382             */
383            @Override
384            public String getBeanIdentifier() {
385                    return _beanIdentifier;
386            }
387    
388            /**
389             * Sets the Spring bean ID for this bean.
390             *
391             * @param beanIdentifier the Spring bean ID for this bean
392             */
393            @Override
394            public void setBeanIdentifier(String beanIdentifier) {
395                    _beanIdentifier = beanIdentifier;
396            }
397    
398            protected Class<?> getModelClass() {
399                    return Account.class;
400            }
401    
402            protected String getModelClassName() {
403                    return Account.class.getName();
404            }
405    
406            /**
407             * Performs a SQL query.
408             *
409             * @param sql the sql query
410             */
411            protected void runSQL(String sql) {
412                    try {
413                            DataSource dataSource = accountPersistence.getDataSource();
414    
415                            DB db = DBFactoryUtil.getDB();
416    
417                            sql = db.buildSQL(sql);
418                            sql = PortalUtil.transformSQL(sql);
419    
420                            SqlUpdate sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(dataSource,
421                                            sql, new int[0]);
422    
423                            sqlUpdate.update();
424                    }
425                    catch (Exception e) {
426                            throw new SystemException(e);
427                    }
428            }
429    
430            @BeanReference(type = com.liferay.portal.service.AccountLocalService.class)
431            protected com.liferay.portal.service.AccountLocalService accountLocalService;
432            @BeanReference(type = com.liferay.portal.service.AccountService.class)
433            protected com.liferay.portal.service.AccountService accountService;
434            @BeanReference(type = AccountPersistence.class)
435            protected AccountPersistence accountPersistence;
436            @BeanReference(type = com.liferay.counter.service.CounterLocalService.class)
437            protected com.liferay.counter.service.CounterLocalService counterLocalService;
438            @BeanReference(type = PersistedModelLocalServiceRegistry.class)
439            protected PersistedModelLocalServiceRegistry persistedModelLocalServiceRegistry;
440            private String _beanIdentifier;
441    }