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