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.NoSuchOrgLaborException;
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.model.ModelListener;
38  import com.liferay.portal.model.OrgLabor;
39  import com.liferay.portal.model.impl.OrgLaborImpl;
40  import com.liferay.portal.model.impl.OrgLaborModelImpl;
41  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
42  
43  import java.io.Serializable;
44  
45  import java.util.ArrayList;
46  import java.util.Collections;
47  import java.util.List;
48  
49  /**
50   * <a href="OrgLaborPersistenceImpl.java.html"><b><i>View Source</i></b></a>
51   *
52   * <p>
53   * ServiceBuilder generated this class. Modifications in this class will be
54   * overwritten the next time is generated.
55   * </p>
56   *
57   * @author    Brian Wing Shun Chan
58   * @see       OrgLaborPersistence
59   * @see       OrgLaborUtil
60   * @generated
61   */
62  public class OrgLaborPersistenceImpl extends BasePersistenceImpl<OrgLabor>
63      implements OrgLaborPersistence {
64      public static final String FINDER_CLASS_NAME_ENTITY = OrgLaborImpl.class.getName();
65      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
66          ".List";
67      public static final FinderPath FINDER_PATH_FIND_BY_ORGANIZATIONID = new FinderPath(OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
68              OrgLaborModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
69              "findByOrganizationId",
70              new String[] {
71                  Long.class.getName(),
72                  
73              "java.lang.Integer", "java.lang.Integer",
74                  "com.liferay.portal.kernel.util.OrderByComparator"
75              });
76      public static final FinderPath FINDER_PATH_COUNT_BY_ORGANIZATIONID = new FinderPath(OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
77              OrgLaborModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
78              "countByOrganizationId", new String[] { Long.class.getName() });
79      public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
80              OrgLaborModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
81              "findAll", new String[0]);
82      public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
83              OrgLaborModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
84              "countAll", new String[0]);
85  
86      public void cacheResult(OrgLabor orgLabor) {
87          EntityCacheUtil.putResult(OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
88              OrgLaborImpl.class, orgLabor.getPrimaryKey(), orgLabor);
89      }
90  
91      public void cacheResult(List<OrgLabor> orgLabors) {
92          for (OrgLabor orgLabor : orgLabors) {
93              if (EntityCacheUtil.getResult(
94                          OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
95                          OrgLaborImpl.class, orgLabor.getPrimaryKey(), this) == null) {
96                  cacheResult(orgLabor);
97              }
98          }
99      }
100 
101     public void clearCache() {
102         CacheRegistry.clear(OrgLaborImpl.class.getName());
103         EntityCacheUtil.clearCache(OrgLaborImpl.class.getName());
104         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
105         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
106     }
107 
108     public void clearCache(OrgLabor orgLabor) {
109         EntityCacheUtil.removeResult(OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
110             OrgLaborImpl.class, orgLabor.getPrimaryKey());
111     }
112 
113     public OrgLabor create(long orgLaborId) {
114         OrgLabor orgLabor = new OrgLaborImpl();
115 
116         orgLabor.setNew(true);
117         orgLabor.setPrimaryKey(orgLaborId);
118 
119         return orgLabor;
120     }
121 
122     public OrgLabor remove(Serializable primaryKey)
123         throws NoSuchModelException, SystemException {
124         return remove(((Long)primaryKey).longValue());
125     }
126 
127     public OrgLabor remove(long orgLaborId)
128         throws NoSuchOrgLaborException, SystemException {
129         Session session = null;
130 
131         try {
132             session = openSession();
133 
134             OrgLabor orgLabor = (OrgLabor)session.get(OrgLaborImpl.class,
135                     new Long(orgLaborId));
136 
137             if (orgLabor == null) {
138                 if (_log.isWarnEnabled()) {
139                     _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + orgLaborId);
140                 }
141 
142                 throw new NoSuchOrgLaborException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
143                     orgLaborId);
144             }
145 
146             return remove(orgLabor);
147         }
148         catch (NoSuchOrgLaborException nsee) {
149             throw nsee;
150         }
151         catch (Exception e) {
152             throw processException(e);
153         }
154         finally {
155             closeSession(session);
156         }
157     }
158 
159     public OrgLabor remove(OrgLabor orgLabor) throws SystemException {
160         for (ModelListener<OrgLabor> listener : listeners) {
161             listener.onBeforeRemove(orgLabor);
162         }
163 
164         orgLabor = removeImpl(orgLabor);
165 
166         for (ModelListener<OrgLabor> listener : listeners) {
167             listener.onAfterRemove(orgLabor);
168         }
169 
170         return orgLabor;
171     }
172 
173     protected OrgLabor removeImpl(OrgLabor orgLabor) throws SystemException {
174         orgLabor = toUnwrappedModel(orgLabor);
175 
176         Session session = null;
177 
178         try {
179             session = openSession();
180 
181             if (orgLabor.isCachedModel() || BatchSessionUtil.isEnabled()) {
182                 Object staleObject = session.get(OrgLaborImpl.class,
183                         orgLabor.getPrimaryKeyObj());
184 
185                 if (staleObject != null) {
186                     session.evict(staleObject);
187                 }
188             }
189 
190             session.delete(orgLabor);
191 
192             session.flush();
193         }
194         catch (Exception e) {
195             throw processException(e);
196         }
197         finally {
198             closeSession(session);
199         }
200 
201         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
202 
203         EntityCacheUtil.removeResult(OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
204             OrgLaborImpl.class, orgLabor.getPrimaryKey());
205 
206         return orgLabor;
207     }
208 
209     public OrgLabor updateImpl(com.liferay.portal.model.OrgLabor orgLabor,
210         boolean merge) throws SystemException {
211         orgLabor = toUnwrappedModel(orgLabor);
212 
213         Session session = null;
214 
215         try {
216             session = openSession();
217 
218             BatchSessionUtil.update(session, orgLabor, merge);
219 
220             orgLabor.setNew(false);
221         }
222         catch (Exception e) {
223             throw processException(e);
224         }
225         finally {
226             closeSession(session);
227         }
228 
229         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
230 
231         EntityCacheUtil.putResult(OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
232             OrgLaborImpl.class, orgLabor.getPrimaryKey(), orgLabor);
233 
234         return orgLabor;
235     }
236 
237     protected OrgLabor toUnwrappedModel(OrgLabor orgLabor) {
238         if (orgLabor instanceof OrgLaborImpl) {
239             return orgLabor;
240         }
241 
242         OrgLaborImpl orgLaborImpl = new OrgLaborImpl();
243 
244         orgLaborImpl.setNew(orgLabor.isNew());
245         orgLaborImpl.setPrimaryKey(orgLabor.getPrimaryKey());
246 
247         orgLaborImpl.setOrgLaborId(orgLabor.getOrgLaborId());
248         orgLaborImpl.setOrganizationId(orgLabor.getOrganizationId());
249         orgLaborImpl.setTypeId(orgLabor.getTypeId());
250         orgLaborImpl.setSunOpen(orgLabor.getSunOpen());
251         orgLaborImpl.setSunClose(orgLabor.getSunClose());
252         orgLaborImpl.setMonOpen(orgLabor.getMonOpen());
253         orgLaborImpl.setMonClose(orgLabor.getMonClose());
254         orgLaborImpl.setTueOpen(orgLabor.getTueOpen());
255         orgLaborImpl.setTueClose(orgLabor.getTueClose());
256         orgLaborImpl.setWedOpen(orgLabor.getWedOpen());
257         orgLaborImpl.setWedClose(orgLabor.getWedClose());
258         orgLaborImpl.setThuOpen(orgLabor.getThuOpen());
259         orgLaborImpl.setThuClose(orgLabor.getThuClose());
260         orgLaborImpl.setFriOpen(orgLabor.getFriOpen());
261         orgLaborImpl.setFriClose(orgLabor.getFriClose());
262         orgLaborImpl.setSatOpen(orgLabor.getSatOpen());
263         orgLaborImpl.setSatClose(orgLabor.getSatClose());
264 
265         return orgLaborImpl;
266     }
267 
268     public OrgLabor findByPrimaryKey(Serializable primaryKey)
269         throws NoSuchModelException, SystemException {
270         return findByPrimaryKey(((Long)primaryKey).longValue());
271     }
272 
273     public OrgLabor findByPrimaryKey(long orgLaborId)
274         throws NoSuchOrgLaborException, SystemException {
275         OrgLabor orgLabor = fetchByPrimaryKey(orgLaborId);
276 
277         if (orgLabor == null) {
278             if (_log.isWarnEnabled()) {
279                 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + orgLaborId);
280             }
281 
282             throw new NoSuchOrgLaborException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
283                 orgLaborId);
284         }
285 
286         return orgLabor;
287     }
288 
289     public OrgLabor fetchByPrimaryKey(Serializable primaryKey)
290         throws SystemException {
291         return fetchByPrimaryKey(((Long)primaryKey).longValue());
292     }
293 
294     public OrgLabor fetchByPrimaryKey(long orgLaborId)
295         throws SystemException {
296         OrgLabor orgLabor = (OrgLabor)EntityCacheUtil.getResult(OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
297                 OrgLaborImpl.class, orgLaborId, this);
298 
299         if (orgLabor == null) {
300             Session session = null;
301 
302             try {
303                 session = openSession();
304 
305                 orgLabor = (OrgLabor)session.get(OrgLaborImpl.class,
306                         new Long(orgLaborId));
307             }
308             catch (Exception e) {
309                 throw processException(e);
310             }
311             finally {
312                 if (orgLabor != null) {
313                     cacheResult(orgLabor);
314                 }
315 
316                 closeSession(session);
317             }
318         }
319 
320         return orgLabor;
321     }
322 
323     public List<OrgLabor> findByOrganizationId(long organizationId)
324         throws SystemException {
325         return findByOrganizationId(organizationId, QueryUtil.ALL_POS,
326             QueryUtil.ALL_POS, null);
327     }
328 
329     public List<OrgLabor> findByOrganizationId(long organizationId, int start,
330         int end) throws SystemException {
331         return findByOrganizationId(organizationId, start, end, null);
332     }
333 
334     public List<OrgLabor> findByOrganizationId(long organizationId, int start,
335         int end, OrderByComparator orderByComparator) throws SystemException {
336         Object[] finderArgs = new Object[] {
337                 new Long(organizationId),
338                 
339                 String.valueOf(start), String.valueOf(end),
340                 String.valueOf(orderByComparator)
341             };
342 
343         List<OrgLabor> list = (List<OrgLabor>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_ORGANIZATIONID,
344                 finderArgs, this);
345 
346         if (list == null) {
347             Session session = null;
348 
349             try {
350                 session = openSession();
351 
352                 StringBundler query = null;
353 
354                 if (orderByComparator != null) {
355                     query = new StringBundler(3 +
356                             (orderByComparator.getOrderByFields().length * 3));
357                 }
358                 else {
359                     query = new StringBundler(3);
360                 }
361 
362                 query.append(_SQL_SELECT_ORGLABOR_WHERE);
363 
364                 query.append(_FINDER_COLUMN_ORGANIZATIONID_ORGANIZATIONID_2);
365 
366                 if (orderByComparator != null) {
367                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
368                         orderByComparator);
369                 }
370 
371                 else {
372                     query.append(OrgLaborModelImpl.ORDER_BY_JPQL);
373                 }
374 
375                 String sql = query.toString();
376 
377                 Query q = session.createQuery(sql);
378 
379                 QueryPos qPos = QueryPos.getInstance(q);
380 
381                 qPos.add(organizationId);
382 
383                 list = (List<OrgLabor>)QueryUtil.list(q, getDialect(), start,
384                         end);
385             }
386             catch (Exception e) {
387                 throw processException(e);
388             }
389             finally {
390                 if (list == null) {
391                     list = new ArrayList<OrgLabor>();
392                 }
393 
394                 cacheResult(list);
395 
396                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_ORGANIZATIONID,
397                     finderArgs, list);
398 
399                 closeSession(session);
400             }
401         }
402 
403         return list;
404     }
405 
406     public OrgLabor findByOrganizationId_First(long organizationId,
407         OrderByComparator orderByComparator)
408         throws NoSuchOrgLaborException, SystemException {
409         List<OrgLabor> list = findByOrganizationId(organizationId, 0, 1,
410                 orderByComparator);
411 
412         if (list.isEmpty()) {
413             StringBundler msg = new StringBundler(4);
414 
415             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
416 
417             msg.append("organizationId=");
418             msg.append(organizationId);
419 
420             msg.append(StringPool.CLOSE_CURLY_BRACE);
421 
422             throw new NoSuchOrgLaborException(msg.toString());
423         }
424         else {
425             return list.get(0);
426         }
427     }
428 
429     public OrgLabor findByOrganizationId_Last(long organizationId,
430         OrderByComparator orderByComparator)
431         throws NoSuchOrgLaborException, SystemException {
432         int count = countByOrganizationId(organizationId);
433 
434         List<OrgLabor> list = findByOrganizationId(organizationId, count - 1,
435                 count, orderByComparator);
436 
437         if (list.isEmpty()) {
438             StringBundler msg = new StringBundler(4);
439 
440             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
441 
442             msg.append("organizationId=");
443             msg.append(organizationId);
444 
445             msg.append(StringPool.CLOSE_CURLY_BRACE);
446 
447             throw new NoSuchOrgLaborException(msg.toString());
448         }
449         else {
450             return list.get(0);
451         }
452     }
453 
454     public OrgLabor[] findByOrganizationId_PrevAndNext(long orgLaborId,
455         long organizationId, OrderByComparator orderByComparator)
456         throws NoSuchOrgLaborException, SystemException {
457         OrgLabor orgLabor = findByPrimaryKey(orgLaborId);
458 
459         Session session = null;
460 
461         try {
462             session = openSession();
463 
464             OrgLabor[] array = new OrgLaborImpl[3];
465 
466             array[0] = getByOrganizationId_PrevAndNext(session, orgLabor,
467                     organizationId, orderByComparator, true);
468 
469             array[1] = orgLabor;
470 
471             array[2] = getByOrganizationId_PrevAndNext(session, orgLabor,
472                     organizationId, orderByComparator, false);
473 
474             return array;
475         }
476         catch (Exception e) {
477             throw processException(e);
478         }
479         finally {
480             closeSession(session);
481         }
482     }
483 
484     protected OrgLabor getByOrganizationId_PrevAndNext(Session session,
485         OrgLabor orgLabor, long organizationId,
486         OrderByComparator orderByComparator, boolean previous) {
487         StringBundler query = null;
488 
489         if (orderByComparator != null) {
490             query = new StringBundler(6 +
491                     (orderByComparator.getOrderByFields().length * 6));
492         }
493         else {
494             query = new StringBundler(3);
495         }
496 
497         query.append(_SQL_SELECT_ORGLABOR_WHERE);
498 
499         query.append(_FINDER_COLUMN_ORGANIZATIONID_ORGANIZATIONID_2);
500 
501         if (orderByComparator != null) {
502             String[] orderByFields = orderByComparator.getOrderByFields();
503 
504             if (orderByFields.length > 0) {
505                 query.append(WHERE_AND);
506             }
507 
508             for (int i = 0; i < orderByFields.length; i++) {
509                 query.append(_ORDER_BY_ENTITY_ALIAS);
510                 query.append(orderByFields[i]);
511 
512                 if ((i + 1) < orderByFields.length) {
513                     if (orderByComparator.isAscending() ^ previous) {
514                         query.append(WHERE_GREATER_THAN_HAS_NEXT);
515                     }
516                     else {
517                         query.append(WHERE_LESSER_THAN_HAS_NEXT);
518                     }
519                 }
520                 else {
521                     if (orderByComparator.isAscending() ^ previous) {
522                         query.append(WHERE_GREATER_THAN);
523                     }
524                     else {
525                         query.append(WHERE_LESSER_THAN);
526                     }
527                 }
528             }
529 
530             query.append(ORDER_BY_CLAUSE);
531 
532             for (int i = 0; i < orderByFields.length; i++) {
533                 query.append(_ORDER_BY_ENTITY_ALIAS);
534                 query.append(orderByFields[i]);
535 
536                 if ((i + 1) < orderByFields.length) {
537                     if (orderByComparator.isAscending() ^ previous) {
538                         query.append(ORDER_BY_ASC_HAS_NEXT);
539                     }
540                     else {
541                         query.append(ORDER_BY_DESC_HAS_NEXT);
542                     }
543                 }
544                 else {
545                     if (orderByComparator.isAscending() ^ previous) {
546                         query.append(ORDER_BY_ASC);
547                     }
548                     else {
549                         query.append(ORDER_BY_DESC);
550                     }
551                 }
552             }
553         }
554 
555         else {
556             query.append(OrgLaborModelImpl.ORDER_BY_JPQL);
557         }
558 
559         String sql = query.toString();
560 
561         Query q = session.createQuery(sql);
562 
563         q.setFirstResult(0);
564         q.setMaxResults(2);
565 
566         QueryPos qPos = QueryPos.getInstance(q);
567 
568         qPos.add(organizationId);
569 
570         if (orderByComparator != null) {
571             Object[] values = orderByComparator.getOrderByValues(orgLabor);
572 
573             for (Object value : values) {
574                 qPos.add(value);
575             }
576         }
577 
578         List<OrgLabor> list = q.list();
579 
580         if (list.size() == 2) {
581             return list.get(1);
582         }
583         else {
584             return null;
585         }
586     }
587 
588     public List<OrgLabor> findAll() throws SystemException {
589         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
590     }
591 
592     public List<OrgLabor> findAll(int start, int end) throws SystemException {
593         return findAll(start, end, null);
594     }
595 
596     public List<OrgLabor> findAll(int start, int end,
597         OrderByComparator orderByComparator) throws SystemException {
598         Object[] finderArgs = new Object[] {
599                 String.valueOf(start), String.valueOf(end),
600                 String.valueOf(orderByComparator)
601             };
602 
603         List<OrgLabor> list = (List<OrgLabor>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
604                 finderArgs, this);
605 
606         if (list == null) {
607             Session session = null;
608 
609             try {
610                 session = openSession();
611 
612                 StringBundler query = null;
613                 String sql = null;
614 
615                 if (orderByComparator != null) {
616                     query = new StringBundler(2 +
617                             (orderByComparator.getOrderByFields().length * 3));
618 
619                     query.append(_SQL_SELECT_ORGLABOR);
620 
621                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
622                         orderByComparator);
623 
624                     sql = query.toString();
625                 }
626 
627                 else {
628                     sql = _SQL_SELECT_ORGLABOR.concat(OrgLaborModelImpl.ORDER_BY_JPQL);
629                 }
630 
631                 Query q = session.createQuery(sql);
632 
633                 if (orderByComparator == null) {
634                     list = (List<OrgLabor>)QueryUtil.list(q, getDialect(),
635                             start, end, false);
636 
637                     Collections.sort(list);
638                 }
639                 else {
640                     list = (List<OrgLabor>)QueryUtil.list(q, getDialect(),
641                             start, end);
642                 }
643             }
644             catch (Exception e) {
645                 throw processException(e);
646             }
647             finally {
648                 if (list == null) {
649                     list = new ArrayList<OrgLabor>();
650                 }
651 
652                 cacheResult(list);
653 
654                 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
655 
656                 closeSession(session);
657             }
658         }
659 
660         return list;
661     }
662 
663     public void removeByOrganizationId(long organizationId)
664         throws SystemException {
665         for (OrgLabor orgLabor : findByOrganizationId(organizationId)) {
666             remove(orgLabor);
667         }
668     }
669 
670     public void removeAll() throws SystemException {
671         for (OrgLabor orgLabor : findAll()) {
672             remove(orgLabor);
673         }
674     }
675 
676     public int countByOrganizationId(long organizationId)
677         throws SystemException {
678         Object[] finderArgs = new Object[] { new Long(organizationId) };
679 
680         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ORGANIZATIONID,
681                 finderArgs, this);
682 
683         if (count == null) {
684             Session session = null;
685 
686             try {
687                 session = openSession();
688 
689                 StringBundler query = new StringBundler(2);
690 
691                 query.append(_SQL_COUNT_ORGLABOR_WHERE);
692 
693                 query.append(_FINDER_COLUMN_ORGANIZATIONID_ORGANIZATIONID_2);
694 
695                 String sql = query.toString();
696 
697                 Query q = session.createQuery(sql);
698 
699                 QueryPos qPos = QueryPos.getInstance(q);
700 
701                 qPos.add(organizationId);
702 
703                 count = (Long)q.uniqueResult();
704             }
705             catch (Exception e) {
706                 throw processException(e);
707             }
708             finally {
709                 if (count == null) {
710                     count = Long.valueOf(0);
711                 }
712 
713                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ORGANIZATIONID,
714                     finderArgs, count);
715 
716                 closeSession(session);
717             }
718         }
719 
720         return count.intValue();
721     }
722 
723     public int countAll() throws SystemException {
724         Object[] finderArgs = new Object[0];
725 
726         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
727                 finderArgs, this);
728 
729         if (count == null) {
730             Session session = null;
731 
732             try {
733                 session = openSession();
734 
735                 Query q = session.createQuery(_SQL_COUNT_ORGLABOR);
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_ALL, finderArgs,
748                     count);
749 
750                 closeSession(session);
751             }
752         }
753 
754         return count.intValue();
755     }
756 
757     public void afterPropertiesSet() {
758         String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
759                     com.liferay.portal.util.PropsUtil.get(
760                         "value.object.listener.com.liferay.portal.model.OrgLabor")));
761 
762         if (listenerClassNames.length > 0) {
763             try {
764                 List<ModelListener<OrgLabor>> listenersList = new ArrayList<ModelListener<OrgLabor>>();
765 
766                 for (String listenerClassName : listenerClassNames) {
767                     listenersList.add((ModelListener<OrgLabor>)InstanceFactory.newInstance(
768                             listenerClassName));
769                 }
770 
771                 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
772             }
773             catch (Exception e) {
774                 _log.error(e);
775             }
776         }
777     }
778 
779     @BeanReference(type = AccountPersistence.class)
780     protected AccountPersistence accountPersistence;
781     @BeanReference(type = AddressPersistence.class)
782     protected AddressPersistence addressPersistence;
783     @BeanReference(type = BrowserTrackerPersistence.class)
784     protected BrowserTrackerPersistence browserTrackerPersistence;
785     @BeanReference(type = ClassNamePersistence.class)
786     protected ClassNamePersistence classNamePersistence;
787     @BeanReference(type = CompanyPersistence.class)
788     protected CompanyPersistence companyPersistence;
789     @BeanReference(type = ContactPersistence.class)
790     protected ContactPersistence contactPersistence;
791     @BeanReference(type = CountryPersistence.class)
792     protected CountryPersistence countryPersistence;
793     @BeanReference(type = EmailAddressPersistence.class)
794     protected EmailAddressPersistence emailAddressPersistence;
795     @BeanReference(type = GroupPersistence.class)
796     protected GroupPersistence groupPersistence;
797     @BeanReference(type = ImagePersistence.class)
798     protected ImagePersistence imagePersistence;
799     @BeanReference(type = LayoutPersistence.class)
800     protected LayoutPersistence layoutPersistence;
801     @BeanReference(type = LayoutPrototypePersistence.class)
802     protected LayoutPrototypePersistence layoutPrototypePersistence;
803     @BeanReference(type = LayoutSetPersistence.class)
804     protected LayoutSetPersistence layoutSetPersistence;
805     @BeanReference(type = LayoutSetPrototypePersistence.class)
806     protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
807     @BeanReference(type = ListTypePersistence.class)
808     protected ListTypePersistence listTypePersistence;
809     @BeanReference(type = LockPersistence.class)
810     protected LockPersistence lockPersistence;
811     @BeanReference(type = MembershipRequestPersistence.class)
812     protected MembershipRequestPersistence membershipRequestPersistence;
813     @BeanReference(type = OrganizationPersistence.class)
814     protected OrganizationPersistence organizationPersistence;
815     @BeanReference(type = OrgGroupPermissionPersistence.class)
816     protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
817     @BeanReference(type = OrgGroupRolePersistence.class)
818     protected OrgGroupRolePersistence orgGroupRolePersistence;
819     @BeanReference(type = OrgLaborPersistence.class)
820     protected OrgLaborPersistence orgLaborPersistence;
821     @BeanReference(type = PasswordPolicyPersistence.class)
822     protected PasswordPolicyPersistence passwordPolicyPersistence;
823     @BeanReference(type = PasswordPolicyRelPersistence.class)
824     protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
825     @BeanReference(type = PasswordTrackerPersistence.class)
826     protected PasswordTrackerPersistence passwordTrackerPersistence;
827     @BeanReference(type = PermissionPersistence.class)
828     protected PermissionPersistence permissionPersistence;
829     @BeanReference(type = PhonePersistence.class)
830     protected PhonePersistence phonePersistence;
831     @BeanReference(type = PluginSettingPersistence.class)
832     protected PluginSettingPersistence pluginSettingPersistence;
833     @BeanReference(type = PortletPersistence.class)
834     protected PortletPersistence portletPersistence;
835     @BeanReference(type = PortletItemPersistence.class)
836     protected PortletItemPersistence portletItemPersistence;
837     @BeanReference(type = PortletPreferencesPersistence.class)
838     protected PortletPreferencesPersistence portletPreferencesPersistence;
839     @BeanReference(type = RegionPersistence.class)
840     protected RegionPersistence regionPersistence;
841     @BeanReference(type = ReleasePersistence.class)
842     protected ReleasePersistence releasePersistence;
843     @BeanReference(type = ResourcePersistence.class)
844     protected ResourcePersistence resourcePersistence;
845     @BeanReference(type = ResourceActionPersistence.class)
846     protected ResourceActionPersistence resourceActionPersistence;
847     @BeanReference(type = ResourceCodePersistence.class)
848     protected ResourceCodePersistence resourceCodePersistence;
849     @BeanReference(type = ResourcePermissionPersistence.class)
850     protected ResourcePermissionPersistence resourcePermissionPersistence;
851     @BeanReference(type = RolePersistence.class)
852     protected RolePersistence rolePersistence;
853     @BeanReference(type = ServiceComponentPersistence.class)
854     protected ServiceComponentPersistence serviceComponentPersistence;
855     @BeanReference(type = ShardPersistence.class)
856     protected ShardPersistence shardPersistence;
857     @BeanReference(type = SubscriptionPersistence.class)
858     protected SubscriptionPersistence subscriptionPersistence;
859     @BeanReference(type = TicketPersistence.class)
860     protected TicketPersistence ticketPersistence;
861     @BeanReference(type = TeamPersistence.class)
862     protected TeamPersistence teamPersistence;
863     @BeanReference(type = UserPersistence.class)
864     protected UserPersistence userPersistence;
865     @BeanReference(type = UserGroupPersistence.class)
866     protected UserGroupPersistence userGroupPersistence;
867     @BeanReference(type = UserGroupGroupRolePersistence.class)
868     protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
869     @BeanReference(type = UserGroupRolePersistence.class)
870     protected UserGroupRolePersistence userGroupRolePersistence;
871     @BeanReference(type = UserIdMapperPersistence.class)
872     protected UserIdMapperPersistence userIdMapperPersistence;
873     @BeanReference(type = UserTrackerPersistence.class)
874     protected UserTrackerPersistence userTrackerPersistence;
875     @BeanReference(type = UserTrackerPathPersistence.class)
876     protected UserTrackerPathPersistence userTrackerPathPersistence;
877     @BeanReference(type = WebDAVPropsPersistence.class)
878     protected WebDAVPropsPersistence webDAVPropsPersistence;
879     @BeanReference(type = WebsitePersistence.class)
880     protected WebsitePersistence websitePersistence;
881     @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
882     protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
883     @BeanReference(type = WorkflowInstanceLinkPersistence.class)
884     protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
885     private static final String _SQL_SELECT_ORGLABOR = "SELECT orgLabor FROM OrgLabor orgLabor";
886     private static final String _SQL_SELECT_ORGLABOR_WHERE = "SELECT orgLabor FROM OrgLabor orgLabor WHERE ";
887     private static final String _SQL_COUNT_ORGLABOR = "SELECT COUNT(orgLabor) FROM OrgLabor orgLabor";
888     private static final String _SQL_COUNT_ORGLABOR_WHERE = "SELECT COUNT(orgLabor) FROM OrgLabor orgLabor WHERE ";
889     private static final String _FINDER_COLUMN_ORGANIZATIONID_ORGANIZATIONID_2 = "orgLabor.organizationId = ?";
890     private static final String _ORDER_BY_ENTITY_ALIAS = "orgLabor.";
891     private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No OrgLabor exists with the primary key ";
892     private static final String _NO_SUCH_ENTITY_WITH_KEY = "No OrgLabor exists with the key {";
893     private static Log _log = LogFactoryUtil.getLog(OrgLaborPersistenceImpl.class);
894 }