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