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