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