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