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