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