001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.NoSuchLockException;
018    import com.liferay.portal.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[] { lockModelImpl.getClassName(), lockModelImpl.getKey() });
262    
263                    EntityCacheUtil.removeResult(LockModelImpl.ENTITY_CACHE_ENABLED,
264                            LockImpl.class, lock.getPrimaryKey());
265    
266                    return lock;
267            }
268    
269            public Lock updateImpl(com.liferay.portal.model.Lock lock, boolean merge)
270                    throws SystemException {
271                    lock = toUnwrappedModel(lock);
272    
273                    boolean isNew = lock.isNew();
274    
275                    LockModelImpl lockModelImpl = (LockModelImpl)lock;
276    
277                    if (Validator.isNull(lock.getUuid())) {
278                            String uuid = PortalUUIDUtil.generate();
279    
280                            lock.setUuid(uuid);
281                    }
282    
283                    Session session = null;
284    
285                    try {
286                            session = openSession();
287    
288                            BatchSessionUtil.update(session, lock, merge);
289    
290                            lock.setNew(false);
291                    }
292                    catch (Exception e) {
293                            throw processException(e);
294                    }
295                    finally {
296                            closeSession(session);
297                    }
298    
299                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
300    
301                    EntityCacheUtil.putResult(LockModelImpl.ENTITY_CACHE_ENABLED,
302                            LockImpl.class, lock.getPrimaryKey(), lock);
303    
304                    if (!isNew &&
305                                    (!Validator.equals(lock.getClassName(),
306                                            lockModelImpl.getOriginalClassName()) ||
307                                    !Validator.equals(lock.getKey(), lockModelImpl.getOriginalKey()))) {
308                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_K,
309                                    new Object[] {
310                                            lockModelImpl.getOriginalClassName(),
311                                            
312                                    lockModelImpl.getOriginalKey()
313                                    });
314                    }
315    
316                    if (isNew ||
317                                    (!Validator.equals(lock.getClassName(),
318                                            lockModelImpl.getOriginalClassName()) ||
319                                    !Validator.equals(lock.getKey(), lockModelImpl.getOriginalKey()))) {
320                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K,
321                                    new Object[] { lock.getClassName(), lock.getKey() }, lock);
322                    }
323    
324                    return lock;
325            }
326    
327            protected Lock toUnwrappedModel(Lock lock) {
328                    if (lock instanceof LockImpl) {
329                            return lock;
330                    }
331    
332                    LockImpl lockImpl = new LockImpl();
333    
334                    lockImpl.setNew(lock.isNew());
335                    lockImpl.setPrimaryKey(lock.getPrimaryKey());
336    
337                    lockImpl.setUuid(lock.getUuid());
338                    lockImpl.setLockId(lock.getLockId());
339                    lockImpl.setCompanyId(lock.getCompanyId());
340                    lockImpl.setUserId(lock.getUserId());
341                    lockImpl.setUserName(lock.getUserName());
342                    lockImpl.setCreateDate(lock.getCreateDate());
343                    lockImpl.setClassName(lock.getClassName());
344                    lockImpl.setKey(lock.getKey());
345                    lockImpl.setOwner(lock.getOwner());
346                    lockImpl.setInheritable(lock.isInheritable());
347                    lockImpl.setExpirationDate(lock.getExpirationDate());
348    
349                    return lockImpl;
350            }
351    
352            /**
353             * Finds the lock with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
354             *
355             * @param primaryKey the primary key of the lock to find
356             * @return the lock
357             * @throws com.liferay.portal.NoSuchModelException if a lock with the primary key could not be found
358             * @throws SystemException if a system exception occurred
359             */
360            public Lock findByPrimaryKey(Serializable primaryKey)
361                    throws NoSuchModelException, SystemException {
362                    return findByPrimaryKey(((Long)primaryKey).longValue());
363            }
364    
365            /**
366             * Finds the lock with the primary key or throws a {@link com.liferay.portal.NoSuchLockException} if it could not be found.
367             *
368             * @param lockId the primary key of the lock to find
369             * @return the lock
370             * @throws com.liferay.portal.NoSuchLockException if a lock with the primary key could not be found
371             * @throws SystemException if a system exception occurred
372             */
373            public Lock findByPrimaryKey(long lockId)
374                    throws NoSuchLockException, SystemException {
375                    Lock lock = fetchByPrimaryKey(lockId);
376    
377                    if (lock == null) {
378                            if (_log.isWarnEnabled()) {
379                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + lockId);
380                            }
381    
382                            throw new NoSuchLockException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
383                                    lockId);
384                    }
385    
386                    return lock;
387            }
388    
389            /**
390             * Finds the lock with the primary key or returns <code>null</code> if it could not be found.
391             *
392             * @param primaryKey the primary key of the lock to find
393             * @return the lock, or <code>null</code> if a lock with the primary key could not be found
394             * @throws SystemException if a system exception occurred
395             */
396            public Lock fetchByPrimaryKey(Serializable primaryKey)
397                    throws SystemException {
398                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
399            }
400    
401            /**
402             * Finds the lock with the primary key or returns <code>null</code> if it could not be found.
403             *
404             * @param lockId the primary key of the lock to find
405             * @return the lock, or <code>null</code> if a lock with the primary key could not be found
406             * @throws SystemException if a system exception occurred
407             */
408            public Lock fetchByPrimaryKey(long lockId) throws SystemException {
409                    Lock lock = (Lock)EntityCacheUtil.getResult(LockModelImpl.ENTITY_CACHE_ENABLED,
410                                    LockImpl.class, lockId, this);
411    
412                    if (lock == null) {
413                            Session session = null;
414    
415                            try {
416                                    session = openSession();
417    
418                                    lock = (Lock)session.get(LockImpl.class, new Long(lockId));
419                            }
420                            catch (Exception e) {
421                                    throw processException(e);
422                            }
423                            finally {
424                                    if (lock != null) {
425                                            cacheResult(lock);
426                                    }
427    
428                                    closeSession(session);
429                            }
430                    }
431    
432                    return lock;
433            }
434    
435            /**
436             * Finds all the locks where uuid = &#63;.
437             *
438             * @param uuid the uuid to search with
439             * @return the matching locks
440             * @throws SystemException if a system exception occurred
441             */
442            public List<Lock> findByUuid(String uuid) throws SystemException {
443                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
444            }
445    
446            /**
447             * Finds a range of all the locks where uuid = &#63;.
448             *
449             * <p>
450             * 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.
451             * </p>
452             *
453             * @param uuid the uuid to search with
454             * @param start the lower bound of the range of locks to return
455             * @param end the upper bound of the range of locks to return (not inclusive)
456             * @return the range of matching locks
457             * @throws SystemException if a system exception occurred
458             */
459            public List<Lock> findByUuid(String uuid, int start, int end)
460                    throws SystemException {
461                    return findByUuid(uuid, start, end, null);
462            }
463    
464            /**
465             * Finds an ordered range of all the locks where uuid = &#63;.
466             *
467             * <p>
468             * 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.
469             * </p>
470             *
471             * @param uuid the uuid to search with
472             * @param start the lower bound of the range of locks to return
473             * @param end the upper bound of the range of locks to return (not inclusive)
474             * @param orderByComparator the comparator to order the results by
475             * @return the ordered range of matching locks
476             * @throws SystemException if a system exception occurred
477             */
478            public List<Lock> findByUuid(String uuid, int start, int end,
479                    OrderByComparator orderByComparator) throws SystemException {
480                    Object[] finderArgs = new Object[] {
481                                    uuid,
482                                    
483                                    String.valueOf(start), String.valueOf(end),
484                                    String.valueOf(orderByComparator)
485                            };
486    
487                    List<Lock> list = (List<Lock>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
488                                    finderArgs, this);
489    
490                    if (list == null) {
491                            StringBundler query = null;
492    
493                            if (orderByComparator != null) {
494                                    query = new StringBundler(3 +
495                                                    (orderByComparator.getOrderByFields().length * 3));
496                            }
497                            else {
498                                    query = new StringBundler(2);
499                            }
500    
501                            query.append(_SQL_SELECT_LOCK_WHERE);
502    
503                            if (uuid == null) {
504                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
505                            }
506                            else {
507                                    if (uuid.equals(StringPool.BLANK)) {
508                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
509                                    }
510                                    else {
511                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
512                                    }
513                            }
514    
515                            if (orderByComparator != null) {
516                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
517                                            orderByComparator);
518                            }
519    
520                            String sql = query.toString();
521    
522                            Session session = null;
523    
524                            try {
525                                    session = openSession();
526    
527                                    Query q = session.createQuery(sql);
528    
529                                    QueryPos qPos = QueryPos.getInstance(q);
530    
531                                    if (uuid != null) {
532                                            qPos.add(uuid);
533                                    }
534    
535                                    list = (List<Lock>)QueryUtil.list(q, getDialect(), start, end);
536                            }
537                            catch (Exception e) {
538                                    throw processException(e);
539                            }
540                            finally {
541                                    if (list == null) {
542                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_UUID,
543                                                    finderArgs);
544                                    }
545                                    else {
546                                            cacheResult(list);
547    
548                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID,
549                                                    finderArgs, list);
550                                    }
551    
552                                    closeSession(session);
553                            }
554                    }
555    
556                    return list;
557            }
558    
559            /**
560             * Finds the first lock in the ordered set where uuid = &#63;.
561             *
562             * <p>
563             * 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.
564             * </p>
565             *
566             * @param uuid the uuid to search with
567             * @param orderByComparator the comparator to order the set by
568             * @return the first matching lock
569             * @throws com.liferay.portal.NoSuchLockException if a matching lock could not be found
570             * @throws SystemException if a system exception occurred
571             */
572            public Lock findByUuid_First(String uuid,
573                    OrderByComparator orderByComparator)
574                    throws NoSuchLockException, SystemException {
575                    List<Lock> list = findByUuid(uuid, 0, 1, orderByComparator);
576    
577                    if (list.isEmpty()) {
578                            StringBundler msg = new StringBundler(4);
579    
580                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
581    
582                            msg.append("uuid=");
583                            msg.append(uuid);
584    
585                            msg.append(StringPool.CLOSE_CURLY_BRACE);
586    
587                            throw new NoSuchLockException(msg.toString());
588                    }
589                    else {
590                            return list.get(0);
591                    }
592            }
593    
594            /**
595             * Finds the last lock in the ordered set where uuid = &#63;.
596             *
597             * <p>
598             * 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.
599             * </p>
600             *
601             * @param uuid the uuid to search with
602             * @param orderByComparator the comparator to order the set by
603             * @return the last matching lock
604             * @throws com.liferay.portal.NoSuchLockException if a matching lock could not be found
605             * @throws SystemException if a system exception occurred
606             */
607            public Lock findByUuid_Last(String uuid, OrderByComparator orderByComparator)
608                    throws NoSuchLockException, SystemException {
609                    int count = countByUuid(uuid);
610    
611                    List<Lock> list = findByUuid(uuid, count - 1, count, orderByComparator);
612    
613                    if (list.isEmpty()) {
614                            StringBundler msg = new StringBundler(4);
615    
616                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
617    
618                            msg.append("uuid=");
619                            msg.append(uuid);
620    
621                            msg.append(StringPool.CLOSE_CURLY_BRACE);
622    
623                            throw new NoSuchLockException(msg.toString());
624                    }
625                    else {
626                            return list.get(0);
627                    }
628            }
629    
630            /**
631             * Finds the locks before and after the current lock in the ordered set where uuid = &#63;.
632             *
633             * <p>
634             * 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.
635             * </p>
636             *
637             * @param lockId the primary key of the current lock
638             * @param uuid the uuid to search with
639             * @param orderByComparator the comparator to order the set by
640             * @return the previous, current, and next lock
641             * @throws com.liferay.portal.NoSuchLockException if a lock with the primary key could not be found
642             * @throws SystemException if a system exception occurred
643             */
644            public Lock[] findByUuid_PrevAndNext(long lockId, String uuid,
645                    OrderByComparator orderByComparator)
646                    throws NoSuchLockException, SystemException {
647                    Lock lock = findByPrimaryKey(lockId);
648    
649                    Session session = null;
650    
651                    try {
652                            session = openSession();
653    
654                            Lock[] array = new LockImpl[3];
655    
656                            array[0] = getByUuid_PrevAndNext(session, lock, uuid,
657                                            orderByComparator, true);
658    
659                            array[1] = lock;
660    
661                            array[2] = getByUuid_PrevAndNext(session, lock, uuid,
662                                            orderByComparator, false);
663    
664                            return array;
665                    }
666                    catch (Exception e) {
667                            throw processException(e);
668                    }
669                    finally {
670                            closeSession(session);
671                    }
672            }
673    
674            protected Lock getByUuid_PrevAndNext(Session session, Lock lock,
675                    String uuid, OrderByComparator orderByComparator, boolean previous) {
676                    StringBundler query = null;
677    
678                    if (orderByComparator != null) {
679                            query = new StringBundler(6 +
680                                            (orderByComparator.getOrderByFields().length * 6));
681                    }
682                    else {
683                            query = new StringBundler(3);
684                    }
685    
686                    query.append(_SQL_SELECT_LOCK_WHERE);
687    
688                    if (uuid == null) {
689                            query.append(_FINDER_COLUMN_UUID_UUID_1);
690                    }
691                    else {
692                            if (uuid.equals(StringPool.BLANK)) {
693                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
694                            }
695                            else {
696                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
697                            }
698                    }
699    
700                    if (orderByComparator != null) {
701                            String[] orderByFields = orderByComparator.getOrderByFields();
702    
703                            if (orderByFields.length > 0) {
704                                    query.append(WHERE_AND);
705                            }
706    
707                            for (int i = 0; i < orderByFields.length; i++) {
708                                    query.append(_ORDER_BY_ENTITY_ALIAS);
709                                    query.append(orderByFields[i]);
710    
711                                    if ((i + 1) < orderByFields.length) {
712                                            if (orderByComparator.isAscending() ^ previous) {
713                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
714                                            }
715                                            else {
716                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
717                                            }
718                                    }
719                                    else {
720                                            if (orderByComparator.isAscending() ^ previous) {
721                                                    query.append(WHERE_GREATER_THAN);
722                                            }
723                                            else {
724                                                    query.append(WHERE_LESSER_THAN);
725                                            }
726                                    }
727                            }
728    
729                            query.append(ORDER_BY_CLAUSE);
730    
731                            for (int i = 0; i < orderByFields.length; i++) {
732                                    query.append(_ORDER_BY_ENTITY_ALIAS);
733                                    query.append(orderByFields[i]);
734    
735                                    if ((i + 1) < orderByFields.length) {
736                                            if (orderByComparator.isAscending() ^ previous) {
737                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
738                                            }
739                                            else {
740                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
741                                            }
742                                    }
743                                    else {
744                                            if (orderByComparator.isAscending() ^ previous) {
745                                                    query.append(ORDER_BY_ASC);
746                                            }
747                                            else {
748                                                    query.append(ORDER_BY_DESC);
749                                            }
750                                    }
751                            }
752                    }
753    
754                    String sql = query.toString();
755    
756                    Query q = session.createQuery(sql);
757    
758                    q.setFirstResult(0);
759                    q.setMaxResults(2);
760    
761                    QueryPos qPos = QueryPos.getInstance(q);
762    
763                    if (uuid != null) {
764                            qPos.add(uuid);
765                    }
766    
767                    if (orderByComparator != null) {
768                            Object[] values = orderByComparator.getOrderByValues(lock);
769    
770                            for (Object value : values) {
771                                    qPos.add(value);
772                            }
773                    }
774    
775                    List<Lock> list = q.list();
776    
777                    if (list.size() == 2) {
778                            return list.get(1);
779                    }
780                    else {
781                            return null;
782                    }
783            }
784    
785            /**
786             * Finds all the locks where expirationDate &lt; &#63;.
787             *
788             * @param expirationDate the expiration date to search with
789             * @return the matching locks
790             * @throws SystemException if a system exception occurred
791             */
792            public List<Lock> findByLtExpirationDate(Date expirationDate)
793                    throws SystemException {
794                    return findByLtExpirationDate(expirationDate, QueryUtil.ALL_POS,
795                            QueryUtil.ALL_POS, null);
796            }
797    
798            /**
799             * Finds a range of all the locks where expirationDate &lt; &#63;.
800             *
801             * <p>
802             * 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.
803             * </p>
804             *
805             * @param expirationDate the expiration date to search with
806             * @param start the lower bound of the range of locks to return
807             * @param end the upper bound of the range of locks to return (not inclusive)
808             * @return the range of matching locks
809             * @throws SystemException if a system exception occurred
810             */
811            public List<Lock> findByLtExpirationDate(Date expirationDate, int start,
812                    int end) throws SystemException {
813                    return findByLtExpirationDate(expirationDate, start, end, null);
814            }
815    
816            /**
817             * Finds an ordered range of all the locks where expirationDate &lt; &#63;.
818             *
819             * <p>
820             * 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.
821             * </p>
822             *
823             * @param expirationDate the expiration date to search with
824             * @param start the lower bound of the range of locks to return
825             * @param end the upper bound of the range of locks to return (not inclusive)
826             * @param orderByComparator the comparator to order the results by
827             * @return the ordered range of matching locks
828             * @throws SystemException if a system exception occurred
829             */
830            public List<Lock> findByLtExpirationDate(Date expirationDate, int start,
831                    int end, OrderByComparator orderByComparator) throws SystemException {
832                    Object[] finderArgs = new Object[] {
833                                    expirationDate,
834                                    
835                                    String.valueOf(start), String.valueOf(end),
836                                    String.valueOf(orderByComparator)
837                            };
838    
839                    List<Lock> list = (List<Lock>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_LTEXPIRATIONDATE,
840                                    finderArgs, this);
841    
842                    if (list == null) {
843                            StringBundler query = null;
844    
845                            if (orderByComparator != null) {
846                                    query = new StringBundler(3 +
847                                                    (orderByComparator.getOrderByFields().length * 3));
848                            }
849                            else {
850                                    query = new StringBundler(2);
851                            }
852    
853                            query.append(_SQL_SELECT_LOCK_WHERE);
854    
855                            if (expirationDate == null) {
856                                    query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_1);
857                            }
858                            else {
859                                    query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_2);
860                            }
861    
862                            if (orderByComparator != null) {
863                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
864                                            orderByComparator);
865                            }
866    
867                            String sql = query.toString();
868    
869                            Session session = null;
870    
871                            try {
872                                    session = openSession();
873    
874                                    Query q = session.createQuery(sql);
875    
876                                    QueryPos qPos = QueryPos.getInstance(q);
877    
878                                    if (expirationDate != null) {
879                                            qPos.add(CalendarUtil.getTimestamp(expirationDate));
880                                    }
881    
882                                    list = (List<Lock>)QueryUtil.list(q, getDialect(), start, end);
883                            }
884                            catch (Exception e) {
885                                    throw processException(e);
886                            }
887                            finally {
888                                    if (list == null) {
889                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_LTEXPIRATIONDATE,
890                                                    finderArgs);
891                                    }
892                                    else {
893                                            cacheResult(list);
894    
895                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_LTEXPIRATIONDATE,
896                                                    finderArgs, list);
897                                    }
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                            StringBundler query = new StringBundler(3);
1201    
1202                            query.append(_SQL_SELECT_LOCK_WHERE);
1203    
1204                            if (className == null) {
1205                                    query.append(_FINDER_COLUMN_C_K_CLASSNAME_1);
1206                            }
1207                            else {
1208                                    if (className.equals(StringPool.BLANK)) {
1209                                            query.append(_FINDER_COLUMN_C_K_CLASSNAME_3);
1210                                    }
1211                                    else {
1212                                            query.append(_FINDER_COLUMN_C_K_CLASSNAME_2);
1213                                    }
1214                            }
1215    
1216                            if (key == null) {
1217                                    query.append(_FINDER_COLUMN_C_K_KEY_1);
1218                            }
1219                            else {
1220                                    if (key.equals(StringPool.BLANK)) {
1221                                            query.append(_FINDER_COLUMN_C_K_KEY_3);
1222                                    }
1223                                    else {
1224                                            query.append(_FINDER_COLUMN_C_K_KEY_2);
1225                                    }
1226                            }
1227    
1228                            String sql = query.toString();
1229    
1230                            Session session = null;
1231    
1232                            try {
1233                                    session = openSession();
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.removeResult(FINDER_PATH_FETCH_BY_C_K,
1279                                                    finderArgs);
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                            StringBundler query = null;
1346                            String sql = null;
1347    
1348                            if (orderByComparator != null) {
1349                                    query = new StringBundler(2 +
1350                                                    (orderByComparator.getOrderByFields().length * 3));
1351    
1352                                    query.append(_SQL_SELECT_LOCK);
1353    
1354                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1355                                            orderByComparator);
1356    
1357                                    sql = query.toString();
1358                            }
1359                            else {
1360                                    sql = _SQL_SELECT_LOCK;
1361                            }
1362    
1363                            Session session = null;
1364    
1365                            try {
1366                                    session = openSession();
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                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_ALL,
1387                                                    finderArgs);
1388                                    }
1389                                    else {
1390                                            cacheResult(list);
1391    
1392                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs,
1393                                                    list);
1394                                    }
1395    
1396                                    closeSession(session);
1397                            }
1398                    }
1399    
1400                    return list;
1401            }
1402    
1403            /**
1404             * Removes all the locks where uuid = &#63; from the database.
1405             *
1406             * @param uuid the uuid to search with
1407             * @throws SystemException if a system exception occurred
1408             */
1409            public void removeByUuid(String uuid) throws SystemException {
1410                    for (Lock lock : findByUuid(uuid)) {
1411                            remove(lock);
1412                    }
1413            }
1414    
1415            /**
1416             * Removes all the locks where expirationDate &lt; &#63; from the database.
1417             *
1418             * @param expirationDate the expiration date to search with
1419             * @throws SystemException if a system exception occurred
1420             */
1421            public void removeByLtExpirationDate(Date expirationDate)
1422                    throws SystemException {
1423                    for (Lock lock : findByLtExpirationDate(expirationDate)) {
1424                            remove(lock);
1425                    }
1426            }
1427    
1428            /**
1429             * Removes the lock where className = &#63; and key = &#63; from the database.
1430             *
1431             * @param className the class name to search with
1432             * @param key the key to search with
1433             * @throws SystemException if a system exception occurred
1434             */
1435            public void removeByC_K(String className, String key)
1436                    throws NoSuchLockException, SystemException {
1437                    Lock lock = findByC_K(className, key);
1438    
1439                    remove(lock);
1440            }
1441    
1442            /**
1443             * Removes all the locks from the database.
1444             *
1445             * @throws SystemException if a system exception occurred
1446             */
1447            public void removeAll() throws SystemException {
1448                    for (Lock lock : findAll()) {
1449                            remove(lock);
1450                    }
1451            }
1452    
1453            /**
1454             * Counts all the locks where uuid = &#63;.
1455             *
1456             * @param uuid the uuid to search with
1457             * @return the number of matching locks
1458             * @throws SystemException if a system exception occurred
1459             */
1460            public int countByUuid(String uuid) throws SystemException {
1461                    Object[] finderArgs = new Object[] { uuid };
1462    
1463                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1464                                    finderArgs, this);
1465    
1466                    if (count == null) {
1467                            StringBundler query = new StringBundler(2);
1468    
1469                            query.append(_SQL_COUNT_LOCK_WHERE);
1470    
1471                            if (uuid == null) {
1472                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
1473                            }
1474                            else {
1475                                    if (uuid.equals(StringPool.BLANK)) {
1476                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
1477                                    }
1478                                    else {
1479                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
1480                                    }
1481                            }
1482    
1483                            String sql = query.toString();
1484    
1485                            Session session = null;
1486    
1487                            try {
1488                                    session = openSession();
1489    
1490                                    Query q = session.createQuery(sql);
1491    
1492                                    QueryPos qPos = QueryPos.getInstance(q);
1493    
1494                                    if (uuid != null) {
1495                                            qPos.add(uuid);
1496                                    }
1497    
1498                                    count = (Long)q.uniqueResult();
1499                            }
1500                            catch (Exception e) {
1501                                    throw processException(e);
1502                            }
1503                            finally {
1504                                    if (count == null) {
1505                                            count = Long.valueOf(0);
1506                                    }
1507    
1508                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
1509                                            finderArgs, count);
1510    
1511                                    closeSession(session);
1512                            }
1513                    }
1514    
1515                    return count.intValue();
1516            }
1517    
1518            /**
1519             * Counts all the locks where expirationDate &lt; &#63;.
1520             *
1521             * @param expirationDate the expiration date to search with
1522             * @return the number of matching locks
1523             * @throws SystemException if a system exception occurred
1524             */
1525            public int countByLtExpirationDate(Date expirationDate)
1526                    throws SystemException {
1527                    Object[] finderArgs = new Object[] { expirationDate };
1528    
1529                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_LTEXPIRATIONDATE,
1530                                    finderArgs, this);
1531    
1532                    if (count == null) {
1533                            StringBundler query = new StringBundler(2);
1534    
1535                            query.append(_SQL_COUNT_LOCK_WHERE);
1536    
1537                            if (expirationDate == null) {
1538                                    query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_1);
1539                            }
1540                            else {
1541                                    query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_2);
1542                            }
1543    
1544                            String sql = query.toString();
1545    
1546                            Session session = null;
1547    
1548                            try {
1549                                    session = openSession();
1550    
1551                                    Query q = session.createQuery(sql);
1552    
1553                                    QueryPos qPos = QueryPos.getInstance(q);
1554    
1555                                    if (expirationDate != null) {
1556                                            qPos.add(CalendarUtil.getTimestamp(expirationDate));
1557                                    }
1558    
1559                                    count = (Long)q.uniqueResult();
1560                            }
1561                            catch (Exception e) {
1562                                    throw processException(e);
1563                            }
1564                            finally {
1565                                    if (count == null) {
1566                                            count = Long.valueOf(0);
1567                                    }
1568    
1569                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_LTEXPIRATIONDATE,
1570                                            finderArgs, count);
1571    
1572                                    closeSession(session);
1573                            }
1574                    }
1575    
1576                    return count.intValue();
1577            }
1578    
1579            /**
1580             * Counts all the locks where className = &#63; and key = &#63;.
1581             *
1582             * @param className the class name to search with
1583             * @param key the key to search with
1584             * @return the number of matching locks
1585             * @throws SystemException if a system exception occurred
1586             */
1587            public int countByC_K(String className, String key)
1588                    throws SystemException {
1589                    Object[] finderArgs = new Object[] { className, key };
1590    
1591                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_K,
1592                                    finderArgs, this);
1593    
1594                    if (count == null) {
1595                            StringBundler query = new StringBundler(3);
1596    
1597                            query.append(_SQL_COUNT_LOCK_WHERE);
1598    
1599                            if (className == null) {
1600                                    query.append(_FINDER_COLUMN_C_K_CLASSNAME_1);
1601                            }
1602                            else {
1603                                    if (className.equals(StringPool.BLANK)) {
1604                                            query.append(_FINDER_COLUMN_C_K_CLASSNAME_3);
1605                                    }
1606                                    else {
1607                                            query.append(_FINDER_COLUMN_C_K_CLASSNAME_2);
1608                                    }
1609                            }
1610    
1611                            if (key == null) {
1612                                    query.append(_FINDER_COLUMN_C_K_KEY_1);
1613                            }
1614                            else {
1615                                    if (key.equals(StringPool.BLANK)) {
1616                                            query.append(_FINDER_COLUMN_C_K_KEY_3);
1617                                    }
1618                                    else {
1619                                            query.append(_FINDER_COLUMN_C_K_KEY_2);
1620                                    }
1621                            }
1622    
1623                            String sql = query.toString();
1624    
1625                            Session session = null;
1626    
1627                            try {
1628                                    session = openSession();
1629    
1630                                    Query q = session.createQuery(sql);
1631    
1632                                    QueryPos qPos = QueryPos.getInstance(q);
1633    
1634                                    if (className != null) {
1635                                            qPos.add(className);
1636                                    }
1637    
1638                                    if (key != null) {
1639                                            qPos.add(key);
1640                                    }
1641    
1642                                    count = (Long)q.uniqueResult();
1643                            }
1644                            catch (Exception e) {
1645                                    throw processException(e);
1646                            }
1647                            finally {
1648                                    if (count == null) {
1649                                            count = Long.valueOf(0);
1650                                    }
1651    
1652                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_K, finderArgs,
1653                                            count);
1654    
1655                                    closeSession(session);
1656                            }
1657                    }
1658    
1659                    return count.intValue();
1660            }
1661    
1662            /**
1663             * Counts all the locks.
1664             *
1665             * @return the number of locks
1666             * @throws SystemException if a system exception occurred
1667             */
1668            public int countAll() throws SystemException {
1669                    Object[] finderArgs = new Object[0];
1670    
1671                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1672                                    finderArgs, this);
1673    
1674                    if (count == null) {
1675                            Session session = null;
1676    
1677                            try {
1678                                    session = openSession();
1679    
1680                                    Query q = session.createQuery(_SQL_COUNT_LOCK);
1681    
1682                                    count = (Long)q.uniqueResult();
1683                            }
1684                            catch (Exception e) {
1685                                    throw processException(e);
1686                            }
1687                            finally {
1688                                    if (count == null) {
1689                                            count = Long.valueOf(0);
1690                                    }
1691    
1692                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1693                                            count);
1694    
1695                                    closeSession(session);
1696                            }
1697                    }
1698    
1699                    return count.intValue();
1700            }
1701    
1702            /**
1703             * Initializes the lock persistence.
1704             */
1705            public void afterPropertiesSet() {
1706                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1707                                            com.liferay.portal.util.PropsUtil.get(
1708                                                    "value.object.listener.com.liferay.portal.model.Lock")));
1709    
1710                    if (listenerClassNames.length > 0) {
1711                            try {
1712                                    List<ModelListener<Lock>> listenersList = new ArrayList<ModelListener<Lock>>();
1713    
1714                                    for (String listenerClassName : listenerClassNames) {
1715                                            listenersList.add((ModelListener<Lock>)InstanceFactory.newInstance(
1716                                                            listenerClassName));
1717                                    }
1718    
1719                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1720                            }
1721                            catch (Exception e) {
1722                                    _log.error(e);
1723                            }
1724                    }
1725            }
1726    
1727            public void destroy() {
1728                    EntityCacheUtil.removeCache(LockImpl.class.getName());
1729                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1730                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
1731            }
1732    
1733            @BeanReference(type = AccountPersistence.class)
1734            protected AccountPersistence accountPersistence;
1735            @BeanReference(type = AddressPersistence.class)
1736            protected AddressPersistence addressPersistence;
1737            @BeanReference(type = BrowserTrackerPersistence.class)
1738            protected BrowserTrackerPersistence browserTrackerPersistence;
1739            @BeanReference(type = ClassNamePersistence.class)
1740            protected ClassNamePersistence classNamePersistence;
1741            @BeanReference(type = ClusterGroupPersistence.class)
1742            protected ClusterGroupPersistence clusterGroupPersistence;
1743            @BeanReference(type = CompanyPersistence.class)
1744            protected CompanyPersistence companyPersistence;
1745            @BeanReference(type = ContactPersistence.class)
1746            protected ContactPersistence contactPersistence;
1747            @BeanReference(type = CountryPersistence.class)
1748            protected CountryPersistence countryPersistence;
1749            @BeanReference(type = EmailAddressPersistence.class)
1750            protected EmailAddressPersistence emailAddressPersistence;
1751            @BeanReference(type = GroupPersistence.class)
1752            protected GroupPersistence groupPersistence;
1753            @BeanReference(type = ImagePersistence.class)
1754            protected ImagePersistence imagePersistence;
1755            @BeanReference(type = LayoutPersistence.class)
1756            protected LayoutPersistence layoutPersistence;
1757            @BeanReference(type = LayoutPrototypePersistence.class)
1758            protected LayoutPrototypePersistence layoutPrototypePersistence;
1759            @BeanReference(type = LayoutSetPersistence.class)
1760            protected LayoutSetPersistence layoutSetPersistence;
1761            @BeanReference(type = LayoutSetPrototypePersistence.class)
1762            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1763            @BeanReference(type = ListTypePersistence.class)
1764            protected ListTypePersistence listTypePersistence;
1765            @BeanReference(type = LockPersistence.class)
1766            protected LockPersistence lockPersistence;
1767            @BeanReference(type = MembershipRequestPersistence.class)
1768            protected MembershipRequestPersistence membershipRequestPersistence;
1769            @BeanReference(type = OrganizationPersistence.class)
1770            protected OrganizationPersistence organizationPersistence;
1771            @BeanReference(type = OrgGroupPermissionPersistence.class)
1772            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1773            @BeanReference(type = OrgGroupRolePersistence.class)
1774            protected OrgGroupRolePersistence orgGroupRolePersistence;
1775            @BeanReference(type = OrgLaborPersistence.class)
1776            protected OrgLaborPersistence orgLaborPersistence;
1777            @BeanReference(type = PasswordPolicyPersistence.class)
1778            protected PasswordPolicyPersistence passwordPolicyPersistence;
1779            @BeanReference(type = PasswordPolicyRelPersistence.class)
1780            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1781            @BeanReference(type = PasswordTrackerPersistence.class)
1782            protected PasswordTrackerPersistence passwordTrackerPersistence;
1783            @BeanReference(type = PermissionPersistence.class)
1784            protected PermissionPersistence permissionPersistence;
1785            @BeanReference(type = PhonePersistence.class)
1786            protected PhonePersistence phonePersistence;
1787            @BeanReference(type = PluginSettingPersistence.class)
1788            protected PluginSettingPersistence pluginSettingPersistence;
1789            @BeanReference(type = PortletPersistence.class)
1790            protected PortletPersistence portletPersistence;
1791            @BeanReference(type = PortletItemPersistence.class)
1792            protected PortletItemPersistence portletItemPersistence;
1793            @BeanReference(type = PortletPreferencesPersistence.class)
1794            protected PortletPreferencesPersistence portletPreferencesPersistence;
1795            @BeanReference(type = RegionPersistence.class)
1796            protected RegionPersistence regionPersistence;
1797            @BeanReference(type = ReleasePersistence.class)
1798            protected ReleasePersistence releasePersistence;
1799            @BeanReference(type = ResourcePersistence.class)
1800            protected ResourcePersistence resourcePersistence;
1801            @BeanReference(type = ResourceActionPersistence.class)
1802            protected ResourceActionPersistence resourceActionPersistence;
1803            @BeanReference(type = ResourceCodePersistence.class)
1804            protected ResourceCodePersistence resourceCodePersistence;
1805            @BeanReference(type = ResourcePermissionPersistence.class)
1806            protected ResourcePermissionPersistence resourcePermissionPersistence;
1807            @BeanReference(type = RolePersistence.class)
1808            protected RolePersistence rolePersistence;
1809            @BeanReference(type = ServiceComponentPersistence.class)
1810            protected ServiceComponentPersistence serviceComponentPersistence;
1811            @BeanReference(type = ShardPersistence.class)
1812            protected ShardPersistence shardPersistence;
1813            @BeanReference(type = SubscriptionPersistence.class)
1814            protected SubscriptionPersistence subscriptionPersistence;
1815            @BeanReference(type = TicketPersistence.class)
1816            protected TicketPersistence ticketPersistence;
1817            @BeanReference(type = TeamPersistence.class)
1818            protected TeamPersistence teamPersistence;
1819            @BeanReference(type = UserPersistence.class)
1820            protected UserPersistence userPersistence;
1821            @BeanReference(type = UserGroupPersistence.class)
1822            protected UserGroupPersistence userGroupPersistence;
1823            @BeanReference(type = UserGroupGroupRolePersistence.class)
1824            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1825            @BeanReference(type = UserGroupRolePersistence.class)
1826            protected UserGroupRolePersistence userGroupRolePersistence;
1827            @BeanReference(type = UserIdMapperPersistence.class)
1828            protected UserIdMapperPersistence userIdMapperPersistence;
1829            @BeanReference(type = UserTrackerPersistence.class)
1830            protected UserTrackerPersistence userTrackerPersistence;
1831            @BeanReference(type = UserTrackerPathPersistence.class)
1832            protected UserTrackerPathPersistence userTrackerPathPersistence;
1833            @BeanReference(type = WebDAVPropsPersistence.class)
1834            protected WebDAVPropsPersistence webDAVPropsPersistence;
1835            @BeanReference(type = WebsitePersistence.class)
1836            protected WebsitePersistence websitePersistence;
1837            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1838            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1839            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1840            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1841            private static final String _SQL_SELECT_LOCK = "SELECT lock FROM Lock lock";
1842            private static final String _SQL_SELECT_LOCK_WHERE = "SELECT lock FROM Lock lock WHERE ";
1843            private static final String _SQL_COUNT_LOCK = "SELECT COUNT(lock) FROM Lock lock";
1844            private static final String _SQL_COUNT_LOCK_WHERE = "SELECT COUNT(lock) FROM Lock lock WHERE ";
1845            private static final String _FINDER_COLUMN_UUID_UUID_1 = "lock.uuid IS NULL";
1846            private static final String _FINDER_COLUMN_UUID_UUID_2 = "lock.uuid = ?";
1847            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(lock.uuid IS NULL OR lock.uuid = ?)";
1848            private static final String _FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_1 =
1849                    "lock.expirationDate < NULL";
1850            private static final String _FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_2 =
1851                    "lock.expirationDate < ?";
1852            private static final String _FINDER_COLUMN_C_K_CLASSNAME_1 = "lock.className IS NULL AND ";
1853            private static final String _FINDER_COLUMN_C_K_CLASSNAME_2 = "lock.className = ? AND ";
1854            private static final String _FINDER_COLUMN_C_K_CLASSNAME_3 = "(lock.className IS NULL OR lock.className = ?) AND ";
1855            private static final String _FINDER_COLUMN_C_K_KEY_1 = "lock.key IS NULL";
1856            private static final String _FINDER_COLUMN_C_K_KEY_2 = "lock.key = ?";
1857            private static final String _FINDER_COLUMN_C_K_KEY_3 = "(lock.key IS NULL OR lock.key = ?)";
1858            private static final String _ORDER_BY_ENTITY_ALIAS = "lock.";
1859            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Lock exists with the primary key ";
1860            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Lock exists with the key {";
1861            private static Log _log = LogFactoryUtil.getLog(LockPersistenceImpl.class);
1862    }