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