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