001    /**
002     * Copyright (c) 2000-2012 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.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.CalendarUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.kernel.util.UnmodifiableList;
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_ALL = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
079                            LockModelImpl.FINDER_CACHE_ENABLED, LockImpl.class,
080                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
081            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
082                            LockModelImpl.FINDER_CACHE_ENABLED, LockImpl.class,
083                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
084            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
085                            LockModelImpl.FINDER_CACHE_ENABLED, Long.class,
086                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
087            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
088                            LockModelImpl.FINDER_CACHE_ENABLED, LockImpl.class,
089                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
090                            new String[] {
091                                    String.class.getName(),
092                                    
093                            Integer.class.getName(), Integer.class.getName(),
094                                    OrderByComparator.class.getName()
095                            });
096            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
097                            LockModelImpl.FINDER_CACHE_ENABLED, LockImpl.class,
098                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
099                            new String[] { String.class.getName() },
100                            LockModelImpl.UUID_COLUMN_BITMASK);
101            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
102                            LockModelImpl.FINDER_CACHE_ENABLED, Long.class,
103                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
104                            new String[] { String.class.getName() });
105    
106            /**
107             * Returns all the locks where uuid = &#63;.
108             *
109             * @param uuid the uuid
110             * @return the matching locks
111             * @throws SystemException if a system exception occurred
112             */
113            public List<Lock> findByUuid(String uuid) throws SystemException {
114                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
115            }
116    
117            /**
118             * Returns a range of all the locks where uuid = &#63;.
119             *
120             * <p>
121             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.LockModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
122             * </p>
123             *
124             * @param uuid the uuid
125             * @param start the lower bound of the range of locks
126             * @param end the upper bound of the range of locks (not inclusive)
127             * @return the range of matching locks
128             * @throws SystemException if a system exception occurred
129             */
130            public List<Lock> findByUuid(String uuid, int start, int end)
131                    throws SystemException {
132                    return findByUuid(uuid, start, end, null);
133            }
134    
135            /**
136             * Returns an ordered range of all the locks where uuid = &#63;.
137             *
138             * <p>
139             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.LockModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
140             * </p>
141             *
142             * @param uuid the uuid
143             * @param start the lower bound of the range of locks
144             * @param end the upper bound of the range of locks (not inclusive)
145             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
146             * @return the ordered range of matching locks
147             * @throws SystemException if a system exception occurred
148             */
149            public List<Lock> findByUuid(String uuid, int start, int end,
150                    OrderByComparator orderByComparator) throws SystemException {
151                    boolean pagination = true;
152                    FinderPath finderPath = null;
153                    Object[] finderArgs = null;
154    
155                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
156                                    (orderByComparator == null)) {
157                            pagination = false;
158                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
159                            finderArgs = new Object[] { uuid };
160                    }
161                    else {
162                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
163                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
164                    }
165    
166                    List<Lock> list = (List<Lock>)FinderCacheUtil.getResult(finderPath,
167                                    finderArgs, this);
168    
169                    if ((list != null) && !list.isEmpty()) {
170                            for (Lock lock : list) {
171                                    if (!Validator.equals(uuid, lock.getUuid())) {
172                                            list = null;
173    
174                                            break;
175                                    }
176                            }
177                    }
178    
179                    if (list == null) {
180                            StringBundler query = null;
181    
182                            if (orderByComparator != null) {
183                                    query = new StringBundler(3 +
184                                                    (orderByComparator.getOrderByFields().length * 3));
185                            }
186                            else {
187                                    query = new StringBundler(3);
188                            }
189    
190                            query.append(_SQL_SELECT_LOCK_WHERE);
191    
192                            if (uuid == null) {
193                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
194                            }
195                            else {
196                                    if (uuid.equals(StringPool.BLANK)) {
197                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
198                                    }
199                                    else {
200                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
201                                    }
202                            }
203    
204                            if (orderByComparator != null) {
205                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
206                                            orderByComparator);
207                            }
208                            else
209                             if (pagination) {
210                                    query.append(LockModelImpl.ORDER_BY_JPQL);
211                            }
212    
213                            String sql = query.toString();
214    
215                            Session session = null;
216    
217                            try {
218                                    session = openSession();
219    
220                                    Query q = session.createQuery(sql);
221    
222                                    QueryPos qPos = QueryPos.getInstance(q);
223    
224                                    if (uuid != null) {
225                                            qPos.add(uuid);
226                                    }
227    
228                                    if (!pagination) {
229                                            list = (List<Lock>)QueryUtil.list(q, getDialect(), start,
230                                                            end, false);
231    
232                                            Collections.sort(list);
233    
234                                            list = new UnmodifiableList<Lock>(list);
235                                    }
236                                    else {
237                                            list = (List<Lock>)QueryUtil.list(q, getDialect(), start,
238                                                            end);
239                                    }
240    
241                                    cacheResult(list);
242    
243                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
244                            }
245                            catch (Exception e) {
246                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
247    
248                                    throw processException(e);
249                            }
250                            finally {
251                                    closeSession(session);
252                            }
253                    }
254    
255                    return list;
256            }
257    
258            /**
259             * Returns the first lock in the ordered set where uuid = &#63;.
260             *
261             * @param uuid the uuid
262             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
263             * @return the first matching lock
264             * @throws com.liferay.portal.NoSuchLockException if a matching lock could not be found
265             * @throws SystemException if a system exception occurred
266             */
267            public Lock findByUuid_First(String uuid,
268                    OrderByComparator orderByComparator)
269                    throws NoSuchLockException, SystemException {
270                    Lock lock = fetchByUuid_First(uuid, orderByComparator);
271    
272                    if (lock != null) {
273                            return lock;
274                    }
275    
276                    StringBundler msg = new StringBundler(4);
277    
278                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
279    
280                    msg.append("uuid=");
281                    msg.append(uuid);
282    
283                    msg.append(StringPool.CLOSE_CURLY_BRACE);
284    
285                    throw new NoSuchLockException(msg.toString());
286            }
287    
288            /**
289             * Returns the first lock in the ordered set where uuid = &#63;.
290             *
291             * @param uuid the uuid
292             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
293             * @return the first matching lock, or <code>null</code> if a matching lock could not be found
294             * @throws SystemException if a system exception occurred
295             */
296            public Lock fetchByUuid_First(String uuid,
297                    OrderByComparator orderByComparator) throws SystemException {
298                    List<Lock> list = findByUuid(uuid, 0, 1, orderByComparator);
299    
300                    if (!list.isEmpty()) {
301                            return list.get(0);
302                    }
303    
304                    return null;
305            }
306    
307            /**
308             * Returns the last lock in the ordered set where uuid = &#63;.
309             *
310             * @param uuid the uuid
311             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
312             * @return the last matching lock
313             * @throws com.liferay.portal.NoSuchLockException if a matching lock could not be found
314             * @throws SystemException if a system exception occurred
315             */
316            public Lock findByUuid_Last(String uuid, OrderByComparator orderByComparator)
317                    throws NoSuchLockException, SystemException {
318                    Lock lock = fetchByUuid_Last(uuid, orderByComparator);
319    
320                    if (lock != null) {
321                            return lock;
322                    }
323    
324                    StringBundler msg = new StringBundler(4);
325    
326                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
327    
328                    msg.append("uuid=");
329                    msg.append(uuid);
330    
331                    msg.append(StringPool.CLOSE_CURLY_BRACE);
332    
333                    throw new NoSuchLockException(msg.toString());
334            }
335    
336            /**
337             * Returns the last lock in the ordered set where uuid = &#63;.
338             *
339             * @param uuid the uuid
340             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
341             * @return the last matching lock, or <code>null</code> if a matching lock could not be found
342             * @throws SystemException if a system exception occurred
343             */
344            public Lock fetchByUuid_Last(String uuid,
345                    OrderByComparator orderByComparator) throws SystemException {
346                    int count = countByUuid(uuid);
347    
348                    List<Lock> list = findByUuid(uuid, count - 1, count, orderByComparator);
349    
350                    if (!list.isEmpty()) {
351                            return list.get(0);
352                    }
353    
354                    return null;
355            }
356    
357            /**
358             * Returns the locks before and after the current lock in the ordered set where uuid = &#63;.
359             *
360             * @param lockId the primary key of the current lock
361             * @param uuid the uuid
362             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
363             * @return the previous, current, and next lock
364             * @throws com.liferay.portal.NoSuchLockException if a lock with the primary key could not be found
365             * @throws SystemException if a system exception occurred
366             */
367            public Lock[] findByUuid_PrevAndNext(long lockId, String uuid,
368                    OrderByComparator orderByComparator)
369                    throws NoSuchLockException, SystemException {
370                    Lock lock = findByPrimaryKey(lockId);
371    
372                    Session session = null;
373    
374                    try {
375                            session = openSession();
376    
377                            Lock[] array = new LockImpl[3];
378    
379                            array[0] = getByUuid_PrevAndNext(session, lock, uuid,
380                                            orderByComparator, true);
381    
382                            array[1] = lock;
383    
384                            array[2] = getByUuid_PrevAndNext(session, lock, uuid,
385                                            orderByComparator, false);
386    
387                            return array;
388                    }
389                    catch (Exception e) {
390                            throw processException(e);
391                    }
392                    finally {
393                            closeSession(session);
394                    }
395            }
396    
397            protected Lock getByUuid_PrevAndNext(Session session, Lock lock,
398                    String uuid, OrderByComparator orderByComparator, boolean previous) {
399                    StringBundler query = null;
400    
401                    if (orderByComparator != null) {
402                            query = new StringBundler(6 +
403                                            (orderByComparator.getOrderByFields().length * 6));
404                    }
405                    else {
406                            query = new StringBundler(3);
407                    }
408    
409                    query.append(_SQL_SELECT_LOCK_WHERE);
410    
411                    if (uuid == null) {
412                            query.append(_FINDER_COLUMN_UUID_UUID_1);
413                    }
414                    else {
415                            if (uuid.equals(StringPool.BLANK)) {
416                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
417                            }
418                            else {
419                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
420                            }
421                    }
422    
423                    if (orderByComparator != null) {
424                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
425    
426                            if (orderByConditionFields.length > 0) {
427                                    query.append(WHERE_AND);
428                            }
429    
430                            for (int i = 0; i < orderByConditionFields.length; i++) {
431                                    query.append(_ORDER_BY_ENTITY_ALIAS);
432                                    query.append(orderByConditionFields[i]);
433    
434                                    if ((i + 1) < orderByConditionFields.length) {
435                                            if (orderByComparator.isAscending() ^ previous) {
436                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
437                                            }
438                                            else {
439                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
440                                            }
441                                    }
442                                    else {
443                                            if (orderByComparator.isAscending() ^ previous) {
444                                                    query.append(WHERE_GREATER_THAN);
445                                            }
446                                            else {
447                                                    query.append(WHERE_LESSER_THAN);
448                                            }
449                                    }
450                            }
451    
452                            query.append(ORDER_BY_CLAUSE);
453    
454                            String[] orderByFields = orderByComparator.getOrderByFields();
455    
456                            for (int i = 0; i < orderByFields.length; i++) {
457                                    query.append(_ORDER_BY_ENTITY_ALIAS);
458                                    query.append(orderByFields[i]);
459    
460                                    if ((i + 1) < orderByFields.length) {
461                                            if (orderByComparator.isAscending() ^ previous) {
462                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
463                                            }
464                                            else {
465                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
466                                            }
467                                    }
468                                    else {
469                                            if (orderByComparator.isAscending() ^ previous) {
470                                                    query.append(ORDER_BY_ASC);
471                                            }
472                                            else {
473                                                    query.append(ORDER_BY_DESC);
474                                            }
475                                    }
476                            }
477                    }
478                    else {
479                            query.append(LockModelImpl.ORDER_BY_JPQL);
480                    }
481    
482                    String sql = query.toString();
483    
484                    Query q = session.createQuery(sql);
485    
486                    q.setFirstResult(0);
487                    q.setMaxResults(2);
488    
489                    QueryPos qPos = QueryPos.getInstance(q);
490    
491                    if (uuid != null) {
492                            qPos.add(uuid);
493                    }
494    
495                    if (orderByComparator != null) {
496                            Object[] values = orderByComparator.getOrderByConditionValues(lock);
497    
498                            for (Object value : values) {
499                                    qPos.add(value);
500                            }
501                    }
502    
503                    List<Lock> list = q.list();
504    
505                    if (list.size() == 2) {
506                            return list.get(1);
507                    }
508                    else {
509                            return null;
510                    }
511            }
512    
513            /**
514             * Removes all the locks where uuid = &#63; from the database.
515             *
516             * @param uuid the uuid
517             * @throws SystemException if a system exception occurred
518             */
519            public void removeByUuid(String uuid) throws SystemException {
520                    for (Lock lock : findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
521                                    null)) {
522                            remove(lock);
523                    }
524            }
525    
526            /**
527             * Returns the number of locks where uuid = &#63;.
528             *
529             * @param uuid the uuid
530             * @return the number of matching locks
531             * @throws SystemException if a system exception occurred
532             */
533            public int countByUuid(String uuid) throws SystemException {
534                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
535    
536                    Object[] finderArgs = new Object[] { uuid };
537    
538                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
539                                    this);
540    
541                    if (count == null) {
542                            StringBundler query = new StringBundler(2);
543    
544                            query.append(_SQL_COUNT_LOCK_WHERE);
545    
546                            if (uuid == null) {
547                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
548                            }
549                            else {
550                                    if (uuid.equals(StringPool.BLANK)) {
551                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
552                                    }
553                                    else {
554                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
555                                    }
556                            }
557    
558                            String sql = query.toString();
559    
560                            Session session = null;
561    
562                            try {
563                                    session = openSession();
564    
565                                    Query q = session.createQuery(sql);
566    
567                                    QueryPos qPos = QueryPos.getInstance(q);
568    
569                                    if (uuid != null) {
570                                            qPos.add(uuid);
571                                    }
572    
573                                    count = (Long)q.uniqueResult();
574    
575                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
576                            }
577                            catch (Exception e) {
578                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
579    
580                                    throw processException(e);
581                            }
582                            finally {
583                                    closeSession(session);
584                            }
585                    }
586    
587                    return count.intValue();
588            }
589    
590            private static final String _FINDER_COLUMN_UUID_UUID_1 = "lock.uuid IS NULL";
591            private static final String _FINDER_COLUMN_UUID_UUID_2 = "lock.uuid = ?";
592            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(lock.uuid IS NULL OR lock.uuid = ?)";
593            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
594                            LockModelImpl.FINDER_CACHE_ENABLED, LockImpl.class,
595                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
596                            new String[] {
597                                    String.class.getName(), Long.class.getName(),
598                                    
599                            Integer.class.getName(), Integer.class.getName(),
600                                    OrderByComparator.class.getName()
601                            });
602            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
603                    new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
604                            LockModelImpl.FINDER_CACHE_ENABLED, LockImpl.class,
605                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
606                            new String[] { String.class.getName(), Long.class.getName() },
607                            LockModelImpl.UUID_COLUMN_BITMASK |
608                            LockModelImpl.COMPANYID_COLUMN_BITMASK);
609            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
610                            LockModelImpl.FINDER_CACHE_ENABLED, Long.class,
611                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
612                            new String[] { String.class.getName(), Long.class.getName() });
613    
614            /**
615             * Returns all the locks where uuid = &#63; and companyId = &#63;.
616             *
617             * @param uuid the uuid
618             * @param companyId the company ID
619             * @return the matching locks
620             * @throws SystemException if a system exception occurred
621             */
622            public List<Lock> findByUuid_C(String uuid, long companyId)
623                    throws SystemException {
624                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
625                            QueryUtil.ALL_POS, null);
626            }
627    
628            /**
629             * Returns a range of all the locks where uuid = &#63; and companyId = &#63;.
630             *
631             * <p>
632             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.LockModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
633             * </p>
634             *
635             * @param uuid the uuid
636             * @param companyId the company ID
637             * @param start the lower bound of the range of locks
638             * @param end the upper bound of the range of locks (not inclusive)
639             * @return the range of matching locks
640             * @throws SystemException if a system exception occurred
641             */
642            public List<Lock> findByUuid_C(String uuid, long companyId, int start,
643                    int end) throws SystemException {
644                    return findByUuid_C(uuid, companyId, start, end, null);
645            }
646    
647            /**
648             * Returns an ordered range of all the locks where uuid = &#63; and companyId = &#63;.
649             *
650             * <p>
651             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.LockModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
652             * </p>
653             *
654             * @param uuid the uuid
655             * @param companyId the company ID
656             * @param start the lower bound of the range of locks
657             * @param end the upper bound of the range of locks (not inclusive)
658             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
659             * @return the ordered range of matching locks
660             * @throws SystemException if a system exception occurred
661             */
662            public List<Lock> findByUuid_C(String uuid, long companyId, int start,
663                    int end, OrderByComparator orderByComparator) throws SystemException {
664                    boolean pagination = true;
665                    FinderPath finderPath = null;
666                    Object[] finderArgs = null;
667    
668                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
669                                    (orderByComparator == null)) {
670                            pagination = false;
671                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
672                            finderArgs = new Object[] { uuid, companyId };
673                    }
674                    else {
675                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
676                            finderArgs = new Object[] {
677                                            uuid, companyId,
678                                            
679                                            start, end, orderByComparator
680                                    };
681                    }
682    
683                    List<Lock> list = (List<Lock>)FinderCacheUtil.getResult(finderPath,
684                                    finderArgs, this);
685    
686                    if ((list != null) && !list.isEmpty()) {
687                            for (Lock lock : list) {
688                                    if (!Validator.equals(uuid, lock.getUuid()) ||
689                                                    (companyId != lock.getCompanyId())) {
690                                            list = null;
691    
692                                            break;
693                                    }
694                            }
695                    }
696    
697                    if (list == null) {
698                            StringBundler query = null;
699    
700                            if (orderByComparator != null) {
701                                    query = new StringBundler(4 +
702                                                    (orderByComparator.getOrderByFields().length * 3));
703                            }
704                            else {
705                                    query = new StringBundler(4);
706                            }
707    
708                            query.append(_SQL_SELECT_LOCK_WHERE);
709    
710                            if (uuid == null) {
711                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
712                            }
713                            else {
714                                    if (uuid.equals(StringPool.BLANK)) {
715                                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
716                                    }
717                                    else {
718                                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
719                                    }
720                            }
721    
722                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
723    
724                            if (orderByComparator != null) {
725                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
726                                            orderByComparator);
727                            }
728                            else
729                             if (pagination) {
730                                    query.append(LockModelImpl.ORDER_BY_JPQL);
731                            }
732    
733                            String sql = query.toString();
734    
735                            Session session = null;
736    
737                            try {
738                                    session = openSession();
739    
740                                    Query q = session.createQuery(sql);
741    
742                                    QueryPos qPos = QueryPos.getInstance(q);
743    
744                                    if (uuid != null) {
745                                            qPos.add(uuid);
746                                    }
747    
748                                    qPos.add(companyId);
749    
750                                    if (!pagination) {
751                                            list = (List<Lock>)QueryUtil.list(q, getDialect(), start,
752                                                            end, false);
753    
754                                            Collections.sort(list);
755    
756                                            list = new UnmodifiableList<Lock>(list);
757                                    }
758                                    else {
759                                            list = (List<Lock>)QueryUtil.list(q, getDialect(), start,
760                                                            end);
761                                    }
762    
763                                    cacheResult(list);
764    
765                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
766                            }
767                            catch (Exception e) {
768                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
769    
770                                    throw processException(e);
771                            }
772                            finally {
773                                    closeSession(session);
774                            }
775                    }
776    
777                    return list;
778            }
779    
780            /**
781             * Returns the first lock in the ordered set where uuid = &#63; and companyId = &#63;.
782             *
783             * @param uuid the uuid
784             * @param companyId the company ID
785             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
786             * @return the first matching lock
787             * @throws com.liferay.portal.NoSuchLockException if a matching lock could not be found
788             * @throws SystemException if a system exception occurred
789             */
790            public Lock findByUuid_C_First(String uuid, long companyId,
791                    OrderByComparator orderByComparator)
792                    throws NoSuchLockException, SystemException {
793                    Lock lock = fetchByUuid_C_First(uuid, companyId, orderByComparator);
794    
795                    if (lock != null) {
796                            return lock;
797                    }
798    
799                    StringBundler msg = new StringBundler(6);
800    
801                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
802    
803                    msg.append("uuid=");
804                    msg.append(uuid);
805    
806                    msg.append(", companyId=");
807                    msg.append(companyId);
808    
809                    msg.append(StringPool.CLOSE_CURLY_BRACE);
810    
811                    throw new NoSuchLockException(msg.toString());
812            }
813    
814            /**
815             * Returns the first lock in the ordered set where uuid = &#63; and companyId = &#63;.
816             *
817             * @param uuid the uuid
818             * @param companyId the company ID
819             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
820             * @return the first matching lock, or <code>null</code> if a matching lock could not be found
821             * @throws SystemException if a system exception occurred
822             */
823            public Lock fetchByUuid_C_First(String uuid, long companyId,
824                    OrderByComparator orderByComparator) throws SystemException {
825                    List<Lock> list = findByUuid_C(uuid, companyId, 0, 1, orderByComparator);
826    
827                    if (!list.isEmpty()) {
828                            return list.get(0);
829                    }
830    
831                    return null;
832            }
833    
834            /**
835             * Returns the last lock in the ordered set where uuid = &#63; and companyId = &#63;.
836             *
837             * @param uuid the uuid
838             * @param companyId the company ID
839             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
840             * @return the last matching lock
841             * @throws com.liferay.portal.NoSuchLockException if a matching lock could not be found
842             * @throws SystemException if a system exception occurred
843             */
844            public Lock findByUuid_C_Last(String uuid, long companyId,
845                    OrderByComparator orderByComparator)
846                    throws NoSuchLockException, SystemException {
847                    Lock lock = fetchByUuid_C_Last(uuid, companyId, orderByComparator);
848    
849                    if (lock != null) {
850                            return lock;
851                    }
852    
853                    StringBundler msg = new StringBundler(6);
854    
855                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
856    
857                    msg.append("uuid=");
858                    msg.append(uuid);
859    
860                    msg.append(", companyId=");
861                    msg.append(companyId);
862    
863                    msg.append(StringPool.CLOSE_CURLY_BRACE);
864    
865                    throw new NoSuchLockException(msg.toString());
866            }
867    
868            /**
869             * Returns the last lock in the ordered set where uuid = &#63; and companyId = &#63;.
870             *
871             * @param uuid the uuid
872             * @param companyId the company ID
873             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
874             * @return the last matching lock, or <code>null</code> if a matching lock could not be found
875             * @throws SystemException if a system exception occurred
876             */
877            public Lock fetchByUuid_C_Last(String uuid, long companyId,
878                    OrderByComparator orderByComparator) throws SystemException {
879                    int count = countByUuid_C(uuid, companyId);
880    
881                    List<Lock> list = findByUuid_C(uuid, companyId, count - 1, count,
882                                    orderByComparator);
883    
884                    if (!list.isEmpty()) {
885                            return list.get(0);
886                    }
887    
888                    return null;
889            }
890    
891            /**
892             * Returns the locks before and after the current lock in the ordered set where uuid = &#63; and companyId = &#63;.
893             *
894             * @param lockId the primary key of the current lock
895             * @param uuid the uuid
896             * @param companyId the company ID
897             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
898             * @return the previous, current, and next lock
899             * @throws com.liferay.portal.NoSuchLockException if a lock with the primary key could not be found
900             * @throws SystemException if a system exception occurred
901             */
902            public Lock[] findByUuid_C_PrevAndNext(long lockId, String uuid,
903                    long companyId, OrderByComparator orderByComparator)
904                    throws NoSuchLockException, SystemException {
905                    Lock lock = findByPrimaryKey(lockId);
906    
907                    Session session = null;
908    
909                    try {
910                            session = openSession();
911    
912                            Lock[] array = new LockImpl[3];
913    
914                            array[0] = getByUuid_C_PrevAndNext(session, lock, uuid, companyId,
915                                            orderByComparator, true);
916    
917                            array[1] = lock;
918    
919                            array[2] = getByUuid_C_PrevAndNext(session, lock, uuid, companyId,
920                                            orderByComparator, false);
921    
922                            return array;
923                    }
924                    catch (Exception e) {
925                            throw processException(e);
926                    }
927                    finally {
928                            closeSession(session);
929                    }
930            }
931    
932            protected Lock getByUuid_C_PrevAndNext(Session session, Lock lock,
933                    String uuid, long companyId, OrderByComparator orderByComparator,
934                    boolean previous) {
935                    StringBundler query = null;
936    
937                    if (orderByComparator != null) {
938                            query = new StringBundler(6 +
939                                            (orderByComparator.getOrderByFields().length * 6));
940                    }
941                    else {
942                            query = new StringBundler(3);
943                    }
944    
945                    query.append(_SQL_SELECT_LOCK_WHERE);
946    
947                    if (uuid == null) {
948                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
949                    }
950                    else {
951                            if (uuid.equals(StringPool.BLANK)) {
952                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
953                            }
954                            else {
955                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
956                            }
957                    }
958    
959                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
960    
961                    if (orderByComparator != null) {
962                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
963    
964                            if (orderByConditionFields.length > 0) {
965                                    query.append(WHERE_AND);
966                            }
967    
968                            for (int i = 0; i < orderByConditionFields.length; i++) {
969                                    query.append(_ORDER_BY_ENTITY_ALIAS);
970                                    query.append(orderByConditionFields[i]);
971    
972                                    if ((i + 1) < orderByConditionFields.length) {
973                                            if (orderByComparator.isAscending() ^ previous) {
974                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
975                                            }
976                                            else {
977                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
978                                            }
979                                    }
980                                    else {
981                                            if (orderByComparator.isAscending() ^ previous) {
982                                                    query.append(WHERE_GREATER_THAN);
983                                            }
984                                            else {
985                                                    query.append(WHERE_LESSER_THAN);
986                                            }
987                                    }
988                            }
989    
990                            query.append(ORDER_BY_CLAUSE);
991    
992                            String[] orderByFields = orderByComparator.getOrderByFields();
993    
994                            for (int i = 0; i < orderByFields.length; i++) {
995                                    query.append(_ORDER_BY_ENTITY_ALIAS);
996                                    query.append(orderByFields[i]);
997    
998                                    if ((i + 1) < orderByFields.length) {
999                                            if (orderByComparator.isAscending() ^ previous) {
1000                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1001                                            }
1002                                            else {
1003                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1004                                            }
1005                                    }
1006                                    else {
1007                                            if (orderByComparator.isAscending() ^ previous) {
1008                                                    query.append(ORDER_BY_ASC);
1009                                            }
1010                                            else {
1011                                                    query.append(ORDER_BY_DESC);
1012                                            }
1013                                    }
1014                            }
1015                    }
1016                    else {
1017                            query.append(LockModelImpl.ORDER_BY_JPQL);
1018                    }
1019    
1020                    String sql = query.toString();
1021    
1022                    Query q = session.createQuery(sql);
1023    
1024                    q.setFirstResult(0);
1025                    q.setMaxResults(2);
1026    
1027                    QueryPos qPos = QueryPos.getInstance(q);
1028    
1029                    if (uuid != null) {
1030                            qPos.add(uuid);
1031                    }
1032    
1033                    qPos.add(companyId);
1034    
1035                    if (orderByComparator != null) {
1036                            Object[] values = orderByComparator.getOrderByConditionValues(lock);
1037    
1038                            for (Object value : values) {
1039                                    qPos.add(value);
1040                            }
1041                    }
1042    
1043                    List<Lock> list = q.list();
1044    
1045                    if (list.size() == 2) {
1046                            return list.get(1);
1047                    }
1048                    else {
1049                            return null;
1050                    }
1051            }
1052    
1053            /**
1054             * Removes all the locks where uuid = &#63; and companyId = &#63; from the database.
1055             *
1056             * @param uuid the uuid
1057             * @param companyId the company ID
1058             * @throws SystemException if a system exception occurred
1059             */
1060            public void removeByUuid_C(String uuid, long companyId)
1061                    throws SystemException {
1062                    for (Lock lock : findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1063                                    QueryUtil.ALL_POS, null)) {
1064                            remove(lock);
1065                    }
1066            }
1067    
1068            /**
1069             * Returns the number of locks where uuid = &#63; and companyId = &#63;.
1070             *
1071             * @param uuid the uuid
1072             * @param companyId the company ID
1073             * @return the number of matching locks
1074             * @throws SystemException if a system exception occurred
1075             */
1076            public int countByUuid_C(String uuid, long companyId)
1077                    throws SystemException {
1078                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1079    
1080                    Object[] finderArgs = new Object[] { uuid, companyId };
1081    
1082                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1083                                    this);
1084    
1085                    if (count == null) {
1086                            StringBundler query = new StringBundler(3);
1087    
1088                            query.append(_SQL_COUNT_LOCK_WHERE);
1089    
1090                            if (uuid == null) {
1091                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1092                            }
1093                            else {
1094                                    if (uuid.equals(StringPool.BLANK)) {
1095                                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1096                                    }
1097                                    else {
1098                                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1099                                    }
1100                            }
1101    
1102                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1103    
1104                            String sql = query.toString();
1105    
1106                            Session session = null;
1107    
1108                            try {
1109                                    session = openSession();
1110    
1111                                    Query q = session.createQuery(sql);
1112    
1113                                    QueryPos qPos = QueryPos.getInstance(q);
1114    
1115                                    if (uuid != null) {
1116                                            qPos.add(uuid);
1117                                    }
1118    
1119                                    qPos.add(companyId);
1120    
1121                                    count = (Long)q.uniqueResult();
1122    
1123                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1124                            }
1125                            catch (Exception e) {
1126                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1127    
1128                                    throw processException(e);
1129                            }
1130                            finally {
1131                                    closeSession(session);
1132                            }
1133                    }
1134    
1135                    return count.intValue();
1136            }
1137    
1138            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "lock.uuid IS NULL AND ";
1139            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "lock.uuid = ? AND ";
1140            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(lock.uuid IS NULL OR lock.uuid = ?) AND ";
1141            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "lock.companyId = ?";
1142            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_LTEXPIRATIONDATE =
1143                    new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
1144                            LockModelImpl.FINDER_CACHE_ENABLED, LockImpl.class,
1145                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByLtExpirationDate",
1146                            new String[] {
1147                                    Date.class.getName(),
1148                                    
1149                            Integer.class.getName(), Integer.class.getName(),
1150                                    OrderByComparator.class.getName()
1151                            });
1152            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_LTEXPIRATIONDATE =
1153                    new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
1154                            LockModelImpl.FINDER_CACHE_ENABLED, Long.class,
1155                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByLtExpirationDate",
1156                            new String[] { Date.class.getName() });
1157    
1158            /**
1159             * Returns all the locks where expirationDate &lt; &#63;.
1160             *
1161             * @param expirationDate the expiration date
1162             * @return the matching locks
1163             * @throws SystemException if a system exception occurred
1164             */
1165            public List<Lock> findByLtExpirationDate(Date expirationDate)
1166                    throws SystemException {
1167                    return findByLtExpirationDate(expirationDate, QueryUtil.ALL_POS,
1168                            QueryUtil.ALL_POS, null);
1169            }
1170    
1171            /**
1172             * Returns a range of all the locks where expirationDate &lt; &#63;.
1173             *
1174             * <p>
1175             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.LockModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1176             * </p>
1177             *
1178             * @param expirationDate the expiration date
1179             * @param start the lower bound of the range of locks
1180             * @param end the upper bound of the range of locks (not inclusive)
1181             * @return the range of matching locks
1182             * @throws SystemException if a system exception occurred
1183             */
1184            public List<Lock> findByLtExpirationDate(Date expirationDate, int start,
1185                    int end) throws SystemException {
1186                    return findByLtExpirationDate(expirationDate, start, end, null);
1187            }
1188    
1189            /**
1190             * Returns an ordered range of all the locks where expirationDate &lt; &#63;.
1191             *
1192             * <p>
1193             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.LockModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1194             * </p>
1195             *
1196             * @param expirationDate the expiration date
1197             * @param start the lower bound of the range of locks
1198             * @param end the upper bound of the range of locks (not inclusive)
1199             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1200             * @return the ordered range of matching locks
1201             * @throws SystemException if a system exception occurred
1202             */
1203            public List<Lock> findByLtExpirationDate(Date expirationDate, int start,
1204                    int end, OrderByComparator orderByComparator) throws SystemException {
1205                    boolean pagination = true;
1206                    FinderPath finderPath = null;
1207                    Object[] finderArgs = null;
1208    
1209                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_LTEXPIRATIONDATE;
1210                    finderArgs = new Object[] { expirationDate, start, end, orderByComparator };
1211    
1212                    List<Lock> list = (List<Lock>)FinderCacheUtil.getResult(finderPath,
1213                                    finderArgs, this);
1214    
1215                    if ((list != null) && !list.isEmpty()) {
1216                            for (Lock lock : list) {
1217                                    if (!Validator.equals(expirationDate, lock.getExpirationDate())) {
1218                                            list = null;
1219    
1220                                            break;
1221                                    }
1222                            }
1223                    }
1224    
1225                    if (list == null) {
1226                            StringBundler query = null;
1227    
1228                            if (orderByComparator != null) {
1229                                    query = new StringBundler(3 +
1230                                                    (orderByComparator.getOrderByFields().length * 3));
1231                            }
1232                            else {
1233                                    query = new StringBundler(3);
1234                            }
1235    
1236                            query.append(_SQL_SELECT_LOCK_WHERE);
1237    
1238                            if (expirationDate == null) {
1239                                    query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_1);
1240                            }
1241                            else {
1242                                    query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_2);
1243                            }
1244    
1245                            if (orderByComparator != null) {
1246                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1247                                            orderByComparator);
1248                            }
1249                            else
1250                             if (pagination) {
1251                                    query.append(LockModelImpl.ORDER_BY_JPQL);
1252                            }
1253    
1254                            String sql = query.toString();
1255    
1256                            Session session = null;
1257    
1258                            try {
1259                                    session = openSession();
1260    
1261                                    Query q = session.createQuery(sql);
1262    
1263                                    QueryPos qPos = QueryPos.getInstance(q);
1264    
1265                                    if (expirationDate != null) {
1266                                            qPos.add(CalendarUtil.getTimestamp(expirationDate));
1267                                    }
1268    
1269                                    if (!pagination) {
1270                                            list = (List<Lock>)QueryUtil.list(q, getDialect(), start,
1271                                                            end, false);
1272    
1273                                            Collections.sort(list);
1274    
1275                                            list = new UnmodifiableList<Lock>(list);
1276                                    }
1277                                    else {
1278                                            list = (List<Lock>)QueryUtil.list(q, getDialect(), start,
1279                                                            end);
1280                                    }
1281    
1282                                    cacheResult(list);
1283    
1284                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1285                            }
1286                            catch (Exception e) {
1287                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1288    
1289                                    throw processException(e);
1290                            }
1291                            finally {
1292                                    closeSession(session);
1293                            }
1294                    }
1295    
1296                    return list;
1297            }
1298    
1299            /**
1300             * Returns the first lock in the ordered set where expirationDate &lt; &#63;.
1301             *
1302             * @param expirationDate the expiration date
1303             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1304             * @return the first matching lock
1305             * @throws com.liferay.portal.NoSuchLockException if a matching lock could not be found
1306             * @throws SystemException if a system exception occurred
1307             */
1308            public Lock findByLtExpirationDate_First(Date expirationDate,
1309                    OrderByComparator orderByComparator)
1310                    throws NoSuchLockException, SystemException {
1311                    Lock lock = fetchByLtExpirationDate_First(expirationDate,
1312                                    orderByComparator);
1313    
1314                    if (lock != null) {
1315                            return lock;
1316                    }
1317    
1318                    StringBundler msg = new StringBundler(4);
1319    
1320                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1321    
1322                    msg.append("expirationDate=");
1323                    msg.append(expirationDate);
1324    
1325                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1326    
1327                    throw new NoSuchLockException(msg.toString());
1328            }
1329    
1330            /**
1331             * Returns the first lock in the ordered set where expirationDate &lt; &#63;.
1332             *
1333             * @param expirationDate the expiration date
1334             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1335             * @return the first matching lock, or <code>null</code> if a matching lock could not be found
1336             * @throws SystemException if a system exception occurred
1337             */
1338            public Lock fetchByLtExpirationDate_First(Date expirationDate,
1339                    OrderByComparator orderByComparator) throws SystemException {
1340                    List<Lock> list = findByLtExpirationDate(expirationDate, 0, 1,
1341                                    orderByComparator);
1342    
1343                    if (!list.isEmpty()) {
1344                            return list.get(0);
1345                    }
1346    
1347                    return null;
1348            }
1349    
1350            /**
1351             * Returns the last lock in the ordered set where expirationDate &lt; &#63;.
1352             *
1353             * @param expirationDate the expiration date
1354             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1355             * @return the last matching lock
1356             * @throws com.liferay.portal.NoSuchLockException if a matching lock could not be found
1357             * @throws SystemException if a system exception occurred
1358             */
1359            public Lock findByLtExpirationDate_Last(Date expirationDate,
1360                    OrderByComparator orderByComparator)
1361                    throws NoSuchLockException, SystemException {
1362                    Lock lock = fetchByLtExpirationDate_Last(expirationDate,
1363                                    orderByComparator);
1364    
1365                    if (lock != null) {
1366                            return lock;
1367                    }
1368    
1369                    StringBundler msg = new StringBundler(4);
1370    
1371                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1372    
1373                    msg.append("expirationDate=");
1374                    msg.append(expirationDate);
1375    
1376                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1377    
1378                    throw new NoSuchLockException(msg.toString());
1379            }
1380    
1381            /**
1382             * Returns the last lock in the ordered set where expirationDate &lt; &#63;.
1383             *
1384             * @param expirationDate the expiration date
1385             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1386             * @return the last matching lock, or <code>null</code> if a matching lock could not be found
1387             * @throws SystemException if a system exception occurred
1388             */
1389            public Lock fetchByLtExpirationDate_Last(Date expirationDate,
1390                    OrderByComparator orderByComparator) throws SystemException {
1391                    int count = countByLtExpirationDate(expirationDate);
1392    
1393                    List<Lock> list = findByLtExpirationDate(expirationDate, count - 1,
1394                                    count, orderByComparator);
1395    
1396                    if (!list.isEmpty()) {
1397                            return list.get(0);
1398                    }
1399    
1400                    return null;
1401            }
1402    
1403            /**
1404             * Returns the locks before and after the current lock in the ordered set where expirationDate &lt; &#63;.
1405             *
1406             * @param lockId the primary key of the current lock
1407             * @param expirationDate the expiration date
1408             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1409             * @return the previous, current, and next lock
1410             * @throws com.liferay.portal.NoSuchLockException if a lock with the primary key could not be found
1411             * @throws SystemException if a system exception occurred
1412             */
1413            public Lock[] findByLtExpirationDate_PrevAndNext(long lockId,
1414                    Date expirationDate, OrderByComparator orderByComparator)
1415                    throws NoSuchLockException, SystemException {
1416                    Lock lock = findByPrimaryKey(lockId);
1417    
1418                    Session session = null;
1419    
1420                    try {
1421                            session = openSession();
1422    
1423                            Lock[] array = new LockImpl[3];
1424    
1425                            array[0] = getByLtExpirationDate_PrevAndNext(session, lock,
1426                                            expirationDate, orderByComparator, true);
1427    
1428                            array[1] = lock;
1429    
1430                            array[2] = getByLtExpirationDate_PrevAndNext(session, lock,
1431                                            expirationDate, orderByComparator, false);
1432    
1433                            return array;
1434                    }
1435                    catch (Exception e) {
1436                            throw processException(e);
1437                    }
1438                    finally {
1439                            closeSession(session);
1440                    }
1441            }
1442    
1443            protected Lock getByLtExpirationDate_PrevAndNext(Session session,
1444                    Lock lock, Date expirationDate, OrderByComparator orderByComparator,
1445                    boolean previous) {
1446                    StringBundler query = null;
1447    
1448                    if (orderByComparator != null) {
1449                            query = new StringBundler(6 +
1450                                            (orderByComparator.getOrderByFields().length * 6));
1451                    }
1452                    else {
1453                            query = new StringBundler(3);
1454                    }
1455    
1456                    query.append(_SQL_SELECT_LOCK_WHERE);
1457    
1458                    if (expirationDate == null) {
1459                            query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_1);
1460                    }
1461                    else {
1462                            query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_2);
1463                    }
1464    
1465                    if (orderByComparator != null) {
1466                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1467    
1468                            if (orderByConditionFields.length > 0) {
1469                                    query.append(WHERE_AND);
1470                            }
1471    
1472                            for (int i = 0; i < orderByConditionFields.length; i++) {
1473                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1474                                    query.append(orderByConditionFields[i]);
1475    
1476                                    if ((i + 1) < orderByConditionFields.length) {
1477                                            if (orderByComparator.isAscending() ^ previous) {
1478                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1479                                            }
1480                                            else {
1481                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1482                                            }
1483                                    }
1484                                    else {
1485                                            if (orderByComparator.isAscending() ^ previous) {
1486                                                    query.append(WHERE_GREATER_THAN);
1487                                            }
1488                                            else {
1489                                                    query.append(WHERE_LESSER_THAN);
1490                                            }
1491                                    }
1492                            }
1493    
1494                            query.append(ORDER_BY_CLAUSE);
1495    
1496                            String[] orderByFields = orderByComparator.getOrderByFields();
1497    
1498                            for (int i = 0; i < orderByFields.length; i++) {
1499                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1500                                    query.append(orderByFields[i]);
1501    
1502                                    if ((i + 1) < orderByFields.length) {
1503                                            if (orderByComparator.isAscending() ^ previous) {
1504                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1505                                            }
1506                                            else {
1507                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1508                                            }
1509                                    }
1510                                    else {
1511                                            if (orderByComparator.isAscending() ^ previous) {
1512                                                    query.append(ORDER_BY_ASC);
1513                                            }
1514                                            else {
1515                                                    query.append(ORDER_BY_DESC);
1516                                            }
1517                                    }
1518                            }
1519                    }
1520                    else {
1521                            query.append(LockModelImpl.ORDER_BY_JPQL);
1522                    }
1523    
1524                    String sql = query.toString();
1525    
1526                    Query q = session.createQuery(sql);
1527    
1528                    q.setFirstResult(0);
1529                    q.setMaxResults(2);
1530    
1531                    QueryPos qPos = QueryPos.getInstance(q);
1532    
1533                    if (expirationDate != null) {
1534                            qPos.add(CalendarUtil.getTimestamp(expirationDate));
1535                    }
1536    
1537                    if (orderByComparator != null) {
1538                            Object[] values = orderByComparator.getOrderByConditionValues(lock);
1539    
1540                            for (Object value : values) {
1541                                    qPos.add(value);
1542                            }
1543                    }
1544    
1545                    List<Lock> list = q.list();
1546    
1547                    if (list.size() == 2) {
1548                            return list.get(1);
1549                    }
1550                    else {
1551                            return null;
1552                    }
1553            }
1554    
1555            /**
1556             * Removes all the locks where expirationDate &lt; &#63; from the database.
1557             *
1558             * @param expirationDate the expiration date
1559             * @throws SystemException if a system exception occurred
1560             */
1561            public void removeByLtExpirationDate(Date expirationDate)
1562                    throws SystemException {
1563                    for (Lock lock : findByLtExpirationDate(expirationDate,
1564                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1565                            remove(lock);
1566                    }
1567            }
1568    
1569            /**
1570             * Returns the number of locks where expirationDate &lt; &#63;.
1571             *
1572             * @param expirationDate the expiration date
1573             * @return the number of matching locks
1574             * @throws SystemException if a system exception occurred
1575             */
1576            public int countByLtExpirationDate(Date expirationDate)
1577                    throws SystemException {
1578                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_LTEXPIRATIONDATE;
1579    
1580                    Object[] finderArgs = new Object[] { expirationDate };
1581    
1582                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1583                                    this);
1584    
1585                    if (count == null) {
1586                            StringBundler query = new StringBundler(2);
1587    
1588                            query.append(_SQL_COUNT_LOCK_WHERE);
1589    
1590                            if (expirationDate == null) {
1591                                    query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_1);
1592                            }
1593                            else {
1594                                    query.append(_FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_2);
1595                            }
1596    
1597                            String sql = query.toString();
1598    
1599                            Session session = null;
1600    
1601                            try {
1602                                    session = openSession();
1603    
1604                                    Query q = session.createQuery(sql);
1605    
1606                                    QueryPos qPos = QueryPos.getInstance(q);
1607    
1608                                    if (expirationDate != null) {
1609                                            qPos.add(CalendarUtil.getTimestamp(expirationDate));
1610                                    }
1611    
1612                                    count = (Long)q.uniqueResult();
1613    
1614                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1615                            }
1616                            catch (Exception e) {
1617                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1618    
1619                                    throw processException(e);
1620                            }
1621                            finally {
1622                                    closeSession(session);
1623                            }
1624                    }
1625    
1626                    return count.intValue();
1627            }
1628    
1629            private static final String _FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_1 =
1630                    "lock.expirationDate < NULL";
1631            private static final String _FINDER_COLUMN_LTEXPIRATIONDATE_EXPIRATIONDATE_2 =
1632                    "lock.expirationDate < ?";
1633            public static final FinderPath FINDER_PATH_FETCH_BY_C_K = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
1634                            LockModelImpl.FINDER_CACHE_ENABLED, LockImpl.class,
1635                            FINDER_CLASS_NAME_ENTITY, "fetchByC_K",
1636                            new String[] { String.class.getName(), String.class.getName() },
1637                            LockModelImpl.CLASSNAME_COLUMN_BITMASK |
1638                            LockModelImpl.KEY_COLUMN_BITMASK);
1639            public static final FinderPath FINDER_PATH_COUNT_BY_C_K = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
1640                            LockModelImpl.FINDER_CACHE_ENABLED, Long.class,
1641                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_K",
1642                            new String[] { String.class.getName(), String.class.getName() });
1643    
1644            /**
1645             * Returns the lock where className = &#63; and key = &#63; or throws a {@link com.liferay.portal.NoSuchLockException} if it could not be found.
1646             *
1647             * @param className the class name
1648             * @param key the key
1649             * @return the matching lock
1650             * @throws com.liferay.portal.NoSuchLockException if a matching lock could not be found
1651             * @throws SystemException if a system exception occurred
1652             */
1653            public Lock findByC_K(String className, String key)
1654                    throws NoSuchLockException, SystemException {
1655                    Lock lock = fetchByC_K(className, key);
1656    
1657                    if (lock == null) {
1658                            StringBundler msg = new StringBundler(6);
1659    
1660                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1661    
1662                            msg.append("className=");
1663                            msg.append(className);
1664    
1665                            msg.append(", key=");
1666                            msg.append(key);
1667    
1668                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1669    
1670                            if (_log.isWarnEnabled()) {
1671                                    _log.warn(msg.toString());
1672                            }
1673    
1674                            throw new NoSuchLockException(msg.toString());
1675                    }
1676    
1677                    return lock;
1678            }
1679    
1680            /**
1681             * Returns the lock where className = &#63; and key = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1682             *
1683             * @param className the class name
1684             * @param key the key
1685             * @return the matching lock, or <code>null</code> if a matching lock could not be found
1686             * @throws SystemException if a system exception occurred
1687             */
1688            public Lock fetchByC_K(String className, String key)
1689                    throws SystemException {
1690                    return fetchByC_K(className, key, true);
1691            }
1692    
1693            /**
1694             * 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.
1695             *
1696             * @param className the class name
1697             * @param key the key
1698             * @param retrieveFromCache whether to use the finder cache
1699             * @return the matching lock, or <code>null</code> if a matching lock could not be found
1700             * @throws SystemException if a system exception occurred
1701             */
1702            public Lock fetchByC_K(String className, String key,
1703                    boolean retrieveFromCache) throws SystemException {
1704                    Object[] finderArgs = new Object[] { className, key };
1705    
1706                    Object result = null;
1707    
1708                    if (retrieveFromCache) {
1709                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_K,
1710                                            finderArgs, this);
1711                    }
1712    
1713                    if (result instanceof Lock) {
1714                            Lock lock = (Lock)result;
1715    
1716                            if (!Validator.equals(className, lock.getClassName()) ||
1717                                            !Validator.equals(key, lock.getKey())) {
1718                                    result = null;
1719                            }
1720                    }
1721    
1722                    if (result == null) {
1723                            StringBundler query = new StringBundler(4);
1724    
1725                            query.append(_SQL_SELECT_LOCK_WHERE);
1726    
1727                            if (className == null) {
1728                                    query.append(_FINDER_COLUMN_C_K_CLASSNAME_1);
1729                            }
1730                            else {
1731                                    if (className.equals(StringPool.BLANK)) {
1732                                            query.append(_FINDER_COLUMN_C_K_CLASSNAME_3);
1733                                    }
1734                                    else {
1735                                            query.append(_FINDER_COLUMN_C_K_CLASSNAME_2);
1736                                    }
1737                            }
1738    
1739                            if (key == null) {
1740                                    query.append(_FINDER_COLUMN_C_K_KEY_1);
1741                            }
1742                            else {
1743                                    if (key.equals(StringPool.BLANK)) {
1744                                            query.append(_FINDER_COLUMN_C_K_KEY_3);
1745                                    }
1746                                    else {
1747                                            query.append(_FINDER_COLUMN_C_K_KEY_2);
1748                                    }
1749                            }
1750    
1751                            String sql = query.toString();
1752    
1753                            Session session = null;
1754    
1755                            try {
1756                                    session = openSession();
1757    
1758                                    Query q = session.createQuery(sql);
1759    
1760                                    QueryPos qPos = QueryPos.getInstance(q);
1761    
1762                                    if (className != null) {
1763                                            qPos.add(className);
1764                                    }
1765    
1766                                    if (key != null) {
1767                                            qPos.add(key);
1768                                    }
1769    
1770                                    List<Lock> list = q.list();
1771    
1772                                    if (list.isEmpty()) {
1773                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K,
1774                                                    finderArgs, list);
1775                                    }
1776                                    else {
1777                                            if ((list.size() > 1) && _log.isWarnEnabled()) {
1778                                                    _log.warn(
1779                                                            "LockPersistenceImpl.fetchByC_K(String, String, boolean) with parameters (" +
1780                                                            StringUtil.merge(finderArgs) +
1781                                                            ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
1782                                            }
1783    
1784                                            Lock lock = list.get(0);
1785    
1786                                            result = lock;
1787    
1788                                            cacheResult(lock);
1789    
1790                                            if ((lock.getClassName() == null) ||
1791                                                            !lock.getClassName().equals(className) ||
1792                                                            (lock.getKey() == null) ||
1793                                                            !lock.getKey().equals(key)) {
1794                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K,
1795                                                            finderArgs, lock);
1796                                            }
1797                                    }
1798                            }
1799                            catch (Exception e) {
1800                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_K,
1801                                            finderArgs);
1802    
1803                                    throw processException(e);
1804                            }
1805                            finally {
1806                                    closeSession(session);
1807                            }
1808                    }
1809    
1810                    if (result instanceof List<?>) {
1811                            return null;
1812                    }
1813                    else {
1814                            return (Lock)result;
1815                    }
1816            }
1817    
1818            /**
1819             * Removes the lock where className = &#63; and key = &#63; from the database.
1820             *
1821             * @param className the class name
1822             * @param key the key
1823             * @return the lock that was removed
1824             * @throws SystemException if a system exception occurred
1825             */
1826            public Lock removeByC_K(String className, String key)
1827                    throws NoSuchLockException, SystemException {
1828                    Lock lock = findByC_K(className, key);
1829    
1830                    return remove(lock);
1831            }
1832    
1833            /**
1834             * Returns the number of locks where className = &#63; and key = &#63;.
1835             *
1836             * @param className the class name
1837             * @param key the key
1838             * @return the number of matching locks
1839             * @throws SystemException if a system exception occurred
1840             */
1841            public int countByC_K(String className, String key)
1842                    throws SystemException {
1843                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_K;
1844    
1845                    Object[] finderArgs = new Object[] { className, key };
1846    
1847                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1848                                    this);
1849    
1850                    if (count == null) {
1851                            StringBundler query = new StringBundler(3);
1852    
1853                            query.append(_SQL_COUNT_LOCK_WHERE);
1854    
1855                            if (className == null) {
1856                                    query.append(_FINDER_COLUMN_C_K_CLASSNAME_1);
1857                            }
1858                            else {
1859                                    if (className.equals(StringPool.BLANK)) {
1860                                            query.append(_FINDER_COLUMN_C_K_CLASSNAME_3);
1861                                    }
1862                                    else {
1863                                            query.append(_FINDER_COLUMN_C_K_CLASSNAME_2);
1864                                    }
1865                            }
1866    
1867                            if (key == null) {
1868                                    query.append(_FINDER_COLUMN_C_K_KEY_1);
1869                            }
1870                            else {
1871                                    if (key.equals(StringPool.BLANK)) {
1872                                            query.append(_FINDER_COLUMN_C_K_KEY_3);
1873                                    }
1874                                    else {
1875                                            query.append(_FINDER_COLUMN_C_K_KEY_2);
1876                                    }
1877                            }
1878    
1879                            String sql = query.toString();
1880    
1881                            Session session = null;
1882    
1883                            try {
1884                                    session = openSession();
1885    
1886                                    Query q = session.createQuery(sql);
1887    
1888                                    QueryPos qPos = QueryPos.getInstance(q);
1889    
1890                                    if (className != null) {
1891                                            qPos.add(className);
1892                                    }
1893    
1894                                    if (key != null) {
1895                                            qPos.add(key);
1896                                    }
1897    
1898                                    count = (Long)q.uniqueResult();
1899    
1900                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1901                            }
1902                            catch (Exception e) {
1903                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1904    
1905                                    throw processException(e);
1906                            }
1907                            finally {
1908                                    closeSession(session);
1909                            }
1910                    }
1911    
1912                    return count.intValue();
1913            }
1914    
1915            private static final String _FINDER_COLUMN_C_K_CLASSNAME_1 = "lock.className IS NULL AND ";
1916            private static final String _FINDER_COLUMN_C_K_CLASSNAME_2 = "lock.className = ? AND ";
1917            private static final String _FINDER_COLUMN_C_K_CLASSNAME_3 = "(lock.className IS NULL OR lock.className = ?) AND ";
1918            private static final String _FINDER_COLUMN_C_K_KEY_1 = "lock.key IS NULL";
1919            private static final String _FINDER_COLUMN_C_K_KEY_2 = "lock.key = ?";
1920            private static final String _FINDER_COLUMN_C_K_KEY_3 = "(lock.key IS NULL OR lock.key = ?)";
1921            public static final FinderPath FINDER_PATH_FETCH_BY_C_K_O = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
1922                            LockModelImpl.FINDER_CACHE_ENABLED, LockImpl.class,
1923                            FINDER_CLASS_NAME_ENTITY, "fetchByC_K_O",
1924                            new String[] {
1925                                    String.class.getName(), String.class.getName(),
1926                                    String.class.getName()
1927                            },
1928                            LockModelImpl.CLASSNAME_COLUMN_BITMASK |
1929                            LockModelImpl.KEY_COLUMN_BITMASK |
1930                            LockModelImpl.OWNER_COLUMN_BITMASK);
1931            public static final FinderPath FINDER_PATH_COUNT_BY_C_K_O = new FinderPath(LockModelImpl.ENTITY_CACHE_ENABLED,
1932                            LockModelImpl.FINDER_CACHE_ENABLED, Long.class,
1933                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_K_O",
1934                            new String[] {
1935                                    String.class.getName(), String.class.getName(),
1936                                    String.class.getName()
1937                            });
1938    
1939            /**
1940             * 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.
1941             *
1942             * @param className the class name
1943             * @param key the key
1944             * @param owner the owner
1945             * @return the matching lock
1946             * @throws com.liferay.portal.NoSuchLockException if a matching lock could not be found
1947             * @throws SystemException if a system exception occurred
1948             */
1949            public Lock findByC_K_O(String className, String key, String owner)
1950                    throws NoSuchLockException, SystemException {
1951                    Lock lock = fetchByC_K_O(className, key, owner);
1952    
1953                    if (lock == null) {
1954                            StringBundler msg = new StringBundler(8);
1955    
1956                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1957    
1958                            msg.append("className=");
1959                            msg.append(className);
1960    
1961                            msg.append(", key=");
1962                            msg.append(key);
1963    
1964                            msg.append(", owner=");
1965                            msg.append(owner);
1966    
1967                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1968    
1969                            if (_log.isWarnEnabled()) {
1970                                    _log.warn(msg.toString());
1971                            }
1972    
1973                            throw new NoSuchLockException(msg.toString());
1974                    }
1975    
1976                    return lock;
1977            }
1978    
1979            /**
1980             * 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.
1981             *
1982             * @param className the class name
1983             * @param key the key
1984             * @param owner the owner
1985             * @return the matching lock, or <code>null</code> if a matching lock could not be found
1986             * @throws SystemException if a system exception occurred
1987             */
1988            public Lock fetchByC_K_O(String className, String key, String owner)
1989                    throws SystemException {
1990                    return fetchByC_K_O(className, key, owner, true);
1991            }
1992    
1993            /**
1994             * 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.
1995             *
1996             * @param className the class name
1997             * @param key the key
1998             * @param owner the owner
1999             * @param retrieveFromCache whether to use the finder cache
2000             * @return the matching lock, or <code>null</code> if a matching lock could not be found
2001             * @throws SystemException if a system exception occurred
2002             */
2003            public Lock fetchByC_K_O(String className, String key, String owner,
2004                    boolean retrieveFromCache) throws SystemException {
2005                    Object[] finderArgs = new Object[] { className, key, owner };
2006    
2007                    Object result = null;
2008    
2009                    if (retrieveFromCache) {
2010                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_K_O,
2011                                            finderArgs, this);
2012                    }
2013    
2014                    if (result instanceof Lock) {
2015                            Lock lock = (Lock)result;
2016    
2017                            if (!Validator.equals(className, lock.getClassName()) ||
2018                                            !Validator.equals(key, lock.getKey()) ||
2019                                            !Validator.equals(owner, lock.getOwner())) {
2020                                    result = null;
2021                            }
2022                    }
2023    
2024                    if (result == null) {
2025                            StringBundler query = new StringBundler(5);
2026    
2027                            query.append(_SQL_SELECT_LOCK_WHERE);
2028    
2029                            if (className == null) {
2030                                    query.append(_FINDER_COLUMN_C_K_O_CLASSNAME_1);
2031                            }
2032                            else {
2033                                    if (className.equals(StringPool.BLANK)) {
2034                                            query.append(_FINDER_COLUMN_C_K_O_CLASSNAME_3);
2035                                    }
2036                                    else {
2037                                            query.append(_FINDER_COLUMN_C_K_O_CLASSNAME_2);
2038                                    }
2039                            }
2040    
2041                            if (key == null) {
2042                                    query.append(_FINDER_COLUMN_C_K_O_KEY_1);
2043                            }
2044                            else {
2045                                    if (key.equals(StringPool.BLANK)) {
2046                                            query.append(_FINDER_COLUMN_C_K_O_KEY_3);
2047                                    }
2048                                    else {
2049                                            query.append(_FINDER_COLUMN_C_K_O_KEY_2);
2050                                    }
2051                            }
2052    
2053                            if (owner == null) {
2054                                    query.append(_FINDER_COLUMN_C_K_O_OWNER_1);
2055                            }
2056                            else {
2057                                    if (owner.equals(StringPool.BLANK)) {
2058                                            query.append(_FINDER_COLUMN_C_K_O_OWNER_3);
2059                                    }
2060                                    else {
2061                                            query.append(_FINDER_COLUMN_C_K_O_OWNER_2);
2062                                    }
2063                            }
2064    
2065                            String sql = query.toString();
2066    
2067                            Session session = null;
2068    
2069                            try {
2070                                    session = openSession();
2071    
2072                                    Query q = session.createQuery(sql);
2073    
2074                                    QueryPos qPos = QueryPos.getInstance(q);
2075    
2076                                    if (className != null) {
2077                                            qPos.add(className);
2078                                    }
2079    
2080                                    if (key != null) {
2081                                            qPos.add(key);
2082                                    }
2083    
2084                                    if (owner != null) {
2085                                            qPos.add(owner);
2086                                    }
2087    
2088                                    List<Lock> list = q.list();
2089    
2090                                    if (list.isEmpty()) {
2091                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K_O,
2092                                                    finderArgs, list);
2093                                    }
2094                                    else {
2095                                            Lock lock = list.get(0);
2096    
2097                                            result = lock;
2098    
2099                                            cacheResult(lock);
2100    
2101                                            if ((lock.getClassName() == null) ||
2102                                                            !lock.getClassName().equals(className) ||
2103                                                            (lock.getKey() == null) ||
2104                                                            !lock.getKey().equals(key) ||
2105                                                            (lock.getOwner() == null) ||
2106                                                            !lock.getOwner().equals(owner)) {
2107                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K_O,
2108                                                            finderArgs, lock);
2109                                            }
2110                                    }
2111                            }
2112                            catch (Exception e) {
2113                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_K_O,
2114                                            finderArgs);
2115    
2116                                    throw processException(e);
2117                            }
2118                            finally {
2119                                    closeSession(session);
2120                            }
2121                    }
2122    
2123                    if (result instanceof List<?>) {
2124                            return null;
2125                    }
2126                    else {
2127                            return (Lock)result;
2128                    }
2129            }
2130    
2131            /**
2132             * Removes the lock where className = &#63; and key = &#63; and owner = &#63; from the database.
2133             *
2134             * @param className the class name
2135             * @param key the key
2136             * @param owner the owner
2137             * @return the lock that was removed
2138             * @throws SystemException if a system exception occurred
2139             */
2140            public Lock removeByC_K_O(String className, String key, String owner)
2141                    throws NoSuchLockException, SystemException {
2142                    Lock lock = findByC_K_O(className, key, owner);
2143    
2144                    return remove(lock);
2145            }
2146    
2147            /**
2148             * Returns the number of locks where className = &#63; and key = &#63; and owner = &#63;.
2149             *
2150             * @param className the class name
2151             * @param key the key
2152             * @param owner the owner
2153             * @return the number of matching locks
2154             * @throws SystemException if a system exception occurred
2155             */
2156            public int countByC_K_O(String className, String key, String owner)
2157                    throws SystemException {
2158                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_K_O;
2159    
2160                    Object[] finderArgs = new Object[] { className, key, owner };
2161    
2162                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2163                                    this);
2164    
2165                    if (count == null) {
2166                            StringBundler query = new StringBundler(4);
2167    
2168                            query.append(_SQL_COUNT_LOCK_WHERE);
2169    
2170                            if (className == null) {
2171                                    query.append(_FINDER_COLUMN_C_K_O_CLASSNAME_1);
2172                            }
2173                            else {
2174                                    if (className.equals(StringPool.BLANK)) {
2175                                            query.append(_FINDER_COLUMN_C_K_O_CLASSNAME_3);
2176                                    }
2177                                    else {
2178                                            query.append(_FINDER_COLUMN_C_K_O_CLASSNAME_2);
2179                                    }
2180                            }
2181    
2182                            if (key == null) {
2183                                    query.append(_FINDER_COLUMN_C_K_O_KEY_1);
2184                            }
2185                            else {
2186                                    if (key.equals(StringPool.BLANK)) {
2187                                            query.append(_FINDER_COLUMN_C_K_O_KEY_3);
2188                                    }
2189                                    else {
2190                                            query.append(_FINDER_COLUMN_C_K_O_KEY_2);
2191                                    }
2192                            }
2193    
2194                            if (owner == null) {
2195                                    query.append(_FINDER_COLUMN_C_K_O_OWNER_1);
2196                            }
2197                            else {
2198                                    if (owner.equals(StringPool.BLANK)) {
2199                                            query.append(_FINDER_COLUMN_C_K_O_OWNER_3);
2200                                    }
2201                                    else {
2202                                            query.append(_FINDER_COLUMN_C_K_O_OWNER_2);
2203                                    }
2204                            }
2205    
2206                            String sql = query.toString();
2207    
2208                            Session session = null;
2209    
2210                            try {
2211                                    session = openSession();
2212    
2213                                    Query q = session.createQuery(sql);
2214    
2215                                    QueryPos qPos = QueryPos.getInstance(q);
2216    
2217                                    if (className != null) {
2218                                            qPos.add(className);
2219                                    }
2220    
2221                                    if (key != null) {
2222                                            qPos.add(key);
2223                                    }
2224    
2225                                    if (owner != null) {
2226                                            qPos.add(owner);
2227                                    }
2228    
2229                                    count = (Long)q.uniqueResult();
2230    
2231                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2232                            }
2233                            catch (Exception e) {
2234                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2235    
2236                                    throw processException(e);
2237                            }
2238                            finally {
2239                                    closeSession(session);
2240                            }
2241                    }
2242    
2243                    return count.intValue();
2244            }
2245    
2246            private static final String _FINDER_COLUMN_C_K_O_CLASSNAME_1 = "lock.className IS NULL AND ";
2247            private static final String _FINDER_COLUMN_C_K_O_CLASSNAME_2 = "lock.className = ? AND ";
2248            private static final String _FINDER_COLUMN_C_K_O_CLASSNAME_3 = "(lock.className IS NULL OR lock.className = ?) AND ";
2249            private static final String _FINDER_COLUMN_C_K_O_KEY_1 = "lock.key IS NULL AND ";
2250            private static final String _FINDER_COLUMN_C_K_O_KEY_2 = "lock.key = ? AND ";
2251            private static final String _FINDER_COLUMN_C_K_O_KEY_3 = "(lock.key IS NULL OR lock.key = ?) AND ";
2252            private static final String _FINDER_COLUMN_C_K_O_OWNER_1 = "lock.owner IS NULL";
2253            private static final String _FINDER_COLUMN_C_K_O_OWNER_2 = "lock.owner = ?";
2254            private static final String _FINDER_COLUMN_C_K_O_OWNER_3 = "(lock.owner IS NULL OR lock.owner = ?)";
2255    
2256            /**
2257             * Caches the lock in the entity cache if it is enabled.
2258             *
2259             * @param lock the lock
2260             */
2261            public void cacheResult(Lock lock) {
2262                    EntityCacheUtil.putResult(LockModelImpl.ENTITY_CACHE_ENABLED,
2263                            LockImpl.class, lock.getPrimaryKey(), lock);
2264    
2265                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K,
2266                            new Object[] { lock.getClassName(), lock.getKey() }, lock);
2267    
2268                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K_O,
2269                            new Object[] { lock.getClassName(), lock.getKey(), lock.getOwner() },
2270                            lock);
2271    
2272                    lock.resetOriginalValues();
2273            }
2274    
2275            /**
2276             * Caches the locks in the entity cache if it is enabled.
2277             *
2278             * @param locks the locks
2279             */
2280            public void cacheResult(List<Lock> locks) {
2281                    for (Lock lock : locks) {
2282                            if (EntityCacheUtil.getResult(LockModelImpl.ENTITY_CACHE_ENABLED,
2283                                                    LockImpl.class, lock.getPrimaryKey()) == null) {
2284                                    cacheResult(lock);
2285                            }
2286                            else {
2287                                    lock.resetOriginalValues();
2288                            }
2289                    }
2290            }
2291    
2292            /**
2293             * Clears the cache for all locks.
2294             *
2295             * <p>
2296             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2297             * </p>
2298             */
2299            @Override
2300            public void clearCache() {
2301                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
2302                            CacheRegistryUtil.clear(LockImpl.class.getName());
2303                    }
2304    
2305                    EntityCacheUtil.clearCache(LockImpl.class.getName());
2306    
2307                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2308                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2309                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2310            }
2311    
2312            /**
2313             * Clears the cache for the lock.
2314             *
2315             * <p>
2316             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2317             * </p>
2318             */
2319            @Override
2320            public void clearCache(Lock lock) {
2321                    EntityCacheUtil.removeResult(LockModelImpl.ENTITY_CACHE_ENABLED,
2322                            LockImpl.class, lock.getPrimaryKey());
2323    
2324                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2325                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2326    
2327                    clearUniqueFindersCache(lock);
2328            }
2329    
2330            @Override
2331            public void clearCache(List<Lock> locks) {
2332                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2333                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2334    
2335                    for (Lock lock : locks) {
2336                            EntityCacheUtil.removeResult(LockModelImpl.ENTITY_CACHE_ENABLED,
2337                                    LockImpl.class, lock.getPrimaryKey());
2338    
2339                            clearUniqueFindersCache(lock);
2340                    }
2341            }
2342    
2343            protected void cacheUniqueFindersCache(Lock lock) {
2344                    if (lock.isNew()) {
2345                            Object[] args = new Object[] { lock.getClassName(), lock.getKey() };
2346    
2347                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_K, args,
2348                                    Long.valueOf(1));
2349                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K, args, lock);
2350    
2351                            args = new Object[] {
2352                                            lock.getClassName(),
2353                                            
2354                                            lock.getKey(),
2355                                            
2356                                            lock.getOwner()
2357                                    };
2358    
2359                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_K_O, args,
2360                                    Long.valueOf(1));
2361                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K_O, args, lock);
2362                    }
2363                    else {
2364                            LockModelImpl lockModelImpl = (LockModelImpl)lock;
2365    
2366                            if ((lockModelImpl.getColumnBitmask() &
2367                                            FINDER_PATH_FETCH_BY_C_K.getColumnBitmask()) != 0) {
2368                                    Object[] args = new Object[] { lock.getClassName(), lock.getKey() };
2369    
2370                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_K, args,
2371                                            Long.valueOf(1));
2372                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K, args, lock);
2373                            }
2374    
2375                            if ((lockModelImpl.getColumnBitmask() &
2376                                            FINDER_PATH_FETCH_BY_C_K_O.getColumnBitmask()) != 0) {
2377                                    Object[] args = new Object[] {
2378                                                    lock.getClassName(),
2379                                                    
2380                                                    lock.getKey(),
2381                                                    
2382                                                    lock.getOwner()
2383                                            };
2384    
2385                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_K_O, args,
2386                                            Long.valueOf(1));
2387                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_K_O, args, lock);
2388                            }
2389                    }
2390            }
2391    
2392            protected void clearUniqueFindersCache(Lock lock) {
2393                    LockModelImpl lockModelImpl = (LockModelImpl)lock;
2394    
2395                    Object[] args = new Object[] { lock.getClassName(), lock.getKey() };
2396    
2397                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_K, args);
2398                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_K, args);
2399    
2400                    if ((lockModelImpl.getColumnBitmask() &
2401                                    FINDER_PATH_FETCH_BY_C_K.getColumnBitmask()) != 0) {
2402                            args = new Object[] {
2403                                            lockModelImpl.getOriginalClassName(),
2404                                            
2405                                            lockModelImpl.getOriginalKey()
2406                                    };
2407    
2408                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_K, args);
2409                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_K, args);
2410                    }
2411    
2412                    args = new Object[] { lock.getClassName(), lock.getKey(), lock.getOwner() };
2413    
2414                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_K_O, args);
2415                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_K_O, args);
2416    
2417                    if ((lockModelImpl.getColumnBitmask() &
2418                                    FINDER_PATH_FETCH_BY_C_K_O.getColumnBitmask()) != 0) {
2419                            args = new Object[] {
2420                                            lockModelImpl.getOriginalClassName(),
2421                                            
2422                                            lockModelImpl.getOriginalKey(),
2423                                            
2424                                            lockModelImpl.getOriginalOwner()
2425                                    };
2426    
2427                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_K_O, args);
2428                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_K_O, args);
2429                    }
2430            }
2431    
2432            /**
2433             * Creates a new lock with the primary key. Does not add the lock to the database.
2434             *
2435             * @param lockId the primary key for the new lock
2436             * @return the new lock
2437             */
2438            public Lock create(long lockId) {
2439                    Lock lock = new LockImpl();
2440    
2441                    lock.setNew(true);
2442                    lock.setPrimaryKey(lockId);
2443    
2444                    String uuid = PortalUUIDUtil.generate();
2445    
2446                    lock.setUuid(uuid);
2447    
2448                    return lock;
2449            }
2450    
2451            /**
2452             * Removes the lock with the primary key from the database. Also notifies the appropriate model listeners.
2453             *
2454             * @param lockId the primary key of the lock
2455             * @return the lock that was removed
2456             * @throws com.liferay.portal.NoSuchLockException if a lock with the primary key could not be found
2457             * @throws SystemException if a system exception occurred
2458             */
2459            public Lock remove(long lockId) throws NoSuchLockException, SystemException {
2460                    return remove(Long.valueOf(lockId));
2461            }
2462    
2463            /**
2464             * Removes the lock with the primary key from the database. Also notifies the appropriate model listeners.
2465             *
2466             * @param primaryKey the primary key of the lock
2467             * @return the lock that was removed
2468             * @throws com.liferay.portal.NoSuchLockException if a lock with the primary key could not be found
2469             * @throws SystemException if a system exception occurred
2470             */
2471            @Override
2472            public Lock remove(Serializable primaryKey)
2473                    throws NoSuchLockException, SystemException {
2474                    Session session = null;
2475    
2476                    try {
2477                            session = openSession();
2478    
2479                            Lock lock = (Lock)session.get(LockImpl.class, primaryKey);
2480    
2481                            if (lock == null) {
2482                                    if (_log.isWarnEnabled()) {
2483                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2484                                    }
2485    
2486                                    throw new NoSuchLockException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2487                                            primaryKey);
2488                            }
2489    
2490                            return remove(lock);
2491                    }
2492                    catch (NoSuchLockException nsee) {
2493                            throw nsee;
2494                    }
2495                    catch (Exception e) {
2496                            throw processException(e);
2497                    }
2498                    finally {
2499                            closeSession(session);
2500                    }
2501            }
2502    
2503            @Override
2504            protected Lock removeImpl(Lock lock) throws SystemException {
2505                    lock = toUnwrappedModel(lock);
2506    
2507                    Session session = null;
2508    
2509                    try {
2510                            session = openSession();
2511    
2512                            if (!session.contains(lock)) {
2513                                    lock = (Lock)session.get(LockImpl.class, lock.getPrimaryKeyObj());
2514                            }
2515    
2516                            if (lock != null) {
2517                                    session.delete(lock);
2518                            }
2519                    }
2520                    catch (Exception e) {
2521                            throw processException(e);
2522                    }
2523                    finally {
2524                            closeSession(session);
2525                    }
2526    
2527                    if (lock != null) {
2528                            clearCache(lock);
2529                    }
2530    
2531                    return lock;
2532            }
2533    
2534            @Override
2535            public Lock updateImpl(com.liferay.portal.model.Lock lock)
2536                    throws SystemException {
2537                    lock = toUnwrappedModel(lock);
2538    
2539                    boolean isNew = lock.isNew();
2540    
2541                    LockModelImpl lockModelImpl = (LockModelImpl)lock;
2542    
2543                    if (Validator.isNull(lock.getUuid())) {
2544                            String uuid = PortalUUIDUtil.generate();
2545    
2546                            lock.setUuid(uuid);
2547                    }
2548    
2549                    Session session = null;
2550    
2551                    try {
2552                            session = openSession();
2553    
2554                            if (lock.isNew()) {
2555                                    session.save(lock);
2556    
2557                                    lock.setNew(false);
2558                            }
2559                            else {
2560                                    session.merge(lock);
2561                            }
2562                    }
2563                    catch (Exception e) {
2564                            throw processException(e);
2565                    }
2566                    finally {
2567                            closeSession(session);
2568                    }
2569    
2570                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2571    
2572                    if (isNew || !LockModelImpl.COLUMN_BITMASK_ENABLED) {
2573                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2574                    }
2575    
2576                    else {
2577                            if ((lockModelImpl.getColumnBitmask() &
2578                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
2579                                    Object[] args = new Object[] { lockModelImpl.getOriginalUuid() };
2580    
2581                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2582                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2583                                            args);
2584    
2585                                    args = new Object[] { lockModelImpl.getUuid() };
2586    
2587                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2588                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2589                                            args);
2590                            }
2591    
2592                            if ((lockModelImpl.getColumnBitmask() &
2593                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
2594                                    Object[] args = new Object[] {
2595                                                    lockModelImpl.getOriginalUuid(),
2596                                                    Long.valueOf(lockModelImpl.getOriginalCompanyId())
2597                                            };
2598    
2599                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2600                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2601                                            args);
2602    
2603                                    args = new Object[] {
2604                                                    lockModelImpl.getUuid(),
2605                                                    Long.valueOf(lockModelImpl.getCompanyId())
2606                                            };
2607    
2608                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2609                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2610                                            args);
2611                            }
2612                    }
2613    
2614                    EntityCacheUtil.putResult(LockModelImpl.ENTITY_CACHE_ENABLED,
2615                            LockImpl.class, lock.getPrimaryKey(), lock);
2616    
2617                    clearUniqueFindersCache(lock);
2618                    cacheUniqueFindersCache(lock);
2619    
2620                    return lock;
2621            }
2622    
2623            protected Lock toUnwrappedModel(Lock lock) {
2624                    if (lock instanceof LockImpl) {
2625                            return lock;
2626                    }
2627    
2628                    LockImpl lockImpl = new LockImpl();
2629    
2630                    lockImpl.setNew(lock.isNew());
2631                    lockImpl.setPrimaryKey(lock.getPrimaryKey());
2632    
2633                    lockImpl.setUuid(lock.getUuid());
2634                    lockImpl.setLockId(lock.getLockId());
2635                    lockImpl.setCompanyId(lock.getCompanyId());
2636                    lockImpl.setUserId(lock.getUserId());
2637                    lockImpl.setUserName(lock.getUserName());
2638                    lockImpl.setCreateDate(lock.getCreateDate());
2639                    lockImpl.setClassName(lock.getClassName());
2640                    lockImpl.setKey(lock.getKey());
2641                    lockImpl.setOwner(lock.getOwner());
2642                    lockImpl.setInheritable(lock.isInheritable());
2643                    lockImpl.setExpirationDate(lock.getExpirationDate());
2644    
2645                    return lockImpl;
2646            }
2647    
2648            /**
2649             * Returns the lock with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
2650             *
2651             * @param primaryKey the primary key of the lock
2652             * @return the lock
2653             * @throws com.liferay.portal.NoSuchModelException if a lock with the primary key could not be found
2654             * @throws SystemException if a system exception occurred
2655             */
2656            @Override
2657            public Lock findByPrimaryKey(Serializable primaryKey)
2658                    throws NoSuchModelException, SystemException {
2659                    return findByPrimaryKey(((Long)primaryKey).longValue());
2660            }
2661    
2662            /**
2663             * Returns the lock with the primary key or throws a {@link com.liferay.portal.NoSuchLockException} if it could not be found.
2664             *
2665             * @param lockId the primary key of the lock
2666             * @return the lock
2667             * @throws com.liferay.portal.NoSuchLockException if a lock with the primary key could not be found
2668             * @throws SystemException if a system exception occurred
2669             */
2670            public Lock findByPrimaryKey(long lockId)
2671                    throws NoSuchLockException, SystemException {
2672                    Lock lock = fetchByPrimaryKey(lockId);
2673    
2674                    if (lock == null) {
2675                            if (_log.isWarnEnabled()) {
2676                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + lockId);
2677                            }
2678    
2679                            throw new NoSuchLockException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2680                                    lockId);
2681                    }
2682    
2683                    return lock;
2684            }
2685    
2686            /**
2687             * Returns the lock with the primary key or returns <code>null</code> if it could not be found.
2688             *
2689             * @param primaryKey the primary key of the lock
2690             * @return the lock, or <code>null</code> if a lock with the primary key could not be found
2691             * @throws SystemException if a system exception occurred
2692             */
2693            @Override
2694            public Lock fetchByPrimaryKey(Serializable primaryKey)
2695                    throws SystemException {
2696                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
2697            }
2698    
2699            /**
2700             * Returns the lock with the primary key or returns <code>null</code> if it could not be found.
2701             *
2702             * @param lockId the primary key of the lock
2703             * @return the lock, or <code>null</code> if a lock with the primary key could not be found
2704             * @throws SystemException if a system exception occurred
2705             */
2706            public Lock fetchByPrimaryKey(long lockId) throws SystemException {
2707                    Lock lock = (Lock)EntityCacheUtil.getResult(LockModelImpl.ENTITY_CACHE_ENABLED,
2708                                    LockImpl.class, lockId);
2709    
2710                    if (lock == _nullLock) {
2711                            return null;
2712                    }
2713    
2714                    if (lock == null) {
2715                            Session session = null;
2716    
2717                            try {
2718                                    session = openSession();
2719    
2720                                    lock = (Lock)session.get(LockImpl.class, Long.valueOf(lockId));
2721    
2722                                    if (lock != null) {
2723                                            cacheResult(lock);
2724                                    }
2725                                    else {
2726                                            EntityCacheUtil.putResult(LockModelImpl.ENTITY_CACHE_ENABLED,
2727                                                    LockImpl.class, lockId, _nullLock);
2728                                    }
2729                            }
2730                            catch (Exception e) {
2731                                    EntityCacheUtil.removeResult(LockModelImpl.ENTITY_CACHE_ENABLED,
2732                                            LockImpl.class, lockId);
2733    
2734                                    throw processException(e);
2735                            }
2736                            finally {
2737                                    closeSession(session);
2738                            }
2739                    }
2740    
2741                    return lock;
2742            }
2743    
2744            /**
2745             * Returns all the locks.
2746             *
2747             * @return the locks
2748             * @throws SystemException if a system exception occurred
2749             */
2750            public List<Lock> findAll() throws SystemException {
2751                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2752            }
2753    
2754            /**
2755             * Returns a range of all the locks.
2756             *
2757             * <p>
2758             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.LockModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2759             * </p>
2760             *
2761             * @param start the lower bound of the range of locks
2762             * @param end the upper bound of the range of locks (not inclusive)
2763             * @return the range of locks
2764             * @throws SystemException if a system exception occurred
2765             */
2766            public List<Lock> findAll(int start, int end) throws SystemException {
2767                    return findAll(start, end, null);
2768            }
2769    
2770            /**
2771             * Returns an ordered range of all the locks.
2772             *
2773             * <p>
2774             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.LockModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2775             * </p>
2776             *
2777             * @param start the lower bound of the range of locks
2778             * @param end the upper bound of the range of locks (not inclusive)
2779             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2780             * @return the ordered range of locks
2781             * @throws SystemException if a system exception occurred
2782             */
2783            public List<Lock> findAll(int start, int end,
2784                    OrderByComparator orderByComparator) throws SystemException {
2785                    boolean pagination = true;
2786                    FinderPath finderPath = null;
2787                    Object[] finderArgs = null;
2788    
2789                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2790                                    (orderByComparator == null)) {
2791                            pagination = false;
2792                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2793                            finderArgs = FINDER_ARGS_EMPTY;
2794                    }
2795                    else {
2796                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2797                            finderArgs = new Object[] { start, end, orderByComparator };
2798                    }
2799    
2800                    List<Lock> list = (List<Lock>)FinderCacheUtil.getResult(finderPath,
2801                                    finderArgs, this);
2802    
2803                    if (list == null) {
2804                            StringBundler query = null;
2805                            String sql = null;
2806    
2807                            if (orderByComparator != null) {
2808                                    query = new StringBundler(2 +
2809                                                    (orderByComparator.getOrderByFields().length * 3));
2810    
2811                                    query.append(_SQL_SELECT_LOCK);
2812    
2813                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2814                                            orderByComparator);
2815    
2816                                    sql = query.toString();
2817                            }
2818                            else {
2819                                    sql = _SQL_SELECT_LOCK;
2820    
2821                                    if (pagination) {
2822                                            sql = sql.concat(LockModelImpl.ORDER_BY_JPQL);
2823                                    }
2824                            }
2825    
2826                            Session session = null;
2827    
2828                            try {
2829                                    session = openSession();
2830    
2831                                    Query q = session.createQuery(sql);
2832    
2833                                    if (!pagination) {
2834                                            list = (List<Lock>)QueryUtil.list(q, getDialect(), start,
2835                                                            end, false);
2836    
2837                                            Collections.sort(list);
2838    
2839                                            list = new UnmodifiableList<Lock>(list);
2840                                    }
2841                                    else {
2842                                            list = (List<Lock>)QueryUtil.list(q, getDialect(), start,
2843                                                            end);
2844                                    }
2845    
2846                                    cacheResult(list);
2847    
2848                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2849                            }
2850                            catch (Exception e) {
2851                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2852    
2853                                    throw processException(e);
2854                            }
2855                            finally {
2856                                    closeSession(session);
2857                            }
2858                    }
2859    
2860                    return list;
2861            }
2862    
2863            /**
2864             * Removes all the locks from the database.
2865             *
2866             * @throws SystemException if a system exception occurred
2867             */
2868            public void removeAll() throws SystemException {
2869                    for (Lock lock : findAll()) {
2870                            remove(lock);
2871                    }
2872            }
2873    
2874            /**
2875             * Returns the number of locks.
2876             *
2877             * @return the number of locks
2878             * @throws SystemException if a system exception occurred
2879             */
2880            public int countAll() throws SystemException {
2881                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2882                                    FINDER_ARGS_EMPTY, this);
2883    
2884                    if (count == null) {
2885                            Session session = null;
2886    
2887                            try {
2888                                    session = openSession();
2889    
2890                                    Query q = session.createQuery(_SQL_COUNT_LOCK);
2891    
2892                                    count = (Long)q.uniqueResult();
2893    
2894                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2895                                            FINDER_ARGS_EMPTY, count);
2896                            }
2897                            catch (Exception e) {
2898                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2899                                            FINDER_ARGS_EMPTY);
2900    
2901                                    throw processException(e);
2902                            }
2903                            finally {
2904                                    closeSession(session);
2905                            }
2906                    }
2907    
2908                    return count.intValue();
2909            }
2910    
2911            /**
2912             * Initializes the lock persistence.
2913             */
2914            public void afterPropertiesSet() {
2915                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2916                                            com.liferay.portal.util.PropsUtil.get(
2917                                                    "value.object.listener.com.liferay.portal.model.Lock")));
2918    
2919                    if (listenerClassNames.length > 0) {
2920                            try {
2921                                    List<ModelListener<Lock>> listenersList = new ArrayList<ModelListener<Lock>>();
2922    
2923                                    for (String listenerClassName : listenerClassNames) {
2924                                            listenersList.add((ModelListener<Lock>)InstanceFactory.newInstance(
2925                                                            listenerClassName));
2926                                    }
2927    
2928                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2929                            }
2930                            catch (Exception e) {
2931                                    _log.error(e);
2932                            }
2933                    }
2934            }
2935    
2936            public void destroy() {
2937                    EntityCacheUtil.removeCache(LockImpl.class.getName());
2938                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2939                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2940                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2941            }
2942    
2943            private static final String _SQL_SELECT_LOCK = "SELECT lock FROM Lock lock";
2944            private static final String _SQL_SELECT_LOCK_WHERE = "SELECT lock FROM Lock lock WHERE ";
2945            private static final String _SQL_COUNT_LOCK = "SELECT COUNT(lock) FROM Lock lock";
2946            private static final String _SQL_COUNT_LOCK_WHERE = "SELECT COUNT(lock) FROM Lock lock WHERE ";
2947            private static final String _ORDER_BY_ENTITY_ALIAS = "lock.";
2948            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Lock exists with the primary key ";
2949            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Lock exists with the key {";
2950            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2951            private static Log _log = LogFactoryUtil.getLog(LockPersistenceImpl.class);
2952            private static Lock _nullLock = new LockImpl() {
2953                            @Override
2954                            public Object clone() {
2955                                    return this;
2956                            }
2957    
2958                            @Override
2959                            public CacheModel<Lock> toCacheModel() {
2960                                    return _nullLockCacheModel;
2961                            }
2962                    };
2963    
2964            private static CacheModel<Lock> _nullLockCacheModel = new CacheModel<Lock>() {
2965                            public Lock toEntityModel() {
2966                                    return _nullLock;
2967                            }
2968                    };
2969    }