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