1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.service.persistence;
24  
25  import com.liferay.portal.NoSuchShardException;
26  import com.liferay.portal.SystemException;
27  import com.liferay.portal.kernel.annotation.BeanReference;
28  import com.liferay.portal.kernel.cache.CacheRegistry;
29  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
30  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
31  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
32  import com.liferay.portal.kernel.dao.orm.FinderPath;
33  import com.liferay.portal.kernel.dao.orm.Query;
34  import com.liferay.portal.kernel.dao.orm.QueryPos;
35  import com.liferay.portal.kernel.dao.orm.QueryUtil;
36  import com.liferay.portal.kernel.dao.orm.Session;
37  import com.liferay.portal.kernel.log.Log;
38  import com.liferay.portal.kernel.log.LogFactoryUtil;
39  import com.liferay.portal.kernel.util.GetterUtil;
40  import com.liferay.portal.kernel.util.OrderByComparator;
41  import com.liferay.portal.kernel.util.StringPool;
42  import com.liferay.portal.kernel.util.StringUtil;
43  import com.liferay.portal.kernel.util.Validator;
44  import com.liferay.portal.model.ModelListener;
45  import com.liferay.portal.model.Shard;
46  import com.liferay.portal.model.impl.ShardImpl;
47  import com.liferay.portal.model.impl.ShardModelImpl;
48  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
49  
50  import java.util.ArrayList;
51  import java.util.Collections;
52  import java.util.List;
53  
54  /**
55   * <a href="ShardPersistenceImpl.java.html"><b><i>View Source</i></b></a>
56   *
57   * <p>
58   * ServiceBuilder generated this class. Modifications in this class will be
59   * overwritten the next time is generated.
60   * </p>
61   *
62   * @author    Brian Wing Shun Chan
63   * @see       ShardPersistence
64   * @see       ShardUtil
65   * @generated
66   */
67  public class ShardPersistenceImpl extends BasePersistenceImpl
68      implements ShardPersistence {
69      public static final String FINDER_CLASS_NAME_ENTITY = ShardImpl.class.getName();
70      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
71          ".List";
72      public static final FinderPath FINDER_PATH_FETCH_BY_NAME = new FinderPath(ShardModelImpl.ENTITY_CACHE_ENABLED,
73              ShardModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
74              "fetchByName", new String[] { String.class.getName() });
75      public static final FinderPath FINDER_PATH_COUNT_BY_NAME = new FinderPath(ShardModelImpl.ENTITY_CACHE_ENABLED,
76              ShardModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
77              "countByName", new String[] { String.class.getName() });
78      public static final FinderPath FINDER_PATH_FETCH_BY_C_C = new FinderPath(ShardModelImpl.ENTITY_CACHE_ENABLED,
79              ShardModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
80              "fetchByC_C",
81              new String[] { Long.class.getName(), Long.class.getName() });
82      public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(ShardModelImpl.ENTITY_CACHE_ENABLED,
83              ShardModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
84              "countByC_C",
85              new String[] { Long.class.getName(), Long.class.getName() });
86      public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(ShardModelImpl.ENTITY_CACHE_ENABLED,
87              ShardModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
88              "findAll", new String[0]);
89      public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ShardModelImpl.ENTITY_CACHE_ENABLED,
90              ShardModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
91              "countAll", new String[0]);
92  
93      public void cacheResult(Shard shard) {
94          EntityCacheUtil.putResult(ShardModelImpl.ENTITY_CACHE_ENABLED,
95              ShardImpl.class, shard.getPrimaryKey(), shard);
96  
97          FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME,
98              new Object[] { shard.getName() }, shard);
99  
100         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
101             new Object[] {
102                 new Long(shard.getClassNameId()), new Long(shard.getClassPK())
103             }, shard);
104     }
105 
106     public void cacheResult(List<Shard> shards) {
107         for (Shard shard : shards) {
108             if (EntityCacheUtil.getResult(ShardModelImpl.ENTITY_CACHE_ENABLED,
109                         ShardImpl.class, shard.getPrimaryKey(), this) == null) {
110                 cacheResult(shard);
111             }
112         }
113     }
114 
115     public void clearCache() {
116         CacheRegistry.clear(ShardImpl.class.getName());
117         EntityCacheUtil.clearCache(ShardImpl.class.getName());
118         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
119         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
120     }
121 
122     public Shard create(long shardId) {
123         Shard shard = new ShardImpl();
124 
125         shard.setNew(true);
126         shard.setPrimaryKey(shardId);
127 
128         return shard;
129     }
130 
131     public Shard remove(long shardId)
132         throws NoSuchShardException, SystemException {
133         Session session = null;
134 
135         try {
136             session = openSession();
137 
138             Shard shard = (Shard)session.get(ShardImpl.class, new Long(shardId));
139 
140             if (shard == null) {
141                 if (_log.isWarnEnabled()) {
142                     _log.warn("No Shard exists with the primary key " +
143                         shardId);
144                 }
145 
146                 throw new NoSuchShardException(
147                     "No Shard exists with the primary key " + shardId);
148             }
149 
150             return remove(shard);
151         }
152         catch (NoSuchShardException nsee) {
153             throw nsee;
154         }
155         catch (Exception e) {
156             throw processException(e);
157         }
158         finally {
159             closeSession(session);
160         }
161     }
162 
163     public Shard remove(Shard shard) throws SystemException {
164         for (ModelListener<Shard> listener : listeners) {
165             listener.onBeforeRemove(shard);
166         }
167 
168         shard = removeImpl(shard);
169 
170         for (ModelListener<Shard> listener : listeners) {
171             listener.onAfterRemove(shard);
172         }
173 
174         return shard;
175     }
176 
177     protected Shard removeImpl(Shard shard) throws SystemException {
178         Session session = null;
179 
180         try {
181             session = openSession();
182 
183             if (shard.isCachedModel() || BatchSessionUtil.isEnabled()) {
184                 Object staleObject = session.get(ShardImpl.class,
185                         shard.getPrimaryKeyObj());
186 
187                 if (staleObject != null) {
188                     session.evict(staleObject);
189                 }
190             }
191 
192             session.delete(shard);
193 
194             session.flush();
195         }
196         catch (Exception e) {
197             throw processException(e);
198         }
199         finally {
200             closeSession(session);
201         }
202 
203         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
204 
205         ShardModelImpl shardModelImpl = (ShardModelImpl)shard;
206 
207         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_NAME,
208             new Object[] { shardModelImpl.getOriginalName() });
209 
210         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
211             new Object[] {
212                 new Long(shardModelImpl.getOriginalClassNameId()),
213                 new Long(shardModelImpl.getOriginalClassPK())
214             });
215 
216         EntityCacheUtil.removeResult(ShardModelImpl.ENTITY_CACHE_ENABLED,
217             ShardImpl.class, shard.getPrimaryKey());
218 
219         return shard;
220     }
221 
222     /**
223      * @deprecated Use {@link #update(Shard, boolean merge)}.
224      */
225     public Shard update(Shard shard) throws SystemException {
226         if (_log.isWarnEnabled()) {
227             _log.warn(
228                 "Using the deprecated update(Shard shard) method. Use update(Shard shard, boolean merge) instead.");
229         }
230 
231         return update(shard, false);
232     }
233 
234     /**
235      * Add, update, or merge, the entity. This method also calls the model
236      * listeners to trigger the proper events associated with adding, deleting,
237      * or updating an entity.
238      *
239      * @param  shard the entity to add, update, or merge
240      * @param  merge boolean value for whether to merge the entity. The default
241      *         value is false. Setting merge to true is more expensive and
242      *         should only be true when shard is transient. See
243      *         LEP-5473 for a detailed discussion of this method.
244      * @return the entity that was added, updated, or merged
245      */
246     public Shard update(Shard shard, boolean merge) throws SystemException {
247         boolean isNew = shard.isNew();
248 
249         for (ModelListener<Shard> listener : listeners) {
250             if (isNew) {
251                 listener.onBeforeCreate(shard);
252             }
253             else {
254                 listener.onBeforeUpdate(shard);
255             }
256         }
257 
258         shard = updateImpl(shard, merge);
259 
260         for (ModelListener<Shard> listener : listeners) {
261             if (isNew) {
262                 listener.onAfterCreate(shard);
263             }
264             else {
265                 listener.onAfterUpdate(shard);
266             }
267         }
268 
269         return shard;
270     }
271 
272     public Shard updateImpl(com.liferay.portal.model.Shard shard, boolean merge)
273         throws SystemException {
274         boolean isNew = shard.isNew();
275 
276         ShardModelImpl shardModelImpl = (ShardModelImpl)shard;
277 
278         Session session = null;
279 
280         try {
281             session = openSession();
282 
283             BatchSessionUtil.update(session, shard, merge);
284 
285             shard.setNew(false);
286         }
287         catch (Exception e) {
288             throw processException(e);
289         }
290         finally {
291             closeSession(session);
292         }
293 
294         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
295 
296         EntityCacheUtil.putResult(ShardModelImpl.ENTITY_CACHE_ENABLED,
297             ShardImpl.class, shard.getPrimaryKey(), shard);
298 
299         if (!isNew &&
300                 (!Validator.equals(shard.getName(),
301                     shardModelImpl.getOriginalName()))) {
302             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_NAME,
303                 new Object[] { shardModelImpl.getOriginalName() });
304         }
305 
306         if (isNew ||
307                 (!Validator.equals(shard.getName(),
308                     shardModelImpl.getOriginalName()))) {
309             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME,
310                 new Object[] { shard.getName() }, shard);
311         }
312 
313         if (!isNew &&
314                 ((shard.getClassNameId() != shardModelImpl.getOriginalClassNameId()) ||
315                 (shard.getClassPK() != shardModelImpl.getOriginalClassPK()))) {
316             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
317                 new Object[] {
318                     new Long(shardModelImpl.getOriginalClassNameId()),
319                     new Long(shardModelImpl.getOriginalClassPK())
320                 });
321         }
322 
323         if (isNew ||
324                 ((shard.getClassNameId() != shardModelImpl.getOriginalClassNameId()) ||
325                 (shard.getClassPK() != shardModelImpl.getOriginalClassPK()))) {
326             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
327                 new Object[] {
328                     new Long(shard.getClassNameId()),
329                     new Long(shard.getClassPK())
330                 }, shard);
331         }
332 
333         return shard;
334     }
335 
336     public Shard findByPrimaryKey(long shardId)
337         throws NoSuchShardException, SystemException {
338         Shard shard = fetchByPrimaryKey(shardId);
339 
340         if (shard == null) {
341             if (_log.isWarnEnabled()) {
342                 _log.warn("No Shard exists with the primary key " + shardId);
343             }
344 
345             throw new NoSuchShardException(
346                 "No Shard exists with the primary key " + shardId);
347         }
348 
349         return shard;
350     }
351 
352     public Shard fetchByPrimaryKey(long shardId) throws SystemException {
353         Shard shard = (Shard)EntityCacheUtil.getResult(ShardModelImpl.ENTITY_CACHE_ENABLED,
354                 ShardImpl.class, shardId, this);
355 
356         if (shard == null) {
357             Session session = null;
358 
359             try {
360                 session = openSession();
361 
362                 shard = (Shard)session.get(ShardImpl.class, new Long(shardId));
363             }
364             catch (Exception e) {
365                 throw processException(e);
366             }
367             finally {
368                 if (shard != null) {
369                     cacheResult(shard);
370                 }
371 
372                 closeSession(session);
373             }
374         }
375 
376         return shard;
377     }
378 
379     public Shard findByName(String name)
380         throws NoSuchShardException, SystemException {
381         Shard shard = fetchByName(name);
382 
383         if (shard == null) {
384             StringBuilder msg = new StringBuilder();
385 
386             msg.append("No Shard exists with the key {");
387 
388             msg.append("name=" + name);
389 
390             msg.append(StringPool.CLOSE_CURLY_BRACE);
391 
392             if (_log.isWarnEnabled()) {
393                 _log.warn(msg.toString());
394             }
395 
396             throw new NoSuchShardException(msg.toString());
397         }
398 
399         return shard;
400     }
401 
402     public Shard fetchByName(String name) throws SystemException {
403         return fetchByName(name, true);
404     }
405 
406     public Shard fetchByName(String name, boolean retrieveFromCache)
407         throws SystemException {
408         Object[] finderArgs = new Object[] { name };
409 
410         Object result = null;
411 
412         if (retrieveFromCache) {
413             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_NAME,
414                     finderArgs, this);
415         }
416 
417         if (result == null) {
418             Session session = null;
419 
420             try {
421                 session = openSession();
422 
423                 StringBuilder query = new StringBuilder();
424 
425                 query.append("SELECT shard FROM Shard shard WHERE ");
426 
427                 if (name == null) {
428                     query.append("shard.name IS NULL");
429                 }
430                 else {
431                     query.append("shard.name = ?");
432                 }
433 
434                 query.append(" ");
435 
436                 Query q = session.createQuery(query.toString());
437 
438                 QueryPos qPos = QueryPos.getInstance(q);
439 
440                 if (name != null) {
441                     qPos.add(name);
442                 }
443 
444                 List<Shard> list = q.list();
445 
446                 result = list;
447 
448                 Shard shard = null;
449 
450                 if (list.isEmpty()) {
451                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME,
452                         finderArgs, list);
453                 }
454                 else {
455                     shard = list.get(0);
456 
457                     cacheResult(shard);
458 
459                     if ((shard.getName() == null) ||
460                             !shard.getName().equals(name)) {
461                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME,
462                             finderArgs, shard);
463                     }
464                 }
465 
466                 return shard;
467             }
468             catch (Exception e) {
469                 throw processException(e);
470             }
471             finally {
472                 if (result == null) {
473                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME,
474                         finderArgs, new ArrayList<Shard>());
475                 }
476 
477                 closeSession(session);
478             }
479         }
480         else {
481             if (result instanceof List<?>) {
482                 return null;
483             }
484             else {
485                 return (Shard)result;
486             }
487         }
488     }
489 
490     public Shard findByC_C(long classNameId, long classPK)
491         throws NoSuchShardException, SystemException {
492         Shard shard = fetchByC_C(classNameId, classPK);
493 
494         if (shard == null) {
495             StringBuilder msg = new StringBuilder();
496 
497             msg.append("No Shard exists with the key {");
498 
499             msg.append("classNameId=" + classNameId);
500 
501             msg.append(", ");
502             msg.append("classPK=" + classPK);
503 
504             msg.append(StringPool.CLOSE_CURLY_BRACE);
505 
506             if (_log.isWarnEnabled()) {
507                 _log.warn(msg.toString());
508             }
509 
510             throw new NoSuchShardException(msg.toString());
511         }
512 
513         return shard;
514     }
515 
516     public Shard fetchByC_C(long classNameId, long classPK)
517         throws SystemException {
518         return fetchByC_C(classNameId, classPK, true);
519     }
520 
521     public Shard fetchByC_C(long classNameId, long classPK,
522         boolean retrieveFromCache) throws SystemException {
523         Object[] finderArgs = new Object[] {
524                 new Long(classNameId), new Long(classPK)
525             };
526 
527         Object result = null;
528 
529         if (retrieveFromCache) {
530             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C,
531                     finderArgs, this);
532         }
533 
534         if (result == null) {
535             Session session = null;
536 
537             try {
538                 session = openSession();
539 
540                 StringBuilder query = new StringBuilder();
541 
542                 query.append("SELECT shard FROM Shard shard WHERE ");
543 
544                 query.append("shard.classNameId = ?");
545 
546                 query.append(" AND ");
547 
548                 query.append("shard.classPK = ?");
549 
550                 query.append(" ");
551 
552                 Query q = session.createQuery(query.toString());
553 
554                 QueryPos qPos = QueryPos.getInstance(q);
555 
556                 qPos.add(classNameId);
557 
558                 qPos.add(classPK);
559 
560                 List<Shard> list = q.list();
561 
562                 result = list;
563 
564                 Shard shard = null;
565 
566                 if (list.isEmpty()) {
567                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
568                         finderArgs, list);
569                 }
570                 else {
571                     shard = list.get(0);
572 
573                     cacheResult(shard);
574 
575                     if ((shard.getClassNameId() != classNameId) ||
576                             (shard.getClassPK() != classPK)) {
577                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
578                             finderArgs, shard);
579                     }
580                 }
581 
582                 return shard;
583             }
584             catch (Exception e) {
585                 throw processException(e);
586             }
587             finally {
588                 if (result == null) {
589                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
590                         finderArgs, new ArrayList<Shard>());
591                 }
592 
593                 closeSession(session);
594             }
595         }
596         else {
597             if (result instanceof List<?>) {
598                 return null;
599             }
600             else {
601                 return (Shard)result;
602             }
603         }
604     }
605 
606     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
607         throws SystemException {
608         Session session = null;
609 
610         try {
611             session = openSession();
612 
613             dynamicQuery.compile(session);
614 
615             return dynamicQuery.list();
616         }
617         catch (Exception e) {
618             throw processException(e);
619         }
620         finally {
621             closeSession(session);
622         }
623     }
624 
625     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
626         int start, int end) throws SystemException {
627         Session session = null;
628 
629         try {
630             session = openSession();
631 
632             dynamicQuery.setLimit(start, end);
633 
634             dynamicQuery.compile(session);
635 
636             return dynamicQuery.list();
637         }
638         catch (Exception e) {
639             throw processException(e);
640         }
641         finally {
642             closeSession(session);
643         }
644     }
645 
646     public List<Shard> findAll() throws SystemException {
647         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
648     }
649 
650     public List<Shard> findAll(int start, int end) throws SystemException {
651         return findAll(start, end, null);
652     }
653 
654     public List<Shard> findAll(int start, int end, OrderByComparator obc)
655         throws SystemException {
656         Object[] finderArgs = new Object[] {
657                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
658             };
659 
660         List<Shard> list = (List<Shard>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
661                 finderArgs, this);
662 
663         if (list == null) {
664             Session session = null;
665 
666             try {
667                 session = openSession();
668 
669                 StringBuilder query = new StringBuilder();
670 
671                 query.append("SELECT shard FROM Shard shard ");
672 
673                 if (obc != null) {
674                     query.append("ORDER BY ");
675 
676                     String[] orderByFields = obc.getOrderByFields();
677 
678                     for (int i = 0; i < orderByFields.length; i++) {
679                         query.append("shard.");
680                         query.append(orderByFields[i]);
681 
682                         if (obc.isAscending()) {
683                             query.append(" ASC");
684                         }
685                         else {
686                             query.append(" DESC");
687                         }
688 
689                         if ((i + 1) < orderByFields.length) {
690                             query.append(", ");
691                         }
692                     }
693                 }
694 
695                 Query q = session.createQuery(query.toString());
696 
697                 if (obc == null) {
698                     list = (List<Shard>)QueryUtil.list(q, getDialect(), start,
699                             end, false);
700 
701                     Collections.sort(list);
702                 }
703                 else {
704                     list = (List<Shard>)QueryUtil.list(q, getDialect(), start,
705                             end);
706                 }
707             }
708             catch (Exception e) {
709                 throw processException(e);
710             }
711             finally {
712                 if (list == null) {
713                     list = new ArrayList<Shard>();
714                 }
715 
716                 cacheResult(list);
717 
718                 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
719 
720                 closeSession(session);
721             }
722         }
723 
724         return list;
725     }
726 
727     public void removeByName(String name)
728         throws NoSuchShardException, SystemException {
729         Shard shard = findByName(name);
730 
731         remove(shard);
732     }
733 
734     public void removeByC_C(long classNameId, long classPK)
735         throws NoSuchShardException, SystemException {
736         Shard shard = findByC_C(classNameId, classPK);
737 
738         remove(shard);
739     }
740 
741     public void removeAll() throws SystemException {
742         for (Shard shard : findAll()) {
743             remove(shard);
744         }
745     }
746 
747     public int countByName(String name) throws SystemException {
748         Object[] finderArgs = new Object[] { name };
749 
750         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_NAME,
751                 finderArgs, this);
752 
753         if (count == null) {
754             Session session = null;
755 
756             try {
757                 session = openSession();
758 
759                 StringBuilder query = new StringBuilder();
760 
761                 query.append("SELECT COUNT(shard) ");
762                 query.append("FROM Shard shard WHERE ");
763 
764                 if (name == null) {
765                     query.append("shard.name IS NULL");
766                 }
767                 else {
768                     query.append("shard.name = ?");
769                 }
770 
771                 query.append(" ");
772 
773                 Query q = session.createQuery(query.toString());
774 
775                 QueryPos qPos = QueryPos.getInstance(q);
776 
777                 if (name != null) {
778                     qPos.add(name);
779                 }
780 
781                 count = (Long)q.uniqueResult();
782             }
783             catch (Exception e) {
784                 throw processException(e);
785             }
786             finally {
787                 if (count == null) {
788                     count = Long.valueOf(0);
789                 }
790 
791                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_NAME,
792                     finderArgs, count);
793 
794                 closeSession(session);
795             }
796         }
797 
798         return count.intValue();
799     }
800 
801     public int countByC_C(long classNameId, long classPK)
802         throws SystemException {
803         Object[] finderArgs = new Object[] {
804                 new Long(classNameId), new Long(classPK)
805             };
806 
807         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
808                 finderArgs, this);
809 
810         if (count == null) {
811             Session session = null;
812 
813             try {
814                 session = openSession();
815 
816                 StringBuilder query = new StringBuilder();
817 
818                 query.append("SELECT COUNT(shard) ");
819                 query.append("FROM Shard shard WHERE ");
820 
821                 query.append("shard.classNameId = ?");
822 
823                 query.append(" AND ");
824 
825                 query.append("shard.classPK = ?");
826 
827                 query.append(" ");
828 
829                 Query q = session.createQuery(query.toString());
830 
831                 QueryPos qPos = QueryPos.getInstance(q);
832 
833                 qPos.add(classNameId);
834 
835                 qPos.add(classPK);
836 
837                 count = (Long)q.uniqueResult();
838             }
839             catch (Exception e) {
840                 throw processException(e);
841             }
842             finally {
843                 if (count == null) {
844                     count = Long.valueOf(0);
845                 }
846 
847                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
848                     count);
849 
850                 closeSession(session);
851             }
852         }
853 
854         return count.intValue();
855     }
856 
857     public int countAll() throws SystemException {
858         Object[] finderArgs = new Object[0];
859 
860         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
861                 finderArgs, this);
862 
863         if (count == null) {
864             Session session = null;
865 
866             try {
867                 session = openSession();
868 
869                 Query q = session.createQuery(
870                         "SELECT COUNT(shard) FROM Shard shard");
871 
872                 count = (Long)q.uniqueResult();
873             }
874             catch (Exception e) {
875                 throw processException(e);
876             }
877             finally {
878                 if (count == null) {
879                     count = Long.valueOf(0);
880                 }
881 
882                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
883                     count);
884 
885                 closeSession(session);
886             }
887         }
888 
889         return count.intValue();
890     }
891 
892     public void afterPropertiesSet() {
893         String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
894                     com.liferay.portal.util.PropsUtil.get(
895                         "value.object.listener.com.liferay.portal.model.Shard")));
896 
897         if (listenerClassNames.length > 0) {
898             try {
899                 List<ModelListener<Shard>> listenersList = new ArrayList<ModelListener<Shard>>();
900 
901                 for (String listenerClassName : listenerClassNames) {
902                     listenersList.add((ModelListener<Shard>)Class.forName(
903                             listenerClassName).newInstance());
904                 }
905 
906                 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
907             }
908             catch (Exception e) {
909                 _log.error(e);
910             }
911         }
912     }
913 
914     @BeanReference(name = "com.liferay.portal.service.persistence.AccountPersistence.impl")
915     protected com.liferay.portal.service.persistence.AccountPersistence accountPersistence;
916     @BeanReference(name = "com.liferay.portal.service.persistence.AddressPersistence.impl")
917     protected com.liferay.portal.service.persistence.AddressPersistence addressPersistence;
918     @BeanReference(name = "com.liferay.portal.service.persistence.BrowserTrackerPersistence.impl")
919     protected com.liferay.portal.service.persistence.BrowserTrackerPersistence browserTrackerPersistence;
920     @BeanReference(name = "com.liferay.portal.service.persistence.ClassNamePersistence.impl")
921     protected com.liferay.portal.service.persistence.ClassNamePersistence classNamePersistence;
922     @BeanReference(name = "com.liferay.portal.service.persistence.CompanyPersistence.impl")
923     protected com.liferay.portal.service.persistence.CompanyPersistence companyPersistence;
924     @BeanReference(name = "com.liferay.portal.service.persistence.ContactPersistence.impl")
925     protected com.liferay.portal.service.persistence.ContactPersistence contactPersistence;
926     @BeanReference(name = "com.liferay.portal.service.persistence.CountryPersistence.impl")
927     protected com.liferay.portal.service.persistence.CountryPersistence countryPersistence;
928     @BeanReference(name = "com.liferay.portal.service.persistence.EmailAddressPersistence.impl")
929     protected com.liferay.portal.service.persistence.EmailAddressPersistence emailAddressPersistence;
930     @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence.impl")
931     protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
932     @BeanReference(name = "com.liferay.portal.service.persistence.ImagePersistence.impl")
933     protected com.liferay.portal.service.persistence.ImagePersistence imagePersistence;
934     @BeanReference(name = "com.liferay.portal.service.persistence.LayoutPersistence.impl")
935     protected com.liferay.portal.service.persistence.LayoutPersistence layoutPersistence;
936     @BeanReference(name = "com.liferay.portal.service.persistence.LayoutSetPersistence.impl")
937     protected com.liferay.portal.service.persistence.LayoutSetPersistence layoutSetPersistence;
938     @BeanReference(name = "com.liferay.portal.service.persistence.ListTypePersistence.impl")
939     protected com.liferay.portal.service.persistence.ListTypePersistence listTypePersistence;
940     @BeanReference(name = "com.liferay.portal.service.persistence.LockPersistence.impl")
941     protected com.liferay.portal.service.persistence.LockPersistence lockPersistence;
942     @BeanReference(name = "com.liferay.portal.service.persistence.MembershipRequestPersistence.impl")
943     protected com.liferay.portal.service.persistence.MembershipRequestPersistence membershipRequestPersistence;
944     @BeanReference(name = "com.liferay.portal.service.persistence.OrganizationPersistence.impl")
945     protected com.liferay.portal.service.persistence.OrganizationPersistence organizationPersistence;
946     @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupPermissionPersistence.impl")
947     protected com.liferay.portal.service.persistence.OrgGroupPermissionPersistence orgGroupPermissionPersistence;
948     @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupRolePersistence.impl")
949     protected com.liferay.portal.service.persistence.OrgGroupRolePersistence orgGroupRolePersistence;
950     @BeanReference(name = "com.liferay.portal.service.persistence.OrgLaborPersistence.impl")
951     protected com.liferay.portal.service.persistence.OrgLaborPersistence orgLaborPersistence;
952     @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyPersistence.impl")
953     protected com.liferay.portal.service.persistence.PasswordPolicyPersistence passwordPolicyPersistence;
954     @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyRelPersistence.impl")
955     protected com.liferay.portal.service.persistence.PasswordPolicyRelPersistence passwordPolicyRelPersistence;
956     @BeanReference(name = "com.liferay.portal.service.persistence.PasswordTrackerPersistence.impl")
957     protected com.liferay.portal.service.persistence.PasswordTrackerPersistence passwordTrackerPersistence;
958     @BeanReference(name = "com.liferay.portal.service.persistence.PermissionPersistence.impl")
959     protected com.liferay.portal.service.persistence.PermissionPersistence permissionPersistence;
960     @BeanReference(name = "com.liferay.portal.service.persistence.PhonePersistence.impl")
961     protected com.liferay.portal.service.persistence.PhonePersistence phonePersistence;
962     @BeanReference(name = "com.liferay.portal.service.persistence.PluginSettingPersistence.impl")
963     protected com.liferay.portal.service.persistence.PluginSettingPersistence pluginSettingPersistence;
964     @BeanReference(name = "com.liferay.portal.service.persistence.PortletPersistence.impl")
965     protected com.liferay.portal.service.persistence.PortletPersistence portletPersistence;
966     @BeanReference(name = "com.liferay.portal.service.persistence.PortletItemPersistence.impl")
967     protected com.liferay.portal.service.persistence.PortletItemPersistence portletItemPersistence;
968     @BeanReference(name = "com.liferay.portal.service.persistence.PortletPreferencesPersistence.impl")
969     protected com.liferay.portal.service.persistence.PortletPreferencesPersistence portletPreferencesPersistence;
970     @BeanReference(name = "com.liferay.portal.service.persistence.RegionPersistence.impl")
971     protected com.liferay.portal.service.persistence.RegionPersistence regionPersistence;
972     @BeanReference(name = "com.liferay.portal.service.persistence.ReleasePersistence.impl")
973     protected com.liferay.portal.service.persistence.ReleasePersistence releasePersistence;
974     @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
975     protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
976     @BeanReference(name = "com.liferay.portal.service.persistence.ResourceActionPersistence.impl")
977     protected com.liferay.portal.service.persistence.ResourceActionPersistence resourceActionPersistence;
978     @BeanReference(name = "com.liferay.portal.service.persistence.ResourceCodePersistence.impl")
979     protected com.liferay.portal.service.persistence.ResourceCodePersistence resourceCodePersistence;
980     @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePermissionPersistence.impl")
981     protected com.liferay.portal.service.persistence.ResourcePermissionPersistence resourcePermissionPersistence;
982     @BeanReference(name = "com.liferay.portal.service.persistence.RolePersistence.impl")
983     protected com.liferay.portal.service.persistence.RolePersistence rolePersistence;
984     @BeanReference(name = "com.liferay.portal.service.persistence.ServiceComponentPersistence.impl")
985     protected com.liferay.portal.service.persistence.ServiceComponentPersistence serviceComponentPersistence;
986     @BeanReference(name = "com.liferay.portal.service.persistence.ShardPersistence.impl")
987     protected com.liferay.portal.service.persistence.ShardPersistence shardPersistence;
988     @BeanReference(name = "com.liferay.portal.service.persistence.SubscriptionPersistence.impl")
989     protected com.liferay.portal.service.persistence.SubscriptionPersistence subscriptionPersistence;
990     @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
991     protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
992     @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupPersistence.impl")
993     protected com.liferay.portal.service.persistence.UserGroupPersistence userGroupPersistence;
994     @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupRolePersistence.impl")
995     protected com.liferay.portal.service.persistence.UserGroupRolePersistence userGroupRolePersistence;
996     @BeanReference(name = "com.liferay.portal.service.persistence.UserIdMapperPersistence.impl")
997     protected com.liferay.portal.service.persistence.UserIdMapperPersistence userIdMapperPersistence;
998     @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPersistence.impl")
999     protected com.liferay.portal.service.persistence.UserTrackerPersistence userTrackerPersistence;
1000    @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPathPersistence.impl")
1001    protected com.liferay.portal.service.persistence.UserTrackerPathPersistence userTrackerPathPersistence;
1002    @BeanReference(name = "com.liferay.portal.service.persistence.WebDAVPropsPersistence.impl")
1003    protected com.liferay.portal.service.persistence.WebDAVPropsPersistence webDAVPropsPersistence;
1004    @BeanReference(name = "com.liferay.portal.service.persistence.WebsitePersistence.impl")
1005    protected com.liferay.portal.service.persistence.WebsitePersistence websitePersistence;
1006    private static Log _log = LogFactoryUtil.getLog(ShardPersistenceImpl.class);
1007}