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