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