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 * 3));
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(6 +
436                                            (orderByComparator.getOrderByFields().length * 6));
437                    }
438                    else {
439                            query = new StringBundler(3);
440                    }
441    
442                    query.append(_SQL_SELECT_ORGLABOR_WHERE);
443    
444                    query.append(_FINDER_COLUMN_ORGANIZATIONID_ORGANIZATIONID_2);
445    
446                    if (orderByComparator != null) {
447                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
448    
449                            if (orderByConditionFields.length > 0) {
450                                    query.append(WHERE_AND);
451                            }
452    
453                            for (int i = 0; i < orderByConditionFields.length; i++) {
454                                    query.append(_ORDER_BY_ENTITY_ALIAS);
455                                    query.append(orderByConditionFields[i]);
456    
457                                    if ((i + 1) < orderByConditionFields.length) {
458                                            if (orderByComparator.isAscending() ^ previous) {
459                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
460                                            }
461                                            else {
462                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
463                                            }
464                                    }
465                                    else {
466                                            if (orderByComparator.isAscending() ^ previous) {
467                                                    query.append(WHERE_GREATER_THAN);
468                                            }
469                                            else {
470                                                    query.append(WHERE_LESSER_THAN);
471                                            }
472                                    }
473                            }
474    
475                            query.append(ORDER_BY_CLAUSE);
476    
477                            String[] orderByFields = orderByComparator.getOrderByFields();
478    
479                            for (int i = 0; i < orderByFields.length; i++) {
480                                    query.append(_ORDER_BY_ENTITY_ALIAS);
481                                    query.append(orderByFields[i]);
482    
483                                    if ((i + 1) < orderByFields.length) {
484                                            if (orderByComparator.isAscending() ^ previous) {
485                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
486                                            }
487                                            else {
488                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
489                                            }
490                                    }
491                                    else {
492                                            if (orderByComparator.isAscending() ^ previous) {
493                                                    query.append(ORDER_BY_ASC);
494                                            }
495                                            else {
496                                                    query.append(ORDER_BY_DESC);
497                                            }
498                                    }
499                            }
500                    }
501                    else {
502                            query.append(OrgLaborModelImpl.ORDER_BY_JPQL);
503                    }
504    
505                    String sql = query.toString();
506    
507                    Query q = session.createQuery(sql);
508    
509                    q.setFirstResult(0);
510                    q.setMaxResults(2);
511    
512                    QueryPos qPos = QueryPos.getInstance(q);
513    
514                    qPos.add(organizationId);
515    
516                    if (orderByComparator != null) {
517                            Object[] values = orderByComparator.getOrderByConditionValues(orgLabor);
518    
519                            for (Object value : values) {
520                                    qPos.add(value);
521                            }
522                    }
523    
524                    List<OrgLabor> list = q.list();
525    
526                    if (list.size() == 2) {
527                            return list.get(1);
528                    }
529                    else {
530                            return null;
531                    }
532            }
533    
534            /**
535             * Removes all the org labors where organizationId = &#63; from the database.
536             *
537             * @param organizationId the organization ID
538             */
539            @Override
540            public void removeByOrganizationId(long organizationId) {
541                    for (OrgLabor orgLabor : findByOrganizationId(organizationId,
542                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
543                            remove(orgLabor);
544                    }
545            }
546    
547            /**
548             * Returns the number of org labors where organizationId = &#63;.
549             *
550             * @param organizationId the organization ID
551             * @return the number of matching org labors
552             */
553            @Override
554            public int countByOrganizationId(long organizationId) {
555                    FinderPath finderPath = FINDER_PATH_COUNT_BY_ORGANIZATIONID;
556    
557                    Object[] finderArgs = new Object[] { organizationId };
558    
559                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
560    
561                    if (count == null) {
562                            StringBundler query = new StringBundler(2);
563    
564                            query.append(_SQL_COUNT_ORGLABOR_WHERE);
565    
566                            query.append(_FINDER_COLUMN_ORGANIZATIONID_ORGANIZATIONID_2);
567    
568                            String sql = query.toString();
569    
570                            Session session = null;
571    
572                            try {
573                                    session = openSession();
574    
575                                    Query q = session.createQuery(sql);
576    
577                                    QueryPos qPos = QueryPos.getInstance(q);
578    
579                                    qPos.add(organizationId);
580    
581                                    count = (Long)q.uniqueResult();
582    
583                                    finderCache.putResult(finderPath, finderArgs, count);
584                            }
585                            catch (Exception e) {
586                                    finderCache.removeResult(finderPath, finderArgs);
587    
588                                    throw processException(e);
589                            }
590                            finally {
591                                    closeSession(session);
592                            }
593                    }
594    
595                    return count.intValue();
596            }
597    
598            private static final String _FINDER_COLUMN_ORGANIZATIONID_ORGANIZATIONID_2 = "orgLabor.organizationId = ?";
599    
600            public OrgLaborPersistenceImpl() {
601                    setModelClass(OrgLabor.class);
602            }
603    
604            /**
605             * Caches the org labor in the entity cache if it is enabled.
606             *
607             * @param orgLabor the org labor
608             */
609            @Override
610            public void cacheResult(OrgLabor orgLabor) {
611                    entityCache.putResult(OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
612                            OrgLaborImpl.class, orgLabor.getPrimaryKey(), orgLabor);
613    
614                    orgLabor.resetOriginalValues();
615            }
616    
617            /**
618             * Caches the org labors in the entity cache if it is enabled.
619             *
620             * @param orgLabors the org labors
621             */
622            @Override
623            public void cacheResult(List<OrgLabor> orgLabors) {
624                    for (OrgLabor orgLabor : orgLabors) {
625                            if (entityCache.getResult(OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
626                                                    OrgLaborImpl.class, orgLabor.getPrimaryKey()) == null) {
627                                    cacheResult(orgLabor);
628                            }
629                            else {
630                                    orgLabor.resetOriginalValues();
631                            }
632                    }
633            }
634    
635            /**
636             * Clears the cache for all org labors.
637             *
638             * <p>
639             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
640             * </p>
641             */
642            @Override
643            public void clearCache() {
644                    entityCache.clearCache(OrgLaborImpl.class);
645    
646                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
647                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
648                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
649            }
650    
651            /**
652             * Clears the cache for the org labor.
653             *
654             * <p>
655             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
656             * </p>
657             */
658            @Override
659            public void clearCache(OrgLabor orgLabor) {
660                    entityCache.removeResult(OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
661                            OrgLaborImpl.class, orgLabor.getPrimaryKey());
662    
663                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
664                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
665            }
666    
667            @Override
668            public void clearCache(List<OrgLabor> orgLabors) {
669                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
670                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
671    
672                    for (OrgLabor orgLabor : orgLabors) {
673                            entityCache.removeResult(OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
674                                    OrgLaborImpl.class, orgLabor.getPrimaryKey());
675                    }
676            }
677    
678            /**
679             * Creates a new org labor with the primary key. Does not add the org labor to the database.
680             *
681             * @param orgLaborId the primary key for the new org labor
682             * @return the new org labor
683             */
684            @Override
685            public OrgLabor create(long orgLaborId) {
686                    OrgLabor orgLabor = new OrgLaborImpl();
687    
688                    orgLabor.setNew(true);
689                    orgLabor.setPrimaryKey(orgLaborId);
690    
691                    orgLabor.setCompanyId(companyProvider.getCompanyId());
692    
693                    return orgLabor;
694            }
695    
696            /**
697             * Removes the org labor with the primary key from the database. Also notifies the appropriate model listeners.
698             *
699             * @param orgLaborId the primary key of the org labor
700             * @return the org labor that was removed
701             * @throws NoSuchOrgLaborException if a org labor with the primary key could not be found
702             */
703            @Override
704            public OrgLabor remove(long orgLaborId) throws NoSuchOrgLaborException {
705                    return remove((Serializable)orgLaborId);
706            }
707    
708            /**
709             * Removes the org labor with the primary key from the database. Also notifies the appropriate model listeners.
710             *
711             * @param primaryKey the primary key of the org labor
712             * @return the org labor that was removed
713             * @throws NoSuchOrgLaborException if a org labor with the primary key could not be found
714             */
715            @Override
716            public OrgLabor remove(Serializable primaryKey)
717                    throws NoSuchOrgLaborException {
718                    Session session = null;
719    
720                    try {
721                            session = openSession();
722    
723                            OrgLabor orgLabor = (OrgLabor)session.get(OrgLaborImpl.class,
724                                            primaryKey);
725    
726                            if (orgLabor == null) {
727                                    if (_log.isWarnEnabled()) {
728                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
729                                    }
730    
731                                    throw new NoSuchOrgLaborException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
732                                            primaryKey);
733                            }
734    
735                            return remove(orgLabor);
736                    }
737                    catch (NoSuchOrgLaborException nsee) {
738                            throw nsee;
739                    }
740                    catch (Exception e) {
741                            throw processException(e);
742                    }
743                    finally {
744                            closeSession(session);
745                    }
746            }
747    
748            @Override
749            protected OrgLabor removeImpl(OrgLabor orgLabor) {
750                    orgLabor = toUnwrappedModel(orgLabor);
751    
752                    Session session = null;
753    
754                    try {
755                            session = openSession();
756    
757                            if (!session.contains(orgLabor)) {
758                                    orgLabor = (OrgLabor)session.get(OrgLaborImpl.class,
759                                                    orgLabor.getPrimaryKeyObj());
760                            }
761    
762                            if (orgLabor != null) {
763                                    session.delete(orgLabor);
764                            }
765                    }
766                    catch (Exception e) {
767                            throw processException(e);
768                    }
769                    finally {
770                            closeSession(session);
771                    }
772    
773                    if (orgLabor != null) {
774                            clearCache(orgLabor);
775                    }
776    
777                    return orgLabor;
778            }
779    
780            @Override
781            public OrgLabor updateImpl(OrgLabor orgLabor) {
782                    orgLabor = toUnwrappedModel(orgLabor);
783    
784                    boolean isNew = orgLabor.isNew();
785    
786                    OrgLaborModelImpl orgLaborModelImpl = (OrgLaborModelImpl)orgLabor;
787    
788                    Session session = null;
789    
790                    try {
791                            session = openSession();
792    
793                            if (orgLabor.isNew()) {
794                                    session.save(orgLabor);
795    
796                                    orgLabor.setNew(false);
797                            }
798                            else {
799                                    orgLabor = (OrgLabor)session.merge(orgLabor);
800                            }
801                    }
802                    catch (Exception e) {
803                            throw processException(e);
804                    }
805                    finally {
806                            closeSession(session);
807                    }
808    
809                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
810    
811                    if (isNew || !OrgLaborModelImpl.COLUMN_BITMASK_ENABLED) {
812                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
813                    }
814    
815                    else {
816                            if ((orgLaborModelImpl.getColumnBitmask() &
817                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ORGANIZATIONID.getColumnBitmask()) != 0) {
818                                    Object[] args = new Object[] {
819                                                    orgLaborModelImpl.getOriginalOrganizationId()
820                                            };
821    
822                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_ORGANIZATIONID,
823                                            args);
824                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ORGANIZATIONID,
825                                            args);
826    
827                                    args = new Object[] { orgLaborModelImpl.getOrganizationId() };
828    
829                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_ORGANIZATIONID,
830                                            args);
831                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ORGANIZATIONID,
832                                            args);
833                            }
834                    }
835    
836                    entityCache.putResult(OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
837                            OrgLaborImpl.class, orgLabor.getPrimaryKey(), orgLabor, false);
838    
839                    orgLabor.resetOriginalValues();
840    
841                    return orgLabor;
842            }
843    
844            protected OrgLabor toUnwrappedModel(OrgLabor orgLabor) {
845                    if (orgLabor instanceof OrgLaborImpl) {
846                            return orgLabor;
847                    }
848    
849                    OrgLaborImpl orgLaborImpl = new OrgLaborImpl();
850    
851                    orgLaborImpl.setNew(orgLabor.isNew());
852                    orgLaborImpl.setPrimaryKey(orgLabor.getPrimaryKey());
853    
854                    orgLaborImpl.setMvccVersion(orgLabor.getMvccVersion());
855                    orgLaborImpl.setOrgLaborId(orgLabor.getOrgLaborId());
856                    orgLaborImpl.setCompanyId(orgLabor.getCompanyId());
857                    orgLaborImpl.setOrganizationId(orgLabor.getOrganizationId());
858                    orgLaborImpl.setTypeId(orgLabor.getTypeId());
859                    orgLaborImpl.setSunOpen(orgLabor.getSunOpen());
860                    orgLaborImpl.setSunClose(orgLabor.getSunClose());
861                    orgLaborImpl.setMonOpen(orgLabor.getMonOpen());
862                    orgLaborImpl.setMonClose(orgLabor.getMonClose());
863                    orgLaborImpl.setTueOpen(orgLabor.getTueOpen());
864                    orgLaborImpl.setTueClose(orgLabor.getTueClose());
865                    orgLaborImpl.setWedOpen(orgLabor.getWedOpen());
866                    orgLaborImpl.setWedClose(orgLabor.getWedClose());
867                    orgLaborImpl.setThuOpen(orgLabor.getThuOpen());
868                    orgLaborImpl.setThuClose(orgLabor.getThuClose());
869                    orgLaborImpl.setFriOpen(orgLabor.getFriOpen());
870                    orgLaborImpl.setFriClose(orgLabor.getFriClose());
871                    orgLaborImpl.setSatOpen(orgLabor.getSatOpen());
872                    orgLaborImpl.setSatClose(orgLabor.getSatClose());
873    
874                    return orgLaborImpl;
875            }
876    
877            /**
878             * Returns the org labor with the primary key or throws a {@link com.liferay.portal.exception.NoSuchModelException} if it could not be found.
879             *
880             * @param primaryKey the primary key of the org labor
881             * @return the org labor
882             * @throws NoSuchOrgLaborException if a org labor with the primary key could not be found
883             */
884            @Override
885            public OrgLabor findByPrimaryKey(Serializable primaryKey)
886                    throws NoSuchOrgLaborException {
887                    OrgLabor orgLabor = fetchByPrimaryKey(primaryKey);
888    
889                    if (orgLabor == null) {
890                            if (_log.isWarnEnabled()) {
891                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
892                            }
893    
894                            throw new NoSuchOrgLaborException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
895                                    primaryKey);
896                    }
897    
898                    return orgLabor;
899            }
900    
901            /**
902             * Returns the org labor with the primary key or throws a {@link NoSuchOrgLaborException} if it could not be found.
903             *
904             * @param orgLaborId the primary key of the org labor
905             * @return the org labor
906             * @throws NoSuchOrgLaborException if a org labor with the primary key could not be found
907             */
908            @Override
909            public OrgLabor findByPrimaryKey(long orgLaborId)
910                    throws NoSuchOrgLaborException {
911                    return findByPrimaryKey((Serializable)orgLaborId);
912            }
913    
914            /**
915             * Returns the org labor with the primary key or returns <code>null</code> if it could not be found.
916             *
917             * @param primaryKey the primary key of the org labor
918             * @return the org labor, or <code>null</code> if a org labor with the primary key could not be found
919             */
920            @Override
921            public OrgLabor fetchByPrimaryKey(Serializable primaryKey) {
922                    OrgLabor orgLabor = (OrgLabor)entityCache.getResult(OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
923                                    OrgLaborImpl.class, primaryKey);
924    
925                    if (orgLabor == _nullOrgLabor) {
926                            return null;
927                    }
928    
929                    if (orgLabor == null) {
930                            Session session = null;
931    
932                            try {
933                                    session = openSession();
934    
935                                    orgLabor = (OrgLabor)session.get(OrgLaborImpl.class, primaryKey);
936    
937                                    if (orgLabor != null) {
938                                            cacheResult(orgLabor);
939                                    }
940                                    else {
941                                            entityCache.putResult(OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
942                                                    OrgLaborImpl.class, primaryKey, _nullOrgLabor);
943                                    }
944                            }
945                            catch (Exception e) {
946                                    entityCache.removeResult(OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
947                                            OrgLaborImpl.class, primaryKey);
948    
949                                    throw processException(e);
950                            }
951                            finally {
952                                    closeSession(session);
953                            }
954                    }
955    
956                    return orgLabor;
957            }
958    
959            /**
960             * Returns the org labor with the primary key or returns <code>null</code> if it could not be found.
961             *
962             * @param orgLaborId the primary key of the org labor
963             * @return the org labor, or <code>null</code> if a org labor with the primary key could not be found
964             */
965            @Override
966            public OrgLabor fetchByPrimaryKey(long orgLaborId) {
967                    return fetchByPrimaryKey((Serializable)orgLaborId);
968            }
969    
970            @Override
971            public Map<Serializable, OrgLabor> fetchByPrimaryKeys(
972                    Set<Serializable> primaryKeys) {
973                    if (primaryKeys.isEmpty()) {
974                            return Collections.emptyMap();
975                    }
976    
977                    Map<Serializable, OrgLabor> map = new HashMap<Serializable, OrgLabor>();
978    
979                    if (primaryKeys.size() == 1) {
980                            Iterator<Serializable> iterator = primaryKeys.iterator();
981    
982                            Serializable primaryKey = iterator.next();
983    
984                            OrgLabor orgLabor = fetchByPrimaryKey(primaryKey);
985    
986                            if (orgLabor != null) {
987                                    map.put(primaryKey, orgLabor);
988                            }
989    
990                            return map;
991                    }
992    
993                    Set<Serializable> uncachedPrimaryKeys = null;
994    
995                    for (Serializable primaryKey : primaryKeys) {
996                            OrgLabor orgLabor = (OrgLabor)entityCache.getResult(OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
997                                            OrgLaborImpl.class, primaryKey);
998    
999                            if (orgLabor == null) {
1000                                    if (uncachedPrimaryKeys == null) {
1001                                            uncachedPrimaryKeys = new HashSet<Serializable>();
1002                                    }
1003    
1004                                    uncachedPrimaryKeys.add(primaryKey);
1005                            }
1006                            else {
1007                                    map.put(primaryKey, orgLabor);
1008                            }
1009                    }
1010    
1011                    if (uncachedPrimaryKeys == null) {
1012                            return map;
1013                    }
1014    
1015                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
1016                                    1);
1017    
1018                    query.append(_SQL_SELECT_ORGLABOR_WHERE_PKS_IN);
1019    
1020                    for (Serializable primaryKey : uncachedPrimaryKeys) {
1021                            query.append(String.valueOf(primaryKey));
1022    
1023                            query.append(StringPool.COMMA);
1024                    }
1025    
1026                    query.setIndex(query.index() - 1);
1027    
1028                    query.append(StringPool.CLOSE_PARENTHESIS);
1029    
1030                    String sql = query.toString();
1031    
1032                    Session session = null;
1033    
1034                    try {
1035                            session = openSession();
1036    
1037                            Query q = session.createQuery(sql);
1038    
1039                            for (OrgLabor orgLabor : (List<OrgLabor>)q.list()) {
1040                                    map.put(orgLabor.getPrimaryKeyObj(), orgLabor);
1041    
1042                                    cacheResult(orgLabor);
1043    
1044                                    uncachedPrimaryKeys.remove(orgLabor.getPrimaryKeyObj());
1045                            }
1046    
1047                            for (Serializable primaryKey : uncachedPrimaryKeys) {
1048                                    entityCache.putResult(OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
1049                                            OrgLaborImpl.class, primaryKey, _nullOrgLabor);
1050                            }
1051                    }
1052                    catch (Exception e) {
1053                            throw processException(e);
1054                    }
1055                    finally {
1056                            closeSession(session);
1057                    }
1058    
1059                    return map;
1060            }
1061    
1062            /**
1063             * Returns all the org labors.
1064             *
1065             * @return the org labors
1066             */
1067            @Override
1068            public List<OrgLabor> findAll() {
1069                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1070            }
1071    
1072            /**
1073             * Returns a range of all the org labors.
1074             *
1075             * <p>
1076             * 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.
1077             * </p>
1078             *
1079             * @param start the lower bound of the range of org labors
1080             * @param end the upper bound of the range of org labors (not inclusive)
1081             * @return the range of org labors
1082             */
1083            @Override
1084            public List<OrgLabor> findAll(int start, int end) {
1085                    return findAll(start, end, null);
1086            }
1087    
1088            /**
1089             * Returns an ordered range of all the org labors.
1090             *
1091             * <p>
1092             * 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.
1093             * </p>
1094             *
1095             * @param start the lower bound of the range of org labors
1096             * @param end the upper bound of the range of org labors (not inclusive)
1097             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1098             * @return the ordered range of org labors
1099             */
1100            @Override
1101            public List<OrgLabor> findAll(int start, int end,
1102                    OrderByComparator<OrgLabor> orderByComparator) {
1103                    return findAll(start, end, orderByComparator, true);
1104            }
1105    
1106            /**
1107             * Returns an ordered range of all the org labors.
1108             *
1109             * <p>
1110             * 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.
1111             * </p>
1112             *
1113             * @param start the lower bound of the range of org labors
1114             * @param end the upper bound of the range of org labors (not inclusive)
1115             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1116             * @param retrieveFromCache whether to retrieve from the finder cache
1117             * @return the ordered range of org labors
1118             */
1119            @Override
1120            public List<OrgLabor> findAll(int start, int end,
1121                    OrderByComparator<OrgLabor> orderByComparator, boolean retrieveFromCache) {
1122                    boolean pagination = true;
1123                    FinderPath finderPath = null;
1124                    Object[] finderArgs = null;
1125    
1126                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1127                                    (orderByComparator == null)) {
1128                            pagination = false;
1129                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1130                            finderArgs = FINDER_ARGS_EMPTY;
1131                    }
1132                    else {
1133                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1134                            finderArgs = new Object[] { start, end, orderByComparator };
1135                    }
1136    
1137                    List<OrgLabor> list = null;
1138    
1139                    if (retrieveFromCache) {
1140                            list = (List<OrgLabor>)finderCache.getResult(finderPath,
1141                                            finderArgs, this);
1142                    }
1143    
1144                    if (list == null) {
1145                            StringBundler query = null;
1146                            String sql = null;
1147    
1148                            if (orderByComparator != null) {
1149                                    query = new StringBundler(2 +
1150                                                    (orderByComparator.getOrderByFields().length * 3));
1151    
1152                                    query.append(_SQL_SELECT_ORGLABOR);
1153    
1154                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1155                                            orderByComparator);
1156    
1157                                    sql = query.toString();
1158                            }
1159                            else {
1160                                    sql = _SQL_SELECT_ORGLABOR;
1161    
1162                                    if (pagination) {
1163                                            sql = sql.concat(OrgLaborModelImpl.ORDER_BY_JPQL);
1164                                    }
1165                            }
1166    
1167                            Session session = null;
1168    
1169                            try {
1170                                    session = openSession();
1171    
1172                                    Query q = session.createQuery(sql);
1173    
1174                                    if (!pagination) {
1175                                            list = (List<OrgLabor>)QueryUtil.list(q, getDialect(),
1176                                                            start, end, false);
1177    
1178                                            Collections.sort(list);
1179    
1180                                            list = Collections.unmodifiableList(list);
1181                                    }
1182                                    else {
1183                                            list = (List<OrgLabor>)QueryUtil.list(q, getDialect(),
1184                                                            start, end);
1185                                    }
1186    
1187                                    cacheResult(list);
1188    
1189                                    finderCache.putResult(finderPath, finderArgs, list);
1190                            }
1191                            catch (Exception e) {
1192                                    finderCache.removeResult(finderPath, finderArgs);
1193    
1194                                    throw processException(e);
1195                            }
1196                            finally {
1197                                    closeSession(session);
1198                            }
1199                    }
1200    
1201                    return list;
1202            }
1203    
1204            /**
1205             * Removes all the org labors from the database.
1206             *
1207             */
1208            @Override
1209            public void removeAll() {
1210                    for (OrgLabor orgLabor : findAll()) {
1211                            remove(orgLabor);
1212                    }
1213            }
1214    
1215            /**
1216             * Returns the number of org labors.
1217             *
1218             * @return the number of org labors
1219             */
1220            @Override
1221            public int countAll() {
1222                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
1223                                    FINDER_ARGS_EMPTY, this);
1224    
1225                    if (count == null) {
1226                            Session session = null;
1227    
1228                            try {
1229                                    session = openSession();
1230    
1231                                    Query q = session.createQuery(_SQL_COUNT_ORGLABOR);
1232    
1233                                    count = (Long)q.uniqueResult();
1234    
1235                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
1236                                            count);
1237                            }
1238                            catch (Exception e) {
1239                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
1240                                            FINDER_ARGS_EMPTY);
1241    
1242                                    throw processException(e);
1243                            }
1244                            finally {
1245                                    closeSession(session);
1246                            }
1247                    }
1248    
1249                    return count.intValue();
1250            }
1251    
1252            @Override
1253            protected Map<String, Integer> getTableColumnsMap() {
1254                    return OrgLaborModelImpl.TABLE_COLUMNS_MAP;
1255            }
1256    
1257            /**
1258             * Initializes the org labor persistence.
1259             */
1260            public void afterPropertiesSet() {
1261            }
1262    
1263            public void destroy() {
1264                    entityCache.removeCache(OrgLaborImpl.class.getName());
1265                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
1266                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1267                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1268            }
1269    
1270            @BeanReference(type = CompanyProviderWrapper.class)
1271            protected CompanyProvider companyProvider;
1272            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
1273            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
1274            private static final String _SQL_SELECT_ORGLABOR = "SELECT orgLabor FROM OrgLabor orgLabor";
1275            private static final String _SQL_SELECT_ORGLABOR_WHERE_PKS_IN = "SELECT orgLabor FROM OrgLabor orgLabor WHERE orgLaborId IN (";
1276            private static final String _SQL_SELECT_ORGLABOR_WHERE = "SELECT orgLabor FROM OrgLabor orgLabor WHERE ";
1277            private static final String _SQL_COUNT_ORGLABOR = "SELECT COUNT(orgLabor) FROM OrgLabor orgLabor";
1278            private static final String _SQL_COUNT_ORGLABOR_WHERE = "SELECT COUNT(orgLabor) FROM OrgLabor orgLabor WHERE ";
1279            private static final String _ORDER_BY_ENTITY_ALIAS = "orgLabor.";
1280            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No OrgLabor exists with the primary key ";
1281            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No OrgLabor exists with the key {";
1282            private static final Log _log = LogFactoryUtil.getLog(OrgLaborPersistenceImpl.class);
1283            private static final OrgLabor _nullOrgLabor = new OrgLaborImpl() {
1284                            @Override
1285                            public Object clone() {
1286                                    return this;
1287                            }
1288    
1289                            @Override
1290                            public CacheModel<OrgLabor> toCacheModel() {
1291                                    return _nullOrgLaborCacheModel;
1292                            }
1293                    };
1294    
1295            private static final CacheModel<OrgLabor> _nullOrgLaborCacheModel = new NullCacheModel();
1296    
1297            private static class NullCacheModel implements CacheModel<OrgLabor>,
1298                    MVCCModel {
1299                    @Override
1300                    public long getMvccVersion() {
1301                            return -1;
1302                    }
1303    
1304                    @Override
1305                    public void setMvccVersion(long mvccVersion) {
1306                    }
1307    
1308                    @Override
1309                    public OrgLabor toEntityModel() {
1310                            return _nullOrgLabor;
1311                    }
1312            }
1313    }