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