001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.NoSuchOrgLaborException;
018    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderPath;
022    import com.liferay.portal.kernel.dao.orm.Query;
023    import com.liferay.portal.kernel.dao.orm.QueryPos;
024    import com.liferay.portal.kernel.dao.orm.QueryUtil;
025    import com.liferay.portal.kernel.dao.orm.Session;
026    import com.liferay.portal.kernel.exception.SystemException;
027    import com.liferay.portal.kernel.log.Log;
028    import com.liferay.portal.kernel.log.LogFactoryUtil;
029    import com.liferay.portal.kernel.util.GetterUtil;
030    import com.liferay.portal.kernel.util.InstanceFactory;
031    import com.liferay.portal.kernel.util.OrderByComparator;
032    import com.liferay.portal.kernel.util.StringBundler;
033    import com.liferay.portal.kernel.util.StringPool;
034    import com.liferay.portal.kernel.util.StringUtil;
035    import com.liferay.portal.kernel.util.UnmodifiableList;
036    import com.liferay.portal.model.CacheModel;
037    import com.liferay.portal.model.ModelListener;
038    import com.liferay.portal.model.OrgLabor;
039    import com.liferay.portal.model.impl.OrgLaborImpl;
040    import com.liferay.portal.model.impl.OrgLaborModelImpl;
041    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042    
043    import java.io.Serializable;
044    
045    import java.util.ArrayList;
046    import java.util.Collections;
047    import java.util.List;
048    
049    /**
050     * The persistence implementation for the org labor service.
051     *
052     * <p>
053     * Caching information and settings can be found in <code>portal.properties</code>
054     * </p>
055     *
056     * @author Brian Wing Shun Chan
057     * @see OrgLaborPersistence
058     * @see OrgLaborUtil
059     * @generated
060     */
061    public class OrgLaborPersistenceImpl extends BasePersistenceImpl<OrgLabor>
062            implements OrgLaborPersistence {
063            /*
064             * NOTE FOR DEVELOPERS:
065             *
066             * Never modify or reference this class directly. Always use {@link OrgLaborUtil} to access the org labor persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
067             */
068            public static final String FINDER_CLASS_NAME_ENTITY = OrgLaborImpl.class.getName();
069            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
070                    ".List1";
071            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
072                    ".List2";
073            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
074                            OrgLaborModelImpl.FINDER_CACHE_ENABLED, OrgLaborImpl.class,
075                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
076            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
077                            OrgLaborModelImpl.FINDER_CACHE_ENABLED, OrgLaborImpl.class,
078                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
079            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
080                            OrgLaborModelImpl.FINDER_CACHE_ENABLED, Long.class,
081                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
082            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ORGANIZATIONID =
083                    new FinderPath(OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
084                            OrgLaborModelImpl.FINDER_CACHE_ENABLED, OrgLaborImpl.class,
085                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByOrganizationId",
086                            new String[] {
087                                    Long.class.getName(),
088                                    
089                            Integer.class.getName(), Integer.class.getName(),
090                                    OrderByComparator.class.getName()
091                            });
092            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ORGANIZATIONID =
093                    new FinderPath(OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
094                            OrgLaborModelImpl.FINDER_CACHE_ENABLED, OrgLaborImpl.class,
095                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByOrganizationId",
096                            new String[] { Long.class.getName() },
097                            OrgLaborModelImpl.ORGANIZATIONID_COLUMN_BITMASK |
098                            OrgLaborModelImpl.TYPEID_COLUMN_BITMASK);
099            public static final FinderPath FINDER_PATH_COUNT_BY_ORGANIZATIONID = new FinderPath(OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
100                            OrgLaborModelImpl.FINDER_CACHE_ENABLED, Long.class,
101                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByOrganizationId",
102                            new String[] { Long.class.getName() });
103    
104            /**
105             * Returns all the org labors where organizationId = &#63;.
106             *
107             * @param organizationId the organization ID
108             * @return the matching org labors
109             * @throws SystemException if a system exception occurred
110             */
111            @Override
112            public List<OrgLabor> findByOrganizationId(long organizationId)
113                    throws SystemException {
114                    return findByOrganizationId(organizationId, QueryUtil.ALL_POS,
115                            QueryUtil.ALL_POS, null);
116            }
117    
118            /**
119             * Returns a range of all the org labors where organizationId = &#63;.
120             *
121             * <p>
122             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.OrgLaborModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
123             * </p>
124             *
125             * @param organizationId the organization ID
126             * @param start the lower bound of the range of org labors
127             * @param end the upper bound of the range of org labors (not inclusive)
128             * @return the range of matching org labors
129             * @throws SystemException if a system exception occurred
130             */
131            @Override
132            public List<OrgLabor> findByOrganizationId(long organizationId, int start,
133                    int end) throws SystemException {
134                    return findByOrganizationId(organizationId, start, end, null);
135            }
136    
137            /**
138             * Returns an ordered range of all the org labors where organizationId = &#63;.
139             *
140             * <p>
141             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.OrgLaborModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
142             * </p>
143             *
144             * @param organizationId the organization ID
145             * @param start the lower bound of the range of org labors
146             * @param end the upper bound of the range of org labors (not inclusive)
147             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
148             * @return the ordered range of matching org labors
149             * @throws SystemException if a system exception occurred
150             */
151            @Override
152            public List<OrgLabor> findByOrganizationId(long organizationId, int start,
153                    int end, OrderByComparator orderByComparator) throws SystemException {
154                    boolean pagination = true;
155                    FinderPath finderPath = null;
156                    Object[] finderArgs = null;
157    
158                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
159                                    (orderByComparator == null)) {
160                            pagination = false;
161                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ORGANIZATIONID;
162                            finderArgs = new Object[] { organizationId };
163                    }
164                    else {
165                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ORGANIZATIONID;
166                            finderArgs = new Object[] {
167                                            organizationId,
168                                            
169                                            start, end, orderByComparator
170                                    };
171                    }
172    
173                    List<OrgLabor> list = (List<OrgLabor>)FinderCacheUtil.getResult(finderPath,
174                                    finderArgs, this);
175    
176                    if ((list != null) && !list.isEmpty()) {
177                            for (OrgLabor orgLabor : list) {
178                                    if ((organizationId != orgLabor.getOrganizationId())) {
179                                            list = null;
180    
181                                            break;
182                                    }
183                            }
184                    }
185    
186                    if (list == null) {
187                            StringBundler query = null;
188    
189                            if (orderByComparator != null) {
190                                    query = new StringBundler(3 +
191                                                    (orderByComparator.getOrderByFields().length * 3));
192                            }
193                            else {
194                                    query = new StringBundler(3);
195                            }
196    
197                            query.append(_SQL_SELECT_ORGLABOR_WHERE);
198    
199                            query.append(_FINDER_COLUMN_ORGANIZATIONID_ORGANIZATIONID_2);
200    
201                            if (orderByComparator != null) {
202                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
203                                            orderByComparator);
204                            }
205                            else
206                             if (pagination) {
207                                    query.append(OrgLaborModelImpl.ORDER_BY_JPQL);
208                            }
209    
210                            String sql = query.toString();
211    
212                            Session session = null;
213    
214                            try {
215                                    session = openSession();
216    
217                                    Query q = session.createQuery(sql);
218    
219                                    QueryPos qPos = QueryPos.getInstance(q);
220    
221                                    qPos.add(organizationId);
222    
223                                    if (!pagination) {
224                                            list = (List<OrgLabor>)QueryUtil.list(q, getDialect(),
225                                                            start, end, false);
226    
227                                            Collections.sort(list);
228    
229                                            list = new UnmodifiableList<OrgLabor>(list);
230                                    }
231                                    else {
232                                            list = (List<OrgLabor>)QueryUtil.list(q, getDialect(),
233                                                            start, end);
234                                    }
235    
236                                    cacheResult(list);
237    
238                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
239                            }
240                            catch (Exception e) {
241                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
242    
243                                    throw processException(e);
244                            }
245                            finally {
246                                    closeSession(session);
247                            }
248                    }
249    
250                    return list;
251            }
252    
253            /**
254             * Returns the first org labor in the ordered set where organizationId = &#63;.
255             *
256             * @param organizationId the organization ID
257             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
258             * @return the first matching org labor
259             * @throws com.liferay.portal.NoSuchOrgLaborException if a matching org labor could not be found
260             * @throws SystemException if a system exception occurred
261             */
262            @Override
263            public OrgLabor findByOrganizationId_First(long organizationId,
264                    OrderByComparator orderByComparator)
265                    throws NoSuchOrgLaborException, SystemException {
266                    OrgLabor orgLabor = fetchByOrganizationId_First(organizationId,
267                                    orderByComparator);
268    
269                    if (orgLabor != null) {
270                            return orgLabor;
271                    }
272    
273                    StringBundler msg = new StringBundler(4);
274    
275                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
276    
277                    msg.append("organizationId=");
278                    msg.append(organizationId);
279    
280                    msg.append(StringPool.CLOSE_CURLY_BRACE);
281    
282                    throw new NoSuchOrgLaborException(msg.toString());
283            }
284    
285            /**
286             * Returns the first org labor in the ordered set where organizationId = &#63;.
287             *
288             * @param organizationId the organization ID
289             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
290             * @return the first matching org labor, or <code>null</code> if a matching org labor could not be found
291             * @throws SystemException if a system exception occurred
292             */
293            @Override
294            public OrgLabor fetchByOrganizationId_First(long organizationId,
295                    OrderByComparator orderByComparator) throws SystemException {
296                    List<OrgLabor> list = findByOrganizationId(organizationId, 0, 1,
297                                    orderByComparator);
298    
299                    if (!list.isEmpty()) {
300                            return list.get(0);
301                    }
302    
303                    return null;
304            }
305    
306            /**
307             * Returns the last org labor in the ordered set where organizationId = &#63;.
308             *
309             * @param organizationId the organization ID
310             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
311             * @return the last matching org labor
312             * @throws com.liferay.portal.NoSuchOrgLaborException if a matching org labor could not be found
313             * @throws SystemException if a system exception occurred
314             */
315            @Override
316            public OrgLabor findByOrganizationId_Last(long organizationId,
317                    OrderByComparator orderByComparator)
318                    throws NoSuchOrgLaborException, SystemException {
319                    OrgLabor orgLabor = fetchByOrganizationId_Last(organizationId,
320                                    orderByComparator);
321    
322                    if (orgLabor != null) {
323                            return orgLabor;
324                    }
325    
326                    StringBundler msg = new StringBundler(4);
327    
328                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
329    
330                    msg.append("organizationId=");
331                    msg.append(organizationId);
332    
333                    msg.append(StringPool.CLOSE_CURLY_BRACE);
334    
335                    throw new NoSuchOrgLaborException(msg.toString());
336            }
337    
338            /**
339             * Returns the last org labor in the ordered set where organizationId = &#63;.
340             *
341             * @param organizationId the organization ID
342             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
343             * @return the last matching org labor, or <code>null</code> if a matching org labor could not be found
344             * @throws SystemException if a system exception occurred
345             */
346            @Override
347            public OrgLabor fetchByOrganizationId_Last(long organizationId,
348                    OrderByComparator orderByComparator) throws SystemException {
349                    int count = countByOrganizationId(organizationId);
350    
351                    if (count == 0) {
352                            return null;
353                    }
354    
355                    List<OrgLabor> list = findByOrganizationId(organizationId, count - 1,
356                                    count, orderByComparator);
357    
358                    if (!list.isEmpty()) {
359                            return list.get(0);
360                    }
361    
362                    return null;
363            }
364    
365            /**
366             * Returns the org labors before and after the current org labor in the ordered set where organizationId = &#63;.
367             *
368             * @param orgLaborId the primary key of the current org labor
369             * @param organizationId the organization ID
370             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
371             * @return the previous, current, and next org labor
372             * @throws com.liferay.portal.NoSuchOrgLaborException if a org labor with the primary key could not be found
373             * @throws SystemException if a system exception occurred
374             */
375            @Override
376            public OrgLabor[] findByOrganizationId_PrevAndNext(long orgLaborId,
377                    long organizationId, OrderByComparator orderByComparator)
378                    throws NoSuchOrgLaborException, SystemException {
379                    OrgLabor orgLabor = findByPrimaryKey(orgLaborId);
380    
381                    Session session = null;
382    
383                    try {
384                            session = openSession();
385    
386                            OrgLabor[] array = new OrgLaborImpl[3];
387    
388                            array[0] = getByOrganizationId_PrevAndNext(session, orgLabor,
389                                            organizationId, orderByComparator, true);
390    
391                            array[1] = orgLabor;
392    
393                            array[2] = getByOrganizationId_PrevAndNext(session, orgLabor,
394                                            organizationId, orderByComparator, false);
395    
396                            return array;
397                    }
398                    catch (Exception e) {
399                            throw processException(e);
400                    }
401                    finally {
402                            closeSession(session);
403                    }
404            }
405    
406            protected OrgLabor getByOrganizationId_PrevAndNext(Session session,
407                    OrgLabor orgLabor, long organizationId,
408                    OrderByComparator orderByComparator, boolean previous) {
409                    StringBundler query = null;
410    
411                    if (orderByComparator != null) {
412                            query = new StringBundler(6 +
413                                            (orderByComparator.getOrderByFields().length * 6));
414                    }
415                    else {
416                            query = new StringBundler(3);
417                    }
418    
419                    query.append(_SQL_SELECT_ORGLABOR_WHERE);
420    
421                    query.append(_FINDER_COLUMN_ORGANIZATIONID_ORGANIZATIONID_2);
422    
423                    if (orderByComparator != null) {
424                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
425    
426                            if (orderByConditionFields.length > 0) {
427                                    query.append(WHERE_AND);
428                            }
429    
430                            for (int i = 0; i < orderByConditionFields.length; i++) {
431                                    query.append(_ORDER_BY_ENTITY_ALIAS);
432                                    query.append(orderByConditionFields[i]);
433    
434                                    if ((i + 1) < orderByConditionFields.length) {
435                                            if (orderByComparator.isAscending() ^ previous) {
436                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
437                                            }
438                                            else {
439                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
440                                            }
441                                    }
442                                    else {
443                                            if (orderByComparator.isAscending() ^ previous) {
444                                                    query.append(WHERE_GREATER_THAN);
445                                            }
446                                            else {
447                                                    query.append(WHERE_LESSER_THAN);
448                                            }
449                                    }
450                            }
451    
452                            query.append(ORDER_BY_CLAUSE);
453    
454                            String[] orderByFields = orderByComparator.getOrderByFields();
455    
456                            for (int i = 0; i < orderByFields.length; i++) {
457                                    query.append(_ORDER_BY_ENTITY_ALIAS);
458                                    query.append(orderByFields[i]);
459    
460                                    if ((i + 1) < orderByFields.length) {
461                                            if (orderByComparator.isAscending() ^ previous) {
462                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
463                                            }
464                                            else {
465                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
466                                            }
467                                    }
468                                    else {
469                                            if (orderByComparator.isAscending() ^ previous) {
470                                                    query.append(ORDER_BY_ASC);
471                                            }
472                                            else {
473                                                    query.append(ORDER_BY_DESC);
474                                            }
475                                    }
476                            }
477                    }
478                    else {
479                            query.append(OrgLaborModelImpl.ORDER_BY_JPQL);
480                    }
481    
482                    String sql = query.toString();
483    
484                    Query q = session.createQuery(sql);
485    
486                    q.setFirstResult(0);
487                    q.setMaxResults(2);
488    
489                    QueryPos qPos = QueryPos.getInstance(q);
490    
491                    qPos.add(organizationId);
492    
493                    if (orderByComparator != null) {
494                            Object[] values = orderByComparator.getOrderByConditionValues(orgLabor);
495    
496                            for (Object value : values) {
497                                    qPos.add(value);
498                            }
499                    }
500    
501                    List<OrgLabor> list = q.list();
502    
503                    if (list.size() == 2) {
504                            return list.get(1);
505                    }
506                    else {
507                            return null;
508                    }
509            }
510    
511            /**
512             * Removes all the org labors where organizationId = &#63; from the database.
513             *
514             * @param organizationId the organization ID
515             * @throws SystemException if a system exception occurred
516             */
517            @Override
518            public void removeByOrganizationId(long organizationId)
519                    throws SystemException {
520                    for (OrgLabor orgLabor : findByOrganizationId(organizationId,
521                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
522                            remove(orgLabor);
523                    }
524            }
525    
526            /**
527             * Returns the number of org labors where organizationId = &#63;.
528             *
529             * @param organizationId the organization ID
530             * @return the number of matching org labors
531             * @throws SystemException if a system exception occurred
532             */
533            @Override
534            public int countByOrganizationId(long organizationId)
535                    throws SystemException {
536                    FinderPath finderPath = FINDER_PATH_COUNT_BY_ORGANIZATIONID;
537    
538                    Object[] finderArgs = new Object[] { organizationId };
539    
540                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
541                                    this);
542    
543                    if (count == null) {
544                            StringBundler query = new StringBundler(2);
545    
546                            query.append(_SQL_COUNT_ORGLABOR_WHERE);
547    
548                            query.append(_FINDER_COLUMN_ORGANIZATIONID_ORGANIZATIONID_2);
549    
550                            String sql = query.toString();
551    
552                            Session session = null;
553    
554                            try {
555                                    session = openSession();
556    
557                                    Query q = session.createQuery(sql);
558    
559                                    QueryPos qPos = QueryPos.getInstance(q);
560    
561                                    qPos.add(organizationId);
562    
563                                    count = (Long)q.uniqueResult();
564    
565                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
566                            }
567                            catch (Exception e) {
568                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
569    
570                                    throw processException(e);
571                            }
572                            finally {
573                                    closeSession(session);
574                            }
575                    }
576    
577                    return count.intValue();
578            }
579    
580            private static final String _FINDER_COLUMN_ORGANIZATIONID_ORGANIZATIONID_2 = "orgLabor.organizationId = ?";
581    
582            /**
583             * Caches the org labor in the entity cache if it is enabled.
584             *
585             * @param orgLabor the org labor
586             */
587            @Override
588            public void cacheResult(OrgLabor orgLabor) {
589                    EntityCacheUtil.putResult(OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
590                            OrgLaborImpl.class, orgLabor.getPrimaryKey(), orgLabor);
591    
592                    orgLabor.resetOriginalValues();
593            }
594    
595            /**
596             * Caches the org labors in the entity cache if it is enabled.
597             *
598             * @param orgLabors the org labors
599             */
600            @Override
601            public void cacheResult(List<OrgLabor> orgLabors) {
602                    for (OrgLabor orgLabor : orgLabors) {
603                            if (EntityCacheUtil.getResult(
604                                                    OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
605                                                    OrgLaborImpl.class, orgLabor.getPrimaryKey()) == null) {
606                                    cacheResult(orgLabor);
607                            }
608                            else {
609                                    orgLabor.resetOriginalValues();
610                            }
611                    }
612            }
613    
614            /**
615             * Clears the cache for all org labors.
616             *
617             * <p>
618             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
619             * </p>
620             */
621            @Override
622            public void clearCache() {
623                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
624                            CacheRegistryUtil.clear(OrgLaborImpl.class.getName());
625                    }
626    
627                    EntityCacheUtil.clearCache(OrgLaborImpl.class.getName());
628    
629                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
630                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
631                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
632            }
633    
634            /**
635             * Clears the cache for the org labor.
636             *
637             * <p>
638             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
639             * </p>
640             */
641            @Override
642            public void clearCache(OrgLabor orgLabor) {
643                    EntityCacheUtil.removeResult(OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
644                            OrgLaborImpl.class, orgLabor.getPrimaryKey());
645    
646                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
647                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
648            }
649    
650            @Override
651            public void clearCache(List<OrgLabor> orgLabors) {
652                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
653                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
654    
655                    for (OrgLabor orgLabor : orgLabors) {
656                            EntityCacheUtil.removeResult(OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
657                                    OrgLaborImpl.class, orgLabor.getPrimaryKey());
658                    }
659            }
660    
661            /**
662             * Creates a new org labor with the primary key. Does not add the org labor to the database.
663             *
664             * @param orgLaborId the primary key for the new org labor
665             * @return the new org labor
666             */
667            @Override
668            public OrgLabor create(long orgLaborId) {
669                    OrgLabor orgLabor = new OrgLaborImpl();
670    
671                    orgLabor.setNew(true);
672                    orgLabor.setPrimaryKey(orgLaborId);
673    
674                    return orgLabor;
675            }
676    
677            /**
678             * Removes the org labor with the primary key from the database. Also notifies the appropriate model listeners.
679             *
680             * @param orgLaborId the primary key of the org labor
681             * @return the org labor that was removed
682             * @throws com.liferay.portal.NoSuchOrgLaborException if a org labor with the primary key could not be found
683             * @throws SystemException if a system exception occurred
684             */
685            @Override
686            public OrgLabor remove(long orgLaborId)
687                    throws NoSuchOrgLaborException, SystemException {
688                    return remove((Serializable)orgLaborId);
689            }
690    
691            /**
692             * Removes the org labor with the primary key from the database. Also notifies the appropriate model listeners.
693             *
694             * @param primaryKey the primary key of the org labor
695             * @return the org labor that was removed
696             * @throws com.liferay.portal.NoSuchOrgLaborException if a org labor with the primary key could not be found
697             * @throws SystemException if a system exception occurred
698             */
699            @Override
700            public OrgLabor remove(Serializable primaryKey)
701                    throws NoSuchOrgLaborException, SystemException {
702                    Session session = null;
703    
704                    try {
705                            session = openSession();
706    
707                            OrgLabor orgLabor = (OrgLabor)session.get(OrgLaborImpl.class,
708                                            primaryKey);
709    
710                            if (orgLabor == null) {
711                                    if (_log.isWarnEnabled()) {
712                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
713                                    }
714    
715                                    throw new NoSuchOrgLaborException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
716                                            primaryKey);
717                            }
718    
719                            return remove(orgLabor);
720                    }
721                    catch (NoSuchOrgLaborException nsee) {
722                            throw nsee;
723                    }
724                    catch (Exception e) {
725                            throw processException(e);
726                    }
727                    finally {
728                            closeSession(session);
729                    }
730            }
731    
732            @Override
733            protected OrgLabor removeImpl(OrgLabor orgLabor) throws SystemException {
734                    orgLabor = toUnwrappedModel(orgLabor);
735    
736                    Session session = null;
737    
738                    try {
739                            session = openSession();
740    
741                            if (!session.contains(orgLabor)) {
742                                    orgLabor = (OrgLabor)session.get(OrgLaborImpl.class,
743                                                    orgLabor.getPrimaryKeyObj());
744                            }
745    
746                            if (orgLabor != null) {
747                                    session.delete(orgLabor);
748                            }
749                    }
750                    catch (Exception e) {
751                            throw processException(e);
752                    }
753                    finally {
754                            closeSession(session);
755                    }
756    
757                    if (orgLabor != null) {
758                            clearCache(orgLabor);
759                    }
760    
761                    return orgLabor;
762            }
763    
764            @Override
765            public OrgLabor updateImpl(com.liferay.portal.model.OrgLabor orgLabor)
766                    throws SystemException {
767                    orgLabor = toUnwrappedModel(orgLabor);
768    
769                    boolean isNew = orgLabor.isNew();
770    
771                    OrgLaborModelImpl orgLaborModelImpl = (OrgLaborModelImpl)orgLabor;
772    
773                    Session session = null;
774    
775                    try {
776                            session = openSession();
777    
778                            if (orgLabor.isNew()) {
779                                    session.save(orgLabor);
780    
781                                    orgLabor.setNew(false);
782                            }
783                            else {
784                                    session.merge(orgLabor);
785                            }
786                    }
787                    catch (Exception e) {
788                            throw processException(e);
789                    }
790                    finally {
791                            closeSession(session);
792                    }
793    
794                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
795    
796                    if (isNew || !OrgLaborModelImpl.COLUMN_BITMASK_ENABLED) {
797                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
798                    }
799    
800                    else {
801                            if ((orgLaborModelImpl.getColumnBitmask() &
802                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ORGANIZATIONID.getColumnBitmask()) != 0) {
803                                    Object[] args = new Object[] {
804                                                    orgLaborModelImpl.getOriginalOrganizationId()
805                                            };
806    
807                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ORGANIZATIONID,
808                                            args);
809                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ORGANIZATIONID,
810                                            args);
811    
812                                    args = new Object[] { orgLaborModelImpl.getOrganizationId() };
813    
814                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ORGANIZATIONID,
815                                            args);
816                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ORGANIZATIONID,
817                                            args);
818                            }
819                    }
820    
821                    EntityCacheUtil.putResult(OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
822                            OrgLaborImpl.class, orgLabor.getPrimaryKey(), orgLabor);
823    
824                    return orgLabor;
825            }
826    
827            protected OrgLabor toUnwrappedModel(OrgLabor orgLabor) {
828                    if (orgLabor instanceof OrgLaborImpl) {
829                            return orgLabor;
830                    }
831    
832                    OrgLaborImpl orgLaborImpl = new OrgLaborImpl();
833    
834                    orgLaborImpl.setNew(orgLabor.isNew());
835                    orgLaborImpl.setPrimaryKey(orgLabor.getPrimaryKey());
836    
837                    orgLaborImpl.setOrgLaborId(orgLabor.getOrgLaborId());
838                    orgLaborImpl.setOrganizationId(orgLabor.getOrganizationId());
839                    orgLaborImpl.setTypeId(orgLabor.getTypeId());
840                    orgLaborImpl.setSunOpen(orgLabor.getSunOpen());
841                    orgLaborImpl.setSunClose(orgLabor.getSunClose());
842                    orgLaborImpl.setMonOpen(orgLabor.getMonOpen());
843                    orgLaborImpl.setMonClose(orgLabor.getMonClose());
844                    orgLaborImpl.setTueOpen(orgLabor.getTueOpen());
845                    orgLaborImpl.setTueClose(orgLabor.getTueClose());
846                    orgLaborImpl.setWedOpen(orgLabor.getWedOpen());
847                    orgLaborImpl.setWedClose(orgLabor.getWedClose());
848                    orgLaborImpl.setThuOpen(orgLabor.getThuOpen());
849                    orgLaborImpl.setThuClose(orgLabor.getThuClose());
850                    orgLaborImpl.setFriOpen(orgLabor.getFriOpen());
851                    orgLaborImpl.setFriClose(orgLabor.getFriClose());
852                    orgLaborImpl.setSatOpen(orgLabor.getSatOpen());
853                    orgLaborImpl.setSatClose(orgLabor.getSatClose());
854    
855                    return orgLaborImpl;
856            }
857    
858            /**
859             * Returns the org labor with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
860             *
861             * @param primaryKey the primary key of the org labor
862             * @return the org labor
863             * @throws com.liferay.portal.NoSuchOrgLaborException if a org labor with the primary key could not be found
864             * @throws SystemException if a system exception occurred
865             */
866            @Override
867            public OrgLabor findByPrimaryKey(Serializable primaryKey)
868                    throws NoSuchOrgLaborException, SystemException {
869                    OrgLabor orgLabor = fetchByPrimaryKey(primaryKey);
870    
871                    if (orgLabor == null) {
872                            if (_log.isWarnEnabled()) {
873                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
874                            }
875    
876                            throw new NoSuchOrgLaborException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
877                                    primaryKey);
878                    }
879    
880                    return orgLabor;
881            }
882    
883            /**
884             * Returns the org labor with the primary key or throws a {@link com.liferay.portal.NoSuchOrgLaborException} if it could not be found.
885             *
886             * @param orgLaborId the primary key of the org labor
887             * @return the org labor
888             * @throws com.liferay.portal.NoSuchOrgLaborException if a org labor with the primary key could not be found
889             * @throws SystemException if a system exception occurred
890             */
891            @Override
892            public OrgLabor findByPrimaryKey(long orgLaborId)
893                    throws NoSuchOrgLaborException, SystemException {
894                    return findByPrimaryKey((Serializable)orgLaborId);
895            }
896    
897            /**
898             * Returns the org labor with the primary key or returns <code>null</code> if it could not be found.
899             *
900             * @param primaryKey the primary key of the org labor
901             * @return the org labor, or <code>null</code> if a org labor with the primary key could not be found
902             * @throws SystemException if a system exception occurred
903             */
904            @Override
905            public OrgLabor fetchByPrimaryKey(Serializable primaryKey)
906                    throws SystemException {
907                    OrgLabor orgLabor = (OrgLabor)EntityCacheUtil.getResult(OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
908                                    OrgLaborImpl.class, primaryKey);
909    
910                    if (orgLabor == _nullOrgLabor) {
911                            return null;
912                    }
913    
914                    if (orgLabor == null) {
915                            Session session = null;
916    
917                            try {
918                                    session = openSession();
919    
920                                    orgLabor = (OrgLabor)session.get(OrgLaborImpl.class, primaryKey);
921    
922                                    if (orgLabor != null) {
923                                            cacheResult(orgLabor);
924                                    }
925                                    else {
926                                            EntityCacheUtil.putResult(OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
927                                                    OrgLaborImpl.class, primaryKey, _nullOrgLabor);
928                                    }
929                            }
930                            catch (Exception e) {
931                                    EntityCacheUtil.removeResult(OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
932                                            OrgLaborImpl.class, primaryKey);
933    
934                                    throw processException(e);
935                            }
936                            finally {
937                                    closeSession(session);
938                            }
939                    }
940    
941                    return orgLabor;
942            }
943    
944            /**
945             * Returns the org labor with the primary key or returns <code>null</code> if it could not be found.
946             *
947             * @param orgLaborId the primary key of the org labor
948             * @return the org labor, or <code>null</code> if a org labor with the primary key could not be found
949             * @throws SystemException if a system exception occurred
950             */
951            @Override
952            public OrgLabor fetchByPrimaryKey(long orgLaborId)
953                    throws SystemException {
954                    return fetchByPrimaryKey((Serializable)orgLaborId);
955            }
956    
957            /**
958             * Returns all the org labors.
959             *
960             * @return the org labors
961             * @throws SystemException if a system exception occurred
962             */
963            @Override
964            public List<OrgLabor> findAll() throws SystemException {
965                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
966            }
967    
968            /**
969             * Returns a range of all the org labors.
970             *
971             * <p>
972             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.OrgLaborModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
973             * </p>
974             *
975             * @param start the lower bound of the range of org labors
976             * @param end the upper bound of the range of org labors (not inclusive)
977             * @return the range of org labors
978             * @throws SystemException if a system exception occurred
979             */
980            @Override
981            public List<OrgLabor> findAll(int start, int end) throws SystemException {
982                    return findAll(start, end, null);
983            }
984    
985            /**
986             * Returns an ordered range of all the org labors.
987             *
988             * <p>
989             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.OrgLaborModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
990             * </p>
991             *
992             * @param start the lower bound of the range of org labors
993             * @param end the upper bound of the range of org labors (not inclusive)
994             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
995             * @return the ordered range of org labors
996             * @throws SystemException if a system exception occurred
997             */
998            @Override
999            public List<OrgLabor> findAll(int start, int end,
1000                    OrderByComparator orderByComparator) throws SystemException {
1001                    boolean pagination = true;
1002                    FinderPath finderPath = null;
1003                    Object[] finderArgs = null;
1004    
1005                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1006                                    (orderByComparator == null)) {
1007                            pagination = false;
1008                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1009                            finderArgs = FINDER_ARGS_EMPTY;
1010                    }
1011                    else {
1012                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1013                            finderArgs = new Object[] { start, end, orderByComparator };
1014                    }
1015    
1016                    List<OrgLabor> list = (List<OrgLabor>)FinderCacheUtil.getResult(finderPath,
1017                                    finderArgs, this);
1018    
1019                    if (list == null) {
1020                            StringBundler query = null;
1021                            String sql = null;
1022    
1023                            if (orderByComparator != null) {
1024                                    query = new StringBundler(2 +
1025                                                    (orderByComparator.getOrderByFields().length * 3));
1026    
1027                                    query.append(_SQL_SELECT_ORGLABOR);
1028    
1029                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1030                                            orderByComparator);
1031    
1032                                    sql = query.toString();
1033                            }
1034                            else {
1035                                    sql = _SQL_SELECT_ORGLABOR;
1036    
1037                                    if (pagination) {
1038                                            sql = sql.concat(OrgLaborModelImpl.ORDER_BY_JPQL);
1039                                    }
1040                            }
1041    
1042                            Session session = null;
1043    
1044                            try {
1045                                    session = openSession();
1046    
1047                                    Query q = session.createQuery(sql);
1048    
1049                                    if (!pagination) {
1050                                            list = (List<OrgLabor>)QueryUtil.list(q, getDialect(),
1051                                                            start, end, false);
1052    
1053                                            Collections.sort(list);
1054    
1055                                            list = new UnmodifiableList<OrgLabor>(list);
1056                                    }
1057                                    else {
1058                                            list = (List<OrgLabor>)QueryUtil.list(q, getDialect(),
1059                                                            start, end);
1060                                    }
1061    
1062                                    cacheResult(list);
1063    
1064                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1065                            }
1066                            catch (Exception e) {
1067                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1068    
1069                                    throw processException(e);
1070                            }
1071                            finally {
1072                                    closeSession(session);
1073                            }
1074                    }
1075    
1076                    return list;
1077            }
1078    
1079            /**
1080             * Removes all the org labors from the database.
1081             *
1082             * @throws SystemException if a system exception occurred
1083             */
1084            @Override
1085            public void removeAll() throws SystemException {
1086                    for (OrgLabor orgLabor : findAll()) {
1087                            remove(orgLabor);
1088                    }
1089            }
1090    
1091            /**
1092             * Returns the number of org labors.
1093             *
1094             * @return the number of org labors
1095             * @throws SystemException if a system exception occurred
1096             */
1097            @Override
1098            public int countAll() throws SystemException {
1099                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1100                                    FINDER_ARGS_EMPTY, this);
1101    
1102                    if (count == null) {
1103                            Session session = null;
1104    
1105                            try {
1106                                    session = openSession();
1107    
1108                                    Query q = session.createQuery(_SQL_COUNT_ORGLABOR);
1109    
1110                                    count = (Long)q.uniqueResult();
1111    
1112                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1113                                            FINDER_ARGS_EMPTY, count);
1114                            }
1115                            catch (Exception e) {
1116                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1117                                            FINDER_ARGS_EMPTY);
1118    
1119                                    throw processException(e);
1120                            }
1121                            finally {
1122                                    closeSession(session);
1123                            }
1124                    }
1125    
1126                    return count.intValue();
1127            }
1128    
1129            /**
1130             * Initializes the org labor persistence.
1131             */
1132            public void afterPropertiesSet() {
1133                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1134                                            com.liferay.portal.util.PropsUtil.get(
1135                                                    "value.object.listener.com.liferay.portal.model.OrgLabor")));
1136    
1137                    if (listenerClassNames.length > 0) {
1138                            try {
1139                                    List<ModelListener<OrgLabor>> listenersList = new ArrayList<ModelListener<OrgLabor>>();
1140    
1141                                    for (String listenerClassName : listenerClassNames) {
1142                                            listenersList.add((ModelListener<OrgLabor>)InstanceFactory.newInstance(
1143                                                            getClassLoader(), listenerClassName));
1144                                    }
1145    
1146                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1147                            }
1148                            catch (Exception e) {
1149                                    _log.error(e);
1150                            }
1151                    }
1152            }
1153    
1154            public void destroy() {
1155                    EntityCacheUtil.removeCache(OrgLaborImpl.class.getName());
1156                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1157                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1158                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1159            }
1160    
1161            private static final String _SQL_SELECT_ORGLABOR = "SELECT orgLabor FROM OrgLabor orgLabor";
1162            private static final String _SQL_SELECT_ORGLABOR_WHERE = "SELECT orgLabor FROM OrgLabor orgLabor WHERE ";
1163            private static final String _SQL_COUNT_ORGLABOR = "SELECT COUNT(orgLabor) FROM OrgLabor orgLabor";
1164            private static final String _SQL_COUNT_ORGLABOR_WHERE = "SELECT COUNT(orgLabor) FROM OrgLabor orgLabor WHERE ";
1165            private static final String _ORDER_BY_ENTITY_ALIAS = "orgLabor.";
1166            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No OrgLabor exists with the primary key ";
1167            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No OrgLabor exists with the key {";
1168            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1169            private static Log _log = LogFactoryUtil.getLog(OrgLaborPersistenceImpl.class);
1170            private static OrgLabor _nullOrgLabor = new OrgLaborImpl() {
1171                            @Override
1172                            public Object clone() {
1173                                    return this;
1174                            }
1175    
1176                            @Override
1177                            public CacheModel<OrgLabor> toCacheModel() {
1178                                    return _nullOrgLaborCacheModel;
1179                            }
1180                    };
1181    
1182            private static CacheModel<OrgLabor> _nullOrgLaborCacheModel = new CacheModel<OrgLabor>() {
1183                            @Override
1184                            public OrgLabor toEntityModel() {
1185                                    return _nullOrgLabor;
1186                            }
1187                    };
1188    }