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