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