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 com.liferay.portal.service.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(
309                    com.liferay.portal.service.ShardLocalService shardLocalService) {
310                    this.shardLocalService = shardLocalService;
311            }
312    
313            /**
314             * Returns the shard persistence.
315             *
316             * @return the shard persistence
317             */
318            public ShardPersistence getShardPersistence() {
319                    return shardPersistence;
320            }
321    
322            /**
323             * Sets the shard persistence.
324             *
325             * @param shardPersistence the shard persistence
326             */
327            public void setShardPersistence(ShardPersistence shardPersistence) {
328                    this.shardPersistence = shardPersistence;
329            }
330    
331            /**
332             * Returns the counter local service.
333             *
334             * @return the counter local service
335             */
336            public com.liferay.counter.service.CounterLocalService getCounterLocalService() {
337                    return counterLocalService;
338            }
339    
340            /**
341             * Sets the counter local service.
342             *
343             * @param counterLocalService the counter local service
344             */
345            public void setCounterLocalService(
346                    com.liferay.counter.service.CounterLocalService counterLocalService) {
347                    this.counterLocalService = counterLocalService;
348            }
349    
350            /**
351             * Returns the class name local service.
352             *
353             * @return the class name local service
354             */
355            public com.liferay.portal.service.ClassNameLocalService getClassNameLocalService() {
356                    return classNameLocalService;
357            }
358    
359            /**
360             * Sets the class name local service.
361             *
362             * @param classNameLocalService the class name local service
363             */
364            public void setClassNameLocalService(
365                    com.liferay.portal.service.ClassNameLocalService classNameLocalService) {
366                    this.classNameLocalService = classNameLocalService;
367            }
368    
369            /**
370             * Returns the class name remote service.
371             *
372             * @return the class name remote service
373             */
374            public com.liferay.portal.service.ClassNameService getClassNameService() {
375                    return classNameService;
376            }
377    
378            /**
379             * Sets the class name remote service.
380             *
381             * @param classNameService the class name remote service
382             */
383            public void setClassNameService(
384                    com.liferay.portal.service.ClassNameService classNameService) {
385                    this.classNameService = classNameService;
386            }
387    
388            /**
389             * Returns the class name persistence.
390             *
391             * @return the class name persistence
392             */
393            public ClassNamePersistence getClassNamePersistence() {
394                    return classNamePersistence;
395            }
396    
397            /**
398             * Sets the class name persistence.
399             *
400             * @param classNamePersistence the class name persistence
401             */
402            public void setClassNamePersistence(
403                    ClassNamePersistence classNamePersistence) {
404                    this.classNamePersistence = classNamePersistence;
405            }
406    
407            public void afterPropertiesSet() {
408                    persistedModelLocalServiceRegistry.register("com.liferay.portal.model.Shard",
409                            shardLocalService);
410            }
411    
412            public void destroy() {
413                    persistedModelLocalServiceRegistry.unregister(
414                            "com.liferay.portal.model.Shard");
415            }
416    
417            /**
418             * Returns the Spring bean ID for this bean.
419             *
420             * @return the Spring bean ID for this bean
421             */
422            @Override
423            public String getBeanIdentifier() {
424                    return _beanIdentifier;
425            }
426    
427            /**
428             * Sets the Spring bean ID for this bean.
429             *
430             * @param beanIdentifier the Spring bean ID for this bean
431             */
432            @Override
433            public void setBeanIdentifier(String beanIdentifier) {
434                    _beanIdentifier = beanIdentifier;
435            }
436    
437            protected Class<?> getModelClass() {
438                    return Shard.class;
439            }
440    
441            protected String getModelClassName() {
442                    return Shard.class.getName();
443            }
444    
445            /**
446             * Performs a SQL query.
447             *
448             * @param sql the sql query
449             */
450            protected void runSQL(String sql) {
451                    try {
452                            DataSource dataSource = shardPersistence.getDataSource();
453    
454                            DB db = DBFactoryUtil.getDB();
455    
456                            sql = db.buildSQL(sql);
457                            sql = PortalUtil.transformSQL(sql);
458    
459                            SqlUpdate sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(dataSource,
460                                            sql, new int[0]);
461    
462                            sqlUpdate.update();
463                    }
464                    catch (Exception e) {
465                            throw new SystemException(e);
466                    }
467            }
468    
469            @BeanReference(type = com.liferay.portal.service.ShardLocalService.class)
470            protected com.liferay.portal.service.ShardLocalService shardLocalService;
471            @BeanReference(type = ShardPersistence.class)
472            protected ShardPersistence shardPersistence;
473            @BeanReference(type = com.liferay.counter.service.CounterLocalService.class)
474            protected com.liferay.counter.service.CounterLocalService counterLocalService;
475            @BeanReference(type = com.liferay.portal.service.ClassNameLocalService.class)
476            protected com.liferay.portal.service.ClassNameLocalService classNameLocalService;
477            @BeanReference(type = com.liferay.portal.service.ClassNameService.class)
478            protected com.liferay.portal.service.ClassNameService classNameService;
479            @BeanReference(type = ClassNamePersistence.class)
480            protected ClassNamePersistence classNamePersistence;
481            @BeanReference(type = PersistedModelLocalServiceRegistry.class)
482            protected PersistedModelLocalServiceRegistry persistedModelLocalServiceRegistry;
483            private String _beanIdentifier;
484    }