001    /**
002     * Copyright (c) 2000-2010 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                            if (orgLabor.isCachedModel() || BatchSessionUtil.isEnabled()) {
217                                    Object staleObject = session.get(OrgLaborImpl.class,
218                                                    orgLabor.getPrimaryKeyObj());
219    
220                                    if (staleObject != null) {
221                                            session.evict(staleObject);
222                                    }
223                            }
224    
225                            session.delete(orgLabor);
226    
227                            session.flush();
228                    }
229                    catch (Exception e) {
230                            throw processException(e);
231                    }
232                    finally {
233                            closeSession(session);
234                    }
235    
236                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
237    
238                    EntityCacheUtil.removeResult(OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
239                            OrgLaborImpl.class, orgLabor.getPrimaryKey());
240    
241                    return orgLabor;
242            }
243    
244            public OrgLabor updateImpl(com.liferay.portal.model.OrgLabor orgLabor,
245                    boolean merge) throws SystemException {
246                    orgLabor = toUnwrappedModel(orgLabor);
247    
248                    Session session = null;
249    
250                    try {
251                            session = openSession();
252    
253                            BatchSessionUtil.update(session, orgLabor, merge);
254    
255                            orgLabor.setNew(false);
256                    }
257                    catch (Exception e) {
258                            throw processException(e);
259                    }
260                    finally {
261                            closeSession(session);
262                    }
263    
264                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
265    
266                    EntityCacheUtil.putResult(OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
267                            OrgLaborImpl.class, orgLabor.getPrimaryKey(), orgLabor);
268    
269                    return orgLabor;
270            }
271    
272            protected OrgLabor toUnwrappedModel(OrgLabor orgLabor) {
273                    if (orgLabor instanceof OrgLaborImpl) {
274                            return orgLabor;
275                    }
276    
277                    OrgLaborImpl orgLaborImpl = new OrgLaborImpl();
278    
279                    orgLaborImpl.setNew(orgLabor.isNew());
280                    orgLaborImpl.setPrimaryKey(orgLabor.getPrimaryKey());
281    
282                    orgLaborImpl.setOrgLaborId(orgLabor.getOrgLaborId());
283                    orgLaborImpl.setOrganizationId(orgLabor.getOrganizationId());
284                    orgLaborImpl.setTypeId(orgLabor.getTypeId());
285                    orgLaborImpl.setSunOpen(orgLabor.getSunOpen());
286                    orgLaborImpl.setSunClose(orgLabor.getSunClose());
287                    orgLaborImpl.setMonOpen(orgLabor.getMonOpen());
288                    orgLaborImpl.setMonClose(orgLabor.getMonClose());
289                    orgLaborImpl.setTueOpen(orgLabor.getTueOpen());
290                    orgLaborImpl.setTueClose(orgLabor.getTueClose());
291                    orgLaborImpl.setWedOpen(orgLabor.getWedOpen());
292                    orgLaborImpl.setWedClose(orgLabor.getWedClose());
293                    orgLaborImpl.setThuOpen(orgLabor.getThuOpen());
294                    orgLaborImpl.setThuClose(orgLabor.getThuClose());
295                    orgLaborImpl.setFriOpen(orgLabor.getFriOpen());
296                    orgLaborImpl.setFriClose(orgLabor.getFriClose());
297                    orgLaborImpl.setSatOpen(orgLabor.getSatOpen());
298                    orgLaborImpl.setSatClose(orgLabor.getSatClose());
299    
300                    return orgLaborImpl;
301            }
302    
303            /**
304             * Finds the org labor with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
305             *
306             * @param primaryKey the primary key of the org labor to find
307             * @return the org labor
308             * @throws com.liferay.portal.NoSuchModelException if a org labor with the primary key could not be found
309             * @throws SystemException if a system exception occurred
310             */
311            public OrgLabor findByPrimaryKey(Serializable primaryKey)
312                    throws NoSuchModelException, SystemException {
313                    return findByPrimaryKey(((Long)primaryKey).longValue());
314            }
315    
316            /**
317             * Finds the org labor with the primary key or throws a {@link com.liferay.portal.NoSuchOrgLaborException} if it could not be found.
318             *
319             * @param orgLaborId the primary key of the org labor to find
320             * @return the org labor
321             * @throws com.liferay.portal.NoSuchOrgLaborException if a org labor with the primary key could not be found
322             * @throws SystemException if a system exception occurred
323             */
324            public OrgLabor findByPrimaryKey(long orgLaborId)
325                    throws NoSuchOrgLaborException, SystemException {
326                    OrgLabor orgLabor = fetchByPrimaryKey(orgLaborId);
327    
328                    if (orgLabor == null) {
329                            if (_log.isWarnEnabled()) {
330                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + orgLaborId);
331                            }
332    
333                            throw new NoSuchOrgLaborException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
334                                    orgLaborId);
335                    }
336    
337                    return orgLabor;
338            }
339    
340            /**
341             * Finds the org labor with the primary key or returns <code>null</code> if it could not be found.
342             *
343             * @param primaryKey the primary key of the org labor to find
344             * @return the org labor, or <code>null</code> if a org labor with the primary key could not be found
345             * @throws SystemException if a system exception occurred
346             */
347            public OrgLabor fetchByPrimaryKey(Serializable primaryKey)
348                    throws SystemException {
349                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
350            }
351    
352            /**
353             * Finds the org labor with the primary key or returns <code>null</code> if it could not be found.
354             *
355             * @param orgLaborId the primary key of the org labor to find
356             * @return the org labor, or <code>null</code> if a org labor with the primary key could not be found
357             * @throws SystemException if a system exception occurred
358             */
359            public OrgLabor fetchByPrimaryKey(long orgLaborId)
360                    throws SystemException {
361                    OrgLabor orgLabor = (OrgLabor)EntityCacheUtil.getResult(OrgLaborModelImpl.ENTITY_CACHE_ENABLED,
362                                    OrgLaborImpl.class, orgLaborId, this);
363    
364                    if (orgLabor == null) {
365                            Session session = null;
366    
367                            try {
368                                    session = openSession();
369    
370                                    orgLabor = (OrgLabor)session.get(OrgLaborImpl.class,
371                                                    new Long(orgLaborId));
372                            }
373                            catch (Exception e) {
374                                    throw processException(e);
375                            }
376                            finally {
377                                    if (orgLabor != null) {
378                                            cacheResult(orgLabor);
379                                    }
380    
381                                    closeSession(session);
382                            }
383                    }
384    
385                    return orgLabor;
386            }
387    
388            /**
389             * Finds all the org labors where organizationId = &#63;.
390             *
391             * @param organizationId the organization id to search with
392             * @return the matching org labors
393             * @throws SystemException if a system exception occurred
394             */
395            public List<OrgLabor> findByOrganizationId(long organizationId)
396                    throws SystemException {
397                    return findByOrganizationId(organizationId, QueryUtil.ALL_POS,
398                            QueryUtil.ALL_POS, null);
399            }
400    
401            /**
402             * Finds a range of all the org labors where organizationId = &#63;.
403             *
404             * <p>
405             * 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.
406             * </p>
407             *
408             * @param organizationId the organization id to search with
409             * @param start the lower bound of the range of org labors to return
410             * @param end the upper bound of the range of org labors to return (not inclusive)
411             * @return the range of matching org labors
412             * @throws SystemException if a system exception occurred
413             */
414            public List<OrgLabor> findByOrganizationId(long organizationId, int start,
415                    int end) throws SystemException {
416                    return findByOrganizationId(organizationId, start, end, null);
417            }
418    
419            /**
420             * Finds an ordered range of all the org labors where organizationId = &#63;.
421             *
422             * <p>
423             * 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.
424             * </p>
425             *
426             * @param organizationId the organization id to search with
427             * @param start the lower bound of the range of org labors to return
428             * @param end the upper bound of the range of org labors to return (not inclusive)
429             * @param orderByComparator the comparator to order the results by
430             * @return the ordered range of matching org labors
431             * @throws SystemException if a system exception occurred
432             */
433            public List<OrgLabor> findByOrganizationId(long organizationId, int start,
434                    int end, OrderByComparator orderByComparator) throws SystemException {
435                    Object[] finderArgs = new Object[] {
436                                    organizationId,
437                                    
438                                    String.valueOf(start), String.valueOf(end),
439                                    String.valueOf(orderByComparator)
440                            };
441    
442                    List<OrgLabor> list = (List<OrgLabor>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_ORGANIZATIONID,
443                                    finderArgs, this);
444    
445                    if (list == null) {
446                            Session session = null;
447    
448                            try {
449                                    session = openSession();
450    
451                                    StringBundler query = null;
452    
453                                    if (orderByComparator != null) {
454                                            query = new StringBundler(3 +
455                                                            (orderByComparator.getOrderByFields().length * 3));
456                                    }
457                                    else {
458                                            query = new StringBundler(3);
459                                    }
460    
461                                    query.append(_SQL_SELECT_ORGLABOR_WHERE);
462    
463                                    query.append(_FINDER_COLUMN_ORGANIZATIONID_ORGANIZATIONID_2);
464    
465                                    if (orderByComparator != null) {
466                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
467                                                    orderByComparator);
468                                    }
469    
470                                    else {
471                                            query.append(OrgLaborModelImpl.ORDER_BY_JPQL);
472                                    }
473    
474                                    String sql = query.toString();
475    
476                                    Query q = session.createQuery(sql);
477    
478                                    QueryPos qPos = QueryPos.getInstance(q);
479    
480                                    qPos.add(organizationId);
481    
482                                    list = (List<OrgLabor>)QueryUtil.list(q, getDialect(), start,
483                                                    end);
484                            }
485                            catch (Exception e) {
486                                    throw processException(e);
487                            }
488                            finally {
489                                    if (list == null) {
490                                            list = new ArrayList<OrgLabor>();
491                                    }
492    
493                                    cacheResult(list);
494    
495                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_ORGANIZATIONID,
496                                            finderArgs, list);
497    
498                                    closeSession(session);
499                            }
500                    }
501    
502                    return list;
503            }
504    
505            /**
506             * Finds the first org labor in the ordered set where organizationId = &#63;.
507             *
508             * <p>
509             * 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.
510             * </p>
511             *
512             * @param organizationId the organization id to search with
513             * @param orderByComparator the comparator to order the set by
514             * @return the first matching org labor
515             * @throws com.liferay.portal.NoSuchOrgLaborException if a matching org labor could not be found
516             * @throws SystemException if a system exception occurred
517             */
518            public OrgLabor findByOrganizationId_First(long organizationId,
519                    OrderByComparator orderByComparator)
520                    throws NoSuchOrgLaborException, SystemException {
521                    List<OrgLabor> list = findByOrganizationId(organizationId, 0, 1,
522                                    orderByComparator);
523    
524                    if (list.isEmpty()) {
525                            StringBundler msg = new StringBundler(4);
526    
527                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
528    
529                            msg.append("organizationId=");
530                            msg.append(organizationId);
531    
532                            msg.append(StringPool.CLOSE_CURLY_BRACE);
533    
534                            throw new NoSuchOrgLaborException(msg.toString());
535                    }
536                    else {
537                            return list.get(0);
538                    }
539            }
540    
541            /**
542             * Finds the last org labor in the ordered set where organizationId = &#63;.
543             *
544             * <p>
545             * 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.
546             * </p>
547             *
548             * @param organizationId the organization id to search with
549             * @param orderByComparator the comparator to order the set by
550             * @return the last matching org labor
551             * @throws com.liferay.portal.NoSuchOrgLaborException if a matching org labor could not be found
552             * @throws SystemException if a system exception occurred
553             */
554            public OrgLabor findByOrganizationId_Last(long organizationId,
555                    OrderByComparator orderByComparator)
556                    throws NoSuchOrgLaborException, SystemException {
557                    int count = countByOrganizationId(organizationId);
558    
559                    List<OrgLabor> list = findByOrganizationId(organizationId, count - 1,
560                                    count, orderByComparator);
561    
562                    if (list.isEmpty()) {
563                            StringBundler msg = new StringBundler(4);
564    
565                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
566    
567                            msg.append("organizationId=");
568                            msg.append(organizationId);
569    
570                            msg.append(StringPool.CLOSE_CURLY_BRACE);
571    
572                            throw new NoSuchOrgLaborException(msg.toString());
573                    }
574                    else {
575                            return list.get(0);
576                    }
577            }
578    
579            /**
580             * Finds the org labors before and after the current org labor in the ordered set where organizationId = &#63;.
581             *
582             * <p>
583             * 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.
584             * </p>
585             *
586             * @param orgLaborId the primary key of the current org labor
587             * @param organizationId the organization id to search with
588             * @param orderByComparator the comparator to order the set by
589             * @return the previous, current, and next org labor
590             * @throws com.liferay.portal.NoSuchOrgLaborException if a org labor with the primary key could not be found
591             * @throws SystemException if a system exception occurred
592             */
593            public OrgLabor[] findByOrganizationId_PrevAndNext(long orgLaborId,
594                    long organizationId, OrderByComparator orderByComparator)
595                    throws NoSuchOrgLaborException, SystemException {
596                    OrgLabor orgLabor = findByPrimaryKey(orgLaborId);
597    
598                    Session session = null;
599    
600                    try {
601                            session = openSession();
602    
603                            OrgLabor[] array = new OrgLaborImpl[3];
604    
605                            array[0] = getByOrganizationId_PrevAndNext(session, orgLabor,
606                                            organizationId, orderByComparator, true);
607    
608                            array[1] = orgLabor;
609    
610                            array[2] = getByOrganizationId_PrevAndNext(session, orgLabor,
611                                            organizationId, orderByComparator, false);
612    
613                            return array;
614                    }
615                    catch (Exception e) {
616                            throw processException(e);
617                    }
618                    finally {
619                            closeSession(session);
620                    }
621            }
622    
623            protected OrgLabor getByOrganizationId_PrevAndNext(Session session,
624                    OrgLabor orgLabor, long organizationId,
625                    OrderByComparator orderByComparator, boolean previous) {
626                    StringBundler query = null;
627    
628                    if (orderByComparator != null) {
629                            query = new StringBundler(6 +
630                                            (orderByComparator.getOrderByFields().length * 6));
631                    }
632                    else {
633                            query = new StringBundler(3);
634                    }
635    
636                    query.append(_SQL_SELECT_ORGLABOR_WHERE);
637    
638                    query.append(_FINDER_COLUMN_ORGANIZATIONID_ORGANIZATIONID_2);
639    
640                    if (orderByComparator != null) {
641                            String[] orderByFields = orderByComparator.getOrderByFields();
642    
643                            if (orderByFields.length > 0) {
644                                    query.append(WHERE_AND);
645                            }
646    
647                            for (int i = 0; i < orderByFields.length; i++) {
648                                    query.append(_ORDER_BY_ENTITY_ALIAS);
649                                    query.append(orderByFields[i]);
650    
651                                    if ((i + 1) < orderByFields.length) {
652                                            if (orderByComparator.isAscending() ^ previous) {
653                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
654                                            }
655                                            else {
656                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
657                                            }
658                                    }
659                                    else {
660                                            if (orderByComparator.isAscending() ^ previous) {
661                                                    query.append(WHERE_GREATER_THAN);
662                                            }
663                                            else {
664                                                    query.append(WHERE_LESSER_THAN);
665                                            }
666                                    }
667                            }
668    
669                            query.append(ORDER_BY_CLAUSE);
670    
671                            for (int i = 0; i < orderByFields.length; i++) {
672                                    query.append(_ORDER_BY_ENTITY_ALIAS);
673                                    query.append(orderByFields[i]);
674    
675                                    if ((i + 1) < orderByFields.length) {
676                                            if (orderByComparator.isAscending() ^ previous) {
677                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
678                                            }
679                                            else {
680                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
681                                            }
682                                    }
683                                    else {
684                                            if (orderByComparator.isAscending() ^ previous) {
685                                                    query.append(ORDER_BY_ASC);
686                                            }
687                                            else {
688                                                    query.append(ORDER_BY_DESC);
689                                            }
690                                    }
691                            }
692                    }
693    
694                    else {
695                            query.append(OrgLaborModelImpl.ORDER_BY_JPQL);
696                    }
697    
698                    String sql = query.toString();
699    
700                    Query q = session.createQuery(sql);
701    
702                    q.setFirstResult(0);
703                    q.setMaxResults(2);
704    
705                    QueryPos qPos = QueryPos.getInstance(q);
706    
707                    qPos.add(organizationId);
708    
709                    if (orderByComparator != null) {
710                            Object[] values = orderByComparator.getOrderByValues(orgLabor);
711    
712                            for (Object value : values) {
713                                    qPos.add(value);
714                            }
715                    }
716    
717                    List<OrgLabor> list = q.list();
718    
719                    if (list.size() == 2) {
720                            return list.get(1);
721                    }
722                    else {
723                            return null;
724                    }
725            }
726    
727            /**
728             * Finds all the org labors.
729             *
730             * @return the org labors
731             * @throws SystemException if a system exception occurred
732             */
733            public List<OrgLabor> findAll() throws SystemException {
734                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
735            }
736    
737            /**
738             * Finds a range of all the org labors.
739             *
740             * <p>
741             * 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.
742             * </p>
743             *
744             * @param start the lower bound of the range of org labors to return
745             * @param end the upper bound of the range of org labors to return (not inclusive)
746             * @return the range of org labors
747             * @throws SystemException if a system exception occurred
748             */
749            public List<OrgLabor> findAll(int start, int end) throws SystemException {
750                    return findAll(start, end, null);
751            }
752    
753            /**
754             * Finds an ordered range of all the org labors.
755             *
756             * <p>
757             * 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.
758             * </p>
759             *
760             * @param start the lower bound of the range of org labors to return
761             * @param end the upper bound of the range of org labors to return (not inclusive)
762             * @param orderByComparator the comparator to order the results by
763             * @return the ordered range of org labors
764             * @throws SystemException if a system exception occurred
765             */
766            public List<OrgLabor> findAll(int start, int end,
767                    OrderByComparator orderByComparator) throws SystemException {
768                    Object[] finderArgs = new Object[] {
769                                    String.valueOf(start), String.valueOf(end),
770                                    String.valueOf(orderByComparator)
771                            };
772    
773                    List<OrgLabor> list = (List<OrgLabor>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
774                                    finderArgs, this);
775    
776                    if (list == null) {
777                            Session session = null;
778    
779                            try {
780                                    session = openSession();
781    
782                                    StringBundler query = null;
783                                    String sql = null;
784    
785                                    if (orderByComparator != null) {
786                                            query = new StringBundler(2 +
787                                                            (orderByComparator.getOrderByFields().length * 3));
788    
789                                            query.append(_SQL_SELECT_ORGLABOR);
790    
791                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
792                                                    orderByComparator);
793    
794                                            sql = query.toString();
795                                    }
796                                    else {
797                                            sql = _SQL_SELECT_ORGLABOR.concat(OrgLaborModelImpl.ORDER_BY_JPQL);
798                                    }
799    
800                                    Query q = session.createQuery(sql);
801    
802                                    if (orderByComparator == null) {
803                                            list = (List<OrgLabor>)QueryUtil.list(q, getDialect(),
804                                                            start, end, false);
805    
806                                            Collections.sort(list);
807                                    }
808                                    else {
809                                            list = (List<OrgLabor>)QueryUtil.list(q, getDialect(),
810                                                            start, end);
811                                    }
812                            }
813                            catch (Exception e) {
814                                    throw processException(e);
815                            }
816                            finally {
817                                    if (list == null) {
818                                            list = new ArrayList<OrgLabor>();
819                                    }
820    
821                                    cacheResult(list);
822    
823                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
824    
825                                    closeSession(session);
826                            }
827                    }
828    
829                    return list;
830            }
831    
832            /**
833             * Removes all the org labors where organizationId = &#63; from the database.
834             *
835             * @param organizationId the organization id to search with
836             * @throws SystemException if a system exception occurred
837             */
838            public void removeByOrganizationId(long organizationId)
839                    throws SystemException {
840                    for (OrgLabor orgLabor : findByOrganizationId(organizationId)) {
841                            remove(orgLabor);
842                    }
843            }
844    
845            /**
846             * Removes all the org labors from the database.
847             *
848             * @throws SystemException if a system exception occurred
849             */
850            public void removeAll() throws SystemException {
851                    for (OrgLabor orgLabor : findAll()) {
852                            remove(orgLabor);
853                    }
854            }
855    
856            /**
857             * Counts all the org labors where organizationId = &#63;.
858             *
859             * @param organizationId the organization id to search with
860             * @return the number of matching org labors
861             * @throws SystemException if a system exception occurred
862             */
863            public int countByOrganizationId(long organizationId)
864                    throws SystemException {
865                    Object[] finderArgs = new Object[] { organizationId };
866    
867                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ORGANIZATIONID,
868                                    finderArgs, this);
869    
870                    if (count == null) {
871                            Session session = null;
872    
873                            try {
874                                    session = openSession();
875    
876                                    StringBundler query = new StringBundler(2);
877    
878                                    query.append(_SQL_COUNT_ORGLABOR_WHERE);
879    
880                                    query.append(_FINDER_COLUMN_ORGANIZATIONID_ORGANIZATIONID_2);
881    
882                                    String sql = query.toString();
883    
884                                    Query q = session.createQuery(sql);
885    
886                                    QueryPos qPos = QueryPos.getInstance(q);
887    
888                                    qPos.add(organizationId);
889    
890                                    count = (Long)q.uniqueResult();
891                            }
892                            catch (Exception e) {
893                                    throw processException(e);
894                            }
895                            finally {
896                                    if (count == null) {
897                                            count = Long.valueOf(0);
898                                    }
899    
900                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ORGANIZATIONID,
901                                            finderArgs, count);
902    
903                                    closeSession(session);
904                            }
905                    }
906    
907                    return count.intValue();
908            }
909    
910            /**
911             * Counts all the org labors.
912             *
913             * @return the number of org labors
914             * @throws SystemException if a system exception occurred
915             */
916            public int countAll() throws SystemException {
917                    Object[] finderArgs = new Object[0];
918    
919                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
920                                    finderArgs, this);
921    
922                    if (count == null) {
923                            Session session = null;
924    
925                            try {
926                                    session = openSession();
927    
928                                    Query q = session.createQuery(_SQL_COUNT_ORGLABOR);
929    
930                                    count = (Long)q.uniqueResult();
931                            }
932                            catch (Exception e) {
933                                    throw processException(e);
934                            }
935                            finally {
936                                    if (count == null) {
937                                            count = Long.valueOf(0);
938                                    }
939    
940                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
941                                            count);
942    
943                                    closeSession(session);
944                            }
945                    }
946    
947                    return count.intValue();
948            }
949    
950            /**
951             * Initializes the org labor persistence.
952             */
953            public void afterPropertiesSet() {
954                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
955                                            com.liferay.portal.util.PropsUtil.get(
956                                                    "value.object.listener.com.liferay.portal.model.OrgLabor")));
957    
958                    if (listenerClassNames.length > 0) {
959                            try {
960                                    List<ModelListener<OrgLabor>> listenersList = new ArrayList<ModelListener<OrgLabor>>();
961    
962                                    for (String listenerClassName : listenerClassNames) {
963                                            listenersList.add((ModelListener<OrgLabor>)InstanceFactory.newInstance(
964                                                            listenerClassName));
965                                    }
966    
967                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
968                            }
969                            catch (Exception e) {
970                                    _log.error(e);
971                            }
972                    }
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    }