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