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