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