001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.asset.service.persistence;
016    
017    import com.liferay.portal.kernel.bean.BeanReference;
018    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderPath;
022    import com.liferay.portal.kernel.dao.orm.Query;
023    import com.liferay.portal.kernel.dao.orm.QueryPos;
024    import com.liferay.portal.kernel.dao.orm.QueryUtil;
025    import com.liferay.portal.kernel.dao.orm.Session;
026    import com.liferay.portal.kernel.exception.SystemException;
027    import com.liferay.portal.kernel.log.Log;
028    import com.liferay.portal.kernel.log.LogFactoryUtil;
029    import com.liferay.portal.kernel.util.CalendarUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.kernel.util.UnmodifiableList;
037    import com.liferay.portal.kernel.util.Validator;
038    import com.liferay.portal.model.CacheModel;
039    import com.liferay.portal.model.ModelListener;
040    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
041    import com.liferay.portal.service.persistence.impl.TableMapper;
042    import com.liferay.portal.service.persistence.impl.TableMapperFactory;
043    
044    import com.liferay.portlet.asset.NoSuchEntryException;
045    import com.liferay.portlet.asset.model.AssetEntry;
046    import com.liferay.portlet.asset.model.impl.AssetEntryImpl;
047    import com.liferay.portlet.asset.model.impl.AssetEntryModelImpl;
048    
049    import java.io.Serializable;
050    
051    import java.util.ArrayList;
052    import java.util.Collections;
053    import java.util.Date;
054    import java.util.List;
055    
056    /**
057     * The persistence implementation for the asset entry service.
058     *
059     * <p>
060     * Caching information and settings can be found in <code>portal.properties</code>
061     * </p>
062     *
063     * @author Brian Wing Shun Chan
064     * @see AssetEntryPersistence
065     * @see AssetEntryUtil
066     * @generated
067     */
068    public class AssetEntryPersistenceImpl extends BasePersistenceImpl<AssetEntry>
069            implements AssetEntryPersistence {
070            /*
071             * NOTE FOR DEVELOPERS:
072             *
073             * Never modify or reference this class directly. Always use {@link AssetEntryUtil} to access the asset entry persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
074             */
075            public static final String FINDER_CLASS_NAME_ENTITY = AssetEntryImpl.class.getName();
076            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077                    ".List1";
078            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079                    ".List2";
080            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
081                            AssetEntryModelImpl.FINDER_CACHE_ENABLED, AssetEntryImpl.class,
082                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
083            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
084                            AssetEntryModelImpl.FINDER_CACHE_ENABLED, AssetEntryImpl.class,
085                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
086            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
087                            AssetEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
088                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
089            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
090                    new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
091                            AssetEntryModelImpl.FINDER_CACHE_ENABLED, AssetEntryImpl.class,
092                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
093                            new String[] {
094                                    Long.class.getName(),
095                                    
096                            Integer.class.getName(), Integer.class.getName(),
097                                    OrderByComparator.class.getName()
098                            });
099            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
100                    new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
101                            AssetEntryModelImpl.FINDER_CACHE_ENABLED, AssetEntryImpl.class,
102                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
103                            new String[] { Long.class.getName() },
104                            AssetEntryModelImpl.COMPANYID_COLUMN_BITMASK);
105            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
106                            AssetEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
107                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
108                            new String[] { Long.class.getName() });
109    
110            /**
111             * Returns all the asset entries where companyId = &#63;.
112             *
113             * @param companyId the company ID
114             * @return the matching asset entries
115             * @throws SystemException if a system exception occurred
116             */
117            @Override
118            public List<AssetEntry> findByCompanyId(long companyId)
119                    throws SystemException {
120                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
121                            null);
122            }
123    
124            /**
125             * Returns a range of all the asset entries where companyId = &#63;.
126             *
127             * <p>
128             * 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.portlet.asset.model.impl.AssetEntryModelImpl}. 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.
129             * </p>
130             *
131             * @param companyId the company ID
132             * @param start the lower bound of the range of asset entries
133             * @param end the upper bound of the range of asset entries (not inclusive)
134             * @return the range of matching asset entries
135             * @throws SystemException if a system exception occurred
136             */
137            @Override
138            public List<AssetEntry> findByCompanyId(long companyId, int start, int end)
139                    throws SystemException {
140                    return findByCompanyId(companyId, start, end, null);
141            }
142    
143            /**
144             * Returns an ordered range of all the asset entries where companyId = &#63;.
145             *
146             * <p>
147             * 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.portlet.asset.model.impl.AssetEntryModelImpl}. 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.
148             * </p>
149             *
150             * @param companyId the company ID
151             * @param start the lower bound of the range of asset entries
152             * @param end the upper bound of the range of asset entries (not inclusive)
153             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
154             * @return the ordered range of matching asset entries
155             * @throws SystemException if a system exception occurred
156             */
157            @Override
158            public List<AssetEntry> findByCompanyId(long companyId, int start, int end,
159                    OrderByComparator orderByComparator) throws SystemException {
160                    boolean pagination = true;
161                    FinderPath finderPath = null;
162                    Object[] finderArgs = null;
163    
164                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
165                                    (orderByComparator == null)) {
166                            pagination = false;
167                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
168                            finderArgs = new Object[] { companyId };
169                    }
170                    else {
171                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
172                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
173                    }
174    
175                    List<AssetEntry> list = (List<AssetEntry>)FinderCacheUtil.getResult(finderPath,
176                                    finderArgs, this);
177    
178                    if ((list != null) && !list.isEmpty()) {
179                            for (AssetEntry assetEntry : list) {
180                                    if ((companyId != assetEntry.getCompanyId())) {
181                                            list = null;
182    
183                                            break;
184                                    }
185                            }
186                    }
187    
188                    if (list == null) {
189                            StringBundler query = null;
190    
191                            if (orderByComparator != null) {
192                                    query = new StringBundler(3 +
193                                                    (orderByComparator.getOrderByFields().length * 3));
194                            }
195                            else {
196                                    query = new StringBundler(3);
197                            }
198    
199                            query.append(_SQL_SELECT_ASSETENTRY_WHERE);
200    
201                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
202    
203                            if (orderByComparator != null) {
204                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
205                                            orderByComparator);
206                            }
207                            else
208                             if (pagination) {
209                                    query.append(AssetEntryModelImpl.ORDER_BY_JPQL);
210                            }
211    
212                            String sql = query.toString();
213    
214                            Session session = null;
215    
216                            try {
217                                    session = openSession();
218    
219                                    Query q = session.createQuery(sql);
220    
221                                    QueryPos qPos = QueryPos.getInstance(q);
222    
223                                    qPos.add(companyId);
224    
225                                    if (!pagination) {
226                                            list = (List<AssetEntry>)QueryUtil.list(q, getDialect(),
227                                                            start, end, false);
228    
229                                            Collections.sort(list);
230    
231                                            list = new UnmodifiableList<AssetEntry>(list);
232                                    }
233                                    else {
234                                            list = (List<AssetEntry>)QueryUtil.list(q, getDialect(),
235                                                            start, end);
236                                    }
237    
238                                    cacheResult(list);
239    
240                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
241                            }
242                            catch (Exception e) {
243                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
244    
245                                    throw processException(e);
246                            }
247                            finally {
248                                    closeSession(session);
249                            }
250                    }
251    
252                    return list;
253            }
254    
255            /**
256             * Returns the first asset entry in the ordered set where companyId = &#63;.
257             *
258             * @param companyId the company ID
259             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
260             * @return the first matching asset entry
261             * @throws com.liferay.portlet.asset.NoSuchEntryException if a matching asset entry could not be found
262             * @throws SystemException if a system exception occurred
263             */
264            @Override
265            public AssetEntry findByCompanyId_First(long companyId,
266                    OrderByComparator orderByComparator)
267                    throws NoSuchEntryException, SystemException {
268                    AssetEntry assetEntry = fetchByCompanyId_First(companyId,
269                                    orderByComparator);
270    
271                    if (assetEntry != null) {
272                            return assetEntry;
273                    }
274    
275                    StringBundler msg = new StringBundler(4);
276    
277                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
278    
279                    msg.append("companyId=");
280                    msg.append(companyId);
281    
282                    msg.append(StringPool.CLOSE_CURLY_BRACE);
283    
284                    throw new NoSuchEntryException(msg.toString());
285            }
286    
287            /**
288             * Returns the first asset entry in the ordered set where companyId = &#63;.
289             *
290             * @param companyId the company ID
291             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
292             * @return the first matching asset entry, or <code>null</code> if a matching asset entry could not be found
293             * @throws SystemException if a system exception occurred
294             */
295            @Override
296            public AssetEntry fetchByCompanyId_First(long companyId,
297                    OrderByComparator orderByComparator) throws SystemException {
298                    List<AssetEntry> list = findByCompanyId(companyId, 0, 1,
299                                    orderByComparator);
300    
301                    if (!list.isEmpty()) {
302                            return list.get(0);
303                    }
304    
305                    return null;
306            }
307    
308            /**
309             * Returns the last asset entry in the ordered set where companyId = &#63;.
310             *
311             * @param companyId the company ID
312             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
313             * @return the last matching asset entry
314             * @throws com.liferay.portlet.asset.NoSuchEntryException if a matching asset entry could not be found
315             * @throws SystemException if a system exception occurred
316             */
317            @Override
318            public AssetEntry findByCompanyId_Last(long companyId,
319                    OrderByComparator orderByComparator)
320                    throws NoSuchEntryException, SystemException {
321                    AssetEntry assetEntry = fetchByCompanyId_Last(companyId,
322                                    orderByComparator);
323    
324                    if (assetEntry != null) {
325                            return assetEntry;
326                    }
327    
328                    StringBundler msg = new StringBundler(4);
329    
330                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
331    
332                    msg.append("companyId=");
333                    msg.append(companyId);
334    
335                    msg.append(StringPool.CLOSE_CURLY_BRACE);
336    
337                    throw new NoSuchEntryException(msg.toString());
338            }
339    
340            /**
341             * Returns the last asset entry in the ordered set where companyId = &#63;.
342             *
343             * @param companyId the company ID
344             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
345             * @return the last matching asset entry, or <code>null</code> if a matching asset entry could not be found
346             * @throws SystemException if a system exception occurred
347             */
348            @Override
349            public AssetEntry fetchByCompanyId_Last(long companyId,
350                    OrderByComparator orderByComparator) throws SystemException {
351                    int count = countByCompanyId(companyId);
352    
353                    if (count == 0) {
354                            return null;
355                    }
356    
357                    List<AssetEntry> list = findByCompanyId(companyId, count - 1, count,
358                                    orderByComparator);
359    
360                    if (!list.isEmpty()) {
361                            return list.get(0);
362                    }
363    
364                    return null;
365            }
366    
367            /**
368             * Returns the asset entries before and after the current asset entry in the ordered set where companyId = &#63;.
369             *
370             * @param entryId the primary key of the current asset entry
371             * @param companyId the company ID
372             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
373             * @return the previous, current, and next asset entry
374             * @throws com.liferay.portlet.asset.NoSuchEntryException if a asset entry with the primary key could not be found
375             * @throws SystemException if a system exception occurred
376             */
377            @Override
378            public AssetEntry[] findByCompanyId_PrevAndNext(long entryId,
379                    long companyId, OrderByComparator orderByComparator)
380                    throws NoSuchEntryException, SystemException {
381                    AssetEntry assetEntry = findByPrimaryKey(entryId);
382    
383                    Session session = null;
384    
385                    try {
386                            session = openSession();
387    
388                            AssetEntry[] array = new AssetEntryImpl[3];
389    
390                            array[0] = getByCompanyId_PrevAndNext(session, assetEntry,
391                                            companyId, orderByComparator, true);
392    
393                            array[1] = assetEntry;
394    
395                            array[2] = getByCompanyId_PrevAndNext(session, assetEntry,
396                                            companyId, orderByComparator, false);
397    
398                            return array;
399                    }
400                    catch (Exception e) {
401                            throw processException(e);
402                    }
403                    finally {
404                            closeSession(session);
405                    }
406            }
407    
408            protected AssetEntry getByCompanyId_PrevAndNext(Session session,
409                    AssetEntry assetEntry, long companyId,
410                    OrderByComparator orderByComparator, boolean previous) {
411                    StringBundler query = null;
412    
413                    if (orderByComparator != null) {
414                            query = new StringBundler(6 +
415                                            (orderByComparator.getOrderByFields().length * 6));
416                    }
417                    else {
418                            query = new StringBundler(3);
419                    }
420    
421                    query.append(_SQL_SELECT_ASSETENTRY_WHERE);
422    
423                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
424    
425                    if (orderByComparator != null) {
426                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
427    
428                            if (orderByConditionFields.length > 0) {
429                                    query.append(WHERE_AND);
430                            }
431    
432                            for (int i = 0; i < orderByConditionFields.length; i++) {
433                                    query.append(_ORDER_BY_ENTITY_ALIAS);
434                                    query.append(orderByConditionFields[i]);
435    
436                                    if ((i + 1) < orderByConditionFields.length) {
437                                            if (orderByComparator.isAscending() ^ previous) {
438                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
439                                            }
440                                            else {
441                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
442                                            }
443                                    }
444                                    else {
445                                            if (orderByComparator.isAscending() ^ previous) {
446                                                    query.append(WHERE_GREATER_THAN);
447                                            }
448                                            else {
449                                                    query.append(WHERE_LESSER_THAN);
450                                            }
451                                    }
452                            }
453    
454                            query.append(ORDER_BY_CLAUSE);
455    
456                            String[] orderByFields = orderByComparator.getOrderByFields();
457    
458                            for (int i = 0; i < orderByFields.length; i++) {
459                                    query.append(_ORDER_BY_ENTITY_ALIAS);
460                                    query.append(orderByFields[i]);
461    
462                                    if ((i + 1) < orderByFields.length) {
463                                            if (orderByComparator.isAscending() ^ previous) {
464                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
465                                            }
466                                            else {
467                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
468                                            }
469                                    }
470                                    else {
471                                            if (orderByComparator.isAscending() ^ previous) {
472                                                    query.append(ORDER_BY_ASC);
473                                            }
474                                            else {
475                                                    query.append(ORDER_BY_DESC);
476                                            }
477                                    }
478                            }
479                    }
480                    else {
481                            query.append(AssetEntryModelImpl.ORDER_BY_JPQL);
482                    }
483    
484                    String sql = query.toString();
485    
486                    Query q = session.createQuery(sql);
487    
488                    q.setFirstResult(0);
489                    q.setMaxResults(2);
490    
491                    QueryPos qPos = QueryPos.getInstance(q);
492    
493                    qPos.add(companyId);
494    
495                    if (orderByComparator != null) {
496                            Object[] values = orderByComparator.getOrderByConditionValues(assetEntry);
497    
498                            for (Object value : values) {
499                                    qPos.add(value);
500                            }
501                    }
502    
503                    List<AssetEntry> 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 asset entries where companyId = &#63; from the database.
515             *
516             * @param companyId the company ID
517             * @throws SystemException if a system exception occurred
518             */
519            @Override
520            public void removeByCompanyId(long companyId) throws SystemException {
521                    for (AssetEntry assetEntry : findByCompanyId(companyId,
522                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
523                            remove(assetEntry);
524                    }
525            }
526    
527            /**
528             * Returns the number of asset entries where companyId = &#63;.
529             *
530             * @param companyId the company ID
531             * @return the number of matching asset entries
532             * @throws SystemException if a system exception occurred
533             */
534            @Override
535            public int countByCompanyId(long companyId) throws SystemException {
536                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
537    
538                    Object[] finderArgs = new Object[] { companyId };
539    
540                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
541                                    this);
542    
543                    if (count == null) {
544                            StringBundler query = new StringBundler(2);
545    
546                            query.append(_SQL_COUNT_ASSETENTRY_WHERE);
547    
548                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
549    
550                            String sql = query.toString();
551    
552                            Session session = null;
553    
554                            try {
555                                    session = openSession();
556    
557                                    Query q = session.createQuery(sql);
558    
559                                    QueryPos qPos = QueryPos.getInstance(q);
560    
561                                    qPos.add(companyId);
562    
563                                    count = (Long)q.uniqueResult();
564    
565                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
566                            }
567                            catch (Exception e) {
568                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
569    
570                                    throw processException(e);
571                            }
572                            finally {
573                                    closeSession(session);
574                            }
575                    }
576    
577                    return count.intValue();
578            }
579    
580            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "assetEntry.companyId = ?";
581            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_VISIBLE = new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
582                            AssetEntryModelImpl.FINDER_CACHE_ENABLED, AssetEntryImpl.class,
583                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByVisible",
584                            new String[] {
585                                    Boolean.class.getName(),
586                                    
587                            Integer.class.getName(), Integer.class.getName(),
588                                    OrderByComparator.class.getName()
589                            });
590            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_VISIBLE =
591                    new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
592                            AssetEntryModelImpl.FINDER_CACHE_ENABLED, AssetEntryImpl.class,
593                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByVisible",
594                            new String[] { Boolean.class.getName() },
595                            AssetEntryModelImpl.VISIBLE_COLUMN_BITMASK);
596            public static final FinderPath FINDER_PATH_COUNT_BY_VISIBLE = new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
597                            AssetEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
598                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByVisible",
599                            new String[] { Boolean.class.getName() });
600    
601            /**
602             * Returns all the asset entries where visible = &#63;.
603             *
604             * @param visible the visible
605             * @return the matching asset entries
606             * @throws SystemException if a system exception occurred
607             */
608            @Override
609            public List<AssetEntry> findByVisible(boolean visible)
610                    throws SystemException {
611                    return findByVisible(visible, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
612            }
613    
614            /**
615             * Returns a range of all the asset entries where visible = &#63;.
616             *
617             * <p>
618             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. 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.portlet.asset.model.impl.AssetEntryModelImpl}. 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.
619             * </p>
620             *
621             * @param visible the visible
622             * @param start the lower bound of the range of asset entries
623             * @param end the upper bound of the range of asset entries (not inclusive)
624             * @return the range of matching asset entries
625             * @throws SystemException if a system exception occurred
626             */
627            @Override
628            public List<AssetEntry> findByVisible(boolean visible, int start, int end)
629                    throws SystemException {
630                    return findByVisible(visible, start, end, null);
631            }
632    
633            /**
634             * Returns an ordered range of all the asset entries where visible = &#63;.
635             *
636             * <p>
637             * 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.portlet.asset.model.impl.AssetEntryModelImpl}. 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.
638             * </p>
639             *
640             * @param visible the visible
641             * @param start the lower bound of the range of asset entries
642             * @param end the upper bound of the range of asset entries (not inclusive)
643             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
644             * @return the ordered range of matching asset entries
645             * @throws SystemException if a system exception occurred
646             */
647            @Override
648            public List<AssetEntry> findByVisible(boolean visible, int start, int end,
649                    OrderByComparator orderByComparator) throws SystemException {
650                    boolean pagination = true;
651                    FinderPath finderPath = null;
652                    Object[] finderArgs = null;
653    
654                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
655                                    (orderByComparator == null)) {
656                            pagination = false;
657                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_VISIBLE;
658                            finderArgs = new Object[] { visible };
659                    }
660                    else {
661                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_VISIBLE;
662                            finderArgs = new Object[] { visible, start, end, orderByComparator };
663                    }
664    
665                    List<AssetEntry> list = (List<AssetEntry>)FinderCacheUtil.getResult(finderPath,
666                                    finderArgs, this);
667    
668                    if ((list != null) && !list.isEmpty()) {
669                            for (AssetEntry assetEntry : list) {
670                                    if ((visible != assetEntry.getVisible())) {
671                                            list = null;
672    
673                                            break;
674                                    }
675                            }
676                    }
677    
678                    if (list == null) {
679                            StringBundler query = null;
680    
681                            if (orderByComparator != null) {
682                                    query = new StringBundler(3 +
683                                                    (orderByComparator.getOrderByFields().length * 3));
684                            }
685                            else {
686                                    query = new StringBundler(3);
687                            }
688    
689                            query.append(_SQL_SELECT_ASSETENTRY_WHERE);
690    
691                            query.append(_FINDER_COLUMN_VISIBLE_VISIBLE_2);
692    
693                            if (orderByComparator != null) {
694                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
695                                            orderByComparator);
696                            }
697                            else
698                             if (pagination) {
699                                    query.append(AssetEntryModelImpl.ORDER_BY_JPQL);
700                            }
701    
702                            String sql = query.toString();
703    
704                            Session session = null;
705    
706                            try {
707                                    session = openSession();
708    
709                                    Query q = session.createQuery(sql);
710    
711                                    QueryPos qPos = QueryPos.getInstance(q);
712    
713                                    qPos.add(visible);
714    
715                                    if (!pagination) {
716                                            list = (List<AssetEntry>)QueryUtil.list(q, getDialect(),
717                                                            start, end, false);
718    
719                                            Collections.sort(list);
720    
721                                            list = new UnmodifiableList<AssetEntry>(list);
722                                    }
723                                    else {
724                                            list = (List<AssetEntry>)QueryUtil.list(q, getDialect(),
725                                                            start, end);
726                                    }
727    
728                                    cacheResult(list);
729    
730                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
731                            }
732                            catch (Exception e) {
733                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
734    
735                                    throw processException(e);
736                            }
737                            finally {
738                                    closeSession(session);
739                            }
740                    }
741    
742                    return list;
743            }
744    
745            /**
746             * Returns the first asset entry in the ordered set where visible = &#63;.
747             *
748             * @param visible the visible
749             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
750             * @return the first matching asset entry
751             * @throws com.liferay.portlet.asset.NoSuchEntryException if a matching asset entry could not be found
752             * @throws SystemException if a system exception occurred
753             */
754            @Override
755            public AssetEntry findByVisible_First(boolean visible,
756                    OrderByComparator orderByComparator)
757                    throws NoSuchEntryException, SystemException {
758                    AssetEntry assetEntry = fetchByVisible_First(visible, orderByComparator);
759    
760                    if (assetEntry != null) {
761                            return assetEntry;
762                    }
763    
764                    StringBundler msg = new StringBundler(4);
765    
766                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
767    
768                    msg.append("visible=");
769                    msg.append(visible);
770    
771                    msg.append(StringPool.CLOSE_CURLY_BRACE);
772    
773                    throw new NoSuchEntryException(msg.toString());
774            }
775    
776            /**
777             * Returns the first asset entry in the ordered set where visible = &#63;.
778             *
779             * @param visible the visible
780             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
781             * @return the first matching asset entry, or <code>null</code> if a matching asset entry could not be found
782             * @throws SystemException if a system exception occurred
783             */
784            @Override
785            public AssetEntry fetchByVisible_First(boolean visible,
786                    OrderByComparator orderByComparator) throws SystemException {
787                    List<AssetEntry> list = findByVisible(visible, 0, 1, orderByComparator);
788    
789                    if (!list.isEmpty()) {
790                            return list.get(0);
791                    }
792    
793                    return null;
794            }
795    
796            /**
797             * Returns the last asset entry in the ordered set where visible = &#63;.
798             *
799             * @param visible the visible
800             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
801             * @return the last matching asset entry
802             * @throws com.liferay.portlet.asset.NoSuchEntryException if a matching asset entry could not be found
803             * @throws SystemException if a system exception occurred
804             */
805            @Override
806            public AssetEntry findByVisible_Last(boolean visible,
807                    OrderByComparator orderByComparator)
808                    throws NoSuchEntryException, SystemException {
809                    AssetEntry assetEntry = fetchByVisible_Last(visible, orderByComparator);
810    
811                    if (assetEntry != null) {
812                            return assetEntry;
813                    }
814    
815                    StringBundler msg = new StringBundler(4);
816    
817                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
818    
819                    msg.append("visible=");
820                    msg.append(visible);
821    
822                    msg.append(StringPool.CLOSE_CURLY_BRACE);
823    
824                    throw new NoSuchEntryException(msg.toString());
825            }
826    
827            /**
828             * Returns the last asset entry in the ordered set where visible = &#63;.
829             *
830             * @param visible the visible
831             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
832             * @return the last matching asset entry, or <code>null</code> if a matching asset entry could not be found
833             * @throws SystemException if a system exception occurred
834             */
835            @Override
836            public AssetEntry fetchByVisible_Last(boolean visible,
837                    OrderByComparator orderByComparator) throws SystemException {
838                    int count = countByVisible(visible);
839    
840                    if (count == 0) {
841                            return null;
842                    }
843    
844                    List<AssetEntry> list = findByVisible(visible, count - 1, count,
845                                    orderByComparator);
846    
847                    if (!list.isEmpty()) {
848                            return list.get(0);
849                    }
850    
851                    return null;
852            }
853    
854            /**
855             * Returns the asset entries before and after the current asset entry in the ordered set where visible = &#63;.
856             *
857             * @param entryId the primary key of the current asset entry
858             * @param visible the visible
859             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
860             * @return the previous, current, and next asset entry
861             * @throws com.liferay.portlet.asset.NoSuchEntryException if a asset entry with the primary key could not be found
862             * @throws SystemException if a system exception occurred
863             */
864            @Override
865            public AssetEntry[] findByVisible_PrevAndNext(long entryId,
866                    boolean visible, OrderByComparator orderByComparator)
867                    throws NoSuchEntryException, SystemException {
868                    AssetEntry assetEntry = findByPrimaryKey(entryId);
869    
870                    Session session = null;
871    
872                    try {
873                            session = openSession();
874    
875                            AssetEntry[] array = new AssetEntryImpl[3];
876    
877                            array[0] = getByVisible_PrevAndNext(session, assetEntry, visible,
878                                            orderByComparator, true);
879    
880                            array[1] = assetEntry;
881    
882                            array[2] = getByVisible_PrevAndNext(session, assetEntry, visible,
883                                            orderByComparator, false);
884    
885                            return array;
886                    }
887                    catch (Exception e) {
888                            throw processException(e);
889                    }
890                    finally {
891                            closeSession(session);
892                    }
893            }
894    
895            protected AssetEntry getByVisible_PrevAndNext(Session session,
896                    AssetEntry assetEntry, boolean visible,
897                    OrderByComparator orderByComparator, boolean previous) {
898                    StringBundler query = null;
899    
900                    if (orderByComparator != null) {
901                            query = new StringBundler(6 +
902                                            (orderByComparator.getOrderByFields().length * 6));
903                    }
904                    else {
905                            query = new StringBundler(3);
906                    }
907    
908                    query.append(_SQL_SELECT_ASSETENTRY_WHERE);
909    
910                    query.append(_FINDER_COLUMN_VISIBLE_VISIBLE_2);
911    
912                    if (orderByComparator != null) {
913                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
914    
915                            if (orderByConditionFields.length > 0) {
916                                    query.append(WHERE_AND);
917                            }
918    
919                            for (int i = 0; i < orderByConditionFields.length; i++) {
920                                    query.append(_ORDER_BY_ENTITY_ALIAS);
921                                    query.append(orderByConditionFields[i]);
922    
923                                    if ((i + 1) < orderByConditionFields.length) {
924                                            if (orderByComparator.isAscending() ^ previous) {
925                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
926                                            }
927                                            else {
928                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
929                                            }
930                                    }
931                                    else {
932                                            if (orderByComparator.isAscending() ^ previous) {
933                                                    query.append(WHERE_GREATER_THAN);
934                                            }
935                                            else {
936                                                    query.append(WHERE_LESSER_THAN);
937                                            }
938                                    }
939                            }
940    
941                            query.append(ORDER_BY_CLAUSE);
942    
943                            String[] orderByFields = orderByComparator.getOrderByFields();
944    
945                            for (int i = 0; i < orderByFields.length; i++) {
946                                    query.append(_ORDER_BY_ENTITY_ALIAS);
947                                    query.append(orderByFields[i]);
948    
949                                    if ((i + 1) < orderByFields.length) {
950                                            if (orderByComparator.isAscending() ^ previous) {
951                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
952                                            }
953                                            else {
954                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
955                                            }
956                                    }
957                                    else {
958                                            if (orderByComparator.isAscending() ^ previous) {
959                                                    query.append(ORDER_BY_ASC);
960                                            }
961                                            else {
962                                                    query.append(ORDER_BY_DESC);
963                                            }
964                                    }
965                            }
966                    }
967                    else {
968                            query.append(AssetEntryModelImpl.ORDER_BY_JPQL);
969                    }
970    
971                    String sql = query.toString();
972    
973                    Query q = session.createQuery(sql);
974    
975                    q.setFirstResult(0);
976                    q.setMaxResults(2);
977    
978                    QueryPos qPos = QueryPos.getInstance(q);
979    
980                    qPos.add(visible);
981    
982                    if (orderByComparator != null) {
983                            Object[] values = orderByComparator.getOrderByConditionValues(assetEntry);
984    
985                            for (Object value : values) {
986                                    qPos.add(value);
987                            }
988                    }
989    
990                    List<AssetEntry> list = q.list();
991    
992                    if (list.size() == 2) {
993                            return list.get(1);
994                    }
995                    else {
996                            return null;
997                    }
998            }
999    
1000            /**
1001             * Removes all the asset entries where visible = &#63; from the database.
1002             *
1003             * @param visible the visible
1004             * @throws SystemException if a system exception occurred
1005             */
1006            @Override
1007            public void removeByVisible(boolean visible) throws SystemException {
1008                    for (AssetEntry assetEntry : findByVisible(visible, QueryUtil.ALL_POS,
1009                                    QueryUtil.ALL_POS, null)) {
1010                            remove(assetEntry);
1011                    }
1012            }
1013    
1014            /**
1015             * Returns the number of asset entries where visible = &#63;.
1016             *
1017             * @param visible the visible
1018             * @return the number of matching asset entries
1019             * @throws SystemException if a system exception occurred
1020             */
1021            @Override
1022            public int countByVisible(boolean visible) throws SystemException {
1023                    FinderPath finderPath = FINDER_PATH_COUNT_BY_VISIBLE;
1024    
1025                    Object[] finderArgs = new Object[] { visible };
1026    
1027                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1028                                    this);
1029    
1030                    if (count == null) {
1031                            StringBundler query = new StringBundler(2);
1032    
1033                            query.append(_SQL_COUNT_ASSETENTRY_WHERE);
1034    
1035                            query.append(_FINDER_COLUMN_VISIBLE_VISIBLE_2);
1036    
1037                            String sql = query.toString();
1038    
1039                            Session session = null;
1040    
1041                            try {
1042                                    session = openSession();
1043    
1044                                    Query q = session.createQuery(sql);
1045    
1046                                    QueryPos qPos = QueryPos.getInstance(q);
1047    
1048                                    qPos.add(visible);
1049    
1050                                    count = (Long)q.uniqueResult();
1051    
1052                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1053                            }
1054                            catch (Exception e) {
1055                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1056    
1057                                    throw processException(e);
1058                            }
1059                            finally {
1060                                    closeSession(session);
1061                            }
1062                    }
1063    
1064                    return count.intValue();
1065            }
1066    
1067            private static final String _FINDER_COLUMN_VISIBLE_VISIBLE_2 = "assetEntry.visible = ?";
1068            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_PUBLISHDATE =
1069                    new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
1070                            AssetEntryModelImpl.FINDER_CACHE_ENABLED, AssetEntryImpl.class,
1071                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByPublishDate",
1072                            new String[] {
1073                                    Date.class.getName(),
1074                                    
1075                            Integer.class.getName(), Integer.class.getName(),
1076                                    OrderByComparator.class.getName()
1077                            });
1078            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PUBLISHDATE =
1079                    new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
1080                            AssetEntryModelImpl.FINDER_CACHE_ENABLED, AssetEntryImpl.class,
1081                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByPublishDate",
1082                            new String[] { Date.class.getName() },
1083                            AssetEntryModelImpl.PUBLISHDATE_COLUMN_BITMASK);
1084            public static final FinderPath FINDER_PATH_COUNT_BY_PUBLISHDATE = new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
1085                            AssetEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
1086                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByPublishDate",
1087                            new String[] { Date.class.getName() });
1088    
1089            /**
1090             * Returns all the asset entries where publishDate = &#63;.
1091             *
1092             * @param publishDate the publish date
1093             * @return the matching asset entries
1094             * @throws SystemException if a system exception occurred
1095             */
1096            @Override
1097            public List<AssetEntry> findByPublishDate(Date publishDate)
1098                    throws SystemException {
1099                    return findByPublishDate(publishDate, QueryUtil.ALL_POS,
1100                            QueryUtil.ALL_POS, null);
1101            }
1102    
1103            /**
1104             * Returns a range of all the asset entries where publishDate = &#63;.
1105             *
1106             * <p>
1107             * 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.portlet.asset.model.impl.AssetEntryModelImpl}. 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.
1108             * </p>
1109             *
1110             * @param publishDate the publish date
1111             * @param start the lower bound of the range of asset entries
1112             * @param end the upper bound of the range of asset entries (not inclusive)
1113             * @return the range of matching asset entries
1114             * @throws SystemException if a system exception occurred
1115             */
1116            @Override
1117            public List<AssetEntry> findByPublishDate(Date publishDate, int start,
1118                    int end) throws SystemException {
1119                    return findByPublishDate(publishDate, start, end, null);
1120            }
1121    
1122            /**
1123             * Returns an ordered range of all the asset entries where publishDate = &#63;.
1124             *
1125             * <p>
1126             * 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.portlet.asset.model.impl.AssetEntryModelImpl}. 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.
1127             * </p>
1128             *
1129             * @param publishDate the publish date
1130             * @param start the lower bound of the range of asset entries
1131             * @param end the upper bound of the range of asset entries (not inclusive)
1132             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1133             * @return the ordered range of matching asset entries
1134             * @throws SystemException if a system exception occurred
1135             */
1136            @Override
1137            public List<AssetEntry> findByPublishDate(Date publishDate, int start,
1138                    int end, OrderByComparator orderByComparator) throws SystemException {
1139                    boolean pagination = true;
1140                    FinderPath finderPath = null;
1141                    Object[] finderArgs = null;
1142    
1143                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1144                                    (orderByComparator == null)) {
1145                            pagination = false;
1146                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PUBLISHDATE;
1147                            finderArgs = new Object[] { publishDate };
1148                    }
1149                    else {
1150                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_PUBLISHDATE;
1151                            finderArgs = new Object[] { publishDate, start, end, orderByComparator };
1152                    }
1153    
1154                    List<AssetEntry> list = (List<AssetEntry>)FinderCacheUtil.getResult(finderPath,
1155                                    finderArgs, this);
1156    
1157                    if ((list != null) && !list.isEmpty()) {
1158                            for (AssetEntry assetEntry : list) {
1159                                    if (!Validator.equals(publishDate, assetEntry.getPublishDate())) {
1160                                            list = null;
1161    
1162                                            break;
1163                                    }
1164                            }
1165                    }
1166    
1167                    if (list == null) {
1168                            StringBundler query = null;
1169    
1170                            if (orderByComparator != null) {
1171                                    query = new StringBundler(3 +
1172                                                    (orderByComparator.getOrderByFields().length * 3));
1173                            }
1174                            else {
1175                                    query = new StringBundler(3);
1176                            }
1177    
1178                            query.append(_SQL_SELECT_ASSETENTRY_WHERE);
1179    
1180                            boolean bindPublishDate = false;
1181    
1182                            if (publishDate == null) {
1183                                    query.append(_FINDER_COLUMN_PUBLISHDATE_PUBLISHDATE_1);
1184                            }
1185                            else {
1186                                    bindPublishDate = true;
1187    
1188                                    query.append(_FINDER_COLUMN_PUBLISHDATE_PUBLISHDATE_2);
1189                            }
1190    
1191                            if (orderByComparator != null) {
1192                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1193                                            orderByComparator);
1194                            }
1195                            else
1196                             if (pagination) {
1197                                    query.append(AssetEntryModelImpl.ORDER_BY_JPQL);
1198                            }
1199    
1200                            String sql = query.toString();
1201    
1202                            Session session = null;
1203    
1204                            try {
1205                                    session = openSession();
1206    
1207                                    Query q = session.createQuery(sql);
1208    
1209                                    QueryPos qPos = QueryPos.getInstance(q);
1210    
1211                                    if (bindPublishDate) {
1212                                            qPos.add(CalendarUtil.getTimestamp(publishDate));
1213                                    }
1214    
1215                                    if (!pagination) {
1216                                            list = (List<AssetEntry>)QueryUtil.list(q, getDialect(),
1217                                                            start, end, false);
1218    
1219                                            Collections.sort(list);
1220    
1221                                            list = new UnmodifiableList<AssetEntry>(list);
1222                                    }
1223                                    else {
1224                                            list = (List<AssetEntry>)QueryUtil.list(q, getDialect(),
1225                                                            start, end);
1226                                    }
1227    
1228                                    cacheResult(list);
1229    
1230                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1231                            }
1232                            catch (Exception e) {
1233                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1234    
1235                                    throw processException(e);
1236                            }
1237                            finally {
1238                                    closeSession(session);
1239                            }
1240                    }
1241    
1242                    return list;
1243            }
1244    
1245            /**
1246             * Returns the first asset entry in the ordered set where publishDate = &#63;.
1247             *
1248             * @param publishDate the publish date
1249             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1250             * @return the first matching asset entry
1251             * @throws com.liferay.portlet.asset.NoSuchEntryException if a matching asset entry could not be found
1252             * @throws SystemException if a system exception occurred
1253             */
1254            @Override
1255            public AssetEntry findByPublishDate_First(Date publishDate,
1256                    OrderByComparator orderByComparator)
1257                    throws NoSuchEntryException, SystemException {
1258                    AssetEntry assetEntry = fetchByPublishDate_First(publishDate,
1259                                    orderByComparator);
1260    
1261                    if (assetEntry != null) {
1262                            return assetEntry;
1263                    }
1264    
1265                    StringBundler msg = new StringBundler(4);
1266    
1267                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1268    
1269                    msg.append("publishDate=");
1270                    msg.append(publishDate);
1271    
1272                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1273    
1274                    throw new NoSuchEntryException(msg.toString());
1275            }
1276    
1277            /**
1278             * Returns the first asset entry in the ordered set where publishDate = &#63;.
1279             *
1280             * @param publishDate the publish date
1281             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1282             * @return the first matching asset entry, or <code>null</code> if a matching asset entry could not be found
1283             * @throws SystemException if a system exception occurred
1284             */
1285            @Override
1286            public AssetEntry fetchByPublishDate_First(Date publishDate,
1287                    OrderByComparator orderByComparator) throws SystemException {
1288                    List<AssetEntry> list = findByPublishDate(publishDate, 0, 1,
1289                                    orderByComparator);
1290    
1291                    if (!list.isEmpty()) {
1292                            return list.get(0);
1293                    }
1294    
1295                    return null;
1296            }
1297    
1298            /**
1299             * Returns the last asset entry in the ordered set where publishDate = &#63;.
1300             *
1301             * @param publishDate the publish date
1302             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1303             * @return the last matching asset entry
1304             * @throws com.liferay.portlet.asset.NoSuchEntryException if a matching asset entry could not be found
1305             * @throws SystemException if a system exception occurred
1306             */
1307            @Override
1308            public AssetEntry findByPublishDate_Last(Date publishDate,
1309                    OrderByComparator orderByComparator)
1310                    throws NoSuchEntryException, SystemException {
1311                    AssetEntry assetEntry = fetchByPublishDate_Last(publishDate,
1312                                    orderByComparator);
1313    
1314                    if (assetEntry != null) {
1315                            return assetEntry;
1316                    }
1317    
1318                    StringBundler msg = new StringBundler(4);
1319    
1320                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1321    
1322                    msg.append("publishDate=");
1323                    msg.append(publishDate);
1324    
1325                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1326    
1327                    throw new NoSuchEntryException(msg.toString());
1328            }
1329    
1330            /**
1331             * Returns the last asset entry in the ordered set where publishDate = &#63;.
1332             *
1333             * @param publishDate the publish date
1334             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1335             * @return the last matching asset entry, or <code>null</code> if a matching asset entry could not be found
1336             * @throws SystemException if a system exception occurred
1337             */
1338            @Override
1339            public AssetEntry fetchByPublishDate_Last(Date publishDate,
1340                    OrderByComparator orderByComparator) throws SystemException {
1341                    int count = countByPublishDate(publishDate);
1342    
1343                    if (count == 0) {
1344                            return null;
1345                    }
1346    
1347                    List<AssetEntry> list = findByPublishDate(publishDate, count - 1,
1348                                    count, orderByComparator);
1349    
1350                    if (!list.isEmpty()) {
1351                            return list.get(0);
1352                    }
1353    
1354                    return null;
1355            }
1356    
1357            /**
1358             * Returns the asset entries before and after the current asset entry in the ordered set where publishDate = &#63;.
1359             *
1360             * @param entryId the primary key of the current asset entry
1361             * @param publishDate the publish date
1362             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1363             * @return the previous, current, and next asset entry
1364             * @throws com.liferay.portlet.asset.NoSuchEntryException if a asset entry with the primary key could not be found
1365             * @throws SystemException if a system exception occurred
1366             */
1367            @Override
1368            public AssetEntry[] findByPublishDate_PrevAndNext(long entryId,
1369                    Date publishDate, OrderByComparator orderByComparator)
1370                    throws NoSuchEntryException, SystemException {
1371                    AssetEntry assetEntry = findByPrimaryKey(entryId);
1372    
1373                    Session session = null;
1374    
1375                    try {
1376                            session = openSession();
1377    
1378                            AssetEntry[] array = new AssetEntryImpl[3];
1379    
1380                            array[0] = getByPublishDate_PrevAndNext(session, assetEntry,
1381                                            publishDate, orderByComparator, true);
1382    
1383                            array[1] = assetEntry;
1384    
1385                            array[2] = getByPublishDate_PrevAndNext(session, assetEntry,
1386                                            publishDate, orderByComparator, false);
1387    
1388                            return array;
1389                    }
1390                    catch (Exception e) {
1391                            throw processException(e);
1392                    }
1393                    finally {
1394                            closeSession(session);
1395                    }
1396            }
1397    
1398            protected AssetEntry getByPublishDate_PrevAndNext(Session session,
1399                    AssetEntry assetEntry, Date publishDate,
1400                    OrderByComparator orderByComparator, boolean previous) {
1401                    StringBundler query = null;
1402    
1403                    if (orderByComparator != null) {
1404                            query = new StringBundler(6 +
1405                                            (orderByComparator.getOrderByFields().length * 6));
1406                    }
1407                    else {
1408                            query = new StringBundler(3);
1409                    }
1410    
1411                    query.append(_SQL_SELECT_ASSETENTRY_WHERE);
1412    
1413                    boolean bindPublishDate = false;
1414    
1415                    if (publishDate == null) {
1416                            query.append(_FINDER_COLUMN_PUBLISHDATE_PUBLISHDATE_1);
1417                    }
1418                    else {
1419                            bindPublishDate = true;
1420    
1421                            query.append(_FINDER_COLUMN_PUBLISHDATE_PUBLISHDATE_2);
1422                    }
1423    
1424                    if (orderByComparator != null) {
1425                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1426    
1427                            if (orderByConditionFields.length > 0) {
1428                                    query.append(WHERE_AND);
1429                            }
1430    
1431                            for (int i = 0; i < orderByConditionFields.length; i++) {
1432                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1433                                    query.append(orderByConditionFields[i]);
1434    
1435                                    if ((i + 1) < orderByConditionFields.length) {
1436                                            if (orderByComparator.isAscending() ^ previous) {
1437                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1438                                            }
1439                                            else {
1440                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1441                                            }
1442                                    }
1443                                    else {
1444                                            if (orderByComparator.isAscending() ^ previous) {
1445                                                    query.append(WHERE_GREATER_THAN);
1446                                            }
1447                                            else {
1448                                                    query.append(WHERE_LESSER_THAN);
1449                                            }
1450                                    }
1451                            }
1452    
1453                            query.append(ORDER_BY_CLAUSE);
1454    
1455                            String[] orderByFields = orderByComparator.getOrderByFields();
1456    
1457                            for (int i = 0; i < orderByFields.length; i++) {
1458                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1459                                    query.append(orderByFields[i]);
1460    
1461                                    if ((i + 1) < orderByFields.length) {
1462                                            if (orderByComparator.isAscending() ^ previous) {
1463                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1464                                            }
1465                                            else {
1466                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1467                                            }
1468                                    }
1469                                    else {
1470                                            if (orderByComparator.isAscending() ^ previous) {
1471                                                    query.append(ORDER_BY_ASC);
1472                                            }
1473                                            else {
1474                                                    query.append(ORDER_BY_DESC);
1475                                            }
1476                                    }
1477                            }
1478                    }
1479                    else {
1480                            query.append(AssetEntryModelImpl.ORDER_BY_JPQL);
1481                    }
1482    
1483                    String sql = query.toString();
1484    
1485                    Query q = session.createQuery(sql);
1486    
1487                    q.setFirstResult(0);
1488                    q.setMaxResults(2);
1489    
1490                    QueryPos qPos = QueryPos.getInstance(q);
1491    
1492                    if (bindPublishDate) {
1493                            qPos.add(CalendarUtil.getTimestamp(publishDate));
1494                    }
1495    
1496                    if (orderByComparator != null) {
1497                            Object[] values = orderByComparator.getOrderByConditionValues(assetEntry);
1498    
1499                            for (Object value : values) {
1500                                    qPos.add(value);
1501                            }
1502                    }
1503    
1504                    List<AssetEntry> list = q.list();
1505    
1506                    if (list.size() == 2) {
1507                            return list.get(1);
1508                    }
1509                    else {
1510                            return null;
1511                    }
1512            }
1513    
1514            /**
1515             * Removes all the asset entries where publishDate = &#63; from the database.
1516             *
1517             * @param publishDate the publish date
1518             * @throws SystemException if a system exception occurred
1519             */
1520            @Override
1521            public void removeByPublishDate(Date publishDate) throws SystemException {
1522                    for (AssetEntry assetEntry : findByPublishDate(publishDate,
1523                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1524                            remove(assetEntry);
1525                    }
1526            }
1527    
1528            /**
1529             * Returns the number of asset entries where publishDate = &#63;.
1530             *
1531             * @param publishDate the publish date
1532             * @return the number of matching asset entries
1533             * @throws SystemException if a system exception occurred
1534             */
1535            @Override
1536            public int countByPublishDate(Date publishDate) throws SystemException {
1537                    FinderPath finderPath = FINDER_PATH_COUNT_BY_PUBLISHDATE;
1538    
1539                    Object[] finderArgs = new Object[] { publishDate };
1540    
1541                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1542                                    this);
1543    
1544                    if (count == null) {
1545                            StringBundler query = new StringBundler(2);
1546    
1547                            query.append(_SQL_COUNT_ASSETENTRY_WHERE);
1548    
1549                            boolean bindPublishDate = false;
1550    
1551                            if (publishDate == null) {
1552                                    query.append(_FINDER_COLUMN_PUBLISHDATE_PUBLISHDATE_1);
1553                            }
1554                            else {
1555                                    bindPublishDate = true;
1556    
1557                                    query.append(_FINDER_COLUMN_PUBLISHDATE_PUBLISHDATE_2);
1558                            }
1559    
1560                            String sql = query.toString();
1561    
1562                            Session session = null;
1563    
1564                            try {
1565                                    session = openSession();
1566    
1567                                    Query q = session.createQuery(sql);
1568    
1569                                    QueryPos qPos = QueryPos.getInstance(q);
1570    
1571                                    if (bindPublishDate) {
1572                                            qPos.add(CalendarUtil.getTimestamp(publishDate));
1573                                    }
1574    
1575                                    count = (Long)q.uniqueResult();
1576    
1577                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1578                            }
1579                            catch (Exception e) {
1580                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1581    
1582                                    throw processException(e);
1583                            }
1584                            finally {
1585                                    closeSession(session);
1586                            }
1587                    }
1588    
1589                    return count.intValue();
1590            }
1591    
1592            private static final String _FINDER_COLUMN_PUBLISHDATE_PUBLISHDATE_1 = "assetEntry.publishDate IS NULL";
1593            private static final String _FINDER_COLUMN_PUBLISHDATE_PUBLISHDATE_2 = "assetEntry.publishDate = ?";
1594            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_EXPIRATIONDATE =
1595                    new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
1596                            AssetEntryModelImpl.FINDER_CACHE_ENABLED, AssetEntryImpl.class,
1597                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByExpirationDate",
1598                            new String[] {
1599                                    Date.class.getName(),
1600                                    
1601                            Integer.class.getName(), Integer.class.getName(),
1602                                    OrderByComparator.class.getName()
1603                            });
1604            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_EXPIRATIONDATE =
1605                    new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
1606                            AssetEntryModelImpl.FINDER_CACHE_ENABLED, AssetEntryImpl.class,
1607                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByExpirationDate",
1608                            new String[] { Date.class.getName() },
1609                            AssetEntryModelImpl.EXPIRATIONDATE_COLUMN_BITMASK);
1610            public static final FinderPath FINDER_PATH_COUNT_BY_EXPIRATIONDATE = new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
1611                            AssetEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
1612                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByExpirationDate",
1613                            new String[] { Date.class.getName() });
1614    
1615            /**
1616             * Returns all the asset entries where expirationDate = &#63;.
1617             *
1618             * @param expirationDate the expiration date
1619             * @return the matching asset entries
1620             * @throws SystemException if a system exception occurred
1621             */
1622            @Override
1623            public List<AssetEntry> findByExpirationDate(Date expirationDate)
1624                    throws SystemException {
1625                    return findByExpirationDate(expirationDate, QueryUtil.ALL_POS,
1626                            QueryUtil.ALL_POS, null);
1627            }
1628    
1629            /**
1630             * Returns a range of all the asset entries where expirationDate = &#63;.
1631             *
1632             * <p>
1633             * 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.portlet.asset.model.impl.AssetEntryModelImpl}. 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.
1634             * </p>
1635             *
1636             * @param expirationDate the expiration date
1637             * @param start the lower bound of the range of asset entries
1638             * @param end the upper bound of the range of asset entries (not inclusive)
1639             * @return the range of matching asset entries
1640             * @throws SystemException if a system exception occurred
1641             */
1642            @Override
1643            public List<AssetEntry> findByExpirationDate(Date expirationDate,
1644                    int start, int end) throws SystemException {
1645                    return findByExpirationDate(expirationDate, start, end, null);
1646            }
1647    
1648            /**
1649             * Returns an ordered range of all the asset entries where expirationDate = &#63;.
1650             *
1651             * <p>
1652             * 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.portlet.asset.model.impl.AssetEntryModelImpl}. 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.
1653             * </p>
1654             *
1655             * @param expirationDate the expiration date
1656             * @param start the lower bound of the range of asset entries
1657             * @param end the upper bound of the range of asset entries (not inclusive)
1658             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1659             * @return the ordered range of matching asset entries
1660             * @throws SystemException if a system exception occurred
1661             */
1662            @Override
1663            public List<AssetEntry> findByExpirationDate(Date expirationDate,
1664                    int start, int end, OrderByComparator orderByComparator)
1665                    throws SystemException {
1666                    boolean pagination = true;
1667                    FinderPath finderPath = null;
1668                    Object[] finderArgs = null;
1669    
1670                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1671                                    (orderByComparator == null)) {
1672                            pagination = false;
1673                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_EXPIRATIONDATE;
1674                            finderArgs = new Object[] { expirationDate };
1675                    }
1676                    else {
1677                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_EXPIRATIONDATE;
1678                            finderArgs = new Object[] {
1679                                            expirationDate,
1680                                            
1681                                            start, end, orderByComparator
1682                                    };
1683                    }
1684    
1685                    List<AssetEntry> list = (List<AssetEntry>)FinderCacheUtil.getResult(finderPath,
1686                                    finderArgs, this);
1687    
1688                    if ((list != null) && !list.isEmpty()) {
1689                            for (AssetEntry assetEntry : list) {
1690                                    if (!Validator.equals(expirationDate,
1691                                                            assetEntry.getExpirationDate())) {
1692                                            list = null;
1693    
1694                                            break;
1695                                    }
1696                            }
1697                    }
1698    
1699                    if (list == null) {
1700                            StringBundler query = null;
1701    
1702                            if (orderByComparator != null) {
1703                                    query = new StringBundler(3 +
1704                                                    (orderByComparator.getOrderByFields().length * 3));
1705                            }
1706                            else {
1707                                    query = new StringBundler(3);
1708                            }
1709    
1710                            query.append(_SQL_SELECT_ASSETENTRY_WHERE);
1711    
1712                            boolean bindExpirationDate = false;
1713    
1714                            if (expirationDate == null) {
1715                                    query.append(_FINDER_COLUMN_EXPIRATIONDATE_EXPIRATIONDATE_1);
1716                            }
1717                            else {
1718                                    bindExpirationDate = true;
1719    
1720                                    query.append(_FINDER_COLUMN_EXPIRATIONDATE_EXPIRATIONDATE_2);
1721                            }
1722    
1723                            if (orderByComparator != null) {
1724                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1725                                            orderByComparator);
1726                            }
1727                            else
1728                             if (pagination) {
1729                                    query.append(AssetEntryModelImpl.ORDER_BY_JPQL);
1730                            }
1731    
1732                            String sql = query.toString();
1733    
1734                            Session session = null;
1735    
1736                            try {
1737                                    session = openSession();
1738    
1739                                    Query q = session.createQuery(sql);
1740    
1741                                    QueryPos qPos = QueryPos.getInstance(q);
1742    
1743                                    if (bindExpirationDate) {
1744                                            qPos.add(CalendarUtil.getTimestamp(expirationDate));
1745                                    }
1746    
1747                                    if (!pagination) {
1748                                            list = (List<AssetEntry>)QueryUtil.list(q, getDialect(),
1749                                                            start, end, false);
1750    
1751                                            Collections.sort(list);
1752    
1753                                            list = new UnmodifiableList<AssetEntry>(list);
1754                                    }
1755                                    else {
1756                                            list = (List<AssetEntry>)QueryUtil.list(q, getDialect(),
1757                                                            start, end);
1758                                    }
1759    
1760                                    cacheResult(list);
1761    
1762                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1763                            }
1764                            catch (Exception e) {
1765                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1766    
1767                                    throw processException(e);
1768                            }
1769                            finally {
1770                                    closeSession(session);
1771                            }
1772                    }
1773    
1774                    return list;
1775            }
1776    
1777            /**
1778             * Returns the first asset entry in the ordered set where expirationDate = &#63;.
1779             *
1780             * @param expirationDate the expiration date
1781             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1782             * @return the first matching asset entry
1783             * @throws com.liferay.portlet.asset.NoSuchEntryException if a matching asset entry could not be found
1784             * @throws SystemException if a system exception occurred
1785             */
1786            @Override
1787            public AssetEntry findByExpirationDate_First(Date expirationDate,
1788                    OrderByComparator orderByComparator)
1789                    throws NoSuchEntryException, SystemException {
1790                    AssetEntry assetEntry = fetchByExpirationDate_First(expirationDate,
1791                                    orderByComparator);
1792    
1793                    if (assetEntry != null) {
1794                            return assetEntry;
1795                    }
1796    
1797                    StringBundler msg = new StringBundler(4);
1798    
1799                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1800    
1801                    msg.append("expirationDate=");
1802                    msg.append(expirationDate);
1803    
1804                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1805    
1806                    throw new NoSuchEntryException(msg.toString());
1807            }
1808    
1809            /**
1810             * Returns the first asset entry in the ordered set where expirationDate = &#63;.
1811             *
1812             * @param expirationDate the expiration date
1813             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1814             * @return the first matching asset entry, or <code>null</code> if a matching asset entry could not be found
1815             * @throws SystemException if a system exception occurred
1816             */
1817            @Override
1818            public AssetEntry fetchByExpirationDate_First(Date expirationDate,
1819                    OrderByComparator orderByComparator) throws SystemException {
1820                    List<AssetEntry> list = findByExpirationDate(expirationDate, 0, 1,
1821                                    orderByComparator);
1822    
1823                    if (!list.isEmpty()) {
1824                            return list.get(0);
1825                    }
1826    
1827                    return null;
1828            }
1829    
1830            /**
1831             * Returns the last asset entry in the ordered set where expirationDate = &#63;.
1832             *
1833             * @param expirationDate the expiration date
1834             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1835             * @return the last matching asset entry
1836             * @throws com.liferay.portlet.asset.NoSuchEntryException if a matching asset entry could not be found
1837             * @throws SystemException if a system exception occurred
1838             */
1839            @Override
1840            public AssetEntry findByExpirationDate_Last(Date expirationDate,
1841                    OrderByComparator orderByComparator)
1842                    throws NoSuchEntryException, SystemException {
1843                    AssetEntry assetEntry = fetchByExpirationDate_Last(expirationDate,
1844                                    orderByComparator);
1845    
1846                    if (assetEntry != null) {
1847                            return assetEntry;
1848                    }
1849    
1850                    StringBundler msg = new StringBundler(4);
1851    
1852                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1853    
1854                    msg.append("expirationDate=");
1855                    msg.append(expirationDate);
1856    
1857                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1858    
1859                    throw new NoSuchEntryException(msg.toString());
1860            }
1861    
1862            /**
1863             * Returns the last asset entry in the ordered set where expirationDate = &#63;.
1864             *
1865             * @param expirationDate the expiration date
1866             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1867             * @return the last matching asset entry, or <code>null</code> if a matching asset entry could not be found
1868             * @throws SystemException if a system exception occurred
1869             */
1870            @Override
1871            public AssetEntry fetchByExpirationDate_Last(Date expirationDate,
1872                    OrderByComparator orderByComparator) throws SystemException {
1873                    int count = countByExpirationDate(expirationDate);
1874    
1875                    if (count == 0) {
1876                            return null;
1877                    }
1878    
1879                    List<AssetEntry> list = findByExpirationDate(expirationDate, count - 1,
1880                                    count, orderByComparator);
1881    
1882                    if (!list.isEmpty()) {
1883                            return list.get(0);
1884                    }
1885    
1886                    return null;
1887            }
1888    
1889            /**
1890             * Returns the asset entries before and after the current asset entry in the ordered set where expirationDate = &#63;.
1891             *
1892             * @param entryId the primary key of the current asset entry
1893             * @param expirationDate the expiration date
1894             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1895             * @return the previous, current, and next asset entry
1896             * @throws com.liferay.portlet.asset.NoSuchEntryException if a asset entry with the primary key could not be found
1897             * @throws SystemException if a system exception occurred
1898             */
1899            @Override
1900            public AssetEntry[] findByExpirationDate_PrevAndNext(long entryId,
1901                    Date expirationDate, OrderByComparator orderByComparator)
1902                    throws NoSuchEntryException, SystemException {
1903                    AssetEntry assetEntry = findByPrimaryKey(entryId);
1904    
1905                    Session session = null;
1906    
1907                    try {
1908                            session = openSession();
1909    
1910                            AssetEntry[] array = new AssetEntryImpl[3];
1911    
1912                            array[0] = getByExpirationDate_PrevAndNext(session, assetEntry,
1913                                            expirationDate, orderByComparator, true);
1914    
1915                            array[1] = assetEntry;
1916    
1917                            array[2] = getByExpirationDate_PrevAndNext(session, assetEntry,
1918                                            expirationDate, orderByComparator, false);
1919    
1920                            return array;
1921                    }
1922                    catch (Exception e) {
1923                            throw processException(e);
1924                    }
1925                    finally {
1926                            closeSession(session);
1927                    }
1928            }
1929    
1930            protected AssetEntry getByExpirationDate_PrevAndNext(Session session,
1931                    AssetEntry assetEntry, Date expirationDate,
1932                    OrderByComparator orderByComparator, boolean previous) {
1933                    StringBundler query = null;
1934    
1935                    if (orderByComparator != null) {
1936                            query = new StringBundler(6 +
1937                                            (orderByComparator.getOrderByFields().length * 6));
1938                    }
1939                    else {
1940                            query = new StringBundler(3);
1941                    }
1942    
1943                    query.append(_SQL_SELECT_ASSETENTRY_WHERE);
1944    
1945                    boolean bindExpirationDate = false;
1946    
1947                    if (expirationDate == null) {
1948                            query.append(_FINDER_COLUMN_EXPIRATIONDATE_EXPIRATIONDATE_1);
1949                    }
1950                    else {
1951                            bindExpirationDate = true;
1952    
1953                            query.append(_FINDER_COLUMN_EXPIRATIONDATE_EXPIRATIONDATE_2);
1954                    }
1955    
1956                    if (orderByComparator != null) {
1957                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1958    
1959                            if (orderByConditionFields.length > 0) {
1960                                    query.append(WHERE_AND);
1961                            }
1962    
1963                            for (int i = 0; i < orderByConditionFields.length; i++) {
1964                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1965                                    query.append(orderByConditionFields[i]);
1966    
1967                                    if ((i + 1) < orderByConditionFields.length) {
1968                                            if (orderByComparator.isAscending() ^ previous) {
1969                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1970                                            }
1971                                            else {
1972                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1973                                            }
1974                                    }
1975                                    else {
1976                                            if (orderByComparator.isAscending() ^ previous) {
1977                                                    query.append(WHERE_GREATER_THAN);
1978                                            }
1979                                            else {
1980                                                    query.append(WHERE_LESSER_THAN);
1981                                            }
1982                                    }
1983                            }
1984    
1985                            query.append(ORDER_BY_CLAUSE);
1986    
1987                            String[] orderByFields = orderByComparator.getOrderByFields();
1988    
1989                            for (int i = 0; i < orderByFields.length; i++) {
1990                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1991                                    query.append(orderByFields[i]);
1992    
1993                                    if ((i + 1) < orderByFields.length) {
1994                                            if (orderByComparator.isAscending() ^ previous) {
1995                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1996                                            }
1997                                            else {
1998                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1999                                            }
2000                                    }
2001                                    else {
2002                                            if (orderByComparator.isAscending() ^ previous) {
2003                                                    query.append(ORDER_BY_ASC);
2004                                            }
2005                                            else {
2006                                                    query.append(ORDER_BY_DESC);
2007                                            }
2008                                    }
2009                            }
2010                    }
2011                    else {
2012                            query.append(AssetEntryModelImpl.ORDER_BY_JPQL);
2013                    }
2014    
2015                    String sql = query.toString();
2016    
2017                    Query q = session.createQuery(sql);
2018    
2019                    q.setFirstResult(0);
2020                    q.setMaxResults(2);
2021    
2022                    QueryPos qPos = QueryPos.getInstance(q);
2023    
2024                    if (bindExpirationDate) {
2025                            qPos.add(CalendarUtil.getTimestamp(expirationDate));
2026                    }
2027    
2028                    if (orderByComparator != null) {
2029                            Object[] values = orderByComparator.getOrderByConditionValues(assetEntry);
2030    
2031                            for (Object value : values) {
2032                                    qPos.add(value);
2033                            }
2034                    }
2035    
2036                    List<AssetEntry> list = q.list();
2037    
2038                    if (list.size() == 2) {
2039                            return list.get(1);
2040                    }
2041                    else {
2042                            return null;
2043                    }
2044            }
2045    
2046            /**
2047             * Removes all the asset entries where expirationDate = &#63; from the database.
2048             *
2049             * @param expirationDate the expiration date
2050             * @throws SystemException if a system exception occurred
2051             */
2052            @Override
2053            public void removeByExpirationDate(Date expirationDate)
2054                    throws SystemException {
2055                    for (AssetEntry assetEntry : findByExpirationDate(expirationDate,
2056                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2057                            remove(assetEntry);
2058                    }
2059            }
2060    
2061            /**
2062             * Returns the number of asset entries where expirationDate = &#63;.
2063             *
2064             * @param expirationDate the expiration date
2065             * @return the number of matching asset entries
2066             * @throws SystemException if a system exception occurred
2067             */
2068            @Override
2069            public int countByExpirationDate(Date expirationDate)
2070                    throws SystemException {
2071                    FinderPath finderPath = FINDER_PATH_COUNT_BY_EXPIRATIONDATE;
2072    
2073                    Object[] finderArgs = new Object[] { expirationDate };
2074    
2075                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2076                                    this);
2077    
2078                    if (count == null) {
2079                            StringBundler query = new StringBundler(2);
2080    
2081                            query.append(_SQL_COUNT_ASSETENTRY_WHERE);
2082    
2083                            boolean bindExpirationDate = false;
2084    
2085                            if (expirationDate == null) {
2086                                    query.append(_FINDER_COLUMN_EXPIRATIONDATE_EXPIRATIONDATE_1);
2087                            }
2088                            else {
2089                                    bindExpirationDate = true;
2090    
2091                                    query.append(_FINDER_COLUMN_EXPIRATIONDATE_EXPIRATIONDATE_2);
2092                            }
2093    
2094                            String sql = query.toString();
2095    
2096                            Session session = null;
2097    
2098                            try {
2099                                    session = openSession();
2100    
2101                                    Query q = session.createQuery(sql);
2102    
2103                                    QueryPos qPos = QueryPos.getInstance(q);
2104    
2105                                    if (bindExpirationDate) {
2106                                            qPos.add(CalendarUtil.getTimestamp(expirationDate));
2107                                    }
2108    
2109                                    count = (Long)q.uniqueResult();
2110    
2111                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2112                            }
2113                            catch (Exception e) {
2114                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2115    
2116                                    throw processException(e);
2117                            }
2118                            finally {
2119                                    closeSession(session);
2120                            }
2121                    }
2122    
2123                    return count.intValue();
2124            }
2125    
2126            private static final String _FINDER_COLUMN_EXPIRATIONDATE_EXPIRATIONDATE_1 = "assetEntry.expirationDate IS NULL";
2127            private static final String _FINDER_COLUMN_EXPIRATIONDATE_EXPIRATIONDATE_2 = "assetEntry.expirationDate = ?";
2128            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_LAYOUTUUID =
2129                    new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
2130                            AssetEntryModelImpl.FINDER_CACHE_ENABLED, AssetEntryImpl.class,
2131                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByLayoutUuid",
2132                            new String[] {
2133                                    String.class.getName(),
2134                                    
2135                            Integer.class.getName(), Integer.class.getName(),
2136                                    OrderByComparator.class.getName()
2137                            });
2138            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTUUID =
2139                    new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
2140                            AssetEntryModelImpl.FINDER_CACHE_ENABLED, AssetEntryImpl.class,
2141                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByLayoutUuid",
2142                            new String[] { String.class.getName() },
2143                            AssetEntryModelImpl.LAYOUTUUID_COLUMN_BITMASK);
2144            public static final FinderPath FINDER_PATH_COUNT_BY_LAYOUTUUID = new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
2145                            AssetEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
2146                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByLayoutUuid",
2147                            new String[] { String.class.getName() });
2148    
2149            /**
2150             * Returns all the asset entries where layoutUuid = &#63;.
2151             *
2152             * @param layoutUuid the layout uuid
2153             * @return the matching asset entries
2154             * @throws SystemException if a system exception occurred
2155             */
2156            @Override
2157            public List<AssetEntry> findByLayoutUuid(String layoutUuid)
2158                    throws SystemException {
2159                    return findByLayoutUuid(layoutUuid, QueryUtil.ALL_POS,
2160                            QueryUtil.ALL_POS, null);
2161            }
2162    
2163            /**
2164             * Returns a range of all the asset entries where layoutUuid = &#63;.
2165             *
2166             * <p>
2167             * 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.portlet.asset.model.impl.AssetEntryModelImpl}. 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.
2168             * </p>
2169             *
2170             * @param layoutUuid the layout uuid
2171             * @param start the lower bound of the range of asset entries
2172             * @param end the upper bound of the range of asset entries (not inclusive)
2173             * @return the range of matching asset entries
2174             * @throws SystemException if a system exception occurred
2175             */
2176            @Override
2177            public List<AssetEntry> findByLayoutUuid(String layoutUuid, int start,
2178                    int end) throws SystemException {
2179                    return findByLayoutUuid(layoutUuid, start, end, null);
2180            }
2181    
2182            /**
2183             * Returns an ordered range of all the asset entries where layoutUuid = &#63;.
2184             *
2185             * <p>
2186             * 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.portlet.asset.model.impl.AssetEntryModelImpl}. 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.
2187             * </p>
2188             *
2189             * @param layoutUuid the layout uuid
2190             * @param start the lower bound of the range of asset entries
2191             * @param end the upper bound of the range of asset entries (not inclusive)
2192             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2193             * @return the ordered range of matching asset entries
2194             * @throws SystemException if a system exception occurred
2195             */
2196            @Override
2197            public List<AssetEntry> findByLayoutUuid(String layoutUuid, int start,
2198                    int end, OrderByComparator orderByComparator) throws SystemException {
2199                    boolean pagination = true;
2200                    FinderPath finderPath = null;
2201                    Object[] finderArgs = null;
2202    
2203                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2204                                    (orderByComparator == null)) {
2205                            pagination = false;
2206                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTUUID;
2207                            finderArgs = new Object[] { layoutUuid };
2208                    }
2209                    else {
2210                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_LAYOUTUUID;
2211                            finderArgs = new Object[] { layoutUuid, start, end, orderByComparator };
2212                    }
2213    
2214                    List<AssetEntry> list = (List<AssetEntry>)FinderCacheUtil.getResult(finderPath,
2215                                    finderArgs, this);
2216    
2217                    if ((list != null) && !list.isEmpty()) {
2218                            for (AssetEntry assetEntry : list) {
2219                                    if (!Validator.equals(layoutUuid, assetEntry.getLayoutUuid())) {
2220                                            list = null;
2221    
2222                                            break;
2223                                    }
2224                            }
2225                    }
2226    
2227                    if (list == null) {
2228                            StringBundler query = null;
2229    
2230                            if (orderByComparator != null) {
2231                                    query = new StringBundler(3 +
2232                                                    (orderByComparator.getOrderByFields().length * 3));
2233                            }
2234                            else {
2235                                    query = new StringBundler(3);
2236                            }
2237    
2238                            query.append(_SQL_SELECT_ASSETENTRY_WHERE);
2239    
2240                            boolean bindLayoutUuid = false;
2241    
2242                            if (layoutUuid == null) {
2243                                    query.append(_FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_1);
2244                            }
2245                            else if (layoutUuid.equals(StringPool.BLANK)) {
2246                                    query.append(_FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_3);
2247                            }
2248                            else {
2249                                    bindLayoutUuid = true;
2250    
2251                                    query.append(_FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_2);
2252                            }
2253    
2254                            if (orderByComparator != null) {
2255                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2256                                            orderByComparator);
2257                            }
2258                            else
2259                             if (pagination) {
2260                                    query.append(AssetEntryModelImpl.ORDER_BY_JPQL);
2261                            }
2262    
2263                            String sql = query.toString();
2264    
2265                            Session session = null;
2266    
2267                            try {
2268                                    session = openSession();
2269    
2270                                    Query q = session.createQuery(sql);
2271    
2272                                    QueryPos qPos = QueryPos.getInstance(q);
2273    
2274                                    if (bindLayoutUuid) {
2275                                            qPos.add(layoutUuid);
2276                                    }
2277    
2278                                    if (!pagination) {
2279                                            list = (List<AssetEntry>)QueryUtil.list(q, getDialect(),
2280                                                            start, end, false);
2281    
2282                                            Collections.sort(list);
2283    
2284                                            list = new UnmodifiableList<AssetEntry>(list);
2285                                    }
2286                                    else {
2287                                            list = (List<AssetEntry>)QueryUtil.list(q, getDialect(),
2288                                                            start, end);
2289                                    }
2290    
2291                                    cacheResult(list);
2292    
2293                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2294                            }
2295                            catch (Exception e) {
2296                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2297    
2298                                    throw processException(e);
2299                            }
2300                            finally {
2301                                    closeSession(session);
2302                            }
2303                    }
2304    
2305                    return list;
2306            }
2307    
2308            /**
2309             * Returns the first asset entry in the ordered set where layoutUuid = &#63;.
2310             *
2311             * @param layoutUuid the layout uuid
2312             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2313             * @return the first matching asset entry
2314             * @throws com.liferay.portlet.asset.NoSuchEntryException if a matching asset entry could not be found
2315             * @throws SystemException if a system exception occurred
2316             */
2317            @Override
2318            public AssetEntry findByLayoutUuid_First(String layoutUuid,
2319                    OrderByComparator orderByComparator)
2320                    throws NoSuchEntryException, SystemException {
2321                    AssetEntry assetEntry = fetchByLayoutUuid_First(layoutUuid,
2322                                    orderByComparator);
2323    
2324                    if (assetEntry != null) {
2325                            return assetEntry;
2326                    }
2327    
2328                    StringBundler msg = new StringBundler(4);
2329    
2330                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2331    
2332                    msg.append("layoutUuid=");
2333                    msg.append(layoutUuid);
2334    
2335                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2336    
2337                    throw new NoSuchEntryException(msg.toString());
2338            }
2339    
2340            /**
2341             * Returns the first asset entry in the ordered set where layoutUuid = &#63;.
2342             *
2343             * @param layoutUuid the layout uuid
2344             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2345             * @return the first matching asset entry, or <code>null</code> if a matching asset entry could not be found
2346             * @throws SystemException if a system exception occurred
2347             */
2348            @Override
2349            public AssetEntry fetchByLayoutUuid_First(String layoutUuid,
2350                    OrderByComparator orderByComparator) throws SystemException {
2351                    List<AssetEntry> list = findByLayoutUuid(layoutUuid, 0, 1,
2352                                    orderByComparator);
2353    
2354                    if (!list.isEmpty()) {
2355                            return list.get(0);
2356                    }
2357    
2358                    return null;
2359            }
2360    
2361            /**
2362             * Returns the last asset entry in the ordered set where layoutUuid = &#63;.
2363             *
2364             * @param layoutUuid the layout uuid
2365             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2366             * @return the last matching asset entry
2367             * @throws com.liferay.portlet.asset.NoSuchEntryException if a matching asset entry could not be found
2368             * @throws SystemException if a system exception occurred
2369             */
2370            @Override
2371            public AssetEntry findByLayoutUuid_Last(String layoutUuid,
2372                    OrderByComparator orderByComparator)
2373                    throws NoSuchEntryException, SystemException {
2374                    AssetEntry assetEntry = fetchByLayoutUuid_Last(layoutUuid,
2375                                    orderByComparator);
2376    
2377                    if (assetEntry != null) {
2378                            return assetEntry;
2379                    }
2380    
2381                    StringBundler msg = new StringBundler(4);
2382    
2383                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2384    
2385                    msg.append("layoutUuid=");
2386                    msg.append(layoutUuid);
2387    
2388                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2389    
2390                    throw new NoSuchEntryException(msg.toString());
2391            }
2392    
2393            /**
2394             * Returns the last asset entry in the ordered set where layoutUuid = &#63;.
2395             *
2396             * @param layoutUuid the layout uuid
2397             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2398             * @return the last matching asset entry, or <code>null</code> if a matching asset entry could not be found
2399             * @throws SystemException if a system exception occurred
2400             */
2401            @Override
2402            public AssetEntry fetchByLayoutUuid_Last(String layoutUuid,
2403                    OrderByComparator orderByComparator) throws SystemException {
2404                    int count = countByLayoutUuid(layoutUuid);
2405    
2406                    if (count == 0) {
2407                            return null;
2408                    }
2409    
2410                    List<AssetEntry> list = findByLayoutUuid(layoutUuid, count - 1, count,
2411                                    orderByComparator);
2412    
2413                    if (!list.isEmpty()) {
2414                            return list.get(0);
2415                    }
2416    
2417                    return null;
2418            }
2419    
2420            /**
2421             * Returns the asset entries before and after the current asset entry in the ordered set where layoutUuid = &#63;.
2422             *
2423             * @param entryId the primary key of the current asset entry
2424             * @param layoutUuid the layout uuid
2425             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2426             * @return the previous, current, and next asset entry
2427             * @throws com.liferay.portlet.asset.NoSuchEntryException if a asset entry with the primary key could not be found
2428             * @throws SystemException if a system exception occurred
2429             */
2430            @Override
2431            public AssetEntry[] findByLayoutUuid_PrevAndNext(long entryId,
2432                    String layoutUuid, OrderByComparator orderByComparator)
2433                    throws NoSuchEntryException, SystemException {
2434                    AssetEntry assetEntry = findByPrimaryKey(entryId);
2435    
2436                    Session session = null;
2437    
2438                    try {
2439                            session = openSession();
2440    
2441                            AssetEntry[] array = new AssetEntryImpl[3];
2442    
2443                            array[0] = getByLayoutUuid_PrevAndNext(session, assetEntry,
2444                                            layoutUuid, orderByComparator, true);
2445    
2446                            array[1] = assetEntry;
2447    
2448                            array[2] = getByLayoutUuid_PrevAndNext(session, assetEntry,
2449                                            layoutUuid, orderByComparator, false);
2450    
2451                            return array;
2452                    }
2453                    catch (Exception e) {
2454                            throw processException(e);
2455                    }
2456                    finally {
2457                            closeSession(session);
2458                    }
2459            }
2460    
2461            protected AssetEntry getByLayoutUuid_PrevAndNext(Session session,
2462                    AssetEntry assetEntry, String layoutUuid,
2463                    OrderByComparator orderByComparator, boolean previous) {
2464                    StringBundler query = null;
2465    
2466                    if (orderByComparator != null) {
2467                            query = new StringBundler(6 +
2468                                            (orderByComparator.getOrderByFields().length * 6));
2469                    }
2470                    else {
2471                            query = new StringBundler(3);
2472                    }
2473    
2474                    query.append(_SQL_SELECT_ASSETENTRY_WHERE);
2475    
2476                    boolean bindLayoutUuid = false;
2477    
2478                    if (layoutUuid == null) {
2479                            query.append(_FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_1);
2480                    }
2481                    else if (layoutUuid.equals(StringPool.BLANK)) {
2482                            query.append(_FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_3);
2483                    }
2484                    else {
2485                            bindLayoutUuid = true;
2486    
2487                            query.append(_FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_2);
2488                    }
2489    
2490                    if (orderByComparator != null) {
2491                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2492    
2493                            if (orderByConditionFields.length > 0) {
2494                                    query.append(WHERE_AND);
2495                            }
2496    
2497                            for (int i = 0; i < orderByConditionFields.length; i++) {
2498                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2499                                    query.append(orderByConditionFields[i]);
2500    
2501                                    if ((i + 1) < orderByConditionFields.length) {
2502                                            if (orderByComparator.isAscending() ^ previous) {
2503                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2504                                            }
2505                                            else {
2506                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2507                                            }
2508                                    }
2509                                    else {
2510                                            if (orderByComparator.isAscending() ^ previous) {
2511                                                    query.append(WHERE_GREATER_THAN);
2512                                            }
2513                                            else {
2514                                                    query.append(WHERE_LESSER_THAN);
2515                                            }
2516                                    }
2517                            }
2518    
2519                            query.append(ORDER_BY_CLAUSE);
2520    
2521                            String[] orderByFields = orderByComparator.getOrderByFields();
2522    
2523                            for (int i = 0; i < orderByFields.length; i++) {
2524                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2525                                    query.append(orderByFields[i]);
2526    
2527                                    if ((i + 1) < orderByFields.length) {
2528                                            if (orderByComparator.isAscending() ^ previous) {
2529                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2530                                            }
2531                                            else {
2532                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2533                                            }
2534                                    }
2535                                    else {
2536                                            if (orderByComparator.isAscending() ^ previous) {
2537                                                    query.append(ORDER_BY_ASC);
2538                                            }
2539                                            else {
2540                                                    query.append(ORDER_BY_DESC);
2541                                            }
2542                                    }
2543                            }
2544                    }
2545                    else {
2546                            query.append(AssetEntryModelImpl.ORDER_BY_JPQL);
2547                    }
2548    
2549                    String sql = query.toString();
2550    
2551                    Query q = session.createQuery(sql);
2552    
2553                    q.setFirstResult(0);
2554                    q.setMaxResults(2);
2555    
2556                    QueryPos qPos = QueryPos.getInstance(q);
2557    
2558                    if (bindLayoutUuid) {
2559                            qPos.add(layoutUuid);
2560                    }
2561    
2562                    if (orderByComparator != null) {
2563                            Object[] values = orderByComparator.getOrderByConditionValues(assetEntry);
2564    
2565                            for (Object value : values) {
2566                                    qPos.add(value);
2567                            }
2568                    }
2569    
2570                    List<AssetEntry> list = q.list();
2571    
2572                    if (list.size() == 2) {
2573                            return list.get(1);
2574                    }
2575                    else {
2576                            return null;
2577                    }
2578            }
2579    
2580            /**
2581             * Removes all the asset entries where layoutUuid = &#63; from the database.
2582             *
2583             * @param layoutUuid the layout uuid
2584             * @throws SystemException if a system exception occurred
2585             */
2586            @Override
2587            public void removeByLayoutUuid(String layoutUuid) throws SystemException {
2588                    for (AssetEntry assetEntry : findByLayoutUuid(layoutUuid,
2589                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2590                            remove(assetEntry);
2591                    }
2592            }
2593    
2594            /**
2595             * Returns the number of asset entries where layoutUuid = &#63;.
2596             *
2597             * @param layoutUuid the layout uuid
2598             * @return the number of matching asset entries
2599             * @throws SystemException if a system exception occurred
2600             */
2601            @Override
2602            public int countByLayoutUuid(String layoutUuid) throws SystemException {
2603                    FinderPath finderPath = FINDER_PATH_COUNT_BY_LAYOUTUUID;
2604    
2605                    Object[] finderArgs = new Object[] { layoutUuid };
2606    
2607                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2608                                    this);
2609    
2610                    if (count == null) {
2611                            StringBundler query = new StringBundler(2);
2612    
2613                            query.append(_SQL_COUNT_ASSETENTRY_WHERE);
2614    
2615                            boolean bindLayoutUuid = false;
2616    
2617                            if (layoutUuid == null) {
2618                                    query.append(_FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_1);
2619                            }
2620                            else if (layoutUuid.equals(StringPool.BLANK)) {
2621                                    query.append(_FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_3);
2622                            }
2623                            else {
2624                                    bindLayoutUuid = true;
2625    
2626                                    query.append(_FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_2);
2627                            }
2628    
2629                            String sql = query.toString();
2630    
2631                            Session session = null;
2632    
2633                            try {
2634                                    session = openSession();
2635    
2636                                    Query q = session.createQuery(sql);
2637    
2638                                    QueryPos qPos = QueryPos.getInstance(q);
2639    
2640                                    if (bindLayoutUuid) {
2641                                            qPos.add(layoutUuid);
2642                                    }
2643    
2644                                    count = (Long)q.uniqueResult();
2645    
2646                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2647                            }
2648                            catch (Exception e) {
2649                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2650    
2651                                    throw processException(e);
2652                            }
2653                            finally {
2654                                    closeSession(session);
2655                            }
2656                    }
2657    
2658                    return count.intValue();
2659            }
2660    
2661            private static final String _FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_1 = "assetEntry.layoutUuid IS NULL";
2662            private static final String _FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_2 = "assetEntry.layoutUuid = ?";
2663            private static final String _FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_3 = "(assetEntry.layoutUuid IS NULL OR assetEntry.layoutUuid = '')";
2664            public static final FinderPath FINDER_PATH_FETCH_BY_G_CU = new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
2665                            AssetEntryModelImpl.FINDER_CACHE_ENABLED, AssetEntryImpl.class,
2666                            FINDER_CLASS_NAME_ENTITY, "fetchByG_CU",
2667                            new String[] { Long.class.getName(), String.class.getName() },
2668                            AssetEntryModelImpl.GROUPID_COLUMN_BITMASK |
2669                            AssetEntryModelImpl.CLASSUUID_COLUMN_BITMASK);
2670            public static final FinderPath FINDER_PATH_COUNT_BY_G_CU = new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
2671                            AssetEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
2672                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_CU",
2673                            new String[] { Long.class.getName(), String.class.getName() });
2674    
2675            /**
2676             * Returns the asset entry where groupId = &#63; and classUuid = &#63; or throws a {@link com.liferay.portlet.asset.NoSuchEntryException} if it could not be found.
2677             *
2678             * @param groupId the group ID
2679             * @param classUuid the class uuid
2680             * @return the matching asset entry
2681             * @throws com.liferay.portlet.asset.NoSuchEntryException if a matching asset entry could not be found
2682             * @throws SystemException if a system exception occurred
2683             */
2684            @Override
2685            public AssetEntry findByG_CU(long groupId, String classUuid)
2686                    throws NoSuchEntryException, SystemException {
2687                    AssetEntry assetEntry = fetchByG_CU(groupId, classUuid);
2688    
2689                    if (assetEntry == null) {
2690                            StringBundler msg = new StringBundler(6);
2691    
2692                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2693    
2694                            msg.append("groupId=");
2695                            msg.append(groupId);
2696    
2697                            msg.append(", classUuid=");
2698                            msg.append(classUuid);
2699    
2700                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2701    
2702                            if (_log.isWarnEnabled()) {
2703                                    _log.warn(msg.toString());
2704                            }
2705    
2706                            throw new NoSuchEntryException(msg.toString());
2707                    }
2708    
2709                    return assetEntry;
2710            }
2711    
2712            /**
2713             * Returns the asset entry where groupId = &#63; and classUuid = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
2714             *
2715             * @param groupId the group ID
2716             * @param classUuid the class uuid
2717             * @return the matching asset entry, or <code>null</code> if a matching asset entry could not be found
2718             * @throws SystemException if a system exception occurred
2719             */
2720            @Override
2721            public AssetEntry fetchByG_CU(long groupId, String classUuid)
2722                    throws SystemException {
2723                    return fetchByG_CU(groupId, classUuid, true);
2724            }
2725    
2726            /**
2727             * Returns the asset entry where groupId = &#63; and classUuid = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
2728             *
2729             * @param groupId the group ID
2730             * @param classUuid the class uuid
2731             * @param retrieveFromCache whether to use the finder cache
2732             * @return the matching asset entry, or <code>null</code> if a matching asset entry could not be found
2733             * @throws SystemException if a system exception occurred
2734             */
2735            @Override
2736            public AssetEntry fetchByG_CU(long groupId, String classUuid,
2737                    boolean retrieveFromCache) throws SystemException {
2738                    Object[] finderArgs = new Object[] { groupId, classUuid };
2739    
2740                    Object result = null;
2741    
2742                    if (retrieveFromCache) {
2743                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_CU,
2744                                            finderArgs, this);
2745                    }
2746    
2747                    if (result instanceof AssetEntry) {
2748                            AssetEntry assetEntry = (AssetEntry)result;
2749    
2750                            if ((groupId != assetEntry.getGroupId()) ||
2751                                            !Validator.equals(classUuid, assetEntry.getClassUuid())) {
2752                                    result = null;
2753                            }
2754                    }
2755    
2756                    if (result == null) {
2757                            StringBundler query = new StringBundler(4);
2758    
2759                            query.append(_SQL_SELECT_ASSETENTRY_WHERE);
2760    
2761                            query.append(_FINDER_COLUMN_G_CU_GROUPID_2);
2762    
2763                            boolean bindClassUuid = false;
2764    
2765                            if (classUuid == null) {
2766                                    query.append(_FINDER_COLUMN_G_CU_CLASSUUID_1);
2767                            }
2768                            else if (classUuid.equals(StringPool.BLANK)) {
2769                                    query.append(_FINDER_COLUMN_G_CU_CLASSUUID_3);
2770                            }
2771                            else {
2772                                    bindClassUuid = true;
2773    
2774                                    query.append(_FINDER_COLUMN_G_CU_CLASSUUID_2);
2775                            }
2776    
2777                            String sql = query.toString();
2778    
2779                            Session session = null;
2780    
2781                            try {
2782                                    session = openSession();
2783    
2784                                    Query q = session.createQuery(sql);
2785    
2786                                    QueryPos qPos = QueryPos.getInstance(q);
2787    
2788                                    qPos.add(groupId);
2789    
2790                                    if (bindClassUuid) {
2791                                            qPos.add(classUuid);
2792                                    }
2793    
2794                                    List<AssetEntry> list = q.list();
2795    
2796                                    if (list.isEmpty()) {
2797                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_CU,
2798                                                    finderArgs, list);
2799                                    }
2800                                    else {
2801                                            if ((list.size() > 1) && _log.isWarnEnabled()) {
2802                                                    _log.warn(
2803                                                            "AssetEntryPersistenceImpl.fetchByG_CU(long, String, boolean) with parameters (" +
2804                                                            StringUtil.merge(finderArgs) +
2805                                                            ") 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.");
2806                                            }
2807    
2808                                            AssetEntry assetEntry = list.get(0);
2809    
2810                                            result = assetEntry;
2811    
2812                                            cacheResult(assetEntry);
2813    
2814                                            if ((assetEntry.getGroupId() != groupId) ||
2815                                                            (assetEntry.getClassUuid() == null) ||
2816                                                            !assetEntry.getClassUuid().equals(classUuid)) {
2817                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_CU,
2818                                                            finderArgs, assetEntry);
2819                                            }
2820                                    }
2821                            }
2822                            catch (Exception e) {
2823                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_CU,
2824                                            finderArgs);
2825    
2826                                    throw processException(e);
2827                            }
2828                            finally {
2829                                    closeSession(session);
2830                            }
2831                    }
2832    
2833                    if (result instanceof List<?>) {
2834                            return null;
2835                    }
2836                    else {
2837                            return (AssetEntry)result;
2838                    }
2839            }
2840    
2841            /**
2842             * Removes the asset entry where groupId = &#63; and classUuid = &#63; from the database.
2843             *
2844             * @param groupId the group ID
2845             * @param classUuid the class uuid
2846             * @return the asset entry that was removed
2847             * @throws SystemException if a system exception occurred
2848             */
2849            @Override
2850            public AssetEntry removeByG_CU(long groupId, String classUuid)
2851                    throws NoSuchEntryException, SystemException {
2852                    AssetEntry assetEntry = findByG_CU(groupId, classUuid);
2853    
2854                    return remove(assetEntry);
2855            }
2856    
2857            /**
2858             * Returns the number of asset entries where groupId = &#63; and classUuid = &#63;.
2859             *
2860             * @param groupId the group ID
2861             * @param classUuid the class uuid
2862             * @return the number of matching asset entries
2863             * @throws SystemException if a system exception occurred
2864             */
2865            @Override
2866            public int countByG_CU(long groupId, String classUuid)
2867                    throws SystemException {
2868                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_CU;
2869    
2870                    Object[] finderArgs = new Object[] { groupId, classUuid };
2871    
2872                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2873                                    this);
2874    
2875                    if (count == null) {
2876                            StringBundler query = new StringBundler(3);
2877    
2878                            query.append(_SQL_COUNT_ASSETENTRY_WHERE);
2879    
2880                            query.append(_FINDER_COLUMN_G_CU_GROUPID_2);
2881    
2882                            boolean bindClassUuid = false;
2883    
2884                            if (classUuid == null) {
2885                                    query.append(_FINDER_COLUMN_G_CU_CLASSUUID_1);
2886                            }
2887                            else if (classUuid.equals(StringPool.BLANK)) {
2888                                    query.append(_FINDER_COLUMN_G_CU_CLASSUUID_3);
2889                            }
2890                            else {
2891                                    bindClassUuid = true;
2892    
2893                                    query.append(_FINDER_COLUMN_G_CU_CLASSUUID_2);
2894                            }
2895    
2896                            String sql = query.toString();
2897    
2898                            Session session = null;
2899    
2900                            try {
2901                                    session = openSession();
2902    
2903                                    Query q = session.createQuery(sql);
2904    
2905                                    QueryPos qPos = QueryPos.getInstance(q);
2906    
2907                                    qPos.add(groupId);
2908    
2909                                    if (bindClassUuid) {
2910                                            qPos.add(classUuid);
2911                                    }
2912    
2913                                    count = (Long)q.uniqueResult();
2914    
2915                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2916                            }
2917                            catch (Exception e) {
2918                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2919    
2920                                    throw processException(e);
2921                            }
2922                            finally {
2923                                    closeSession(session);
2924                            }
2925                    }
2926    
2927                    return count.intValue();
2928            }
2929    
2930            private static final String _FINDER_COLUMN_G_CU_GROUPID_2 = "assetEntry.groupId = ? AND ";
2931            private static final String _FINDER_COLUMN_G_CU_CLASSUUID_1 = "assetEntry.classUuid IS NULL";
2932            private static final String _FINDER_COLUMN_G_CU_CLASSUUID_2 = "assetEntry.classUuid = ?";
2933            private static final String _FINDER_COLUMN_G_CU_CLASSUUID_3 = "(assetEntry.classUuid IS NULL OR assetEntry.classUuid = '')";
2934            public static final FinderPath FINDER_PATH_FETCH_BY_C_C = new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
2935                            AssetEntryModelImpl.FINDER_CACHE_ENABLED, AssetEntryImpl.class,
2936                            FINDER_CLASS_NAME_ENTITY, "fetchByC_C",
2937                            new String[] { Long.class.getName(), Long.class.getName() },
2938                            AssetEntryModelImpl.CLASSNAMEID_COLUMN_BITMASK |
2939                            AssetEntryModelImpl.CLASSPK_COLUMN_BITMASK);
2940            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
2941                            AssetEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
2942                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
2943                            new String[] { Long.class.getName(), Long.class.getName() });
2944    
2945            /**
2946             * Returns the asset entry where classNameId = &#63; and classPK = &#63; or throws a {@link com.liferay.portlet.asset.NoSuchEntryException} if it could not be found.
2947             *
2948             * @param classNameId the class name ID
2949             * @param classPK the class p k
2950             * @return the matching asset entry
2951             * @throws com.liferay.portlet.asset.NoSuchEntryException if a matching asset entry could not be found
2952             * @throws SystemException if a system exception occurred
2953             */
2954            @Override
2955            public AssetEntry findByC_C(long classNameId, long classPK)
2956                    throws NoSuchEntryException, SystemException {
2957                    AssetEntry assetEntry = fetchByC_C(classNameId, classPK);
2958    
2959                    if (assetEntry == null) {
2960                            StringBundler msg = new StringBundler(6);
2961    
2962                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2963    
2964                            msg.append("classNameId=");
2965                            msg.append(classNameId);
2966    
2967                            msg.append(", classPK=");
2968                            msg.append(classPK);
2969    
2970                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2971    
2972                            if (_log.isWarnEnabled()) {
2973                                    _log.warn(msg.toString());
2974                            }
2975    
2976                            throw new NoSuchEntryException(msg.toString());
2977                    }
2978    
2979                    return assetEntry;
2980            }
2981    
2982            /**
2983             * Returns the asset entry where classNameId = &#63; and classPK = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
2984             *
2985             * @param classNameId the class name ID
2986             * @param classPK the class p k
2987             * @return the matching asset entry, or <code>null</code> if a matching asset entry could not be found
2988             * @throws SystemException if a system exception occurred
2989             */
2990            @Override
2991            public AssetEntry fetchByC_C(long classNameId, long classPK)
2992                    throws SystemException {
2993                    return fetchByC_C(classNameId, classPK, true);
2994            }
2995    
2996            /**
2997             * Returns the asset entry where classNameId = &#63; and classPK = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
2998             *
2999             * @param classNameId the class name ID
3000             * @param classPK the class p k
3001             * @param retrieveFromCache whether to use the finder cache
3002             * @return the matching asset entry, or <code>null</code> if a matching asset entry could not be found
3003             * @throws SystemException if a system exception occurred
3004             */
3005            @Override
3006            public AssetEntry fetchByC_C(long classNameId, long classPK,
3007                    boolean retrieveFromCache) throws SystemException {
3008                    Object[] finderArgs = new Object[] { classNameId, classPK };
3009    
3010                    Object result = null;
3011    
3012                    if (retrieveFromCache) {
3013                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C,
3014                                            finderArgs, this);
3015                    }
3016    
3017                    if (result instanceof AssetEntry) {
3018                            AssetEntry assetEntry = (AssetEntry)result;
3019    
3020                            if ((classNameId != assetEntry.getClassNameId()) ||
3021                                            (classPK != assetEntry.getClassPK())) {
3022                                    result = null;
3023                            }
3024                    }
3025    
3026                    if (result == null) {
3027                            StringBundler query = new StringBundler(4);
3028    
3029                            query.append(_SQL_SELECT_ASSETENTRY_WHERE);
3030    
3031                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
3032    
3033                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
3034    
3035                            String sql = query.toString();
3036    
3037                            Session session = null;
3038    
3039                            try {
3040                                    session = openSession();
3041    
3042                                    Query q = session.createQuery(sql);
3043    
3044                                    QueryPos qPos = QueryPos.getInstance(q);
3045    
3046                                    qPos.add(classNameId);
3047    
3048                                    qPos.add(classPK);
3049    
3050                                    List<AssetEntry> list = q.list();
3051    
3052                                    if (list.isEmpty()) {
3053                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
3054                                                    finderArgs, list);
3055                                    }
3056                                    else {
3057                                            AssetEntry assetEntry = list.get(0);
3058    
3059                                            result = assetEntry;
3060    
3061                                            cacheResult(assetEntry);
3062    
3063                                            if ((assetEntry.getClassNameId() != classNameId) ||
3064                                                            (assetEntry.getClassPK() != classPK)) {
3065                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
3066                                                            finderArgs, assetEntry);
3067                                            }
3068                                    }
3069                            }
3070                            catch (Exception e) {
3071                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
3072                                            finderArgs);
3073    
3074                                    throw processException(e);
3075                            }
3076                            finally {
3077                                    closeSession(session);
3078                            }
3079                    }
3080    
3081                    if (result instanceof List<?>) {
3082                            return null;
3083                    }
3084                    else {
3085                            return (AssetEntry)result;
3086                    }
3087            }
3088    
3089            /**
3090             * Removes the asset entry where classNameId = &#63; and classPK = &#63; from the database.
3091             *
3092             * @param classNameId the class name ID
3093             * @param classPK the class p k
3094             * @return the asset entry that was removed
3095             * @throws SystemException if a system exception occurred
3096             */
3097            @Override
3098            public AssetEntry removeByC_C(long classNameId, long classPK)
3099                    throws NoSuchEntryException, SystemException {
3100                    AssetEntry assetEntry = findByC_C(classNameId, classPK);
3101    
3102                    return remove(assetEntry);
3103            }
3104    
3105            /**
3106             * Returns the number of asset entries where classNameId = &#63; and classPK = &#63;.
3107             *
3108             * @param classNameId the class name ID
3109             * @param classPK the class p k
3110             * @return the number of matching asset entries
3111             * @throws SystemException if a system exception occurred
3112             */
3113            @Override
3114            public int countByC_C(long classNameId, long classPK)
3115                    throws SystemException {
3116                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
3117    
3118                    Object[] finderArgs = new Object[] { classNameId, classPK };
3119    
3120                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3121                                    this);
3122    
3123                    if (count == null) {
3124                            StringBundler query = new StringBundler(3);
3125    
3126                            query.append(_SQL_COUNT_ASSETENTRY_WHERE);
3127    
3128                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
3129    
3130                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
3131    
3132                            String sql = query.toString();
3133    
3134                            Session session = null;
3135    
3136                            try {
3137                                    session = openSession();
3138    
3139                                    Query q = session.createQuery(sql);
3140    
3141                                    QueryPos qPos = QueryPos.getInstance(q);
3142    
3143                                    qPos.add(classNameId);
3144    
3145                                    qPos.add(classPK);
3146    
3147                                    count = (Long)q.uniqueResult();
3148    
3149                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3150                            }
3151                            catch (Exception e) {
3152                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3153    
3154                                    throw processException(e);
3155                            }
3156                            finally {
3157                                    closeSession(session);
3158                            }
3159                    }
3160    
3161                    return count.intValue();
3162            }
3163    
3164            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "assetEntry.classNameId = ? AND ";
3165            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "assetEntry.classPK = ?";
3166    
3167            public AssetEntryPersistenceImpl() {
3168                    setModelClass(AssetEntry.class);
3169            }
3170    
3171            /**
3172             * Caches the asset entry in the entity cache if it is enabled.
3173             *
3174             * @param assetEntry the asset entry
3175             */
3176            @Override
3177            public void cacheResult(AssetEntry assetEntry) {
3178                    EntityCacheUtil.putResult(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
3179                            AssetEntryImpl.class, assetEntry.getPrimaryKey(), assetEntry);
3180    
3181                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_CU,
3182                            new Object[] { assetEntry.getGroupId(), assetEntry.getClassUuid() },
3183                            assetEntry);
3184    
3185                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
3186                            new Object[] { assetEntry.getClassNameId(), assetEntry.getClassPK() },
3187                            assetEntry);
3188    
3189                    assetEntry.resetOriginalValues();
3190            }
3191    
3192            /**
3193             * Caches the asset entries in the entity cache if it is enabled.
3194             *
3195             * @param assetEntries the asset entries
3196             */
3197            @Override
3198            public void cacheResult(List<AssetEntry> assetEntries) {
3199                    for (AssetEntry assetEntry : assetEntries) {
3200                            if (EntityCacheUtil.getResult(
3201                                                    AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
3202                                                    AssetEntryImpl.class, assetEntry.getPrimaryKey()) == null) {
3203                                    cacheResult(assetEntry);
3204                            }
3205                            else {
3206                                    assetEntry.resetOriginalValues();
3207                            }
3208                    }
3209            }
3210    
3211            /**
3212             * Clears the cache for all asset entries.
3213             *
3214             * <p>
3215             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
3216             * </p>
3217             */
3218            @Override
3219            public void clearCache() {
3220                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
3221                            CacheRegistryUtil.clear(AssetEntryImpl.class.getName());
3222                    }
3223    
3224                    EntityCacheUtil.clearCache(AssetEntryImpl.class.getName());
3225    
3226                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
3227                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3228                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3229            }
3230    
3231            /**
3232             * Clears the cache for the asset entry.
3233             *
3234             * <p>
3235             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
3236             * </p>
3237             */
3238            @Override
3239            public void clearCache(AssetEntry assetEntry) {
3240                    EntityCacheUtil.removeResult(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
3241                            AssetEntryImpl.class, assetEntry.getPrimaryKey());
3242    
3243                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3244                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3245    
3246                    clearUniqueFindersCache(assetEntry);
3247            }
3248    
3249            @Override
3250            public void clearCache(List<AssetEntry> assetEntries) {
3251                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3252                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3253    
3254                    for (AssetEntry assetEntry : assetEntries) {
3255                            EntityCacheUtil.removeResult(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
3256                                    AssetEntryImpl.class, assetEntry.getPrimaryKey());
3257    
3258                            clearUniqueFindersCache(assetEntry);
3259                    }
3260            }
3261    
3262            protected void cacheUniqueFindersCache(AssetEntry assetEntry) {
3263                    if (assetEntry.isNew()) {
3264                            Object[] args = new Object[] {
3265                                            assetEntry.getGroupId(), assetEntry.getClassUuid()
3266                                    };
3267    
3268                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_CU, args,
3269                                    Long.valueOf(1));
3270                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_CU, args,
3271                                    assetEntry);
3272    
3273                            args = new Object[] {
3274                                            assetEntry.getClassNameId(), assetEntry.getClassPK()
3275                                    };
3276    
3277                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, args,
3278                                    Long.valueOf(1));
3279                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C, args, assetEntry);
3280                    }
3281                    else {
3282                            AssetEntryModelImpl assetEntryModelImpl = (AssetEntryModelImpl)assetEntry;
3283    
3284                            if ((assetEntryModelImpl.getColumnBitmask() &
3285                                            FINDER_PATH_FETCH_BY_G_CU.getColumnBitmask()) != 0) {
3286                                    Object[] args = new Object[] {
3287                                                    assetEntry.getGroupId(), assetEntry.getClassUuid()
3288                                            };
3289    
3290                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_CU, args,
3291                                            Long.valueOf(1));
3292                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_CU, args,
3293                                            assetEntry);
3294                            }
3295    
3296                            if ((assetEntryModelImpl.getColumnBitmask() &
3297                                            FINDER_PATH_FETCH_BY_C_C.getColumnBitmask()) != 0) {
3298                                    Object[] args = new Object[] {
3299                                                    assetEntry.getClassNameId(), assetEntry.getClassPK()
3300                                            };
3301    
3302                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, args,
3303                                            Long.valueOf(1));
3304                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C, args,
3305                                            assetEntry);
3306                            }
3307                    }
3308            }
3309    
3310            protected void clearUniqueFindersCache(AssetEntry assetEntry) {
3311                    AssetEntryModelImpl assetEntryModelImpl = (AssetEntryModelImpl)assetEntry;
3312    
3313                    Object[] args = new Object[] {
3314                                    assetEntry.getGroupId(), assetEntry.getClassUuid()
3315                            };
3316    
3317                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_CU, args);
3318                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_CU, args);
3319    
3320                    if ((assetEntryModelImpl.getColumnBitmask() &
3321                                    FINDER_PATH_FETCH_BY_G_CU.getColumnBitmask()) != 0) {
3322                            args = new Object[] {
3323                                            assetEntryModelImpl.getOriginalGroupId(),
3324                                            assetEntryModelImpl.getOriginalClassUuid()
3325                                    };
3326    
3327                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_CU, args);
3328                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_CU, args);
3329                    }
3330    
3331                    args = new Object[] { assetEntry.getClassNameId(), assetEntry.getClassPK() };
3332    
3333                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
3334                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C, args);
3335    
3336                    if ((assetEntryModelImpl.getColumnBitmask() &
3337                                    FINDER_PATH_FETCH_BY_C_C.getColumnBitmask()) != 0) {
3338                            args = new Object[] {
3339                                            assetEntryModelImpl.getOriginalClassNameId(),
3340                                            assetEntryModelImpl.getOriginalClassPK()
3341                                    };
3342    
3343                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
3344                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C, args);
3345                    }
3346            }
3347    
3348            /**
3349             * Creates a new asset entry with the primary key. Does not add the asset entry to the database.
3350             *
3351             * @param entryId the primary key for the new asset entry
3352             * @return the new asset entry
3353             */
3354            @Override
3355            public AssetEntry create(long entryId) {
3356                    AssetEntry assetEntry = new AssetEntryImpl();
3357    
3358                    assetEntry.setNew(true);
3359                    assetEntry.setPrimaryKey(entryId);
3360    
3361                    return assetEntry;
3362            }
3363    
3364            /**
3365             * Removes the asset entry with the primary key from the database. Also notifies the appropriate model listeners.
3366             *
3367             * @param entryId the primary key of the asset entry
3368             * @return the asset entry that was removed
3369             * @throws com.liferay.portlet.asset.NoSuchEntryException if a asset entry with the primary key could not be found
3370             * @throws SystemException if a system exception occurred
3371             */
3372            @Override
3373            public AssetEntry remove(long entryId)
3374                    throws NoSuchEntryException, SystemException {
3375                    return remove((Serializable)entryId);
3376            }
3377    
3378            /**
3379             * Removes the asset entry with the primary key from the database. Also notifies the appropriate model listeners.
3380             *
3381             * @param primaryKey the primary key of the asset entry
3382             * @return the asset entry that was removed
3383             * @throws com.liferay.portlet.asset.NoSuchEntryException if a asset entry with the primary key could not be found
3384             * @throws SystemException if a system exception occurred
3385             */
3386            @Override
3387            public AssetEntry remove(Serializable primaryKey)
3388                    throws NoSuchEntryException, SystemException {
3389                    Session session = null;
3390    
3391                    try {
3392                            session = openSession();
3393    
3394                            AssetEntry assetEntry = (AssetEntry)session.get(AssetEntryImpl.class,
3395                                            primaryKey);
3396    
3397                            if (assetEntry == null) {
3398                                    if (_log.isWarnEnabled()) {
3399                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
3400                                    }
3401    
3402                                    throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
3403                                            primaryKey);
3404                            }
3405    
3406                            return remove(assetEntry);
3407                    }
3408                    catch (NoSuchEntryException nsee) {
3409                            throw nsee;
3410                    }
3411                    catch (Exception e) {
3412                            throw processException(e);
3413                    }
3414                    finally {
3415                            closeSession(session);
3416                    }
3417            }
3418    
3419            @Override
3420            protected AssetEntry removeImpl(AssetEntry assetEntry)
3421                    throws SystemException {
3422                    assetEntry = toUnwrappedModel(assetEntry);
3423    
3424                    assetEntryToAssetCategoryTableMapper.deleteLeftPrimaryKeyTableMappings(assetEntry.getPrimaryKey());
3425    
3426                    assetEntryToAssetTagTableMapper.deleteLeftPrimaryKeyTableMappings(assetEntry.getPrimaryKey());
3427    
3428                    Session session = null;
3429    
3430                    try {
3431                            session = openSession();
3432    
3433                            if (!session.contains(assetEntry)) {
3434                                    assetEntry = (AssetEntry)session.get(AssetEntryImpl.class,
3435                                                    assetEntry.getPrimaryKeyObj());
3436                            }
3437    
3438                            if (assetEntry != null) {
3439                                    session.delete(assetEntry);
3440                            }
3441                    }
3442                    catch (Exception e) {
3443                            throw processException(e);
3444                    }
3445                    finally {
3446                            closeSession(session);
3447                    }
3448    
3449                    if (assetEntry != null) {
3450                            clearCache(assetEntry);
3451                    }
3452    
3453                    return assetEntry;
3454            }
3455    
3456            @Override
3457            public AssetEntry updateImpl(
3458                    com.liferay.portlet.asset.model.AssetEntry assetEntry)
3459                    throws SystemException {
3460                    assetEntry = toUnwrappedModel(assetEntry);
3461    
3462                    boolean isNew = assetEntry.isNew();
3463    
3464                    AssetEntryModelImpl assetEntryModelImpl = (AssetEntryModelImpl)assetEntry;
3465    
3466                    Session session = null;
3467    
3468                    try {
3469                            session = openSession();
3470    
3471                            if (assetEntry.isNew()) {
3472                                    session.save(assetEntry);
3473    
3474                                    assetEntry.setNew(false);
3475                            }
3476                            else {
3477                                    session.merge(assetEntry);
3478                            }
3479                    }
3480                    catch (Exception e) {
3481                            throw processException(e);
3482                    }
3483                    finally {
3484                            closeSession(session);
3485                    }
3486    
3487                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3488    
3489                    if (isNew || !AssetEntryModelImpl.COLUMN_BITMASK_ENABLED) {
3490                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3491                    }
3492    
3493                    else {
3494                            if ((assetEntryModelImpl.getColumnBitmask() &
3495                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
3496                                    Object[] args = new Object[] {
3497                                                    assetEntryModelImpl.getOriginalCompanyId()
3498                                            };
3499    
3500                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
3501                                            args);
3502                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
3503                                            args);
3504    
3505                                    args = new Object[] { assetEntryModelImpl.getCompanyId() };
3506    
3507                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
3508                                            args);
3509                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
3510                                            args);
3511                            }
3512    
3513                            if ((assetEntryModelImpl.getColumnBitmask() &
3514                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_VISIBLE.getColumnBitmask()) != 0) {
3515                                    Object[] args = new Object[] {
3516                                                    assetEntryModelImpl.getOriginalVisible()
3517                                            };
3518    
3519                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_VISIBLE, args);
3520                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_VISIBLE,
3521                                            args);
3522    
3523                                    args = new Object[] { assetEntryModelImpl.getVisible() };
3524    
3525                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_VISIBLE, args);
3526                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_VISIBLE,
3527                                            args);
3528                            }
3529    
3530                            if ((assetEntryModelImpl.getColumnBitmask() &
3531                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PUBLISHDATE.getColumnBitmask()) != 0) {
3532                                    Object[] args = new Object[] {
3533                                                    assetEntryModelImpl.getOriginalPublishDate()
3534                                            };
3535    
3536                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_PUBLISHDATE,
3537                                            args);
3538                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PUBLISHDATE,
3539                                            args);
3540    
3541                                    args = new Object[] { assetEntryModelImpl.getPublishDate() };
3542    
3543                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_PUBLISHDATE,
3544                                            args);
3545                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_PUBLISHDATE,
3546                                            args);
3547                            }
3548    
3549                            if ((assetEntryModelImpl.getColumnBitmask() &
3550                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_EXPIRATIONDATE.getColumnBitmask()) != 0) {
3551                                    Object[] args = new Object[] {
3552                                                    assetEntryModelImpl.getOriginalExpirationDate()
3553                                            };
3554    
3555                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_EXPIRATIONDATE,
3556                                            args);
3557                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_EXPIRATIONDATE,
3558                                            args);
3559    
3560                                    args = new Object[] { assetEntryModelImpl.getExpirationDate() };
3561    
3562                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_EXPIRATIONDATE,
3563                                            args);
3564                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_EXPIRATIONDATE,
3565                                            args);
3566                            }
3567    
3568                            if ((assetEntryModelImpl.getColumnBitmask() &
3569                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTUUID.getColumnBitmask()) != 0) {
3570                                    Object[] args = new Object[] {
3571                                                    assetEntryModelImpl.getOriginalLayoutUuid()
3572                                            };
3573    
3574                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LAYOUTUUID,
3575                                            args);
3576                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTUUID,
3577                                            args);
3578    
3579                                    args = new Object[] { assetEntryModelImpl.getLayoutUuid() };
3580    
3581                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LAYOUTUUID,
3582                                            args);
3583                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTUUID,
3584                                            args);
3585                            }
3586                    }
3587    
3588                    EntityCacheUtil.putResult(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
3589                            AssetEntryImpl.class, assetEntry.getPrimaryKey(), assetEntry);
3590    
3591                    clearUniqueFindersCache(assetEntry);
3592                    cacheUniqueFindersCache(assetEntry);
3593    
3594                    return assetEntry;
3595            }
3596    
3597            protected AssetEntry toUnwrappedModel(AssetEntry assetEntry) {
3598                    if (assetEntry instanceof AssetEntryImpl) {
3599                            return assetEntry;
3600                    }
3601    
3602                    AssetEntryImpl assetEntryImpl = new AssetEntryImpl();
3603    
3604                    assetEntryImpl.setNew(assetEntry.isNew());
3605                    assetEntryImpl.setPrimaryKey(assetEntry.getPrimaryKey());
3606    
3607                    assetEntryImpl.setEntryId(assetEntry.getEntryId());
3608                    assetEntryImpl.setGroupId(assetEntry.getGroupId());
3609                    assetEntryImpl.setCompanyId(assetEntry.getCompanyId());
3610                    assetEntryImpl.setUserId(assetEntry.getUserId());
3611                    assetEntryImpl.setUserName(assetEntry.getUserName());
3612                    assetEntryImpl.setCreateDate(assetEntry.getCreateDate());
3613                    assetEntryImpl.setModifiedDate(assetEntry.getModifiedDate());
3614                    assetEntryImpl.setClassNameId(assetEntry.getClassNameId());
3615                    assetEntryImpl.setClassPK(assetEntry.getClassPK());
3616                    assetEntryImpl.setClassUuid(assetEntry.getClassUuid());
3617                    assetEntryImpl.setClassTypeId(assetEntry.getClassTypeId());
3618                    assetEntryImpl.setVisible(assetEntry.isVisible());
3619                    assetEntryImpl.setStartDate(assetEntry.getStartDate());
3620                    assetEntryImpl.setEndDate(assetEntry.getEndDate());
3621                    assetEntryImpl.setPublishDate(assetEntry.getPublishDate());
3622                    assetEntryImpl.setExpirationDate(assetEntry.getExpirationDate());
3623                    assetEntryImpl.setMimeType(assetEntry.getMimeType());
3624                    assetEntryImpl.setTitle(assetEntry.getTitle());
3625                    assetEntryImpl.setDescription(assetEntry.getDescription());
3626                    assetEntryImpl.setSummary(assetEntry.getSummary());
3627                    assetEntryImpl.setUrl(assetEntry.getUrl());
3628                    assetEntryImpl.setLayoutUuid(assetEntry.getLayoutUuid());
3629                    assetEntryImpl.setHeight(assetEntry.getHeight());
3630                    assetEntryImpl.setWidth(assetEntry.getWidth());
3631                    assetEntryImpl.setPriority(assetEntry.getPriority());
3632                    assetEntryImpl.setViewCount(assetEntry.getViewCount());
3633    
3634                    return assetEntryImpl;
3635            }
3636    
3637            /**
3638             * Returns the asset entry with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
3639             *
3640             * @param primaryKey the primary key of the asset entry
3641             * @return the asset entry
3642             * @throws com.liferay.portlet.asset.NoSuchEntryException if a asset entry with the primary key could not be found
3643             * @throws SystemException if a system exception occurred
3644             */
3645            @Override
3646            public AssetEntry findByPrimaryKey(Serializable primaryKey)
3647                    throws NoSuchEntryException, SystemException {
3648                    AssetEntry assetEntry = fetchByPrimaryKey(primaryKey);
3649    
3650                    if (assetEntry == null) {
3651                            if (_log.isWarnEnabled()) {
3652                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
3653                            }
3654    
3655                            throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
3656                                    primaryKey);
3657                    }
3658    
3659                    return assetEntry;
3660            }
3661    
3662            /**
3663             * Returns the asset entry with the primary key or throws a {@link com.liferay.portlet.asset.NoSuchEntryException} if it could not be found.
3664             *
3665             * @param entryId the primary key of the asset entry
3666             * @return the asset entry
3667             * @throws com.liferay.portlet.asset.NoSuchEntryException if a asset entry with the primary key could not be found
3668             * @throws SystemException if a system exception occurred
3669             */
3670            @Override
3671            public AssetEntry findByPrimaryKey(long entryId)
3672                    throws NoSuchEntryException, SystemException {
3673                    return findByPrimaryKey((Serializable)entryId);
3674            }
3675    
3676            /**
3677             * Returns the asset entry with the primary key or returns <code>null</code> if it could not be found.
3678             *
3679             * @param primaryKey the primary key of the asset entry
3680             * @return the asset entry, or <code>null</code> if a asset entry with the primary key could not be found
3681             * @throws SystemException if a system exception occurred
3682             */
3683            @Override
3684            public AssetEntry fetchByPrimaryKey(Serializable primaryKey)
3685                    throws SystemException {
3686                    AssetEntry assetEntry = (AssetEntry)EntityCacheUtil.getResult(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
3687                                    AssetEntryImpl.class, primaryKey);
3688    
3689                    if (assetEntry == _nullAssetEntry) {
3690                            return null;
3691                    }
3692    
3693                    if (assetEntry == null) {
3694                            Session session = null;
3695    
3696                            try {
3697                                    session = openSession();
3698    
3699                                    assetEntry = (AssetEntry)session.get(AssetEntryImpl.class,
3700                                                    primaryKey);
3701    
3702                                    if (assetEntry != null) {
3703                                            cacheResult(assetEntry);
3704                                    }
3705                                    else {
3706                                            EntityCacheUtil.putResult(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
3707                                                    AssetEntryImpl.class, primaryKey, _nullAssetEntry);
3708                                    }
3709                            }
3710                            catch (Exception e) {
3711                                    EntityCacheUtil.removeResult(AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
3712                                            AssetEntryImpl.class, primaryKey);
3713    
3714                                    throw processException(e);
3715                            }
3716                            finally {
3717                                    closeSession(session);
3718                            }
3719                    }
3720    
3721                    return assetEntry;
3722            }
3723    
3724            /**
3725             * Returns the asset entry with the primary key or returns <code>null</code> if it could not be found.
3726             *
3727             * @param entryId the primary key of the asset entry
3728             * @return the asset entry, or <code>null</code> if a asset entry with the primary key could not be found
3729             * @throws SystemException if a system exception occurred
3730             */
3731            @Override
3732            public AssetEntry fetchByPrimaryKey(long entryId) throws SystemException {
3733                    return fetchByPrimaryKey((Serializable)entryId);
3734            }
3735    
3736            /**
3737             * Returns all the asset entries.
3738             *
3739             * @return the asset entries
3740             * @throws SystemException if a system exception occurred
3741             */
3742            @Override
3743            public List<AssetEntry> findAll() throws SystemException {
3744                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3745            }
3746    
3747            /**
3748             * Returns a range of all the asset entries.
3749             *
3750             * <p>
3751             * 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.portlet.asset.model.impl.AssetEntryModelImpl}. 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.
3752             * </p>
3753             *
3754             * @param start the lower bound of the range of asset entries
3755             * @param end the upper bound of the range of asset entries (not inclusive)
3756             * @return the range of asset entries
3757             * @throws SystemException if a system exception occurred
3758             */
3759            @Override
3760            public List<AssetEntry> findAll(int start, int end)
3761                    throws SystemException {
3762                    return findAll(start, end, null);
3763            }
3764    
3765            /**
3766             * Returns an ordered range of all the asset entries.
3767             *
3768             * <p>
3769             * 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.portlet.asset.model.impl.AssetEntryModelImpl}. 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.
3770             * </p>
3771             *
3772             * @param start the lower bound of the range of asset entries
3773             * @param end the upper bound of the range of asset entries (not inclusive)
3774             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3775             * @return the ordered range of asset entries
3776             * @throws SystemException if a system exception occurred
3777             */
3778            @Override
3779            public List<AssetEntry> findAll(int start, int end,
3780                    OrderByComparator orderByComparator) throws SystemException {
3781                    boolean pagination = true;
3782                    FinderPath finderPath = null;
3783                    Object[] finderArgs = null;
3784    
3785                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3786                                    (orderByComparator == null)) {
3787                            pagination = false;
3788                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
3789                            finderArgs = FINDER_ARGS_EMPTY;
3790                    }
3791                    else {
3792                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
3793                            finderArgs = new Object[] { start, end, orderByComparator };
3794                    }
3795    
3796                    List<AssetEntry> list = (List<AssetEntry>)FinderCacheUtil.getResult(finderPath,
3797                                    finderArgs, this);
3798    
3799                    if (list == null) {
3800                            StringBundler query = null;
3801                            String sql = null;
3802    
3803                            if (orderByComparator != null) {
3804                                    query = new StringBundler(2 +
3805                                                    (orderByComparator.getOrderByFields().length * 3));
3806    
3807                                    query.append(_SQL_SELECT_ASSETENTRY);
3808    
3809                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3810                                            orderByComparator);
3811    
3812                                    sql = query.toString();
3813                            }
3814                            else {
3815                                    sql = _SQL_SELECT_ASSETENTRY;
3816    
3817                                    if (pagination) {
3818                                            sql = sql.concat(AssetEntryModelImpl.ORDER_BY_JPQL);
3819                                    }
3820                            }
3821    
3822                            Session session = null;
3823    
3824                            try {
3825                                    session = openSession();
3826    
3827                                    Query q = session.createQuery(sql);
3828    
3829                                    if (!pagination) {
3830                                            list = (List<AssetEntry>)QueryUtil.list(q, getDialect(),
3831                                                            start, end, false);
3832    
3833                                            Collections.sort(list);
3834    
3835                                            list = new UnmodifiableList<AssetEntry>(list);
3836                                    }
3837                                    else {
3838                                            list = (List<AssetEntry>)QueryUtil.list(q, getDialect(),
3839                                                            start, end);
3840                                    }
3841    
3842                                    cacheResult(list);
3843    
3844                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3845                            }
3846                            catch (Exception e) {
3847                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3848    
3849                                    throw processException(e);
3850                            }
3851                            finally {
3852                                    closeSession(session);
3853                            }
3854                    }
3855    
3856                    return list;
3857            }
3858    
3859            /**
3860             * Removes all the asset entries from the database.
3861             *
3862             * @throws SystemException if a system exception occurred
3863             */
3864            @Override
3865            public void removeAll() throws SystemException {
3866                    for (AssetEntry assetEntry : findAll()) {
3867                            remove(assetEntry);
3868                    }
3869            }
3870    
3871            /**
3872             * Returns the number of asset entries.
3873             *
3874             * @return the number of asset entries
3875             * @throws SystemException if a system exception occurred
3876             */
3877            @Override
3878            public int countAll() throws SystemException {
3879                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3880                                    FINDER_ARGS_EMPTY, this);
3881    
3882                    if (count == null) {
3883                            Session session = null;
3884    
3885                            try {
3886                                    session = openSession();
3887    
3888                                    Query q = session.createQuery(_SQL_COUNT_ASSETENTRY);
3889    
3890                                    count = (Long)q.uniqueResult();
3891    
3892                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
3893                                            FINDER_ARGS_EMPTY, count);
3894                            }
3895                            catch (Exception e) {
3896                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
3897                                            FINDER_ARGS_EMPTY);
3898    
3899                                    throw processException(e);
3900                            }
3901                            finally {
3902                                    closeSession(session);
3903                            }
3904                    }
3905    
3906                    return count.intValue();
3907            }
3908    
3909            /**
3910             * Returns all the asset categories associated with the asset entry.
3911             *
3912             * @param pk the primary key of the asset entry
3913             * @return the asset categories associated with the asset entry
3914             * @throws SystemException if a system exception occurred
3915             */
3916            @Override
3917            public List<com.liferay.portlet.asset.model.AssetCategory> getAssetCategories(
3918                    long pk) throws SystemException {
3919                    return getAssetCategories(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
3920            }
3921    
3922            /**
3923             * Returns a range of all the asset categories associated with the asset entry.
3924             *
3925             * <p>
3926             * 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.portlet.asset.model.impl.AssetEntryModelImpl}. 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.
3927             * </p>
3928             *
3929             * @param pk the primary key of the asset entry
3930             * @param start the lower bound of the range of asset entries
3931             * @param end the upper bound of the range of asset entries (not inclusive)
3932             * @return the range of asset categories associated with the asset entry
3933             * @throws SystemException if a system exception occurred
3934             */
3935            @Override
3936            public List<com.liferay.portlet.asset.model.AssetCategory> getAssetCategories(
3937                    long pk, int start, int end) throws SystemException {
3938                    return getAssetCategories(pk, start, end, null);
3939            }
3940    
3941            /**
3942             * Returns an ordered range of all the asset categories associated with the asset entry.
3943             *
3944             * <p>
3945             * 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.portlet.asset.model.impl.AssetEntryModelImpl}. 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.
3946             * </p>
3947             *
3948             * @param pk the primary key of the asset entry
3949             * @param start the lower bound of the range of asset entries
3950             * @param end the upper bound of the range of asset entries (not inclusive)
3951             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3952             * @return the ordered range of asset categories associated with the asset entry
3953             * @throws SystemException if a system exception occurred
3954             */
3955            @Override
3956            public List<com.liferay.portlet.asset.model.AssetCategory> getAssetCategories(
3957                    long pk, int start, int end, OrderByComparator orderByComparator)
3958                    throws SystemException {
3959                    return assetEntryToAssetCategoryTableMapper.getRightBaseModels(pk,
3960                            start, end, orderByComparator);
3961            }
3962    
3963            /**
3964             * Returns the number of asset categories associated with the asset entry.
3965             *
3966             * @param pk the primary key of the asset entry
3967             * @return the number of asset categories associated with the asset entry
3968             * @throws SystemException if a system exception occurred
3969             */
3970            @Override
3971            public int getAssetCategoriesSize(long pk) throws SystemException {
3972                    long[] pks = assetEntryToAssetCategoryTableMapper.getRightPrimaryKeys(pk);
3973    
3974                    return pks.length;
3975            }
3976    
3977            /**
3978             * Returns <code>true</code> if the asset category is associated with the asset entry.
3979             *
3980             * @param pk the primary key of the asset entry
3981             * @param assetCategoryPK the primary key of the asset category
3982             * @return <code>true</code> if the asset category is associated with the asset entry; <code>false</code> otherwise
3983             * @throws SystemException if a system exception occurred
3984             */
3985            @Override
3986            public boolean containsAssetCategory(long pk, long assetCategoryPK)
3987                    throws SystemException {
3988                    return assetEntryToAssetCategoryTableMapper.containsTableMapping(pk,
3989                            assetCategoryPK);
3990            }
3991    
3992            /**
3993             * Returns <code>true</code> if the asset entry has any asset categories associated with it.
3994             *
3995             * @param pk the primary key of the asset entry to check for associations with asset categories
3996             * @return <code>true</code> if the asset entry has any asset categories associated with it; <code>false</code> otherwise
3997             * @throws SystemException if a system exception occurred
3998             */
3999            @Override
4000            public boolean containsAssetCategories(long pk) throws SystemException {
4001                    if (getAssetCategoriesSize(pk) > 0) {
4002                            return true;
4003                    }
4004                    else {
4005                            return false;
4006                    }
4007            }
4008    
4009            /**
4010             * Adds an association between the asset entry and the asset category. Also notifies the appropriate model listeners and clears the mapping table finder cache.
4011             *
4012             * @param pk the primary key of the asset entry
4013             * @param assetCategoryPK the primary key of the asset category
4014             * @throws SystemException if a system exception occurred
4015             */
4016            @Override
4017            public void addAssetCategory(long pk, long assetCategoryPK)
4018                    throws SystemException {
4019                    assetEntryToAssetCategoryTableMapper.addTableMapping(pk, assetCategoryPK);
4020            }
4021    
4022            /**
4023             * Adds an association between the asset entry and the asset category. Also notifies the appropriate model listeners and clears the mapping table finder cache.
4024             *
4025             * @param pk the primary key of the asset entry
4026             * @param assetCategory the asset category
4027             * @throws SystemException if a system exception occurred
4028             */
4029            @Override
4030            public void addAssetCategory(long pk,
4031                    com.liferay.portlet.asset.model.AssetCategory assetCategory)
4032                    throws SystemException {
4033                    assetEntryToAssetCategoryTableMapper.addTableMapping(pk,
4034                            assetCategory.getPrimaryKey());
4035            }
4036    
4037            /**
4038             * Adds an association between the asset entry and the asset categories. Also notifies the appropriate model listeners and clears the mapping table finder cache.
4039             *
4040             * @param pk the primary key of the asset entry
4041             * @param assetCategoryPKs the primary keys of the asset categories
4042             * @throws SystemException if a system exception occurred
4043             */
4044            @Override
4045            public void addAssetCategories(long pk, long[] assetCategoryPKs)
4046                    throws SystemException {
4047                    for (long assetCategoryPK : assetCategoryPKs) {
4048                            assetEntryToAssetCategoryTableMapper.addTableMapping(pk,
4049                                    assetCategoryPK);
4050                    }
4051            }
4052    
4053            /**
4054             * Adds an association between the asset entry and the asset categories. Also notifies the appropriate model listeners and clears the mapping table finder cache.
4055             *
4056             * @param pk the primary key of the asset entry
4057             * @param assetCategories the asset categories
4058             * @throws SystemException if a system exception occurred
4059             */
4060            @Override
4061            public void addAssetCategories(long pk,
4062                    List<com.liferay.portlet.asset.model.AssetCategory> assetCategories)
4063                    throws SystemException {
4064                    for (com.liferay.portlet.asset.model.AssetCategory assetCategory : assetCategories) {
4065                            assetEntryToAssetCategoryTableMapper.addTableMapping(pk,
4066                                    assetCategory.getPrimaryKey());
4067                    }
4068            }
4069    
4070            /**
4071             * Clears all associations between the asset entry and its asset categories. Also notifies the appropriate model listeners and clears the mapping table finder cache.
4072             *
4073             * @param pk the primary key of the asset entry to clear the associated asset categories from
4074             * @throws SystemException if a system exception occurred
4075             */
4076            @Override
4077            public void clearAssetCategories(long pk) throws SystemException {
4078                    assetEntryToAssetCategoryTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
4079            }
4080    
4081            /**
4082             * Removes the association between the asset entry and the asset category. Also notifies the appropriate model listeners and clears the mapping table finder cache.
4083             *
4084             * @param pk the primary key of the asset entry
4085             * @param assetCategoryPK the primary key of the asset category
4086             * @throws SystemException if a system exception occurred
4087             */
4088            @Override
4089            public void removeAssetCategory(long pk, long assetCategoryPK)
4090                    throws SystemException {
4091                    assetEntryToAssetCategoryTableMapper.deleteTableMapping(pk,
4092                            assetCategoryPK);
4093            }
4094    
4095            /**
4096             * Removes the association between the asset entry and the asset category. Also notifies the appropriate model listeners and clears the mapping table finder cache.
4097             *
4098             * @param pk the primary key of the asset entry
4099             * @param assetCategory the asset category
4100             * @throws SystemException if a system exception occurred
4101             */
4102            @Override
4103            public void removeAssetCategory(long pk,
4104                    com.liferay.portlet.asset.model.AssetCategory assetCategory)
4105                    throws SystemException {
4106                    assetEntryToAssetCategoryTableMapper.deleteTableMapping(pk,
4107                            assetCategory.getPrimaryKey());
4108            }
4109    
4110            /**
4111             * Removes the association between the asset entry and the asset categories. Also notifies the appropriate model listeners and clears the mapping table finder cache.
4112             *
4113             * @param pk the primary key of the asset entry
4114             * @param assetCategoryPKs the primary keys of the asset categories
4115             * @throws SystemException if a system exception occurred
4116             */
4117            @Override
4118            public void removeAssetCategories(long pk, long[] assetCategoryPKs)
4119                    throws SystemException {
4120                    for (long assetCategoryPK : assetCategoryPKs) {
4121                            assetEntryToAssetCategoryTableMapper.deleteTableMapping(pk,
4122                                    assetCategoryPK);
4123                    }
4124            }
4125    
4126            /**
4127             * Removes the association between the asset entry and the asset categories. Also notifies the appropriate model listeners and clears the mapping table finder cache.
4128             *
4129             * @param pk the primary key of the asset entry
4130             * @param assetCategories the asset categories
4131             * @throws SystemException if a system exception occurred
4132             */
4133            @Override
4134            public void removeAssetCategories(long pk,
4135                    List<com.liferay.portlet.asset.model.AssetCategory> assetCategories)
4136                    throws SystemException {
4137                    for (com.liferay.portlet.asset.model.AssetCategory assetCategory : assetCategories) {
4138                            assetEntryToAssetCategoryTableMapper.deleteTableMapping(pk,
4139                                    assetCategory.getPrimaryKey());
4140                    }
4141            }
4142    
4143            /**
4144             * Sets the asset categories associated with the asset entry, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
4145             *
4146             * @param pk the primary key of the asset entry
4147             * @param assetCategoryPKs the primary keys of the asset categories to be associated with the asset entry
4148             * @throws SystemException if a system exception occurred
4149             */
4150            @Override
4151            public void setAssetCategories(long pk, long[] assetCategoryPKs)
4152                    throws SystemException {
4153                    assetEntryToAssetCategoryTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
4154    
4155                    for (Long assetCategoryPK : assetCategoryPKs) {
4156                            assetEntryToAssetCategoryTableMapper.addTableMapping(pk,
4157                                    assetCategoryPK);
4158                    }
4159            }
4160    
4161            /**
4162             * Sets the asset categories associated with the asset entry, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
4163             *
4164             * @param pk the primary key of the asset entry
4165             * @param assetCategories the asset categories to be associated with the asset entry
4166             * @throws SystemException if a system exception occurred
4167             */
4168            @Override
4169            public void setAssetCategories(long pk,
4170                    List<com.liferay.portlet.asset.model.AssetCategory> assetCategories)
4171                    throws SystemException {
4172                    try {
4173                            long[] assetCategoryPKs = new long[assetCategories.size()];
4174    
4175                            for (int i = 0; i < assetCategories.size(); i++) {
4176                                    com.liferay.portlet.asset.model.AssetCategory assetCategory = assetCategories.get(i);
4177    
4178                                    assetCategoryPKs[i] = assetCategory.getPrimaryKey();
4179                            }
4180    
4181                            setAssetCategories(pk, assetCategoryPKs);
4182                    }
4183                    catch (Exception e) {
4184                            throw processException(e);
4185                    }
4186                    finally {
4187                            FinderCacheUtil.clearCache(AssetEntryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETCATEGORIES_NAME);
4188                    }
4189            }
4190    
4191            /**
4192             * Returns all the asset tags associated with the asset entry.
4193             *
4194             * @param pk the primary key of the asset entry
4195             * @return the asset tags associated with the asset entry
4196             * @throws SystemException if a system exception occurred
4197             */
4198            @Override
4199            public List<com.liferay.portlet.asset.model.AssetTag> getAssetTags(long pk)
4200                    throws SystemException {
4201                    return getAssetTags(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
4202            }
4203    
4204            /**
4205             * Returns a range of all the asset tags associated with the asset entry.
4206             *
4207             * <p>
4208             * 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.portlet.asset.model.impl.AssetEntryModelImpl}. 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.
4209             * </p>
4210             *
4211             * @param pk the primary key of the asset entry
4212             * @param start the lower bound of the range of asset entries
4213             * @param end the upper bound of the range of asset entries (not inclusive)
4214             * @return the range of asset tags associated with the asset entry
4215             * @throws SystemException if a system exception occurred
4216             */
4217            @Override
4218            public List<com.liferay.portlet.asset.model.AssetTag> getAssetTags(
4219                    long pk, int start, int end) throws SystemException {
4220                    return getAssetTags(pk, start, end, null);
4221            }
4222    
4223            /**
4224             * Returns an ordered range of all the asset tags associated with the asset entry.
4225             *
4226             * <p>
4227             * 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.portlet.asset.model.impl.AssetEntryModelImpl}. 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.
4228             * </p>
4229             *
4230             * @param pk the primary key of the asset entry
4231             * @param start the lower bound of the range of asset entries
4232             * @param end the upper bound of the range of asset entries (not inclusive)
4233             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4234             * @return the ordered range of asset tags associated with the asset entry
4235             * @throws SystemException if a system exception occurred
4236             */
4237            @Override
4238            public List<com.liferay.portlet.asset.model.AssetTag> getAssetTags(
4239                    long pk, int start, int end, OrderByComparator orderByComparator)
4240                    throws SystemException {
4241                    return assetEntryToAssetTagTableMapper.getRightBaseModels(pk, start,
4242                            end, orderByComparator);
4243            }
4244    
4245            /**
4246             * Returns the number of asset tags associated with the asset entry.
4247             *
4248             * @param pk the primary key of the asset entry
4249             * @return the number of asset tags associated with the asset entry
4250             * @throws SystemException if a system exception occurred
4251             */
4252            @Override
4253            public int getAssetTagsSize(long pk) throws SystemException {
4254                    long[] pks = assetEntryToAssetTagTableMapper.getRightPrimaryKeys(pk);
4255    
4256                    return pks.length;
4257            }
4258    
4259            /**
4260             * Returns <code>true</code> if the asset tag is associated with the asset entry.
4261             *
4262             * @param pk the primary key of the asset entry
4263             * @param assetTagPK the primary key of the asset tag
4264             * @return <code>true</code> if the asset tag is associated with the asset entry; <code>false</code> otherwise
4265             * @throws SystemException if a system exception occurred
4266             */
4267            @Override
4268            public boolean containsAssetTag(long pk, long assetTagPK)
4269                    throws SystemException {
4270                    return assetEntryToAssetTagTableMapper.containsTableMapping(pk,
4271                            assetTagPK);
4272            }
4273    
4274            /**
4275             * Returns <code>true</code> if the asset entry has any asset tags associated with it.
4276             *
4277             * @param pk the primary key of the asset entry to check for associations with asset tags
4278             * @return <code>true</code> if the asset entry has any asset tags associated with it; <code>false</code> otherwise
4279             * @throws SystemException if a system exception occurred
4280             */
4281            @Override
4282            public boolean containsAssetTags(long pk) throws SystemException {
4283                    if (getAssetTagsSize(pk) > 0) {
4284                            return true;
4285                    }
4286                    else {
4287                            return false;
4288                    }
4289            }
4290    
4291            /**
4292             * Adds an association between the asset entry and the asset tag. Also notifies the appropriate model listeners and clears the mapping table finder cache.
4293             *
4294             * @param pk the primary key of the asset entry
4295             * @param assetTagPK the primary key of the asset tag
4296             * @throws SystemException if a system exception occurred
4297             */
4298            @Override
4299            public void addAssetTag(long pk, long assetTagPK) throws SystemException {
4300                    assetEntryToAssetTagTableMapper.addTableMapping(pk, assetTagPK);
4301            }
4302    
4303            /**
4304             * Adds an association between the asset entry and the asset tag. Also notifies the appropriate model listeners and clears the mapping table finder cache.
4305             *
4306             * @param pk the primary key of the asset entry
4307             * @param assetTag the asset tag
4308             * @throws SystemException if a system exception occurred
4309             */
4310            @Override
4311            public void addAssetTag(long pk,
4312                    com.liferay.portlet.asset.model.AssetTag assetTag)
4313                    throws SystemException {
4314                    assetEntryToAssetTagTableMapper.addTableMapping(pk,
4315                            assetTag.getPrimaryKey());
4316            }
4317    
4318            /**
4319             * Adds an association between the asset entry and the asset tags. Also notifies the appropriate model listeners and clears the mapping table finder cache.
4320             *
4321             * @param pk the primary key of the asset entry
4322             * @param assetTagPKs the primary keys of the asset tags
4323             * @throws SystemException if a system exception occurred
4324             */
4325            @Override
4326            public void addAssetTags(long pk, long[] assetTagPKs)
4327                    throws SystemException {
4328                    for (long assetTagPK : assetTagPKs) {
4329                            assetEntryToAssetTagTableMapper.addTableMapping(pk, assetTagPK);
4330                    }
4331            }
4332    
4333            /**
4334             * Adds an association between the asset entry and the asset tags. Also notifies the appropriate model listeners and clears the mapping table finder cache.
4335             *
4336             * @param pk the primary key of the asset entry
4337             * @param assetTags the asset tags
4338             * @throws SystemException if a system exception occurred
4339             */
4340            @Override
4341            public void addAssetTags(long pk,
4342                    List<com.liferay.portlet.asset.model.AssetTag> assetTags)
4343                    throws SystemException {
4344                    for (com.liferay.portlet.asset.model.AssetTag assetTag : assetTags) {
4345                            assetEntryToAssetTagTableMapper.addTableMapping(pk,
4346                                    assetTag.getPrimaryKey());
4347                    }
4348            }
4349    
4350            /**
4351             * Clears all associations between the asset entry and its asset tags. Also notifies the appropriate model listeners and clears the mapping table finder cache.
4352             *
4353             * @param pk the primary key of the asset entry to clear the associated asset tags from
4354             * @throws SystemException if a system exception occurred
4355             */
4356            @Override
4357            public void clearAssetTags(long pk) throws SystemException {
4358                    assetEntryToAssetTagTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
4359            }
4360    
4361            /**
4362             * Removes the association between the asset entry and the asset tag. Also notifies the appropriate model listeners and clears the mapping table finder cache.
4363             *
4364             * @param pk the primary key of the asset entry
4365             * @param assetTagPK the primary key of the asset tag
4366             * @throws SystemException if a system exception occurred
4367             */
4368            @Override
4369            public void removeAssetTag(long pk, long assetTagPK)
4370                    throws SystemException {
4371                    assetEntryToAssetTagTableMapper.deleteTableMapping(pk, assetTagPK);
4372            }
4373    
4374            /**
4375             * Removes the association between the asset entry and the asset tag. Also notifies the appropriate model listeners and clears the mapping table finder cache.
4376             *
4377             * @param pk the primary key of the asset entry
4378             * @param assetTag the asset tag
4379             * @throws SystemException if a system exception occurred
4380             */
4381            @Override
4382            public void removeAssetTag(long pk,
4383                    com.liferay.portlet.asset.model.AssetTag assetTag)
4384                    throws SystemException {
4385                    assetEntryToAssetTagTableMapper.deleteTableMapping(pk,
4386                            assetTag.getPrimaryKey());
4387            }
4388    
4389            /**
4390             * Removes the association between the asset entry and the asset tags. Also notifies the appropriate model listeners and clears the mapping table finder cache.
4391             *
4392             * @param pk the primary key of the asset entry
4393             * @param assetTagPKs the primary keys of the asset tags
4394             * @throws SystemException if a system exception occurred
4395             */
4396            @Override
4397            public void removeAssetTags(long pk, long[] assetTagPKs)
4398                    throws SystemException {
4399                    for (long assetTagPK : assetTagPKs) {
4400                            assetEntryToAssetTagTableMapper.deleteTableMapping(pk, assetTagPK);
4401                    }
4402            }
4403    
4404            /**
4405             * Removes the association between the asset entry and the asset tags. Also notifies the appropriate model listeners and clears the mapping table finder cache.
4406             *
4407             * @param pk the primary key of the asset entry
4408             * @param assetTags the asset tags
4409             * @throws SystemException if a system exception occurred
4410             */
4411            @Override
4412            public void removeAssetTags(long pk,
4413                    List<com.liferay.portlet.asset.model.AssetTag> assetTags)
4414                    throws SystemException {
4415                    for (com.liferay.portlet.asset.model.AssetTag assetTag : assetTags) {
4416                            assetEntryToAssetTagTableMapper.deleteTableMapping(pk,
4417                                    assetTag.getPrimaryKey());
4418                    }
4419            }
4420    
4421            /**
4422             * Sets the asset tags associated with the asset entry, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
4423             *
4424             * @param pk the primary key of the asset entry
4425             * @param assetTagPKs the primary keys of the asset tags to be associated with the asset entry
4426             * @throws SystemException if a system exception occurred
4427             */
4428            @Override
4429            public void setAssetTags(long pk, long[] assetTagPKs)
4430                    throws SystemException {
4431                    assetEntryToAssetTagTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
4432    
4433                    for (Long assetTagPK : assetTagPKs) {
4434                            assetEntryToAssetTagTableMapper.addTableMapping(pk, assetTagPK);
4435                    }
4436            }
4437    
4438            /**
4439             * Sets the asset tags associated with the asset entry, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
4440             *
4441             * @param pk the primary key of the asset entry
4442             * @param assetTags the asset tags to be associated with the asset entry
4443             * @throws SystemException if a system exception occurred
4444             */
4445            @Override
4446            public void setAssetTags(long pk,
4447                    List<com.liferay.portlet.asset.model.AssetTag> assetTags)
4448                    throws SystemException {
4449                    try {
4450                            long[] assetTagPKs = new long[assetTags.size()];
4451    
4452                            for (int i = 0; i < assetTags.size(); i++) {
4453                                    com.liferay.portlet.asset.model.AssetTag assetTag = assetTags.get(i);
4454    
4455                                    assetTagPKs[i] = assetTag.getPrimaryKey();
4456                            }
4457    
4458                            setAssetTags(pk, assetTagPKs);
4459                    }
4460                    catch (Exception e) {
4461                            throw processException(e);
4462                    }
4463                    finally {
4464                            FinderCacheUtil.clearCache(AssetEntryModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
4465                    }
4466            }
4467    
4468            /**
4469             * Initializes the asset entry persistence.
4470             */
4471            public void afterPropertiesSet() {
4472                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
4473                                            com.liferay.portal.util.PropsUtil.get(
4474                                                    "value.object.listener.com.liferay.portlet.asset.model.AssetEntry")));
4475    
4476                    if (listenerClassNames.length > 0) {
4477                            try {
4478                                    List<ModelListener<AssetEntry>> listenersList = new ArrayList<ModelListener<AssetEntry>>();
4479    
4480                                    for (String listenerClassName : listenerClassNames) {
4481                                            listenersList.add((ModelListener<AssetEntry>)InstanceFactory.newInstance(
4482                                                            getClassLoader(), listenerClassName));
4483                                    }
4484    
4485                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
4486                            }
4487                            catch (Exception e) {
4488                                    _log.error(e);
4489                            }
4490                    }
4491    
4492                    assetEntryToAssetCategoryTableMapper = TableMapperFactory.getTableMapper("AssetEntries_AssetCategories",
4493                                    "entryId", "categoryId", this, assetCategoryPersistence);
4494    
4495                    assetEntryToAssetTagTableMapper = TableMapperFactory.getTableMapper("AssetEntries_AssetTags",
4496                                    "entryId", "tagId", this, assetTagPersistence);
4497            }
4498    
4499            public void destroy() {
4500                    EntityCacheUtil.removeCache(AssetEntryImpl.class.getName());
4501                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
4502                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4503                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4504            }
4505    
4506            @BeanReference(type = AssetCategoryPersistence.class)
4507            protected AssetCategoryPersistence assetCategoryPersistence;
4508            protected TableMapper<AssetEntry, com.liferay.portlet.asset.model.AssetCategory> assetEntryToAssetCategoryTableMapper;
4509            @BeanReference(type = AssetTagPersistence.class)
4510            protected AssetTagPersistence assetTagPersistence;
4511            protected TableMapper<AssetEntry, com.liferay.portlet.asset.model.AssetTag> assetEntryToAssetTagTableMapper;
4512            private static final String _SQL_SELECT_ASSETENTRY = "SELECT assetEntry FROM AssetEntry assetEntry";
4513            private static final String _SQL_SELECT_ASSETENTRY_WHERE = "SELECT assetEntry FROM AssetEntry assetEntry WHERE ";
4514            private static final String _SQL_COUNT_ASSETENTRY = "SELECT COUNT(assetEntry) FROM AssetEntry assetEntry";
4515            private static final String _SQL_COUNT_ASSETENTRY_WHERE = "SELECT COUNT(assetEntry) FROM AssetEntry assetEntry WHERE ";
4516            private static final String _ORDER_BY_ENTITY_ALIAS = "assetEntry.";
4517            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AssetEntry exists with the primary key ";
4518            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AssetEntry exists with the key {";
4519            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
4520            private static Log _log = LogFactoryUtil.getLog(AssetEntryPersistenceImpl.class);
4521            private static AssetEntry _nullAssetEntry = new AssetEntryImpl() {
4522                            @Override
4523                            public Object clone() {
4524                                    return this;
4525                            }
4526    
4527                            @Override
4528                            public CacheModel<AssetEntry> toCacheModel() {
4529                                    return _nullAssetEntryCacheModel;
4530                            }
4531                    };
4532    
4533            private static CacheModel<AssetEntry> _nullAssetEntryCacheModel = new CacheModel<AssetEntry>() {
4534                            @Override
4535                            public AssetEntry toEntityModel() {
4536                                    return _nullAssetEntry;
4537                            }
4538                    };
4539    }