001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.asset.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.bean.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.model.CacheModel;
037    import com.liferay.portal.model.ModelListener;
038    import com.liferay.portal.service.persistence.UserPersistence;
039    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
040    
041    import com.liferay.portlet.asset.NoSuchLinkException;
042    import com.liferay.portlet.asset.model.AssetLink;
043    import com.liferay.portlet.asset.model.impl.AssetLinkImpl;
044    import com.liferay.portlet.asset.model.impl.AssetLinkModelImpl;
045    
046    import java.io.Serializable;
047    
048    import java.util.ArrayList;
049    import java.util.Collections;
050    import java.util.List;
051    
052    /**
053     * The persistence implementation for the asset link service.
054     *
055     * <p>
056     * Caching information and settings can be found in <code>portal.properties</code>
057     * </p>
058     *
059     * @author Brian Wing Shun Chan
060     * @see AssetLinkPersistence
061     * @see AssetLinkUtil
062     * @generated
063     */
064    public class AssetLinkPersistenceImpl extends BasePersistenceImpl<AssetLink>
065            implements AssetLinkPersistence {
066            /*
067             * NOTE FOR DEVELOPERS:
068             *
069             * Never modify or reference this class directly. Always use {@link AssetLinkUtil} to access the asset link persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
070             */
071            public static final String FINDER_CLASS_NAME_ENTITY = AssetLinkImpl.class.getName();
072            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073                    ".List1";
074            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075                    ".List2";
076            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_E1 = new FinderPath(AssetLinkModelImpl.ENTITY_CACHE_ENABLED,
077                            AssetLinkModelImpl.FINDER_CACHE_ENABLED, AssetLinkImpl.class,
078                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByE1",
079                            new String[] {
080                                    Long.class.getName(),
081                                    
082                            "java.lang.Integer", "java.lang.Integer",
083                                    "com.liferay.portal.kernel.util.OrderByComparator"
084                            });
085            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_E1 = new FinderPath(AssetLinkModelImpl.ENTITY_CACHE_ENABLED,
086                            AssetLinkModelImpl.FINDER_CACHE_ENABLED, AssetLinkImpl.class,
087                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByE1",
088                            new String[] { Long.class.getName() },
089                            AssetLinkModelImpl.ENTRYID1_COLUMN_BITMASK);
090            public static final FinderPath FINDER_PATH_COUNT_BY_E1 = new FinderPath(AssetLinkModelImpl.ENTITY_CACHE_ENABLED,
091                            AssetLinkModelImpl.FINDER_CACHE_ENABLED, Long.class,
092                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByE1",
093                            new String[] { Long.class.getName() });
094            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_E2 = new FinderPath(AssetLinkModelImpl.ENTITY_CACHE_ENABLED,
095                            AssetLinkModelImpl.FINDER_CACHE_ENABLED, AssetLinkImpl.class,
096                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByE2",
097                            new String[] {
098                                    Long.class.getName(),
099                                    
100                            "java.lang.Integer", "java.lang.Integer",
101                                    "com.liferay.portal.kernel.util.OrderByComparator"
102                            });
103            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_E2 = new FinderPath(AssetLinkModelImpl.ENTITY_CACHE_ENABLED,
104                            AssetLinkModelImpl.FINDER_CACHE_ENABLED, AssetLinkImpl.class,
105                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByE2",
106                            new String[] { Long.class.getName() },
107                            AssetLinkModelImpl.ENTRYID2_COLUMN_BITMASK);
108            public static final FinderPath FINDER_PATH_COUNT_BY_E2 = new FinderPath(AssetLinkModelImpl.ENTITY_CACHE_ENABLED,
109                            AssetLinkModelImpl.FINDER_CACHE_ENABLED, Long.class,
110                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByE2",
111                            new String[] { Long.class.getName() });
112            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_E_E = new FinderPath(AssetLinkModelImpl.ENTITY_CACHE_ENABLED,
113                            AssetLinkModelImpl.FINDER_CACHE_ENABLED, AssetLinkImpl.class,
114                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByE_E",
115                            new String[] {
116                                    Long.class.getName(), Long.class.getName(),
117                                    
118                            "java.lang.Integer", "java.lang.Integer",
119                                    "com.liferay.portal.kernel.util.OrderByComparator"
120                            });
121            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_E_E = new FinderPath(AssetLinkModelImpl.ENTITY_CACHE_ENABLED,
122                            AssetLinkModelImpl.FINDER_CACHE_ENABLED, AssetLinkImpl.class,
123                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByE_E",
124                            new String[] { Long.class.getName(), Long.class.getName() },
125                            AssetLinkModelImpl.ENTRYID1_COLUMN_BITMASK |
126                            AssetLinkModelImpl.ENTRYID2_COLUMN_BITMASK);
127            public static final FinderPath FINDER_PATH_COUNT_BY_E_E = new FinderPath(AssetLinkModelImpl.ENTITY_CACHE_ENABLED,
128                            AssetLinkModelImpl.FINDER_CACHE_ENABLED, Long.class,
129                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByE_E",
130                            new String[] { Long.class.getName(), Long.class.getName() });
131            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_E1_T = new FinderPath(AssetLinkModelImpl.ENTITY_CACHE_ENABLED,
132                            AssetLinkModelImpl.FINDER_CACHE_ENABLED, AssetLinkImpl.class,
133                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByE1_T",
134                            new String[] {
135                                    Long.class.getName(), Integer.class.getName(),
136                                    
137                            "java.lang.Integer", "java.lang.Integer",
138                                    "com.liferay.portal.kernel.util.OrderByComparator"
139                            });
140            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_E1_T = new FinderPath(AssetLinkModelImpl.ENTITY_CACHE_ENABLED,
141                            AssetLinkModelImpl.FINDER_CACHE_ENABLED, AssetLinkImpl.class,
142                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByE1_T",
143                            new String[] { Long.class.getName(), Integer.class.getName() },
144                            AssetLinkModelImpl.ENTRYID1_COLUMN_BITMASK |
145                            AssetLinkModelImpl.TYPE_COLUMN_BITMASK);
146            public static final FinderPath FINDER_PATH_COUNT_BY_E1_T = new FinderPath(AssetLinkModelImpl.ENTITY_CACHE_ENABLED,
147                            AssetLinkModelImpl.FINDER_CACHE_ENABLED, Long.class,
148                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByE1_T",
149                            new String[] { Long.class.getName(), Integer.class.getName() });
150            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_E2_T = new FinderPath(AssetLinkModelImpl.ENTITY_CACHE_ENABLED,
151                            AssetLinkModelImpl.FINDER_CACHE_ENABLED, AssetLinkImpl.class,
152                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByE2_T",
153                            new String[] {
154                                    Long.class.getName(), Integer.class.getName(),
155                                    
156                            "java.lang.Integer", "java.lang.Integer",
157                                    "com.liferay.portal.kernel.util.OrderByComparator"
158                            });
159            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_E2_T = new FinderPath(AssetLinkModelImpl.ENTITY_CACHE_ENABLED,
160                            AssetLinkModelImpl.FINDER_CACHE_ENABLED, AssetLinkImpl.class,
161                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByE2_T",
162                            new String[] { Long.class.getName(), Integer.class.getName() },
163                            AssetLinkModelImpl.ENTRYID2_COLUMN_BITMASK |
164                            AssetLinkModelImpl.TYPE_COLUMN_BITMASK);
165            public static final FinderPath FINDER_PATH_COUNT_BY_E2_T = new FinderPath(AssetLinkModelImpl.ENTITY_CACHE_ENABLED,
166                            AssetLinkModelImpl.FINDER_CACHE_ENABLED, Long.class,
167                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByE2_T",
168                            new String[] { Long.class.getName(), Integer.class.getName() });
169            public static final FinderPath FINDER_PATH_FETCH_BY_E_E_T = new FinderPath(AssetLinkModelImpl.ENTITY_CACHE_ENABLED,
170                            AssetLinkModelImpl.FINDER_CACHE_ENABLED, AssetLinkImpl.class,
171                            FINDER_CLASS_NAME_ENTITY, "fetchByE_E_T",
172                            new String[] {
173                                    Long.class.getName(), Long.class.getName(),
174                                    Integer.class.getName()
175                            },
176                            AssetLinkModelImpl.ENTRYID1_COLUMN_BITMASK |
177                            AssetLinkModelImpl.ENTRYID2_COLUMN_BITMASK |
178                            AssetLinkModelImpl.TYPE_COLUMN_BITMASK);
179            public static final FinderPath FINDER_PATH_COUNT_BY_E_E_T = new FinderPath(AssetLinkModelImpl.ENTITY_CACHE_ENABLED,
180                            AssetLinkModelImpl.FINDER_CACHE_ENABLED, Long.class,
181                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByE_E_T",
182                            new String[] {
183                                    Long.class.getName(), Long.class.getName(),
184                                    Integer.class.getName()
185                            });
186            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(AssetLinkModelImpl.ENTITY_CACHE_ENABLED,
187                            AssetLinkModelImpl.FINDER_CACHE_ENABLED, AssetLinkImpl.class,
188                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
189            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(AssetLinkModelImpl.ENTITY_CACHE_ENABLED,
190                            AssetLinkModelImpl.FINDER_CACHE_ENABLED, AssetLinkImpl.class,
191                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
192            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AssetLinkModelImpl.ENTITY_CACHE_ENABLED,
193                            AssetLinkModelImpl.FINDER_CACHE_ENABLED, Long.class,
194                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
195    
196            /**
197             * Caches the asset link in the entity cache if it is enabled.
198             *
199             * @param assetLink the asset link
200             */
201            public void cacheResult(AssetLink assetLink) {
202                    EntityCacheUtil.putResult(AssetLinkModelImpl.ENTITY_CACHE_ENABLED,
203                            AssetLinkImpl.class, assetLink.getPrimaryKey(), assetLink);
204    
205                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_E_E_T,
206                            new Object[] {
207                                    Long.valueOf(assetLink.getEntryId1()),
208                                    Long.valueOf(assetLink.getEntryId2()),
209                                    Integer.valueOf(assetLink.getType())
210                            }, assetLink);
211    
212                    assetLink.resetOriginalValues();
213            }
214    
215            /**
216             * Caches the asset links in the entity cache if it is enabled.
217             *
218             * @param assetLinks the asset links
219             */
220            public void cacheResult(List<AssetLink> assetLinks) {
221                    for (AssetLink assetLink : assetLinks) {
222                            if (EntityCacheUtil.getResult(
223                                                    AssetLinkModelImpl.ENTITY_CACHE_ENABLED,
224                                                    AssetLinkImpl.class, assetLink.getPrimaryKey()) == null) {
225                                    cacheResult(assetLink);
226                            }
227                            else {
228                                    assetLink.resetOriginalValues();
229                            }
230                    }
231            }
232    
233            /**
234             * Clears the cache for all asset links.
235             *
236             * <p>
237             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
238             * </p>
239             */
240            @Override
241            public void clearCache() {
242                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
243                            CacheRegistryUtil.clear(AssetLinkImpl.class.getName());
244                    }
245    
246                    EntityCacheUtil.clearCache(AssetLinkImpl.class.getName());
247    
248                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
249                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
250                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
251            }
252    
253            /**
254             * Clears the cache for the asset link.
255             *
256             * <p>
257             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
258             * </p>
259             */
260            @Override
261            public void clearCache(AssetLink assetLink) {
262                    EntityCacheUtil.removeResult(AssetLinkModelImpl.ENTITY_CACHE_ENABLED,
263                            AssetLinkImpl.class, assetLink.getPrimaryKey());
264    
265                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
266                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
267    
268                    clearUniqueFindersCache(assetLink);
269            }
270    
271            @Override
272            public void clearCache(List<AssetLink> assetLinks) {
273                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
274                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
275    
276                    for (AssetLink assetLink : assetLinks) {
277                            EntityCacheUtil.removeResult(AssetLinkModelImpl.ENTITY_CACHE_ENABLED,
278                                    AssetLinkImpl.class, assetLink.getPrimaryKey());
279    
280                            clearUniqueFindersCache(assetLink);
281                    }
282            }
283    
284            protected void clearUniqueFindersCache(AssetLink assetLink) {
285                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_E_E_T,
286                            new Object[] {
287                                    Long.valueOf(assetLink.getEntryId1()),
288                                    Long.valueOf(assetLink.getEntryId2()),
289                                    Integer.valueOf(assetLink.getType())
290                            });
291            }
292    
293            /**
294             * Creates a new asset link with the primary key. Does not add the asset link to the database.
295             *
296             * @param linkId the primary key for the new asset link
297             * @return the new asset link
298             */
299            public AssetLink create(long linkId) {
300                    AssetLink assetLink = new AssetLinkImpl();
301    
302                    assetLink.setNew(true);
303                    assetLink.setPrimaryKey(linkId);
304    
305                    return assetLink;
306            }
307    
308            /**
309             * Removes the asset link with the primary key from the database. Also notifies the appropriate model listeners.
310             *
311             * @param linkId the primary key of the asset link
312             * @return the asset link that was removed
313             * @throws com.liferay.portlet.asset.NoSuchLinkException if a asset link with the primary key could not be found
314             * @throws SystemException if a system exception occurred
315             */
316            public AssetLink remove(long linkId)
317                    throws NoSuchLinkException, SystemException {
318                    return remove(Long.valueOf(linkId));
319            }
320    
321            /**
322             * Removes the asset link with the primary key from the database. Also notifies the appropriate model listeners.
323             *
324             * @param primaryKey the primary key of the asset link
325             * @return the asset link that was removed
326             * @throws com.liferay.portlet.asset.NoSuchLinkException if a asset link with the primary key could not be found
327             * @throws SystemException if a system exception occurred
328             */
329            @Override
330            public AssetLink remove(Serializable primaryKey)
331                    throws NoSuchLinkException, SystemException {
332                    Session session = null;
333    
334                    try {
335                            session = openSession();
336    
337                            AssetLink assetLink = (AssetLink)session.get(AssetLinkImpl.class,
338                                            primaryKey);
339    
340                            if (assetLink == null) {
341                                    if (_log.isWarnEnabled()) {
342                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
343                                    }
344    
345                                    throw new NoSuchLinkException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
346                                            primaryKey);
347                            }
348    
349                            return remove(assetLink);
350                    }
351                    catch (NoSuchLinkException nsee) {
352                            throw nsee;
353                    }
354                    catch (Exception e) {
355                            throw processException(e);
356                    }
357                    finally {
358                            closeSession(session);
359                    }
360            }
361    
362            @Override
363            protected AssetLink removeImpl(AssetLink assetLink)
364                    throws SystemException {
365                    assetLink = toUnwrappedModel(assetLink);
366    
367                    Session session = null;
368    
369                    try {
370                            session = openSession();
371    
372                            if (assetLink.isCachedModel()) {
373                                    assetLink = (AssetLink)session.get(AssetLinkImpl.class,
374                                                    assetLink.getPrimaryKeyObj());
375                            }
376    
377                            session.delete(assetLink);
378                    }
379                    catch (Exception e) {
380                            throw processException(e);
381                    }
382                    finally {
383                            closeSession(session);
384                    }
385    
386                    clearCache(assetLink);
387    
388                    return assetLink;
389            }
390    
391            @Override
392            public AssetLink updateImpl(
393                    com.liferay.portlet.asset.model.AssetLink assetLink)
394                    throws SystemException {
395                    assetLink = toUnwrappedModel(assetLink);
396    
397                    boolean isNew = assetLink.isNew();
398    
399                    AssetLinkModelImpl assetLinkModelImpl = (AssetLinkModelImpl)assetLink;
400    
401                    Session session = null;
402    
403                    try {
404                            session = openSession();
405    
406                            if (assetLink.isNew()) {
407                                    session.save(assetLink);
408    
409                                    assetLink.setNew(false);
410                            }
411                            else {
412                                    session.merge(assetLink);
413                            }
414                    }
415                    catch (Exception e) {
416                            throw processException(e);
417                    }
418                    finally {
419                            closeSession(session);
420                    }
421    
422                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
423    
424                    if (isNew || !AssetLinkModelImpl.COLUMN_BITMASK_ENABLED) {
425                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
426                    }
427    
428                    else {
429                            if ((assetLinkModelImpl.getColumnBitmask() &
430                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_E1.getColumnBitmask()) != 0) {
431                                    Object[] args = new Object[] {
432                                                    Long.valueOf(assetLinkModelImpl.getOriginalEntryId1())
433                                            };
434    
435                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_E1, args);
436                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_E1,
437                                            args);
438    
439                                    args = new Object[] {
440                                                    Long.valueOf(assetLinkModelImpl.getEntryId1())
441                                            };
442    
443                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_E1, args);
444                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_E1,
445                                            args);
446                            }
447    
448                            if ((assetLinkModelImpl.getColumnBitmask() &
449                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_E2.getColumnBitmask()) != 0) {
450                                    Object[] args = new Object[] {
451                                                    Long.valueOf(assetLinkModelImpl.getOriginalEntryId2())
452                                            };
453    
454                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_E2, args);
455                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_E2,
456                                            args);
457    
458                                    args = new Object[] {
459                                                    Long.valueOf(assetLinkModelImpl.getEntryId2())
460                                            };
461    
462                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_E2, args);
463                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_E2,
464                                            args);
465                            }
466    
467                            if ((assetLinkModelImpl.getColumnBitmask() &
468                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_E_E.getColumnBitmask()) != 0) {
469                                    Object[] args = new Object[] {
470                                                    Long.valueOf(assetLinkModelImpl.getOriginalEntryId1()),
471                                                    Long.valueOf(assetLinkModelImpl.getOriginalEntryId2())
472                                            };
473    
474                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_E_E, args);
475                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_E_E,
476                                            args);
477    
478                                    args = new Object[] {
479                                                    Long.valueOf(assetLinkModelImpl.getEntryId1()),
480                                                    Long.valueOf(assetLinkModelImpl.getEntryId2())
481                                            };
482    
483                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_E_E, args);
484                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_E_E,
485                                            args);
486                            }
487    
488                            if ((assetLinkModelImpl.getColumnBitmask() &
489                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_E1_T.getColumnBitmask()) != 0) {
490                                    Object[] args = new Object[] {
491                                                    Long.valueOf(assetLinkModelImpl.getOriginalEntryId1()),
492                                                    Integer.valueOf(assetLinkModelImpl.getOriginalType())
493                                            };
494    
495                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_E1_T, args);
496                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_E1_T,
497                                            args);
498    
499                                    args = new Object[] {
500                                                    Long.valueOf(assetLinkModelImpl.getEntryId1()),
501                                                    Integer.valueOf(assetLinkModelImpl.getType())
502                                            };
503    
504                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_E1_T, args);
505                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_E1_T,
506                                            args);
507                            }
508    
509                            if ((assetLinkModelImpl.getColumnBitmask() &
510                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_E2_T.getColumnBitmask()) != 0) {
511                                    Object[] args = new Object[] {
512                                                    Long.valueOf(assetLinkModelImpl.getOriginalEntryId2()),
513                                                    Integer.valueOf(assetLinkModelImpl.getOriginalType())
514                                            };
515    
516                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_E2_T, args);
517                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_E2_T,
518                                            args);
519    
520                                    args = new Object[] {
521                                                    Long.valueOf(assetLinkModelImpl.getEntryId2()),
522                                                    Integer.valueOf(assetLinkModelImpl.getType())
523                                            };
524    
525                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_E2_T, args);
526                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_E2_T,
527                                            args);
528                            }
529                    }
530    
531                    EntityCacheUtil.putResult(AssetLinkModelImpl.ENTITY_CACHE_ENABLED,
532                            AssetLinkImpl.class, assetLink.getPrimaryKey(), assetLink);
533    
534                    if (isNew) {
535                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_E_E_T,
536                                    new Object[] {
537                                            Long.valueOf(assetLink.getEntryId1()),
538                                            Long.valueOf(assetLink.getEntryId2()),
539                                            Integer.valueOf(assetLink.getType())
540                                    }, assetLink);
541                    }
542                    else {
543                            if ((assetLinkModelImpl.getColumnBitmask() &
544                                            FINDER_PATH_FETCH_BY_E_E_T.getColumnBitmask()) != 0) {
545                                    Object[] args = new Object[] {
546                                                    Long.valueOf(assetLinkModelImpl.getOriginalEntryId1()),
547                                                    Long.valueOf(assetLinkModelImpl.getOriginalEntryId2()),
548                                                    Integer.valueOf(assetLinkModelImpl.getOriginalType())
549                                            };
550    
551                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_E_E_T, args);
552    
553                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_E_E_T, args);
554    
555                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_E_E_T,
556                                            new Object[] {
557                                                    Long.valueOf(assetLink.getEntryId1()),
558                                                    Long.valueOf(assetLink.getEntryId2()),
559                                                    Integer.valueOf(assetLink.getType())
560                                            }, assetLink);
561                            }
562                    }
563    
564                    return assetLink;
565            }
566    
567            protected AssetLink toUnwrappedModel(AssetLink assetLink) {
568                    if (assetLink instanceof AssetLinkImpl) {
569                            return assetLink;
570                    }
571    
572                    AssetLinkImpl assetLinkImpl = new AssetLinkImpl();
573    
574                    assetLinkImpl.setNew(assetLink.isNew());
575                    assetLinkImpl.setPrimaryKey(assetLink.getPrimaryKey());
576    
577                    assetLinkImpl.setLinkId(assetLink.getLinkId());
578                    assetLinkImpl.setCompanyId(assetLink.getCompanyId());
579                    assetLinkImpl.setUserId(assetLink.getUserId());
580                    assetLinkImpl.setUserName(assetLink.getUserName());
581                    assetLinkImpl.setCreateDate(assetLink.getCreateDate());
582                    assetLinkImpl.setEntryId1(assetLink.getEntryId1());
583                    assetLinkImpl.setEntryId2(assetLink.getEntryId2());
584                    assetLinkImpl.setType(assetLink.getType());
585                    assetLinkImpl.setWeight(assetLink.getWeight());
586    
587                    return assetLinkImpl;
588            }
589    
590            /**
591             * Returns the asset link with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
592             *
593             * @param primaryKey the primary key of the asset link
594             * @return the asset link
595             * @throws com.liferay.portal.NoSuchModelException if a asset link with the primary key could not be found
596             * @throws SystemException if a system exception occurred
597             */
598            @Override
599            public AssetLink findByPrimaryKey(Serializable primaryKey)
600                    throws NoSuchModelException, SystemException {
601                    return findByPrimaryKey(((Long)primaryKey).longValue());
602            }
603    
604            /**
605             * Returns the asset link with the primary key or throws a {@link com.liferay.portlet.asset.NoSuchLinkException} if it could not be found.
606             *
607             * @param linkId the primary key of the asset link
608             * @return the asset link
609             * @throws com.liferay.portlet.asset.NoSuchLinkException if a asset link with the primary key could not be found
610             * @throws SystemException if a system exception occurred
611             */
612            public AssetLink findByPrimaryKey(long linkId)
613                    throws NoSuchLinkException, SystemException {
614                    AssetLink assetLink = fetchByPrimaryKey(linkId);
615    
616                    if (assetLink == null) {
617                            if (_log.isWarnEnabled()) {
618                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + linkId);
619                            }
620    
621                            throw new NoSuchLinkException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
622                                    linkId);
623                    }
624    
625                    return assetLink;
626            }
627    
628            /**
629             * Returns the asset link with the primary key or returns <code>null</code> if it could not be found.
630             *
631             * @param primaryKey the primary key of the asset link
632             * @return the asset link, or <code>null</code> if a asset link with the primary key could not be found
633             * @throws SystemException if a system exception occurred
634             */
635            @Override
636            public AssetLink fetchByPrimaryKey(Serializable primaryKey)
637                    throws SystemException {
638                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
639            }
640    
641            /**
642             * Returns the asset link with the primary key or returns <code>null</code> if it could not be found.
643             *
644             * @param linkId the primary key of the asset link
645             * @return the asset link, or <code>null</code> if a asset link with the primary key could not be found
646             * @throws SystemException if a system exception occurred
647             */
648            public AssetLink fetchByPrimaryKey(long linkId) throws SystemException {
649                    AssetLink assetLink = (AssetLink)EntityCacheUtil.getResult(AssetLinkModelImpl.ENTITY_CACHE_ENABLED,
650                                    AssetLinkImpl.class, linkId);
651    
652                    if (assetLink == _nullAssetLink) {
653                            return null;
654                    }
655    
656                    if (assetLink == null) {
657                            Session session = null;
658    
659                            boolean hasException = false;
660    
661                            try {
662                                    session = openSession();
663    
664                                    assetLink = (AssetLink)session.get(AssetLinkImpl.class,
665                                                    Long.valueOf(linkId));
666                            }
667                            catch (Exception e) {
668                                    hasException = true;
669    
670                                    throw processException(e);
671                            }
672                            finally {
673                                    if (assetLink != null) {
674                                            cacheResult(assetLink);
675                                    }
676                                    else if (!hasException) {
677                                            EntityCacheUtil.putResult(AssetLinkModelImpl.ENTITY_CACHE_ENABLED,
678                                                    AssetLinkImpl.class, linkId, _nullAssetLink);
679                                    }
680    
681                                    closeSession(session);
682                            }
683                    }
684    
685                    return assetLink;
686            }
687    
688            /**
689             * Returns all the asset links where entryId1 = &#63;.
690             *
691             * @param entryId1 the entry id1
692             * @return the matching asset links
693             * @throws SystemException if a system exception occurred
694             */
695            public List<AssetLink> findByE1(long entryId1) throws SystemException {
696                    return findByE1(entryId1, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
697            }
698    
699            /**
700             * Returns a range of all the asset links where entryId1 = &#63;.
701             *
702             * <p>
703             * 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.
704             * </p>
705             *
706             * @param entryId1 the entry id1
707             * @param start the lower bound of the range of asset links
708             * @param end the upper bound of the range of asset links (not inclusive)
709             * @return the range of matching asset links
710             * @throws SystemException if a system exception occurred
711             */
712            public List<AssetLink> findByE1(long entryId1, int start, int end)
713                    throws SystemException {
714                    return findByE1(entryId1, start, end, null);
715            }
716    
717            /**
718             * Returns an ordered range of all the asset links where entryId1 = &#63;.
719             *
720             * <p>
721             * 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.
722             * </p>
723             *
724             * @param entryId1 the entry id1
725             * @param start the lower bound of the range of asset links
726             * @param end the upper bound of the range of asset links (not inclusive)
727             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
728             * @return the ordered range of matching asset links
729             * @throws SystemException if a system exception occurred
730             */
731            public List<AssetLink> findByE1(long entryId1, int start, int end,
732                    OrderByComparator orderByComparator) throws SystemException {
733                    FinderPath finderPath = null;
734                    Object[] finderArgs = null;
735    
736                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
737                                    (orderByComparator == null)) {
738                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_E1;
739                            finderArgs = new Object[] { entryId1 };
740                    }
741                    else {
742                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_E1;
743                            finderArgs = new Object[] { entryId1, start, end, orderByComparator };
744                    }
745    
746                    List<AssetLink> list = (List<AssetLink>)FinderCacheUtil.getResult(finderPath,
747                                    finderArgs, this);
748    
749                    if ((list != null) && !list.isEmpty()) {
750                            for (AssetLink assetLink : list) {
751                                    if ((entryId1 != assetLink.getEntryId1())) {
752                                            list = null;
753    
754                                            break;
755                                    }
756                            }
757                    }
758    
759                    if (list == null) {
760                            StringBundler query = null;
761    
762                            if (orderByComparator != null) {
763                                    query = new StringBundler(3 +
764                                                    (orderByComparator.getOrderByFields().length * 3));
765                            }
766                            else {
767                                    query = new StringBundler(3);
768                            }
769    
770                            query.append(_SQL_SELECT_ASSETLINK_WHERE);
771    
772                            query.append(_FINDER_COLUMN_E1_ENTRYID1_2);
773    
774                            if (orderByComparator != null) {
775                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
776                                            orderByComparator);
777                            }
778    
779                            else {
780                                    query.append(AssetLinkModelImpl.ORDER_BY_JPQL);
781                            }
782    
783                            String sql = query.toString();
784    
785                            Session session = null;
786    
787                            try {
788                                    session = openSession();
789    
790                                    Query q = session.createQuery(sql);
791    
792                                    QueryPos qPos = QueryPos.getInstance(q);
793    
794                                    qPos.add(entryId1);
795    
796                                    list = (List<AssetLink>)QueryUtil.list(q, getDialect(), start,
797                                                    end);
798                            }
799                            catch (Exception e) {
800                                    throw processException(e);
801                            }
802                            finally {
803                                    if (list == null) {
804                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
805                                    }
806                                    else {
807                                            cacheResult(list);
808    
809                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
810                                    }
811    
812                                    closeSession(session);
813                            }
814                    }
815    
816                    return list;
817            }
818    
819            /**
820             * Returns the first asset link in the ordered set where entryId1 = &#63;.
821             *
822             * @param entryId1 the entry id1
823             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
824             * @return the first matching asset link
825             * @throws com.liferay.portlet.asset.NoSuchLinkException if a matching asset link could not be found
826             * @throws SystemException if a system exception occurred
827             */
828            public AssetLink findByE1_First(long entryId1,
829                    OrderByComparator orderByComparator)
830                    throws NoSuchLinkException, SystemException {
831                    AssetLink assetLink = fetchByE1_First(entryId1, orderByComparator);
832    
833                    if (assetLink != null) {
834                            return assetLink;
835                    }
836    
837                    StringBundler msg = new StringBundler(4);
838    
839                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
840    
841                    msg.append("entryId1=");
842                    msg.append(entryId1);
843    
844                    msg.append(StringPool.CLOSE_CURLY_BRACE);
845    
846                    throw new NoSuchLinkException(msg.toString());
847            }
848    
849            /**
850             * Returns the first asset link in the ordered set where entryId1 = &#63;.
851             *
852             * @param entryId1 the entry id1
853             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
854             * @return the first matching asset link, or <code>null</code> if a matching asset link could not be found
855             * @throws SystemException if a system exception occurred
856             */
857            public AssetLink fetchByE1_First(long entryId1,
858                    OrderByComparator orderByComparator) throws SystemException {
859                    List<AssetLink> list = findByE1(entryId1, 0, 1, orderByComparator);
860    
861                    if (!list.isEmpty()) {
862                            return list.get(0);
863                    }
864    
865                    return null;
866            }
867    
868            /**
869             * Returns the last asset link in the ordered set where entryId1 = &#63;.
870             *
871             * @param entryId1 the entry id1
872             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
873             * @return the last matching asset link
874             * @throws com.liferay.portlet.asset.NoSuchLinkException if a matching asset link could not be found
875             * @throws SystemException if a system exception occurred
876             */
877            public AssetLink findByE1_Last(long entryId1,
878                    OrderByComparator orderByComparator)
879                    throws NoSuchLinkException, SystemException {
880                    AssetLink assetLink = fetchByE1_Last(entryId1, orderByComparator);
881    
882                    if (assetLink != null) {
883                            return assetLink;
884                    }
885    
886                    StringBundler msg = new StringBundler(4);
887    
888                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
889    
890                    msg.append("entryId1=");
891                    msg.append(entryId1);
892    
893                    msg.append(StringPool.CLOSE_CURLY_BRACE);
894    
895                    throw new NoSuchLinkException(msg.toString());
896            }
897    
898            /**
899             * Returns the last asset link in the ordered set where entryId1 = &#63;.
900             *
901             * @param entryId1 the entry id1
902             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
903             * @return the last matching asset link, or <code>null</code> if a matching asset link could not be found
904             * @throws SystemException if a system exception occurred
905             */
906            public AssetLink fetchByE1_Last(long entryId1,
907                    OrderByComparator orderByComparator) throws SystemException {
908                    int count = countByE1(entryId1);
909    
910                    List<AssetLink> list = findByE1(entryId1, count - 1, count,
911                                    orderByComparator);
912    
913                    if (!list.isEmpty()) {
914                            return list.get(0);
915                    }
916    
917                    return null;
918            }
919    
920            /**
921             * Returns the asset links before and after the current asset link in the ordered set where entryId1 = &#63;.
922             *
923             * @param linkId the primary key of the current asset link
924             * @param entryId1 the entry id1
925             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
926             * @return the previous, current, and next asset link
927             * @throws com.liferay.portlet.asset.NoSuchLinkException if a asset link with the primary key could not be found
928             * @throws SystemException if a system exception occurred
929             */
930            public AssetLink[] findByE1_PrevAndNext(long linkId, long entryId1,
931                    OrderByComparator orderByComparator)
932                    throws NoSuchLinkException, SystemException {
933                    AssetLink assetLink = findByPrimaryKey(linkId);
934    
935                    Session session = null;
936    
937                    try {
938                            session = openSession();
939    
940                            AssetLink[] array = new AssetLinkImpl[3];
941    
942                            array[0] = getByE1_PrevAndNext(session, assetLink, entryId1,
943                                            orderByComparator, true);
944    
945                            array[1] = assetLink;
946    
947                            array[2] = getByE1_PrevAndNext(session, assetLink, entryId1,
948                                            orderByComparator, false);
949    
950                            return array;
951                    }
952                    catch (Exception e) {
953                            throw processException(e);
954                    }
955                    finally {
956                            closeSession(session);
957                    }
958            }
959    
960            protected AssetLink getByE1_PrevAndNext(Session session,
961                    AssetLink assetLink, long entryId1,
962                    OrderByComparator orderByComparator, boolean previous) {
963                    StringBundler query = null;
964    
965                    if (orderByComparator != null) {
966                            query = new StringBundler(6 +
967                                            (orderByComparator.getOrderByFields().length * 6));
968                    }
969                    else {
970                            query = new StringBundler(3);
971                    }
972    
973                    query.append(_SQL_SELECT_ASSETLINK_WHERE);
974    
975                    query.append(_FINDER_COLUMN_E1_ENTRYID1_2);
976    
977                    if (orderByComparator != null) {
978                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
979    
980                            if (orderByConditionFields.length > 0) {
981                                    query.append(WHERE_AND);
982                            }
983    
984                            for (int i = 0; i < orderByConditionFields.length; i++) {
985                                    query.append(_ORDER_BY_ENTITY_ALIAS);
986                                    query.append(orderByConditionFields[i]);
987    
988                                    if ((i + 1) < orderByConditionFields.length) {
989                                            if (orderByComparator.isAscending() ^ previous) {
990                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
991                                            }
992                                            else {
993                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
994                                            }
995                                    }
996                                    else {
997                                            if (orderByComparator.isAscending() ^ previous) {
998                                                    query.append(WHERE_GREATER_THAN);
999                                            }
1000                                            else {
1001                                                    query.append(WHERE_LESSER_THAN);
1002                                            }
1003                                    }
1004                            }
1005    
1006                            query.append(ORDER_BY_CLAUSE);
1007    
1008                            String[] orderByFields = orderByComparator.getOrderByFields();
1009    
1010                            for (int i = 0; i < orderByFields.length; i++) {
1011                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1012                                    query.append(orderByFields[i]);
1013    
1014                                    if ((i + 1) < orderByFields.length) {
1015                                            if (orderByComparator.isAscending() ^ previous) {
1016                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1017                                            }
1018                                            else {
1019                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1020                                            }
1021                                    }
1022                                    else {
1023                                            if (orderByComparator.isAscending() ^ previous) {
1024                                                    query.append(ORDER_BY_ASC);
1025                                            }
1026                                            else {
1027                                                    query.append(ORDER_BY_DESC);
1028                                            }
1029                                    }
1030                            }
1031                    }
1032    
1033                    else {
1034                            query.append(AssetLinkModelImpl.ORDER_BY_JPQL);
1035                    }
1036    
1037                    String sql = query.toString();
1038    
1039                    Query q = session.createQuery(sql);
1040    
1041                    q.setFirstResult(0);
1042                    q.setMaxResults(2);
1043    
1044                    QueryPos qPos = QueryPos.getInstance(q);
1045    
1046                    qPos.add(entryId1);
1047    
1048                    if (orderByComparator != null) {
1049                            Object[] values = orderByComparator.getOrderByConditionValues(assetLink);
1050    
1051                            for (Object value : values) {
1052                                    qPos.add(value);
1053                            }
1054                    }
1055    
1056                    List<AssetLink> list = q.list();
1057    
1058                    if (list.size() == 2) {
1059                            return list.get(1);
1060                    }
1061                    else {
1062                            return null;
1063                    }
1064            }
1065    
1066            /**
1067             * Returns all the asset links where entryId2 = &#63;.
1068             *
1069             * @param entryId2 the entry id2
1070             * @return the matching asset links
1071             * @throws SystemException if a system exception occurred
1072             */
1073            public List<AssetLink> findByE2(long entryId2) throws SystemException {
1074                    return findByE2(entryId2, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1075            }
1076    
1077            /**
1078             * Returns a range of all the asset links where entryId2 = &#63;.
1079             *
1080             * <p>
1081             * 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.
1082             * </p>
1083             *
1084             * @param entryId2 the entry id2
1085             * @param start the lower bound of the range of asset links
1086             * @param end the upper bound of the range of asset links (not inclusive)
1087             * @return the range of matching asset links
1088             * @throws SystemException if a system exception occurred
1089             */
1090            public List<AssetLink> findByE2(long entryId2, int start, int end)
1091                    throws SystemException {
1092                    return findByE2(entryId2, start, end, null);
1093            }
1094    
1095            /**
1096             * Returns an ordered range of all the asset links where entryId2 = &#63;.
1097             *
1098             * <p>
1099             * 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.
1100             * </p>
1101             *
1102             * @param entryId2 the entry id2
1103             * @param start the lower bound of the range of asset links
1104             * @param end the upper bound of the range of asset links (not inclusive)
1105             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1106             * @return the ordered range of matching asset links
1107             * @throws SystemException if a system exception occurred
1108             */
1109            public List<AssetLink> findByE2(long entryId2, int start, int end,
1110                    OrderByComparator orderByComparator) throws SystemException {
1111                    FinderPath finderPath = null;
1112                    Object[] finderArgs = null;
1113    
1114                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1115                                    (orderByComparator == null)) {
1116                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_E2;
1117                            finderArgs = new Object[] { entryId2 };
1118                    }
1119                    else {
1120                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_E2;
1121                            finderArgs = new Object[] { entryId2, start, end, orderByComparator };
1122                    }
1123    
1124                    List<AssetLink> list = (List<AssetLink>)FinderCacheUtil.getResult(finderPath,
1125                                    finderArgs, this);
1126    
1127                    if ((list != null) && !list.isEmpty()) {
1128                            for (AssetLink assetLink : list) {
1129                                    if ((entryId2 != assetLink.getEntryId2())) {
1130                                            list = null;
1131    
1132                                            break;
1133                                    }
1134                            }
1135                    }
1136    
1137                    if (list == null) {
1138                            StringBundler query = null;
1139    
1140                            if (orderByComparator != null) {
1141                                    query = new StringBundler(3 +
1142                                                    (orderByComparator.getOrderByFields().length * 3));
1143                            }
1144                            else {
1145                                    query = new StringBundler(3);
1146                            }
1147    
1148                            query.append(_SQL_SELECT_ASSETLINK_WHERE);
1149    
1150                            query.append(_FINDER_COLUMN_E2_ENTRYID2_2);
1151    
1152                            if (orderByComparator != null) {
1153                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1154                                            orderByComparator);
1155                            }
1156    
1157                            else {
1158                                    query.append(AssetLinkModelImpl.ORDER_BY_JPQL);
1159                            }
1160    
1161                            String sql = query.toString();
1162    
1163                            Session session = null;
1164    
1165                            try {
1166                                    session = openSession();
1167    
1168                                    Query q = session.createQuery(sql);
1169    
1170                                    QueryPos qPos = QueryPos.getInstance(q);
1171    
1172                                    qPos.add(entryId2);
1173    
1174                                    list = (List<AssetLink>)QueryUtil.list(q, getDialect(), start,
1175                                                    end);
1176                            }
1177                            catch (Exception e) {
1178                                    throw processException(e);
1179                            }
1180                            finally {
1181                                    if (list == null) {
1182                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1183                                    }
1184                                    else {
1185                                            cacheResult(list);
1186    
1187                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1188                                    }
1189    
1190                                    closeSession(session);
1191                            }
1192                    }
1193    
1194                    return list;
1195            }
1196    
1197            /**
1198             * Returns the first asset link in the ordered set where entryId2 = &#63;.
1199             *
1200             * @param entryId2 the entry id2
1201             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1202             * @return the first matching asset link
1203             * @throws com.liferay.portlet.asset.NoSuchLinkException if a matching asset link could not be found
1204             * @throws SystemException if a system exception occurred
1205             */
1206            public AssetLink findByE2_First(long entryId2,
1207                    OrderByComparator orderByComparator)
1208                    throws NoSuchLinkException, SystemException {
1209                    AssetLink assetLink = fetchByE2_First(entryId2, orderByComparator);
1210    
1211                    if (assetLink != null) {
1212                            return assetLink;
1213                    }
1214    
1215                    StringBundler msg = new StringBundler(4);
1216    
1217                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1218    
1219                    msg.append("entryId2=");
1220                    msg.append(entryId2);
1221    
1222                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1223    
1224                    throw new NoSuchLinkException(msg.toString());
1225            }
1226    
1227            /**
1228             * Returns the first asset link in the ordered set where entryId2 = &#63;.
1229             *
1230             * @param entryId2 the entry id2
1231             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1232             * @return the first matching asset link, or <code>null</code> if a matching asset link could not be found
1233             * @throws SystemException if a system exception occurred
1234             */
1235            public AssetLink fetchByE2_First(long entryId2,
1236                    OrderByComparator orderByComparator) throws SystemException {
1237                    List<AssetLink> list = findByE2(entryId2, 0, 1, orderByComparator);
1238    
1239                    if (!list.isEmpty()) {
1240                            return list.get(0);
1241                    }
1242    
1243                    return null;
1244            }
1245    
1246            /**
1247             * Returns the last asset link in the ordered set where entryId2 = &#63;.
1248             *
1249             * @param entryId2 the entry id2
1250             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1251             * @return the last matching asset link
1252             * @throws com.liferay.portlet.asset.NoSuchLinkException if a matching asset link could not be found
1253             * @throws SystemException if a system exception occurred
1254             */
1255            public AssetLink findByE2_Last(long entryId2,
1256                    OrderByComparator orderByComparator)
1257                    throws NoSuchLinkException, SystemException {
1258                    AssetLink assetLink = fetchByE2_Last(entryId2, orderByComparator);
1259    
1260                    if (assetLink != null) {
1261                            return assetLink;
1262                    }
1263    
1264                    StringBundler msg = new StringBundler(4);
1265    
1266                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1267    
1268                    msg.append("entryId2=");
1269                    msg.append(entryId2);
1270    
1271                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1272    
1273                    throw new NoSuchLinkException(msg.toString());
1274            }
1275    
1276            /**
1277             * Returns the last asset link in the ordered set where entryId2 = &#63;.
1278             *
1279             * @param entryId2 the entry id2
1280             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1281             * @return the last matching asset link, or <code>null</code> if a matching asset link could not be found
1282             * @throws SystemException if a system exception occurred
1283             */
1284            public AssetLink fetchByE2_Last(long entryId2,
1285                    OrderByComparator orderByComparator) throws SystemException {
1286                    int count = countByE2(entryId2);
1287    
1288                    List<AssetLink> list = findByE2(entryId2, count - 1, count,
1289                                    orderByComparator);
1290    
1291                    if (!list.isEmpty()) {
1292                            return list.get(0);
1293                    }
1294    
1295                    return null;
1296            }
1297    
1298            /**
1299             * Returns the asset links before and after the current asset link in the ordered set where entryId2 = &#63;.
1300             *
1301             * @param linkId the primary key of the current asset link
1302             * @param entryId2 the entry id2
1303             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1304             * @return the previous, current, and next asset link
1305             * @throws com.liferay.portlet.asset.NoSuchLinkException if a asset link with the primary key could not be found
1306             * @throws SystemException if a system exception occurred
1307             */
1308            public AssetLink[] findByE2_PrevAndNext(long linkId, long entryId2,
1309                    OrderByComparator orderByComparator)
1310                    throws NoSuchLinkException, SystemException {
1311                    AssetLink assetLink = findByPrimaryKey(linkId);
1312    
1313                    Session session = null;
1314    
1315                    try {
1316                            session = openSession();
1317    
1318                            AssetLink[] array = new AssetLinkImpl[3];
1319    
1320                            array[0] = getByE2_PrevAndNext(session, assetLink, entryId2,
1321                                            orderByComparator, true);
1322    
1323                            array[1] = assetLink;
1324    
1325                            array[2] = getByE2_PrevAndNext(session, assetLink, entryId2,
1326                                            orderByComparator, false);
1327    
1328                            return array;
1329                    }
1330                    catch (Exception e) {
1331                            throw processException(e);
1332                    }
1333                    finally {
1334                            closeSession(session);
1335                    }
1336            }
1337    
1338            protected AssetLink getByE2_PrevAndNext(Session session,
1339                    AssetLink assetLink, long entryId2,
1340                    OrderByComparator orderByComparator, boolean previous) {
1341                    StringBundler query = null;
1342    
1343                    if (orderByComparator != null) {
1344                            query = new StringBundler(6 +
1345                                            (orderByComparator.getOrderByFields().length * 6));
1346                    }
1347                    else {
1348                            query = new StringBundler(3);
1349                    }
1350    
1351                    query.append(_SQL_SELECT_ASSETLINK_WHERE);
1352    
1353                    query.append(_FINDER_COLUMN_E2_ENTRYID2_2);
1354    
1355                    if (orderByComparator != null) {
1356                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1357    
1358                            if (orderByConditionFields.length > 0) {
1359                                    query.append(WHERE_AND);
1360                            }
1361    
1362                            for (int i = 0; i < orderByConditionFields.length; i++) {
1363                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1364                                    query.append(orderByConditionFields[i]);
1365    
1366                                    if ((i + 1) < orderByConditionFields.length) {
1367                                            if (orderByComparator.isAscending() ^ previous) {
1368                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1369                                            }
1370                                            else {
1371                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1372                                            }
1373                                    }
1374                                    else {
1375                                            if (orderByComparator.isAscending() ^ previous) {
1376                                                    query.append(WHERE_GREATER_THAN);
1377                                            }
1378                                            else {
1379                                                    query.append(WHERE_LESSER_THAN);
1380                                            }
1381                                    }
1382                            }
1383    
1384                            query.append(ORDER_BY_CLAUSE);
1385    
1386                            String[] orderByFields = orderByComparator.getOrderByFields();
1387    
1388                            for (int i = 0; i < orderByFields.length; i++) {
1389                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1390                                    query.append(orderByFields[i]);
1391    
1392                                    if ((i + 1) < orderByFields.length) {
1393                                            if (orderByComparator.isAscending() ^ previous) {
1394                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1395                                            }
1396                                            else {
1397                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1398                                            }
1399                                    }
1400                                    else {
1401                                            if (orderByComparator.isAscending() ^ previous) {
1402                                                    query.append(ORDER_BY_ASC);
1403                                            }
1404                                            else {
1405                                                    query.append(ORDER_BY_DESC);
1406                                            }
1407                                    }
1408                            }
1409                    }
1410    
1411                    else {
1412                            query.append(AssetLinkModelImpl.ORDER_BY_JPQL);
1413                    }
1414    
1415                    String sql = query.toString();
1416    
1417                    Query q = session.createQuery(sql);
1418    
1419                    q.setFirstResult(0);
1420                    q.setMaxResults(2);
1421    
1422                    QueryPos qPos = QueryPos.getInstance(q);
1423    
1424                    qPos.add(entryId2);
1425    
1426                    if (orderByComparator != null) {
1427                            Object[] values = orderByComparator.getOrderByConditionValues(assetLink);
1428    
1429                            for (Object value : values) {
1430                                    qPos.add(value);
1431                            }
1432                    }
1433    
1434                    List<AssetLink> list = q.list();
1435    
1436                    if (list.size() == 2) {
1437                            return list.get(1);
1438                    }
1439                    else {
1440                            return null;
1441                    }
1442            }
1443    
1444            /**
1445             * Returns all the asset links where entryId1 = &#63; and entryId2 = &#63;.
1446             *
1447             * @param entryId1 the entry id1
1448             * @param entryId2 the entry id2
1449             * @return the matching asset links
1450             * @throws SystemException if a system exception occurred
1451             */
1452            public List<AssetLink> findByE_E(long entryId1, long entryId2)
1453                    throws SystemException {
1454                    return findByE_E(entryId1, entryId2, QueryUtil.ALL_POS,
1455                            QueryUtil.ALL_POS, null);
1456            }
1457    
1458            /**
1459             * Returns a range of all the asset links where entryId1 = &#63; and entryId2 = &#63;.
1460             *
1461             * <p>
1462             * 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.
1463             * </p>
1464             *
1465             * @param entryId1 the entry id1
1466             * @param entryId2 the entry id2
1467             * @param start the lower bound of the range of asset links
1468             * @param end the upper bound of the range of asset links (not inclusive)
1469             * @return the range of matching asset links
1470             * @throws SystemException if a system exception occurred
1471             */
1472            public List<AssetLink> findByE_E(long entryId1, long entryId2, int start,
1473                    int end) throws SystemException {
1474                    return findByE_E(entryId1, entryId2, start, end, null);
1475            }
1476    
1477            /**
1478             * Returns an ordered range of all the asset links where entryId1 = &#63; and entryId2 = &#63;.
1479             *
1480             * <p>
1481             * 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.
1482             * </p>
1483             *
1484             * @param entryId1 the entry id1
1485             * @param entryId2 the entry id2
1486             * @param start the lower bound of the range of asset links
1487             * @param end the upper bound of the range of asset links (not inclusive)
1488             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1489             * @return the ordered range of matching asset links
1490             * @throws SystemException if a system exception occurred
1491             */
1492            public List<AssetLink> findByE_E(long entryId1, long entryId2, int start,
1493                    int end, OrderByComparator orderByComparator) throws SystemException {
1494                    FinderPath finderPath = null;
1495                    Object[] finderArgs = null;
1496    
1497                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1498                                    (orderByComparator == null)) {
1499                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_E_E;
1500                            finderArgs = new Object[] { entryId1, entryId2 };
1501                    }
1502                    else {
1503                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_E_E;
1504                            finderArgs = new Object[] {
1505                                            entryId1, entryId2,
1506                                            
1507                                            start, end, orderByComparator
1508                                    };
1509                    }
1510    
1511                    List<AssetLink> list = (List<AssetLink>)FinderCacheUtil.getResult(finderPath,
1512                                    finderArgs, this);
1513    
1514                    if ((list != null) && !list.isEmpty()) {
1515                            for (AssetLink assetLink : list) {
1516                                    if ((entryId1 != assetLink.getEntryId1()) ||
1517                                                    (entryId2 != assetLink.getEntryId2())) {
1518                                            list = null;
1519    
1520                                            break;
1521                                    }
1522                            }
1523                    }
1524    
1525                    if (list == null) {
1526                            StringBundler query = null;
1527    
1528                            if (orderByComparator != null) {
1529                                    query = new StringBundler(4 +
1530                                                    (orderByComparator.getOrderByFields().length * 3));
1531                            }
1532                            else {
1533                                    query = new StringBundler(4);
1534                            }
1535    
1536                            query.append(_SQL_SELECT_ASSETLINK_WHERE);
1537    
1538                            query.append(_FINDER_COLUMN_E_E_ENTRYID1_2);
1539    
1540                            query.append(_FINDER_COLUMN_E_E_ENTRYID2_2);
1541    
1542                            if (orderByComparator != null) {
1543                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1544                                            orderByComparator);
1545                            }
1546    
1547                            else {
1548                                    query.append(AssetLinkModelImpl.ORDER_BY_JPQL);
1549                            }
1550    
1551                            String sql = query.toString();
1552    
1553                            Session session = null;
1554    
1555                            try {
1556                                    session = openSession();
1557    
1558                                    Query q = session.createQuery(sql);
1559    
1560                                    QueryPos qPos = QueryPos.getInstance(q);
1561    
1562                                    qPos.add(entryId1);
1563    
1564                                    qPos.add(entryId2);
1565    
1566                                    list = (List<AssetLink>)QueryUtil.list(q, getDialect(), start,
1567                                                    end);
1568                            }
1569                            catch (Exception e) {
1570                                    throw processException(e);
1571                            }
1572                            finally {
1573                                    if (list == null) {
1574                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1575                                    }
1576                                    else {
1577                                            cacheResult(list);
1578    
1579                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1580                                    }
1581    
1582                                    closeSession(session);
1583                            }
1584                    }
1585    
1586                    return list;
1587            }
1588    
1589            /**
1590             * Returns the first asset link in the ordered set where entryId1 = &#63; and entryId2 = &#63;.
1591             *
1592             * @param entryId1 the entry id1
1593             * @param entryId2 the entry id2
1594             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1595             * @return the first matching asset link
1596             * @throws com.liferay.portlet.asset.NoSuchLinkException if a matching asset link could not be found
1597             * @throws SystemException if a system exception occurred
1598             */
1599            public AssetLink findByE_E_First(long entryId1, long entryId2,
1600                    OrderByComparator orderByComparator)
1601                    throws NoSuchLinkException, SystemException {
1602                    AssetLink assetLink = fetchByE_E_First(entryId1, entryId2,
1603                                    orderByComparator);
1604    
1605                    if (assetLink != null) {
1606                            return assetLink;
1607                    }
1608    
1609                    StringBundler msg = new StringBundler(6);
1610    
1611                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1612    
1613                    msg.append("entryId1=");
1614                    msg.append(entryId1);
1615    
1616                    msg.append(", entryId2=");
1617                    msg.append(entryId2);
1618    
1619                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1620    
1621                    throw new NoSuchLinkException(msg.toString());
1622            }
1623    
1624            /**
1625             * Returns the first asset link in the ordered set where entryId1 = &#63; and entryId2 = &#63;.
1626             *
1627             * @param entryId1 the entry id1
1628             * @param entryId2 the entry id2
1629             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1630             * @return the first matching asset link, or <code>null</code> if a matching asset link could not be found
1631             * @throws SystemException if a system exception occurred
1632             */
1633            public AssetLink fetchByE_E_First(long entryId1, long entryId2,
1634                    OrderByComparator orderByComparator) throws SystemException {
1635                    List<AssetLink> list = findByE_E(entryId1, entryId2, 0, 1,
1636                                    orderByComparator);
1637    
1638                    if (!list.isEmpty()) {
1639                            return list.get(0);
1640                    }
1641    
1642                    return null;
1643            }
1644    
1645            /**
1646             * Returns the last asset link in the ordered set where entryId1 = &#63; and entryId2 = &#63;.
1647             *
1648             * @param entryId1 the entry id1
1649             * @param entryId2 the entry id2
1650             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1651             * @return the last matching asset link
1652             * @throws com.liferay.portlet.asset.NoSuchLinkException if a matching asset link could not be found
1653             * @throws SystemException if a system exception occurred
1654             */
1655            public AssetLink findByE_E_Last(long entryId1, long entryId2,
1656                    OrderByComparator orderByComparator)
1657                    throws NoSuchLinkException, SystemException {
1658                    AssetLink assetLink = fetchByE_E_Last(entryId1, entryId2,
1659                                    orderByComparator);
1660    
1661                    if (assetLink != null) {
1662                            return assetLink;
1663                    }
1664    
1665                    StringBundler msg = new StringBundler(6);
1666    
1667                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1668    
1669                    msg.append("entryId1=");
1670                    msg.append(entryId1);
1671    
1672                    msg.append(", entryId2=");
1673                    msg.append(entryId2);
1674    
1675                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1676    
1677                    throw new NoSuchLinkException(msg.toString());
1678            }
1679    
1680            /**
1681             * Returns the last asset link in the ordered set where entryId1 = &#63; and entryId2 = &#63;.
1682             *
1683             * @param entryId1 the entry id1
1684             * @param entryId2 the entry id2
1685             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1686             * @return the last matching asset link, or <code>null</code> if a matching asset link could not be found
1687             * @throws SystemException if a system exception occurred
1688             */
1689            public AssetLink fetchByE_E_Last(long entryId1, long entryId2,
1690                    OrderByComparator orderByComparator) throws SystemException {
1691                    int count = countByE_E(entryId1, entryId2);
1692    
1693                    List<AssetLink> list = findByE_E(entryId1, entryId2, count - 1, count,
1694                                    orderByComparator);
1695    
1696                    if (!list.isEmpty()) {
1697                            return list.get(0);
1698                    }
1699    
1700                    return null;
1701            }
1702    
1703            /**
1704             * Returns the asset links before and after the current asset link in the ordered set where entryId1 = &#63; and entryId2 = &#63;.
1705             *
1706             * @param linkId the primary key of the current asset link
1707             * @param entryId1 the entry id1
1708             * @param entryId2 the entry id2
1709             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1710             * @return the previous, current, and next asset link
1711             * @throws com.liferay.portlet.asset.NoSuchLinkException if a asset link with the primary key could not be found
1712             * @throws SystemException if a system exception occurred
1713             */
1714            public AssetLink[] findByE_E_PrevAndNext(long linkId, long entryId1,
1715                    long entryId2, OrderByComparator orderByComparator)
1716                    throws NoSuchLinkException, SystemException {
1717                    AssetLink assetLink = findByPrimaryKey(linkId);
1718    
1719                    Session session = null;
1720    
1721                    try {
1722                            session = openSession();
1723    
1724                            AssetLink[] array = new AssetLinkImpl[3];
1725    
1726                            array[0] = getByE_E_PrevAndNext(session, assetLink, entryId1,
1727                                            entryId2, orderByComparator, true);
1728    
1729                            array[1] = assetLink;
1730    
1731                            array[2] = getByE_E_PrevAndNext(session, assetLink, entryId1,
1732                                            entryId2, orderByComparator, false);
1733    
1734                            return array;
1735                    }
1736                    catch (Exception e) {
1737                            throw processException(e);
1738                    }
1739                    finally {
1740                            closeSession(session);
1741                    }
1742            }
1743    
1744            protected AssetLink getByE_E_PrevAndNext(Session session,
1745                    AssetLink assetLink, long entryId1, long entryId2,
1746                    OrderByComparator orderByComparator, boolean previous) {
1747                    StringBundler query = null;
1748    
1749                    if (orderByComparator != null) {
1750                            query = new StringBundler(6 +
1751                                            (orderByComparator.getOrderByFields().length * 6));
1752                    }
1753                    else {
1754                            query = new StringBundler(3);
1755                    }
1756    
1757                    query.append(_SQL_SELECT_ASSETLINK_WHERE);
1758    
1759                    query.append(_FINDER_COLUMN_E_E_ENTRYID1_2);
1760    
1761                    query.append(_FINDER_COLUMN_E_E_ENTRYID2_2);
1762    
1763                    if (orderByComparator != null) {
1764                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1765    
1766                            if (orderByConditionFields.length > 0) {
1767                                    query.append(WHERE_AND);
1768                            }
1769    
1770                            for (int i = 0; i < orderByConditionFields.length; i++) {
1771                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1772                                    query.append(orderByConditionFields[i]);
1773    
1774                                    if ((i + 1) < orderByConditionFields.length) {
1775                                            if (orderByComparator.isAscending() ^ previous) {
1776                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1777                                            }
1778                                            else {
1779                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1780                                            }
1781                                    }
1782                                    else {
1783                                            if (orderByComparator.isAscending() ^ previous) {
1784                                                    query.append(WHERE_GREATER_THAN);
1785                                            }
1786                                            else {
1787                                                    query.append(WHERE_LESSER_THAN);
1788                                            }
1789                                    }
1790                            }
1791    
1792                            query.append(ORDER_BY_CLAUSE);
1793    
1794                            String[] orderByFields = orderByComparator.getOrderByFields();
1795    
1796                            for (int i = 0; i < orderByFields.length; i++) {
1797                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1798                                    query.append(orderByFields[i]);
1799    
1800                                    if ((i + 1) < orderByFields.length) {
1801                                            if (orderByComparator.isAscending() ^ previous) {
1802                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1803                                            }
1804                                            else {
1805                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1806                                            }
1807                                    }
1808                                    else {
1809                                            if (orderByComparator.isAscending() ^ previous) {
1810                                                    query.append(ORDER_BY_ASC);
1811                                            }
1812                                            else {
1813                                                    query.append(ORDER_BY_DESC);
1814                                            }
1815                                    }
1816                            }
1817                    }
1818    
1819                    else {
1820                            query.append(AssetLinkModelImpl.ORDER_BY_JPQL);
1821                    }
1822    
1823                    String sql = query.toString();
1824    
1825                    Query q = session.createQuery(sql);
1826    
1827                    q.setFirstResult(0);
1828                    q.setMaxResults(2);
1829    
1830                    QueryPos qPos = QueryPos.getInstance(q);
1831    
1832                    qPos.add(entryId1);
1833    
1834                    qPos.add(entryId2);
1835    
1836                    if (orderByComparator != null) {
1837                            Object[] values = orderByComparator.getOrderByConditionValues(assetLink);
1838    
1839                            for (Object value : values) {
1840                                    qPos.add(value);
1841                            }
1842                    }
1843    
1844                    List<AssetLink> list = q.list();
1845    
1846                    if (list.size() == 2) {
1847                            return list.get(1);
1848                    }
1849                    else {
1850                            return null;
1851                    }
1852            }
1853    
1854            /**
1855             * Returns all the asset links where entryId1 = &#63; and type = &#63;.
1856             *
1857             * @param entryId1 the entry id1
1858             * @param type the type
1859             * @return the matching asset links
1860             * @throws SystemException if a system exception occurred
1861             */
1862            public List<AssetLink> findByE1_T(long entryId1, int type)
1863                    throws SystemException {
1864                    return findByE1_T(entryId1, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1865                            null);
1866            }
1867    
1868            /**
1869             * Returns a range of all the asset links where entryId1 = &#63; and type = &#63;.
1870             *
1871             * <p>
1872             * 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.
1873             * </p>
1874             *
1875             * @param entryId1 the entry id1
1876             * @param type the type
1877             * @param start the lower bound of the range of asset links
1878             * @param end the upper bound of the range of asset links (not inclusive)
1879             * @return the range of matching asset links
1880             * @throws SystemException if a system exception occurred
1881             */
1882            public List<AssetLink> findByE1_T(long entryId1, int type, int start,
1883                    int end) throws SystemException {
1884                    return findByE1_T(entryId1, type, start, end, null);
1885            }
1886    
1887            /**
1888             * Returns an ordered range of all the asset links where entryId1 = &#63; and type = &#63;.
1889             *
1890             * <p>
1891             * 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.
1892             * </p>
1893             *
1894             * @param entryId1 the entry id1
1895             * @param type the type
1896             * @param start the lower bound of the range of asset links
1897             * @param end the upper bound of the range of asset links (not inclusive)
1898             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1899             * @return the ordered range of matching asset links
1900             * @throws SystemException if a system exception occurred
1901             */
1902            public List<AssetLink> findByE1_T(long entryId1, int type, int start,
1903                    int end, OrderByComparator orderByComparator) throws SystemException {
1904                    FinderPath finderPath = null;
1905                    Object[] finderArgs = null;
1906    
1907                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1908                                    (orderByComparator == null)) {
1909                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_E1_T;
1910                            finderArgs = new Object[] { entryId1, type };
1911                    }
1912                    else {
1913                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_E1_T;
1914                            finderArgs = new Object[] {
1915                                            entryId1, type,
1916                                            
1917                                            start, end, orderByComparator
1918                                    };
1919                    }
1920    
1921                    List<AssetLink> list = (List<AssetLink>)FinderCacheUtil.getResult(finderPath,
1922                                    finderArgs, this);
1923    
1924                    if ((list != null) && !list.isEmpty()) {
1925                            for (AssetLink assetLink : list) {
1926                                    if ((entryId1 != assetLink.getEntryId1()) ||
1927                                                    (type != assetLink.getType())) {
1928                                            list = null;
1929    
1930                                            break;
1931                                    }
1932                            }
1933                    }
1934    
1935                    if (list == null) {
1936                            StringBundler query = null;
1937    
1938                            if (orderByComparator != null) {
1939                                    query = new StringBundler(4 +
1940                                                    (orderByComparator.getOrderByFields().length * 3));
1941                            }
1942                            else {
1943                                    query = new StringBundler(4);
1944                            }
1945    
1946                            query.append(_SQL_SELECT_ASSETLINK_WHERE);
1947    
1948                            query.append(_FINDER_COLUMN_E1_T_ENTRYID1_2);
1949    
1950                            query.append(_FINDER_COLUMN_E1_T_TYPE_2);
1951    
1952                            if (orderByComparator != null) {
1953                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1954                                            orderByComparator);
1955                            }
1956    
1957                            else {
1958                                    query.append(AssetLinkModelImpl.ORDER_BY_JPQL);
1959                            }
1960    
1961                            String sql = query.toString();
1962    
1963                            Session session = null;
1964    
1965                            try {
1966                                    session = openSession();
1967    
1968                                    Query q = session.createQuery(sql);
1969    
1970                                    QueryPos qPos = QueryPos.getInstance(q);
1971    
1972                                    qPos.add(entryId1);
1973    
1974                                    qPos.add(type);
1975    
1976                                    list = (List<AssetLink>)QueryUtil.list(q, getDialect(), start,
1977                                                    end);
1978                            }
1979                            catch (Exception e) {
1980                                    throw processException(e);
1981                            }
1982                            finally {
1983                                    if (list == null) {
1984                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1985                                    }
1986                                    else {
1987                                            cacheResult(list);
1988    
1989                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1990                                    }
1991    
1992                                    closeSession(session);
1993                            }
1994                    }
1995    
1996                    return list;
1997            }
1998    
1999            /**
2000             * Returns the first asset link in the ordered set where entryId1 = &#63; and type = &#63;.
2001             *
2002             * @param entryId1 the entry id1
2003             * @param type the type
2004             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2005             * @return the first matching asset link
2006             * @throws com.liferay.portlet.asset.NoSuchLinkException if a matching asset link could not be found
2007             * @throws SystemException if a system exception occurred
2008             */
2009            public AssetLink findByE1_T_First(long entryId1, int type,
2010                    OrderByComparator orderByComparator)
2011                    throws NoSuchLinkException, SystemException {
2012                    AssetLink assetLink = fetchByE1_T_First(entryId1, type,
2013                                    orderByComparator);
2014    
2015                    if (assetLink != null) {
2016                            return assetLink;
2017                    }
2018    
2019                    StringBundler msg = new StringBundler(6);
2020    
2021                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2022    
2023                    msg.append("entryId1=");
2024                    msg.append(entryId1);
2025    
2026                    msg.append(", type=");
2027                    msg.append(type);
2028    
2029                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2030    
2031                    throw new NoSuchLinkException(msg.toString());
2032            }
2033    
2034            /**
2035             * Returns the first asset link in the ordered set where entryId1 = &#63; and type = &#63;.
2036             *
2037             * @param entryId1 the entry id1
2038             * @param type the type
2039             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2040             * @return the first matching asset link, or <code>null</code> if a matching asset link could not be found
2041             * @throws SystemException if a system exception occurred
2042             */
2043            public AssetLink fetchByE1_T_First(long entryId1, int type,
2044                    OrderByComparator orderByComparator) throws SystemException {
2045                    List<AssetLink> list = findByE1_T(entryId1, type, 0, 1,
2046                                    orderByComparator);
2047    
2048                    if (!list.isEmpty()) {
2049                            return list.get(0);
2050                    }
2051    
2052                    return null;
2053            }
2054    
2055            /**
2056             * Returns the last asset link in the ordered set where entryId1 = &#63; and type = &#63;.
2057             *
2058             * @param entryId1 the entry id1
2059             * @param type the type
2060             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2061             * @return the last matching asset link
2062             * @throws com.liferay.portlet.asset.NoSuchLinkException if a matching asset link could not be found
2063             * @throws SystemException if a system exception occurred
2064             */
2065            public AssetLink findByE1_T_Last(long entryId1, int type,
2066                    OrderByComparator orderByComparator)
2067                    throws NoSuchLinkException, SystemException {
2068                    AssetLink assetLink = fetchByE1_T_Last(entryId1, type, orderByComparator);
2069    
2070                    if (assetLink != null) {
2071                            return assetLink;
2072                    }
2073    
2074                    StringBundler msg = new StringBundler(6);
2075    
2076                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2077    
2078                    msg.append("entryId1=");
2079                    msg.append(entryId1);
2080    
2081                    msg.append(", type=");
2082                    msg.append(type);
2083    
2084                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2085    
2086                    throw new NoSuchLinkException(msg.toString());
2087            }
2088    
2089            /**
2090             * Returns the last asset link in the ordered set where entryId1 = &#63; and type = &#63;.
2091             *
2092             * @param entryId1 the entry id1
2093             * @param type the type
2094             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2095             * @return the last matching asset link, or <code>null</code> if a matching asset link could not be found
2096             * @throws SystemException if a system exception occurred
2097             */
2098            public AssetLink fetchByE1_T_Last(long entryId1, int type,
2099                    OrderByComparator orderByComparator) throws SystemException {
2100                    int count = countByE1_T(entryId1, type);
2101    
2102                    List<AssetLink> list = findByE1_T(entryId1, type, count - 1, count,
2103                                    orderByComparator);
2104    
2105                    if (!list.isEmpty()) {
2106                            return list.get(0);
2107                    }
2108    
2109                    return null;
2110            }
2111    
2112            /**
2113             * Returns the asset links before and after the current asset link in the ordered set where entryId1 = &#63; and type = &#63;.
2114             *
2115             * @param linkId the primary key of the current asset link
2116             * @param entryId1 the entry id1
2117             * @param type the type
2118             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2119             * @return the previous, current, and next asset link
2120             * @throws com.liferay.portlet.asset.NoSuchLinkException if a asset link with the primary key could not be found
2121             * @throws SystemException if a system exception occurred
2122             */
2123            public AssetLink[] findByE1_T_PrevAndNext(long linkId, long entryId1,
2124                    int type, OrderByComparator orderByComparator)
2125                    throws NoSuchLinkException, SystemException {
2126                    AssetLink assetLink = findByPrimaryKey(linkId);
2127    
2128                    Session session = null;
2129    
2130                    try {
2131                            session = openSession();
2132    
2133                            AssetLink[] array = new AssetLinkImpl[3];
2134    
2135                            array[0] = getByE1_T_PrevAndNext(session, assetLink, entryId1,
2136                                            type, orderByComparator, true);
2137    
2138                            array[1] = assetLink;
2139    
2140                            array[2] = getByE1_T_PrevAndNext(session, assetLink, entryId1,
2141                                            type, orderByComparator, false);
2142    
2143                            return array;
2144                    }
2145                    catch (Exception e) {
2146                            throw processException(e);
2147                    }
2148                    finally {
2149                            closeSession(session);
2150                    }
2151            }
2152    
2153            protected AssetLink getByE1_T_PrevAndNext(Session session,
2154                    AssetLink assetLink, long entryId1, int type,
2155                    OrderByComparator orderByComparator, boolean previous) {
2156                    StringBundler query = null;
2157    
2158                    if (orderByComparator != null) {
2159                            query = new StringBundler(6 +
2160                                            (orderByComparator.getOrderByFields().length * 6));
2161                    }
2162                    else {
2163                            query = new StringBundler(3);
2164                    }
2165    
2166                    query.append(_SQL_SELECT_ASSETLINK_WHERE);
2167    
2168                    query.append(_FINDER_COLUMN_E1_T_ENTRYID1_2);
2169    
2170                    query.append(_FINDER_COLUMN_E1_T_TYPE_2);
2171    
2172                    if (orderByComparator != null) {
2173                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2174    
2175                            if (orderByConditionFields.length > 0) {
2176                                    query.append(WHERE_AND);
2177                            }
2178    
2179                            for (int i = 0; i < orderByConditionFields.length; i++) {
2180                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2181                                    query.append(orderByConditionFields[i]);
2182    
2183                                    if ((i + 1) < orderByConditionFields.length) {
2184                                            if (orderByComparator.isAscending() ^ previous) {
2185                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2186                                            }
2187                                            else {
2188                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2189                                            }
2190                                    }
2191                                    else {
2192                                            if (orderByComparator.isAscending() ^ previous) {
2193                                                    query.append(WHERE_GREATER_THAN);
2194                                            }
2195                                            else {
2196                                                    query.append(WHERE_LESSER_THAN);
2197                                            }
2198                                    }
2199                            }
2200    
2201                            query.append(ORDER_BY_CLAUSE);
2202    
2203                            String[] orderByFields = orderByComparator.getOrderByFields();
2204    
2205                            for (int i = 0; i < orderByFields.length; i++) {
2206                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2207                                    query.append(orderByFields[i]);
2208    
2209                                    if ((i + 1) < orderByFields.length) {
2210                                            if (orderByComparator.isAscending() ^ previous) {
2211                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2212                                            }
2213                                            else {
2214                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2215                                            }
2216                                    }
2217                                    else {
2218                                            if (orderByComparator.isAscending() ^ previous) {
2219                                                    query.append(ORDER_BY_ASC);
2220                                            }
2221                                            else {
2222                                                    query.append(ORDER_BY_DESC);
2223                                            }
2224                                    }
2225                            }
2226                    }
2227    
2228                    else {
2229                            query.append(AssetLinkModelImpl.ORDER_BY_JPQL);
2230                    }
2231    
2232                    String sql = query.toString();
2233    
2234                    Query q = session.createQuery(sql);
2235    
2236                    q.setFirstResult(0);
2237                    q.setMaxResults(2);
2238    
2239                    QueryPos qPos = QueryPos.getInstance(q);
2240    
2241                    qPos.add(entryId1);
2242    
2243                    qPos.add(type);
2244    
2245                    if (orderByComparator != null) {
2246                            Object[] values = orderByComparator.getOrderByConditionValues(assetLink);
2247    
2248                            for (Object value : values) {
2249                                    qPos.add(value);
2250                            }
2251                    }
2252    
2253                    List<AssetLink> list = q.list();
2254    
2255                    if (list.size() == 2) {
2256                            return list.get(1);
2257                    }
2258                    else {
2259                            return null;
2260                    }
2261            }
2262    
2263            /**
2264             * Returns all the asset links where entryId2 = &#63; and type = &#63;.
2265             *
2266             * @param entryId2 the entry id2
2267             * @param type the type
2268             * @return the matching asset links
2269             * @throws SystemException if a system exception occurred
2270             */
2271            public List<AssetLink> findByE2_T(long entryId2, int type)
2272                    throws SystemException {
2273                    return findByE2_T(entryId2, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2274                            null);
2275            }
2276    
2277            /**
2278             * Returns a range of all the asset links where entryId2 = &#63; and type = &#63;.
2279             *
2280             * <p>
2281             * 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.
2282             * </p>
2283             *
2284             * @param entryId2 the entry id2
2285             * @param type the type
2286             * @param start the lower bound of the range of asset links
2287             * @param end the upper bound of the range of asset links (not inclusive)
2288             * @return the range of matching asset links
2289             * @throws SystemException if a system exception occurred
2290             */
2291            public List<AssetLink> findByE2_T(long entryId2, int type, int start,
2292                    int end) throws SystemException {
2293                    return findByE2_T(entryId2, type, start, end, null);
2294            }
2295    
2296            /**
2297             * Returns an ordered range of all the asset links where entryId2 = &#63; and type = &#63;.
2298             *
2299             * <p>
2300             * 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.
2301             * </p>
2302             *
2303             * @param entryId2 the entry id2
2304             * @param type the type
2305             * @param start the lower bound of the range of asset links
2306             * @param end the upper bound of the range of asset links (not inclusive)
2307             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2308             * @return the ordered range of matching asset links
2309             * @throws SystemException if a system exception occurred
2310             */
2311            public List<AssetLink> findByE2_T(long entryId2, int type, int start,
2312                    int end, OrderByComparator orderByComparator) throws SystemException {
2313                    FinderPath finderPath = null;
2314                    Object[] finderArgs = null;
2315    
2316                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2317                                    (orderByComparator == null)) {
2318                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_E2_T;
2319                            finderArgs = new Object[] { entryId2, type };
2320                    }
2321                    else {
2322                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_E2_T;
2323                            finderArgs = new Object[] {
2324                                            entryId2, type,
2325                                            
2326                                            start, end, orderByComparator
2327                                    };
2328                    }
2329    
2330                    List<AssetLink> list = (List<AssetLink>)FinderCacheUtil.getResult(finderPath,
2331                                    finderArgs, this);
2332    
2333                    if ((list != null) && !list.isEmpty()) {
2334                            for (AssetLink assetLink : list) {
2335                                    if ((entryId2 != assetLink.getEntryId2()) ||
2336                                                    (type != assetLink.getType())) {
2337                                            list = null;
2338    
2339                                            break;
2340                                    }
2341                            }
2342                    }
2343    
2344                    if (list == null) {
2345                            StringBundler query = null;
2346    
2347                            if (orderByComparator != null) {
2348                                    query = new StringBundler(4 +
2349                                                    (orderByComparator.getOrderByFields().length * 3));
2350                            }
2351                            else {
2352                                    query = new StringBundler(4);
2353                            }
2354    
2355                            query.append(_SQL_SELECT_ASSETLINK_WHERE);
2356    
2357                            query.append(_FINDER_COLUMN_E2_T_ENTRYID2_2);
2358    
2359                            query.append(_FINDER_COLUMN_E2_T_TYPE_2);
2360    
2361                            if (orderByComparator != null) {
2362                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2363                                            orderByComparator);
2364                            }
2365    
2366                            else {
2367                                    query.append(AssetLinkModelImpl.ORDER_BY_JPQL);
2368                            }
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(entryId2);
2382    
2383                                    qPos.add(type);
2384    
2385                                    list = (List<AssetLink>)QueryUtil.list(q, getDialect(), start,
2386                                                    end);
2387                            }
2388                            catch (Exception e) {
2389                                    throw processException(e);
2390                            }
2391                            finally {
2392                                    if (list == null) {
2393                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2394                                    }
2395                                    else {
2396                                            cacheResult(list);
2397    
2398                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2399                                    }
2400    
2401                                    closeSession(session);
2402                            }
2403                    }
2404    
2405                    return list;
2406            }
2407    
2408            /**
2409             * Returns the first asset link in the ordered set where entryId2 = &#63; and type = &#63;.
2410             *
2411             * @param entryId2 the entry id2
2412             * @param type the type
2413             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2414             * @return the first matching asset link
2415             * @throws com.liferay.portlet.asset.NoSuchLinkException if a matching asset link could not be found
2416             * @throws SystemException if a system exception occurred
2417             */
2418            public AssetLink findByE2_T_First(long entryId2, int type,
2419                    OrderByComparator orderByComparator)
2420                    throws NoSuchLinkException, SystemException {
2421                    AssetLink assetLink = fetchByE2_T_First(entryId2, type,
2422                                    orderByComparator);
2423    
2424                    if (assetLink != null) {
2425                            return assetLink;
2426                    }
2427    
2428                    StringBundler msg = new StringBundler(6);
2429    
2430                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2431    
2432                    msg.append("entryId2=");
2433                    msg.append(entryId2);
2434    
2435                    msg.append(", type=");
2436                    msg.append(type);
2437    
2438                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2439    
2440                    throw new NoSuchLinkException(msg.toString());
2441            }
2442    
2443            /**
2444             * Returns the first asset link in the ordered set where entryId2 = &#63; and type = &#63;.
2445             *
2446             * @param entryId2 the entry id2
2447             * @param type the type
2448             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2449             * @return the first matching asset link, or <code>null</code> if a matching asset link could not be found
2450             * @throws SystemException if a system exception occurred
2451             */
2452            public AssetLink fetchByE2_T_First(long entryId2, int type,
2453                    OrderByComparator orderByComparator) throws SystemException {
2454                    List<AssetLink> list = findByE2_T(entryId2, type, 0, 1,
2455                                    orderByComparator);
2456    
2457                    if (!list.isEmpty()) {
2458                            return list.get(0);
2459                    }
2460    
2461                    return null;
2462            }
2463    
2464            /**
2465             * Returns the last asset link in the ordered set where entryId2 = &#63; and type = &#63;.
2466             *
2467             * @param entryId2 the entry id2
2468             * @param type the type
2469             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2470             * @return the last matching asset link
2471             * @throws com.liferay.portlet.asset.NoSuchLinkException if a matching asset link could not be found
2472             * @throws SystemException if a system exception occurred
2473             */
2474            public AssetLink findByE2_T_Last(long entryId2, int type,
2475                    OrderByComparator orderByComparator)
2476                    throws NoSuchLinkException, SystemException {
2477                    AssetLink assetLink = fetchByE2_T_Last(entryId2, type, orderByComparator);
2478    
2479                    if (assetLink != null) {
2480                            return assetLink;
2481                    }
2482    
2483                    StringBundler msg = new StringBundler(6);
2484    
2485                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2486    
2487                    msg.append("entryId2=");
2488                    msg.append(entryId2);
2489    
2490                    msg.append(", type=");
2491                    msg.append(type);
2492    
2493                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2494    
2495                    throw new NoSuchLinkException(msg.toString());
2496            }
2497    
2498            /**
2499             * Returns the last asset link in the ordered set where entryId2 = &#63; and type = &#63;.
2500             *
2501             * @param entryId2 the entry id2
2502             * @param type the type
2503             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2504             * @return the last matching asset link, or <code>null</code> if a matching asset link could not be found
2505             * @throws SystemException if a system exception occurred
2506             */
2507            public AssetLink fetchByE2_T_Last(long entryId2, int type,
2508                    OrderByComparator orderByComparator) throws SystemException {
2509                    int count = countByE2_T(entryId2, type);
2510    
2511                    List<AssetLink> list = findByE2_T(entryId2, type, count - 1, count,
2512                                    orderByComparator);
2513    
2514                    if (!list.isEmpty()) {
2515                            return list.get(0);
2516                    }
2517    
2518                    return null;
2519            }
2520    
2521            /**
2522             * Returns the asset links before and after the current asset link in the ordered set where entryId2 = &#63; and type = &#63;.
2523             *
2524             * @param linkId the primary key of the current asset link
2525             * @param entryId2 the entry id2
2526             * @param type the type
2527             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2528             * @return the previous, current, and next asset link
2529             * @throws com.liferay.portlet.asset.NoSuchLinkException if a asset link with the primary key could not be found
2530             * @throws SystemException if a system exception occurred
2531             */
2532            public AssetLink[] findByE2_T_PrevAndNext(long linkId, long entryId2,
2533                    int type, OrderByComparator orderByComparator)
2534                    throws NoSuchLinkException, SystemException {
2535                    AssetLink assetLink = findByPrimaryKey(linkId);
2536    
2537                    Session session = null;
2538    
2539                    try {
2540                            session = openSession();
2541    
2542                            AssetLink[] array = new AssetLinkImpl[3];
2543    
2544                            array[0] = getByE2_T_PrevAndNext(session, assetLink, entryId2,
2545                                            type, orderByComparator, true);
2546    
2547                            array[1] = assetLink;
2548    
2549                            array[2] = getByE2_T_PrevAndNext(session, assetLink, entryId2,
2550                                            type, orderByComparator, false);
2551    
2552                            return array;
2553                    }
2554                    catch (Exception e) {
2555                            throw processException(e);
2556                    }
2557                    finally {
2558                            closeSession(session);
2559                    }
2560            }
2561    
2562            protected AssetLink getByE2_T_PrevAndNext(Session session,
2563                    AssetLink assetLink, long entryId2, int type,
2564                    OrderByComparator orderByComparator, boolean previous) {
2565                    StringBundler query = null;
2566    
2567                    if (orderByComparator != null) {
2568                            query = new StringBundler(6 +
2569                                            (orderByComparator.getOrderByFields().length * 6));
2570                    }
2571                    else {
2572                            query = new StringBundler(3);
2573                    }
2574    
2575                    query.append(_SQL_SELECT_ASSETLINK_WHERE);
2576    
2577                    query.append(_FINDER_COLUMN_E2_T_ENTRYID2_2);
2578    
2579                    query.append(_FINDER_COLUMN_E2_T_TYPE_2);
2580    
2581                    if (orderByComparator != null) {
2582                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2583    
2584                            if (orderByConditionFields.length > 0) {
2585                                    query.append(WHERE_AND);
2586                            }
2587    
2588                            for (int i = 0; i < orderByConditionFields.length; i++) {
2589                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2590                                    query.append(orderByConditionFields[i]);
2591    
2592                                    if ((i + 1) < orderByConditionFields.length) {
2593                                            if (orderByComparator.isAscending() ^ previous) {
2594                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2595                                            }
2596                                            else {
2597                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2598                                            }
2599                                    }
2600                                    else {
2601                                            if (orderByComparator.isAscending() ^ previous) {
2602                                                    query.append(WHERE_GREATER_THAN);
2603                                            }
2604                                            else {
2605                                                    query.append(WHERE_LESSER_THAN);
2606                                            }
2607                                    }
2608                            }
2609    
2610                            query.append(ORDER_BY_CLAUSE);
2611    
2612                            String[] orderByFields = orderByComparator.getOrderByFields();
2613    
2614                            for (int i = 0; i < orderByFields.length; i++) {
2615                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2616                                    query.append(orderByFields[i]);
2617    
2618                                    if ((i + 1) < orderByFields.length) {
2619                                            if (orderByComparator.isAscending() ^ previous) {
2620                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2621                                            }
2622                                            else {
2623                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2624                                            }
2625                                    }
2626                                    else {
2627                                            if (orderByComparator.isAscending() ^ previous) {
2628                                                    query.append(ORDER_BY_ASC);
2629                                            }
2630                                            else {
2631                                                    query.append(ORDER_BY_DESC);
2632                                            }
2633                                    }
2634                            }
2635                    }
2636    
2637                    else {
2638                            query.append(AssetLinkModelImpl.ORDER_BY_JPQL);
2639                    }
2640    
2641                    String sql = query.toString();
2642    
2643                    Query q = session.createQuery(sql);
2644    
2645                    q.setFirstResult(0);
2646                    q.setMaxResults(2);
2647    
2648                    QueryPos qPos = QueryPos.getInstance(q);
2649    
2650                    qPos.add(entryId2);
2651    
2652                    qPos.add(type);
2653    
2654                    if (orderByComparator != null) {
2655                            Object[] values = orderByComparator.getOrderByConditionValues(assetLink);
2656    
2657                            for (Object value : values) {
2658                                    qPos.add(value);
2659                            }
2660                    }
2661    
2662                    List<AssetLink> list = q.list();
2663    
2664                    if (list.size() == 2) {
2665                            return list.get(1);
2666                    }
2667                    else {
2668                            return null;
2669                    }
2670            }
2671    
2672            /**
2673             * Returns the asset link where entryId1 = &#63; and entryId2 = &#63; and type = &#63; or throws a {@link com.liferay.portlet.asset.NoSuchLinkException} if it could not be found.
2674             *
2675             * @param entryId1 the entry id1
2676             * @param entryId2 the entry id2
2677             * @param type the type
2678             * @return the matching asset link
2679             * @throws com.liferay.portlet.asset.NoSuchLinkException if a matching asset link could not be found
2680             * @throws SystemException if a system exception occurred
2681             */
2682            public AssetLink findByE_E_T(long entryId1, long entryId2, int type)
2683                    throws NoSuchLinkException, SystemException {
2684                    AssetLink assetLink = fetchByE_E_T(entryId1, entryId2, type);
2685    
2686                    if (assetLink == null) {
2687                            StringBundler msg = new StringBundler(8);
2688    
2689                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2690    
2691                            msg.append("entryId1=");
2692                            msg.append(entryId1);
2693    
2694                            msg.append(", entryId2=");
2695                            msg.append(entryId2);
2696    
2697                            msg.append(", type=");
2698                            msg.append(type);
2699    
2700                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2701    
2702                            if (_log.isWarnEnabled()) {
2703                                    _log.warn(msg.toString());
2704                            }
2705    
2706                            throw new NoSuchLinkException(msg.toString());
2707                    }
2708    
2709                    return assetLink;
2710            }
2711    
2712            /**
2713             * Returns the asset link where entryId1 = &#63; and entryId2 = &#63; and type = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
2714             *
2715             * @param entryId1 the entry id1
2716             * @param entryId2 the entry id2
2717             * @param type the type
2718             * @return the matching asset link, or <code>null</code> if a matching asset link could not be found
2719             * @throws SystemException if a system exception occurred
2720             */
2721            public AssetLink fetchByE_E_T(long entryId1, long entryId2, int type)
2722                    throws SystemException {
2723                    return fetchByE_E_T(entryId1, entryId2, type, true);
2724            }
2725    
2726            /**
2727             * Returns the asset link where entryId1 = &#63; and entryId2 = &#63; and type = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
2728             *
2729             * @param entryId1 the entry id1
2730             * @param entryId2 the entry id2
2731             * @param type the type
2732             * @param retrieveFromCache whether to use the finder cache
2733             * @return the matching asset link, or <code>null</code> if a matching asset link could not be found
2734             * @throws SystemException if a system exception occurred
2735             */
2736            public AssetLink fetchByE_E_T(long entryId1, long entryId2, int type,
2737                    boolean retrieveFromCache) throws SystemException {
2738                    Object[] finderArgs = new Object[] { entryId1, entryId2, type };
2739    
2740                    Object result = null;
2741    
2742                    if (retrieveFromCache) {
2743                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_E_E_T,
2744                                            finderArgs, this);
2745                    }
2746    
2747                    if (result instanceof AssetLink) {
2748                            AssetLink assetLink = (AssetLink)result;
2749    
2750                            if ((entryId1 != assetLink.getEntryId1()) ||
2751                                            (entryId2 != assetLink.getEntryId2()) ||
2752                                            (type != assetLink.getType())) {
2753                                    result = null;
2754                            }
2755                    }
2756    
2757                    if (result == null) {
2758                            StringBundler query = new StringBundler(5);
2759    
2760                            query.append(_SQL_SELECT_ASSETLINK_WHERE);
2761    
2762                            query.append(_FINDER_COLUMN_E_E_T_ENTRYID1_2);
2763    
2764                            query.append(_FINDER_COLUMN_E_E_T_ENTRYID2_2);
2765    
2766                            query.append(_FINDER_COLUMN_E_E_T_TYPE_2);
2767    
2768                            query.append(AssetLinkModelImpl.ORDER_BY_JPQL);
2769    
2770                            String sql = query.toString();
2771    
2772                            Session session = null;
2773    
2774                            try {
2775                                    session = openSession();
2776    
2777                                    Query q = session.createQuery(sql);
2778    
2779                                    QueryPos qPos = QueryPos.getInstance(q);
2780    
2781                                    qPos.add(entryId1);
2782    
2783                                    qPos.add(entryId2);
2784    
2785                                    qPos.add(type);
2786    
2787                                    List<AssetLink> list = q.list();
2788    
2789                                    result = list;
2790    
2791                                    AssetLink assetLink = null;
2792    
2793                                    if (list.isEmpty()) {
2794                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_E_E_T,
2795                                                    finderArgs, list);
2796                                    }
2797                                    else {
2798                                            assetLink = list.get(0);
2799    
2800                                            cacheResult(assetLink);
2801    
2802                                            if ((assetLink.getEntryId1() != entryId1) ||
2803                                                            (assetLink.getEntryId2() != entryId2) ||
2804                                                            (assetLink.getType() != type)) {
2805                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_E_E_T,
2806                                                            finderArgs, assetLink);
2807                                            }
2808                                    }
2809    
2810                                    return assetLink;
2811                            }
2812                            catch (Exception e) {
2813                                    throw processException(e);
2814                            }
2815                            finally {
2816                                    if (result == null) {
2817                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_E_E_T,
2818                                                    finderArgs);
2819                                    }
2820    
2821                                    closeSession(session);
2822                            }
2823                    }
2824                    else {
2825                            if (result instanceof List<?>) {
2826                                    return null;
2827                            }
2828                            else {
2829                                    return (AssetLink)result;
2830                            }
2831                    }
2832            }
2833    
2834            /**
2835             * Returns all the asset links.
2836             *
2837             * @return the asset links
2838             * @throws SystemException if a system exception occurred
2839             */
2840            public List<AssetLink> findAll() throws SystemException {
2841                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2842            }
2843    
2844            /**
2845             * Returns a range of all the asset links.
2846             *
2847             * <p>
2848             * 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.
2849             * </p>
2850             *
2851             * @param start the lower bound of the range of asset links
2852             * @param end the upper bound of the range of asset links (not inclusive)
2853             * @return the range of asset links
2854             * @throws SystemException if a system exception occurred
2855             */
2856            public List<AssetLink> findAll(int start, int end)
2857                    throws SystemException {
2858                    return findAll(start, end, null);
2859            }
2860    
2861            /**
2862             * Returns an ordered range of all the asset links.
2863             *
2864             * <p>
2865             * 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.
2866             * </p>
2867             *
2868             * @param start the lower bound of the range of asset links
2869             * @param end the upper bound of the range of asset links (not inclusive)
2870             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2871             * @return the ordered range of asset links
2872             * @throws SystemException if a system exception occurred
2873             */
2874            public List<AssetLink> findAll(int start, int end,
2875                    OrderByComparator orderByComparator) throws SystemException {
2876                    FinderPath finderPath = null;
2877                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
2878    
2879                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2880                                    (orderByComparator == null)) {
2881                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2882                            finderArgs = FINDER_ARGS_EMPTY;
2883                    }
2884                    else {
2885                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2886                            finderArgs = new Object[] { start, end, orderByComparator };
2887                    }
2888    
2889                    List<AssetLink> list = (List<AssetLink>)FinderCacheUtil.getResult(finderPath,
2890                                    finderArgs, this);
2891    
2892                    if (list == null) {
2893                            StringBundler query = null;
2894                            String sql = null;
2895    
2896                            if (orderByComparator != null) {
2897                                    query = new StringBundler(2 +
2898                                                    (orderByComparator.getOrderByFields().length * 3));
2899    
2900                                    query.append(_SQL_SELECT_ASSETLINK);
2901    
2902                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2903                                            orderByComparator);
2904    
2905                                    sql = query.toString();
2906                            }
2907                            else {
2908                                    sql = _SQL_SELECT_ASSETLINK.concat(AssetLinkModelImpl.ORDER_BY_JPQL);
2909                            }
2910    
2911                            Session session = null;
2912    
2913                            try {
2914                                    session = openSession();
2915    
2916                                    Query q = session.createQuery(sql);
2917    
2918                                    if (orderByComparator == null) {
2919                                            list = (List<AssetLink>)QueryUtil.list(q, getDialect(),
2920                                                            start, end, false);
2921    
2922                                            Collections.sort(list);
2923                                    }
2924                                    else {
2925                                            list = (List<AssetLink>)QueryUtil.list(q, getDialect(),
2926                                                            start, end);
2927                                    }
2928                            }
2929                            catch (Exception e) {
2930                                    throw processException(e);
2931                            }
2932                            finally {
2933                                    if (list == null) {
2934                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2935                                    }
2936                                    else {
2937                                            cacheResult(list);
2938    
2939                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2940                                    }
2941    
2942                                    closeSession(session);
2943                            }
2944                    }
2945    
2946                    return list;
2947            }
2948    
2949            /**
2950             * Removes all the asset links where entryId1 = &#63; from the database.
2951             *
2952             * @param entryId1 the entry id1
2953             * @throws SystemException if a system exception occurred
2954             */
2955            public void removeByE1(long entryId1) throws SystemException {
2956                    for (AssetLink assetLink : findByE1(entryId1)) {
2957                            remove(assetLink);
2958                    }
2959            }
2960    
2961            /**
2962             * Removes all the asset links where entryId2 = &#63; from the database.
2963             *
2964             * @param entryId2 the entry id2
2965             * @throws SystemException if a system exception occurred
2966             */
2967            public void removeByE2(long entryId2) throws SystemException {
2968                    for (AssetLink assetLink : findByE2(entryId2)) {
2969                            remove(assetLink);
2970                    }
2971            }
2972    
2973            /**
2974             * Removes all the asset links where entryId1 = &#63; and entryId2 = &#63; from the database.
2975             *
2976             * @param entryId1 the entry id1
2977             * @param entryId2 the entry id2
2978             * @throws SystemException if a system exception occurred
2979             */
2980            public void removeByE_E(long entryId1, long entryId2)
2981                    throws SystemException {
2982                    for (AssetLink assetLink : findByE_E(entryId1, entryId2)) {
2983                            remove(assetLink);
2984                    }
2985            }
2986    
2987            /**
2988             * Removes all the asset links where entryId1 = &#63; and type = &#63; from the database.
2989             *
2990             * @param entryId1 the entry id1
2991             * @param type the type
2992             * @throws SystemException if a system exception occurred
2993             */
2994            public void removeByE1_T(long entryId1, int type) throws SystemException {
2995                    for (AssetLink assetLink : findByE1_T(entryId1, type)) {
2996                            remove(assetLink);
2997                    }
2998            }
2999    
3000            /**
3001             * Removes all the asset links where entryId2 = &#63; and type = &#63; from the database.
3002             *
3003             * @param entryId2 the entry id2
3004             * @param type the type
3005             * @throws SystemException if a system exception occurred
3006             */
3007            public void removeByE2_T(long entryId2, int type) throws SystemException {
3008                    for (AssetLink assetLink : findByE2_T(entryId2, type)) {
3009                            remove(assetLink);
3010                    }
3011            }
3012    
3013            /**
3014             * Removes the asset link where entryId1 = &#63; and entryId2 = &#63; and type = &#63; from the database.
3015             *
3016             * @param entryId1 the entry id1
3017             * @param entryId2 the entry id2
3018             * @param type the type
3019             * @return the asset link that was removed
3020             * @throws SystemException if a system exception occurred
3021             */
3022            public AssetLink removeByE_E_T(long entryId1, long entryId2, int type)
3023                    throws NoSuchLinkException, SystemException {
3024                    AssetLink assetLink = findByE_E_T(entryId1, entryId2, type);
3025    
3026                    return remove(assetLink);
3027            }
3028    
3029            /**
3030             * Removes all the asset links from the database.
3031             *
3032             * @throws SystemException if a system exception occurred
3033             */
3034            public void removeAll() throws SystemException {
3035                    for (AssetLink assetLink : findAll()) {
3036                            remove(assetLink);
3037                    }
3038            }
3039    
3040            /**
3041             * Returns the number of asset links where entryId1 = &#63;.
3042             *
3043             * @param entryId1 the entry id1
3044             * @return the number of matching asset links
3045             * @throws SystemException if a system exception occurred
3046             */
3047            public int countByE1(long entryId1) throws SystemException {
3048                    Object[] finderArgs = new Object[] { entryId1 };
3049    
3050                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_E1,
3051                                    finderArgs, this);
3052    
3053                    if (count == null) {
3054                            StringBundler query = new StringBundler(2);
3055    
3056                            query.append(_SQL_COUNT_ASSETLINK_WHERE);
3057    
3058                            query.append(_FINDER_COLUMN_E1_ENTRYID1_2);
3059    
3060                            String sql = query.toString();
3061    
3062                            Session session = null;
3063    
3064                            try {
3065                                    session = openSession();
3066    
3067                                    Query q = session.createQuery(sql);
3068    
3069                                    QueryPos qPos = QueryPos.getInstance(q);
3070    
3071                                    qPos.add(entryId1);
3072    
3073                                    count = (Long)q.uniqueResult();
3074                            }
3075                            catch (Exception e) {
3076                                    throw processException(e);
3077                            }
3078                            finally {
3079                                    if (count == null) {
3080                                            count = Long.valueOf(0);
3081                                    }
3082    
3083                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_E1, finderArgs,
3084                                            count);
3085    
3086                                    closeSession(session);
3087                            }
3088                    }
3089    
3090                    return count.intValue();
3091            }
3092    
3093            /**
3094             * Returns the number of asset links where entryId2 = &#63;.
3095             *
3096             * @param entryId2 the entry id2
3097             * @return the number of matching asset links
3098             * @throws SystemException if a system exception occurred
3099             */
3100            public int countByE2(long entryId2) throws SystemException {
3101                    Object[] finderArgs = new Object[] { entryId2 };
3102    
3103                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_E2,
3104                                    finderArgs, this);
3105    
3106                    if (count == null) {
3107                            StringBundler query = new StringBundler(2);
3108    
3109                            query.append(_SQL_COUNT_ASSETLINK_WHERE);
3110    
3111                            query.append(_FINDER_COLUMN_E2_ENTRYID2_2);
3112    
3113                            String sql = query.toString();
3114    
3115                            Session session = null;
3116    
3117                            try {
3118                                    session = openSession();
3119    
3120                                    Query q = session.createQuery(sql);
3121    
3122                                    QueryPos qPos = QueryPos.getInstance(q);
3123    
3124                                    qPos.add(entryId2);
3125    
3126                                    count = (Long)q.uniqueResult();
3127                            }
3128                            catch (Exception e) {
3129                                    throw processException(e);
3130                            }
3131                            finally {
3132                                    if (count == null) {
3133                                            count = Long.valueOf(0);
3134                                    }
3135    
3136                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_E2, finderArgs,
3137                                            count);
3138    
3139                                    closeSession(session);
3140                            }
3141                    }
3142    
3143                    return count.intValue();
3144            }
3145    
3146            /**
3147             * Returns the number of asset links where entryId1 = &#63; and entryId2 = &#63;.
3148             *
3149             * @param entryId1 the entry id1
3150             * @param entryId2 the entry id2
3151             * @return the number of matching asset links
3152             * @throws SystemException if a system exception occurred
3153             */
3154            public int countByE_E(long entryId1, long entryId2)
3155                    throws SystemException {
3156                    Object[] finderArgs = new Object[] { entryId1, entryId2 };
3157    
3158                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_E_E,
3159                                    finderArgs, this);
3160    
3161                    if (count == null) {
3162                            StringBundler query = new StringBundler(3);
3163    
3164                            query.append(_SQL_COUNT_ASSETLINK_WHERE);
3165    
3166                            query.append(_FINDER_COLUMN_E_E_ENTRYID1_2);
3167    
3168                            query.append(_FINDER_COLUMN_E_E_ENTRYID2_2);
3169    
3170                            String sql = query.toString();
3171    
3172                            Session session = null;
3173    
3174                            try {
3175                                    session = openSession();
3176    
3177                                    Query q = session.createQuery(sql);
3178    
3179                                    QueryPos qPos = QueryPos.getInstance(q);
3180    
3181                                    qPos.add(entryId1);
3182    
3183                                    qPos.add(entryId2);
3184    
3185                                    count = (Long)q.uniqueResult();
3186                            }
3187                            catch (Exception e) {
3188                                    throw processException(e);
3189                            }
3190                            finally {
3191                                    if (count == null) {
3192                                            count = Long.valueOf(0);
3193                                    }
3194    
3195                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_E_E, finderArgs,
3196                                            count);
3197    
3198                                    closeSession(session);
3199                            }
3200                    }
3201    
3202                    return count.intValue();
3203            }
3204    
3205            /**
3206             * Returns the number of asset links where entryId1 = &#63; and type = &#63;.
3207             *
3208             * @param entryId1 the entry id1
3209             * @param type the type
3210             * @return the number of matching asset links
3211             * @throws SystemException if a system exception occurred
3212             */
3213            public int countByE1_T(long entryId1, int type) throws SystemException {
3214                    Object[] finderArgs = new Object[] { entryId1, type };
3215    
3216                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_E1_T,
3217                                    finderArgs, this);
3218    
3219                    if (count == null) {
3220                            StringBundler query = new StringBundler(3);
3221    
3222                            query.append(_SQL_COUNT_ASSETLINK_WHERE);
3223    
3224                            query.append(_FINDER_COLUMN_E1_T_ENTRYID1_2);
3225    
3226                            query.append(_FINDER_COLUMN_E1_T_TYPE_2);
3227    
3228                            String sql = query.toString();
3229    
3230                            Session session = null;
3231    
3232                            try {
3233                                    session = openSession();
3234    
3235                                    Query q = session.createQuery(sql);
3236    
3237                                    QueryPos qPos = QueryPos.getInstance(q);
3238    
3239                                    qPos.add(entryId1);
3240    
3241                                    qPos.add(type);
3242    
3243                                    count = (Long)q.uniqueResult();
3244                            }
3245                            catch (Exception e) {
3246                                    throw processException(e);
3247                            }
3248                            finally {
3249                                    if (count == null) {
3250                                            count = Long.valueOf(0);
3251                                    }
3252    
3253                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_E1_T,
3254                                            finderArgs, count);
3255    
3256                                    closeSession(session);
3257                            }
3258                    }
3259    
3260                    return count.intValue();
3261            }
3262    
3263            /**
3264             * Returns the number of asset links where entryId2 = &#63; and type = &#63;.
3265             *
3266             * @param entryId2 the entry id2
3267             * @param type the type
3268             * @return the number of matching asset links
3269             * @throws SystemException if a system exception occurred
3270             */
3271            public int countByE2_T(long entryId2, int type) throws SystemException {
3272                    Object[] finderArgs = new Object[] { entryId2, type };
3273    
3274                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_E2_T,
3275                                    finderArgs, this);
3276    
3277                    if (count == null) {
3278                            StringBundler query = new StringBundler(3);
3279    
3280                            query.append(_SQL_COUNT_ASSETLINK_WHERE);
3281    
3282                            query.append(_FINDER_COLUMN_E2_T_ENTRYID2_2);
3283    
3284                            query.append(_FINDER_COLUMN_E2_T_TYPE_2);
3285    
3286                            String sql = query.toString();
3287    
3288                            Session session = null;
3289    
3290                            try {
3291                                    session = openSession();
3292    
3293                                    Query q = session.createQuery(sql);
3294    
3295                                    QueryPos qPos = QueryPos.getInstance(q);
3296    
3297                                    qPos.add(entryId2);
3298    
3299                                    qPos.add(type);
3300    
3301                                    count = (Long)q.uniqueResult();
3302                            }
3303                            catch (Exception e) {
3304                                    throw processException(e);
3305                            }
3306                            finally {
3307                                    if (count == null) {
3308                                            count = Long.valueOf(0);
3309                                    }
3310    
3311                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_E2_T,
3312                                            finderArgs, count);
3313    
3314                                    closeSession(session);
3315                            }
3316                    }
3317    
3318                    return count.intValue();
3319            }
3320    
3321            /**
3322             * Returns the number of asset links where entryId1 = &#63; and entryId2 = &#63; and type = &#63;.
3323             *
3324             * @param entryId1 the entry id1
3325             * @param entryId2 the entry id2
3326             * @param type the type
3327             * @return the number of matching asset links
3328             * @throws SystemException if a system exception occurred
3329             */
3330            public int countByE_E_T(long entryId1, long entryId2, int type)
3331                    throws SystemException {
3332                    Object[] finderArgs = new Object[] { entryId1, entryId2, type };
3333    
3334                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_E_E_T,
3335                                    finderArgs, this);
3336    
3337                    if (count == null) {
3338                            StringBundler query = new StringBundler(4);
3339    
3340                            query.append(_SQL_COUNT_ASSETLINK_WHERE);
3341    
3342                            query.append(_FINDER_COLUMN_E_E_T_ENTRYID1_2);
3343    
3344                            query.append(_FINDER_COLUMN_E_E_T_ENTRYID2_2);
3345    
3346                            query.append(_FINDER_COLUMN_E_E_T_TYPE_2);
3347    
3348                            String sql = query.toString();
3349    
3350                            Session session = null;
3351    
3352                            try {
3353                                    session = openSession();
3354    
3355                                    Query q = session.createQuery(sql);
3356    
3357                                    QueryPos qPos = QueryPos.getInstance(q);
3358    
3359                                    qPos.add(entryId1);
3360    
3361                                    qPos.add(entryId2);
3362    
3363                                    qPos.add(type);
3364    
3365                                    count = (Long)q.uniqueResult();
3366                            }
3367                            catch (Exception e) {
3368                                    throw processException(e);
3369                            }
3370                            finally {
3371                                    if (count == null) {
3372                                            count = Long.valueOf(0);
3373                                    }
3374    
3375                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_E_E_T,
3376                                            finderArgs, count);
3377    
3378                                    closeSession(session);
3379                            }
3380                    }
3381    
3382                    return count.intValue();
3383            }
3384    
3385            /**
3386             * Returns the number of asset links.
3387             *
3388             * @return the number of asset links
3389             * @throws SystemException if a system exception occurred
3390             */
3391            public int countAll() throws SystemException {
3392                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3393                                    FINDER_ARGS_EMPTY, this);
3394    
3395                    if (count == null) {
3396                            Session session = null;
3397    
3398                            try {
3399                                    session = openSession();
3400    
3401                                    Query q = session.createQuery(_SQL_COUNT_ASSETLINK);
3402    
3403                                    count = (Long)q.uniqueResult();
3404                            }
3405                            catch (Exception e) {
3406                                    throw processException(e);
3407                            }
3408                            finally {
3409                                    if (count == null) {
3410                                            count = Long.valueOf(0);
3411                                    }
3412    
3413                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
3414                                            FINDER_ARGS_EMPTY, count);
3415    
3416                                    closeSession(session);
3417                            }
3418                    }
3419    
3420                    return count.intValue();
3421            }
3422    
3423            /**
3424             * Initializes the asset link persistence.
3425             */
3426            public void afterPropertiesSet() {
3427                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3428                                            com.liferay.portal.util.PropsUtil.get(
3429                                                    "value.object.listener.com.liferay.portlet.asset.model.AssetLink")));
3430    
3431                    if (listenerClassNames.length > 0) {
3432                            try {
3433                                    List<ModelListener<AssetLink>> listenersList = new ArrayList<ModelListener<AssetLink>>();
3434    
3435                                    for (String listenerClassName : listenerClassNames) {
3436                                            listenersList.add((ModelListener<AssetLink>)InstanceFactory.newInstance(
3437                                                            listenerClassName));
3438                                    }
3439    
3440                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3441                            }
3442                            catch (Exception e) {
3443                                    _log.error(e);
3444                            }
3445                    }
3446            }
3447    
3448            public void destroy() {
3449                    EntityCacheUtil.removeCache(AssetLinkImpl.class.getName());
3450                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
3451                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3452            }
3453    
3454            @BeanReference(type = AssetCategoryPersistence.class)
3455            protected AssetCategoryPersistence assetCategoryPersistence;
3456            @BeanReference(type = AssetCategoryPropertyPersistence.class)
3457            protected AssetCategoryPropertyPersistence assetCategoryPropertyPersistence;
3458            @BeanReference(type = AssetEntryPersistence.class)
3459            protected AssetEntryPersistence assetEntryPersistence;
3460            @BeanReference(type = AssetLinkPersistence.class)
3461            protected AssetLinkPersistence assetLinkPersistence;
3462            @BeanReference(type = AssetTagPersistence.class)
3463            protected AssetTagPersistence assetTagPersistence;
3464            @BeanReference(type = AssetTagPropertyPersistence.class)
3465            protected AssetTagPropertyPersistence assetTagPropertyPersistence;
3466            @BeanReference(type = AssetTagStatsPersistence.class)
3467            protected AssetTagStatsPersistence assetTagStatsPersistence;
3468            @BeanReference(type = AssetVocabularyPersistence.class)
3469            protected AssetVocabularyPersistence assetVocabularyPersistence;
3470            @BeanReference(type = UserPersistence.class)
3471            protected UserPersistence userPersistence;
3472            private static final String _SQL_SELECT_ASSETLINK = "SELECT assetLink FROM AssetLink assetLink";
3473            private static final String _SQL_SELECT_ASSETLINK_WHERE = "SELECT assetLink FROM AssetLink assetLink WHERE ";
3474            private static final String _SQL_COUNT_ASSETLINK = "SELECT COUNT(assetLink) FROM AssetLink assetLink";
3475            private static final String _SQL_COUNT_ASSETLINK_WHERE = "SELECT COUNT(assetLink) FROM AssetLink assetLink WHERE ";
3476            private static final String _FINDER_COLUMN_E1_ENTRYID1_2 = "assetLink.entryId1 = ?";
3477            private static final String _FINDER_COLUMN_E2_ENTRYID2_2 = "assetLink.entryId2 = ?";
3478            private static final String _FINDER_COLUMN_E_E_ENTRYID1_2 = "assetLink.entryId1 = ? AND ";
3479            private static final String _FINDER_COLUMN_E_E_ENTRYID2_2 = "assetLink.entryId2 = ?";
3480            private static final String _FINDER_COLUMN_E1_T_ENTRYID1_2 = "assetLink.entryId1 = ? AND ";
3481            private static final String _FINDER_COLUMN_E1_T_TYPE_2 = "assetLink.type = ?";
3482            private static final String _FINDER_COLUMN_E2_T_ENTRYID2_2 = "assetLink.entryId2 = ? AND ";
3483            private static final String _FINDER_COLUMN_E2_T_TYPE_2 = "assetLink.type = ?";
3484            private static final String _FINDER_COLUMN_E_E_T_ENTRYID1_2 = "assetLink.entryId1 = ? AND ";
3485            private static final String _FINDER_COLUMN_E_E_T_ENTRYID2_2 = "assetLink.entryId2 = ? AND ";
3486            private static final String _FINDER_COLUMN_E_E_T_TYPE_2 = "assetLink.type = ?";
3487            private static final String _ORDER_BY_ENTITY_ALIAS = "assetLink.";
3488            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AssetLink exists with the primary key ";
3489            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AssetLink exists with the key {";
3490            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
3491            private static Log _log = LogFactoryUtil.getLog(AssetLinkPersistenceImpl.class);
3492            private static AssetLink _nullAssetLink = new AssetLinkImpl() {
3493                            @Override
3494                            public Object clone() {
3495                                    return this;
3496                            }
3497    
3498                            @Override
3499                            public CacheModel<AssetLink> toCacheModel() {
3500                                    return _nullAssetLinkCacheModel;
3501                            }
3502                    };
3503    
3504            private static CacheModel<AssetLink> _nullAssetLinkCacheModel = new CacheModel<AssetLink>() {
3505                            public AssetLink toEntityModel() {
3506                                    return _nullAssetLink;
3507                            }
3508                    };
3509    }