001    /**
002     * Copyright (c) 2000-2013 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.NoSuchLockException;
018    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderPath;
022    import com.liferay.portal.kernel.dao.orm.Query;
023    import com.liferay.portal.kernel.dao.orm.QueryPos;
024    import com.liferay.portal.kernel.dao.orm.QueryUtil;
025    import com.liferay.portal.kernel.dao.orm.Session;
026    import com.liferay.portal.kernel.exception.SystemException;
027    import com.liferay.portal.kernel.log.Log;
028    import com.liferay.portal.kernel.log.LogFactoryUtil;
029    import com.liferay.portal.kernel.util.CalendarUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.SetUtil;
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.kernel.util.UnmodifiableList;
038    import com.liferay.portal.kernel.util.Validator;
039    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
040    import com.liferay.portal.model.CacheModel;
041    import com.liferay.portal.model.Lock;
042    import com.liferay.portal.model.ModelListener;
043    import com.liferay.portal.model.impl.LockImpl;
044    import com.liferay.portal.model.impl.LockModelImpl;
045    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
046    
047    import java.io.Serializable;
048    
049    import java.util.ArrayList;
050    import java.util.Collections;
051    import java.util.Date;
052    import java.util.List;
053    import java.util.Set;
054    
055    /**
056     * The persistence implementation for the lock service.
057     *
058     * <p>
059     * Caching information and settings can be found in <code>portal.properties</code>
060     * </p>
061     *
062     * @author Brian Wing Shun Chan
063     * @see LockPersistence
064     * @see LockUtil
065     * @generated
066     */
067    public class LockPersistenceImpl extends BasePersistenceImpl<Lock>
068            implements LockPersistence {
069            /*
070             * NOTE FOR DEVELOPERS:
071             *
072             * Never modify or reference this class directly. Always use {@link LockUtil} to access the lock persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
073             */
074            public static final String FINDER_CLASS_NAME_ENTITY = LockImpl.class.getName();
075            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076                    ".List1";
077            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
078                    ".List2";
079            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
080                            LockModelImpl.FINDER_CACHE_ENABLED, LockImpl.class,
081                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
082            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
083                            LockModelImpl.FINDER_CACHE_ENABLED, LockImpl.class,
084                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
085            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
086                            LockModelImpl.FINDER_CACHE_ENABLED, Long.class,
087                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
088            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
089                            LockModelImpl.FINDER_CACHE_ENABLED, LockImpl.class,
090                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
091                            new String[] {
092                                    String.class.getName(),
093                                    
094                            Integer.class.getName(), Integer.class.getName(),
095                                    OrderByComparator.class.getName()
096                            });
097            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
098                            LockModelImpl.FINDER_CACHE_ENABLED, LockImpl.class,
099                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
100                            new String[] { String.class.getName() },
101                            LockModelImpl.UUID_COLUMN_BITMASK);
102            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
103                            LockModelImpl.FINDER_CACHE_ENABLED, Long.class,
104                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
105                            new String[] { String.class.getName() });
106    
107            /**
108             * Returns all the locks where uuid = &#63;.
109             *
110             * @param uuid the uuid
111             * @return the matching locks
112             * @throws SystemException if a system exception occurred
113             */
114            @Override
115            public List<Lock> findByUuid(String uuid) throws SystemException {
116                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
117            }
118    
119            /**
120             * Returns a range of all the locks where uuid = &#63;.
121             *
122             * <p>
123             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.LockModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
124             * </p>
125             *
126             * @param uuid the uuid
127             * @param start the lower bound of the range of locks
128             * @param end the upper bound of the range of locks (not inclusive)
129             * @return the range of matching locks
130             * @throws SystemException if a system exception occurred
131             */
132            @Override
133            public List<Lock> findByUuid(String uuid, int start, int end)
134                    throws SystemException {
135                    return findByUuid(uuid, start, end, null);
136            }
137    
138            /**
139             * Returns an ordered range of all the locks where uuid = &#63;.
140             *
141             * <p>
142             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.LockModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
143             * </p>
144             *
145             * @param uuid the uuid
146             * @param start the lower bound of the range of locks
147             * @param end the upper bound of the range of locks (not inclusive)
148             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
149             * @return the ordered range of matching locks
150             * @throws SystemException if a system exception occurred
151             */
152            @Override
153            public List<Lock> findByUuid(String uuid, int start, int end,
154                    OrderByComparator orderByComparator) throws SystemException {
155                    boolean pagination = true;
156                    FinderPath finderPath = null;
157                    Object[] finderArgs = null;
158    
159                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
160                                    (orderByComparator == null)) {
161                            pagination = false;
162                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
163                            finderArgs = new Object[] { uuid };
164                    }
165                    else {
166                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
167                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
168                    }
169    
170                    List<Lock> list = (List<Lock>)FinderCacheUtil.getResult(finderPath,
171                                    finderArgs, this);
172    
173                    if ((list != null) && !list.isEmpty()) {
174                            for (Lock lock : list) {
175                                    if (!Validator.equals(uuid, lock.getUuid())) {
176                                            list = null;
177    
178                                            break;
179                                    }
180                            }
181                    }
182    
183                    if (list == null) {
184                            StringBundler query = null;
185    
186                            if (orderByComparator != null) {
187                                    query = new StringBundler(3 +
188                                                    (orderByComparator.getOrderByFields().length * 3));
189                            }
190                            else {
191                                    query = new StringBundler(3);
192                            }
193    
194                            query.append(_SQL_SELECT_LOCK_WHERE);
195    
196                            boolean bindUuid = false;
197    
198                            if (uuid == null) {
199                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
200                            }
201                            else if (uuid.equals(StringPool.BLANK)) {
202                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
203                            }
204                            else {
205                                    bindUuid = true;
206    
207                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
208                            }
209    
210                            if (orderByComparator != null) {
211                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
212                                            orderByComparator);
213                            }
214                            else
215                             if (pagination) {
216                                    query.append(LockModelImpl.ORDER_BY_JPQL);
217                            }
218    
219                            String sql = query.toString();
220    
221                            Session session = null;
222    
223                            try {
224                                    session = openSession();
225    
226                                    Query q = session.createQuery(sql);
227    
228                                    QueryPos qPos = QueryPos.getInstance(q);
229    
230                                    if (bindUuid) {
231                                            qPos.add(uuid);
232                                    }
233    
234                                    if (!pagination) {
235                                            list = (List<Lock>)QueryUtil.list(q, getDialect(), start,
236                                                            end, false);
237    
238                                            Collections.sort(list);
239    
240                                            list = new UnmodifiableList<Lock>(list);
241                                    }
242                                    else {
243                                            list = (List<Lock>)QueryUtil.list(q, getDialect(), start,
244                                                            end);
245                                    }
246    
247                                    cacheResult(list);
248    
249                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
250                            }
251                            catch (Exception e) {
252                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
253    
254                                    throw processException(e);
255                            }
256                            finally {
257                                    closeSession(session);
258                            }
259                    }
260    
261                    return list;
262            }
263    
264            /**
265             * Returns the first lock in the ordered set where uuid = &#63;.
266             *
267             * @param uuid the uuid
268             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
269             * @return the first matching lock
270             * @throws com.liferay.portal.NoSuchLockException if a matching lock could not be found
271             * @throws SystemException if a system exception occurred
272             */
273            @Override
274            public Lock findByUuid_First(String uuid,
275                    OrderByComparator orderByComparator)
276                    throws NoSuchLockException, SystemException {
277                    Lock lock = fetchByUuid_First(uuid, orderByComparator);
278    
279                    if (lock != null) {
280                            return lock;
281                    }
282    
283                    StringBundler msg = new StringBundler(4);
284    
285                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
286    
287                    msg.append("uuid=");
288                    msg.append(uuid);
289    
290                    msg.append(StringPool.CLOSE_CURLY_BRACE);
291    
292                    throw new NoSuchLockException(msg.toString());
293            }
294    
295            /**
296             * Returns the first lock in the ordered set where uuid = &#63;.
297             *
298             * @param uuid the uuid
299             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
300             * @return the first matching lock, or <code>null</code> if a matching lock could not be found
301             * @throws SystemException if a system exception occurred
302             */
303            @Override
304            public Lock fetchByUuid_First(String uuid,
305                    OrderByComparator orderByComparator) throws SystemException {
306                    List<Lock> list = findByUuid(uuid, 0, 1, orderByComparator);
307    
308                    if (!list.isEmpty()) {
309                            return list.get(0);
310                    }
311    
312                    return null;
313            }
314    
315            /**
316             * Returns the last lock in the ordered set where uuid = &#63;.
317             *
318             * @param uuid the uuid
319             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
320             * @return the last matching lock
321             * @throws com.liferay.portal.NoSuchLockException if a matching lock could not be found
322             * @throws SystemException if a system exception occurred
323             */
324            @Override
325            public Lock findByUuid_Last(String uuid, OrderByComparator orderByComparator)
326                    throws NoSuchLockException, SystemException {
327                    Lock lock = fetchByUuid_Last(uuid, orderByComparator);
328    
329                    if (lock != null) {
330                            return lock;
331                    }
332    
333                    StringBundler msg = new StringBundler(4);
334    
335                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
336    
337                    msg.append("uuid=");
338                    msg.append(uuid);
339    
340                    msg.append(StringPool.CLOSE_CURLY_BRACE);
341    
342                    throw new NoSuchLockException(msg.toString());
343            }
344    
345            /**
346             * Returns the last lock in the ordered set where uuid = &#63;.
347             *
348             * @param uuid the uuid
349             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
350             * @return the last matching lock, or <code>null</code> if a matching lock could not be found
351             * @throws SystemException if a system exception occurred
352             */
353            @Override
354            public Lock fetchByUuid_Last(String uuid,
355                    OrderByComparator orderByComparator) throws SystemException {
356                    int count = countByUuid(uuid);
357    
358                    if (count == 0) {
359                            return null;
360                    }
361    
362                    List<Lock> list = findByUuid(uuid, count - 1, count, orderByComparator);
363    
364                    if (!list.isEmpty()) {
365                            return list.get(0);
366                    }
367    
368                    return null;
369            }
370    
371            /**
372             * Returns the locks before and after the current lock in the ordered set where uuid = &#63;.
373             *
374             * @param lockId the primary key of the current lock
375             * @param uuid the uuid
376             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
377             * @return the previous, current, and next lock
378             * @throws com.liferay.portal.NoSuchLockException if a lock with the primary key could not be found
379             * @throws SystemException if a system exception occurred
380             */
381            @Override
382            public Lock[] findByUuid_PrevAndNext(long lockId, String uuid,
383                    OrderByComparator orderByComparator)
384                    throws NoSuchLockException, SystemException {
385                    Lock lock = findByPrimaryKey(lockId);
386    
387                    Session session = null;
388    
389                    try {
390                            session = openSession();
391    
392                            Lock[] array = new LockImpl[3];
393    
394                            array[0] = getByUuid_PrevAndNext(session, lock, uuid,
395                                            orderByComparator, true);
396    
397                            array[1] = lock;
398    
399                            array[2] = getByUuid_PrevAndNext(session, lock, uuid,
400                                            orderByComparator, false);
401    
402                            return array;
403                    }
404                    catch (Exception e) {
405                            throw processException(e);
406                    }
407                    finally {
408                            closeSession(session);
409                    }
410            }
411    
412            protected Lock getByUuid_PrevAndNext(Session session, Lock lock,
413                    String uuid, OrderByComparator orderByComparator, boolean previous) {
414                    StringBundler query = null;
415    
416                    if (orderByComparator != null) {
417                            query = new StringBundler(6 +
418                                            (orderByComparator.getOrderByFields().length * 6));
419                    }
420                    else {
421                            query = new StringBundler(3);
422                    }
423    
424                    query.append(_SQL_SELECT_LOCK_WHERE);
425    
426                    boolean bindUuid = false;
427    
428                    if (uuid == null) {
429                            query.append(_FINDER_COLUMN_UUID_UUID_1);
430                    }
431                    else if (uuid.equals(StringPool.BLANK)) {
432                            query.append(_FINDER_COLUMN_UUID_UUID_3);
433                    }
434                    else {
435                            bindUuid = true;
436    
437                            query.append(_FINDER_COLUMN_UUID_UUID_2);
438                    }
439    
440                    if (orderByComparator != null) {
441                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
442    
443                            if (orderByConditionFields.length > 0) {
444                                    query.append(WHERE_AND);
445                            }
446    
447                            for (int i = 0; i < orderByConditionFields.length; i++) {
448                                    query.append(_ORDER_BY_ENTITY_ALIAS);
449                                    query.append(orderByConditionFields[i]);
450    
451                                    if ((i + 1) < orderByConditionFields.length) {
452                                            if (orderByComparator.isAscending() ^ previous) {
453                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
454                                            }
455                                            else {
456                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
457                                            }
458                                    }
459                                    else {
460                                            if (orderByComparator.isAscending() ^ previous) {
461                                                    query.append(WHERE_GREATER_THAN);
462                                            }
463                                            else {
464                                                    query.append(WHERE_LESSER_THAN);
465                                            }
466                                    }
467                            }
468    
469                            query.append(ORDER_BY_CLAUSE);
470    
471                            String[] orderByFields = orderByComparator.getOrderByFields();
472    
473                            for (int i = 0; i < orderByFields.length; i++) {
474                                    query.append(_ORDER_BY_ENTITY_ALIAS);
475                                    query.append(orderByFields[i]);
476    
477                                    if ((i + 1) < orderByFields.length) {
478                                            if (orderByComparator.isAscending() ^ previous) {
479                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
480                                            }
481                                            else {
482                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
483                                            }
484                                    }
485                                    else {
486                                            if (orderByComparator.isAscending() ^ previous) {
487                                                    query.append(ORDER_BY_ASC);
488                                            }
489                                            else {
490                                                    query.append(ORDER_BY_DESC);
491                                            }
492                                    }
493                            }
494                    }
495                    else {
496                            query.append(LockModelImpl.ORDER_BY_JPQL);
497                    }
498    
499                    String sql = query.toString();
500    
501                    Query q = session.createQuery(sql);
502    
503                    q.setFirstResult(0);
504                    q.setMaxResults(2);
505    
506                    QueryPos qPos = QueryPos.getInstance(q);
507    
508                    if (bindUuid) {
509                            qPos.add(uuid);
510                    }
511    
512                    if (orderByComparator != null) {
513                            Object[] values = orderByComparator.getOrderByConditionValues(lock);
514    
515                            for (Object value : values) {
516                                    qPos.add(value);
517                            }
518                    }
519    
520                    List<Lock> list = q.list();
521    
522                    if (list.size() == 2) {
523                            return list.get(1);
524                    }
525                    else {
526                            return null;
527                    }
528            }
529    
530            /**
531             * Removes all the locks where uuid = &#63; from the database.
532             *
533             * @param uuid the uuid
534             * @throws SystemException if a system exception occurred
535             */
536            @Override
537            public void removeByUuid(String uuid) throws SystemException {
538                    for (Lock lock : findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
539                                    null)) {
540                            remove(lock);
541                    }
542            }
543    
544            /**
545             * Returns the number of locks where uuid = &#63;.
546             *
547             * @param uuid the uuid
548             * @return the number of matching locks
549             * @throws SystemException if a system exception occurred
550             */
551            @Override
552            public int countByUuid(String uuid) throws SystemException {
553                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
554    
555                    Object[] finderArgs = new Object[] { uuid };
556    
557                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
558                                    this);
559    
560                    if (count == null) {
561                            StringBundler query = new StringBundler(2);
562    
563                            query.append(_SQL_COUNT_LOCK_WHERE);
564    
565                            boolean bindUuid = false;
566    
567                            if (uuid == null) {
568                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
569                            }
570                            else if (uuid.equals(StringPool.BLANK)) {
571                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
572                            }
573                            else {
574                                    bindUuid = true;
575    
576                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
577                            }
578    
579                            String sql = query.toString();
580    
581                            Session session = null;
582    
583                            try {
584                                    session = openSession();
585    
586                                    Query q = session.createQuery(sql);
587    
588                                    QueryPos qPos = QueryPos.getInstance(q);
589    
590                                    if (bindUuid) {
591                                            qPos.add(uuid);
592                                    }
593    
594                                    count = (Long)q.uniqueResult();
595    
596                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
597                            }
598                            catch (Exception e) {
599                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
600    
601                                    throw processException(e);
602                            }
603                            finally {
604                                    closeSession(session);
605                            }
606                    }
607    
608                    return count.intValue();
609            }
610    
611            private static final String _FINDER_COLUMN_UUID_UUID_1 = "lock.uuid IS NULL";
612            private static final String _FINDER_COLUMN_UUID_UUID_2 = "lock.uuid = ?";
613            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(lock.uuid IS NULL OR lock.uuid = '')";
614            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
615                            LockModelImpl.FINDER_CACHE_ENABLED, LockImpl.class,
616                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
617                            new String[] {
618                                    String.class.getName(), Long.class.getName(),
619                                    
620                            Integer.class.getName(), Integer.class.getName(),
621                                    OrderByComparator.class.getName()
622                            });
623            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
624                    new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
625                            LockModelImpl.FINDER_CACHE_ENABLED, LockImpl.class,
626                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
627                            new String[] { String.class.getName(), Long.class.getName() },
628                            LockModelImpl.UUID_COLUMN_BITMASK |
629                            LockModelImpl.COMPANYID_COLUMN_BITMASK);
630            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
631                            LockModelImpl.FINDER_CACHE_ENABLED, Long.class,
632                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
633                            new String[] { String.class.getName(), Long.class.getName() });
634    
635            /**
636             * Returns all the locks where uuid = &#63; and companyId = &#63;.
637             *
638             * @param uuid the uuid
639             * @param companyId the company ID
640             * @return the matching locks
641             * @throws SystemException if a system exception occurred
642             */
643            @Override
644            public List<Lock> findByUuid_C(String uuid, long companyId)
645                    throws SystemException {
646                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
647                            QueryUtil.ALL_POS, null);
648            }
649    
650            /**
651             * Returns a range of all the locks where uuid = &#63; and companyId = &#63;.
652             *
653             * <p>
654             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.LockModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
655             * </p>
656             *
657             * @param uuid the uuid
658             * @param companyId the company ID
659             * @param start the lower bound of the range of locks
660             * @param end the upper bound of the range of locks (not inclusive)
661             * @return the range of matching locks
662             * @throws SystemException if a system exception occurred
663             */
664            @Override
665            public List<Lock> findByUuid_C(String uuid, long companyId, int start,
666                    int end) throws SystemException {
667                    return findByUuid_C(uuid, companyId, start, end, null);
668            }
669    
670            /**
671             * Returns an ordered range of all the locks where uuid = &#63; and companyId = &#63;.
672             *
673             * <p>
674             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.LockModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
675             * </p>
676             *
677             * @param uuid the uuid
678             * @param companyId the company ID
679             * @param start the lower bound of the range of locks
680             * @param end the upper bound of the range of locks (not inclusive)
681             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
682             * @return the ordered range of matching locks
683             * @throws SystemException if a system exception occurred
684             */
685            @Override
686            public List<Lock> findByUuid_C(String uuid, long companyId, int start,
687                    int end, OrderByComparator orderByComparator) throws SystemException {
688                    boolean pagination = true;
689                    FinderPath finderPath = null;
690                    Object[] finderArgs = null;
691    
692                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
693                                    (orderByComparator == null)) {
694                            pagination = false;
695                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
696                            finderArgs = new Object[] { uuid, companyId };
697                    }
698                    else {
699                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
700                            finderArgs = new Object[] {
701                                            uuid, companyId,
702                                            
703                                            start, end, orderByComparator
704                                    };
705                    }
706    
707                    List<Lock> list = (List<Lock>)FinderCacheUtil.getResult(finderPath,
708                                    finderArgs, this);
709    
710                    if ((list != null) && !list.isEmpty()) {
711                            for (Lock lock : list) {
712                                    if (!Validator.equals(uuid, lock.getUuid()) ||
713                                                    (companyId != lock.getCompanyId())) {
714                                            list = null;
715    
716                                            break;
717                                    }
718                            }
719                    }
720    
721                    if (list == null) {
722                            StringBundler query = null;
723    
724                            if (orderByComparator != null) {
725                                    query = new StringBundler(4 +
726                                                    (orderByComparator.getOrderByFields().length * 3));
727                            }
728                            else {
729                                    query = new StringBundler(4);
730                            }
731    
732                            query.append(_SQL_SELECT_LOCK_WHERE);
733    
734                            boolean bindUuid = false;
735    
736                            if (uuid == null) {
737                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
738                            }
739                            else if (uuid.equals(StringPool.BLANK)) {
740                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
741                            }
742                            else {
743                                    bindUuid = true;
744    
745                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
746                            }
747    
748                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
749    
750                            if (orderByComparator != null) {
751                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
752                                            orderByComparator);
753                            }
754                            else
755                             if (pagination) {
756                                    query.append(LockModelImpl.ORDER_BY_JPQL);
757                            }
758    
759                            String sql = query.toString();
760    
761                            Session session = null;
762    
763                            try {
764                                    session = openSession();
765    
766                                    Query q = session.createQuery(sql);
767    
768                                    QueryPos qPos = QueryPos.getInstance(q);
769    
770                                    if (bindUuid) {
771                                            qPos.add(uuid);
772                                    }
773    
774                                    qPos.add(companyId);
775    
776                                    if (!pagination) {
777                                            list = (List<Lock>)QueryUtil.list(q, getDialect(), start,
778                                                            end, false);
779    
780                                            Collections.sort(list);
781    
782                                            list = new UnmodifiableList<Lock>(list);
783                                    }
784                                    else {
785                                            list = (List<Lock>)QueryUtil.list(q, getDialect(), start,
786                                                            end);
787                                    }
788    
789                                    cacheResult(list);
790    
791                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
792                            }
793                            catch (Exception e) {
794                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
795    
796                                    throw processException(e);
797                            }
798                            finally {
799                                    closeSession(session);
800                            }
801                    }
802    
803                    return list;
804            }
805    
806            /**
807             * Returns the first lock in the ordered set where uuid = &#63; and companyId = &#63;.
808             *
809             * @param uuid the uuid
810             * @param companyId the company ID
811             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
812             * @return the first matching lock
813             * @throws com.liferay.portal.NoSuchLockException if a matching lock could not be found
814             * @throws SystemException if a system exception occurred
815             */
816            @Override
817            public Lock findByUuid_C_First(String uuid, long companyId,
818                    OrderByComparator orderByComparator)
819                    throws NoSuchLockException, SystemException {
820                    Lock lock = fetchByUuid_C_First(uuid, companyId, orderByComparator);
821    
822                    if (lock != null) {
823                            return lock;
824                    }
825    
826                    StringBundler msg = new StringBundler(6);
827    
828                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
829    
830                    msg.append("uuid=");
831                    msg.append(uuid);
832    
833                    msg.append(", companyId=");
834                    msg.append(companyId);
835    
836                    msg.append(StringPool.CLOSE_CURLY_BRACE);
837    
838                    throw new NoSuchLockException(msg.toString());
839            }
840    
841            /**
842             * Returns the first lock in the ordered set where uuid = &#63; and companyId = &#63;.
843             *
844             * @param uuid the uuid
845             * @param companyId the company ID
846             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
847             * @return the first matching lock, or <code>null</code> if a matching lock could not be found
848             * @throws SystemException if a system exception occurred
849             */
850            @Override
851            public Lock fetchByUuid_C_First(String uuid, long companyId,
852                    OrderByComparator orderByComparator) throws SystemException {
853                    List<Lock> list = findByUuid_C(uuid, companyId, 0, 1, orderByComparator);
854    
855                    if (!list.isEmpty()) {
856                            return list.get(0);
857                    }
858    
859                    return null;
860            }
861    
862            /**
863             * Returns the last lock in the ordered set where uuid = &#63; and companyId = &#63;.
864             *
865             * @param uuid the uuid
866             * @param companyId the company ID
867             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
868             * @return the last matching lock
869             * @throws com.liferay.portal.NoSuchLockException if a matching lock could not be found
870             * @throws SystemException if a system exception occurred
871             */
872            @Override
873            public Lock findByUuid_C_Last(String uuid, long companyId,
874                    OrderByComparator orderByComparator)
875                    throws NoSuchLockException, SystemException {
876                    Lock lock = fetchByUuid_C_Last(uuid, companyId, orderByComparator);
877    
878                    if (lock != null) {
879                            return lock;
880                    }
881    
882                    StringBundler msg = new StringBundler(6);
883    
884                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
885    
886                    msg.append("uuid=");
887                    msg.append(uuid);
888    
889                    msg.append(", companyId=");
890                    msg.append(companyId);
891    
892                    msg.append(StringPool.CLOSE_CURLY_BRACE);
893    
894                    throw new NoSuchLockException(msg.toString());
895            }
896    
897            /**
898             * Returns the last lock in the ordered set where uuid = &#63; and companyId = &#63;.
899             *
900             * @param uuid the uuid
901             * @param companyId the company ID
902             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
903             * @return the last matching lock, or <code>null</code> if a matching lock could not be found
904             * @throws SystemException if a system exception occurred
905             */
906            @Override
907            public Lock fetchByUuid_C_Last(String uuid, long companyId,
908                    OrderByComparator orderByComparator) throws SystemException {
909                    int count = countByUuid_C(uuid, companyId);
910    
911                    if (count == 0) {
912                            return null;
913                    }
914    
915                    List<Lock> list = findByUuid_C(uuid, companyId, count - 1, count,
916                                    orderByComparator);
917    
918                    if (!list.isEmpty()) {
919                            return list.get(0);
920                    }
921    
922                    return null;
923            }
924    
925            /**
926             * Returns the locks before and after the current lock in the ordered set where uuid = &#63; and companyId = &#63;.
927             *
928             * @param lockId the primary key of the current lock
929             * @param uuid the uuid
930             * @param companyId the company ID
931             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
932             * @return the previous, current, and next lock
933             * @throws com.liferay.portal.NoSuchLockException if a lock with the primary key could not be found
934             * @throws SystemException if a system exception occurred
935             */
936            @Override
937            public Lock[] findByUuid_C_PrevAndNext(long lockId, String uuid,
938                    long companyId, OrderByComparator orderByComparator)
939                    throws NoSuchLockException, SystemException {
940                    Lock lock = findByPrimaryKey(lockId);
941    
942                    Session session = null;
943    
944                    try {
945                            session = openSession();
946    
947                            Lock[] array = new LockImpl[3];
948    
949                            array[0] = getByUuid_C_PrevAndNext(session, lock, uuid, companyId,
950                                            orderByComparator, true);
951    
952                            array[1] = lock;
953    
954                            array[2] = getByUuid_C_PrevAndNext(session, lock, uuid, companyId,
955                                            orderByComparator, false);
956    
957                            return array;
958                    }
959                    catch (Exception e) {
960                            throw processException(e);
961                    }
962                    finally {
963                            closeSession(session);
964                    }
965            }
966    
967            protected Lock getByUuid_C_PrevAndNext(Session session, Lock lock,
968                    String uuid, long companyId, OrderByComparator orderByComparator,
969                    boolean previous) {
970                    StringBundler query = null;
971    
972                    if (orderByComparator != null) {
973                            query = new StringBundler(6 +
974                                            (orderByComparator.getOrderByFields().length * 6));
975                    }
976                    else {
977                            query = new StringBundler(3);
978                    }
979    
980                    query.append(_SQL_SELECT_LOCK_WHERE);
981    
982                    boolean bindUuid = false;
983    
984                    if (uuid == null) {
985                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
986                    }
987                    else if (uuid.equals(StringPool.BLANK)) {
988                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
989                    }
990                    else {
991                            bindUuid = true;
992    
993                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
994                    }
995    
996                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
997    
998                    if (orderByComparator != null) {
999                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1000    
1001                            if (orderByConditionFields.length > 0) {
1002                                    query.append(WHERE_AND);
1003                            }
1004    
1005                            for (int i = 0; i < orderByConditionFields.length; i++) {
1006                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1007                                    query.append(orderByConditionFields[i]);
1008    
1009                                    if ((i + 1) < orderByConditionFields.length) {
1010                                            if (orderByComparator.isAscending() ^ previous) {
1011                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1012                                            }
1013                                            else {
1014                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1015                                            }
1016                                    }
1017                                    else {
1018                                            if (orderByComparator.isAscending() ^ previous) {
1019                                                    query.append(WHERE_GREATER_THAN);
1020                                            }
1021                                            else {
1022                                                    query.append(WHERE_LESSER_THAN);
1023                                            }
1024                                    }
1025                            }
1026    
1027                            query.append(ORDER_BY_CLAUSE);
1028    
1029                            String[] orderByFields = orderByComparator.getOrderByFields();
1030    
1031                            for (int i = 0; i < orderByFields.length; i++) {
1032                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1033                                    query.append(orderByFields[i]);
1034    
1035                                    if ((i + 1) < orderByFields.length) {
1036                                            if (orderByComparator.isAscending() ^ previous) {
1037                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1038                                            }
1039                                            else {
1040                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1041                                            }
1042                                    }
1043                                    else {
1044                                            if (orderByComparator.isAscending() ^ previous) {
1045                                                    query.append(ORDER_BY_ASC);
1046                                            }
1047                                            else {
1048                                                    query.append(ORDER_BY_DESC);
1049                                            }
1050                                    }
1051                            }
1052                    }
1053                    else {
1054                            query.append(LockModelImpl.ORDER_BY_JPQL);
1055                    }
1056    
1057                    String sql = query.toString();
1058    
1059                    Query q = session.createQuery(sql);
1060    
1061                    q.setFirstResult(0);
1062                    q.setMaxResults(2);
1063    
1064                    QueryPos qPos = QueryPos.getInstance(q);
1065    
1066                    if (bindUuid) {
1067                            qPos.add(uuid);
1068                    }
1069    
1070                    qPos.add(companyId);
1071    
1072                    if (orderByComparator != null) {
1073                            Object[] values = orderByComparator.getOrderByConditionValues(lock);
1074    
1075                            for (Object value : values) {
1076                                    qPos.add(value);
1077                            }
1078                    }
1079    
1080                    List<Lock> list = q.list();
1081    
1082                    if (list.size() == 2) {
1083                            return list.get(1);
1084                    }
1085                    else {
1086                            return null;
1087                    }
1088            }
1089    
1090            /**
1091             * Removes all the locks where uuid = &#63; and companyId = &#63; from the database.
1092             *
1093             * @param uuid the uuid
1094             * @param companyId the company ID
1095             * @throws SystemException if a system exception occurred
1096             */
1097            @Override
1098            public void removeByUuid_C(String uuid, long companyId)
1099                    throws SystemException {
1100                    for (Lock lock : findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1101                                    QueryUtil.ALL_POS, null)) {
1102                            remove(lock);
1103                    }
1104            }
1105    
1106            /**
1107             * Returns the number of locks where uuid = &#63; and companyId = &#63;.
1108             *
1109             * @param uuid the uuid
1110             * @param companyId the company ID
1111             * @return the number of matching locks
1112             * @throws SystemException if a system exception occurred
1113             */
1114            @Override
1115            public int countByUuid_C(String uuid, long companyId)
1116                    throws SystemException {
1117                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1118    
1119                    Object[] finderArgs = new Object[] { uuid, companyId };
1120    
1121                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1122                                    this);
1123    
1124                    if (count == null) {
1125                            StringBundler query = new StringBundler(3);
1126    
1127                            query.append(_SQL_COUNT_LOCK_WHERE);
1128    
1129                            boolean bindUuid = false;
1130    
1131                            if (uuid == null) {
1132                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1133                            }
1134                            else if (uuid.equals(StringPool.BLANK)) {
1135                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1136                            }
1137                            else {
1138                                    bindUuid = true;
1139    
1140                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1141                            }
1142    
1143                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1144    
1145                            String sql = query.toString();
1146    
1147                            Session session = null;
1148    
1149                            try {
1150                                    session = openSession();
1151    
1152                                    Query q = session.createQuery(sql);
1153    
1154                                    QueryPos qPos = QueryPos.getInstance(q);
1155    
1156                                    if (bindUuid) {
1157                                            qPos.add(uuid);
1158                                    }
1159    
1160                                    qPos.add(companyId);
1161    
1162                                    count = (Long)q.uniqueResult();
1163    
1164                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1165                            }
1166                            catch (Exception e) {
1167                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1168    
1169                                    throw processException(e);
1170                            }
1171                            finally {
1172                                    closeSession(session);
1173                            }
1174                    }
1175    
1176                    return count.intValue();
1177            }
1178    
1179            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "lock.uuid IS NULL AND ";
1180            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "lock.uuid = ? AND ";
1181            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(lock.uuid IS NULL OR lock.uuid = '') AND ";
1182            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "lock.companyId = ?";
1183            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_LTEXPIRATIONDATE =
1184                    new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
1185                            LockModelImpl.FINDER_CACHE_ENABLED, LockImpl.class,
1186                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByLtExpirationDate",
1187                            new String[] {
1188                                    Date.class.getName(),
1189                                    
1190                            Integer.class.getName(), Integer.class.getName(),
1191                                    OrderByComparator.class.getName()
1192                            });
1193            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_LTEXPIRATIONDATE =
1194                    new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
1195                            LockModelImpl.FINDER_CACHE_ENABLED, Long.class,
1196                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByLtExpirationDate",
1197                            new String[] { Date.class.getName() });
1198    
1199            /**
1200             * Returns all the locks where expirationDate &lt; &#63;.
1201             *
1202             * @param expirationDate the expiration date
1203             * @return the matching locks
1204             * @throws SystemException if a system exception occurred
1205             */
1206            @Override
1207            public List<Lock> findByLtExpirationDate(Date expirationDate)
1208                    throws SystemException {
1209                    return findByLtExpirationDate(expirationDate, QueryUtil.ALL_POS,
1210                            QueryUtil.ALL_POS, null);
1211            }
1212    
1213            /**
1214             * Returns a range of all the locks where expirationDate &lt; &#63;.
1215             *
1216             * <p>
1217             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.LockModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1218             * </p>
1219             *
1220             * @param expirationDate the expiration date
1221             * @param start the lower bound of the range of locks
1222             * @param end the upper bound of the range of locks (not inclusive)
1223             * @return the range of matching locks
1224             * @throws SystemException if a system exception occurred
1225             */
1226            @Override
1227            public List<Lock> findByLtExpirationDate(Date expirationDate, int start,
1228                    int end) throws SystemException {
1229                    return findByLtExpirationDate(expirationDate, start, end, null);
1230            }
1231    
1232            /**
1233             * Returns an ordered range of all the locks where expirationDate &lt; &#63;.
1234             *
1235             * <p>
1236             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.LockModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1237             * </p>
1238             *
1239             * @param expirationDate the expiration date
1240             * @param start the lower bound of the range of locks
1241             * @param end the upper bound of the range of locks (not inclusive)
1242             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1243             * @return the ordered range of matching locks
1244             * @throws SystemException if a system exception occurred
1245             */
1246            @Override
1247            public List<Lock> findByLtExpirationDate(Date expirationDate, int start,
1248                    int end, OrderByComparator orderByComparator) throws SystemException {
1249                    boolean pagination = true;
1250                    FinderPath finderPath = null;
1251                    Object[] finderArgs = null;
1252    
1253                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_LTEXPIRATIONDATE;
1254                    finderArgs = new Object[] { expirationDate, start, end, orderByComparator };
1255    
1256                    List<Lock> list = (List<Lock>)FinderCacheUtil.getResult(finderPath,
1257                                    finderArgs, this);
1258    
1259                    if ((list != null) && !list.isEmpty()) {
1260                            for (Lock lock : list) {
1261                                    if (!Validator.equals(expirationDate, lock.getExpirationDate())) {
1262                                            list = null;
1263    
1264                                            break;
1265                                    }
1266                            }
1267                    }
1268    
1269                    if (list == null) {
1270                            StringBundler query = null;
1271    
1272                            if (orderByComparator != null) {
1273                                    query = new StringBundler(3 +
1274                                                    (orderByComparator.getOrderByFields().length * 3));
1275                            }
1276                            else {
1277                                    query = new StringBundler(3);
1278                            }
1279    
1280                            query.append(_SQL_SELECT_LOCK_WHERE);
1281    
1282                            boolean bindExpirationDate = false;
1283    
1284                            if (expirationDate == null) {
1285                                    query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_1);
1286                            }
1287                            else {
1288                                    bindExpirationDate = true;
1289    
1290                                    query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_2);
1291                            }
1292    
1293                            if (orderByComparator != null) {
1294                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1295                                            orderByComparator);
1296                            }
1297                            else
1298                             if (pagination) {
1299                                    query.append(LockModelImpl.ORDER_BY_JPQL);
1300                            }
1301    
1302                            String sql = query.toString();
1303    
1304                            Session session = null;
1305    
1306                            try {
1307                                    session = openSession();
1308    
1309                                    Query q = session.createQuery(sql);
1310    
1311                                    QueryPos qPos = QueryPos.getInstance(q);
1312    
1313                                    if (bindExpirationDate) {
1314                                            qPos.add(CalendarUtil.getTimestamp(expirationDate));
1315                                    }
1316    
1317                                    if (!pagination) {
1318                                            list = (List<Lock>)QueryUtil.list(q, getDialect(), start,
1319                                                            end, false);
1320    
1321                                            Collections.sort(list);
1322    
1323                                            list = new UnmodifiableList<Lock>(list);
1324                                    }
1325                                    else {
1326                                            list = (List<Lock>)QueryUtil.list(q, getDialect(), start,
1327                                                            end);
1328                                    }
1329    
1330                                    cacheResult(list);
1331    
1332                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1333                            }
1334                            catch (Exception e) {
1335                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1336    
1337                                    throw processException(e);
1338                            }
1339                            finally {
1340                                    closeSession(session);
1341                            }
1342                    }
1343    
1344                    return list;
1345            }
1346    
1347            /**
1348             * Returns the first lock in the ordered set where expirationDate &lt; &#63;.
1349             *
1350             * @param expirationDate the expiration date
1351             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1352             * @return the first matching lock
1353             * @throws com.liferay.portal.NoSuchLockException if a matching lock could not be found
1354             * @throws SystemException if a system exception occurred
1355             */
1356            @Override
1357            public Lock findByLtExpirationDate_First(Date expirationDate,
1358                    OrderByComparator orderByComparator)
1359                    throws NoSuchLockException, SystemException {
1360                    Lock lock = fetchByLtExpirationDate_First(expirationDate,
1361                                    orderByComparator);
1362    
1363                    if (lock != null) {
1364                            return lock;
1365                    }
1366    
1367                    StringBundler msg = new StringBundler(4);
1368    
1369                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1370    
1371                    msg.append("expirationDate=");
1372                    msg.append(expirationDate);
1373    
1374                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1375    
1376                    throw new NoSuchLockException(msg.toString());
1377            }
1378    
1379            /**
1380             * Returns the first lock in the ordered set where expirationDate &lt; &#63;.
1381             *
1382             * @param expirationDate the expiration date
1383             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1384             * @return the first matching lock, or <code>null</code> if a matching lock could not be found
1385             * @throws SystemException if a system exception occurred
1386             */
1387            @Override
1388            public Lock fetchByLtExpirationDate_First(Date expirationDate,
1389                    OrderByComparator orderByComparator) throws SystemException {
1390                    List<Lock> list = findByLtExpirationDate(expirationDate, 0, 1,
1391                                    orderByComparator);
1392    
1393                    if (!list.isEmpty()) {
1394                            return list.get(0);
1395                    }
1396    
1397                    return null;
1398            }
1399    
1400            /**
1401             * Returns the last lock in the ordered set where expirationDate &lt; &#63;.
1402             *
1403             * @param expirationDate the expiration date
1404             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1405             * @return the last matching lock
1406             * @throws com.liferay.portal.NoSuchLockException if a matching lock could not be found
1407             * @throws SystemException if a system exception occurred
1408             */
1409            @Override
1410            public Lock findByLtExpirationDate_Last(Date expirationDate,
1411                    OrderByComparator orderByComparator)
1412                    throws NoSuchLockException, SystemException {
1413                    Lock lock = fetchByLtExpirationDate_Last(expirationDate,
1414                                    orderByComparator);
1415    
1416                    if (lock != null) {
1417                            return lock;
1418                    }
1419    
1420                    StringBundler msg = new StringBundler(4);
1421    
1422                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1423    
1424                    msg.append("expirationDate=");
1425                    msg.append(expirationDate);
1426    
1427                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1428    
1429                    throw new NoSuchLockException(msg.toString());
1430            }
1431    
1432            /**
1433             * Returns the last lock in the ordered set where expirationDate &lt; &#63;.
1434             *
1435             * @param expirationDate the expiration date
1436             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1437             * @return the last matching lock, or <code>null</code> if a matching lock could not be found
1438             * @throws SystemException if a system exception occurred
1439             */
1440            @Override
1441            public Lock fetchByLtExpirationDate_Last(Date expirationDate,
1442                    OrderByComparator orderByComparator) throws SystemException {
1443                    int count = countByLtExpirationDate(expirationDate);
1444    
1445                    if (count == 0) {
1446                            return null;
1447                    }
1448    
1449                    List<Lock> list = findByLtExpirationDate(expirationDate, count - 1,
1450                                    count, orderByComparator);
1451    
1452                    if (!list.isEmpty()) {
1453                            return list.get(0);
1454                    }
1455    
1456                    return null;
1457            }
1458    
1459            /**
1460             * Returns the locks before and after the current lock in the ordered set where expirationDate &lt; &#63;.
1461             *
1462             * @param lockId the primary key of the current lock
1463             * @param expirationDate the expiration date
1464             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1465             * @return the previous, current, and next lock
1466             * @throws com.liferay.portal.NoSuchLockException if a lock with the primary key could not be found
1467             * @throws SystemException if a system exception occurred
1468             */
1469            @Override
1470            public Lock[] findByLtExpirationDate_PrevAndNext(long lockId,
1471                    Date expirationDate, OrderByComparator orderByComparator)
1472                    throws NoSuchLockException, SystemException {
1473                    Lock lock = findByPrimaryKey(lockId);
1474    
1475                    Session session = null;
1476    
1477                    try {
1478                            session = openSession();
1479    
1480                            Lock[] array = new LockImpl[3];
1481    
1482                            array[0] = getByLtExpirationDate_PrevAndNext(session, lock,
1483                                            expirationDate, orderByComparator, true);
1484    
1485                            array[1] = lock;
1486    
1487                            array[2] = getByLtExpirationDate_PrevAndNext(session, lock,
1488                                            expirationDate, orderByComparator, false);
1489    
1490                            return array;
1491                    }
1492                    catch (Exception e) {
1493                            throw processException(e);
1494                    }
1495                    finally {
1496                            closeSession(session);
1497                    }
1498            }
1499    
1500            protected Lock getByLtExpirationDate_PrevAndNext(Session session,
1501                    Lock lock, Date expirationDate, OrderByComparator orderByComparator,
1502                    boolean previous) {
1503                    StringBundler query = null;
1504    
1505                    if (orderByComparator != null) {
1506                            query = new StringBundler(6 +
1507                                            (orderByComparator.getOrderByFields().length * 6));
1508                    }
1509                    else {
1510                            query = new StringBundler(3);
1511                    }
1512    
1513                    query.append(_SQL_SELECT_LOCK_WHERE);
1514    
1515                    boolean bindExpirationDate = false;
1516    
1517                    if (expirationDate == null) {
1518                            query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_1);
1519                    }
1520                    else {
1521                            bindExpirationDate = true;
1522    
1523                            query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_2);
1524                    }
1525    
1526                    if (orderByComparator != null) {
1527                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1528    
1529                            if (orderByConditionFields.length > 0) {
1530                                    query.append(WHERE_AND);
1531                            }
1532    
1533                            for (int i = 0; i < orderByConditionFields.length; i++) {
1534                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1535                                    query.append(orderByConditionFields[i]);
1536    
1537                                    if ((i + 1) < orderByConditionFields.length) {
1538                                            if (orderByComparator.isAscending() ^ previous) {
1539                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1540                                            }
1541                                            else {
1542                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1543                                            }
1544                                    }
1545                                    else {
1546                                            if (orderByComparator.isAscending() ^ previous) {
1547                                                    query.append(WHERE_GREATER_THAN);
1548                                            }
1549                                            else {
1550                                                    query.append(WHERE_LESSER_THAN);
1551                                            }
1552                                    }
1553                            }
1554    
1555                            query.append(ORDER_BY_CLAUSE);
1556    
1557                            String[] orderByFields = orderByComparator.getOrderByFields();
1558    
1559                            for (int i = 0; i < orderByFields.length; i++) {
1560                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1561                                    query.append(orderByFields[i]);
1562    
1563                                    if ((i + 1) < orderByFields.length) {
1564                                            if (orderByComparator.isAscending() ^ previous) {
1565                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1566                                            }
1567                                            else {
1568                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1569                                            }
1570                                    }
1571                                    else {
1572                                            if (orderByComparator.isAscending() ^ previous) {
1573                                                    query.append(ORDER_BY_ASC);
1574                                            }
1575                                            else {
1576                                                    query.append(ORDER_BY_DESC);
1577                                            }
1578                                    }
1579                            }
1580                    }
1581                    else {
1582                            query.append(LockModelImpl.ORDER_BY_JPQL);
1583                    }
1584    
1585                    String sql = query.toString();
1586    
1587                    Query q = session.createQuery(sql);
1588    
1589                    q.setFirstResult(0);
1590                    q.setMaxResults(2);
1591    
1592                    QueryPos qPos = QueryPos.getInstance(q);
1593    
1594                    if (bindExpirationDate) {
1595                            qPos.add(CalendarUtil.getTimestamp(expirationDate));
1596                    }
1597    
1598                    if (orderByComparator != null) {
1599                            Object[] values = orderByComparator.getOrderByConditionValues(lock);
1600    
1601                            for (Object value : values) {
1602                                    qPos.add(value);
1603                            }
1604                    }
1605    
1606                    List<Lock> list = q.list();
1607    
1608                    if (list.size() == 2) {
1609                            return list.get(1);
1610                    }
1611                    else {
1612                            return null;
1613                    }
1614            }
1615    
1616            /**
1617             * Removes all the locks where expirationDate &lt; &#63; from the database.
1618             *
1619             * @param expirationDate the expiration date
1620             * @throws SystemException if a system exception occurred
1621             */
1622            @Override
1623            public void removeByLtExpirationDate(Date expirationDate)
1624                    throws SystemException {
1625                    for (Lock lock : findByLtExpirationDate(expirationDate,
1626                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1627                            remove(lock);
1628                    }
1629            }
1630    
1631            /**
1632             * Returns the number of locks where expirationDate &lt; &#63;.
1633             *
1634             * @param expirationDate the expiration date
1635             * @return the number of matching locks
1636             * @throws SystemException if a system exception occurred
1637             */
1638            @Override
1639            public int countByLtExpirationDate(Date expirationDate)
1640                    throws SystemException {
1641                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_LTEXPIRATIONDATE;
1642    
1643                    Object[] finderArgs = new Object[] { expirationDate };
1644    
1645                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1646                                    this);
1647    
1648                    if (count == null) {
1649                            StringBundler query = new StringBundler(2);
1650    
1651                            query.append(_SQL_COUNT_LOCK_WHERE);
1652    
1653                            boolean bindExpirationDate = false;
1654    
1655                            if (expirationDate == null) {
1656                                    query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_1);
1657                            }
1658                            else {
1659                                    bindExpirationDate = true;
1660    
1661                                    query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_2);
1662                            }
1663    
1664                            String sql = query.toString();
1665    
1666                            Session session = null;
1667    
1668                            try {
1669                                    session = openSession();
1670    
1671                                    Query q = session.createQuery(sql);
1672    
1673                                    QueryPos qPos = QueryPos.getInstance(q);
1674    
1675                                    if (bindExpirationDate) {
1676                                            qPos.add(CalendarUtil.getTimestamp(expirationDate));
1677                                    }
1678    
1679                                    count = (Long)q.uniqueResult();
1680    
1681                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1682                            }
1683                            catch (Exception e) {
1684                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1685    
1686                                    throw processException(e);
1687                            }
1688                            finally {
1689                                    closeSession(session);
1690                            }
1691                    }
1692    
1693                    return count.intValue();
1694            }
1695    
1696            private static final String _FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_1 =
1697                    "lock.expirationDate < NULL";
1698            private static final String _FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_2 =
1699                    "lock.expirationDate < ?";
1700            public static final FinderPath FINDER_PATH_FETCH_BY_C_K = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
1701                            LockModelImpl.FINDER_CACHE_ENABLED, LockImpl.class,
1702                            FINDER_CLASS_NAME_ENTITY, "fetchByC_K",
1703                            new String[] { String.class.getName(), String.class.getName() },
1704                            LockModelImpl.CLASSNAME_COLUMN_BITMASK |
1705                            LockModelImpl.KEY_COLUMN_BITMASK);
1706            public static final FinderPath FINDER_PATH_COUNT_BY_C_K = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
1707                            LockModelImpl.FINDER_CACHE_ENABLED, Long.class,
1708                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_K",
1709                            new String[] { String.class.getName(), String.class.getName() });
1710    
1711            /**
1712             * Returns the lock where className = &#63; and key = &#63; or throws a {@link com.liferay.portal.NoSuchLockException} if it could not be found.
1713             *
1714             * @param className the class name
1715             * @param key the key
1716             * @return the matching lock
1717             * @throws com.liferay.portal.NoSuchLockException if a matching lock could not be found
1718             * @throws SystemException if a system exception occurred
1719             */
1720            @Override
1721            public Lock findByC_K(String className, String key)
1722                    throws NoSuchLockException, SystemException {
1723                    Lock lock = fetchByC_K(className, key);
1724    
1725                    if (lock == null) {
1726                            StringBundler msg = new StringBundler(6);
1727    
1728                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1729    
1730                            msg.append("className=");
1731                            msg.append(className);
1732    
1733                            msg.append(", key=");
1734                            msg.append(key);
1735    
1736                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1737    
1738                            if (_log.isWarnEnabled()) {
1739                                    _log.warn(msg.toString());
1740                            }
1741    
1742                            throw new NoSuchLockException(msg.toString());
1743                    }
1744    
1745                    return lock;
1746            }
1747    
1748            /**
1749             * Returns the lock where className = &#63; and key = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1750             *
1751             * @param className the class name
1752             * @param key the key
1753             * @return the matching lock, or <code>null</code> if a matching lock could not be found
1754             * @throws SystemException if a system exception occurred
1755             */
1756            @Override
1757            public Lock fetchByC_K(String className, String key)
1758                    throws SystemException {
1759                    return fetchByC_K(className, key, true);
1760            }
1761    
1762            /**
1763             * Returns the lock where className = &#63; and key = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1764             *
1765             * @param className the class name
1766             * @param key the key
1767             * @param retrieveFromCache whether to use the finder cache
1768             * @return the matching lock, or <code>null</code> if a matching lock could not be found
1769             * @throws SystemException if a system exception occurred
1770             */
1771            @Override
1772            public Lock fetchByC_K(String className, String key,
1773                    boolean retrieveFromCache) throws SystemException {
1774                    Object[] finderArgs = new Object[] { className, key };
1775    
1776                    Object result = null;
1777    
1778                    if (retrieveFromCache) {
1779                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_K,
1780                                            finderArgs, this);
1781                    }
1782    
1783                    if (result instanceof Lock) {
1784                            Lock lock = (Lock)result;
1785    
1786                            if (!Validator.equals(className, lock.getClassName()) ||
1787                                            !Validator.equals(key, lock.getKey())) {
1788                                    result = null;
1789                            }
1790                    }
1791    
1792                    if (result == null) {
1793                            StringBundler query = new StringBundler(4);
1794    
1795                            query.append(_SQL_SELECT_LOCK_WHERE);
1796    
1797                            boolean bindClassName = false;
1798    
1799                            if (className == null) {
1800                                    query.append(_FINDER_COLUMN_C_K_CLASSNAME_1);
1801                            }
1802                            else if (className.equals(StringPool.BLANK)) {
1803                                    query.append(_FINDER_COLUMN_C_K_CLASSNAME_3);
1804                            }
1805                            else {
1806                                    bindClassName = true;
1807    
1808                                    query.append(_FINDER_COLUMN_C_K_CLASSNAME_2);
1809                            }
1810    
1811                            boolean bindKey = false;
1812    
1813                            if (key == null) {
1814                                    query.append(_FINDER_COLUMN_C_K_KEY_1);
1815                            }
1816                            else if (key.equals(StringPool.BLANK)) {
1817                                    query.append(_FINDER_COLUMN_C_K_KEY_3);
1818                            }
1819                            else {
1820                                    bindKey = true;
1821    
1822                                    query.append(_FINDER_COLUMN_C_K_KEY_2);
1823                            }
1824    
1825                            String sql = query.toString();
1826    
1827                            Session session = null;
1828    
1829                            try {
1830                                    session = openSession();
1831    
1832                                    Query q = session.createQuery(sql);
1833    
1834                                    QueryPos qPos = QueryPos.getInstance(q);
1835    
1836                                    if (bindClassName) {
1837                                            qPos.add(className);
1838                                    }
1839    
1840                                    if (bindKey) {
1841                                            qPos.add(key);
1842                                    }
1843    
1844                                    List<Lock> list = q.list();
1845    
1846                                    if (list.isEmpty()) {
1847                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K,
1848                                                    finderArgs, list);
1849                                    }
1850                                    else {
1851                                            Lock lock = list.get(0);
1852    
1853                                            result = lock;
1854    
1855                                            cacheResult(lock);
1856    
1857                                            if ((lock.getClassName() == null) ||
1858                                                            !lock.getClassName().equals(className) ||
1859                                                            (lock.getKey() == null) ||
1860                                                            !lock.getKey().equals(key)) {
1861                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K,
1862                                                            finderArgs, lock);
1863                                            }
1864                                    }
1865                            }
1866                            catch (Exception e) {
1867                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_K,
1868                                            finderArgs);
1869    
1870                                    throw processException(e);
1871                            }
1872                            finally {
1873                                    closeSession(session);
1874                            }
1875                    }
1876    
1877                    if (result instanceof List<?>) {
1878                            return null;
1879                    }
1880                    else {
1881                            return (Lock)result;
1882                    }
1883            }
1884    
1885            /**
1886             * Removes the lock where className = &#63; and key = &#63; from the database.
1887             *
1888             * @param className the class name
1889             * @param key the key
1890             * @return the lock that was removed
1891             * @throws SystemException if a system exception occurred
1892             */
1893            @Override
1894            public Lock removeByC_K(String className, String key)
1895                    throws NoSuchLockException, SystemException {
1896                    Lock lock = findByC_K(className, key);
1897    
1898                    return remove(lock);
1899            }
1900    
1901            /**
1902             * Returns the number of locks where className = &#63; and key = &#63;.
1903             *
1904             * @param className the class name
1905             * @param key the key
1906             * @return the number of matching locks
1907             * @throws SystemException if a system exception occurred
1908             */
1909            @Override
1910            public int countByC_K(String className, String key)
1911                    throws SystemException {
1912                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_K;
1913    
1914                    Object[] finderArgs = new Object[] { className, key };
1915    
1916                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1917                                    this);
1918    
1919                    if (count == null) {
1920                            StringBundler query = new StringBundler(3);
1921    
1922                            query.append(_SQL_COUNT_LOCK_WHERE);
1923    
1924                            boolean bindClassName = false;
1925    
1926                            if (className == null) {
1927                                    query.append(_FINDER_COLUMN_C_K_CLASSNAME_1);
1928                            }
1929                            else if (className.equals(StringPool.BLANK)) {
1930                                    query.append(_FINDER_COLUMN_C_K_CLASSNAME_3);
1931                            }
1932                            else {
1933                                    bindClassName = true;
1934    
1935                                    query.append(_FINDER_COLUMN_C_K_CLASSNAME_2);
1936                            }
1937    
1938                            boolean bindKey = false;
1939    
1940                            if (key == null) {
1941                                    query.append(_FINDER_COLUMN_C_K_KEY_1);
1942                            }
1943                            else if (key.equals(StringPool.BLANK)) {
1944                                    query.append(_FINDER_COLUMN_C_K_KEY_3);
1945                            }
1946                            else {
1947                                    bindKey = true;
1948    
1949                                    query.append(_FINDER_COLUMN_C_K_KEY_2);
1950                            }
1951    
1952                            String sql = query.toString();
1953    
1954                            Session session = null;
1955    
1956                            try {
1957                                    session = openSession();
1958    
1959                                    Query q = session.createQuery(sql);
1960    
1961                                    QueryPos qPos = QueryPos.getInstance(q);
1962    
1963                                    if (bindClassName) {
1964                                            qPos.add(className);
1965                                    }
1966    
1967                                    if (bindKey) {
1968                                            qPos.add(key);
1969                                    }
1970    
1971                                    count = (Long)q.uniqueResult();
1972    
1973                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1974                            }
1975                            catch (Exception e) {
1976                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1977    
1978                                    throw processException(e);
1979                            }
1980                            finally {
1981                                    closeSession(session);
1982                            }
1983                    }
1984    
1985                    return count.intValue();
1986            }
1987    
1988            private static final String _FINDER_COLUMN_C_K_CLASSNAME_1 = "lock.className IS NULL AND ";
1989            private static final String _FINDER_COLUMN_C_K_CLASSNAME_2 = "lock.className = ? AND ";
1990            private static final String _FINDER_COLUMN_C_K_CLASSNAME_3 = "(lock.className IS NULL OR lock.className = '') AND ";
1991            private static final String _FINDER_COLUMN_C_K_KEY_1 = "lock.key IS NULL";
1992            private static final String _FINDER_COLUMN_C_K_KEY_2 = "lock.key = ?";
1993            private static final String _FINDER_COLUMN_C_K_KEY_3 = "(lock.key IS NULL OR lock.key = '')";
1994    
1995            public LockPersistenceImpl() {
1996                    setModelClass(Lock.class);
1997            }
1998    
1999            /**
2000             * Caches the lock in the entity cache if it is enabled.
2001             *
2002             * @param lock the lock
2003             */
2004            @Override
2005            public void cacheResult(Lock lock) {
2006                    EntityCacheUtil.putResult(LockModelImpl.ENTITY_CACHE_ENABLED,
2007                            LockImpl.class, lock.getPrimaryKey(), lock);
2008    
2009                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K,
2010                            new Object[] { lock.getClassName(), lock.getKey() }, lock);
2011    
2012                    lock.resetOriginalValues();
2013            }
2014    
2015            /**
2016             * Caches the locks in the entity cache if it is enabled.
2017             *
2018             * @param locks the locks
2019             */
2020            @Override
2021            public void cacheResult(List<Lock> locks) {
2022                    for (Lock lock : locks) {
2023                            if (EntityCacheUtil.getResult(LockModelImpl.ENTITY_CACHE_ENABLED,
2024                                                    LockImpl.class, lock.getPrimaryKey()) == null) {
2025                                    cacheResult(lock);
2026                            }
2027                            else {
2028                                    lock.resetOriginalValues();
2029                            }
2030                    }
2031            }
2032    
2033            /**
2034             * Clears the cache for all locks.
2035             *
2036             * <p>
2037             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2038             * </p>
2039             */
2040            @Override
2041            public void clearCache() {
2042                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
2043                            CacheRegistryUtil.clear(LockImpl.class.getName());
2044                    }
2045    
2046                    EntityCacheUtil.clearCache(LockImpl.class.getName());
2047    
2048                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2049                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2050                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2051            }
2052    
2053            /**
2054             * Clears the cache for the lock.
2055             *
2056             * <p>
2057             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2058             * </p>
2059             */
2060            @Override
2061            public void clearCache(Lock lock) {
2062                    EntityCacheUtil.removeResult(LockModelImpl.ENTITY_CACHE_ENABLED,
2063                            LockImpl.class, lock.getPrimaryKey());
2064    
2065                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2066                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2067    
2068                    clearUniqueFindersCache(lock);
2069            }
2070    
2071            @Override
2072            public void clearCache(List<Lock> locks) {
2073                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2074                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2075    
2076                    for (Lock lock : locks) {
2077                            EntityCacheUtil.removeResult(LockModelImpl.ENTITY_CACHE_ENABLED,
2078                                    LockImpl.class, lock.getPrimaryKey());
2079    
2080                            clearUniqueFindersCache(lock);
2081                    }
2082            }
2083    
2084            protected void cacheUniqueFindersCache(Lock lock) {
2085                    if (lock.isNew()) {
2086                            Object[] args = new Object[] { lock.getClassName(), lock.getKey() };
2087    
2088                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_K, args,
2089                                    Long.valueOf(1));
2090                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K, args, lock);
2091                    }
2092                    else {
2093                            LockModelImpl lockModelImpl = (LockModelImpl)lock;
2094    
2095                            if ((lockModelImpl.getColumnBitmask() &
2096                                            FINDER_PATH_FETCH_BY_C_K.getColumnBitmask()) != 0) {
2097                                    Object[] args = new Object[] { lock.getClassName(), lock.getKey() };
2098    
2099                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_K, args,
2100                                            Long.valueOf(1));
2101                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K, args, lock);
2102                            }
2103                    }
2104            }
2105    
2106            protected void clearUniqueFindersCache(Lock lock) {
2107                    LockModelImpl lockModelImpl = (LockModelImpl)lock;
2108    
2109                    Object[] args = new Object[] { lock.getClassName(), lock.getKey() };
2110    
2111                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_K, args);
2112                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_K, args);
2113    
2114                    if ((lockModelImpl.getColumnBitmask() &
2115                                    FINDER_PATH_FETCH_BY_C_K.getColumnBitmask()) != 0) {
2116                            args = new Object[] {
2117                                            lockModelImpl.getOriginalClassName(),
2118                                            lockModelImpl.getOriginalKey()
2119                                    };
2120    
2121                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_K, args);
2122                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_K, args);
2123                    }
2124            }
2125    
2126            /**
2127             * Creates a new lock with the primary key. Does not add the lock to the database.
2128             *
2129             * @param lockId the primary key for the new lock
2130             * @return the new lock
2131             */
2132            @Override
2133            public Lock create(long lockId) {
2134                    Lock lock = new LockImpl();
2135    
2136                    lock.setNew(true);
2137                    lock.setPrimaryKey(lockId);
2138    
2139                    String uuid = PortalUUIDUtil.generate();
2140    
2141                    lock.setUuid(uuid);
2142    
2143                    return lock;
2144            }
2145    
2146            /**
2147             * Removes the lock with the primary key from the database. Also notifies the appropriate model listeners.
2148             *
2149             * @param lockId the primary key of the lock
2150             * @return the lock that was removed
2151             * @throws com.liferay.portal.NoSuchLockException if a lock with the primary key could not be found
2152             * @throws SystemException if a system exception occurred
2153             */
2154            @Override
2155            public Lock remove(long lockId) throws NoSuchLockException, SystemException {
2156                    return remove((Serializable)lockId);
2157            }
2158    
2159            /**
2160             * Removes the lock with the primary key from the database. Also notifies the appropriate model listeners.
2161             *
2162             * @param primaryKey the primary key of the lock
2163             * @return the lock that was removed
2164             * @throws com.liferay.portal.NoSuchLockException if a lock with the primary key could not be found
2165             * @throws SystemException if a system exception occurred
2166             */
2167            @Override
2168            public Lock remove(Serializable primaryKey)
2169                    throws NoSuchLockException, SystemException {
2170                    Session session = null;
2171    
2172                    try {
2173                            session = openSession();
2174    
2175                            Lock lock = (Lock)session.get(LockImpl.class, primaryKey);
2176    
2177                            if (lock == null) {
2178                                    if (_log.isWarnEnabled()) {
2179                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2180                                    }
2181    
2182                                    throw new NoSuchLockException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2183                                            primaryKey);
2184                            }
2185    
2186                            return remove(lock);
2187                    }
2188                    catch (NoSuchLockException nsee) {
2189                            throw nsee;
2190                    }
2191                    catch (Exception e) {
2192                            throw processException(e);
2193                    }
2194                    finally {
2195                            closeSession(session);
2196                    }
2197            }
2198    
2199            @Override
2200            protected Lock removeImpl(Lock lock) throws SystemException {
2201                    lock = toUnwrappedModel(lock);
2202    
2203                    Session session = null;
2204    
2205                    try {
2206                            session = openSession();
2207    
2208                            if (!session.contains(lock)) {
2209                                    lock = (Lock)session.get(LockImpl.class, lock.getPrimaryKeyObj());
2210                            }
2211    
2212                            if (lock != null) {
2213                                    session.delete(lock);
2214                            }
2215                    }
2216                    catch (Exception e) {
2217                            throw processException(e);
2218                    }
2219                    finally {
2220                            closeSession(session);
2221                    }
2222    
2223                    if (lock != null) {
2224                            clearCache(lock);
2225                    }
2226    
2227                    return lock;
2228            }
2229    
2230            @Override
2231            public Lock updateImpl(com.liferay.portal.model.Lock lock)
2232                    throws SystemException {
2233                    lock = toUnwrappedModel(lock);
2234    
2235                    boolean isNew = lock.isNew();
2236    
2237                    LockModelImpl lockModelImpl = (LockModelImpl)lock;
2238    
2239                    if (Validator.isNull(lock.getUuid())) {
2240                            String uuid = PortalUUIDUtil.generate();
2241    
2242                            lock.setUuid(uuid);
2243                    }
2244    
2245                    Session session = null;
2246    
2247                    try {
2248                            session = openSession();
2249    
2250                            if (lock.isNew()) {
2251                                    session.save(lock);
2252    
2253                                    lock.setNew(false);
2254                            }
2255                            else {
2256                                    session.merge(lock);
2257                            }
2258                    }
2259                    catch (Exception e) {
2260                            throw processException(e);
2261                    }
2262                    finally {
2263                            closeSession(session);
2264                    }
2265    
2266                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2267    
2268                    if (isNew || !LockModelImpl.COLUMN_BITMASK_ENABLED) {
2269                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2270                    }
2271    
2272                    else {
2273                            if ((lockModelImpl.getColumnBitmask() &
2274                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
2275                                    Object[] args = new Object[] { lockModelImpl.getOriginalUuid() };
2276    
2277                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2278                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2279                                            args);
2280    
2281                                    args = new Object[] { lockModelImpl.getUuid() };
2282    
2283                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2284                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2285                                            args);
2286                            }
2287    
2288                            if ((lockModelImpl.getColumnBitmask() &
2289                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
2290                                    Object[] args = new Object[] {
2291                                                    lockModelImpl.getOriginalUuid(),
2292                                                    lockModelImpl.getOriginalCompanyId()
2293                                            };
2294    
2295                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2296                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2297                                            args);
2298    
2299                                    args = new Object[] {
2300                                                    lockModelImpl.getUuid(), lockModelImpl.getCompanyId()
2301                                            };
2302    
2303                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2304                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2305                                            args);
2306                            }
2307                    }
2308    
2309                    EntityCacheUtil.putResult(LockModelImpl.ENTITY_CACHE_ENABLED,
2310                            LockImpl.class, lock.getPrimaryKey(), lock);
2311    
2312                    clearUniqueFindersCache(lock);
2313                    cacheUniqueFindersCache(lock);
2314    
2315                    return lock;
2316            }
2317    
2318            protected Lock toUnwrappedModel(Lock lock) {
2319                    if (lock instanceof LockImpl) {
2320                            return lock;
2321                    }
2322    
2323                    LockImpl lockImpl = new LockImpl();
2324    
2325                    lockImpl.setNew(lock.isNew());
2326                    lockImpl.setPrimaryKey(lock.getPrimaryKey());
2327    
2328                    lockImpl.setUuid(lock.getUuid());
2329                    lockImpl.setLockId(lock.getLockId());
2330                    lockImpl.setCompanyId(lock.getCompanyId());
2331                    lockImpl.setUserId(lock.getUserId());
2332                    lockImpl.setUserName(lock.getUserName());
2333                    lockImpl.setCreateDate(lock.getCreateDate());
2334                    lockImpl.setClassName(lock.getClassName());
2335                    lockImpl.setKey(lock.getKey());
2336                    lockImpl.setOwner(lock.getOwner());
2337                    lockImpl.setInheritable(lock.isInheritable());
2338                    lockImpl.setExpirationDate(lock.getExpirationDate());
2339    
2340                    return lockImpl;
2341            }
2342    
2343            /**
2344             * Returns the lock with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
2345             *
2346             * @param primaryKey the primary key of the lock
2347             * @return the lock
2348             * @throws com.liferay.portal.NoSuchLockException if a lock with the primary key could not be found
2349             * @throws SystemException if a system exception occurred
2350             */
2351            @Override
2352            public Lock findByPrimaryKey(Serializable primaryKey)
2353                    throws NoSuchLockException, SystemException {
2354                    Lock lock = fetchByPrimaryKey(primaryKey);
2355    
2356                    if (lock == null) {
2357                            if (_log.isWarnEnabled()) {
2358                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2359                            }
2360    
2361                            throw new NoSuchLockException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2362                                    primaryKey);
2363                    }
2364    
2365                    return lock;
2366            }
2367    
2368            /**
2369             * Returns the lock with the primary key or throws a {@link com.liferay.portal.NoSuchLockException} if it could not be found.
2370             *
2371             * @param lockId the primary key of the lock
2372             * @return the lock
2373             * @throws com.liferay.portal.NoSuchLockException if a lock with the primary key could not be found
2374             * @throws SystemException if a system exception occurred
2375             */
2376            @Override
2377            public Lock findByPrimaryKey(long lockId)
2378                    throws NoSuchLockException, SystemException {
2379                    return findByPrimaryKey((Serializable)lockId);
2380            }
2381    
2382            /**
2383             * Returns the lock with the primary key or returns <code>null</code> if it could not be found.
2384             *
2385             * @param primaryKey the primary key of the lock
2386             * @return the lock, or <code>null</code> if a lock with the primary key could not be found
2387             * @throws SystemException if a system exception occurred
2388             */
2389            @Override
2390            public Lock fetchByPrimaryKey(Serializable primaryKey)
2391                    throws SystemException {
2392                    Lock lock = (Lock)EntityCacheUtil.getResult(LockModelImpl.ENTITY_CACHE_ENABLED,
2393                                    LockImpl.class, primaryKey);
2394    
2395                    if (lock == _nullLock) {
2396                            return null;
2397                    }
2398    
2399                    if (lock == null) {
2400                            Session session = null;
2401    
2402                            try {
2403                                    session = openSession();
2404    
2405                                    lock = (Lock)session.get(LockImpl.class, primaryKey);
2406    
2407                                    if (lock != null) {
2408                                            cacheResult(lock);
2409                                    }
2410                                    else {
2411                                            EntityCacheUtil.putResult(LockModelImpl.ENTITY_CACHE_ENABLED,
2412                                                    LockImpl.class, primaryKey, _nullLock);
2413                                    }
2414                            }
2415                            catch (Exception e) {
2416                                    EntityCacheUtil.removeResult(LockModelImpl.ENTITY_CACHE_ENABLED,
2417                                            LockImpl.class, primaryKey);
2418    
2419                                    throw processException(e);
2420                            }
2421                            finally {
2422                                    closeSession(session);
2423                            }
2424                    }
2425    
2426                    return lock;
2427            }
2428    
2429            /**
2430             * Returns the lock with the primary key or returns <code>null</code> if it could not be found.
2431             *
2432             * @param lockId the primary key of the lock
2433             * @return the lock, or <code>null</code> if a lock with the primary key could not be found
2434             * @throws SystemException if a system exception occurred
2435             */
2436            @Override
2437            public Lock fetchByPrimaryKey(long lockId) throws SystemException {
2438                    return fetchByPrimaryKey((Serializable)lockId);
2439            }
2440    
2441            /**
2442             * Returns all the locks.
2443             *
2444             * @return the locks
2445             * @throws SystemException if a system exception occurred
2446             */
2447            @Override
2448            public List<Lock> findAll() throws SystemException {
2449                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2450            }
2451    
2452            /**
2453             * Returns a range of all the locks.
2454             *
2455             * <p>
2456             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.LockModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2457             * </p>
2458             *
2459             * @param start the lower bound of the range of locks
2460             * @param end the upper bound of the range of locks (not inclusive)
2461             * @return the range of locks
2462             * @throws SystemException if a system exception occurred
2463             */
2464            @Override
2465            public List<Lock> findAll(int start, int end) throws SystemException {
2466                    return findAll(start, end, null);
2467            }
2468    
2469            /**
2470             * Returns an ordered range of all the locks.
2471             *
2472             * <p>
2473             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.LockModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2474             * </p>
2475             *
2476             * @param start the lower bound of the range of locks
2477             * @param end the upper bound of the range of locks (not inclusive)
2478             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2479             * @return the ordered range of locks
2480             * @throws SystemException if a system exception occurred
2481             */
2482            @Override
2483            public List<Lock> findAll(int start, int end,
2484                    OrderByComparator orderByComparator) throws SystemException {
2485                    boolean pagination = true;
2486                    FinderPath finderPath = null;
2487                    Object[] finderArgs = null;
2488    
2489                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2490                                    (orderByComparator == null)) {
2491                            pagination = false;
2492                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2493                            finderArgs = FINDER_ARGS_EMPTY;
2494                    }
2495                    else {
2496                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2497                            finderArgs = new Object[] { start, end, orderByComparator };
2498                    }
2499    
2500                    List<Lock> list = (List<Lock>)FinderCacheUtil.getResult(finderPath,
2501                                    finderArgs, this);
2502    
2503                    if (list == null) {
2504                            StringBundler query = null;
2505                            String sql = null;
2506    
2507                            if (orderByComparator != null) {
2508                                    query = new StringBundler(2 +
2509                                                    (orderByComparator.getOrderByFields().length * 3));
2510    
2511                                    query.append(_SQL_SELECT_LOCK);
2512    
2513                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2514                                            orderByComparator);
2515    
2516                                    sql = query.toString();
2517                            }
2518                            else {
2519                                    sql = _SQL_SELECT_LOCK;
2520    
2521                                    if (pagination) {
2522                                            sql = sql.concat(LockModelImpl.ORDER_BY_JPQL);
2523                                    }
2524                            }
2525    
2526                            Session session = null;
2527    
2528                            try {
2529                                    session = openSession();
2530    
2531                                    Query q = session.createQuery(sql);
2532    
2533                                    if (!pagination) {
2534                                            list = (List<Lock>)QueryUtil.list(q, getDialect(), start,
2535                                                            end, false);
2536    
2537                                            Collections.sort(list);
2538    
2539                                            list = new UnmodifiableList<Lock>(list);
2540                                    }
2541                                    else {
2542                                            list = (List<Lock>)QueryUtil.list(q, getDialect(), start,
2543                                                            end);
2544                                    }
2545    
2546                                    cacheResult(list);
2547    
2548                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2549                            }
2550                            catch (Exception e) {
2551                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2552    
2553                                    throw processException(e);
2554                            }
2555                            finally {
2556                                    closeSession(session);
2557                            }
2558                    }
2559    
2560                    return list;
2561            }
2562    
2563            /**
2564             * Removes all the locks from the database.
2565             *
2566             * @throws SystemException if a system exception occurred
2567             */
2568            @Override
2569            public void removeAll() throws SystemException {
2570                    for (Lock lock : findAll()) {
2571                            remove(lock);
2572                    }
2573            }
2574    
2575            /**
2576             * Returns the number of locks.
2577             *
2578             * @return the number of locks
2579             * @throws SystemException if a system exception occurred
2580             */
2581            @Override
2582            public int countAll() throws SystemException {
2583                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2584                                    FINDER_ARGS_EMPTY, this);
2585    
2586                    if (count == null) {
2587                            Session session = null;
2588    
2589                            try {
2590                                    session = openSession();
2591    
2592                                    Query q = session.createQuery(_SQL_COUNT_LOCK);
2593    
2594                                    count = (Long)q.uniqueResult();
2595    
2596                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2597                                            FINDER_ARGS_EMPTY, count);
2598                            }
2599                            catch (Exception e) {
2600                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2601                                            FINDER_ARGS_EMPTY);
2602    
2603                                    throw processException(e);
2604                            }
2605                            finally {
2606                                    closeSession(session);
2607                            }
2608                    }
2609    
2610                    return count.intValue();
2611            }
2612    
2613            @Override
2614            protected Set<String> getBadColumnNames() {
2615                    return _badColumnNames;
2616            }
2617    
2618            /**
2619             * Initializes the lock persistence.
2620             */
2621            public void afterPropertiesSet() {
2622                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2623                                            com.liferay.portal.util.PropsUtil.get(
2624                                                    "value.object.listener.com.liferay.portal.model.Lock")));
2625    
2626                    if (listenerClassNames.length > 0) {
2627                            try {
2628                                    List<ModelListener<Lock>> listenersList = new ArrayList<ModelListener<Lock>>();
2629    
2630                                    for (String listenerClassName : listenerClassNames) {
2631                                            listenersList.add((ModelListener<Lock>)InstanceFactory.newInstance(
2632                                                            getClassLoader(), listenerClassName));
2633                                    }
2634    
2635                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2636                            }
2637                            catch (Exception e) {
2638                                    _log.error(e);
2639                            }
2640                    }
2641            }
2642    
2643            public void destroy() {
2644                    EntityCacheUtil.removeCache(LockImpl.class.getName());
2645                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2646                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2647                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2648            }
2649    
2650            private static final String _SQL_SELECT_LOCK = "SELECT lock FROM Lock lock";
2651            private static final String _SQL_SELECT_LOCK_WHERE = "SELECT lock FROM Lock lock WHERE ";
2652            private static final String _SQL_COUNT_LOCK = "SELECT COUNT(lock) FROM Lock lock";
2653            private static final String _SQL_COUNT_LOCK_WHERE = "SELECT COUNT(lock) FROM Lock lock WHERE ";
2654            private static final String _ORDER_BY_ENTITY_ALIAS = "lock.";
2655            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Lock exists with the primary key ";
2656            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Lock exists with the key {";
2657            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2658            private static Log _log = LogFactoryUtil.getLog(LockPersistenceImpl.class);
2659            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
2660                                    "uuid", "key"
2661                            });
2662            private static Lock _nullLock = new LockImpl() {
2663                            @Override
2664                            public Object clone() {
2665                                    return this;
2666                            }
2667    
2668                            @Override
2669                            public CacheModel<Lock> toCacheModel() {
2670                                    return _nullLockCacheModel;
2671                            }
2672                    };
2673    
2674            private static CacheModel<Lock> _nullLockCacheModel = new CacheModel<Lock>() {
2675                            @Override
2676                            public Lock toEntityModel() {
2677                                    return _nullLock;
2678                            }
2679                    };
2680    }