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