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.dao.db.DB;
021    import com.liferay.portal.kernel.dao.db.DBManagerUtil;
022    import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
023    import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
024    import com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery;
025    import com.liferay.portal.kernel.dao.orm.DefaultActionableDynamicQuery;
026    import com.liferay.portal.kernel.dao.orm.DynamicQuery;
027    import com.liferay.portal.kernel.dao.orm.DynamicQueryFactoryUtil;
028    import com.liferay.portal.kernel.dao.orm.IndexableActionableDynamicQuery;
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.module.framework.service.IdentifiableOSGiService;
033    import com.liferay.portal.kernel.search.Indexable;
034    import com.liferay.portal.kernel.search.IndexableType;
035    import com.liferay.portal.kernel.util.OrderByComparator;
036    import com.liferay.portal.model.Account;
037    import com.liferay.portal.model.PersistedModel;
038    import com.liferay.portal.service.AccountLocalService;
039    import com.liferay.portal.service.BaseLocalServiceImpl;
040    import com.liferay.portal.service.PersistedModelLocalServiceRegistry;
041    import com.liferay.portal.service.persistence.AccountPersistence;
042    import com.liferay.portal.util.PortalUtil;
043    
044    import java.io.Serializable;
045    
046    import java.util.List;
047    
048    import javax.sql.DataSource;
049    
050    /**
051     * Provides the base implementation for the account local service.
052     *
053     * <p>
054     * 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}.
055     * </p>
056     *
057     * @author Brian Wing Shun Chan
058     * @see com.liferay.portal.service.impl.AccountLocalServiceImpl
059     * @see com.liferay.portal.service.AccountLocalServiceUtil
060     * @generated
061     */
062    @ProviderType
063    public abstract class AccountLocalServiceBaseImpl extends BaseLocalServiceImpl
064            implements AccountLocalService, IdentifiableOSGiService {
065            /*
066             * NOTE FOR DEVELOPERS:
067             *
068             * Never modify or reference this class directly. Always use {@link com.liferay.portal.service.AccountLocalServiceUtil} to access the account local service.
069             */
070    
071            /**
072             * Adds the account to the database. Also notifies the appropriate model listeners.
073             *
074             * @param account the account
075             * @return the account that was added
076             */
077            @Indexable(type = IndexableType.REINDEX)
078            @Override
079            public Account addAccount(Account account) {
080                    account.setNew(true);
081    
082                    return accountPersistence.update(account);
083            }
084    
085            /**
086             * Creates a new account with the primary key. Does not add the account to the database.
087             *
088             * @param accountId the primary key for the new account
089             * @return the new account
090             */
091            @Override
092            public Account createAccount(long accountId) {
093                    return accountPersistence.create(accountId);
094            }
095    
096            /**
097             * Deletes the account with the primary key from the database. Also notifies the appropriate model listeners.
098             *
099             * @param accountId the primary key of the account
100             * @return the account that was removed
101             * @throws PortalException if a account with the primary key could not be found
102             */
103            @Indexable(type = IndexableType.DELETE)
104            @Override
105            public Account deleteAccount(long accountId) throws PortalException {
106                    return accountPersistence.remove(accountId);
107            }
108    
109            /**
110             * Deletes the account from the database. Also notifies the appropriate model listeners.
111             *
112             * @param account the account
113             * @return the account that was removed
114             */
115            @Indexable(type = IndexableType.DELETE)
116            @Override
117            public Account deleteAccount(Account account) {
118                    return accountPersistence.remove(account);
119            }
120    
121            @Override
122            public DynamicQuery dynamicQuery() {
123                    Class<?> clazz = getClass();
124    
125                    return DynamicQueryFactoryUtil.forClass(Account.class,
126                            clazz.getClassLoader());
127            }
128    
129            /**
130             * Performs a dynamic query on the database and returns the matching rows.
131             *
132             * @param dynamicQuery the dynamic query
133             * @return the matching rows
134             */
135            @Override
136            public <T> List<T> dynamicQuery(DynamicQuery dynamicQuery) {
137                    return accountPersistence.findWithDynamicQuery(dynamicQuery);
138            }
139    
140            /**
141             * Performs a dynamic query on the database and returns a range of the matching rows.
142             *
143             * <p>
144             * 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.
145             * </p>
146             *
147             * @param dynamicQuery the dynamic query
148             * @param start the lower bound of the range of model instances
149             * @param end the upper bound of the range of model instances (not inclusive)
150             * @return the range of matching rows
151             */
152            @Override
153            public <T> List<T> dynamicQuery(DynamicQuery dynamicQuery, int start,
154                    int end) {
155                    return accountPersistence.findWithDynamicQuery(dynamicQuery, start, end);
156            }
157    
158            /**
159             * Performs a dynamic query on the database and returns an ordered range of the matching rows.
160             *
161             * <p>
162             * 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.
163             * </p>
164             *
165             * @param dynamicQuery the dynamic query
166             * @param start the lower bound of the range of model instances
167             * @param end the upper bound of the range of model instances (not inclusive)
168             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
169             * @return the ordered range of matching rows
170             */
171            @Override
172            public <T> List<T> dynamicQuery(DynamicQuery dynamicQuery, int start,
173                    int end, OrderByComparator<T> orderByComparator) {
174                    return accountPersistence.findWithDynamicQuery(dynamicQuery, start,
175                            end, orderByComparator);
176            }
177    
178            /**
179             * Returns the number of rows matching the dynamic query.
180             *
181             * @param dynamicQuery the dynamic query
182             * @return the number of rows matching the dynamic query
183             */
184            @Override
185            public long dynamicQueryCount(DynamicQuery dynamicQuery) {
186                    return accountPersistence.countWithDynamicQuery(dynamicQuery);
187            }
188    
189            /**
190             * Returns the number of rows matching the dynamic query.
191             *
192             * @param dynamicQuery the dynamic query
193             * @param projection the projection to apply to the query
194             * @return the number of rows matching the dynamic query
195             */
196            @Override
197            public long dynamicQueryCount(DynamicQuery dynamicQuery,
198                    Projection projection) {
199                    return accountPersistence.countWithDynamicQuery(dynamicQuery, projection);
200            }
201    
202            @Override
203            public Account fetchAccount(long accountId) {
204                    return accountPersistence.fetchByPrimaryKey(accountId);
205            }
206    
207            /**
208             * Returns the account with the primary key.
209             *
210             * @param accountId the primary key of the account
211             * @return the account
212             * @throws PortalException if a account with the primary key could not be found
213             */
214            @Override
215            public Account getAccount(long accountId) throws PortalException {
216                    return accountPersistence.findByPrimaryKey(accountId);
217            }
218    
219            @Override
220            public ActionableDynamicQuery getActionableDynamicQuery() {
221                    ActionableDynamicQuery actionableDynamicQuery = new DefaultActionableDynamicQuery();
222    
223                    actionableDynamicQuery.setBaseLocalService(com.liferay.portal.service.AccountLocalServiceUtil.getService());
224                    actionableDynamicQuery.setClassLoader(getClassLoader());
225                    actionableDynamicQuery.setModelClass(Account.class);
226    
227                    actionableDynamicQuery.setPrimaryKeyPropertyName("accountId");
228    
229                    return actionableDynamicQuery;
230            }
231    
232            @Override
233            public IndexableActionableDynamicQuery getIndexableActionableDynamicQuery() {
234                    IndexableActionableDynamicQuery indexableActionableDynamicQuery = new IndexableActionableDynamicQuery();
235    
236                    indexableActionableDynamicQuery.setBaseLocalService(com.liferay.portal.service.AccountLocalServiceUtil.getService());
237                    indexableActionableDynamicQuery.setClassLoader(getClassLoader());
238                    indexableActionableDynamicQuery.setModelClass(Account.class);
239    
240                    indexableActionableDynamicQuery.setPrimaryKeyPropertyName("accountId");
241    
242                    return indexableActionableDynamicQuery;
243            }
244    
245            protected void initActionableDynamicQuery(
246                    ActionableDynamicQuery actionableDynamicQuery) {
247                    actionableDynamicQuery.setBaseLocalService(com.liferay.portal.service.AccountLocalServiceUtil.getService());
248                    actionableDynamicQuery.setClassLoader(getClassLoader());
249                    actionableDynamicQuery.setModelClass(Account.class);
250    
251                    actionableDynamicQuery.setPrimaryKeyPropertyName("accountId");
252            }
253    
254            /**
255             * @throws PortalException
256             */
257            @Override
258            public PersistedModel deletePersistedModel(PersistedModel persistedModel)
259                    throws PortalException {
260                    return accountLocalService.deleteAccount((Account)persistedModel);
261            }
262    
263            @Override
264            public PersistedModel getPersistedModel(Serializable primaryKeyObj)
265                    throws PortalException {
266                    return accountPersistence.findByPrimaryKey(primaryKeyObj);
267            }
268    
269            /**
270             * Returns a range of all the accounts.
271             *
272             * <p>
273             * 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.
274             * </p>
275             *
276             * @param start the lower bound of the range of accounts
277             * @param end the upper bound of the range of accounts (not inclusive)
278             * @return the range of accounts
279             */
280            @Override
281            public List<Account> getAccounts(int start, int end) {
282                    return accountPersistence.findAll(start, end);
283            }
284    
285            /**
286             * Returns the number of accounts.
287             *
288             * @return the number of accounts
289             */
290            @Override
291            public int getAccountsCount() {
292                    return accountPersistence.countAll();
293            }
294    
295            /**
296             * Updates the account in the database or adds it if it does not yet exist. Also notifies the appropriate model listeners.
297             *
298             * @param account the account
299             * @return the account that was updated
300             */
301            @Indexable(type = IndexableType.REINDEX)
302            @Override
303            public Account updateAccount(Account account) {
304                    return accountPersistence.update(account);
305            }
306    
307            /**
308             * Returns the account local service.
309             *
310             * @return the account local service
311             */
312            public AccountLocalService getAccountLocalService() {
313                    return accountLocalService;
314            }
315    
316            /**
317             * Sets the account local service.
318             *
319             * @param accountLocalService the account local service
320             */
321            public void setAccountLocalService(AccountLocalService accountLocalService) {
322                    this.accountLocalService = accountLocalService;
323            }
324    
325            /**
326             * Returns the account persistence.
327             *
328             * @return the account persistence
329             */
330            public AccountPersistence getAccountPersistence() {
331                    return accountPersistence;
332            }
333    
334            /**
335             * Sets the account persistence.
336             *
337             * @param accountPersistence the account persistence
338             */
339            public void setAccountPersistence(AccountPersistence accountPersistence) {
340                    this.accountPersistence = accountPersistence;
341            }
342    
343            /**
344             * Returns the counter local service.
345             *
346             * @return the counter local service
347             */
348            public com.liferay.counter.service.CounterLocalService getCounterLocalService() {
349                    return counterLocalService;
350            }
351    
352            /**
353             * Sets the counter local service.
354             *
355             * @param counterLocalService the counter local service
356             */
357            public void setCounterLocalService(
358                    com.liferay.counter.service.CounterLocalService counterLocalService) {
359                    this.counterLocalService = counterLocalService;
360            }
361    
362            public void afterPropertiesSet() {
363                    persistedModelLocalServiceRegistry.register("com.liferay.portal.model.Account",
364                            accountLocalService);
365            }
366    
367            public void destroy() {
368                    persistedModelLocalServiceRegistry.unregister(
369                            "com.liferay.portal.model.Account");
370            }
371    
372            /**
373             * Returns the OSGi service identifier.
374             *
375             * @return the OSGi service identifier
376             */
377            @Override
378            public String getOSGiServiceIdentifier() {
379                    return AccountLocalService.class.getName();
380            }
381    
382            protected Class<?> getModelClass() {
383                    return Account.class;
384            }
385    
386            protected String getModelClassName() {
387                    return Account.class.getName();
388            }
389    
390            /**
391             * Performs a SQL query.
392             *
393             * @param sql the sql query
394             */
395            protected void runSQL(String sql) {
396                    try {
397                            DataSource dataSource = accountPersistence.getDataSource();
398    
399                            DB db = DBManagerUtil.getDB();
400    
401                            sql = db.buildSQL(sql);
402                            sql = PortalUtil.transformSQL(sql);
403    
404                            SqlUpdate sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(dataSource,
405                                            sql, new int[0]);
406    
407                            sqlUpdate.update();
408                    }
409                    catch (Exception e) {
410                            throw new SystemException(e);
411                    }
412            }
413    
414            @BeanReference(type = com.liferay.portal.service.AccountLocalService.class)
415            protected AccountLocalService accountLocalService;
416            @BeanReference(type = AccountPersistence.class)
417            protected AccountPersistence accountPersistence;
418            @BeanReference(type = com.liferay.counter.service.CounterLocalService.class)
419            protected com.liferay.counter.service.CounterLocalService counterLocalService;
420            @BeanReference(type = PersistedModelLocalServiceRegistry.class)
421            protected PersistedModelLocalServiceRegistry persistedModelLocalServiceRegistry;
422    }