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