1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
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.SystemException;
20  import com.liferay.portal.kernel.annotation.BeanReference;
21  import com.liferay.portal.kernel.cache.CacheRegistry;
22  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
23  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
24  import com.liferay.portal.kernel.dao.orm.FinderPath;
25  import com.liferay.portal.kernel.dao.orm.Query;
26  import com.liferay.portal.kernel.dao.orm.QueryPos;
27  import com.liferay.portal.kernel.dao.orm.QueryUtil;
28  import com.liferay.portal.kernel.dao.orm.Session;
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.InstanceFactory;
33  import com.liferay.portal.kernel.util.OrderByComparator;
34  import com.liferay.portal.kernel.util.StringBundler;
35  import com.liferay.portal.kernel.util.StringPool;
36  import com.liferay.portal.kernel.util.StringUtil;
37  import com.liferay.portal.kernel.util.Validator;
38  import com.liferay.portal.model.ModelListener;
39  import com.liferay.portal.model.Shard;
40  import com.liferay.portal.model.impl.ShardImpl;
41  import com.liferay.portal.model.impl.ShardModelImpl;
42  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
43  
44  import java.io.Serializable;
45  
46  import java.util.ArrayList;
47  import java.util.Collections;
48  import java.util.List;
49  
50  /**
51   * <a href="ShardPersistenceImpl.java.html"><b><i>View Source</i></b></a>
52   *
53   * <p>
54   * ServiceBuilder generated this class. Modifications in this class will be
55   * overwritten the next time is generated.
56   * </p>
57   *
58   * @author    Brian Wing Shun Chan
59   * @see       ShardPersistence
60   * @see       ShardUtil
61   * @generated
62   */
63  public class ShardPersistenceImpl extends BasePersistenceImpl<Shard>
64      implements ShardPersistence {
65      public static final String FINDER_CLASS_NAME_ENTITY = ShardImpl.class.getName();
66      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
67          ".List";
68      public static final FinderPath FINDER_PATH_FETCH_BY_NAME = new FinderPath(ShardModelImpl.ENTITY_CACHE_ENABLED,
69              ShardModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
70              "fetchByName", new String[] { String.class.getName() });
71      public static final FinderPath FINDER_PATH_COUNT_BY_NAME = new FinderPath(ShardModelImpl.ENTITY_CACHE_ENABLED,
72              ShardModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
73              "countByName", new String[] { String.class.getName() });
74      public static final FinderPath FINDER_PATH_FETCH_BY_C_C = new FinderPath(ShardModelImpl.ENTITY_CACHE_ENABLED,
75              ShardModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
76              "fetchByC_C",
77              new String[] { Long.class.getName(), Long.class.getName() });
78      public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(ShardModelImpl.ENTITY_CACHE_ENABLED,
79              ShardModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
80              "countByC_C",
81              new String[] { Long.class.getName(), Long.class.getName() });
82      public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(ShardModelImpl.ENTITY_CACHE_ENABLED,
83              ShardModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
84              "findAll", new String[0]);
85      public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ShardModelImpl.ENTITY_CACHE_ENABLED,
86              ShardModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
87              "countAll", new String[0]);
88  
89      public void cacheResult(Shard shard) {
90          EntityCacheUtil.putResult(ShardModelImpl.ENTITY_CACHE_ENABLED,
91              ShardImpl.class, shard.getPrimaryKey(), shard);
92  
93          FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME,
94              new Object[] { shard.getName() }, shard);
95  
96          FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
97              new Object[] {
98                  new Long(shard.getClassNameId()), new Long(shard.getClassPK())
99              }, shard);
100     }
101 
102     public void cacheResult(List<Shard> shards) {
103         for (Shard shard : shards) {
104             if (EntityCacheUtil.getResult(ShardModelImpl.ENTITY_CACHE_ENABLED,
105                         ShardImpl.class, shard.getPrimaryKey(), this) == null) {
106                 cacheResult(shard);
107             }
108         }
109     }
110 
111     public void clearCache() {
112         CacheRegistry.clear(ShardImpl.class.getName());
113         EntityCacheUtil.clearCache(ShardImpl.class.getName());
114         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
115         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
116     }
117 
118     public void clearCache(Shard shard) {
119         EntityCacheUtil.removeResult(ShardModelImpl.ENTITY_CACHE_ENABLED,
120             ShardImpl.class, shard.getPrimaryKey());
121 
122         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_NAME,
123             new Object[] { shard.getName() });
124 
125         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
126             new Object[] {
127                 new Long(shard.getClassNameId()), new Long(shard.getClassPK())
128             });
129     }
130 
131     public Shard create(long shardId) {
132         Shard shard = new ShardImpl();
133 
134         shard.setNew(true);
135         shard.setPrimaryKey(shardId);
136 
137         return shard;
138     }
139 
140     public Shard remove(Serializable primaryKey)
141         throws NoSuchModelException, SystemException {
142         return remove(((Long)primaryKey).longValue());
143     }
144 
145     public Shard remove(long shardId)
146         throws NoSuchShardException, SystemException {
147         Session session = null;
148 
149         try {
150             session = openSession();
151 
152             Shard shard = (Shard)session.get(ShardImpl.class, new Long(shardId));
153 
154             if (shard == null) {
155                 if (_log.isWarnEnabled()) {
156                     _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + shardId);
157                 }
158 
159                 throw new NoSuchShardException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
160                     shardId);
161             }
162 
163             return remove(shard);
164         }
165         catch (NoSuchShardException nsee) {
166             throw nsee;
167         }
168         catch (Exception e) {
169             throw processException(e);
170         }
171         finally {
172             closeSession(session);
173         }
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             BatchSessionUtil.delete(session, shard);
185         }
186         catch (Exception e) {
187             throw processException(e);
188         }
189         finally {
190             closeSession(session);
191         }
192 
193         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
194 
195         ShardModelImpl shardModelImpl = (ShardModelImpl)shard;
196 
197         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_NAME,
198             new Object[] { shardModelImpl.getOriginalName() });
199 
200         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
201             new Object[] {
202                 new Long(shardModelImpl.getOriginalClassNameId()),
203                 new Long(shardModelImpl.getOriginalClassPK())
204             });
205 
206         EntityCacheUtil.removeResult(ShardModelImpl.ENTITY_CACHE_ENABLED,
207             ShardImpl.class, shard.getPrimaryKey());
208 
209         return shard;
210     }
211 
212     /**
213      * @deprecated Use {@link BasePersistence#update(com.liferay.portal.model.BaseModel, boolean)}.
214      */
215     public Shard update(Shard shard) throws SystemException {
216         if (_log.isWarnEnabled()) {
217             _log.warn(
218                 "Using the deprecated update(Shard shard) method. Use update(Shard shard, boolean merge) instead.");
219         }
220 
221         return update(shard, false);
222     }
223 
224     public Shard updateImpl(com.liferay.portal.model.Shard shard, boolean merge)
225         throws SystemException {
226         shard = toUnwrappedModel(shard);
227 
228         boolean isNew = shard.isNew();
229 
230         ShardModelImpl shardModelImpl = (ShardModelImpl)shard;
231 
232         Session session = null;
233 
234         try {
235             session = openSession();
236 
237             BatchSessionUtil.update(session, shard, merge);
238 
239             shard.setNew(false);
240         }
241         catch (Exception e) {
242             throw processException(e);
243         }
244         finally {
245             closeSession(session);
246         }
247 
248         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
249 
250         EntityCacheUtil.putResult(ShardModelImpl.ENTITY_CACHE_ENABLED,
251             ShardImpl.class, shard.getPrimaryKey(), shard);
252 
253         if (!isNew &&
254                 (!Validator.equals(shard.getName(),
255                     shardModelImpl.getOriginalName()))) {
256             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_NAME,
257                 new Object[] { shardModelImpl.getOriginalName() });
258         }
259 
260         if (isNew ||
261                 (!Validator.equals(shard.getName(),
262                     shardModelImpl.getOriginalName()))) {
263             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME,
264                 new Object[] { shard.getName() }, shard);
265         }
266 
267         if (!isNew &&
268                 ((shard.getClassNameId() != shardModelImpl.getOriginalClassNameId()) ||
269                 (shard.getClassPK() != shardModelImpl.getOriginalClassPK()))) {
270             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
271                 new Object[] {
272                     new Long(shardModelImpl.getOriginalClassNameId()),
273                     new Long(shardModelImpl.getOriginalClassPK())
274                 });
275         }
276 
277         if (isNew ||
278                 ((shard.getClassNameId() != shardModelImpl.getOriginalClassNameId()) ||
279                 (shard.getClassPK() != shardModelImpl.getOriginalClassPK()))) {
280             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
281                 new Object[] {
282                     new Long(shard.getClassNameId()),
283                     new Long(shard.getClassPK())
284                 }, shard);
285         }
286 
287         return shard;
288     }
289 
290     protected Shard toUnwrappedModel(Shard shard) {
291         if (shard instanceof ShardImpl) {
292             return shard;
293         }
294 
295         ShardImpl shardImpl = new ShardImpl();
296 
297         shardImpl.setNew(shard.isNew());
298         shardImpl.setPrimaryKey(shard.getPrimaryKey());
299 
300         shardImpl.setShardId(shard.getShardId());
301         shardImpl.setClassNameId(shard.getClassNameId());
302         shardImpl.setClassPK(shard.getClassPK());
303         shardImpl.setName(shard.getName());
304 
305         return shardImpl;
306     }
307 
308     public Shard findByPrimaryKey(Serializable primaryKey)
309         throws NoSuchModelException, SystemException {
310         return findByPrimaryKey(((Long)primaryKey).longValue());
311     }
312 
313     public Shard findByPrimaryKey(long shardId)
314         throws NoSuchShardException, SystemException {
315         Shard shard = fetchByPrimaryKey(shardId);
316 
317         if (shard == null) {
318             if (_log.isWarnEnabled()) {
319                 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + shardId);
320             }
321 
322             throw new NoSuchShardException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
323                 shardId);
324         }
325 
326         return shard;
327     }
328 
329     public Shard fetchByPrimaryKey(Serializable primaryKey)
330         throws SystemException {
331         return fetchByPrimaryKey(((Long)primaryKey).longValue());
332     }
333 
334     public Shard fetchByPrimaryKey(long shardId) throws SystemException {
335         Shard shard = (Shard)EntityCacheUtil.getResult(ShardModelImpl.ENTITY_CACHE_ENABLED,
336                 ShardImpl.class, shardId, this);
337 
338         if (shard == null) {
339             Session session = null;
340 
341             try {
342                 session = openSession();
343 
344                 shard = (Shard)session.get(ShardImpl.class, new Long(shardId));
345             }
346             catch (Exception e) {
347                 throw processException(e);
348             }
349             finally {
350                 if (shard != null) {
351                     cacheResult(shard);
352                 }
353 
354                 closeSession(session);
355             }
356         }
357 
358         return shard;
359     }
360 
361     public Shard findByName(String name)
362         throws NoSuchShardException, SystemException {
363         Shard shard = fetchByName(name);
364 
365         if (shard == null) {
366             StringBundler msg = new StringBundler(4);
367 
368             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
369 
370             msg.append("name=");
371             msg.append(name);
372 
373             msg.append(StringPool.CLOSE_CURLY_BRACE);
374 
375             if (_log.isWarnEnabled()) {
376                 _log.warn(msg.toString());
377             }
378 
379             throw new NoSuchShardException(msg.toString());
380         }
381 
382         return shard;
383     }
384 
385     public Shard fetchByName(String name) throws SystemException {
386         return fetchByName(name, true);
387     }
388 
389     public Shard fetchByName(String name, boolean retrieveFromCache)
390         throws SystemException {
391         Object[] finderArgs = new Object[] { name };
392 
393         Object result = null;
394 
395         if (retrieveFromCache) {
396             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_NAME,
397                     finderArgs, this);
398         }
399 
400         if (result == null) {
401             StringBundler query = new StringBundler(2);
402 
403             query.append(_SQL_SELECT_SHARD_WHERE);
404 
405             if (name == null) {
406                 query.append(_FINDER_COLUMN_NAME_NAME_1);
407             }
408             else {
409                 if (name.equals(StringPool.BLANK)) {
410                     query.append(_FINDER_COLUMN_NAME_NAME_3);
411                 }
412                 else {
413                     query.append(_FINDER_COLUMN_NAME_NAME_2);
414                 }
415             }
416 
417             String sql = query.toString();
418 
419             Session session = null;
420 
421             try {
422                 session = openSession();
423 
424                 Query q = session.createQuery(sql);
425 
426                 QueryPos qPos = QueryPos.getInstance(q);
427 
428                 if (name != null) {
429                     qPos.add(name);
430                 }
431 
432                 List<Shard> list = q.list();
433 
434                 result = list;
435 
436                 Shard shard = null;
437 
438                 if (list.isEmpty()) {
439                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME,
440                         finderArgs, list);
441                 }
442                 else {
443                     shard = list.get(0);
444 
445                     cacheResult(shard);
446 
447                     if ((shard.getName() == null) ||
448                             !shard.getName().equals(name)) {
449                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME,
450                             finderArgs, shard);
451                     }
452                 }
453 
454                 return shard;
455             }
456             catch (Exception e) {
457                 throw processException(e);
458             }
459             finally {
460                 if (result == null) {
461                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME,
462                         finderArgs, new ArrayList<Shard>());
463                 }
464 
465                 closeSession(session);
466             }
467         }
468         else {
469             if (result instanceof List<?>) {
470                 return null;
471             }
472             else {
473                 return (Shard)result;
474             }
475         }
476     }
477 
478     public Shard findByC_C(long classNameId, long classPK)
479         throws NoSuchShardException, SystemException {
480         Shard shard = fetchByC_C(classNameId, classPK);
481 
482         if (shard == null) {
483             StringBundler msg = new StringBundler(6);
484 
485             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
486 
487             msg.append("classNameId=");
488             msg.append(classNameId);
489 
490             msg.append(", classPK=");
491             msg.append(classPK);
492 
493             msg.append(StringPool.CLOSE_CURLY_BRACE);
494 
495             if (_log.isWarnEnabled()) {
496                 _log.warn(msg.toString());
497             }
498 
499             throw new NoSuchShardException(msg.toString());
500         }
501 
502         return shard;
503     }
504 
505     public Shard fetchByC_C(long classNameId, long classPK)
506         throws SystemException {
507         return fetchByC_C(classNameId, classPK, true);
508     }
509 
510     public Shard fetchByC_C(long classNameId, long classPK,
511         boolean retrieveFromCache) throws SystemException {
512         Object[] finderArgs = new Object[] { classNameId, classPK };
513 
514         Object result = null;
515 
516         if (retrieveFromCache) {
517             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C,
518                     finderArgs, this);
519         }
520 
521         if (result == null) {
522             StringBundler query = new StringBundler(3);
523 
524             query.append(_SQL_SELECT_SHARD_WHERE);
525 
526             query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
527 
528             query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
529 
530             String sql = query.toString();
531 
532             Session session = null;
533 
534             try {
535                 session = openSession();
536 
537                 Query q = session.createQuery(sql);
538 
539                 QueryPos qPos = QueryPos.getInstance(q);
540 
541                 qPos.add(classNameId);
542 
543                 qPos.add(classPK);
544 
545                 List<Shard> list = q.list();
546 
547                 result = list;
548 
549                 Shard shard = null;
550 
551                 if (list.isEmpty()) {
552                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
553                         finderArgs, list);
554                 }
555                 else {
556                     shard = list.get(0);
557 
558                     cacheResult(shard);
559 
560                     if ((shard.getClassNameId() != classNameId) ||
561                             (shard.getClassPK() != classPK)) {
562                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
563                             finderArgs, shard);
564                     }
565                 }
566 
567                 return shard;
568             }
569             catch (Exception e) {
570                 throw processException(e);
571             }
572             finally {
573                 if (result == null) {
574                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
575                         finderArgs, new ArrayList<Shard>());
576                 }
577 
578                 closeSession(session);
579             }
580         }
581         else {
582             if (result instanceof List<?>) {
583                 return null;
584             }
585             else {
586                 return (Shard)result;
587             }
588         }
589     }
590 
591     public List<Shard> findAll() throws SystemException {
592         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
593     }
594 
595     public List<Shard> findAll(int start, int end) throws SystemException {
596         return findAll(start, end, null);
597     }
598 
599     public List<Shard> findAll(int start, int end,
600         OrderByComparator orderByComparator) throws SystemException {
601         Object[] finderArgs = new Object[] {
602                 String.valueOf(start), String.valueOf(end),
603                 String.valueOf(orderByComparator)
604             };
605 
606         List<Shard> list = (List<Shard>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
607                 finderArgs, this);
608 
609         if (list == null) {
610             StringBundler query = null;
611             String sql = null;
612 
613             if (orderByComparator != null) {
614                 query = new StringBundler(2 +
615                         (orderByComparator.getOrderByFields().length * 3));
616 
617                 query.append(_SQL_SELECT_SHARD);
618 
619                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
620                     orderByComparator);
621 
622                 sql = query.toString();
623             }
624             else {
625                 sql = _SQL_SELECT_SHARD;
626             }
627 
628             Session session = null;
629 
630             try {
631                 session = openSession();
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             StringBundler query = new StringBundler(2);
693 
694             query.append(_SQL_COUNT_SHARD_WHERE);
695 
696             if (name == null) {
697                 query.append(_FINDER_COLUMN_NAME_NAME_1);
698             }
699             else {
700                 if (name.equals(StringPool.BLANK)) {
701                     query.append(_FINDER_COLUMN_NAME_NAME_3);
702                 }
703                 else {
704                     query.append(_FINDER_COLUMN_NAME_NAME_2);
705                 }
706             }
707 
708             String sql = query.toString();
709 
710             Session session = null;
711 
712             try {
713                 session = openSession();
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[] { classNameId, classPK };
746 
747         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
748                 finderArgs, this);
749 
750         if (count == null) {
751             StringBundler query = new StringBundler(3);
752 
753             query.append(_SQL_COUNT_SHARD_WHERE);
754 
755             query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
756 
757             query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
758 
759             String sql = query.toString();
760 
761             Session session = null;
762 
763             try {
764                 session = openSession();
765 
766                 Query q = session.createQuery(sql);
767 
768                 QueryPos qPos = QueryPos.getInstance(q);
769 
770                 qPos.add(classNameId);
771 
772                 qPos.add(classPK);
773 
774                 count = (Long)q.uniqueResult();
775             }
776             catch (Exception e) {
777                 throw processException(e);
778             }
779             finally {
780                 if (count == null) {
781                     count = Long.valueOf(0);
782                 }
783 
784                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
785                     count);
786 
787                 closeSession(session);
788             }
789         }
790 
791         return count.intValue();
792     }
793 
794     public int countAll() throws SystemException {
795         Object[] finderArgs = new Object[0];
796 
797         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
798                 finderArgs, this);
799 
800         if (count == null) {
801             Session session = null;
802 
803             try {
804                 session = openSession();
805 
806                 Query q = session.createQuery(_SQL_COUNT_SHARD);
807 
808                 count = (Long)q.uniqueResult();
809             }
810             catch (Exception e) {
811                 throw processException(e);
812             }
813             finally {
814                 if (count == null) {
815                     count = Long.valueOf(0);
816                 }
817 
818                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
819                     count);
820 
821                 closeSession(session);
822             }
823         }
824 
825         return count.intValue();
826     }
827 
828     public void afterPropertiesSet() {
829         String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
830                     com.liferay.portal.util.PropsUtil.get(
831                         "value.object.listener.com.liferay.portal.model.Shard")));
832 
833         if (listenerClassNames.length > 0) {
834             try {
835                 List<ModelListener<Shard>> listenersList = new ArrayList<ModelListener<Shard>>();
836 
837                 for (String listenerClassName : listenerClassNames) {
838                     listenersList.add((ModelListener<Shard>)InstanceFactory.newInstance(
839                             listenerClassName));
840                 }
841 
842                 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
843             }
844             catch (Exception e) {
845                 _log.error(e);
846             }
847         }
848     }
849 
850     public void destroy() {
851         EntityCacheUtil.removeCache(ShardImpl.class.getName());
852         FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
853         FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
854     }
855 
856     @BeanReference(type = AccountPersistence.class)
857     protected AccountPersistence accountPersistence;
858     @BeanReference(type = AddressPersistence.class)
859     protected AddressPersistence addressPersistence;
860     @BeanReference(type = BrowserTrackerPersistence.class)
861     protected BrowserTrackerPersistence browserTrackerPersistence;
862     @BeanReference(type = ClassNamePersistence.class)
863     protected ClassNamePersistence classNamePersistence;
864     @BeanReference(type = CompanyPersistence.class)
865     protected CompanyPersistence companyPersistence;
866     @BeanReference(type = ContactPersistence.class)
867     protected ContactPersistence contactPersistence;
868     @BeanReference(type = CountryPersistence.class)
869     protected CountryPersistence countryPersistence;
870     @BeanReference(type = EmailAddressPersistence.class)
871     protected EmailAddressPersistence emailAddressPersistence;
872     @BeanReference(type = GroupPersistence.class)
873     protected GroupPersistence groupPersistence;
874     @BeanReference(type = ImagePersistence.class)
875     protected ImagePersistence imagePersistence;
876     @BeanReference(type = LayoutPersistence.class)
877     protected LayoutPersistence layoutPersistence;
878     @BeanReference(type = LayoutSetPersistence.class)
879     protected LayoutSetPersistence layoutSetPersistence;
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 = UserPersistence.class)
933     protected UserPersistence userPersistence;
934     @BeanReference(type = UserGroupPersistence.class)
935     protected UserGroupPersistence userGroupPersistence;
936     @BeanReference(type = UserGroupGroupRolePersistence.class)
937     protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
938     @BeanReference(type = UserGroupRolePersistence.class)
939     protected UserGroupRolePersistence userGroupRolePersistence;
940     @BeanReference(type = UserIdMapperPersistence.class)
941     protected UserIdMapperPersistence userIdMapperPersistence;
942     @BeanReference(type = UserTrackerPersistence.class)
943     protected UserTrackerPersistence userTrackerPersistence;
944     @BeanReference(type = UserTrackerPathPersistence.class)
945     protected UserTrackerPathPersistence userTrackerPathPersistence;
946     @BeanReference(type = WebDAVPropsPersistence.class)
947     protected WebDAVPropsPersistence webDAVPropsPersistence;
948     @BeanReference(type = WebsitePersistence.class)
949     protected WebsitePersistence websitePersistence;
950     private static final String _SQL_SELECT_SHARD = "SELECT shard FROM Shard shard";
951     private static final String _SQL_SELECT_SHARD_WHERE = "SELECT shard FROM Shard shard WHERE ";
952     private static final String _SQL_COUNT_SHARD = "SELECT COUNT(shard) FROM Shard shard";
953     private static final String _SQL_COUNT_SHARD_WHERE = "SELECT COUNT(shard) FROM Shard shard WHERE ";
954     private static final String _FINDER_COLUMN_NAME_NAME_1 = "shard.name IS NULL";
955     private static final String _FINDER_COLUMN_NAME_NAME_2 = "shard.name = ?";
956     private static final String _FINDER_COLUMN_NAME_NAME_3 = "(shard.name IS NULL OR shard.name = ?)";
957     private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "shard.classNameId = ? AND ";
958     private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "shard.classPK = ?";
959     private static final String _ORDER_BY_ENTITY_ALIAS = "shard.";
960     private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Shard exists with the primary key ";
961     private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Shard exists with the key {";
962     private static Log _log = LogFactoryUtil.getLog(ShardPersistenceImpl.class);
963 }