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