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