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