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