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