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