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