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