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