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.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     public Shard remove(Shard shard) throws SystemException {
177         for (ModelListener<Shard> listener : listeners) {
178             listener.onBeforeRemove(shard);
179         }
180 
181         shard = removeImpl(shard);
182 
183         for (ModelListener<Shard> listener : listeners) {
184             listener.onAfterRemove(shard);
185         }
186 
187         return shard;
188     }
189 
190     protected Shard removeImpl(Shard shard) throws SystemException {
191         shard = toUnwrappedModel(shard);
192 
193         Session session = null;
194 
195         try {
196             session = openSession();
197 
198             if (shard.isCachedModel() || BatchSessionUtil.isEnabled()) {
199                 Object staleObject = session.get(ShardImpl.class,
200                         shard.getPrimaryKeyObj());
201 
202                 if (staleObject != null) {
203                     session.evict(staleObject);
204                 }
205             }
206 
207             session.delete(shard);
208 
209             session.flush();
210         }
211         catch (Exception e) {
212             throw processException(e);
213         }
214         finally {
215             closeSession(session);
216         }
217 
218         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
219 
220         ShardModelImpl shardModelImpl = (ShardModelImpl)shard;
221 
222         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_NAME,
223             new Object[] { shardModelImpl.getOriginalName() });
224 
225         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
226             new Object[] {
227                 new Long(shardModelImpl.getOriginalClassNameId()),
228                 new Long(shardModelImpl.getOriginalClassPK())
229             });
230 
231         EntityCacheUtil.removeResult(ShardModelImpl.ENTITY_CACHE_ENABLED,
232             ShardImpl.class, shard.getPrimaryKey());
233 
234         return shard;
235     }
236 
237     public Shard updateImpl(com.liferay.portal.model.Shard shard, boolean merge)
238         throws SystemException {
239         shard = toUnwrappedModel(shard);
240 
241         boolean isNew = shard.isNew();
242 
243         ShardModelImpl shardModelImpl = (ShardModelImpl)shard;
244 
245         Session session = null;
246 
247         try {
248             session = openSession();
249 
250             BatchSessionUtil.update(session, shard, merge);
251 
252             shard.setNew(false);
253         }
254         catch (Exception e) {
255             throw processException(e);
256         }
257         finally {
258             closeSession(session);
259         }
260 
261         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
262 
263         EntityCacheUtil.putResult(ShardModelImpl.ENTITY_CACHE_ENABLED,
264             ShardImpl.class, shard.getPrimaryKey(), shard);
265 
266         if (!isNew &&
267                 (!Validator.equals(shard.getName(),
268                     shardModelImpl.getOriginalName()))) {
269             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_NAME,
270                 new Object[] { shardModelImpl.getOriginalName() });
271         }
272 
273         if (isNew ||
274                 (!Validator.equals(shard.getName(),
275                     shardModelImpl.getOriginalName()))) {
276             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME,
277                 new Object[] { shard.getName() }, shard);
278         }
279 
280         if (!isNew &&
281                 ((shard.getClassNameId() != shardModelImpl.getOriginalClassNameId()) ||
282                 (shard.getClassPK() != shardModelImpl.getOriginalClassPK()))) {
283             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
284                 new Object[] {
285                     new Long(shardModelImpl.getOriginalClassNameId()),
286                     new Long(shardModelImpl.getOriginalClassPK())
287                 });
288         }
289 
290         if (isNew ||
291                 ((shard.getClassNameId() != shardModelImpl.getOriginalClassNameId()) ||
292                 (shard.getClassPK() != shardModelImpl.getOriginalClassPK()))) {
293             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
294                 new Object[] {
295                     new Long(shard.getClassNameId()),
296                     new Long(shard.getClassPK())
297                 }, shard);
298         }
299 
300         return shard;
301     }
302 
303     protected Shard toUnwrappedModel(Shard shard) {
304         if (shard instanceof ShardImpl) {
305             return shard;
306         }
307 
308         ShardImpl shardImpl = new ShardImpl();
309 
310         shardImpl.setNew(shard.isNew());
311         shardImpl.setPrimaryKey(shard.getPrimaryKey());
312 
313         shardImpl.setShardId(shard.getShardId());
314         shardImpl.setClassNameId(shard.getClassNameId());
315         shardImpl.setClassPK(shard.getClassPK());
316         shardImpl.setName(shard.getName());
317 
318         return shardImpl;
319     }
320 
321     public Shard findByPrimaryKey(Serializable primaryKey)
322         throws NoSuchModelException, SystemException {
323         return findByPrimaryKey(((Long)primaryKey).longValue());
324     }
325 
326     public Shard findByPrimaryKey(long shardId)
327         throws NoSuchShardException, SystemException {
328         Shard shard = fetchByPrimaryKey(shardId);
329 
330         if (shard == null) {
331             if (_log.isWarnEnabled()) {
332                 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + shardId);
333             }
334 
335             throw new NoSuchShardException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
336                 shardId);
337         }
338 
339         return shard;
340     }
341 
342     public Shard fetchByPrimaryKey(Serializable primaryKey)
343         throws SystemException {
344         return fetchByPrimaryKey(((Long)primaryKey).longValue());
345     }
346 
347     public Shard fetchByPrimaryKey(long shardId) throws SystemException {
348         Shard shard = (Shard)EntityCacheUtil.getResult(ShardModelImpl.ENTITY_CACHE_ENABLED,
349                 ShardImpl.class, shardId, this);
350 
351         if (shard == null) {
352             Session session = null;
353 
354             try {
355                 session = openSession();
356 
357                 shard = (Shard)session.get(ShardImpl.class, new Long(shardId));
358             }
359             catch (Exception e) {
360                 throw processException(e);
361             }
362             finally {
363                 if (shard != null) {
364                     cacheResult(shard);
365                 }
366 
367                 closeSession(session);
368             }
369         }
370 
371         return shard;
372     }
373 
374     public Shard findByName(String name)
375         throws NoSuchShardException, SystemException {
376         Shard shard = fetchByName(name);
377 
378         if (shard == null) {
379             StringBundler msg = new StringBundler(4);
380 
381             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
382 
383             msg.append("name=");
384             msg.append(name);
385 
386             msg.append(StringPool.CLOSE_CURLY_BRACE);
387 
388             if (_log.isWarnEnabled()) {
389                 _log.warn(msg.toString());
390             }
391 
392             throw new NoSuchShardException(msg.toString());
393         }
394 
395         return shard;
396     }
397 
398     public Shard fetchByName(String name) throws SystemException {
399         return fetchByName(name, true);
400     }
401 
402     public Shard fetchByName(String name, boolean retrieveFromCache)
403         throws SystemException {
404         Object[] finderArgs = new Object[] { name };
405 
406         Object result = null;
407 
408         if (retrieveFromCache) {
409             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_NAME,
410                     finderArgs, this);
411         }
412 
413         if (result == null) {
414             Session session = null;
415 
416             try {
417                 session = openSession();
418 
419                 StringBundler query = new StringBundler(2);
420 
421                 query.append(_SQL_SELECT_SHARD_WHERE);
422 
423                 if (name == null) {
424                     query.append(_FINDER_COLUMN_NAME_NAME_1);
425                 }
426                 else {
427                     if (name.equals(StringPool.BLANK)) {
428                         query.append(_FINDER_COLUMN_NAME_NAME_3);
429                     }
430                     else {
431                         query.append(_FINDER_COLUMN_NAME_NAME_2);
432                     }
433                 }
434 
435                 String sql = query.toString();
436 
437                 Query q = session.createQuery(sql);
438 
439                 QueryPos qPos = QueryPos.getInstance(q);
440 
441                 if (name != null) {
442                     qPos.add(name);
443                 }
444 
445                 List<Shard> list = q.list();
446 
447                 result = list;
448 
449                 Shard shard = null;
450 
451                 if (list.isEmpty()) {
452                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME,
453                         finderArgs, list);
454                 }
455                 else {
456                     shard = list.get(0);
457 
458                     cacheResult(shard);
459 
460                     if ((shard.getName() == null) ||
461                             !shard.getName().equals(name)) {
462                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME,
463                             finderArgs, shard);
464                     }
465                 }
466 
467                 return shard;
468             }
469             catch (Exception e) {
470                 throw processException(e);
471             }
472             finally {
473                 if (result == null) {
474                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_NAME,
475                         finderArgs, new ArrayList<Shard>());
476                 }
477 
478                 closeSession(session);
479             }
480         }
481         else {
482             if (result instanceof List<?>) {
483                 return null;
484             }
485             else {
486                 return (Shard)result;
487             }
488         }
489     }
490 
491     public Shard findByC_C(long classNameId, long classPK)
492         throws NoSuchShardException, SystemException {
493         Shard shard = fetchByC_C(classNameId, classPK);
494 
495         if (shard == null) {
496             StringBundler msg = new StringBundler(6);
497 
498             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
499 
500             msg.append("classNameId=");
501             msg.append(classNameId);
502 
503             msg.append(", classPK=");
504             msg.append(classPK);
505 
506             msg.append(StringPool.CLOSE_CURLY_BRACE);
507 
508             if (_log.isWarnEnabled()) {
509                 _log.warn(msg.toString());
510             }
511 
512             throw new NoSuchShardException(msg.toString());
513         }
514 
515         return shard;
516     }
517 
518     public Shard fetchByC_C(long classNameId, long classPK)
519         throws SystemException {
520         return fetchByC_C(classNameId, classPK, true);
521     }
522 
523     public Shard fetchByC_C(long classNameId, long classPK,
524         boolean retrieveFromCache) throws SystemException {
525         Object[] finderArgs = new Object[] {
526                 new Long(classNameId), new Long(classPK)
527             };
528 
529         Object result = null;
530 
531         if (retrieveFromCache) {
532             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C,
533                     finderArgs, this);
534         }
535 
536         if (result == null) {
537             Session session = null;
538 
539             try {
540                 session = openSession();
541 
542                 StringBundler query = new StringBundler(3);
543 
544                 query.append(_SQL_SELECT_SHARD_WHERE);
545 
546                 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
547 
548                 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
549 
550                 String sql = query.toString();
551 
552                 Query q = session.createQuery(sql);
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<Shard> findAll() throws SystemException {
607         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
608     }
609 
610     public List<Shard> findAll(int start, int end) throws SystemException {
611         return findAll(start, end, null);
612     }
613 
614     public List<Shard> findAll(int start, int end,
615         OrderByComparator orderByComparator) throws SystemException {
616         Object[] finderArgs = new Object[] {
617                 String.valueOf(start), String.valueOf(end),
618                 String.valueOf(orderByComparator)
619             };
620 
621         List<Shard> list = (List<Shard>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
622                 finderArgs, this);
623 
624         if (list == null) {
625             Session session = null;
626 
627             try {
628                 session = openSession();
629 
630                 StringBundler query = null;
631                 String sql = null;
632 
633                 if (orderByComparator != null) {
634                     query = new StringBundler(2 +
635                             (orderByComparator.getOrderByFields().length * 3));
636 
637                     query.append(_SQL_SELECT_SHARD);
638 
639                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
640                         orderByComparator);
641 
642                     sql = query.toString();
643                 }
644 
645                 sql = _SQL_SELECT_SHARD;
646 
647                 Query q = session.createQuery(sql);
648 
649                 if (orderByComparator == null) {
650                     list = (List<Shard>)QueryUtil.list(q, getDialect(), start,
651                             end, false);
652 
653                     Collections.sort(list);
654                 }
655                 else {
656                     list = (List<Shard>)QueryUtil.list(q, getDialect(), start,
657                             end);
658                 }
659             }
660             catch (Exception e) {
661                 throw processException(e);
662             }
663             finally {
664                 if (list == null) {
665                     list = new ArrayList<Shard>();
666                 }
667 
668                 cacheResult(list);
669 
670                 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
671 
672                 closeSession(session);
673             }
674         }
675 
676         return list;
677     }
678 
679     public void removeByName(String name)
680         throws NoSuchShardException, SystemException {
681         Shard shard = findByName(name);
682 
683         remove(shard);
684     }
685 
686     public void removeByC_C(long classNameId, long classPK)
687         throws NoSuchShardException, SystemException {
688         Shard shard = findByC_C(classNameId, classPK);
689 
690         remove(shard);
691     }
692 
693     public void removeAll() throws SystemException {
694         for (Shard shard : findAll()) {
695             remove(shard);
696         }
697     }
698 
699     public int countByName(String name) throws SystemException {
700         Object[] finderArgs = new Object[] { name };
701 
702         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_NAME,
703                 finderArgs, this);
704 
705         if (count == null) {
706             Session session = null;
707 
708             try {
709                 session = openSession();
710 
711                 StringBundler query = new StringBundler(2);
712 
713                 query.append(_SQL_COUNT_SHARD_WHERE);
714 
715                 if (name == null) {
716                     query.append(_FINDER_COLUMN_NAME_NAME_1);
717                 }
718                 else {
719                     if (name.equals(StringPool.BLANK)) {
720                         query.append(_FINDER_COLUMN_NAME_NAME_3);
721                     }
722                     else {
723                         query.append(_FINDER_COLUMN_NAME_NAME_2);
724                     }
725                 }
726 
727                 String sql = query.toString();
728 
729                 Query q = session.createQuery(sql);
730 
731                 QueryPos qPos = QueryPos.getInstance(q);
732 
733                 if (name != null) {
734                     qPos.add(name);
735                 }
736 
737                 count = (Long)q.uniqueResult();
738             }
739             catch (Exception e) {
740                 throw processException(e);
741             }
742             finally {
743                 if (count == null) {
744                     count = Long.valueOf(0);
745                 }
746 
747                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_NAME,
748                     finderArgs, count);
749 
750                 closeSession(session);
751             }
752         }
753 
754         return count.intValue();
755     }
756 
757     public int countByC_C(long classNameId, long classPK)
758         throws SystemException {
759         Object[] finderArgs = new Object[] {
760                 new Long(classNameId), new Long(classPK)
761             };
762 
763         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
764                 finderArgs, this);
765 
766         if (count == null) {
767             Session session = null;
768 
769             try {
770                 session = openSession();
771 
772                 StringBundler query = new StringBundler(3);
773 
774                 query.append(_SQL_COUNT_SHARD_WHERE);
775 
776                 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
777 
778                 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
779 
780                 String sql = query.toString();
781 
782                 Query q = session.createQuery(sql);
783 
784                 QueryPos qPos = QueryPos.getInstance(q);
785 
786                 qPos.add(classNameId);
787 
788                 qPos.add(classPK);
789 
790                 count = (Long)q.uniqueResult();
791             }
792             catch (Exception e) {
793                 throw processException(e);
794             }
795             finally {
796                 if (count == null) {
797                     count = Long.valueOf(0);
798                 }
799 
800                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
801                     count);
802 
803                 closeSession(session);
804             }
805         }
806 
807         return count.intValue();
808     }
809 
810     public int countAll() throws SystemException {
811         Object[] finderArgs = new Object[0];
812 
813         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
814                 finderArgs, this);
815 
816         if (count == null) {
817             Session session = null;
818 
819             try {
820                 session = openSession();
821 
822                 Query q = session.createQuery(_SQL_COUNT_SHARD);
823 
824                 count = (Long)q.uniqueResult();
825             }
826             catch (Exception e) {
827                 throw processException(e);
828             }
829             finally {
830                 if (count == null) {
831                     count = Long.valueOf(0);
832                 }
833 
834                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
835                     count);
836 
837                 closeSession(session);
838             }
839         }
840 
841         return count.intValue();
842     }
843 
844     public void afterPropertiesSet() {
845         String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
846                     com.liferay.portal.util.PropsUtil.get(
847                         "value.object.listener.com.liferay.portal.model.Shard")));
848 
849         if (listenerClassNames.length > 0) {
850             try {
851                 List<ModelListener<Shard>> listenersList = new ArrayList<ModelListener<Shard>>();
852 
853                 for (String listenerClassName : listenerClassNames) {
854                     listenersList.add((ModelListener<Shard>)InstanceFactory.newInstance(
855                             listenerClassName));
856                 }
857 
858                 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
859             }
860             catch (Exception e) {
861                 _log.error(e);
862             }
863         }
864     }
865 
866     @BeanReference(type = AccountPersistence.class)
867     protected AccountPersistence accountPersistence;
868     @BeanReference(type = AddressPersistence.class)
869     protected AddressPersistence addressPersistence;
870     @BeanReference(type = BrowserTrackerPersistence.class)
871     protected BrowserTrackerPersistence browserTrackerPersistence;
872     @BeanReference(type = ClassNamePersistence.class)
873     protected ClassNamePersistence classNamePersistence;
874     @BeanReference(type = CompanyPersistence.class)
875     protected CompanyPersistence companyPersistence;
876     @BeanReference(type = ContactPersistence.class)
877     protected ContactPersistence contactPersistence;
878     @BeanReference(type = CountryPersistence.class)
879     protected CountryPersistence countryPersistence;
880     @BeanReference(type = EmailAddressPersistence.class)
881     protected EmailAddressPersistence emailAddressPersistence;
882     @BeanReference(type = GroupPersistence.class)
883     protected GroupPersistence groupPersistence;
884     @BeanReference(type = ImagePersistence.class)
885     protected ImagePersistence imagePersistence;
886     @BeanReference(type = LayoutPersistence.class)
887     protected LayoutPersistence layoutPersistence;
888     @BeanReference(type = LayoutPrototypePersistence.class)
889     protected LayoutPrototypePersistence layoutPrototypePersistence;
890     @BeanReference(type = LayoutSetPersistence.class)
891     protected LayoutSetPersistence layoutSetPersistence;
892     @BeanReference(type = LayoutSetPrototypePersistence.class)
893     protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
894     @BeanReference(type = ListTypePersistence.class)
895     protected ListTypePersistence listTypePersistence;
896     @BeanReference(type = LockPersistence.class)
897     protected LockPersistence lockPersistence;
898     @BeanReference(type = MembershipRequestPersistence.class)
899     protected MembershipRequestPersistence membershipRequestPersistence;
900     @BeanReference(type = OrganizationPersistence.class)
901     protected OrganizationPersistence organizationPersistence;
902     @BeanReference(type = OrgGroupPermissionPersistence.class)
903     protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
904     @BeanReference(type = OrgGroupRolePersistence.class)
905     protected OrgGroupRolePersistence orgGroupRolePersistence;
906     @BeanReference(type = OrgLaborPersistence.class)
907     protected OrgLaborPersistence orgLaborPersistence;
908     @BeanReference(type = PasswordPolicyPersistence.class)
909     protected PasswordPolicyPersistence passwordPolicyPersistence;
910     @BeanReference(type = PasswordPolicyRelPersistence.class)
911     protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
912     @BeanReference(type = PasswordTrackerPersistence.class)
913     protected PasswordTrackerPersistence passwordTrackerPersistence;
914     @BeanReference(type = PermissionPersistence.class)
915     protected PermissionPersistence permissionPersistence;
916     @BeanReference(type = PhonePersistence.class)
917     protected PhonePersistence phonePersistence;
918     @BeanReference(type = PluginSettingPersistence.class)
919     protected PluginSettingPersistence pluginSettingPersistence;
920     @BeanReference(type = PortletPersistence.class)
921     protected PortletPersistence portletPersistence;
922     @BeanReference(type = PortletItemPersistence.class)
923     protected PortletItemPersistence portletItemPersistence;
924     @BeanReference(type = PortletPreferencesPersistence.class)
925     protected PortletPreferencesPersistence portletPreferencesPersistence;
926     @BeanReference(type = RegionPersistence.class)
927     protected RegionPersistence regionPersistence;
928     @BeanReference(type = ReleasePersistence.class)
929     protected ReleasePersistence releasePersistence;
930     @BeanReference(type = ResourcePersistence.class)
931     protected ResourcePersistence resourcePersistence;
932     @BeanReference(type = ResourceActionPersistence.class)
933     protected ResourceActionPersistence resourceActionPersistence;
934     @BeanReference(type = ResourceCodePersistence.class)
935     protected ResourceCodePersistence resourceCodePersistence;
936     @BeanReference(type = ResourcePermissionPersistence.class)
937     protected ResourcePermissionPersistence resourcePermissionPersistence;
938     @BeanReference(type = RolePersistence.class)
939     protected RolePersistence rolePersistence;
940     @BeanReference(type = ServiceComponentPersistence.class)
941     protected ServiceComponentPersistence serviceComponentPersistence;
942     @BeanReference(type = ShardPersistence.class)
943     protected ShardPersistence shardPersistence;
944     @BeanReference(type = SubscriptionPersistence.class)
945     protected SubscriptionPersistence subscriptionPersistence;
946     @BeanReference(type = TicketPersistence.class)
947     protected TicketPersistence ticketPersistence;
948     @BeanReference(type = TeamPersistence.class)
949     protected TeamPersistence teamPersistence;
950     @BeanReference(type = UserPersistence.class)
951     protected UserPersistence userPersistence;
952     @BeanReference(type = UserGroupPersistence.class)
953     protected UserGroupPersistence userGroupPersistence;
954     @BeanReference(type = UserGroupGroupRolePersistence.class)
955     protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
956     @BeanReference(type = UserGroupRolePersistence.class)
957     protected UserGroupRolePersistence userGroupRolePersistence;
958     @BeanReference(type = UserIdMapperPersistence.class)
959     protected UserIdMapperPersistence userIdMapperPersistence;
960     @BeanReference(type = UserTrackerPersistence.class)
961     protected UserTrackerPersistence userTrackerPersistence;
962     @BeanReference(type = UserTrackerPathPersistence.class)
963     protected UserTrackerPathPersistence userTrackerPathPersistence;
964     @BeanReference(type = WebDAVPropsPersistence.class)
965     protected WebDAVPropsPersistence webDAVPropsPersistence;
966     @BeanReference(type = WebsitePersistence.class)
967     protected WebsitePersistence websitePersistence;
968     @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
969     protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
970     @BeanReference(type = WorkflowInstanceLinkPersistence.class)
971     protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
972     private static final String _SQL_SELECT_SHARD = "SELECT shard FROM Shard shard";
973     private static final String _SQL_SELECT_SHARD_WHERE = "SELECT shard FROM Shard shard WHERE ";
974     private static final String _SQL_COUNT_SHARD = "SELECT COUNT(shard) FROM Shard shard";
975     private static final String _SQL_COUNT_SHARD_WHERE = "SELECT COUNT(shard) FROM Shard shard WHERE ";
976     private static final String _FINDER_COLUMN_NAME_NAME_1 = "shard.name IS NULL";
977     private static final String _FINDER_COLUMN_NAME_NAME_2 = "shard.name = ?";
978     private static final String _FINDER_COLUMN_NAME_NAME_3 = "(shard.name IS NULL OR shard.name = ?)";
979     private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "shard.classNameId = ? AND ";
980     private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "shard.classPK = ?";
981     private static final String _ORDER_BY_ENTITY_ALIAS = "shard.";
982     private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Shard exists with the primary key ";
983     private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Shard exists with the key {";
984     private static Log _log = LogFactoryUtil.getLog(ShardPersistenceImpl.class);
985 }