001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.base;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.kernel.bean.BeanReference;
020    import com.liferay.portal.kernel.bean.IdentifiableBean;
021    import com.liferay.portal.kernel.dao.db.DB;
022    import com.liferay.portal.kernel.dao.db.DBFactoryUtil;
023    import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
024    import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
025    import com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery;
026    import com.liferay.portal.kernel.dao.orm.DefaultActionableDynamicQuery;
027    import com.liferay.portal.kernel.dao.orm.DynamicQuery;
028    import com.liferay.portal.kernel.dao.orm.DynamicQueryFactoryUtil;
029    import com.liferay.portal.kernel.dao.orm.Projection;
030    import com.liferay.portal.kernel.exception.PortalException;
031    import com.liferay.portal.kernel.exception.SystemException;
032    import com.liferay.portal.kernel.search.Indexable;
033    import com.liferay.portal.kernel.search.IndexableType;
034    import com.liferay.portal.kernel.util.OrderByComparator;
035    import com.liferay.portal.model.PersistedModel;
036    import com.liferay.portal.model.Shard;
037    import com.liferay.portal.service.BaseLocalServiceImpl;
038    import com.liferay.portal.service.PersistedModelLocalServiceRegistry;
039    import com.liferay.portal.service.ShardLocalService;
040    import com.liferay.portal.service.persistence.ClassNamePersistence;
041    import com.liferay.portal.service.persistence.ShardPersistence;
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 shard 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.ShardLocalServiceImpl}.
055     * </p>
056     *
057     * @author Brian Wing Shun Chan
058     * @see com.liferay.portal.service.impl.ShardLocalServiceImpl
059     * @see com.liferay.portal.service.ShardLocalServiceUtil
060     * @generated
061     */
062    @ProviderType
063    public abstract class ShardLocalServiceBaseImpl extends BaseLocalServiceImpl
064            implements ShardLocalService, IdentifiableBean {
065            /*
066             * NOTE FOR DEVELOPERS:
067             *
068             * Never modify or reference this class directly. Always use {@link com.liferay.portal.service.ShardLocalServiceUtil} to access the shard local service.
069             */
070    
071            /**
072             * Adds the shard to the database. Also notifies the appropriate model listeners.
073             *
074             * @param shard the shard
075             * @return the shard that was added
076             */
077            @Indexable(type = IndexableType.REINDEX)
078            @Override
079            public Shard addShard(Shard shard) {
080                    shard.setNew(true);
081    
082                    return shardPersistence.update(shard);
083            }
084    
085            /**
086             * Creates a new shard with the primary key. Does not add the shard to the database.
087             *
088             * @param shardId the primary key for the new shard
089             * @return the new shard
090             */
091            @Override
092            public Shard createShard(long shardId) {
093                    return shardPersistence.create(shardId);
094            }
095    
096            /**
097             * Deletes the shard with the primary key from the database. Also notifies the appropriate model listeners.
098             *
099             * @param shardId the primary key of the shard
100             * @return the shard that was removed
101             * @throws PortalException if a shard with the primary key could not be found
102             */
103            @Indexable(type = IndexableType.DELETE)
104            @Override
105            public Shard deleteShard(long shardId) throws PortalException {
106                    return shardPersistence.remove(shardId);
107            }
108    
109            /**
110             * Deletes the shard from the database. Also notifies the appropriate model listeners.
111             *
112             * @param shard the shard
113             * @return the shard that was removed
114             */
115            @Indexable(type = IndexableType.DELETE)
116            @Override
117            public Shard deleteShard(Shard shard) {
118                    return shardPersistence.remove(shard);
119            }
120    
121            @Override
122            public DynamicQuery dynamicQuery() {
123                    Class<?> clazz = getClass();
124    
125                    return DynamicQueryFactoryUtil.forClass(Shard.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 shardPersistence.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.ShardModelImpl}. 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 shardPersistence.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.ShardModelImpl}. 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 shardPersistence.findWithDynamicQuery(dynamicQuery, start, end,
175                            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 shardPersistence.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 shardPersistence.countWithDynamicQuery(dynamicQuery, projection);
200            }
201    
202            @Override
203            public Shard fetchShard(long shardId) {
204                    return shardPersistence.fetchByPrimaryKey(shardId);
205            }
206    
207            /**
208             * Returns the shard with the primary key.
209             *
210             * @param shardId the primary key of the shard
211             * @return the shard
212             * @throws PortalException if a shard with the primary key could not be found
213             */
214            @Override
215            public Shard getShard(long shardId) throws PortalException {
216                    return shardPersistence.findByPrimaryKey(shardId);
217            }
218    
219            @Override
220            public ActionableDynamicQuery getActionableDynamicQuery() {
221                    ActionableDynamicQuery actionableDynamicQuery = new DefaultActionableDynamicQuery();
222    
223                    actionableDynamicQuery.setBaseLocalService(com.liferay.portal.service.ShardLocalServiceUtil.getService());
224                    actionableDynamicQuery.setClass(Shard.class);
225                    actionableDynamicQuery.setClassLoader(getClassLoader());
226    
227                    actionableDynamicQuery.setPrimaryKeyPropertyName("shardId");
228    
229                    return actionableDynamicQuery;
230            }
231    
232            protected void initActionableDynamicQuery(
233                    ActionableDynamicQuery actionableDynamicQuery) {
234                    actionableDynamicQuery.setBaseLocalService(com.liferay.portal.service.ShardLocalServiceUtil.getService());
235                    actionableDynamicQuery.setClass(Shard.class);
236                    actionableDynamicQuery.setClassLoader(getClassLoader());
237    
238                    actionableDynamicQuery.setPrimaryKeyPropertyName("shardId");
239            }
240    
241            /**
242             * @throws PortalException
243             */
244            @Override
245            public PersistedModel deletePersistedModel(PersistedModel persistedModel)
246                    throws PortalException {
247                    return shardLocalService.deleteShard((Shard)persistedModel);
248            }
249    
250            @Override
251            public PersistedModel getPersistedModel(Serializable primaryKeyObj)
252                    throws PortalException {
253                    return shardPersistence.findByPrimaryKey(primaryKeyObj);
254            }
255    
256            /**
257             * Returns a range of all the shards.
258             *
259             * <p>
260             * 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.ShardModelImpl}. 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.
261             * </p>
262             *
263             * @param start the lower bound of the range of shards
264             * @param end the upper bound of the range of shards (not inclusive)
265             * @return the range of shards
266             */
267            @Override
268            public List<Shard> getShards(int start, int end) {
269                    return shardPersistence.findAll(start, end);
270            }
271    
272            /**
273             * Returns the number of shards.
274             *
275             * @return the number of shards
276             */
277            @Override
278            public int getShardsCount() {
279                    return shardPersistence.countAll();
280            }
281    
282            /**
283             * Updates the shard in the database or adds it if it does not yet exist. Also notifies the appropriate model listeners.
284             *
285             * @param shard the shard
286             * @return the shard that was updated
287             */
288            @Indexable(type = IndexableType.REINDEX)
289            @Override
290            public Shard updateShard(Shard shard) {
291                    return shardPersistence.update(shard);
292            }
293    
294            /**
295             * Returns the shard local service.
296             *
297             * @return the shard local service
298             */
299            public ShardLocalService getShardLocalService() {
300                    return shardLocalService;
301            }
302    
303            /**
304             * Sets the shard local service.
305             *
306             * @param shardLocalService the shard local service
307             */
308            public void setShardLocalService(ShardLocalService shardLocalService) {
309                    this.shardLocalService = shardLocalService;
310            }
311    
312            /**
313             * Returns the shard persistence.
314             *
315             * @return the shard persistence
316             */
317            public ShardPersistence getShardPersistence() {
318                    return shardPersistence;
319            }
320    
321            /**
322             * Sets the shard persistence.
323             *
324             * @param shardPersistence the shard persistence
325             */
326            public void setShardPersistence(ShardPersistence shardPersistence) {
327                    this.shardPersistence = shardPersistence;
328            }
329    
330            /**
331             * Returns the counter local service.
332             *
333             * @return the counter local service
334             */
335            public com.liferay.counter.service.CounterLocalService getCounterLocalService() {
336                    return counterLocalService;
337            }
338    
339            /**
340             * Sets the counter local service.
341             *
342             * @param counterLocalService the counter local service
343             */
344            public void setCounterLocalService(
345                    com.liferay.counter.service.CounterLocalService counterLocalService) {
346                    this.counterLocalService = counterLocalService;
347            }
348    
349            /**
350             * Returns the class name local service.
351             *
352             * @return the class name local service
353             */
354            public com.liferay.portal.service.ClassNameLocalService getClassNameLocalService() {
355                    return classNameLocalService;
356            }
357    
358            /**
359             * Sets the class name local service.
360             *
361             * @param classNameLocalService the class name local service
362             */
363            public void setClassNameLocalService(
364                    com.liferay.portal.service.ClassNameLocalService classNameLocalService) {
365                    this.classNameLocalService = classNameLocalService;
366            }
367    
368            /**
369             * Returns the class name remote service.
370             *
371             * @return the class name remote service
372             */
373            public com.liferay.portal.service.ClassNameService getClassNameService() {
374                    return classNameService;
375            }
376    
377            /**
378             * Sets the class name remote service.
379             *
380             * @param classNameService the class name remote service
381             */
382            public void setClassNameService(
383                    com.liferay.portal.service.ClassNameService classNameService) {
384                    this.classNameService = classNameService;
385            }
386    
387            /**
388             * Returns the class name persistence.
389             *
390             * @return the class name persistence
391             */
392            public ClassNamePersistence getClassNamePersistence() {
393                    return classNamePersistence;
394            }
395    
396            /**
397             * Sets the class name persistence.
398             *
399             * @param classNamePersistence the class name persistence
400             */
401            public void setClassNamePersistence(
402                    ClassNamePersistence classNamePersistence) {
403                    this.classNamePersistence = classNamePersistence;
404            }
405    
406            public void afterPropertiesSet() {
407                    persistedModelLocalServiceRegistry.register("com.liferay.portal.model.Shard",
408                            shardLocalService);
409            }
410    
411            public void destroy() {
412                    persistedModelLocalServiceRegistry.unregister(
413                            "com.liferay.portal.model.Shard");
414            }
415    
416            /**
417             * Returns the Spring bean ID for this bean.
418             *
419             * @return the Spring bean ID for this bean
420             */
421            @Override
422            public String getBeanIdentifier() {
423                    return _beanIdentifier;
424            }
425    
426            /**
427             * Sets the Spring bean ID for this bean.
428             *
429             * @param beanIdentifier the Spring bean ID for this bean
430             */
431            @Override
432            public void setBeanIdentifier(String beanIdentifier) {
433                    _beanIdentifier = beanIdentifier;
434            }
435    
436            protected Class<?> getModelClass() {
437                    return Shard.class;
438            }
439    
440            protected String getModelClassName() {
441                    return Shard.class.getName();
442            }
443    
444            /**
445             * Performs a SQL query.
446             *
447             * @param sql the sql query
448             */
449            protected void runSQL(String sql) {
450                    try {
451                            DataSource dataSource = shardPersistence.getDataSource();
452    
453                            DB db = DBFactoryUtil.getDB();
454    
455                            sql = db.buildSQL(sql);
456                            sql = PortalUtil.transformSQL(sql);
457    
458                            SqlUpdate sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(dataSource,
459                                            sql, new int[0]);
460    
461                            sqlUpdate.update();
462                    }
463                    catch (Exception e) {
464                            throw new SystemException(e);
465                    }
466            }
467    
468            @BeanReference(type = ShardLocalService.class)
469            protected ShardLocalService shardLocalService;
470            @BeanReference(type = ShardPersistence.class)
471            protected ShardPersistence shardPersistence;
472            @BeanReference(type = com.liferay.counter.service.CounterLocalService.class)
473            protected com.liferay.counter.service.CounterLocalService counterLocalService;
474            @BeanReference(type = com.liferay.portal.service.ClassNameLocalService.class)
475            protected com.liferay.portal.service.ClassNameLocalService classNameLocalService;
476            @BeanReference(type = com.liferay.portal.service.ClassNameService.class)
477            protected com.liferay.portal.service.ClassNameService classNameService;
478            @BeanReference(type = ClassNamePersistence.class)
479            protected ClassNamePersistence classNamePersistence;
480            @BeanReference(type = PersistedModelLocalServiceRegistry.class)
481            protected PersistedModelLocalServiceRegistry persistedModelLocalServiceRegistry;
482            private String _beanIdentifier;
483    }