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