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