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