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