001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.NoSuchLockException;
018    import com.liferay.portal.NoSuchModelException;
019    import com.liferay.portal.kernel.annotation.BeanReference;
020    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderPath;
024    import com.liferay.portal.kernel.dao.orm.Query;
025    import com.liferay.portal.kernel.dao.orm.QueryPos;
026    import com.liferay.portal.kernel.dao.orm.QueryUtil;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.CalendarUtil;
032    import com.liferay.portal.kernel.util.GetterUtil;
033    import com.liferay.portal.kernel.util.InstanceFactory;
034    import com.liferay.portal.kernel.util.OrderByComparator;
035    import com.liferay.portal.kernel.util.StringBundler;
036    import com.liferay.portal.kernel.util.StringPool;
037    import com.liferay.portal.kernel.util.StringUtil;
038    import com.liferay.portal.kernel.util.Validator;
039    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
040    import com.liferay.portal.model.Lock;
041    import com.liferay.portal.model.ModelListener;
042    import com.liferay.portal.model.impl.LockImpl;
043    import com.liferay.portal.model.impl.LockModelImpl;
044    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
045    
046    import java.io.Serializable;
047    
048    import java.util.ArrayList;
049    import java.util.Collections;
050    import java.util.Date;
051    import java.util.List;
052    
053    /**
054     * The persistence implementation for the lock service.
055     *
056     * <p>
057     * 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.
058     * </p>
059     *
060     * <p>
061     * Caching information and settings can be found in <code>portal.properties</code>
062     * </p>
063     *
064     * @author Brian Wing Shun Chan
065     * @see LockPersistence
066     * @see LockUtil
067     * @generated
068     */
069    public class LockPersistenceImpl extends BasePersistenceImpl<Lock>
070            implements LockPersistence {
071            public static final String FINDER_CLASS_NAME_ENTITY = LockImpl.class.getName();
072            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
073                    ".List";
074            public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
075                            LockModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
076                            "findByUuid",
077                            new String[] {
078                                    String.class.getName(),
079                                    
080                            "java.lang.Integer", "java.lang.Integer",
081                                    "com.liferay.portal.kernel.util.OrderByComparator"
082                            });
083            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
084                            LockModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
085                            "countByUuid", new String[] { String.class.getName() });
086            public static final FinderPath FINDER_PATH_FIND_BY_LTEXPIRATIONDATE = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
087                            LockModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
088                            "findByLtExpirationDate",
089                            new String[] {
090                                    Date.class.getName(),
091                                    
092                            "java.lang.Integer", "java.lang.Integer",
093                                    "com.liferay.portal.kernel.util.OrderByComparator"
094                            });
095            public static final FinderPath FINDER_PATH_COUNT_BY_LTEXPIRATIONDATE = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
096                            LockModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
097                            "countByLtExpirationDate", new String[] { Date.class.getName() });
098            public static final FinderPath FINDER_PATH_FETCH_BY_C_K = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
099                            LockModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
100                            "fetchByC_K",
101                            new String[] { String.class.getName(), String.class.getName() });
102            public static final FinderPath FINDER_PATH_COUNT_BY_C_K = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
103                            LockModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
104                            "countByC_K",
105                            new String[] { String.class.getName(), String.class.getName() });
106            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
107                            LockModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
108                            "findAll", new String[0]);
109            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
110                            LockModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
111                            "countAll", new String[0]);
112    
113            /**
114             * Caches the lock in the entity cache if it is enabled.
115             *
116             * @param lock the lock to cache
117             */
118            public void cacheResult(Lock lock) {
119                    EntityCacheUtil.putResult(LockModelImpl.ENTITY_CACHE_ENABLED,
120                            LockImpl.class, lock.getPrimaryKey(), lock);
121    
122                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K,
123                            new Object[] { lock.getClassName(), lock.getKey() }, lock);
124            }
125    
126            /**
127             * Caches the locks in the entity cache if it is enabled.
128             *
129             * @param locks the locks to cache
130             */
131            public void cacheResult(List<Lock> locks) {
132                    for (Lock lock : locks) {
133                            if (EntityCacheUtil.getResult(LockModelImpl.ENTITY_CACHE_ENABLED,
134                                                    LockImpl.class, lock.getPrimaryKey(), this) == null) {
135                                    cacheResult(lock);
136                            }
137                    }
138            }
139    
140            /**
141             * Clears the cache for all locks.
142             *
143             * <p>
144             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
145             * </p>
146             */
147            public void clearCache() {
148                    CacheRegistryUtil.clear(LockImpl.class.getName());
149                    EntityCacheUtil.clearCache(LockImpl.class.getName());
150                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
151                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
152            }
153    
154            /**
155             * Clears the cache for the lock.
156             *
157             * <p>
158             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
159             * </p>
160             */
161            public void clearCache(Lock lock) {
162                    EntityCacheUtil.removeResult(LockModelImpl.ENTITY_CACHE_ENABLED,
163                            LockImpl.class, lock.getPrimaryKey());
164    
165                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_K,
166                            new Object[] { lock.getClassName(), lock.getKey() });
167            }
168    
169            /**
170             * Creates a new lock with the primary key. Does not add the lock to the database.
171             *
172             * @param lockId the primary key for the new lock
173             * @return the new lock
174             */
175            public Lock create(long lockId) {
176                    Lock lock = new LockImpl();
177    
178                    lock.setNew(true);
179                    lock.setPrimaryKey(lockId);
180    
181                    String uuid = PortalUUIDUtil.generate();
182    
183                    lock.setUuid(uuid);
184    
185                    return lock;
186            }
187    
188            /**
189             * Removes the lock with the primary key from the database. Also notifies the appropriate model listeners.
190             *
191             * @param primaryKey the primary key of the lock to remove
192             * @return the lock that was removed
193             * @throws com.liferay.portal.NoSuchModelException if a lock with the primary key could not be found
194             * @throws SystemException if a system exception occurred
195             */
196            public Lock remove(Serializable primaryKey)
197                    throws NoSuchModelException, SystemException {
198                    return remove(((Long)primaryKey).longValue());
199            }
200    
201            /**
202             * Removes the lock with the primary key from the database. Also notifies the appropriate model listeners.
203             *
204             * @param lockId the primary key of the lock to remove
205             * @return the lock that was removed
206             * @throws com.liferay.portal.NoSuchLockException if a lock with the primary key could not be found
207             * @throws SystemException if a system exception occurred
208             */
209            public Lock remove(long lockId) throws NoSuchLockException, SystemException {
210                    Session session = null;
211    
212                    try {
213                            session = openSession();
214    
215                            Lock lock = (Lock)session.get(LockImpl.class, new Long(lockId));
216    
217                            if (lock == null) {
218                                    if (_log.isWarnEnabled()) {
219                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + lockId);
220                                    }
221    
222                                    throw new NoSuchLockException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
223                                            lockId);
224                            }
225    
226                            return remove(lock);
227                    }
228                    catch (NoSuchLockException nsee) {
229                            throw nsee;
230                    }
231                    catch (Exception e) {
232                            throw processException(e);
233                    }
234                    finally {
235                            closeSession(session);
236                    }
237            }
238    
239            protected Lock removeImpl(Lock lock) throws SystemException {
240                    lock = toUnwrappedModel(lock);
241    
242                    Session session = null;
243    
244                    try {
245                            session = openSession();
246    
247                            BatchSessionUtil.delete(session, lock);
248                    }
249                    catch (Exception e) {
250                            throw processException(e);
251                    }
252                    finally {
253                            closeSession(session);
254                    }
255    
256                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
257    
258                    LockModelImpl lockModelImpl = (LockModelImpl)lock;
259    
260                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_K,
261                            new Object[] {
262                                    lockModelImpl.getOriginalClassName(),
263                                    
264                            lockModelImpl.getOriginalKey()
265                            });
266    
267                    EntityCacheUtil.removeResult(LockModelImpl.ENTITY_CACHE_ENABLED,
268                            LockImpl.class, lock.getPrimaryKey());
269    
270                    return lock;
271            }
272    
273            public Lock updateImpl(com.liferay.portal.model.Lock lock, boolean merge)
274                    throws SystemException {
275                    lock = toUnwrappedModel(lock);
276    
277                    boolean isNew = lock.isNew();
278    
279                    LockModelImpl lockModelImpl = (LockModelImpl)lock;
280    
281                    if (Validator.isNull(lock.getUuid())) {
282                            String uuid = PortalUUIDUtil.generate();
283    
284                            lock.setUuid(uuid);
285                    }
286    
287                    Session session = null;
288    
289                    try {
290                            session = openSession();
291    
292                            BatchSessionUtil.update(session, lock, merge);
293    
294                            lock.setNew(false);
295                    }
296                    catch (Exception e) {
297                            throw processException(e);
298                    }
299                    finally {
300                            closeSession(session);
301                    }
302    
303                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
304    
305                    EntityCacheUtil.putResult(LockModelImpl.ENTITY_CACHE_ENABLED,
306                            LockImpl.class, lock.getPrimaryKey(), lock);
307    
308                    if (!isNew &&
309                                    (!Validator.equals(lock.getClassName(),
310                                            lockModelImpl.getOriginalClassName()) ||
311                                    !Validator.equals(lock.getKey(), lockModelImpl.getOriginalKey()))) {
312                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_K,
313                                    new Object[] {
314                                            lockModelImpl.getOriginalClassName(),
315                                            
316                                    lockModelImpl.getOriginalKey()
317                                    });
318                    }
319    
320                    if (isNew ||
321                                    (!Validator.equals(lock.getClassName(),
322                                            lockModelImpl.getOriginalClassName()) ||
323                                    !Validator.equals(lock.getKey(), lockModelImpl.getOriginalKey()))) {
324                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K,
325                                    new Object[] { lock.getClassName(), lock.getKey() }, lock);
326                    }
327    
328                    return lock;
329            }
330    
331            protected Lock toUnwrappedModel(Lock lock) {
332                    if (lock instanceof LockImpl) {
333                            return lock;
334                    }
335    
336                    LockImpl lockImpl = new LockImpl();
337    
338                    lockImpl.setNew(lock.isNew());
339                    lockImpl.setPrimaryKey(lock.getPrimaryKey());
340    
341                    lockImpl.setUuid(lock.getUuid());
342                    lockImpl.setLockId(lock.getLockId());
343                    lockImpl.setCompanyId(lock.getCompanyId());
344                    lockImpl.setUserId(lock.getUserId());
345                    lockImpl.setUserName(lock.getUserName());
346                    lockImpl.setCreateDate(lock.getCreateDate());
347                    lockImpl.setClassName(lock.getClassName());
348                    lockImpl.setKey(lock.getKey());
349                    lockImpl.setOwner(lock.getOwner());
350                    lockImpl.setInheritable(lock.isInheritable());
351                    lockImpl.setExpirationDate(lock.getExpirationDate());
352    
353                    return lockImpl;
354            }
355    
356            /**
357             * Finds the lock with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
358             *
359             * @param primaryKey the primary key of the lock to find
360             * @return the lock
361             * @throws com.liferay.portal.NoSuchModelException if a lock with the primary key could not be found
362             * @throws SystemException if a system exception occurred
363             */
364            public Lock findByPrimaryKey(Serializable primaryKey)
365                    throws NoSuchModelException, SystemException {
366                    return findByPrimaryKey(((Long)primaryKey).longValue());
367            }
368    
369            /**
370             * Finds the lock with the primary key or throws a {@link com.liferay.portal.NoSuchLockException} if it could not be found.
371             *
372             * @param lockId the primary key of the lock to find
373             * @return the lock
374             * @throws com.liferay.portal.NoSuchLockException if a lock with the primary key could not be found
375             * @throws SystemException if a system exception occurred
376             */
377            public Lock findByPrimaryKey(long lockId)
378                    throws NoSuchLockException, SystemException {
379                    Lock lock = fetchByPrimaryKey(lockId);
380    
381                    if (lock == null) {
382                            if (_log.isWarnEnabled()) {
383                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + lockId);
384                            }
385    
386                            throw new NoSuchLockException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
387                                    lockId);
388                    }
389    
390                    return lock;
391            }
392    
393            /**
394             * Finds the lock with the primary key or returns <code>null</code> if it could not be found.
395             *
396             * @param primaryKey the primary key of the lock to find
397             * @return the lock, or <code>null</code> if a lock with the primary key could not be found
398             * @throws SystemException if a system exception occurred
399             */
400            public Lock fetchByPrimaryKey(Serializable primaryKey)
401                    throws SystemException {
402                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
403            }
404    
405            /**
406             * Finds the lock with the primary key or returns <code>null</code> if it could not be found.
407             *
408             * @param lockId the primary key of the lock to find
409             * @return the lock, or <code>null</code> if a lock with the primary key could not be found
410             * @throws SystemException if a system exception occurred
411             */
412            public Lock fetchByPrimaryKey(long lockId) throws SystemException {
413                    Lock lock = (Lock)EntityCacheUtil.getResult(LockModelImpl.ENTITY_CACHE_ENABLED,
414                                    LockImpl.class, lockId, this);
415    
416                    if (lock == null) {
417                            Session session = null;
418    
419                            try {
420                                    session = openSession();
421    
422                                    lock = (Lock)session.get(LockImpl.class, new Long(lockId));
423                            }
424                            catch (Exception e) {
425                                    throw processException(e);
426                            }
427                            finally {
428                                    if (lock != null) {
429                                            cacheResult(lock);
430                                    }
431    
432                                    closeSession(session);
433                            }
434                    }
435    
436                    return lock;
437            }
438    
439            /**
440             * Finds all the locks where uuid = &#63;.
441             *
442             * @param uuid the uuid to search with
443             * @return the matching locks
444             * @throws SystemException if a system exception occurred
445             */
446            public List<Lock> findByUuid(String uuid) throws SystemException {
447                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
448            }
449    
450            /**
451             * Finds a range of all the locks where uuid = &#63;.
452             *
453             * <p>
454             * 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.
455             * </p>
456             *
457             * @param uuid the uuid to search with
458             * @param start the lower bound of the range of locks to return
459             * @param end the upper bound of the range of locks to return (not inclusive)
460             * @return the range of matching locks
461             * @throws SystemException if a system exception occurred
462             */
463            public List<Lock> findByUuid(String uuid, int start, int end)
464                    throws SystemException {
465                    return findByUuid(uuid, start, end, null);
466            }
467    
468            /**
469             * Finds an ordered range of all the locks where uuid = &#63;.
470             *
471             * <p>
472             * 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.
473             * </p>
474             *
475             * @param uuid the uuid to search with
476             * @param start the lower bound of the range of locks to return
477             * @param end the upper bound of the range of locks to return (not inclusive)
478             * @param orderByComparator the comparator to order the results by
479             * @return the ordered range of matching locks
480             * @throws SystemException if a system exception occurred
481             */
482            public List<Lock> findByUuid(String uuid, int start, int end,
483                    OrderByComparator orderByComparator) throws SystemException {
484                    Object[] finderArgs = new Object[] {
485                                    uuid,
486                                    
487                                    String.valueOf(start), String.valueOf(end),
488                                    String.valueOf(orderByComparator)
489                            };
490    
491                    List<Lock> list = (List<Lock>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
492                                    finderArgs, this);
493    
494                    if (list == null) {
495                            Session session = null;
496    
497                            try {
498                                    session = openSession();
499    
500                                    StringBundler query = null;
501    
502                                    if (orderByComparator != null) {
503                                            query = new StringBundler(3 +
504                                                            (orderByComparator.getOrderByFields().length * 3));
505                                    }
506                                    else {
507                                            query = new StringBundler(2);
508                                    }
509    
510                                    query.append(_SQL_SELECT_LOCK_WHERE);
511    
512                                    if (uuid == null) {
513                                            query.append(_FINDER_COLUMN_UUID_UUID_1);
514                                    }
515                                    else {
516                                            if (uuid.equals(StringPool.BLANK)) {
517                                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
518                                            }
519                                            else {
520                                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
521                                            }
522                                    }
523    
524                                    if (orderByComparator != null) {
525                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
526                                                    orderByComparator);
527                                    }
528    
529                                    String sql = query.toString();
530    
531                                    Query q = session.createQuery(sql);
532    
533                                    QueryPos qPos = QueryPos.getInstance(q);
534    
535                                    if (uuid != null) {
536                                            qPos.add(uuid);
537                                    }
538    
539                                    list = (List<Lock>)QueryUtil.list(q, getDialect(), start, end);
540                            }
541                            catch (Exception e) {
542                                    throw processException(e);
543                            }
544                            finally {
545                                    if (list == null) {
546                                            list = new ArrayList<Lock>();
547                                    }
548    
549                                    cacheResult(list);
550    
551                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
552                                            list);
553    
554                                    closeSession(session);
555                            }
556                    }
557    
558                    return list;
559            }
560    
561            /**
562             * Finds the first lock in the ordered set where uuid = &#63;.
563             *
564             * <p>
565             * 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.
566             * </p>
567             *
568             * @param uuid the uuid to search with
569             * @param orderByComparator the comparator to order the set by
570             * @return the first matching lock
571             * @throws com.liferay.portal.NoSuchLockException if a matching lock could not be found
572             * @throws SystemException if a system exception occurred
573             */
574            public Lock findByUuid_First(String uuid,
575                    OrderByComparator orderByComparator)
576                    throws NoSuchLockException, SystemException {
577                    List<Lock> list = findByUuid(uuid, 0, 1, orderByComparator);
578    
579                    if (list.isEmpty()) {
580                            StringBundler msg = new StringBundler(4);
581    
582                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
583    
584                            msg.append("uuid=");
585                            msg.append(uuid);
586    
587                            msg.append(StringPool.CLOSE_CURLY_BRACE);
588    
589                            throw new NoSuchLockException(msg.toString());
590                    }
591                    else {
592                            return list.get(0);
593                    }
594            }
595    
596            /**
597             * Finds the last lock in the ordered set where uuid = &#63;.
598             *
599             * <p>
600             * 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.
601             * </p>
602             *
603             * @param uuid the uuid to search with
604             * @param orderByComparator the comparator to order the set by
605             * @return the last matching lock
606             * @throws com.liferay.portal.NoSuchLockException if a matching lock could not be found
607             * @throws SystemException if a system exception occurred
608             */
609            public Lock findByUuid_Last(String uuid, OrderByComparator orderByComparator)
610                    throws NoSuchLockException, SystemException {
611                    int count = countByUuid(uuid);
612    
613                    List<Lock> list = findByUuid(uuid, count - 1, count, orderByComparator);
614    
615                    if (list.isEmpty()) {
616                            StringBundler msg = new StringBundler(4);
617    
618                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
619    
620                            msg.append("uuid=");
621                            msg.append(uuid);
622    
623                            msg.append(StringPool.CLOSE_CURLY_BRACE);
624    
625                            throw new NoSuchLockException(msg.toString());
626                    }
627                    else {
628                            return list.get(0);
629                    }
630            }
631    
632            /**
633             * Finds the locks before and after the current lock in the ordered set where uuid = &#63;.
634             *
635             * <p>
636             * 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.
637             * </p>
638             *
639             * @param lockId the primary key of the current lock
640             * @param uuid the uuid to search with
641             * @param orderByComparator the comparator to order the set by
642             * @return the previous, current, and next lock
643             * @throws com.liferay.portal.NoSuchLockException if a lock with the primary key could not be found
644             * @throws SystemException if a system exception occurred
645             */
646            public Lock[] findByUuid_PrevAndNext(long lockId, String uuid,
647                    OrderByComparator orderByComparator)
648                    throws NoSuchLockException, SystemException {
649                    Lock lock = findByPrimaryKey(lockId);
650    
651                    Session session = null;
652    
653                    try {
654                            session = openSession();
655    
656                            Lock[] array = new LockImpl[3];
657    
658                            array[0] = getByUuid_PrevAndNext(session, lock, uuid,
659                                            orderByComparator, true);
660    
661                            array[1] = lock;
662    
663                            array[2] = getByUuid_PrevAndNext(session, lock, uuid,
664                                            orderByComparator, false);
665    
666                            return array;
667                    }
668                    catch (Exception e) {
669                            throw processException(e);
670                    }
671                    finally {
672                            closeSession(session);
673                    }
674            }
675    
676            protected Lock getByUuid_PrevAndNext(Session session, Lock lock,
677                    String uuid, OrderByComparator orderByComparator, boolean previous) {
678                    StringBundler query = null;
679    
680                    if (orderByComparator != null) {
681                            query = new StringBundler(6 +
682                                            (orderByComparator.getOrderByFields().length * 6));
683                    }
684                    else {
685                            query = new StringBundler(3);
686                    }
687    
688                    query.append(_SQL_SELECT_LOCK_WHERE);
689    
690                    if (uuid == null) {
691                            query.append(_FINDER_COLUMN_UUID_UUID_1);
692                    }
693                    else {
694                            if (uuid.equals(StringPool.BLANK)) {
695                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
696                            }
697                            else {
698                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
699                            }
700                    }
701    
702                    if (orderByComparator != null) {
703                            String[] orderByFields = orderByComparator.getOrderByFields();
704    
705                            if (orderByFields.length > 0) {
706                                    query.append(WHERE_AND);
707                            }
708    
709                            for (int i = 0; i < orderByFields.length; i++) {
710                                    query.append(_ORDER_BY_ENTITY_ALIAS);
711                                    query.append(orderByFields[i]);
712    
713                                    if ((i + 1) < orderByFields.length) {
714                                            if (orderByComparator.isAscending() ^ previous) {
715                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
716                                            }
717                                            else {
718                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
719                                            }
720                                    }
721                                    else {
722                                            if (orderByComparator.isAscending() ^ previous) {
723                                                    query.append(WHERE_GREATER_THAN);
724                                            }
725                                            else {
726                                                    query.append(WHERE_LESSER_THAN);
727                                            }
728                                    }
729                            }
730    
731                            query.append(ORDER_BY_CLAUSE);
732    
733                            for (int i = 0; i < orderByFields.length; i++) {
734                                    query.append(_ORDER_BY_ENTITY_ALIAS);
735                                    query.append(orderByFields[i]);
736    
737                                    if ((i + 1) < orderByFields.length) {
738                                            if (orderByComparator.isAscending() ^ previous) {
739                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
740                                            }
741                                            else {
742                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
743                                            }
744                                    }
745                                    else {
746                                            if (orderByComparator.isAscending() ^ previous) {
747                                                    query.append(ORDER_BY_ASC);
748                                            }
749                                            else {
750                                                    query.append(ORDER_BY_DESC);
751                                            }
752                                    }
753                            }
754                    }
755    
756                    String sql = query.toString();
757    
758                    Query q = session.createQuery(sql);
759    
760                    q.setFirstResult(0);
761                    q.setMaxResults(2);
762    
763                    QueryPos qPos = QueryPos.getInstance(q);
764    
765                    if (uuid != null) {
766                            qPos.add(uuid);
767                    }
768    
769                    if (orderByComparator != null) {
770                            Object[] values = orderByComparator.getOrderByValues(lock);
771    
772                            for (Object value : values) {
773                                    qPos.add(value);
774                            }
775                    }
776    
777                    List<Lock> list = q.list();
778    
779                    if (list.size() == 2) {
780                            return list.get(1);
781                    }
782                    else {
783                            return null;
784                    }
785            }
786    
787            /**
788             * Finds all the locks where expirationDate &lt; &#63;.
789             *
790             * @param expirationDate the expiration date to search with
791             * @return the matching locks
792             * @throws SystemException if a system exception occurred
793             */
794            public List<Lock> findByLtExpirationDate(Date expirationDate)
795                    throws SystemException {
796                    return findByLtExpirationDate(expirationDate, QueryUtil.ALL_POS,
797                            QueryUtil.ALL_POS, null);
798            }
799    
800            /**
801             * Finds a range of all the locks where expirationDate &lt; &#63;.
802             *
803             * <p>
804             * 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.
805             * </p>
806             *
807             * @param expirationDate the expiration date to search with
808             * @param start the lower bound of the range of locks to return
809             * @param end the upper bound of the range of locks to return (not inclusive)
810             * @return the range of matching locks
811             * @throws SystemException if a system exception occurred
812             */
813            public List<Lock> findByLtExpirationDate(Date expirationDate, int start,
814                    int end) throws SystemException {
815                    return findByLtExpirationDate(expirationDate, start, end, null);
816            }
817    
818            /**
819             * Finds an ordered range of all the locks where expirationDate &lt; &#63;.
820             *
821             * <p>
822             * 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.
823             * </p>
824             *
825             * @param expirationDate the expiration date to search with
826             * @param start the lower bound of the range of locks to return
827             * @param end the upper bound of the range of locks to return (not inclusive)
828             * @param orderByComparator the comparator to order the results by
829             * @return the ordered range of matching locks
830             * @throws SystemException if a system exception occurred
831             */
832            public List<Lock> findByLtExpirationDate(Date expirationDate, int start,
833                    int end, OrderByComparator orderByComparator) throws SystemException {
834                    Object[] finderArgs = new Object[] {
835                                    expirationDate,
836                                    
837                                    String.valueOf(start), String.valueOf(end),
838                                    String.valueOf(orderByComparator)
839                            };
840    
841                    List<Lock> list = (List<Lock>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_LTEXPIRATIONDATE,
842                                    finderArgs, this);
843    
844                    if (list == null) {
845                            Session session = null;
846    
847                            try {
848                                    session = openSession();
849    
850                                    StringBundler query = null;
851    
852                                    if (orderByComparator != null) {
853                                            query = new StringBundler(3 +
854                                                            (orderByComparator.getOrderByFields().length * 3));
855                                    }
856                                    else {
857                                            query = new StringBundler(2);
858                                    }
859    
860                                    query.append(_SQL_SELECT_LOCK_WHERE);
861    
862                                    if (expirationDate == null) {
863                                            query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_1);
864                                    }
865                                    else {
866                                            query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_2);
867                                    }
868    
869                                    if (orderByComparator != null) {
870                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
871                                                    orderByComparator);
872                                    }
873    
874                                    String sql = query.toString();
875    
876                                    Query q = session.createQuery(sql);
877    
878                                    QueryPos qPos = QueryPos.getInstance(q);
879    
880                                    if (expirationDate != null) {
881                                            qPos.add(CalendarUtil.getTimestamp(expirationDate));
882                                    }
883    
884                                    list = (List<Lock>)QueryUtil.list(q, getDialect(), start, end);
885                            }
886                            catch (Exception e) {
887                                    throw processException(e);
888                            }
889                            finally {
890                                    if (list == null) {
891                                            list = new ArrayList<Lock>();
892                                    }
893    
894                                    cacheResult(list);
895    
896                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_LTEXPIRATIONDATE,
897                                            finderArgs, list);
898    
899                                    closeSession(session);
900                            }
901                    }
902    
903                    return list;
904            }
905    
906            /**
907             * Finds the first lock in the ordered set where expirationDate &lt; &#63;.
908             *
909             * <p>
910             * 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.
911             * </p>
912             *
913             * @param expirationDate the expiration date to search with
914             * @param orderByComparator the comparator to order the set by
915             * @return the first matching lock
916             * @throws com.liferay.portal.NoSuchLockException if a matching lock could not be found
917             * @throws SystemException if a system exception occurred
918             */
919            public Lock findByLtExpirationDate_First(Date expirationDate,
920                    OrderByComparator orderByComparator)
921                    throws NoSuchLockException, SystemException {
922                    List<Lock> list = findByLtExpirationDate(expirationDate, 0, 1,
923                                    orderByComparator);
924    
925                    if (list.isEmpty()) {
926                            StringBundler msg = new StringBundler(4);
927    
928                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
929    
930                            msg.append("expirationDate=");
931                            msg.append(expirationDate);
932    
933                            msg.append(StringPool.CLOSE_CURLY_BRACE);
934    
935                            throw new NoSuchLockException(msg.toString());
936                    }
937                    else {
938                            return list.get(0);
939                    }
940            }
941    
942            /**
943             * Finds the last lock in the ordered set where expirationDate &lt; &#63;.
944             *
945             * <p>
946             * 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.
947             * </p>
948             *
949             * @param expirationDate the expiration date to search with
950             * @param orderByComparator the comparator to order the set by
951             * @return the last matching lock
952             * @throws com.liferay.portal.NoSuchLockException if a matching lock could not be found
953             * @throws SystemException if a system exception occurred
954             */
955            public Lock findByLtExpirationDate_Last(Date expirationDate,
956                    OrderByComparator orderByComparator)
957                    throws NoSuchLockException, SystemException {
958                    int count = countByLtExpirationDate(expirationDate);
959    
960                    List<Lock> list = findByLtExpirationDate(expirationDate, count - 1,
961                                    count, orderByComparator);
962    
963                    if (list.isEmpty()) {
964                            StringBundler msg = new StringBundler(4);
965    
966                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
967    
968                            msg.append("expirationDate=");
969                            msg.append(expirationDate);
970    
971                            msg.append(StringPool.CLOSE_CURLY_BRACE);
972    
973                            throw new NoSuchLockException(msg.toString());
974                    }
975                    else {
976                            return list.get(0);
977                    }
978            }
979    
980            /**
981             * Finds the locks before and after the current lock in the ordered set where expirationDate &lt; &#63;.
982             *
983             * <p>
984             * 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.
985             * </p>
986             *
987             * @param lockId the primary key of the current lock
988             * @param expirationDate the expiration date to search with
989             * @param orderByComparator the comparator to order the set by
990             * @return the previous, current, and next lock
991             * @throws com.liferay.portal.NoSuchLockException if a lock with the primary key could not be found
992             * @throws SystemException if a system exception occurred
993             */
994            public Lock[] findByLtExpirationDate_PrevAndNext(long lockId,
995                    Date expirationDate, OrderByComparator orderByComparator)
996                    throws NoSuchLockException, SystemException {
997                    Lock lock = findByPrimaryKey(lockId);
998    
999                    Session session = null;
1000    
1001                    try {
1002                            session = openSession();
1003    
1004                            Lock[] array = new LockImpl[3];
1005    
1006                            array[0] = getByLtExpirationDate_PrevAndNext(session, lock,
1007                                            expirationDate, orderByComparator, true);
1008    
1009                            array[1] = lock;
1010    
1011                            array[2] = getByLtExpirationDate_PrevAndNext(session, lock,
1012                                            expirationDate, orderByComparator, false);
1013    
1014                            return array;
1015                    }
1016                    catch (Exception e) {
1017                            throw processException(e);
1018                    }
1019                    finally {
1020                            closeSession(session);
1021                    }
1022            }
1023    
1024            protected Lock getByLtExpirationDate_PrevAndNext(Session session,
1025                    Lock lock, Date expirationDate, OrderByComparator orderByComparator,
1026                    boolean previous) {
1027                    StringBundler query = null;
1028    
1029                    if (orderByComparator != null) {
1030                            query = new StringBundler(6 +
1031                                            (orderByComparator.getOrderByFields().length * 6));
1032                    }
1033                    else {
1034                            query = new StringBundler(3);
1035                    }
1036    
1037                    query.append(_SQL_SELECT_LOCK_WHERE);
1038    
1039                    if (expirationDate == null) {
1040                            query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_1);
1041                    }
1042                    else {
1043                            query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_2);
1044                    }
1045    
1046                    if (orderByComparator != null) {
1047                            String[] orderByFields = orderByComparator.getOrderByFields();
1048    
1049                            if (orderByFields.length > 0) {
1050                                    query.append(WHERE_AND);
1051                            }
1052    
1053                            for (int i = 0; i < orderByFields.length; i++) {
1054                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1055                                    query.append(orderByFields[i]);
1056    
1057                                    if ((i + 1) < orderByFields.length) {
1058                                            if (orderByComparator.isAscending() ^ previous) {
1059                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1060                                            }
1061                                            else {
1062                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1063                                            }
1064                                    }
1065                                    else {
1066                                            if (orderByComparator.isAscending() ^ previous) {
1067                                                    query.append(WHERE_GREATER_THAN);
1068                                            }
1069                                            else {
1070                                                    query.append(WHERE_LESSER_THAN);
1071                                            }
1072                                    }
1073                            }
1074    
1075                            query.append(ORDER_BY_CLAUSE);
1076    
1077                            for (int i = 0; i < orderByFields.length; i++) {
1078                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1079                                    query.append(orderByFields[i]);
1080    
1081                                    if ((i + 1) < orderByFields.length) {
1082                                            if (orderByComparator.isAscending() ^ previous) {
1083                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1084                                            }
1085                                            else {
1086                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1087                                            }
1088                                    }
1089                                    else {
1090                                            if (orderByComparator.isAscending() ^ previous) {
1091                                                    query.append(ORDER_BY_ASC);
1092                                            }
1093                                            else {
1094                                                    query.append(ORDER_BY_DESC);
1095                                            }
1096                                    }
1097                            }
1098                    }
1099    
1100                    String sql = query.toString();
1101    
1102                    Query q = session.createQuery(sql);
1103    
1104                    q.setFirstResult(0);
1105                    q.setMaxResults(2);
1106    
1107                    QueryPos qPos = QueryPos.getInstance(q);
1108    
1109                    if (expirationDate != null) {
1110                            qPos.add(CalendarUtil.getTimestamp(expirationDate));
1111                    }
1112    
1113                    if (orderByComparator != null) {
1114                            Object[] values = orderByComparator.getOrderByValues(lock);
1115    
1116                            for (Object value : values) {
1117                                    qPos.add(value);
1118                            }
1119                    }
1120    
1121                    List<Lock> list = q.list();
1122    
1123                    if (list.size() == 2) {
1124                            return list.get(1);
1125                    }
1126                    else {
1127                            return null;
1128                    }
1129            }
1130    
1131            /**
1132             * Finds the lock where className = &#63; and key = &#63; or throws a {@link com.liferay.portal.NoSuchLockException} if it could not be found.
1133             *
1134             * @param className the class name to search with
1135             * @param key the key to search with
1136             * @return the matching lock
1137             * @throws com.liferay.portal.NoSuchLockException if a matching lock could not be found
1138             * @throws SystemException if a system exception occurred
1139             */
1140            public Lock findByC_K(String className, String key)
1141                    throws NoSuchLockException, SystemException {
1142                    Lock lock = fetchByC_K(className, key);
1143    
1144                    if (lock == null) {
1145                            StringBundler msg = new StringBundler(6);
1146    
1147                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1148    
1149                            msg.append("className=");
1150                            msg.append(className);
1151    
1152                            msg.append(", key=");
1153                            msg.append(key);
1154    
1155                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1156    
1157                            if (_log.isWarnEnabled()) {
1158                                    _log.warn(msg.toString());
1159                            }
1160    
1161                            throw new NoSuchLockException(msg.toString());
1162                    }
1163    
1164                    return lock;
1165            }
1166    
1167            /**
1168             * Finds the lock where className = &#63; and key = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1169             *
1170             * @param className the class name to search with
1171             * @param key the key to search with
1172             * @return the matching lock, or <code>null</code> if a matching lock could not be found
1173             * @throws SystemException if a system exception occurred
1174             */
1175            public Lock fetchByC_K(String className, String key)
1176                    throws SystemException {
1177                    return fetchByC_K(className, key, true);
1178            }
1179    
1180            /**
1181             * Finds the lock where className = &#63; and key = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1182             *
1183             * @param className the class name to search with
1184             * @param key the key to search with
1185             * @return the matching lock, or <code>null</code> if a matching lock could not be found
1186             * @throws SystemException if a system exception occurred
1187             */
1188            public Lock fetchByC_K(String className, String key,
1189                    boolean retrieveFromCache) throws SystemException {
1190                    Object[] finderArgs = new Object[] { className, key };
1191    
1192                    Object result = null;
1193    
1194                    if (retrieveFromCache) {
1195                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_K,
1196                                            finderArgs, this);
1197                    }
1198    
1199                    if (result == null) {
1200                            Session session = null;
1201    
1202                            try {
1203                                    session = openSession();
1204    
1205                                    StringBundler query = new StringBundler(3);
1206    
1207                                    query.append(_SQL_SELECT_LOCK_WHERE);
1208    
1209                                    if (className == null) {
1210                                            query.append(_FINDER_COLUMN_C_K_CLASSNAME_1);
1211                                    }
1212                                    else {
1213                                            if (className.equals(StringPool.BLANK)) {
1214                                                    query.append(_FINDER_COLUMN_C_K_CLASSNAME_3);
1215                                            }
1216                                            else {
1217                                                    query.append(_FINDER_COLUMN_C_K_CLASSNAME_2);
1218                                            }
1219                                    }
1220    
1221                                    if (key == null) {
1222                                            query.append(_FINDER_COLUMN_C_K_KEY_1);
1223                                    }
1224                                    else {
1225                                            if (key.equals(StringPool.BLANK)) {
1226                                                    query.append(_FINDER_COLUMN_C_K_KEY_3);
1227                                            }
1228                                            else {
1229                                                    query.append(_FINDER_COLUMN_C_K_KEY_2);
1230                                            }
1231                                    }
1232    
1233                                    String sql = query.toString();
1234    
1235                                    Query q = session.createQuery(sql);
1236    
1237                                    QueryPos qPos = QueryPos.getInstance(q);
1238    
1239                                    if (className != null) {
1240                                            qPos.add(className);
1241                                    }
1242    
1243                                    if (key != null) {
1244                                            qPos.add(key);
1245                                    }
1246    
1247                                    List<Lock> list = q.list();
1248    
1249                                    result = list;
1250    
1251                                    Lock lock = null;
1252    
1253                                    if (list.isEmpty()) {
1254                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K,
1255                                                    finderArgs, list);
1256                                    }
1257                                    else {
1258                                            lock = list.get(0);
1259    
1260                                            cacheResult(lock);
1261    
1262                                            if ((lock.getClassName() == null) ||
1263                                                            !lock.getClassName().equals(className) ||
1264                                                            (lock.getKey() == null) ||
1265                                                            !lock.getKey().equals(key)) {
1266                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K,
1267                                                            finderArgs, lock);
1268                                            }
1269                                    }
1270    
1271                                    return lock;
1272                            }
1273                            catch (Exception e) {
1274                                    throw processException(e);
1275                            }
1276                            finally {
1277                                    if (result == null) {
1278                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K,
1279                                                    finderArgs, new ArrayList<Lock>());
1280                                    }
1281    
1282                                    closeSession(session);
1283                            }
1284                    }
1285                    else {
1286                            if (result instanceof List<?>) {
1287                                    return null;
1288                            }
1289                            else {
1290                                    return (Lock)result;
1291                            }
1292                    }
1293            }
1294    
1295            /**
1296             * Finds all the locks.
1297             *
1298             * @return the locks
1299             * @throws SystemException if a system exception occurred
1300             */
1301            public List<Lock> findAll() throws SystemException {
1302                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1303            }
1304    
1305            /**
1306             * Finds a range of all the locks.
1307             *
1308             * <p>
1309             * 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.
1310             * </p>
1311             *
1312             * @param start the lower bound of the range of locks to return
1313             * @param end the upper bound of the range of locks to return (not inclusive)
1314             * @return the range of locks
1315             * @throws SystemException if a system exception occurred
1316             */
1317            public List<Lock> findAll(int start, int end) throws SystemException {
1318                    return findAll(start, end, null);
1319            }
1320    
1321            /**
1322             * Finds an ordered range of all the locks.
1323             *
1324             * <p>
1325             * 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.
1326             * </p>
1327             *
1328             * @param start the lower bound of the range of locks to return
1329             * @param end the upper bound of the range of locks to return (not inclusive)
1330             * @param orderByComparator the comparator to order the results by
1331             * @return the ordered range of locks
1332             * @throws SystemException if a system exception occurred
1333             */
1334            public List<Lock> findAll(int start, int end,
1335                    OrderByComparator orderByComparator) throws SystemException {
1336                    Object[] finderArgs = new Object[] {
1337                                    String.valueOf(start), String.valueOf(end),
1338                                    String.valueOf(orderByComparator)
1339                            };
1340    
1341                    List<Lock> list = (List<Lock>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1342                                    finderArgs, this);
1343    
1344                    if (list == null) {
1345                            Session session = null;
1346    
1347                            try {
1348                                    session = openSession();
1349    
1350                                    StringBundler query = null;
1351                                    String sql = null;
1352    
1353                                    if (orderByComparator != null) {
1354                                            query = new StringBundler(2 +
1355                                                            (orderByComparator.getOrderByFields().length * 3));
1356    
1357                                            query.append(_SQL_SELECT_LOCK);
1358    
1359                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1360                                                    orderByComparator);
1361    
1362                                            sql = query.toString();
1363                                    }
1364                                    else {
1365                                            sql = _SQL_SELECT_LOCK;
1366                                    }
1367    
1368                                    Query q = session.createQuery(sql);
1369    
1370                                    if (orderByComparator == null) {
1371                                            list = (List<Lock>)QueryUtil.list(q, getDialect(), start,
1372                                                            end, false);
1373    
1374                                            Collections.sort(list);
1375                                    }
1376                                    else {
1377                                            list = (List<Lock>)QueryUtil.list(q, getDialect(), start,
1378                                                            end);
1379                                    }
1380                            }
1381                            catch (Exception e) {
1382                                    throw processException(e);
1383                            }
1384                            finally {
1385                                    if (list == null) {
1386                                            list = new ArrayList<Lock>();
1387                                    }
1388    
1389                                    cacheResult(list);
1390    
1391                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1392    
1393                                    closeSession(session);
1394                            }
1395                    }
1396    
1397                    return list;
1398            }
1399    
1400            /**
1401             * Removes all the locks where uuid = &#63; from the database.
1402             *
1403             * @param uuid the uuid to search with
1404             * @throws SystemException if a system exception occurred
1405             */
1406            public void removeByUuid(String uuid) throws SystemException {
1407                    for (Lock lock : findByUuid(uuid)) {
1408                            remove(lock);
1409                    }
1410            }
1411    
1412            /**
1413             * Removes all the locks where expirationDate &lt; &#63; from the database.
1414             *
1415             * @param expirationDate the expiration date to search with
1416             * @throws SystemException if a system exception occurred
1417             */
1418            public void removeByLtExpirationDate(Date expirationDate)
1419                    throws SystemException {
1420                    for (Lock lock : findByLtExpirationDate(expirationDate)) {
1421                            remove(lock);
1422                    }
1423            }
1424    
1425            /**
1426             * Removes the lock where className = &#63; and key = &#63; from the database.
1427             *
1428             * @param className the class name to search with
1429             * @param key the key to search with
1430             * @throws SystemException if a system exception occurred
1431             */
1432            public void removeByC_K(String className, String key)
1433                    throws NoSuchLockException, SystemException {
1434                    Lock lock = findByC_K(className, key);
1435    
1436                    remove(lock);
1437            }
1438    
1439            /**
1440             * Removes all the locks from the database.
1441             *
1442             * @throws SystemException if a system exception occurred
1443             */
1444            public void removeAll() throws SystemException {
1445                    for (Lock lock : findAll()) {
1446                            remove(lock);
1447                    }
1448            }
1449    
1450            /**
1451             * Counts all the locks where uuid = &#63;.
1452             *
1453             * @param uuid the uuid to search with
1454             * @return the number of matching locks
1455             * @throws SystemException if a system exception occurred
1456             */
1457            public int countByUuid(String uuid) throws SystemException {
1458                    Object[] finderArgs = new Object[] { uuid };
1459    
1460                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1461                                    finderArgs, this);
1462    
1463                    if (count == null) {
1464                            Session session = null;
1465    
1466                            try {
1467                                    session = openSession();
1468    
1469                                    StringBundler query = new StringBundler(2);
1470    
1471                                    query.append(_SQL_COUNT_LOCK_WHERE);
1472    
1473                                    if (uuid == null) {
1474                                            query.append(_FINDER_COLUMN_UUID_UUID_1);
1475                                    }
1476                                    else {
1477                                            if (uuid.equals(StringPool.BLANK)) {
1478                                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
1479                                            }
1480                                            else {
1481                                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
1482                                            }
1483                                    }
1484    
1485                                    String sql = query.toString();
1486    
1487                                    Query q = session.createQuery(sql);
1488    
1489                                    QueryPos qPos = QueryPos.getInstance(q);
1490    
1491                                    if (uuid != null) {
1492                                            qPos.add(uuid);
1493                                    }
1494    
1495                                    count = (Long)q.uniqueResult();
1496                            }
1497                            catch (Exception e) {
1498                                    throw processException(e);
1499                            }
1500                            finally {
1501                                    if (count == null) {
1502                                            count = Long.valueOf(0);
1503                                    }
1504    
1505                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
1506                                            finderArgs, count);
1507    
1508                                    closeSession(session);
1509                            }
1510                    }
1511    
1512                    return count.intValue();
1513            }
1514    
1515            /**
1516             * Counts all the locks where expirationDate &lt; &#63;.
1517             *
1518             * @param expirationDate the expiration date to search with
1519             * @return the number of matching locks
1520             * @throws SystemException if a system exception occurred
1521             */
1522            public int countByLtExpirationDate(Date expirationDate)
1523                    throws SystemException {
1524                    Object[] finderArgs = new Object[] { expirationDate };
1525    
1526                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_LTEXPIRATIONDATE,
1527                                    finderArgs, this);
1528    
1529                    if (count == null) {
1530                            Session session = null;
1531    
1532                            try {
1533                                    session = openSession();
1534    
1535                                    StringBundler query = new StringBundler(2);
1536    
1537                                    query.append(_SQL_COUNT_LOCK_WHERE);
1538    
1539                                    if (expirationDate == null) {
1540                                            query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_1);
1541                                    }
1542                                    else {
1543                                            query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_2);
1544                                    }
1545    
1546                                    String sql = query.toString();
1547    
1548                                    Query q = session.createQuery(sql);
1549    
1550                                    QueryPos qPos = QueryPos.getInstance(q);
1551    
1552                                    if (expirationDate != null) {
1553                                            qPos.add(CalendarUtil.getTimestamp(expirationDate));
1554                                    }
1555    
1556                                    count = (Long)q.uniqueResult();
1557                            }
1558                            catch (Exception e) {
1559                                    throw processException(e);
1560                            }
1561                            finally {
1562                                    if (count == null) {
1563                                            count = Long.valueOf(0);
1564                                    }
1565    
1566                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_LTEXPIRATIONDATE,
1567                                            finderArgs, count);
1568    
1569                                    closeSession(session);
1570                            }
1571                    }
1572    
1573                    return count.intValue();
1574            }
1575    
1576            /**
1577             * Counts all the locks where className = &#63; and key = &#63;.
1578             *
1579             * @param className the class name to search with
1580             * @param key the key to search with
1581             * @return the number of matching locks
1582             * @throws SystemException if a system exception occurred
1583             */
1584            public int countByC_K(String className, String key)
1585                    throws SystemException {
1586                    Object[] finderArgs = new Object[] { className, key };
1587    
1588                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_K,
1589                                    finderArgs, this);
1590    
1591                    if (count == null) {
1592                            Session session = null;
1593    
1594                            try {
1595                                    session = openSession();
1596    
1597                                    StringBundler query = new StringBundler(3);
1598    
1599                                    query.append(_SQL_COUNT_LOCK_WHERE);
1600    
1601                                    if (className == null) {
1602                                            query.append(_FINDER_COLUMN_C_K_CLASSNAME_1);
1603                                    }
1604                                    else {
1605                                            if (className.equals(StringPool.BLANK)) {
1606                                                    query.append(_FINDER_COLUMN_C_K_CLASSNAME_3);
1607                                            }
1608                                            else {
1609                                                    query.append(_FINDER_COLUMN_C_K_CLASSNAME_2);
1610                                            }
1611                                    }
1612    
1613                                    if (key == null) {
1614                                            query.append(_FINDER_COLUMN_C_K_KEY_1);
1615                                    }
1616                                    else {
1617                                            if (key.equals(StringPool.BLANK)) {
1618                                                    query.append(_FINDER_COLUMN_C_K_KEY_3);
1619                                            }
1620                                            else {
1621                                                    query.append(_FINDER_COLUMN_C_K_KEY_2);
1622                                            }
1623                                    }
1624    
1625                                    String sql = query.toString();
1626    
1627                                    Query q = session.createQuery(sql);
1628    
1629                                    QueryPos qPos = QueryPos.getInstance(q);
1630    
1631                                    if (className != null) {
1632                                            qPos.add(className);
1633                                    }
1634    
1635                                    if (key != null) {
1636                                            qPos.add(key);
1637                                    }
1638    
1639                                    count = (Long)q.uniqueResult();
1640                            }
1641                            catch (Exception e) {
1642                                    throw processException(e);
1643                            }
1644                            finally {
1645                                    if (count == null) {
1646                                            count = Long.valueOf(0);
1647                                    }
1648    
1649                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_K, finderArgs,
1650                                            count);
1651    
1652                                    closeSession(session);
1653                            }
1654                    }
1655    
1656                    return count.intValue();
1657            }
1658    
1659            /**
1660             * Counts all the locks.
1661             *
1662             * @return the number of locks
1663             * @throws SystemException if a system exception occurred
1664             */
1665            public int countAll() throws SystemException {
1666                    Object[] finderArgs = new Object[0];
1667    
1668                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1669                                    finderArgs, this);
1670    
1671                    if (count == null) {
1672                            Session session = null;
1673    
1674                            try {
1675                                    session = openSession();
1676    
1677                                    Query q = session.createQuery(_SQL_COUNT_LOCK);
1678    
1679                                    count = (Long)q.uniqueResult();
1680                            }
1681                            catch (Exception e) {
1682                                    throw processException(e);
1683                            }
1684                            finally {
1685                                    if (count == null) {
1686                                            count = Long.valueOf(0);
1687                                    }
1688    
1689                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1690                                            count);
1691    
1692                                    closeSession(session);
1693                            }
1694                    }
1695    
1696                    return count.intValue();
1697            }
1698    
1699            /**
1700             * Initializes the lock persistence.
1701             */
1702            public void afterPropertiesSet() {
1703                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1704                                            com.liferay.portal.util.PropsUtil.get(
1705                                                    "value.object.listener.com.liferay.portal.model.Lock")));
1706    
1707                    if (listenerClassNames.length > 0) {
1708                            try {
1709                                    List<ModelListener<Lock>> listenersList = new ArrayList<ModelListener<Lock>>();
1710    
1711                                    for (String listenerClassName : listenerClassNames) {
1712                                            listenersList.add((ModelListener<Lock>)InstanceFactory.newInstance(
1713                                                            listenerClassName));
1714                                    }
1715    
1716                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1717                            }
1718                            catch (Exception e) {
1719                                    _log.error(e);
1720                            }
1721                    }
1722            }
1723    
1724            public void destroy() {
1725                    EntityCacheUtil.removeCache(LockImpl.class.getName());
1726                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1727                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
1728            }
1729    
1730            @BeanReference(type = AccountPersistence.class)
1731            protected AccountPersistence accountPersistence;
1732            @BeanReference(type = AddressPersistence.class)
1733            protected AddressPersistence addressPersistence;
1734            @BeanReference(type = BrowserTrackerPersistence.class)
1735            protected BrowserTrackerPersistence browserTrackerPersistence;
1736            @BeanReference(type = ClassNamePersistence.class)
1737            protected ClassNamePersistence classNamePersistence;
1738            @BeanReference(type = ClusterGroupPersistence.class)
1739            protected ClusterGroupPersistence clusterGroupPersistence;
1740            @BeanReference(type = CompanyPersistence.class)
1741            protected CompanyPersistence companyPersistence;
1742            @BeanReference(type = ContactPersistence.class)
1743            protected ContactPersistence contactPersistence;
1744            @BeanReference(type = CountryPersistence.class)
1745            protected CountryPersistence countryPersistence;
1746            @BeanReference(type = EmailAddressPersistence.class)
1747            protected EmailAddressPersistence emailAddressPersistence;
1748            @BeanReference(type = GroupPersistence.class)
1749            protected GroupPersistence groupPersistence;
1750            @BeanReference(type = ImagePersistence.class)
1751            protected ImagePersistence imagePersistence;
1752            @BeanReference(type = LayoutPersistence.class)
1753            protected LayoutPersistence layoutPersistence;
1754            @BeanReference(type = LayoutPrototypePersistence.class)
1755            protected LayoutPrototypePersistence layoutPrototypePersistence;
1756            @BeanReference(type = LayoutSetPersistence.class)
1757            protected LayoutSetPersistence layoutSetPersistence;
1758            @BeanReference(type = LayoutSetPrototypePersistence.class)
1759            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1760            @BeanReference(type = ListTypePersistence.class)
1761            protected ListTypePersistence listTypePersistence;
1762            @BeanReference(type = LockPersistence.class)
1763            protected LockPersistence lockPersistence;
1764            @BeanReference(type = MembershipRequestPersistence.class)
1765            protected MembershipRequestPersistence membershipRequestPersistence;
1766            @BeanReference(type = OrganizationPersistence.class)
1767            protected OrganizationPersistence organizationPersistence;
1768            @BeanReference(type = OrgGroupPermissionPersistence.class)
1769            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1770            @BeanReference(type = OrgGroupRolePersistence.class)
1771            protected OrgGroupRolePersistence orgGroupRolePersistence;
1772            @BeanReference(type = OrgLaborPersistence.class)
1773            protected OrgLaborPersistence orgLaborPersistence;
1774            @BeanReference(type = PasswordPolicyPersistence.class)
1775            protected PasswordPolicyPersistence passwordPolicyPersistence;
1776            @BeanReference(type = PasswordPolicyRelPersistence.class)
1777            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1778            @BeanReference(type = PasswordTrackerPersistence.class)
1779            protected PasswordTrackerPersistence passwordTrackerPersistence;
1780            @BeanReference(type = PermissionPersistence.class)
1781            protected PermissionPersistence permissionPersistence;
1782            @BeanReference(type = PhonePersistence.class)
1783            protected PhonePersistence phonePersistence;
1784            @BeanReference(type = PluginSettingPersistence.class)
1785            protected PluginSettingPersistence pluginSettingPersistence;
1786            @BeanReference(type = PortletPersistence.class)
1787            protected PortletPersistence portletPersistence;
1788            @BeanReference(type = PortletItemPersistence.class)
1789            protected PortletItemPersistence portletItemPersistence;
1790            @BeanReference(type = PortletPreferencesPersistence.class)
1791            protected PortletPreferencesPersistence portletPreferencesPersistence;
1792            @BeanReference(type = RegionPersistence.class)
1793            protected RegionPersistence regionPersistence;
1794            @BeanReference(type = ReleasePersistence.class)
1795            protected ReleasePersistence releasePersistence;
1796            @BeanReference(type = ResourcePersistence.class)
1797            protected ResourcePersistence resourcePersistence;
1798            @BeanReference(type = ResourceActionPersistence.class)
1799            protected ResourceActionPersistence resourceActionPersistence;
1800            @BeanReference(type = ResourceCodePersistence.class)
1801            protected ResourceCodePersistence resourceCodePersistence;
1802            @BeanReference(type = ResourcePermissionPersistence.class)
1803            protected ResourcePermissionPersistence resourcePermissionPersistence;
1804            @BeanReference(type = RolePersistence.class)
1805            protected RolePersistence rolePersistence;
1806            @BeanReference(type = ServiceComponentPersistence.class)
1807            protected ServiceComponentPersistence serviceComponentPersistence;
1808            @BeanReference(type = ShardPersistence.class)
1809            protected ShardPersistence shardPersistence;
1810            @BeanReference(type = SubscriptionPersistence.class)
1811            protected SubscriptionPersistence subscriptionPersistence;
1812            @BeanReference(type = TicketPersistence.class)
1813            protected TicketPersistence ticketPersistence;
1814            @BeanReference(type = TeamPersistence.class)
1815            protected TeamPersistence teamPersistence;
1816            @BeanReference(type = UserPersistence.class)
1817            protected UserPersistence userPersistence;
1818            @BeanReference(type = UserGroupPersistence.class)
1819            protected UserGroupPersistence userGroupPersistence;
1820            @BeanReference(type = UserGroupGroupRolePersistence.class)
1821            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1822            @BeanReference(type = UserGroupRolePersistence.class)
1823            protected UserGroupRolePersistence userGroupRolePersistence;
1824            @BeanReference(type = UserIdMapperPersistence.class)
1825            protected UserIdMapperPersistence userIdMapperPersistence;
1826            @BeanReference(type = UserTrackerPersistence.class)
1827            protected UserTrackerPersistence userTrackerPersistence;
1828            @BeanReference(type = UserTrackerPathPersistence.class)
1829            protected UserTrackerPathPersistence userTrackerPathPersistence;
1830            @BeanReference(type = WebDAVPropsPersistence.class)
1831            protected WebDAVPropsPersistence webDAVPropsPersistence;
1832            @BeanReference(type = WebsitePersistence.class)
1833            protected WebsitePersistence websitePersistence;
1834            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1835            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1836            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1837            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1838            private static final String _SQL_SELECT_LOCK = "SELECT lock FROM Lock lock";
1839            private static final String _SQL_SELECT_LOCK_WHERE = "SELECT lock FROM Lock lock WHERE ";
1840            private static final String _SQL_COUNT_LOCK = "SELECT COUNT(lock) FROM Lock lock";
1841            private static final String _SQL_COUNT_LOCK_WHERE = "SELECT COUNT(lock) FROM Lock lock WHERE ";
1842            private static final String _FINDER_COLUMN_UUID_UUID_1 = "lock.uuid IS NULL";
1843            private static final String _FINDER_COLUMN_UUID_UUID_2 = "lock.uuid = ?";
1844            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(lock.uuid IS NULL OR lock.uuid = ?)";
1845            private static final String _FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_1 =
1846                    "lock.expirationDate < NULL";
1847            private static final String _FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_2 =
1848                    "lock.expirationDate < ?";
1849            private static final String _FINDER_COLUMN_C_K_CLASSNAME_1 = "lock.className IS NULL AND ";
1850            private static final String _FINDER_COLUMN_C_K_CLASSNAME_2 = "lock.className = ? AND ";
1851            private static final String _FINDER_COLUMN_C_K_CLASSNAME_3 = "(lock.className IS NULL OR lock.className = ?) AND ";
1852            private static final String _FINDER_COLUMN_C_K_KEY_1 = "lock.key IS NULL";
1853            private static final String _FINDER_COLUMN_C_K_KEY_2 = "lock.key = ?";
1854            private static final String _FINDER_COLUMN_C_K_KEY_3 = "(lock.key IS NULL OR lock.key = ?)";
1855            private static final String _ORDER_BY_ENTITY_ALIAS = "lock.";
1856            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Lock exists with the primary key ";
1857            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Lock exists with the key {";
1858            private static Log _log = LogFactoryUtil.getLog(LockPersistenceImpl.class);
1859    }