001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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                            Session session = null;
436    
437                            try {
438                                    session = openSession();
439    
440                                    StringBundler query = null;
441    
442                                    if (orderByComparator != null) {
443                                            query = new StringBundler(3 +
444                                                            (orderByComparator.getOrderByFields().length * 3));
445                                    }
446                                    else {
447                                            query = new StringBundler(3);
448                                    }
449    
450                                    query.append(_SQL_SELECT_ORGLABOR_WHERE);
451    
452                                    query.append(_FINDER_COLUMN_ORGANIZATIONID_ORGANIZATIONID_2);
453    
454                                    if (orderByComparator != null) {
455                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
456                                                    orderByComparator);
457                                    }
458    
459                                    else {
460                                            query.append(OrgLaborModelImpl.ORDER_BY_JPQL);
461                                    }
462    
463                                    String sql = query.toString();
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                                            list = new ArrayList<OrgLabor>();
480                                    }
481    
482                                    cacheResult(list);
483    
484                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_ORGANIZATIONID,
485                                            finderArgs, list);
486    
487                                    closeSession(session);
488                            }
489                    }
490    
491                    return list;
492            }
493    
494            /**
495             * Finds the first org labor in the ordered set where organizationId = &#63;.
496             *
497             * <p>
498             * 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.
499             * </p>
500             *
501             * @param organizationId the organization id to search with
502             * @param orderByComparator the comparator to order the set by
503             * @return the first matching org labor
504             * @throws com.liferay.portal.NoSuchOrgLaborException if a matching org labor could not be found
505             * @throws SystemException if a system exception occurred
506             */
507            public OrgLabor findByOrganizationId_First(long organizationId,
508                    OrderByComparator orderByComparator)
509                    throws NoSuchOrgLaborException, SystemException {
510                    List<OrgLabor> list = findByOrganizationId(organizationId, 0, 1,
511                                    orderByComparator);
512    
513                    if (list.isEmpty()) {
514                            StringBundler msg = new StringBundler(4);
515    
516                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
517    
518                            msg.append("organizationId=");
519                            msg.append(organizationId);
520    
521                            msg.append(StringPool.CLOSE_CURLY_BRACE);
522    
523                            throw new NoSuchOrgLaborException(msg.toString());
524                    }
525                    else {
526                            return list.get(0);
527                    }
528            }
529    
530            /**
531             * Finds the last org labor in the ordered set where organizationId = &#63;.
532             *
533             * <p>
534             * 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.
535             * </p>
536             *
537             * @param organizationId the organization id to search with
538             * @param orderByComparator the comparator to order the set by
539             * @return the last matching org labor
540             * @throws com.liferay.portal.NoSuchOrgLaborException if a matching org labor could not be found
541             * @throws SystemException if a system exception occurred
542             */
543            public OrgLabor findByOrganizationId_Last(long organizationId,
544                    OrderByComparator orderByComparator)
545                    throws NoSuchOrgLaborException, SystemException {
546                    int count = countByOrganizationId(organizationId);
547    
548                    List<OrgLabor> list = findByOrganizationId(organizationId, count - 1,
549                                    count, orderByComparator);
550    
551                    if (list.isEmpty()) {
552                            StringBundler msg = new StringBundler(4);
553    
554                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
555    
556                            msg.append("organizationId=");
557                            msg.append(organizationId);
558    
559                            msg.append(StringPool.CLOSE_CURLY_BRACE);
560    
561                            throw new NoSuchOrgLaborException(msg.toString());
562                    }
563                    else {
564                            return list.get(0);
565                    }
566            }
567    
568            /**
569             * Finds the org labors before and after the current org labor in the ordered set where organizationId = &#63;.
570             *
571             * <p>
572             * 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.
573             * </p>
574             *
575             * @param orgLaborId the primary key of the current org labor
576             * @param organizationId the organization id to search with
577             * @param orderByComparator the comparator to order the set by
578             * @return the previous, current, and next org labor
579             * @throws com.liferay.portal.NoSuchOrgLaborException if a org labor with the primary key could not be found
580             * @throws SystemException if a system exception occurred
581             */
582            public OrgLabor[] findByOrganizationId_PrevAndNext(long orgLaborId,
583                    long organizationId, OrderByComparator orderByComparator)
584                    throws NoSuchOrgLaborException, SystemException {
585                    OrgLabor orgLabor = findByPrimaryKey(orgLaborId);
586    
587                    Session session = null;
588    
589                    try {
590                            session = openSession();
591    
592                            OrgLabor[] array = new OrgLaborImpl[3];
593    
594                            array[0] = getByOrganizationId_PrevAndNext(session, orgLabor,
595                                            organizationId, orderByComparator, true);
596    
597                            array[1] = orgLabor;
598    
599                            array[2] = getByOrganizationId_PrevAndNext(session, orgLabor,
600                                            organizationId, orderByComparator, false);
601    
602                            return array;
603                    }
604                    catch (Exception e) {
605                            throw processException(e);
606                    }
607                    finally {
608                            closeSession(session);
609                    }
610            }
611    
612            protected OrgLabor getByOrganizationId_PrevAndNext(Session session,
613                    OrgLabor orgLabor, long organizationId,
614                    OrderByComparator orderByComparator, boolean previous) {
615                    StringBundler query = null;
616    
617                    if (orderByComparator != null) {
618                            query = new StringBundler(6 +
619                                            (orderByComparator.getOrderByFields().length * 6));
620                    }
621                    else {
622                            query = new StringBundler(3);
623                    }
624    
625                    query.append(_SQL_SELECT_ORGLABOR_WHERE);
626    
627                    query.append(_FINDER_COLUMN_ORGANIZATIONID_ORGANIZATIONID_2);
628    
629                    if (orderByComparator != null) {
630                            String[] orderByFields = orderByComparator.getOrderByFields();
631    
632                            if (orderByFields.length > 0) {
633                                    query.append(WHERE_AND);
634                            }
635    
636                            for (int i = 0; i < orderByFields.length; i++) {
637                                    query.append(_ORDER_BY_ENTITY_ALIAS);
638                                    query.append(orderByFields[i]);
639    
640                                    if ((i + 1) < orderByFields.length) {
641                                            if (orderByComparator.isAscending() ^ previous) {
642                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
643                                            }
644                                            else {
645                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
646                                            }
647                                    }
648                                    else {
649                                            if (orderByComparator.isAscending() ^ previous) {
650                                                    query.append(WHERE_GREATER_THAN);
651                                            }
652                                            else {
653                                                    query.append(WHERE_LESSER_THAN);
654                                            }
655                                    }
656                            }
657    
658                            query.append(ORDER_BY_CLAUSE);
659    
660                            for (int i = 0; i < orderByFields.length; i++) {
661                                    query.append(_ORDER_BY_ENTITY_ALIAS);
662                                    query.append(orderByFields[i]);
663    
664                                    if ((i + 1) < orderByFields.length) {
665                                            if (orderByComparator.isAscending() ^ previous) {
666                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
667                                            }
668                                            else {
669                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
670                                            }
671                                    }
672                                    else {
673                                            if (orderByComparator.isAscending() ^ previous) {
674                                                    query.append(ORDER_BY_ASC);
675                                            }
676                                            else {
677                                                    query.append(ORDER_BY_DESC);
678                                            }
679                                    }
680                            }
681                    }
682    
683                    else {
684                            query.append(OrgLaborModelImpl.ORDER_BY_JPQL);
685                    }
686    
687                    String sql = query.toString();
688    
689                    Query q = session.createQuery(sql);
690    
691                    q.setFirstResult(0);
692                    q.setMaxResults(2);
693    
694                    QueryPos qPos = QueryPos.getInstance(q);
695    
696                    qPos.add(organizationId);
697    
698                    if (orderByComparator != null) {
699                            Object[] values = orderByComparator.getOrderByValues(orgLabor);
700    
701                            for (Object value : values) {
702                                    qPos.add(value);
703                            }
704                    }
705    
706                    List<OrgLabor> list = q.list();
707    
708                    if (list.size() == 2) {
709                            return list.get(1);
710                    }
711                    else {
712                            return null;
713                    }
714            }
715    
716            /**
717             * Finds all the org labors.
718             *
719             * @return the org labors
720             * @throws SystemException if a system exception occurred
721             */
722            public List<OrgLabor> findAll() throws SystemException {
723                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
724            }
725    
726            /**
727             * Finds a range of all the org labors.
728             *
729             * <p>
730             * 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.
731             * </p>
732             *
733             * @param start the lower bound of the range of org labors to return
734             * @param end the upper bound of the range of org labors to return (not inclusive)
735             * @return the range of org labors
736             * @throws SystemException if a system exception occurred
737             */
738            public List<OrgLabor> findAll(int start, int end) throws SystemException {
739                    return findAll(start, end, null);
740            }
741    
742            /**
743             * Finds an ordered range of all the org labors.
744             *
745             * <p>
746             * 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.
747             * </p>
748             *
749             * @param start the lower bound of the range of org labors to return
750             * @param end the upper bound of the range of org labors to return (not inclusive)
751             * @param orderByComparator the comparator to order the results by
752             * @return the ordered range of org labors
753             * @throws SystemException if a system exception occurred
754             */
755            public List<OrgLabor> findAll(int start, int end,
756                    OrderByComparator orderByComparator) throws SystemException {
757                    Object[] finderArgs = new Object[] {
758                                    String.valueOf(start), String.valueOf(end),
759                                    String.valueOf(orderByComparator)
760                            };
761    
762                    List<OrgLabor> list = (List<OrgLabor>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
763                                    finderArgs, this);
764    
765                    if (list == null) {
766                            Session session = null;
767    
768                            try {
769                                    session = openSession();
770    
771                                    StringBundler query = null;
772                                    String sql = null;
773    
774                                    if (orderByComparator != null) {
775                                            query = new StringBundler(2 +
776                                                            (orderByComparator.getOrderByFields().length * 3));
777    
778                                            query.append(_SQL_SELECT_ORGLABOR);
779    
780                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
781                                                    orderByComparator);
782    
783                                            sql = query.toString();
784                                    }
785                                    else {
786                                            sql = _SQL_SELECT_ORGLABOR.concat(OrgLaborModelImpl.ORDER_BY_JPQL);
787                                    }
788    
789                                    Query q = session.createQuery(sql);
790    
791                                    if (orderByComparator == null) {
792                                            list = (List<OrgLabor>)QueryUtil.list(q, getDialect(),
793                                                            start, end, false);
794    
795                                            Collections.sort(list);
796                                    }
797                                    else {
798                                            list = (List<OrgLabor>)QueryUtil.list(q, getDialect(),
799                                                            start, end);
800                                    }
801                            }
802                            catch (Exception e) {
803                                    throw processException(e);
804                            }
805                            finally {
806                                    if (list == null) {
807                                            list = new ArrayList<OrgLabor>();
808                                    }
809    
810                                    cacheResult(list);
811    
812                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
813    
814                                    closeSession(session);
815                            }
816                    }
817    
818                    return list;
819            }
820    
821            /**
822             * Removes all the org labors where organizationId = &#63; from the database.
823             *
824             * @param organizationId the organization id to search with
825             * @throws SystemException if a system exception occurred
826             */
827            public void removeByOrganizationId(long organizationId)
828                    throws SystemException {
829                    for (OrgLabor orgLabor : findByOrganizationId(organizationId)) {
830                            remove(orgLabor);
831                    }
832            }
833    
834            /**
835             * Removes all the org labors from the database.
836             *
837             * @throws SystemException if a system exception occurred
838             */
839            public void removeAll() throws SystemException {
840                    for (OrgLabor orgLabor : findAll()) {
841                            remove(orgLabor);
842                    }
843            }
844    
845            /**
846             * Counts all the org labors where organizationId = &#63;.
847             *
848             * @param organizationId the organization id to search with
849             * @return the number of matching org labors
850             * @throws SystemException if a system exception occurred
851             */
852            public int countByOrganizationId(long organizationId)
853                    throws SystemException {
854                    Object[] finderArgs = new Object[] { organizationId };
855    
856                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ORGANIZATIONID,
857                                    finderArgs, this);
858    
859                    if (count == null) {
860                            Session session = null;
861    
862                            try {
863                                    session = openSession();
864    
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                                    Query q = session.createQuery(sql);
874    
875                                    QueryPos qPos = QueryPos.getInstance(q);
876    
877                                    qPos.add(organizationId);
878    
879                                    count = (Long)q.uniqueResult();
880                            }
881                            catch (Exception e) {
882                                    throw processException(e);
883                            }
884                            finally {
885                                    if (count == null) {
886                                            count = Long.valueOf(0);
887                                    }
888    
889                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ORGANIZATIONID,
890                                            finderArgs, count);
891    
892                                    closeSession(session);
893                            }
894                    }
895    
896                    return count.intValue();
897            }
898    
899            /**
900             * Counts all the org labors.
901             *
902             * @return the number of org labors
903             * @throws SystemException if a system exception occurred
904             */
905            public int countAll() throws SystemException {
906                    Object[] finderArgs = new Object[0];
907    
908                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
909                                    finderArgs, this);
910    
911                    if (count == null) {
912                            Session session = null;
913    
914                            try {
915                                    session = openSession();
916    
917                                    Query q = session.createQuery(_SQL_COUNT_ORGLABOR);
918    
919                                    count = (Long)q.uniqueResult();
920                            }
921                            catch (Exception e) {
922                                    throw processException(e);
923                            }
924                            finally {
925                                    if (count == null) {
926                                            count = Long.valueOf(0);
927                                    }
928    
929                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
930                                            count);
931    
932                                    closeSession(session);
933                            }
934                    }
935    
936                    return count.intValue();
937            }
938    
939            /**
940             * Initializes the org labor persistence.
941             */
942            public void afterPropertiesSet() {
943                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
944                                            com.liferay.portal.util.PropsUtil.get(
945                                                    "value.object.listener.com.liferay.portal.model.OrgLabor")));
946    
947                    if (listenerClassNames.length > 0) {
948                            try {
949                                    List<ModelListener<OrgLabor>> listenersList = new ArrayList<ModelListener<OrgLabor>>();
950    
951                                    for (String listenerClassName : listenerClassNames) {
952                                            listenersList.add((ModelListener<OrgLabor>)InstanceFactory.newInstance(
953                                                            listenerClassName));
954                                    }
955    
956                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
957                            }
958                            catch (Exception e) {
959                                    _log.error(e);
960                            }
961                    }
962            }
963    
964            public void destroy() {
965                    EntityCacheUtil.removeCache(OrgLaborImpl.class.getName());
966                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
967                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
968            }
969    
970            @BeanReference(type = AccountPersistence.class)
971            protected AccountPersistence accountPersistence;
972            @BeanReference(type = AddressPersistence.class)
973            protected AddressPersistence addressPersistence;
974            @BeanReference(type = BrowserTrackerPersistence.class)
975            protected BrowserTrackerPersistence browserTrackerPersistence;
976            @BeanReference(type = ClassNamePersistence.class)
977            protected ClassNamePersistence classNamePersistence;
978            @BeanReference(type = ClusterGroupPersistence.class)
979            protected ClusterGroupPersistence clusterGroupPersistence;
980            @BeanReference(type = CompanyPersistence.class)
981            protected CompanyPersistence companyPersistence;
982            @BeanReference(type = ContactPersistence.class)
983            protected ContactPersistence contactPersistence;
984            @BeanReference(type = CountryPersistence.class)
985            protected CountryPersistence countryPersistence;
986            @BeanReference(type = EmailAddressPersistence.class)
987            protected EmailAddressPersistence emailAddressPersistence;
988            @BeanReference(type = GroupPersistence.class)
989            protected GroupPersistence groupPersistence;
990            @BeanReference(type = ImagePersistence.class)
991            protected ImagePersistence imagePersistence;
992            @BeanReference(type = LayoutPersistence.class)
993            protected LayoutPersistence layoutPersistence;
994            @BeanReference(type = LayoutPrototypePersistence.class)
995            protected LayoutPrototypePersistence layoutPrototypePersistence;
996            @BeanReference(type = LayoutSetPersistence.class)
997            protected LayoutSetPersistence layoutSetPersistence;
998            @BeanReference(type = LayoutSetPrototypePersistence.class)
999            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1000            @BeanReference(type = ListTypePersistence.class)
1001            protected ListTypePersistence listTypePersistence;
1002            @BeanReference(type = LockPersistence.class)
1003            protected LockPersistence lockPersistence;
1004            @BeanReference(type = MembershipRequestPersistence.class)
1005            protected MembershipRequestPersistence membershipRequestPersistence;
1006            @BeanReference(type = OrganizationPersistence.class)
1007            protected OrganizationPersistence organizationPersistence;
1008            @BeanReference(type = OrgGroupPermissionPersistence.class)
1009            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1010            @BeanReference(type = OrgGroupRolePersistence.class)
1011            protected OrgGroupRolePersistence orgGroupRolePersistence;
1012            @BeanReference(type = OrgLaborPersistence.class)
1013            protected OrgLaborPersistence orgLaborPersistence;
1014            @BeanReference(type = PasswordPolicyPersistence.class)
1015            protected PasswordPolicyPersistence passwordPolicyPersistence;
1016            @BeanReference(type = PasswordPolicyRelPersistence.class)
1017            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1018            @BeanReference(type = PasswordTrackerPersistence.class)
1019            protected PasswordTrackerPersistence passwordTrackerPersistence;
1020            @BeanReference(type = PermissionPersistence.class)
1021            protected PermissionPersistence permissionPersistence;
1022            @BeanReference(type = PhonePersistence.class)
1023            protected PhonePersistence phonePersistence;
1024            @BeanReference(type = PluginSettingPersistence.class)
1025            protected PluginSettingPersistence pluginSettingPersistence;
1026            @BeanReference(type = PortletPersistence.class)
1027            protected PortletPersistence portletPersistence;
1028            @BeanReference(type = PortletItemPersistence.class)
1029            protected PortletItemPersistence portletItemPersistence;
1030            @BeanReference(type = PortletPreferencesPersistence.class)
1031            protected PortletPreferencesPersistence portletPreferencesPersistence;
1032            @BeanReference(type = RegionPersistence.class)
1033            protected RegionPersistence regionPersistence;
1034            @BeanReference(type = ReleasePersistence.class)
1035            protected ReleasePersistence releasePersistence;
1036            @BeanReference(type = ResourcePersistence.class)
1037            protected ResourcePersistence resourcePersistence;
1038            @BeanReference(type = ResourceActionPersistence.class)
1039            protected ResourceActionPersistence resourceActionPersistence;
1040            @BeanReference(type = ResourceCodePersistence.class)
1041            protected ResourceCodePersistence resourceCodePersistence;
1042            @BeanReference(type = ResourcePermissionPersistence.class)
1043            protected ResourcePermissionPersistence resourcePermissionPersistence;
1044            @BeanReference(type = RolePersistence.class)
1045            protected RolePersistence rolePersistence;
1046            @BeanReference(type = ServiceComponentPersistence.class)
1047            protected ServiceComponentPersistence serviceComponentPersistence;
1048            @BeanReference(type = ShardPersistence.class)
1049            protected ShardPersistence shardPersistence;
1050            @BeanReference(type = SubscriptionPersistence.class)
1051            protected SubscriptionPersistence subscriptionPersistence;
1052            @BeanReference(type = TicketPersistence.class)
1053            protected TicketPersistence ticketPersistence;
1054            @BeanReference(type = TeamPersistence.class)
1055            protected TeamPersistence teamPersistence;
1056            @BeanReference(type = UserPersistence.class)
1057            protected UserPersistence userPersistence;
1058            @BeanReference(type = UserGroupPersistence.class)
1059            protected UserGroupPersistence userGroupPersistence;
1060            @BeanReference(type = UserGroupGroupRolePersistence.class)
1061            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1062            @BeanReference(type = UserGroupRolePersistence.class)
1063            protected UserGroupRolePersistence userGroupRolePersistence;
1064            @BeanReference(type = UserIdMapperPersistence.class)
1065            protected UserIdMapperPersistence userIdMapperPersistence;
1066            @BeanReference(type = UserTrackerPersistence.class)
1067            protected UserTrackerPersistence userTrackerPersistence;
1068            @BeanReference(type = UserTrackerPathPersistence.class)
1069            protected UserTrackerPathPersistence userTrackerPathPersistence;
1070            @BeanReference(type = WebDAVPropsPersistence.class)
1071            protected WebDAVPropsPersistence webDAVPropsPersistence;
1072            @BeanReference(type = WebsitePersistence.class)
1073            protected WebsitePersistence websitePersistence;
1074            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1075            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1076            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1077            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1078            private static final String _SQL_SELECT_ORGLABOR = "SELECT orgLabor FROM OrgLabor orgLabor";
1079            private static final String _SQL_SELECT_ORGLABOR_WHERE = "SELECT orgLabor FROM OrgLabor orgLabor WHERE ";
1080            private static final String _SQL_COUNT_ORGLABOR = "SELECT COUNT(orgLabor) FROM OrgLabor orgLabor";
1081            private static final String _SQL_COUNT_ORGLABOR_WHERE = "SELECT COUNT(orgLabor) FROM OrgLabor orgLabor WHERE ";
1082            private static final String _FINDER_COLUMN_ORGANIZATIONID_ORGANIZATIONID_2 = "orgLabor.organizationId = ?";
1083            private static final String _ORDER_BY_ENTITY_ALIAS = "orgLabor.";
1084            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No OrgLabor exists with the primary key ";
1085            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No OrgLabor exists with the key {";
1086            private static Log _log = LogFactoryUtil.getLog(OrgLaborPersistenceImpl.class);
1087    }