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