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.PersistedModel;
037    import com.liferay.portal.model.PortletPreferences;
038    import com.liferay.portal.service.BaseLocalServiceImpl;
039    import com.liferay.portal.service.PersistedModelLocalServiceRegistry;
040    import com.liferay.portal.service.PortletPreferencesLocalService;
041    import com.liferay.portal.service.persistence.PortletItemPersistence;
042    import com.liferay.portal.service.persistence.PortletPersistence;
043    import com.liferay.portal.service.persistence.PortletPreferencesFinder;
044    import com.liferay.portal.service.persistence.PortletPreferencesPersistence;
045    import com.liferay.portal.util.PortalUtil;
046    
047    import java.io.Serializable;
048    
049    import java.util.List;
050    
051    import javax.sql.DataSource;
052    
053    /**
054     * Provides the base implementation for the portlet preferences local service.
055     *
056     * <p>
057     * 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.PortletPreferencesLocalServiceImpl}.
058     * </p>
059     *
060     * @author Brian Wing Shun Chan
061     * @see com.liferay.portal.service.impl.PortletPreferencesLocalServiceImpl
062     * @see com.liferay.portal.service.PortletPreferencesLocalServiceUtil
063     * @generated
064     */
065    @ProviderType
066    public abstract class PortletPreferencesLocalServiceBaseImpl
067            extends BaseLocalServiceImpl implements PortletPreferencesLocalService,
068                    IdentifiableOSGiService {
069            /*
070             * NOTE FOR DEVELOPERS:
071             *
072             * Never modify or reference this class directly. Always use {@link com.liferay.portal.service.PortletPreferencesLocalServiceUtil} to access the portlet preferences local service.
073             */
074    
075            /**
076             * Adds the portlet preferences to the database. Also notifies the appropriate model listeners.
077             *
078             * @param portletPreferences the portlet preferences
079             * @return the portlet preferences that was added
080             */
081            @Indexable(type = IndexableType.REINDEX)
082            @Override
083            public PortletPreferences addPortletPreferences(
084                    PortletPreferences portletPreferences) {
085                    portletPreferences.setNew(true);
086    
087                    return portletPreferencesPersistence.update(portletPreferences);
088            }
089    
090            /**
091             * Creates a new portlet preferences with the primary key. Does not add the portlet preferences to the database.
092             *
093             * @param portletPreferencesId the primary key for the new portlet preferences
094             * @return the new portlet preferences
095             */
096            @Override
097            public PortletPreferences createPortletPreferences(
098                    long portletPreferencesId) {
099                    return portletPreferencesPersistence.create(portletPreferencesId);
100            }
101    
102            /**
103             * Deletes the portlet preferences with the primary key from the database. Also notifies the appropriate model listeners.
104             *
105             * @param portletPreferencesId the primary key of the portlet preferences
106             * @return the portlet preferences that was removed
107             * @throws PortalException if a portlet preferences with the primary key could not be found
108             */
109            @Indexable(type = IndexableType.DELETE)
110            @Override
111            public PortletPreferences deletePortletPreferences(
112                    long portletPreferencesId) throws PortalException {
113                    return portletPreferencesPersistence.remove(portletPreferencesId);
114            }
115    
116            /**
117             * Deletes the portlet preferences from the database. Also notifies the appropriate model listeners.
118             *
119             * @param portletPreferences the portlet preferences
120             * @return the portlet preferences that was removed
121             */
122            @Indexable(type = IndexableType.DELETE)
123            @Override
124            public PortletPreferences deletePortletPreferences(
125                    PortletPreferences portletPreferences) {
126                    return portletPreferencesPersistence.remove(portletPreferences);
127            }
128    
129            @Override
130            public DynamicQuery dynamicQuery() {
131                    Class<?> clazz = getClass();
132    
133                    return DynamicQueryFactoryUtil.forClass(PortletPreferences.class,
134                            clazz.getClassLoader());
135            }
136    
137            /**
138             * Performs a dynamic query on the database and returns the matching rows.
139             *
140             * @param dynamicQuery the dynamic query
141             * @return the matching rows
142             */
143            @Override
144            public <T> List<T> dynamicQuery(DynamicQuery dynamicQuery) {
145                    return portletPreferencesPersistence.findWithDynamicQuery(dynamicQuery);
146            }
147    
148            /**
149             * Performs a dynamic query on the database and returns a range of the matching rows.
150             *
151             * <p>
152             * 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.PortletPreferencesModelImpl}. 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.
153             * </p>
154             *
155             * @param dynamicQuery the dynamic query
156             * @param start the lower bound of the range of model instances
157             * @param end the upper bound of the range of model instances (not inclusive)
158             * @return the range of matching rows
159             */
160            @Override
161            public <T> List<T> dynamicQuery(DynamicQuery dynamicQuery, int start,
162                    int end) {
163                    return portletPreferencesPersistence.findWithDynamicQuery(dynamicQuery,
164                            start, end);
165            }
166    
167            /**
168             * Performs a dynamic query on the database and returns an ordered range of the matching rows.
169             *
170             * <p>
171             * 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.PortletPreferencesModelImpl}. 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.
172             * </p>
173             *
174             * @param dynamicQuery the dynamic query
175             * @param start the lower bound of the range of model instances
176             * @param end the upper bound of the range of model instances (not inclusive)
177             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
178             * @return the ordered range of matching rows
179             */
180            @Override
181            public <T> List<T> dynamicQuery(DynamicQuery dynamicQuery, int start,
182                    int end, OrderByComparator<T> orderByComparator) {
183                    return portletPreferencesPersistence.findWithDynamicQuery(dynamicQuery,
184                            start, end, orderByComparator);
185            }
186    
187            /**
188             * Returns the number of rows matching the dynamic query.
189             *
190             * @param dynamicQuery the dynamic query
191             * @return the number of rows matching the dynamic query
192             */
193            @Override
194            public long dynamicQueryCount(DynamicQuery dynamicQuery) {
195                    return portletPreferencesPersistence.countWithDynamicQuery(dynamicQuery);
196            }
197    
198            /**
199             * Returns the number of rows matching the dynamic query.
200             *
201             * @param dynamicQuery the dynamic query
202             * @param projection the projection to apply to the query
203             * @return the number of rows matching the dynamic query
204             */
205            @Override
206            public long dynamicQueryCount(DynamicQuery dynamicQuery,
207                    Projection projection) {
208                    return portletPreferencesPersistence.countWithDynamicQuery(dynamicQuery,
209                            projection);
210            }
211    
212            @Override
213            public PortletPreferences fetchPortletPreferences(long portletPreferencesId) {
214                    return portletPreferencesPersistence.fetchByPrimaryKey(portletPreferencesId);
215            }
216    
217            /**
218             * Returns the portlet preferences with the primary key.
219             *
220             * @param portletPreferencesId the primary key of the portlet preferences
221             * @return the portlet preferences
222             * @throws PortalException if a portlet preferences with the primary key could not be found
223             */
224            @Override
225            public PortletPreferences getPortletPreferences(long portletPreferencesId)
226                    throws PortalException {
227                    return portletPreferencesPersistence.findByPrimaryKey(portletPreferencesId);
228            }
229    
230            @Override
231            public ActionableDynamicQuery getActionableDynamicQuery() {
232                    ActionableDynamicQuery actionableDynamicQuery = new DefaultActionableDynamicQuery();
233    
234                    actionableDynamicQuery.setBaseLocalService(com.liferay.portal.service.PortletPreferencesLocalServiceUtil.getService());
235                    actionableDynamicQuery.setClassLoader(getClassLoader());
236                    actionableDynamicQuery.setModelClass(PortletPreferences.class);
237    
238                    actionableDynamicQuery.setPrimaryKeyPropertyName("portletPreferencesId");
239    
240                    return actionableDynamicQuery;
241            }
242    
243            @Override
244            public IndexableActionableDynamicQuery getIndexableActionableDynamicQuery() {
245                    IndexableActionableDynamicQuery indexableActionableDynamicQuery = new IndexableActionableDynamicQuery();
246    
247                    indexableActionableDynamicQuery.setBaseLocalService(com.liferay.portal.service.PortletPreferencesLocalServiceUtil.getService());
248                    indexableActionableDynamicQuery.setClassLoader(getClassLoader());
249                    indexableActionableDynamicQuery.setModelClass(PortletPreferences.class);
250    
251                    indexableActionableDynamicQuery.setPrimaryKeyPropertyName(
252                            "portletPreferencesId");
253    
254                    return indexableActionableDynamicQuery;
255            }
256    
257            protected void initActionableDynamicQuery(
258                    ActionableDynamicQuery actionableDynamicQuery) {
259                    actionableDynamicQuery.setBaseLocalService(com.liferay.portal.service.PortletPreferencesLocalServiceUtil.getService());
260                    actionableDynamicQuery.setClassLoader(getClassLoader());
261                    actionableDynamicQuery.setModelClass(PortletPreferences.class);
262    
263                    actionableDynamicQuery.setPrimaryKeyPropertyName("portletPreferencesId");
264            }
265    
266            /**
267             * @throws PortalException
268             */
269            @Override
270            public PersistedModel deletePersistedModel(PersistedModel persistedModel)
271                    throws PortalException {
272                    return portletPreferencesLocalService.deletePortletPreferences((PortletPreferences)persistedModel);
273            }
274    
275            @Override
276            public PersistedModel getPersistedModel(Serializable primaryKeyObj)
277                    throws PortalException {
278                    return portletPreferencesPersistence.findByPrimaryKey(primaryKeyObj);
279            }
280    
281            /**
282             * Returns a range of all the portlet preferenceses.
283             *
284             * <p>
285             * 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.PortletPreferencesModelImpl}. 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.
286             * </p>
287             *
288             * @param start the lower bound of the range of portlet preferenceses
289             * @param end the upper bound of the range of portlet preferenceses (not inclusive)
290             * @return the range of portlet preferenceses
291             */
292            @Override
293            public List<PortletPreferences> getPortletPreferenceses(int start, int end) {
294                    return portletPreferencesPersistence.findAll(start, end);
295            }
296    
297            /**
298             * Returns the number of portlet preferenceses.
299             *
300             * @return the number of portlet preferenceses
301             */
302            @Override
303            public int getPortletPreferencesesCount() {
304                    return portletPreferencesPersistence.countAll();
305            }
306    
307            /**
308             * Updates the portlet preferences in the database or adds it if it does not yet exist. Also notifies the appropriate model listeners.
309             *
310             * @param portletPreferences the portlet preferences
311             * @return the portlet preferences that was updated
312             */
313            @Indexable(type = IndexableType.REINDEX)
314            @Override
315            public PortletPreferences updatePortletPreferences(
316                    PortletPreferences portletPreferences) {
317                    return portletPreferencesPersistence.update(portletPreferences);
318            }
319    
320            /**
321             * Returns the portlet preferences local service.
322             *
323             * @return the portlet preferences local service
324             */
325            public PortletPreferencesLocalService getPortletPreferencesLocalService() {
326                    return portletPreferencesLocalService;
327            }
328    
329            /**
330             * Sets the portlet preferences local service.
331             *
332             * @param portletPreferencesLocalService the portlet preferences local service
333             */
334            public void setPortletPreferencesLocalService(
335                    PortletPreferencesLocalService portletPreferencesLocalService) {
336                    this.portletPreferencesLocalService = portletPreferencesLocalService;
337            }
338    
339            /**
340             * Returns the portlet preferences persistence.
341             *
342             * @return the portlet preferences persistence
343             */
344            public PortletPreferencesPersistence getPortletPreferencesPersistence() {
345                    return portletPreferencesPersistence;
346            }
347    
348            /**
349             * Sets the portlet preferences persistence.
350             *
351             * @param portletPreferencesPersistence the portlet preferences persistence
352             */
353            public void setPortletPreferencesPersistence(
354                    PortletPreferencesPersistence portletPreferencesPersistence) {
355                    this.portletPreferencesPersistence = portletPreferencesPersistence;
356            }
357    
358            /**
359             * Returns the portlet preferences finder.
360             *
361             * @return the portlet preferences finder
362             */
363            public PortletPreferencesFinder getPortletPreferencesFinder() {
364                    return portletPreferencesFinder;
365            }
366    
367            /**
368             * Sets the portlet preferences finder.
369             *
370             * @param portletPreferencesFinder the portlet preferences finder
371             */
372            public void setPortletPreferencesFinder(
373                    PortletPreferencesFinder portletPreferencesFinder) {
374                    this.portletPreferencesFinder = portletPreferencesFinder;
375            }
376    
377            /**
378             * Returns the counter local service.
379             *
380             * @return the counter local service
381             */
382            public com.liferay.counter.service.CounterLocalService getCounterLocalService() {
383                    return counterLocalService;
384            }
385    
386            /**
387             * Sets the counter local service.
388             *
389             * @param counterLocalService the counter local service
390             */
391            public void setCounterLocalService(
392                    com.liferay.counter.service.CounterLocalService counterLocalService) {
393                    this.counterLocalService = counterLocalService;
394            }
395    
396            /**
397             * Returns the portlet local service.
398             *
399             * @return the portlet local service
400             */
401            public com.liferay.portal.service.PortletLocalService getPortletLocalService() {
402                    return portletLocalService;
403            }
404    
405            /**
406             * Sets the portlet local service.
407             *
408             * @param portletLocalService the portlet local service
409             */
410            public void setPortletLocalService(
411                    com.liferay.portal.service.PortletLocalService portletLocalService) {
412                    this.portletLocalService = portletLocalService;
413            }
414    
415            /**
416             * Returns the portlet persistence.
417             *
418             * @return the portlet persistence
419             */
420            public PortletPersistence getPortletPersistence() {
421                    return portletPersistence;
422            }
423    
424            /**
425             * Sets the portlet persistence.
426             *
427             * @param portletPersistence the portlet persistence
428             */
429            public void setPortletPersistence(PortletPersistence portletPersistence) {
430                    this.portletPersistence = portletPersistence;
431            }
432    
433            /**
434             * Returns the portlet item local service.
435             *
436             * @return the portlet item local service
437             */
438            public com.liferay.portal.service.PortletItemLocalService getPortletItemLocalService() {
439                    return portletItemLocalService;
440            }
441    
442            /**
443             * Sets the portlet item local service.
444             *
445             * @param portletItemLocalService the portlet item local service
446             */
447            public void setPortletItemLocalService(
448                    com.liferay.portal.service.PortletItemLocalService portletItemLocalService) {
449                    this.portletItemLocalService = portletItemLocalService;
450            }
451    
452            /**
453             * Returns the portlet item persistence.
454             *
455             * @return the portlet item persistence
456             */
457            public PortletItemPersistence getPortletItemPersistence() {
458                    return portletItemPersistence;
459            }
460    
461            /**
462             * Sets the portlet item persistence.
463             *
464             * @param portletItemPersistence the portlet item persistence
465             */
466            public void setPortletItemPersistence(
467                    PortletItemPersistence portletItemPersistence) {
468                    this.portletItemPersistence = portletItemPersistence;
469            }
470    
471            public void afterPropertiesSet() {
472                    persistedModelLocalServiceRegistry.register("com.liferay.portal.model.PortletPreferences",
473                            portletPreferencesLocalService);
474            }
475    
476            public void destroy() {
477                    persistedModelLocalServiceRegistry.unregister(
478                            "com.liferay.portal.model.PortletPreferences");
479            }
480    
481            /**
482             * Returns the OSGi service identifier.
483             *
484             * @return the OSGi service identifier
485             */
486            @Override
487            public String getOSGiServiceIdentifier() {
488                    return PortletPreferencesLocalService.class.getName();
489            }
490    
491            protected Class<?> getModelClass() {
492                    return PortletPreferences.class;
493            }
494    
495            protected String getModelClassName() {
496                    return PortletPreferences.class.getName();
497            }
498    
499            /**
500             * Performs a SQL query.
501             *
502             * @param sql the sql query
503             */
504            protected void runSQL(String sql) {
505                    try {
506                            DataSource dataSource = portletPreferencesPersistence.getDataSource();
507    
508                            DB db = DBManagerUtil.getDB();
509    
510                            sql = db.buildSQL(sql);
511                            sql = PortalUtil.transformSQL(sql);
512    
513                            SqlUpdate sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(dataSource,
514                                            sql, new int[0]);
515    
516                            sqlUpdate.update();
517                    }
518                    catch (Exception e) {
519                            throw new SystemException(e);
520                    }
521            }
522    
523            @BeanReference(type = com.liferay.portal.service.PortletPreferencesLocalService.class)
524            protected PortletPreferencesLocalService portletPreferencesLocalService;
525            @BeanReference(type = PortletPreferencesPersistence.class)
526            protected PortletPreferencesPersistence portletPreferencesPersistence;
527            @BeanReference(type = PortletPreferencesFinder.class)
528            protected PortletPreferencesFinder portletPreferencesFinder;
529            @BeanReference(type = com.liferay.counter.service.CounterLocalService.class)
530            protected com.liferay.counter.service.CounterLocalService counterLocalService;
531            @BeanReference(type = com.liferay.portal.service.PortletLocalService.class)
532            protected com.liferay.portal.service.PortletLocalService portletLocalService;
533            @BeanReference(type = PortletPersistence.class)
534            protected PortletPersistence portletPersistence;
535            @BeanReference(type = com.liferay.portal.service.PortletItemLocalService.class)
536            protected com.liferay.portal.service.PortletItemLocalService portletItemLocalService;
537            @BeanReference(type = PortletItemPersistence.class)
538            protected PortletItemPersistence portletItemPersistence;
539            @BeanReference(type = PersistedModelLocalServiceRegistry.class)
540            protected PersistedModelLocalServiceRegistry persistedModelLocalServiceRegistry;
541    }