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