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