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            public OrgLaborPersistenceImpl() {
583                    setModelClass(OrgLabor.class);
584            }
585    
586            /**
587             * Caches the org labor in the entity cache if it is enabled.
588             *
589             * @param orgLabor the org labor
590             */
591            @Override
592            public void cacheResult(OrgLabor orgLabor) {
593                    EntityCacheUtil.putResult(OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
594                            OrgLaborImpl.class, orgLabor.getPrimaryKey(), orgLabor);
595    
596                    orgLabor.resetOriginalValues();
597            }
598    
599            /**
600             * Caches the org labors in the entity cache if it is enabled.
601             *
602             * @param orgLabors the org labors
603             */
604            @Override
605            public void cacheResult(List<OrgLabor> orgLabors) {
606                    for (OrgLabor orgLabor : orgLabors) {
607                            if (EntityCacheUtil.getResult(
608                                                    OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
609                                                    OrgLaborImpl.class, orgLabor.getPrimaryKey()) == null) {
610                                    cacheResult(orgLabor);
611                            }
612                            else {
613                                    orgLabor.resetOriginalValues();
614                            }
615                    }
616            }
617    
618            /**
619             * Clears the cache for all org labors.
620             *
621             * <p>
622             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
623             * </p>
624             */
625            @Override
626            public void clearCache() {
627                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
628                            CacheRegistryUtil.clear(OrgLaborImpl.class.getName());
629                    }
630    
631                    EntityCacheUtil.clearCache(OrgLaborImpl.class.getName());
632    
633                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
634                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
635                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
636            }
637    
638            /**
639             * Clears the cache for the org labor.
640             *
641             * <p>
642             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
643             * </p>
644             */
645            @Override
646            public void clearCache(OrgLabor orgLabor) {
647                    EntityCacheUtil.removeResult(OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
648                            OrgLaborImpl.class, orgLabor.getPrimaryKey());
649    
650                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
651                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
652            }
653    
654            @Override
655            public void clearCache(List<OrgLabor> orgLabors) {
656                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
657                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
658    
659                    for (OrgLabor orgLabor : orgLabors) {
660                            EntityCacheUtil.removeResult(OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
661                                    OrgLaborImpl.class, orgLabor.getPrimaryKey());
662                    }
663            }
664    
665            /**
666             * Creates a new org labor with the primary key. Does not add the org labor to the database.
667             *
668             * @param orgLaborId the primary key for the new org labor
669             * @return the new org labor
670             */
671            @Override
672            public OrgLabor create(long orgLaborId) {
673                    OrgLabor orgLabor = new OrgLaborImpl();
674    
675                    orgLabor.setNew(true);
676                    orgLabor.setPrimaryKey(orgLaborId);
677    
678                    return orgLabor;
679            }
680    
681            /**
682             * Removes the org labor with the primary key from the database. Also notifies the appropriate model listeners.
683             *
684             * @param orgLaborId the primary key of the org labor
685             * @return the org labor that was removed
686             * @throws com.liferay.portal.NoSuchOrgLaborException if a org labor with the primary key could not be found
687             * @throws SystemException if a system exception occurred
688             */
689            @Override
690            public OrgLabor remove(long orgLaborId)
691                    throws NoSuchOrgLaborException, SystemException {
692                    return remove((Serializable)orgLaborId);
693            }
694    
695            /**
696             * Removes the org labor with the primary key from the database. Also notifies the appropriate model listeners.
697             *
698             * @param primaryKey the primary key of the org labor
699             * @return the org labor that was removed
700             * @throws com.liferay.portal.NoSuchOrgLaborException if a org labor with the primary key could not be found
701             * @throws SystemException if a system exception occurred
702             */
703            @Override
704            public OrgLabor remove(Serializable primaryKey)
705                    throws NoSuchOrgLaborException, SystemException {
706                    Session session = null;
707    
708                    try {
709                            session = openSession();
710    
711                            OrgLabor orgLabor = (OrgLabor)session.get(OrgLaborImpl.class,
712                                            primaryKey);
713    
714                            if (orgLabor == null) {
715                                    if (_log.isWarnEnabled()) {
716                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
717                                    }
718    
719                                    throw new NoSuchOrgLaborException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
720                                            primaryKey);
721                            }
722    
723                            return remove(orgLabor);
724                    }
725                    catch (NoSuchOrgLaborException nsee) {
726                            throw nsee;
727                    }
728                    catch (Exception e) {
729                            throw processException(e);
730                    }
731                    finally {
732                            closeSession(session);
733                    }
734            }
735    
736            @Override
737            protected OrgLabor removeImpl(OrgLabor orgLabor) throws SystemException {
738                    orgLabor = toUnwrappedModel(orgLabor);
739    
740                    Session session = null;
741    
742                    try {
743                            session = openSession();
744    
745                            if (!session.contains(orgLabor)) {
746                                    orgLabor = (OrgLabor)session.get(OrgLaborImpl.class,
747                                                    orgLabor.getPrimaryKeyObj());
748                            }
749    
750                            if (orgLabor != null) {
751                                    session.delete(orgLabor);
752                            }
753                    }
754                    catch (Exception e) {
755                            throw processException(e);
756                    }
757                    finally {
758                            closeSession(session);
759                    }
760    
761                    if (orgLabor != null) {
762                            clearCache(orgLabor);
763                    }
764    
765                    return orgLabor;
766            }
767    
768            @Override
769            public OrgLabor updateImpl(com.liferay.portal.model.OrgLabor orgLabor)
770                    throws SystemException {
771                    orgLabor = toUnwrappedModel(orgLabor);
772    
773                    boolean isNew = orgLabor.isNew();
774    
775                    OrgLaborModelImpl orgLaborModelImpl = (OrgLaborModelImpl)orgLabor;
776    
777                    Session session = null;
778    
779                    try {
780                            session = openSession();
781    
782                            if (orgLabor.isNew()) {
783                                    session.save(orgLabor);
784    
785                                    orgLabor.setNew(false);
786                            }
787                            else {
788                                    session.merge(orgLabor);
789                            }
790                    }
791                    catch (Exception e) {
792                            throw processException(e);
793                    }
794                    finally {
795                            closeSession(session);
796                    }
797    
798                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
799    
800                    if (isNew || !OrgLaborModelImpl.COLUMN_BITMASK_ENABLED) {
801                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
802                    }
803    
804                    else {
805                            if ((orgLaborModelImpl.getColumnBitmask() &
806                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ORGANIZATIONID.getColumnBitmask()) != 0) {
807                                    Object[] args = new Object[] {
808                                                    orgLaborModelImpl.getOriginalOrganizationId()
809                                            };
810    
811                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ORGANIZATIONID,
812                                            args);
813                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ORGANIZATIONID,
814                                            args);
815    
816                                    args = new Object[] { orgLaborModelImpl.getOrganizationId() };
817    
818                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ORGANIZATIONID,
819                                            args);
820                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ORGANIZATIONID,
821                                            args);
822                            }
823                    }
824    
825                    EntityCacheUtil.putResult(OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
826                            OrgLaborImpl.class, orgLabor.getPrimaryKey(), orgLabor);
827    
828                    return orgLabor;
829            }
830    
831            protected OrgLabor toUnwrappedModel(OrgLabor orgLabor) {
832                    if (orgLabor instanceof OrgLaborImpl) {
833                            return orgLabor;
834                    }
835    
836                    OrgLaborImpl orgLaborImpl = new OrgLaborImpl();
837    
838                    orgLaborImpl.setNew(orgLabor.isNew());
839                    orgLaborImpl.setPrimaryKey(orgLabor.getPrimaryKey());
840    
841                    orgLaborImpl.setOrgLaborId(orgLabor.getOrgLaborId());
842                    orgLaborImpl.setOrganizationId(orgLabor.getOrganizationId());
843                    orgLaborImpl.setTypeId(orgLabor.getTypeId());
844                    orgLaborImpl.setSunOpen(orgLabor.getSunOpen());
845                    orgLaborImpl.setSunClose(orgLabor.getSunClose());
846                    orgLaborImpl.setMonOpen(orgLabor.getMonOpen());
847                    orgLaborImpl.setMonClose(orgLabor.getMonClose());
848                    orgLaborImpl.setTueOpen(orgLabor.getTueOpen());
849                    orgLaborImpl.setTueClose(orgLabor.getTueClose());
850                    orgLaborImpl.setWedOpen(orgLabor.getWedOpen());
851                    orgLaborImpl.setWedClose(orgLabor.getWedClose());
852                    orgLaborImpl.setThuOpen(orgLabor.getThuOpen());
853                    orgLaborImpl.setThuClose(orgLabor.getThuClose());
854                    orgLaborImpl.setFriOpen(orgLabor.getFriOpen());
855                    orgLaborImpl.setFriClose(orgLabor.getFriClose());
856                    orgLaborImpl.setSatOpen(orgLabor.getSatOpen());
857                    orgLaborImpl.setSatClose(orgLabor.getSatClose());
858    
859                    return orgLaborImpl;
860            }
861    
862            /**
863             * Returns the org labor with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
864             *
865             * @param primaryKey the primary key of the org labor
866             * @return the org labor
867             * @throws com.liferay.portal.NoSuchOrgLaborException if a org labor with the primary key could not be found
868             * @throws SystemException if a system exception occurred
869             */
870            @Override
871            public OrgLabor findByPrimaryKey(Serializable primaryKey)
872                    throws NoSuchOrgLaborException, SystemException {
873                    OrgLabor orgLabor = fetchByPrimaryKey(primaryKey);
874    
875                    if (orgLabor == null) {
876                            if (_log.isWarnEnabled()) {
877                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
878                            }
879    
880                            throw new NoSuchOrgLaborException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
881                                    primaryKey);
882                    }
883    
884                    return orgLabor;
885            }
886    
887            /**
888             * Returns the org labor with the primary key or throws a {@link com.liferay.portal.NoSuchOrgLaborException} if it could not be found.
889             *
890             * @param orgLaborId the primary key of the org labor
891             * @return the org labor
892             * @throws com.liferay.portal.NoSuchOrgLaborException if a org labor with the primary key could not be found
893             * @throws SystemException if a system exception occurred
894             */
895            @Override
896            public OrgLabor findByPrimaryKey(long orgLaborId)
897                    throws NoSuchOrgLaborException, SystemException {
898                    return findByPrimaryKey((Serializable)orgLaborId);
899            }
900    
901            /**
902             * Returns the org labor with the primary key or returns <code>null</code> if it could not be found.
903             *
904             * @param primaryKey the primary key of the org labor
905             * @return the org labor, or <code>null</code> if a org labor with the primary key could not be found
906             * @throws SystemException if a system exception occurred
907             */
908            @Override
909            public OrgLabor fetchByPrimaryKey(Serializable primaryKey)
910                    throws SystemException {
911                    OrgLabor orgLabor = (OrgLabor)EntityCacheUtil.getResult(OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
912                                    OrgLaborImpl.class, primaryKey);
913    
914                    if (orgLabor == _nullOrgLabor) {
915                            return null;
916                    }
917    
918                    if (orgLabor == null) {
919                            Session session = null;
920    
921                            try {
922                                    session = openSession();
923    
924                                    orgLabor = (OrgLabor)session.get(OrgLaborImpl.class, primaryKey);
925    
926                                    if (orgLabor != null) {
927                                            cacheResult(orgLabor);
928                                    }
929                                    else {
930                                            EntityCacheUtil.putResult(OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
931                                                    OrgLaborImpl.class, primaryKey, _nullOrgLabor);
932                                    }
933                            }
934                            catch (Exception e) {
935                                    EntityCacheUtil.removeResult(OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
936                                            OrgLaborImpl.class, primaryKey);
937    
938                                    throw processException(e);
939                            }
940                            finally {
941                                    closeSession(session);
942                            }
943                    }
944    
945                    return orgLabor;
946            }
947    
948            /**
949             * Returns the org labor with the primary key or returns <code>null</code> if it could not be found.
950             *
951             * @param orgLaborId the primary key of the org labor
952             * @return the org labor, or <code>null</code> if a org labor with the primary key could not be found
953             * @throws SystemException if a system exception occurred
954             */
955            @Override
956            public OrgLabor fetchByPrimaryKey(long orgLaborId)
957                    throws SystemException {
958                    return fetchByPrimaryKey((Serializable)orgLaborId);
959            }
960    
961            /**
962             * Returns all the org labors.
963             *
964             * @return the org labors
965             * @throws SystemException if a system exception occurred
966             */
967            @Override
968            public List<OrgLabor> findAll() throws SystemException {
969                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
970            }
971    
972            /**
973             * Returns a range of all the org labors.
974             *
975             * <p>
976             * 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.
977             * </p>
978             *
979             * @param start the lower bound of the range of org labors
980             * @param end the upper bound of the range of org labors (not inclusive)
981             * @return the range of org labors
982             * @throws SystemException if a system exception occurred
983             */
984            @Override
985            public List<OrgLabor> findAll(int start, int end) throws SystemException {
986                    return findAll(start, end, null);
987            }
988    
989            /**
990             * Returns an ordered range of all the org labors.
991             *
992             * <p>
993             * 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.
994             * </p>
995             *
996             * @param start the lower bound of the range of org labors
997             * @param end the upper bound of the range of org labors (not inclusive)
998             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
999             * @return the ordered range of org labors
1000             * @throws SystemException if a system exception occurred
1001             */
1002            @Override
1003            public List<OrgLabor> findAll(int start, int end,
1004                    OrderByComparator orderByComparator) throws SystemException {
1005                    boolean pagination = true;
1006                    FinderPath finderPath = null;
1007                    Object[] finderArgs = null;
1008    
1009                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1010                                    (orderByComparator == null)) {
1011                            pagination = false;
1012                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1013                            finderArgs = FINDER_ARGS_EMPTY;
1014                    }
1015                    else {
1016                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1017                            finderArgs = new Object[] { start, end, orderByComparator };
1018                    }
1019    
1020                    List<OrgLabor> list = (List<OrgLabor>)FinderCacheUtil.getResult(finderPath,
1021                                    finderArgs, this);
1022    
1023                    if (list == null) {
1024                            StringBundler query = null;
1025                            String sql = null;
1026    
1027                            if (orderByComparator != null) {
1028                                    query = new StringBundler(2 +
1029                                                    (orderByComparator.getOrderByFields().length * 3));
1030    
1031                                    query.append(_SQL_SELECT_ORGLABOR);
1032    
1033                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1034                                            orderByComparator);
1035    
1036                                    sql = query.toString();
1037                            }
1038                            else {
1039                                    sql = _SQL_SELECT_ORGLABOR;
1040    
1041                                    if (pagination) {
1042                                            sql = sql.concat(OrgLaborModelImpl.ORDER_BY_JPQL);
1043                                    }
1044                            }
1045    
1046                            Session session = null;
1047    
1048                            try {
1049                                    session = openSession();
1050    
1051                                    Query q = session.createQuery(sql);
1052    
1053                                    if (!pagination) {
1054                                            list = (List<OrgLabor>)QueryUtil.list(q, getDialect(),
1055                                                            start, end, false);
1056    
1057                                            Collections.sort(list);
1058    
1059                                            list = new UnmodifiableList<OrgLabor>(list);
1060                                    }
1061                                    else {
1062                                            list = (List<OrgLabor>)QueryUtil.list(q, getDialect(),
1063                                                            start, end);
1064                                    }
1065    
1066                                    cacheResult(list);
1067    
1068                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1069                            }
1070                            catch (Exception e) {
1071                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1072    
1073                                    throw processException(e);
1074                            }
1075                            finally {
1076                                    closeSession(session);
1077                            }
1078                    }
1079    
1080                    return list;
1081            }
1082    
1083            /**
1084             * Removes all the org labors from the database.
1085             *
1086             * @throws SystemException if a system exception occurred
1087             */
1088            @Override
1089            public void removeAll() throws SystemException {
1090                    for (OrgLabor orgLabor : findAll()) {
1091                            remove(orgLabor);
1092                    }
1093            }
1094    
1095            /**
1096             * Returns the number of org labors.
1097             *
1098             * @return the number of org labors
1099             * @throws SystemException if a system exception occurred
1100             */
1101            @Override
1102            public int countAll() throws SystemException {
1103                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1104                                    FINDER_ARGS_EMPTY, this);
1105    
1106                    if (count == null) {
1107                            Session session = null;
1108    
1109                            try {
1110                                    session = openSession();
1111    
1112                                    Query q = session.createQuery(_SQL_COUNT_ORGLABOR);
1113    
1114                                    count = (Long)q.uniqueResult();
1115    
1116                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1117                                            FINDER_ARGS_EMPTY, count);
1118                            }
1119                            catch (Exception e) {
1120                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1121                                            FINDER_ARGS_EMPTY);
1122    
1123                                    throw processException(e);
1124                            }
1125                            finally {
1126                                    closeSession(session);
1127                            }
1128                    }
1129    
1130                    return count.intValue();
1131            }
1132    
1133            /**
1134             * Initializes the org labor persistence.
1135             */
1136            public void afterPropertiesSet() {
1137                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1138                                            com.liferay.portal.util.PropsUtil.get(
1139                                                    "value.object.listener.com.liferay.portal.model.OrgLabor")));
1140    
1141                    if (listenerClassNames.length > 0) {
1142                            try {
1143                                    List<ModelListener<OrgLabor>> listenersList = new ArrayList<ModelListener<OrgLabor>>();
1144    
1145                                    for (String listenerClassName : listenerClassNames) {
1146                                            listenersList.add((ModelListener<OrgLabor>)InstanceFactory.newInstance(
1147                                                            getClassLoader(), listenerClassName));
1148                                    }
1149    
1150                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1151                            }
1152                            catch (Exception e) {
1153                                    _log.error(e);
1154                            }
1155                    }
1156            }
1157    
1158            public void destroy() {
1159                    EntityCacheUtil.removeCache(OrgLaborImpl.class.getName());
1160                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1161                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1162                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1163            }
1164    
1165            private static final String _SQL_SELECT_ORGLABOR = "SELECT orgLabor FROM OrgLabor orgLabor";
1166            private static final String _SQL_SELECT_ORGLABOR_WHERE = "SELECT orgLabor FROM OrgLabor orgLabor WHERE ";
1167            private static final String _SQL_COUNT_ORGLABOR = "SELECT COUNT(orgLabor) FROM OrgLabor orgLabor";
1168            private static final String _SQL_COUNT_ORGLABOR_WHERE = "SELECT COUNT(orgLabor) FROM OrgLabor orgLabor WHERE ";
1169            private static final String _ORDER_BY_ENTITY_ALIAS = "orgLabor.";
1170            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No OrgLabor exists with the primary key ";
1171            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No OrgLabor exists with the key {";
1172            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1173            private static Log _log = LogFactoryUtil.getLog(OrgLaborPersistenceImpl.class);
1174            private static OrgLabor _nullOrgLabor = new OrgLaborImpl() {
1175                            @Override
1176                            public Object clone() {
1177                                    return this;
1178                            }
1179    
1180                            @Override
1181                            public CacheModel<OrgLabor> toCacheModel() {
1182                                    return _nullOrgLaborCacheModel;
1183                            }
1184                    };
1185    
1186            private static CacheModel<OrgLabor> _nullOrgLaborCacheModel = new CacheModel<OrgLabor>() {
1187                            @Override
1188                            public OrgLabor toEntityModel() {
1189                                    return _nullOrgLabor;
1190                            }
1191                    };
1192    }