001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.asset.service.persistence.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.kernel.bean.BeanReference;
020    import com.liferay.portal.kernel.dao.orm.EntityCache;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCache;
023    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
024    import com.liferay.portal.kernel.dao.orm.FinderPath;
025    import com.liferay.portal.kernel.dao.orm.Query;
026    import com.liferay.portal.kernel.dao.orm.QueryPos;
027    import com.liferay.portal.kernel.dao.orm.QueryUtil;
028    import com.liferay.portal.kernel.dao.orm.SQLQuery;
029    import com.liferay.portal.kernel.dao.orm.Session;
030    import com.liferay.portal.kernel.log.Log;
031    import com.liferay.portal.kernel.log.LogFactoryUtil;
032    import com.liferay.portal.kernel.util.ArrayUtil;
033    import com.liferay.portal.kernel.util.CharPool;
034    import com.liferay.portal.kernel.util.OrderByComparator;
035    import com.liferay.portal.kernel.util.SetUtil;
036    import com.liferay.portal.kernel.util.StringBundler;
037    import com.liferay.portal.kernel.util.StringPool;
038    import com.liferay.portal.kernel.util.StringUtil;
039    import com.liferay.portal.kernel.util.Validator;
040    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
041    import com.liferay.portal.model.CacheModel;
042    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
043    import com.liferay.portal.service.ServiceContext;
044    import com.liferay.portal.service.ServiceContextThreadLocal;
045    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
046    import com.liferay.portal.service.persistence.impl.TableMapper;
047    import com.liferay.portal.service.persistence.impl.TableMapperFactory;
048    
049    import com.liferay.portlet.asset.NoSuchTagException;
050    import com.liferay.portlet.asset.model.AssetTag;
051    import com.liferay.portlet.asset.model.impl.AssetTagImpl;
052    import com.liferay.portlet.asset.model.impl.AssetTagModelImpl;
053    import com.liferay.portlet.asset.service.persistence.AssetEntryPersistence;
054    import com.liferay.portlet.asset.service.persistence.AssetTagPersistence;
055    
056    import java.io.Serializable;
057    
058    import java.util.Arrays;
059    import java.util.Collections;
060    import java.util.Date;
061    import java.util.HashMap;
062    import java.util.HashSet;
063    import java.util.Iterator;
064    import java.util.List;
065    import java.util.Map;
066    import java.util.Set;
067    
068    /**
069     * The persistence implementation for the asset tag service.
070     *
071     * <p>
072     * Caching information and settings can be found in <code>portal.properties</code>
073     * </p>
074     *
075     * @author Brian Wing Shun Chan
076     * @see AssetTagPersistence
077     * @see com.liferay.portlet.asset.service.persistence.AssetTagUtil
078     * @generated
079     */
080    @ProviderType
081    public class AssetTagPersistenceImpl extends BasePersistenceImpl<AssetTag>
082            implements AssetTagPersistence {
083            /*
084             * NOTE FOR DEVELOPERS:
085             *
086             * Never modify or reference this class directly. Always use {@link AssetTagUtil} to access the asset tag persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
087             */
088            public static final String FINDER_CLASS_NAME_ENTITY = AssetTagImpl.class.getName();
089            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
090                    ".List1";
091            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
092                    ".List2";
093            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
094                            AssetTagModelImpl.FINDER_CACHE_ENABLED, AssetTagImpl.class,
095                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
096            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
097                            AssetTagModelImpl.FINDER_CACHE_ENABLED, AssetTagImpl.class,
098                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
099            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
100                            AssetTagModelImpl.FINDER_CACHE_ENABLED, Long.class,
101                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
102            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
103                            AssetTagModelImpl.FINDER_CACHE_ENABLED, AssetTagImpl.class,
104                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
105                            new String[] {
106                                    String.class.getName(),
107                                    
108                            Integer.class.getName(), Integer.class.getName(),
109                                    OrderByComparator.class.getName()
110                            });
111            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
112                            AssetTagModelImpl.FINDER_CACHE_ENABLED, AssetTagImpl.class,
113                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
114                            new String[] { String.class.getName() },
115                            AssetTagModelImpl.UUID_COLUMN_BITMASK |
116                            AssetTagModelImpl.NAME_COLUMN_BITMASK);
117            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
118                            AssetTagModelImpl.FINDER_CACHE_ENABLED, Long.class,
119                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
120                            new String[] { String.class.getName() });
121    
122            /**
123             * Returns all the asset tags where uuid = &#63;.
124             *
125             * @param uuid the uuid
126             * @return the matching asset tags
127             */
128            @Override
129            public List<AssetTag> findByUuid(String uuid) {
130                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
131            }
132    
133            /**
134             * Returns a range of all the asset tags where uuid = &#63;.
135             *
136             * <p>
137             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. 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.
138             * </p>
139             *
140             * @param uuid the uuid
141             * @param start the lower bound of the range of asset tags
142             * @param end the upper bound of the range of asset tags (not inclusive)
143             * @return the range of matching asset tags
144             */
145            @Override
146            public List<AssetTag> findByUuid(String uuid, int start, int end) {
147                    return findByUuid(uuid, start, end, null);
148            }
149    
150            /**
151             * Returns an ordered range of all the asset tags where uuid = &#63;.
152             *
153             * <p>
154             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. 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.
155             * </p>
156             *
157             * @param uuid the uuid
158             * @param start the lower bound of the range of asset tags
159             * @param end the upper bound of the range of asset tags (not inclusive)
160             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
161             * @return the ordered range of matching asset tags
162             */
163            @Override
164            public List<AssetTag> findByUuid(String uuid, int start, int end,
165                    OrderByComparator<AssetTag> orderByComparator) {
166                    return findByUuid(uuid, start, end, orderByComparator, true);
167            }
168    
169            /**
170             * Returns an ordered range of all the asset tags where uuid = &#63;.
171             *
172             * <p>
173             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. 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.
174             * </p>
175             *
176             * @param uuid the uuid
177             * @param start the lower bound of the range of asset tags
178             * @param end the upper bound of the range of asset tags (not inclusive)
179             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
180             * @param retrieveFromCache whether to retrieve from the finder cache
181             * @return the ordered range of matching asset tags
182             */
183            @Override
184            public List<AssetTag> findByUuid(String uuid, int start, int end,
185                    OrderByComparator<AssetTag> orderByComparator, boolean retrieveFromCache) {
186                    boolean pagination = true;
187                    FinderPath finderPath = null;
188                    Object[] finderArgs = null;
189    
190                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
191                                    (orderByComparator == null)) {
192                            pagination = false;
193                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
194                            finderArgs = new Object[] { uuid };
195                    }
196                    else {
197                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
198                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
199                    }
200    
201                    List<AssetTag> list = null;
202    
203                    if (retrieveFromCache) {
204                            list = (List<AssetTag>)finderCache.getResult(finderPath,
205                                            finderArgs, this);
206    
207                            if ((list != null) && !list.isEmpty()) {
208                                    for (AssetTag assetTag : list) {
209                                            if (!Validator.equals(uuid, assetTag.getUuid())) {
210                                                    list = null;
211    
212                                                    break;
213                                            }
214                                    }
215                            }
216                    }
217    
218                    if (list == null) {
219                            StringBundler query = null;
220    
221                            if (orderByComparator != null) {
222                                    query = new StringBundler(3 +
223                                                    (orderByComparator.getOrderByFields().length * 3));
224                            }
225                            else {
226                                    query = new StringBundler(3);
227                            }
228    
229                            query.append(_SQL_SELECT_ASSETTAG_WHERE);
230    
231                            boolean bindUuid = false;
232    
233                            if (uuid == null) {
234                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
235                            }
236                            else if (uuid.equals(StringPool.BLANK)) {
237                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
238                            }
239                            else {
240                                    bindUuid = true;
241    
242                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
243                            }
244    
245                            if (orderByComparator != null) {
246                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
247                                            orderByComparator);
248                            }
249                            else
250                             if (pagination) {
251                                    query.append(AssetTagModelImpl.ORDER_BY_JPQL);
252                            }
253    
254                            String sql = query.toString();
255    
256                            Session session = null;
257    
258                            try {
259                                    session = openSession();
260    
261                                    Query q = session.createQuery(sql);
262    
263                                    QueryPos qPos = QueryPos.getInstance(q);
264    
265                                    if (bindUuid) {
266                                            qPos.add(uuid);
267                                    }
268    
269                                    if (!pagination) {
270                                            list = (List<AssetTag>)QueryUtil.list(q, getDialect(),
271                                                            start, end, false);
272    
273                                            Collections.sort(list);
274    
275                                            list = Collections.unmodifiableList(list);
276                                    }
277                                    else {
278                                            list = (List<AssetTag>)QueryUtil.list(q, getDialect(),
279                                                            start, end);
280                                    }
281    
282                                    cacheResult(list);
283    
284                                    finderCache.putResult(finderPath, finderArgs, list);
285                            }
286                            catch (Exception e) {
287                                    finderCache.removeResult(finderPath, finderArgs);
288    
289                                    throw processException(e);
290                            }
291                            finally {
292                                    closeSession(session);
293                            }
294                    }
295    
296                    return list;
297            }
298    
299            /**
300             * Returns the first asset tag in the ordered set where uuid = &#63;.
301             *
302             * @param uuid the uuid
303             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
304             * @return the first matching asset tag
305             * @throws NoSuchTagException if a matching asset tag could not be found
306             */
307            @Override
308            public AssetTag findByUuid_First(String uuid,
309                    OrderByComparator<AssetTag> orderByComparator)
310                    throws NoSuchTagException {
311                    AssetTag assetTag = fetchByUuid_First(uuid, orderByComparator);
312    
313                    if (assetTag != null) {
314                            return assetTag;
315                    }
316    
317                    StringBundler msg = new StringBundler(4);
318    
319                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
320    
321                    msg.append("uuid=");
322                    msg.append(uuid);
323    
324                    msg.append(StringPool.CLOSE_CURLY_BRACE);
325    
326                    throw new NoSuchTagException(msg.toString());
327            }
328    
329            /**
330             * Returns the first asset tag in the ordered set where uuid = &#63;.
331             *
332             * @param uuid the uuid
333             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
334             * @return the first matching asset tag, or <code>null</code> if a matching asset tag could not be found
335             */
336            @Override
337            public AssetTag fetchByUuid_First(String uuid,
338                    OrderByComparator<AssetTag> orderByComparator) {
339                    List<AssetTag> list = findByUuid(uuid, 0, 1, orderByComparator);
340    
341                    if (!list.isEmpty()) {
342                            return list.get(0);
343                    }
344    
345                    return null;
346            }
347    
348            /**
349             * Returns the last asset tag in the ordered set where uuid = &#63;.
350             *
351             * @param uuid the uuid
352             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
353             * @return the last matching asset tag
354             * @throws NoSuchTagException if a matching asset tag could not be found
355             */
356            @Override
357            public AssetTag findByUuid_Last(String uuid,
358                    OrderByComparator<AssetTag> orderByComparator)
359                    throws NoSuchTagException {
360                    AssetTag assetTag = fetchByUuid_Last(uuid, orderByComparator);
361    
362                    if (assetTag != null) {
363                            return assetTag;
364                    }
365    
366                    StringBundler msg = new StringBundler(4);
367    
368                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
369    
370                    msg.append("uuid=");
371                    msg.append(uuid);
372    
373                    msg.append(StringPool.CLOSE_CURLY_BRACE);
374    
375                    throw new NoSuchTagException(msg.toString());
376            }
377    
378            /**
379             * Returns the last asset tag in the ordered set where uuid = &#63;.
380             *
381             * @param uuid the uuid
382             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
383             * @return the last matching asset tag, or <code>null</code> if a matching asset tag could not be found
384             */
385            @Override
386            public AssetTag fetchByUuid_Last(String uuid,
387                    OrderByComparator<AssetTag> orderByComparator) {
388                    int count = countByUuid(uuid);
389    
390                    if (count == 0) {
391                            return null;
392                    }
393    
394                    List<AssetTag> list = findByUuid(uuid, count - 1, count,
395                                    orderByComparator);
396    
397                    if (!list.isEmpty()) {
398                            return list.get(0);
399                    }
400    
401                    return null;
402            }
403    
404            /**
405             * Returns the asset tags before and after the current asset tag in the ordered set where uuid = &#63;.
406             *
407             * @param tagId the primary key of the current asset tag
408             * @param uuid the uuid
409             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
410             * @return the previous, current, and next asset tag
411             * @throws NoSuchTagException if a asset tag with the primary key could not be found
412             */
413            @Override
414            public AssetTag[] findByUuid_PrevAndNext(long tagId, String uuid,
415                    OrderByComparator<AssetTag> orderByComparator)
416                    throws NoSuchTagException {
417                    AssetTag assetTag = findByPrimaryKey(tagId);
418    
419                    Session session = null;
420    
421                    try {
422                            session = openSession();
423    
424                            AssetTag[] array = new AssetTagImpl[3];
425    
426                            array[0] = getByUuid_PrevAndNext(session, assetTag, uuid,
427                                            orderByComparator, true);
428    
429                            array[1] = assetTag;
430    
431                            array[2] = getByUuid_PrevAndNext(session, assetTag, uuid,
432                                            orderByComparator, false);
433    
434                            return array;
435                    }
436                    catch (Exception e) {
437                            throw processException(e);
438                    }
439                    finally {
440                            closeSession(session);
441                    }
442            }
443    
444            protected AssetTag getByUuid_PrevAndNext(Session session,
445                    AssetTag assetTag, String uuid,
446                    OrderByComparator<AssetTag> orderByComparator, boolean previous) {
447                    StringBundler query = null;
448    
449                    if (orderByComparator != null) {
450                            query = new StringBundler(6 +
451                                            (orderByComparator.getOrderByFields().length * 6));
452                    }
453                    else {
454                            query = new StringBundler(3);
455                    }
456    
457                    query.append(_SQL_SELECT_ASSETTAG_WHERE);
458    
459                    boolean bindUuid = false;
460    
461                    if (uuid == null) {
462                            query.append(_FINDER_COLUMN_UUID_UUID_1);
463                    }
464                    else if (uuid.equals(StringPool.BLANK)) {
465                            query.append(_FINDER_COLUMN_UUID_UUID_3);
466                    }
467                    else {
468                            bindUuid = true;
469    
470                            query.append(_FINDER_COLUMN_UUID_UUID_2);
471                    }
472    
473                    if (orderByComparator != null) {
474                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
475    
476                            if (orderByConditionFields.length > 0) {
477                                    query.append(WHERE_AND);
478                            }
479    
480                            for (int i = 0; i < orderByConditionFields.length; i++) {
481                                    query.append(_ORDER_BY_ENTITY_ALIAS);
482                                    query.append(orderByConditionFields[i]);
483    
484                                    if ((i + 1) < orderByConditionFields.length) {
485                                            if (orderByComparator.isAscending() ^ previous) {
486                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
487                                            }
488                                            else {
489                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
490                                            }
491                                    }
492                                    else {
493                                            if (orderByComparator.isAscending() ^ previous) {
494                                                    query.append(WHERE_GREATER_THAN);
495                                            }
496                                            else {
497                                                    query.append(WHERE_LESSER_THAN);
498                                            }
499                                    }
500                            }
501    
502                            query.append(ORDER_BY_CLAUSE);
503    
504                            String[] orderByFields = orderByComparator.getOrderByFields();
505    
506                            for (int i = 0; i < orderByFields.length; i++) {
507                                    query.append(_ORDER_BY_ENTITY_ALIAS);
508                                    query.append(orderByFields[i]);
509    
510                                    if ((i + 1) < orderByFields.length) {
511                                            if (orderByComparator.isAscending() ^ previous) {
512                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
513                                            }
514                                            else {
515                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
516                                            }
517                                    }
518                                    else {
519                                            if (orderByComparator.isAscending() ^ previous) {
520                                                    query.append(ORDER_BY_ASC);
521                                            }
522                                            else {
523                                                    query.append(ORDER_BY_DESC);
524                                            }
525                                    }
526                            }
527                    }
528                    else {
529                            query.append(AssetTagModelImpl.ORDER_BY_JPQL);
530                    }
531    
532                    String sql = query.toString();
533    
534                    Query q = session.createQuery(sql);
535    
536                    q.setFirstResult(0);
537                    q.setMaxResults(2);
538    
539                    QueryPos qPos = QueryPos.getInstance(q);
540    
541                    if (bindUuid) {
542                            qPos.add(uuid);
543                    }
544    
545                    if (orderByComparator != null) {
546                            Object[] values = orderByComparator.getOrderByConditionValues(assetTag);
547    
548                            for (Object value : values) {
549                                    qPos.add(value);
550                            }
551                    }
552    
553                    List<AssetTag> list = q.list();
554    
555                    if (list.size() == 2) {
556                            return list.get(1);
557                    }
558                    else {
559                            return null;
560                    }
561            }
562    
563            /**
564             * Removes all the asset tags where uuid = &#63; from the database.
565             *
566             * @param uuid the uuid
567             */
568            @Override
569            public void removeByUuid(String uuid) {
570                    for (AssetTag assetTag : findByUuid(uuid, QueryUtil.ALL_POS,
571                                    QueryUtil.ALL_POS, null)) {
572                            remove(assetTag);
573                    }
574            }
575    
576            /**
577             * Returns the number of asset tags where uuid = &#63;.
578             *
579             * @param uuid the uuid
580             * @return the number of matching asset tags
581             */
582            @Override
583            public int countByUuid(String uuid) {
584                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
585    
586                    Object[] finderArgs = new Object[] { uuid };
587    
588                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
589    
590                    if (count == null) {
591                            StringBundler query = new StringBundler(2);
592    
593                            query.append(_SQL_COUNT_ASSETTAG_WHERE);
594    
595                            boolean bindUuid = false;
596    
597                            if (uuid == null) {
598                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
599                            }
600                            else if (uuid.equals(StringPool.BLANK)) {
601                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
602                            }
603                            else {
604                                    bindUuid = true;
605    
606                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
607                            }
608    
609                            String sql = query.toString();
610    
611                            Session session = null;
612    
613                            try {
614                                    session = openSession();
615    
616                                    Query q = session.createQuery(sql);
617    
618                                    QueryPos qPos = QueryPos.getInstance(q);
619    
620                                    if (bindUuid) {
621                                            qPos.add(uuid);
622                                    }
623    
624                                    count = (Long)q.uniqueResult();
625    
626                                    finderCache.putResult(finderPath, finderArgs, count);
627                            }
628                            catch (Exception e) {
629                                    finderCache.removeResult(finderPath, finderArgs);
630    
631                                    throw processException(e);
632                            }
633                            finally {
634                                    closeSession(session);
635                            }
636                    }
637    
638                    return count.intValue();
639            }
640    
641            private static final String _FINDER_COLUMN_UUID_UUID_1 = "assetTag.uuid IS NULL";
642            private static final String _FINDER_COLUMN_UUID_UUID_2 = "assetTag.uuid = ?";
643            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(assetTag.uuid IS NULL OR assetTag.uuid = '')";
644            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
645                            AssetTagModelImpl.FINDER_CACHE_ENABLED, AssetTagImpl.class,
646                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
647                            new String[] { String.class.getName(), Long.class.getName() },
648                            AssetTagModelImpl.UUID_COLUMN_BITMASK |
649                            AssetTagModelImpl.GROUPID_COLUMN_BITMASK);
650            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
651                            AssetTagModelImpl.FINDER_CACHE_ENABLED, Long.class,
652                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
653                            new String[] { String.class.getName(), Long.class.getName() });
654    
655            /**
656             * Returns the asset tag where uuid = &#63; and groupId = &#63; or throws a {@link NoSuchTagException} if it could not be found.
657             *
658             * @param uuid the uuid
659             * @param groupId the group ID
660             * @return the matching asset tag
661             * @throws NoSuchTagException if a matching asset tag could not be found
662             */
663            @Override
664            public AssetTag findByUUID_G(String uuid, long groupId)
665                    throws NoSuchTagException {
666                    AssetTag assetTag = fetchByUUID_G(uuid, groupId);
667    
668                    if (assetTag == null) {
669                            StringBundler msg = new StringBundler(6);
670    
671                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
672    
673                            msg.append("uuid=");
674                            msg.append(uuid);
675    
676                            msg.append(", groupId=");
677                            msg.append(groupId);
678    
679                            msg.append(StringPool.CLOSE_CURLY_BRACE);
680    
681                            if (_log.isWarnEnabled()) {
682                                    _log.warn(msg.toString());
683                            }
684    
685                            throw new NoSuchTagException(msg.toString());
686                    }
687    
688                    return assetTag;
689            }
690    
691            /**
692             * Returns the asset tag where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
693             *
694             * @param uuid the uuid
695             * @param groupId the group ID
696             * @return the matching asset tag, or <code>null</code> if a matching asset tag could not be found
697             */
698            @Override
699            public AssetTag fetchByUUID_G(String uuid, long groupId) {
700                    return fetchByUUID_G(uuid, groupId, true);
701            }
702    
703            /**
704             * Returns the asset tag where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
705             *
706             * @param uuid the uuid
707             * @param groupId the group ID
708             * @param retrieveFromCache whether to retrieve from the finder cache
709             * @return the matching asset tag, or <code>null</code> if a matching asset tag could not be found
710             */
711            @Override
712            public AssetTag fetchByUUID_G(String uuid, long groupId,
713                    boolean retrieveFromCache) {
714                    Object[] finderArgs = new Object[] { uuid, groupId };
715    
716                    Object result = null;
717    
718                    if (retrieveFromCache) {
719                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_UUID_G,
720                                            finderArgs, this);
721                    }
722    
723                    if (result instanceof AssetTag) {
724                            AssetTag assetTag = (AssetTag)result;
725    
726                            if (!Validator.equals(uuid, assetTag.getUuid()) ||
727                                            (groupId != assetTag.getGroupId())) {
728                                    result = null;
729                            }
730                    }
731    
732                    if (result == null) {
733                            StringBundler query = new StringBundler(4);
734    
735                            query.append(_SQL_SELECT_ASSETTAG_WHERE);
736    
737                            boolean bindUuid = false;
738    
739                            if (uuid == null) {
740                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
741                            }
742                            else if (uuid.equals(StringPool.BLANK)) {
743                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
744                            }
745                            else {
746                                    bindUuid = true;
747    
748                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
749                            }
750    
751                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
752    
753                            String sql = query.toString();
754    
755                            Session session = null;
756    
757                            try {
758                                    session = openSession();
759    
760                                    Query q = session.createQuery(sql);
761    
762                                    QueryPos qPos = QueryPos.getInstance(q);
763    
764                                    if (bindUuid) {
765                                            qPos.add(uuid);
766                                    }
767    
768                                    qPos.add(groupId);
769    
770                                    List<AssetTag> list = q.list();
771    
772                                    if (list.isEmpty()) {
773                                            finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
774                                                    finderArgs, list);
775                                    }
776                                    else {
777                                            AssetTag assetTag = list.get(0);
778    
779                                            result = assetTag;
780    
781                                            cacheResult(assetTag);
782    
783                                            if ((assetTag.getUuid() == null) ||
784                                                            !assetTag.getUuid().equals(uuid) ||
785                                                            (assetTag.getGroupId() != groupId)) {
786                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
787                                                            finderArgs, assetTag);
788                                            }
789                                    }
790                            }
791                            catch (Exception e) {
792                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, finderArgs);
793    
794                                    throw processException(e);
795                            }
796                            finally {
797                                    closeSession(session);
798                            }
799                    }
800    
801                    if (result instanceof List<?>) {
802                            return null;
803                    }
804                    else {
805                            return (AssetTag)result;
806                    }
807            }
808    
809            /**
810             * Removes the asset tag where uuid = &#63; and groupId = &#63; from the database.
811             *
812             * @param uuid the uuid
813             * @param groupId the group ID
814             * @return the asset tag that was removed
815             */
816            @Override
817            public AssetTag removeByUUID_G(String uuid, long groupId)
818                    throws NoSuchTagException {
819                    AssetTag assetTag = findByUUID_G(uuid, groupId);
820    
821                    return remove(assetTag);
822            }
823    
824            /**
825             * Returns the number of asset tags where uuid = &#63; and groupId = &#63;.
826             *
827             * @param uuid the uuid
828             * @param groupId the group ID
829             * @return the number of matching asset tags
830             */
831            @Override
832            public int countByUUID_G(String uuid, long groupId) {
833                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
834    
835                    Object[] finderArgs = new Object[] { uuid, groupId };
836    
837                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
838    
839                    if (count == null) {
840                            StringBundler query = new StringBundler(3);
841    
842                            query.append(_SQL_COUNT_ASSETTAG_WHERE);
843    
844                            boolean bindUuid = false;
845    
846                            if (uuid == null) {
847                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
848                            }
849                            else if (uuid.equals(StringPool.BLANK)) {
850                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
851                            }
852                            else {
853                                    bindUuid = true;
854    
855                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
856                            }
857    
858                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
859    
860                            String sql = query.toString();
861    
862                            Session session = null;
863    
864                            try {
865                                    session = openSession();
866    
867                                    Query q = session.createQuery(sql);
868    
869                                    QueryPos qPos = QueryPos.getInstance(q);
870    
871                                    if (bindUuid) {
872                                            qPos.add(uuid);
873                                    }
874    
875                                    qPos.add(groupId);
876    
877                                    count = (Long)q.uniqueResult();
878    
879                                    finderCache.putResult(finderPath, finderArgs, count);
880                            }
881                            catch (Exception e) {
882                                    finderCache.removeResult(finderPath, finderArgs);
883    
884                                    throw processException(e);
885                            }
886                            finally {
887                                    closeSession(session);
888                            }
889                    }
890    
891                    return count.intValue();
892            }
893    
894            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "assetTag.uuid IS NULL AND ";
895            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "assetTag.uuid = ? AND ";
896            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(assetTag.uuid IS NULL OR assetTag.uuid = '') AND ";
897            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "assetTag.groupId = ?";
898            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
899                            AssetTagModelImpl.FINDER_CACHE_ENABLED, AssetTagImpl.class,
900                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
901                            new String[] {
902                                    String.class.getName(), Long.class.getName(),
903                                    
904                            Integer.class.getName(), Integer.class.getName(),
905                                    OrderByComparator.class.getName()
906                            });
907            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
908                    new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
909                            AssetTagModelImpl.FINDER_CACHE_ENABLED, AssetTagImpl.class,
910                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
911                            new String[] { String.class.getName(), Long.class.getName() },
912                            AssetTagModelImpl.UUID_COLUMN_BITMASK |
913                            AssetTagModelImpl.COMPANYID_COLUMN_BITMASK |
914                            AssetTagModelImpl.NAME_COLUMN_BITMASK);
915            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
916                            AssetTagModelImpl.FINDER_CACHE_ENABLED, Long.class,
917                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
918                            new String[] { String.class.getName(), Long.class.getName() });
919    
920            /**
921             * Returns all the asset tags where uuid = &#63; and companyId = &#63;.
922             *
923             * @param uuid the uuid
924             * @param companyId the company ID
925             * @return the matching asset tags
926             */
927            @Override
928            public List<AssetTag> findByUuid_C(String uuid, long companyId) {
929                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
930                            QueryUtil.ALL_POS, null);
931            }
932    
933            /**
934             * Returns a range of all the asset tags where uuid = &#63; and companyId = &#63;.
935             *
936             * <p>
937             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. 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.
938             * </p>
939             *
940             * @param uuid the uuid
941             * @param companyId the company ID
942             * @param start the lower bound of the range of asset tags
943             * @param end the upper bound of the range of asset tags (not inclusive)
944             * @return the range of matching asset tags
945             */
946            @Override
947            public List<AssetTag> findByUuid_C(String uuid, long companyId, int start,
948                    int end) {
949                    return findByUuid_C(uuid, companyId, start, end, null);
950            }
951    
952            /**
953             * Returns an ordered range of all the asset tags where uuid = &#63; and companyId = &#63;.
954             *
955             * <p>
956             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. 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.
957             * </p>
958             *
959             * @param uuid the uuid
960             * @param companyId the company ID
961             * @param start the lower bound of the range of asset tags
962             * @param end the upper bound of the range of asset tags (not inclusive)
963             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
964             * @return the ordered range of matching asset tags
965             */
966            @Override
967            public List<AssetTag> findByUuid_C(String uuid, long companyId, int start,
968                    int end, OrderByComparator<AssetTag> orderByComparator) {
969                    return findByUuid_C(uuid, companyId, start, end, orderByComparator, true);
970            }
971    
972            /**
973             * Returns an ordered range of all the asset tags where uuid = &#63; and companyId = &#63;.
974             *
975             * <p>
976             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. 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.
977             * </p>
978             *
979             * @param uuid the uuid
980             * @param companyId the company ID
981             * @param start the lower bound of the range of asset tags
982             * @param end the upper bound of the range of asset tags (not inclusive)
983             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
984             * @param retrieveFromCache whether to retrieve from the finder cache
985             * @return the ordered range of matching asset tags
986             */
987            @Override
988            public List<AssetTag> findByUuid_C(String uuid, long companyId, int start,
989                    int end, OrderByComparator<AssetTag> orderByComparator,
990                    boolean retrieveFromCache) {
991                    boolean pagination = true;
992                    FinderPath finderPath = null;
993                    Object[] finderArgs = null;
994    
995                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
996                                    (orderByComparator == null)) {
997                            pagination = false;
998                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
999                            finderArgs = new Object[] { uuid, companyId };
1000                    }
1001                    else {
1002                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
1003                            finderArgs = new Object[] {
1004                                            uuid, companyId,
1005                                            
1006                                            start, end, orderByComparator
1007                                    };
1008                    }
1009    
1010                    List<AssetTag> list = null;
1011    
1012                    if (retrieveFromCache) {
1013                            list = (List<AssetTag>)finderCache.getResult(finderPath,
1014                                            finderArgs, this);
1015    
1016                            if ((list != null) && !list.isEmpty()) {
1017                                    for (AssetTag assetTag : list) {
1018                                            if (!Validator.equals(uuid, assetTag.getUuid()) ||
1019                                                            (companyId != assetTag.getCompanyId())) {
1020                                                    list = null;
1021    
1022                                                    break;
1023                                            }
1024                                    }
1025                            }
1026                    }
1027    
1028                    if (list == null) {
1029                            StringBundler query = null;
1030    
1031                            if (orderByComparator != null) {
1032                                    query = new StringBundler(4 +
1033                                                    (orderByComparator.getOrderByFields().length * 3));
1034                            }
1035                            else {
1036                                    query = new StringBundler(4);
1037                            }
1038    
1039                            query.append(_SQL_SELECT_ASSETTAG_WHERE);
1040    
1041                            boolean bindUuid = false;
1042    
1043                            if (uuid == null) {
1044                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1045                            }
1046                            else if (uuid.equals(StringPool.BLANK)) {
1047                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1048                            }
1049                            else {
1050                                    bindUuid = true;
1051    
1052                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1053                            }
1054    
1055                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1056    
1057                            if (orderByComparator != null) {
1058                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1059                                            orderByComparator);
1060                            }
1061                            else
1062                             if (pagination) {
1063                                    query.append(AssetTagModelImpl.ORDER_BY_JPQL);
1064                            }
1065    
1066                            String sql = query.toString();
1067    
1068                            Session session = null;
1069    
1070                            try {
1071                                    session = openSession();
1072    
1073                                    Query q = session.createQuery(sql);
1074    
1075                                    QueryPos qPos = QueryPos.getInstance(q);
1076    
1077                                    if (bindUuid) {
1078                                            qPos.add(uuid);
1079                                    }
1080    
1081                                    qPos.add(companyId);
1082    
1083                                    if (!pagination) {
1084                                            list = (List<AssetTag>)QueryUtil.list(q, getDialect(),
1085                                                            start, end, false);
1086    
1087                                            Collections.sort(list);
1088    
1089                                            list = Collections.unmodifiableList(list);
1090                                    }
1091                                    else {
1092                                            list = (List<AssetTag>)QueryUtil.list(q, getDialect(),
1093                                                            start, end);
1094                                    }
1095    
1096                                    cacheResult(list);
1097    
1098                                    finderCache.putResult(finderPath, finderArgs, list);
1099                            }
1100                            catch (Exception e) {
1101                                    finderCache.removeResult(finderPath, finderArgs);
1102    
1103                                    throw processException(e);
1104                            }
1105                            finally {
1106                                    closeSession(session);
1107                            }
1108                    }
1109    
1110                    return list;
1111            }
1112    
1113            /**
1114             * Returns the first asset tag in the ordered set where uuid = &#63; and companyId = &#63;.
1115             *
1116             * @param uuid the uuid
1117             * @param companyId the company ID
1118             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1119             * @return the first matching asset tag
1120             * @throws NoSuchTagException if a matching asset tag could not be found
1121             */
1122            @Override
1123            public AssetTag findByUuid_C_First(String uuid, long companyId,
1124                    OrderByComparator<AssetTag> orderByComparator)
1125                    throws NoSuchTagException {
1126                    AssetTag assetTag = fetchByUuid_C_First(uuid, companyId,
1127                                    orderByComparator);
1128    
1129                    if (assetTag != null) {
1130                            return assetTag;
1131                    }
1132    
1133                    StringBundler msg = new StringBundler(6);
1134    
1135                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1136    
1137                    msg.append("uuid=");
1138                    msg.append(uuid);
1139    
1140                    msg.append(", companyId=");
1141                    msg.append(companyId);
1142    
1143                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1144    
1145                    throw new NoSuchTagException(msg.toString());
1146            }
1147    
1148            /**
1149             * Returns the first asset tag in the ordered set where uuid = &#63; and companyId = &#63;.
1150             *
1151             * @param uuid the uuid
1152             * @param companyId the company ID
1153             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1154             * @return the first matching asset tag, or <code>null</code> if a matching asset tag could not be found
1155             */
1156            @Override
1157            public AssetTag fetchByUuid_C_First(String uuid, long companyId,
1158                    OrderByComparator<AssetTag> orderByComparator) {
1159                    List<AssetTag> list = findByUuid_C(uuid, companyId, 0, 1,
1160                                    orderByComparator);
1161    
1162                    if (!list.isEmpty()) {
1163                            return list.get(0);
1164                    }
1165    
1166                    return null;
1167            }
1168    
1169            /**
1170             * Returns the last asset tag in the ordered set where uuid = &#63; and companyId = &#63;.
1171             *
1172             * @param uuid the uuid
1173             * @param companyId the company ID
1174             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1175             * @return the last matching asset tag
1176             * @throws NoSuchTagException if a matching asset tag could not be found
1177             */
1178            @Override
1179            public AssetTag findByUuid_C_Last(String uuid, long companyId,
1180                    OrderByComparator<AssetTag> orderByComparator)
1181                    throws NoSuchTagException {
1182                    AssetTag assetTag = fetchByUuid_C_Last(uuid, companyId,
1183                                    orderByComparator);
1184    
1185                    if (assetTag != null) {
1186                            return assetTag;
1187                    }
1188    
1189                    StringBundler msg = new StringBundler(6);
1190    
1191                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1192    
1193                    msg.append("uuid=");
1194                    msg.append(uuid);
1195    
1196                    msg.append(", companyId=");
1197                    msg.append(companyId);
1198    
1199                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1200    
1201                    throw new NoSuchTagException(msg.toString());
1202            }
1203    
1204            /**
1205             * Returns the last asset tag in the ordered set where uuid = &#63; and companyId = &#63;.
1206             *
1207             * @param uuid the uuid
1208             * @param companyId the company ID
1209             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1210             * @return the last matching asset tag, or <code>null</code> if a matching asset tag could not be found
1211             */
1212            @Override
1213            public AssetTag fetchByUuid_C_Last(String uuid, long companyId,
1214                    OrderByComparator<AssetTag> orderByComparator) {
1215                    int count = countByUuid_C(uuid, companyId);
1216    
1217                    if (count == 0) {
1218                            return null;
1219                    }
1220    
1221                    List<AssetTag> list = findByUuid_C(uuid, companyId, count - 1, count,
1222                                    orderByComparator);
1223    
1224                    if (!list.isEmpty()) {
1225                            return list.get(0);
1226                    }
1227    
1228                    return null;
1229            }
1230    
1231            /**
1232             * Returns the asset tags before and after the current asset tag in the ordered set where uuid = &#63; and companyId = &#63;.
1233             *
1234             * @param tagId the primary key of the current asset tag
1235             * @param uuid the uuid
1236             * @param companyId the company ID
1237             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1238             * @return the previous, current, and next asset tag
1239             * @throws NoSuchTagException if a asset tag with the primary key could not be found
1240             */
1241            @Override
1242            public AssetTag[] findByUuid_C_PrevAndNext(long tagId, String uuid,
1243                    long companyId, OrderByComparator<AssetTag> orderByComparator)
1244                    throws NoSuchTagException {
1245                    AssetTag assetTag = findByPrimaryKey(tagId);
1246    
1247                    Session session = null;
1248    
1249                    try {
1250                            session = openSession();
1251    
1252                            AssetTag[] array = new AssetTagImpl[3];
1253    
1254                            array[0] = getByUuid_C_PrevAndNext(session, assetTag, uuid,
1255                                            companyId, orderByComparator, true);
1256    
1257                            array[1] = assetTag;
1258    
1259                            array[2] = getByUuid_C_PrevAndNext(session, assetTag, uuid,
1260                                            companyId, orderByComparator, false);
1261    
1262                            return array;
1263                    }
1264                    catch (Exception e) {
1265                            throw processException(e);
1266                    }
1267                    finally {
1268                            closeSession(session);
1269                    }
1270            }
1271    
1272            protected AssetTag getByUuid_C_PrevAndNext(Session session,
1273                    AssetTag assetTag, String uuid, long companyId,
1274                    OrderByComparator<AssetTag> orderByComparator, boolean previous) {
1275                    StringBundler query = null;
1276    
1277                    if (orderByComparator != null) {
1278                            query = new StringBundler(6 +
1279                                            (orderByComparator.getOrderByFields().length * 6));
1280                    }
1281                    else {
1282                            query = new StringBundler(3);
1283                    }
1284    
1285                    query.append(_SQL_SELECT_ASSETTAG_WHERE);
1286    
1287                    boolean bindUuid = false;
1288    
1289                    if (uuid == null) {
1290                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1291                    }
1292                    else if (uuid.equals(StringPool.BLANK)) {
1293                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1294                    }
1295                    else {
1296                            bindUuid = true;
1297    
1298                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1299                    }
1300    
1301                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1302    
1303                    if (orderByComparator != null) {
1304                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1305    
1306                            if (orderByConditionFields.length > 0) {
1307                                    query.append(WHERE_AND);
1308                            }
1309    
1310                            for (int i = 0; i < orderByConditionFields.length; i++) {
1311                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1312                                    query.append(orderByConditionFields[i]);
1313    
1314                                    if ((i + 1) < orderByConditionFields.length) {
1315                                            if (orderByComparator.isAscending() ^ previous) {
1316                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1317                                            }
1318                                            else {
1319                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1320                                            }
1321                                    }
1322                                    else {
1323                                            if (orderByComparator.isAscending() ^ previous) {
1324                                                    query.append(WHERE_GREATER_THAN);
1325                                            }
1326                                            else {
1327                                                    query.append(WHERE_LESSER_THAN);
1328                                            }
1329                                    }
1330                            }
1331    
1332                            query.append(ORDER_BY_CLAUSE);
1333    
1334                            String[] orderByFields = orderByComparator.getOrderByFields();
1335    
1336                            for (int i = 0; i < orderByFields.length; i++) {
1337                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1338                                    query.append(orderByFields[i]);
1339    
1340                                    if ((i + 1) < orderByFields.length) {
1341                                            if (orderByComparator.isAscending() ^ previous) {
1342                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1343                                            }
1344                                            else {
1345                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1346                                            }
1347                                    }
1348                                    else {
1349                                            if (orderByComparator.isAscending() ^ previous) {
1350                                                    query.append(ORDER_BY_ASC);
1351                                            }
1352                                            else {
1353                                                    query.append(ORDER_BY_DESC);
1354                                            }
1355                                    }
1356                            }
1357                    }
1358                    else {
1359                            query.append(AssetTagModelImpl.ORDER_BY_JPQL);
1360                    }
1361    
1362                    String sql = query.toString();
1363    
1364                    Query q = session.createQuery(sql);
1365    
1366                    q.setFirstResult(0);
1367                    q.setMaxResults(2);
1368    
1369                    QueryPos qPos = QueryPos.getInstance(q);
1370    
1371                    if (bindUuid) {
1372                            qPos.add(uuid);
1373                    }
1374    
1375                    qPos.add(companyId);
1376    
1377                    if (orderByComparator != null) {
1378                            Object[] values = orderByComparator.getOrderByConditionValues(assetTag);
1379    
1380                            for (Object value : values) {
1381                                    qPos.add(value);
1382                            }
1383                    }
1384    
1385                    List<AssetTag> list = q.list();
1386    
1387                    if (list.size() == 2) {
1388                            return list.get(1);
1389                    }
1390                    else {
1391                            return null;
1392                    }
1393            }
1394    
1395            /**
1396             * Removes all the asset tags where uuid = &#63; and companyId = &#63; from the database.
1397             *
1398             * @param uuid the uuid
1399             * @param companyId the company ID
1400             */
1401            @Override
1402            public void removeByUuid_C(String uuid, long companyId) {
1403                    for (AssetTag assetTag : findByUuid_C(uuid, companyId,
1404                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1405                            remove(assetTag);
1406                    }
1407            }
1408    
1409            /**
1410             * Returns the number of asset tags where uuid = &#63; and companyId = &#63;.
1411             *
1412             * @param uuid the uuid
1413             * @param companyId the company ID
1414             * @return the number of matching asset tags
1415             */
1416            @Override
1417            public int countByUuid_C(String uuid, long companyId) {
1418                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1419    
1420                    Object[] finderArgs = new Object[] { uuid, companyId };
1421    
1422                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1423    
1424                    if (count == null) {
1425                            StringBundler query = new StringBundler(3);
1426    
1427                            query.append(_SQL_COUNT_ASSETTAG_WHERE);
1428    
1429                            boolean bindUuid = false;
1430    
1431                            if (uuid == null) {
1432                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1433                            }
1434                            else if (uuid.equals(StringPool.BLANK)) {
1435                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1436                            }
1437                            else {
1438                                    bindUuid = true;
1439    
1440                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1441                            }
1442    
1443                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1444    
1445                            String sql = query.toString();
1446    
1447                            Session session = null;
1448    
1449                            try {
1450                                    session = openSession();
1451    
1452                                    Query q = session.createQuery(sql);
1453    
1454                                    QueryPos qPos = QueryPos.getInstance(q);
1455    
1456                                    if (bindUuid) {
1457                                            qPos.add(uuid);
1458                                    }
1459    
1460                                    qPos.add(companyId);
1461    
1462                                    count = (Long)q.uniqueResult();
1463    
1464                                    finderCache.putResult(finderPath, finderArgs, count);
1465                            }
1466                            catch (Exception e) {
1467                                    finderCache.removeResult(finderPath, finderArgs);
1468    
1469                                    throw processException(e);
1470                            }
1471                            finally {
1472                                    closeSession(session);
1473                            }
1474                    }
1475    
1476                    return count.intValue();
1477            }
1478    
1479            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "assetTag.uuid IS NULL AND ";
1480            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "assetTag.uuid = ? AND ";
1481            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(assetTag.uuid IS NULL OR assetTag.uuid = '') AND ";
1482            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "assetTag.companyId = ?";
1483            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
1484                            AssetTagModelImpl.FINDER_CACHE_ENABLED, AssetTagImpl.class,
1485                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
1486                            new String[] {
1487                                    Long.class.getName(),
1488                                    
1489                            Integer.class.getName(), Integer.class.getName(),
1490                                    OrderByComparator.class.getName()
1491                            });
1492            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1493                    new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
1494                            AssetTagModelImpl.FINDER_CACHE_ENABLED, AssetTagImpl.class,
1495                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1496                            new String[] { Long.class.getName() },
1497                            AssetTagModelImpl.GROUPID_COLUMN_BITMASK |
1498                            AssetTagModelImpl.NAME_COLUMN_BITMASK);
1499            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
1500                            AssetTagModelImpl.FINDER_CACHE_ENABLED, Long.class,
1501                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1502                            new String[] { Long.class.getName() });
1503            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_GROUPID = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
1504                            AssetTagModelImpl.FINDER_CACHE_ENABLED, Long.class,
1505                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByGroupId",
1506                            new String[] { Long.class.getName() });
1507    
1508            /**
1509             * Returns all the asset tags where groupId = &#63;.
1510             *
1511             * @param groupId the group ID
1512             * @return the matching asset tags
1513             */
1514            @Override
1515            public List<AssetTag> findByGroupId(long groupId) {
1516                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1517            }
1518    
1519            /**
1520             * Returns a range of all the asset tags where groupId = &#63;.
1521             *
1522             * <p>
1523             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. 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.
1524             * </p>
1525             *
1526             * @param groupId the group ID
1527             * @param start the lower bound of the range of asset tags
1528             * @param end the upper bound of the range of asset tags (not inclusive)
1529             * @return the range of matching asset tags
1530             */
1531            @Override
1532            public List<AssetTag> findByGroupId(long groupId, int start, int end) {
1533                    return findByGroupId(groupId, start, end, null);
1534            }
1535    
1536            /**
1537             * Returns an ordered range of all the asset tags where groupId = &#63;.
1538             *
1539             * <p>
1540             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. 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.
1541             * </p>
1542             *
1543             * @param groupId the group ID
1544             * @param start the lower bound of the range of asset tags
1545             * @param end the upper bound of the range of asset tags (not inclusive)
1546             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1547             * @return the ordered range of matching asset tags
1548             */
1549            @Override
1550            public List<AssetTag> findByGroupId(long groupId, int start, int end,
1551                    OrderByComparator<AssetTag> orderByComparator) {
1552                    return findByGroupId(groupId, start, end, orderByComparator, true);
1553            }
1554    
1555            /**
1556             * Returns an ordered range of all the asset tags where groupId = &#63;.
1557             *
1558             * <p>
1559             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. 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.
1560             * </p>
1561             *
1562             * @param groupId the group ID
1563             * @param start the lower bound of the range of asset tags
1564             * @param end the upper bound of the range of asset tags (not inclusive)
1565             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1566             * @param retrieveFromCache whether to retrieve from the finder cache
1567             * @return the ordered range of matching asset tags
1568             */
1569            @Override
1570            public List<AssetTag> findByGroupId(long groupId, int start, int end,
1571                    OrderByComparator<AssetTag> orderByComparator, boolean retrieveFromCache) {
1572                    boolean pagination = true;
1573                    FinderPath finderPath = null;
1574                    Object[] finderArgs = null;
1575    
1576                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1577                                    (orderByComparator == null)) {
1578                            pagination = false;
1579                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1580                            finderArgs = new Object[] { groupId };
1581                    }
1582                    else {
1583                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1584                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1585                    }
1586    
1587                    List<AssetTag> list = null;
1588    
1589                    if (retrieveFromCache) {
1590                            list = (List<AssetTag>)finderCache.getResult(finderPath,
1591                                            finderArgs, this);
1592    
1593                            if ((list != null) && !list.isEmpty()) {
1594                                    for (AssetTag assetTag : list) {
1595                                            if ((groupId != assetTag.getGroupId())) {
1596                                                    list = null;
1597    
1598                                                    break;
1599                                            }
1600                                    }
1601                            }
1602                    }
1603    
1604                    if (list == null) {
1605                            StringBundler query = null;
1606    
1607                            if (orderByComparator != null) {
1608                                    query = new StringBundler(3 +
1609                                                    (orderByComparator.getOrderByFields().length * 3));
1610                            }
1611                            else {
1612                                    query = new StringBundler(3);
1613                            }
1614    
1615                            query.append(_SQL_SELECT_ASSETTAG_WHERE);
1616    
1617                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1618    
1619                            if (orderByComparator != null) {
1620                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1621                                            orderByComparator);
1622                            }
1623                            else
1624                             if (pagination) {
1625                                    query.append(AssetTagModelImpl.ORDER_BY_JPQL);
1626                            }
1627    
1628                            String sql = query.toString();
1629    
1630                            Session session = null;
1631    
1632                            try {
1633                                    session = openSession();
1634    
1635                                    Query q = session.createQuery(sql);
1636    
1637                                    QueryPos qPos = QueryPos.getInstance(q);
1638    
1639                                    qPos.add(groupId);
1640    
1641                                    if (!pagination) {
1642                                            list = (List<AssetTag>)QueryUtil.list(q, getDialect(),
1643                                                            start, end, false);
1644    
1645                                            Collections.sort(list);
1646    
1647                                            list = Collections.unmodifiableList(list);
1648                                    }
1649                                    else {
1650                                            list = (List<AssetTag>)QueryUtil.list(q, getDialect(),
1651                                                            start, end);
1652                                    }
1653    
1654                                    cacheResult(list);
1655    
1656                                    finderCache.putResult(finderPath, finderArgs, list);
1657                            }
1658                            catch (Exception e) {
1659                                    finderCache.removeResult(finderPath, finderArgs);
1660    
1661                                    throw processException(e);
1662                            }
1663                            finally {
1664                                    closeSession(session);
1665                            }
1666                    }
1667    
1668                    return list;
1669            }
1670    
1671            /**
1672             * Returns the first asset tag in the ordered set where groupId = &#63;.
1673             *
1674             * @param groupId the group ID
1675             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1676             * @return the first matching asset tag
1677             * @throws NoSuchTagException if a matching asset tag could not be found
1678             */
1679            @Override
1680            public AssetTag findByGroupId_First(long groupId,
1681                    OrderByComparator<AssetTag> orderByComparator)
1682                    throws NoSuchTagException {
1683                    AssetTag assetTag = fetchByGroupId_First(groupId, orderByComparator);
1684    
1685                    if (assetTag != null) {
1686                            return assetTag;
1687                    }
1688    
1689                    StringBundler msg = new StringBundler(4);
1690    
1691                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1692    
1693                    msg.append("groupId=");
1694                    msg.append(groupId);
1695    
1696                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1697    
1698                    throw new NoSuchTagException(msg.toString());
1699            }
1700    
1701            /**
1702             * Returns the first asset tag in the ordered set where groupId = &#63;.
1703             *
1704             * @param groupId the group ID
1705             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1706             * @return the first matching asset tag, or <code>null</code> if a matching asset tag could not be found
1707             */
1708            @Override
1709            public AssetTag fetchByGroupId_First(long groupId,
1710                    OrderByComparator<AssetTag> orderByComparator) {
1711                    List<AssetTag> list = findByGroupId(groupId, 0, 1, orderByComparator);
1712    
1713                    if (!list.isEmpty()) {
1714                            return list.get(0);
1715                    }
1716    
1717                    return null;
1718            }
1719    
1720            /**
1721             * Returns the last asset tag in the ordered set where groupId = &#63;.
1722             *
1723             * @param groupId the group ID
1724             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1725             * @return the last matching asset tag
1726             * @throws NoSuchTagException if a matching asset tag could not be found
1727             */
1728            @Override
1729            public AssetTag findByGroupId_Last(long groupId,
1730                    OrderByComparator<AssetTag> orderByComparator)
1731                    throws NoSuchTagException {
1732                    AssetTag assetTag = fetchByGroupId_Last(groupId, orderByComparator);
1733    
1734                    if (assetTag != null) {
1735                            return assetTag;
1736                    }
1737    
1738                    StringBundler msg = new StringBundler(4);
1739    
1740                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1741    
1742                    msg.append("groupId=");
1743                    msg.append(groupId);
1744    
1745                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1746    
1747                    throw new NoSuchTagException(msg.toString());
1748            }
1749    
1750            /**
1751             * Returns the last asset tag in the ordered set where groupId = &#63;.
1752             *
1753             * @param groupId the group ID
1754             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1755             * @return the last matching asset tag, or <code>null</code> if a matching asset tag could not be found
1756             */
1757            @Override
1758            public AssetTag fetchByGroupId_Last(long groupId,
1759                    OrderByComparator<AssetTag> orderByComparator) {
1760                    int count = countByGroupId(groupId);
1761    
1762                    if (count == 0) {
1763                            return null;
1764                    }
1765    
1766                    List<AssetTag> list = findByGroupId(groupId, count - 1, count,
1767                                    orderByComparator);
1768    
1769                    if (!list.isEmpty()) {
1770                            return list.get(0);
1771                    }
1772    
1773                    return null;
1774            }
1775    
1776            /**
1777             * Returns the asset tags before and after the current asset tag in the ordered set where groupId = &#63;.
1778             *
1779             * @param tagId the primary key of the current asset tag
1780             * @param groupId the group ID
1781             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1782             * @return the previous, current, and next asset tag
1783             * @throws NoSuchTagException if a asset tag with the primary key could not be found
1784             */
1785            @Override
1786            public AssetTag[] findByGroupId_PrevAndNext(long tagId, long groupId,
1787                    OrderByComparator<AssetTag> orderByComparator)
1788                    throws NoSuchTagException {
1789                    AssetTag assetTag = findByPrimaryKey(tagId);
1790    
1791                    Session session = null;
1792    
1793                    try {
1794                            session = openSession();
1795    
1796                            AssetTag[] array = new AssetTagImpl[3];
1797    
1798                            array[0] = getByGroupId_PrevAndNext(session, assetTag, groupId,
1799                                            orderByComparator, true);
1800    
1801                            array[1] = assetTag;
1802    
1803                            array[2] = getByGroupId_PrevAndNext(session, assetTag, groupId,
1804                                            orderByComparator, false);
1805    
1806                            return array;
1807                    }
1808                    catch (Exception e) {
1809                            throw processException(e);
1810                    }
1811                    finally {
1812                            closeSession(session);
1813                    }
1814            }
1815    
1816            protected AssetTag getByGroupId_PrevAndNext(Session session,
1817                    AssetTag assetTag, long groupId,
1818                    OrderByComparator<AssetTag> orderByComparator, boolean previous) {
1819                    StringBundler query = null;
1820    
1821                    if (orderByComparator != null) {
1822                            query = new StringBundler(6 +
1823                                            (orderByComparator.getOrderByFields().length * 6));
1824                    }
1825                    else {
1826                            query = new StringBundler(3);
1827                    }
1828    
1829                    query.append(_SQL_SELECT_ASSETTAG_WHERE);
1830    
1831                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1832    
1833                    if (orderByComparator != null) {
1834                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1835    
1836                            if (orderByConditionFields.length > 0) {
1837                                    query.append(WHERE_AND);
1838                            }
1839    
1840                            for (int i = 0; i < orderByConditionFields.length; i++) {
1841                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1842                                    query.append(orderByConditionFields[i]);
1843    
1844                                    if ((i + 1) < orderByConditionFields.length) {
1845                                            if (orderByComparator.isAscending() ^ previous) {
1846                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1847                                            }
1848                                            else {
1849                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1850                                            }
1851                                    }
1852                                    else {
1853                                            if (orderByComparator.isAscending() ^ previous) {
1854                                                    query.append(WHERE_GREATER_THAN);
1855                                            }
1856                                            else {
1857                                                    query.append(WHERE_LESSER_THAN);
1858                                            }
1859                                    }
1860                            }
1861    
1862                            query.append(ORDER_BY_CLAUSE);
1863    
1864                            String[] orderByFields = orderByComparator.getOrderByFields();
1865    
1866                            for (int i = 0; i < orderByFields.length; i++) {
1867                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1868                                    query.append(orderByFields[i]);
1869    
1870                                    if ((i + 1) < orderByFields.length) {
1871                                            if (orderByComparator.isAscending() ^ previous) {
1872                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1873                                            }
1874                                            else {
1875                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1876                                            }
1877                                    }
1878                                    else {
1879                                            if (orderByComparator.isAscending() ^ previous) {
1880                                                    query.append(ORDER_BY_ASC);
1881                                            }
1882                                            else {
1883                                                    query.append(ORDER_BY_DESC);
1884                                            }
1885                                    }
1886                            }
1887                    }
1888                    else {
1889                            query.append(AssetTagModelImpl.ORDER_BY_JPQL);
1890                    }
1891    
1892                    String sql = query.toString();
1893    
1894                    Query q = session.createQuery(sql);
1895    
1896                    q.setFirstResult(0);
1897                    q.setMaxResults(2);
1898    
1899                    QueryPos qPos = QueryPos.getInstance(q);
1900    
1901                    qPos.add(groupId);
1902    
1903                    if (orderByComparator != null) {
1904                            Object[] values = orderByComparator.getOrderByConditionValues(assetTag);
1905    
1906                            for (Object value : values) {
1907                                    qPos.add(value);
1908                            }
1909                    }
1910    
1911                    List<AssetTag> list = q.list();
1912    
1913                    if (list.size() == 2) {
1914                            return list.get(1);
1915                    }
1916                    else {
1917                            return null;
1918                    }
1919            }
1920    
1921            /**
1922             * Returns all the asset tags that the user has permission to view where groupId = &#63;.
1923             *
1924             * @param groupId the group ID
1925             * @return the matching asset tags that the user has permission to view
1926             */
1927            @Override
1928            public List<AssetTag> filterFindByGroupId(long groupId) {
1929                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1930                            QueryUtil.ALL_POS, null);
1931            }
1932    
1933            /**
1934             * Returns a range of all the asset tags that the user has permission to view where groupId = &#63;.
1935             *
1936             * <p>
1937             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. 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.
1938             * </p>
1939             *
1940             * @param groupId the group ID
1941             * @param start the lower bound of the range of asset tags
1942             * @param end the upper bound of the range of asset tags (not inclusive)
1943             * @return the range of matching asset tags that the user has permission to view
1944             */
1945            @Override
1946            public List<AssetTag> filterFindByGroupId(long groupId, int start, int end) {
1947                    return filterFindByGroupId(groupId, start, end, null);
1948            }
1949    
1950            /**
1951             * Returns an ordered range of all the asset tags that the user has permissions to view where groupId = &#63;.
1952             *
1953             * <p>
1954             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. 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.
1955             * </p>
1956             *
1957             * @param groupId the group ID
1958             * @param start the lower bound of the range of asset tags
1959             * @param end the upper bound of the range of asset tags (not inclusive)
1960             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1961             * @return the ordered range of matching asset tags that the user has permission to view
1962             */
1963            @Override
1964            public List<AssetTag> filterFindByGroupId(long groupId, int start, int end,
1965                    OrderByComparator<AssetTag> orderByComparator) {
1966                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1967                            return findByGroupId(groupId, start, end, orderByComparator);
1968                    }
1969    
1970                    StringBundler query = null;
1971    
1972                    if (orderByComparator != null) {
1973                            query = new StringBundler(3 +
1974                                            (orderByComparator.getOrderByFields().length * 3));
1975                    }
1976                    else {
1977                            query = new StringBundler(3);
1978                    }
1979    
1980                    if (getDB().isSupportsInlineDistinct()) {
1981                            query.append(_FILTER_SQL_SELECT_ASSETTAG_WHERE);
1982                    }
1983                    else {
1984                            query.append(_FILTER_SQL_SELECT_ASSETTAG_NO_INLINE_DISTINCT_WHERE_1);
1985                    }
1986    
1987                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1988    
1989                    if (!getDB().isSupportsInlineDistinct()) {
1990                            query.append(_FILTER_SQL_SELECT_ASSETTAG_NO_INLINE_DISTINCT_WHERE_2);
1991                    }
1992    
1993                    if (orderByComparator != null) {
1994                            if (getDB().isSupportsInlineDistinct()) {
1995                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1996                                            orderByComparator, true);
1997                            }
1998                            else {
1999                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2000                                            orderByComparator, true);
2001                            }
2002                    }
2003                    else {
2004                            if (getDB().isSupportsInlineDistinct()) {
2005                                    query.append(AssetTagModelImpl.ORDER_BY_JPQL);
2006                            }
2007                            else {
2008                                    query.append(AssetTagModelImpl.ORDER_BY_SQL);
2009                            }
2010                    }
2011    
2012                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2013                                    AssetTag.class.getName(),
2014                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2015    
2016                    Session session = null;
2017    
2018                    try {
2019                            session = openSession();
2020    
2021                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
2022    
2023                            if (getDB().isSupportsInlineDistinct()) {
2024                                    q.addEntity(_FILTER_ENTITY_ALIAS, AssetTagImpl.class);
2025                            }
2026                            else {
2027                                    q.addEntity(_FILTER_ENTITY_TABLE, AssetTagImpl.class);
2028                            }
2029    
2030                            QueryPos qPos = QueryPos.getInstance(q);
2031    
2032                            qPos.add(groupId);
2033    
2034                            return (List<AssetTag>)QueryUtil.list(q, getDialect(), start, end);
2035                    }
2036                    catch (Exception e) {
2037                            throw processException(e);
2038                    }
2039                    finally {
2040                            closeSession(session);
2041                    }
2042            }
2043    
2044            /**
2045             * Returns the asset tags before and after the current asset tag in the ordered set of asset tags that the user has permission to view where groupId = &#63;.
2046             *
2047             * @param tagId the primary key of the current asset tag
2048             * @param groupId the group ID
2049             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2050             * @return the previous, current, and next asset tag
2051             * @throws NoSuchTagException if a asset tag with the primary key could not be found
2052             */
2053            @Override
2054            public AssetTag[] filterFindByGroupId_PrevAndNext(long tagId, long groupId,
2055                    OrderByComparator<AssetTag> orderByComparator)
2056                    throws NoSuchTagException {
2057                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2058                            return findByGroupId_PrevAndNext(tagId, groupId, orderByComparator);
2059                    }
2060    
2061                    AssetTag assetTag = findByPrimaryKey(tagId);
2062    
2063                    Session session = null;
2064    
2065                    try {
2066                            session = openSession();
2067    
2068                            AssetTag[] array = new AssetTagImpl[3];
2069    
2070                            array[0] = filterGetByGroupId_PrevAndNext(session, assetTag,
2071                                            groupId, orderByComparator, true);
2072    
2073                            array[1] = assetTag;
2074    
2075                            array[2] = filterGetByGroupId_PrevAndNext(session, assetTag,
2076                                            groupId, orderByComparator, false);
2077    
2078                            return array;
2079                    }
2080                    catch (Exception e) {
2081                            throw processException(e);
2082                    }
2083                    finally {
2084                            closeSession(session);
2085                    }
2086            }
2087    
2088            protected AssetTag filterGetByGroupId_PrevAndNext(Session session,
2089                    AssetTag assetTag, long groupId,
2090                    OrderByComparator<AssetTag> orderByComparator, boolean previous) {
2091                    StringBundler query = null;
2092    
2093                    if (orderByComparator != null) {
2094                            query = new StringBundler(6 +
2095                                            (orderByComparator.getOrderByFields().length * 6));
2096                    }
2097                    else {
2098                            query = new StringBundler(3);
2099                    }
2100    
2101                    if (getDB().isSupportsInlineDistinct()) {
2102                            query.append(_FILTER_SQL_SELECT_ASSETTAG_WHERE);
2103                    }
2104                    else {
2105                            query.append(_FILTER_SQL_SELECT_ASSETTAG_NO_INLINE_DISTINCT_WHERE_1);
2106                    }
2107    
2108                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2109    
2110                    if (!getDB().isSupportsInlineDistinct()) {
2111                            query.append(_FILTER_SQL_SELECT_ASSETTAG_NO_INLINE_DISTINCT_WHERE_2);
2112                    }
2113    
2114                    if (orderByComparator != null) {
2115                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2116    
2117                            if (orderByConditionFields.length > 0) {
2118                                    query.append(WHERE_AND);
2119                            }
2120    
2121                            for (int i = 0; i < orderByConditionFields.length; i++) {
2122                                    if (getDB().isSupportsInlineDistinct()) {
2123                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2124                                    }
2125                                    else {
2126                                            query.append(_ORDER_BY_ENTITY_TABLE);
2127                                    }
2128    
2129                                    query.append(orderByConditionFields[i]);
2130    
2131                                    if ((i + 1) < orderByConditionFields.length) {
2132                                            if (orderByComparator.isAscending() ^ previous) {
2133                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2134                                            }
2135                                            else {
2136                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2137                                            }
2138                                    }
2139                                    else {
2140                                            if (orderByComparator.isAscending() ^ previous) {
2141                                                    query.append(WHERE_GREATER_THAN);
2142                                            }
2143                                            else {
2144                                                    query.append(WHERE_LESSER_THAN);
2145                                            }
2146                                    }
2147                            }
2148    
2149                            query.append(ORDER_BY_CLAUSE);
2150    
2151                            String[] orderByFields = orderByComparator.getOrderByFields();
2152    
2153                            for (int i = 0; i < orderByFields.length; i++) {
2154                                    if (getDB().isSupportsInlineDistinct()) {
2155                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2156                                    }
2157                                    else {
2158                                            query.append(_ORDER_BY_ENTITY_TABLE);
2159                                    }
2160    
2161                                    query.append(orderByFields[i]);
2162    
2163                                    if ((i + 1) < orderByFields.length) {
2164                                            if (orderByComparator.isAscending() ^ previous) {
2165                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2166                                            }
2167                                            else {
2168                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2169                                            }
2170                                    }
2171                                    else {
2172                                            if (orderByComparator.isAscending() ^ previous) {
2173                                                    query.append(ORDER_BY_ASC);
2174                                            }
2175                                            else {
2176                                                    query.append(ORDER_BY_DESC);
2177                                            }
2178                                    }
2179                            }
2180                    }
2181                    else {
2182                            if (getDB().isSupportsInlineDistinct()) {
2183                                    query.append(AssetTagModelImpl.ORDER_BY_JPQL);
2184                            }
2185                            else {
2186                                    query.append(AssetTagModelImpl.ORDER_BY_SQL);
2187                            }
2188                    }
2189    
2190                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2191                                    AssetTag.class.getName(),
2192                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2193    
2194                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
2195    
2196                    q.setFirstResult(0);
2197                    q.setMaxResults(2);
2198    
2199                    if (getDB().isSupportsInlineDistinct()) {
2200                            q.addEntity(_FILTER_ENTITY_ALIAS, AssetTagImpl.class);
2201                    }
2202                    else {
2203                            q.addEntity(_FILTER_ENTITY_TABLE, AssetTagImpl.class);
2204                    }
2205    
2206                    QueryPos qPos = QueryPos.getInstance(q);
2207    
2208                    qPos.add(groupId);
2209    
2210                    if (orderByComparator != null) {
2211                            Object[] values = orderByComparator.getOrderByConditionValues(assetTag);
2212    
2213                            for (Object value : values) {
2214                                    qPos.add(value);
2215                            }
2216                    }
2217    
2218                    List<AssetTag> list = q.list();
2219    
2220                    if (list.size() == 2) {
2221                            return list.get(1);
2222                    }
2223                    else {
2224                            return null;
2225                    }
2226            }
2227    
2228            /**
2229             * Returns all the asset tags that the user has permission to view where groupId = any &#63;.
2230             *
2231             * @param groupIds the group IDs
2232             * @return the matching asset tags that the user has permission to view
2233             */
2234            @Override
2235            public List<AssetTag> filterFindByGroupId(long[] groupIds) {
2236                    return filterFindByGroupId(groupIds, QueryUtil.ALL_POS,
2237                            QueryUtil.ALL_POS, null);
2238            }
2239    
2240            /**
2241             * Returns a range of all the asset tags that the user has permission to view where groupId = any &#63;.
2242             *
2243             * <p>
2244             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. 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.
2245             * </p>
2246             *
2247             * @param groupIds the group IDs
2248             * @param start the lower bound of the range of asset tags
2249             * @param end the upper bound of the range of asset tags (not inclusive)
2250             * @return the range of matching asset tags that the user has permission to view
2251             */
2252            @Override
2253            public List<AssetTag> filterFindByGroupId(long[] groupIds, int start,
2254                    int end) {
2255                    return filterFindByGroupId(groupIds, start, end, null);
2256            }
2257    
2258            /**
2259             * Returns an ordered range of all the asset tags that the user has permission to view where groupId = any &#63;.
2260             *
2261             * <p>
2262             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. 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.
2263             * </p>
2264             *
2265             * @param groupIds the group IDs
2266             * @param start the lower bound of the range of asset tags
2267             * @param end the upper bound of the range of asset tags (not inclusive)
2268             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2269             * @return the ordered range of matching asset tags that the user has permission to view
2270             */
2271            @Override
2272            public List<AssetTag> filterFindByGroupId(long[] groupIds, int start,
2273                    int end, OrderByComparator<AssetTag> orderByComparator) {
2274                    if (!InlineSQLHelperUtil.isEnabled(groupIds)) {
2275                            return findByGroupId(groupIds, start, end, orderByComparator);
2276                    }
2277    
2278                    if (groupIds == null) {
2279                            groupIds = new long[0];
2280                    }
2281                    else if (groupIds.length > 1) {
2282                            groupIds = ArrayUtil.unique(groupIds);
2283    
2284                            Arrays.sort(groupIds);
2285                    }
2286    
2287                    StringBundler query = new StringBundler();
2288    
2289                    if (getDB().isSupportsInlineDistinct()) {
2290                            query.append(_FILTER_SQL_SELECT_ASSETTAG_WHERE);
2291                    }
2292                    else {
2293                            query.append(_FILTER_SQL_SELECT_ASSETTAG_NO_INLINE_DISTINCT_WHERE_1);
2294                    }
2295    
2296                    if (groupIds.length > 0) {
2297                            query.append(StringPool.OPEN_PARENTHESIS);
2298    
2299                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_7);
2300    
2301                            query.append(StringUtil.merge(groupIds));
2302    
2303                            query.append(StringPool.CLOSE_PARENTHESIS);
2304    
2305                            query.append(StringPool.CLOSE_PARENTHESIS);
2306                    }
2307    
2308                    query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
2309                            query.index() - 1);
2310    
2311                    if (!getDB().isSupportsInlineDistinct()) {
2312                            query.append(_FILTER_SQL_SELECT_ASSETTAG_NO_INLINE_DISTINCT_WHERE_2);
2313                    }
2314    
2315                    if (orderByComparator != null) {
2316                            if (getDB().isSupportsInlineDistinct()) {
2317                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2318                                            orderByComparator, true);
2319                            }
2320                            else {
2321                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2322                                            orderByComparator, true);
2323                            }
2324                    }
2325                    else {
2326                            if (getDB().isSupportsInlineDistinct()) {
2327                                    query.append(AssetTagModelImpl.ORDER_BY_JPQL);
2328                            }
2329                            else {
2330                                    query.append(AssetTagModelImpl.ORDER_BY_SQL);
2331                            }
2332                    }
2333    
2334                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2335                                    AssetTag.class.getName(),
2336                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupIds);
2337    
2338                    Session session = null;
2339    
2340                    try {
2341                            session = openSession();
2342    
2343                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
2344    
2345                            if (getDB().isSupportsInlineDistinct()) {
2346                                    q.addEntity(_FILTER_ENTITY_ALIAS, AssetTagImpl.class);
2347                            }
2348                            else {
2349                                    q.addEntity(_FILTER_ENTITY_TABLE, AssetTagImpl.class);
2350                            }
2351    
2352                            return (List<AssetTag>)QueryUtil.list(q, getDialect(), start, end);
2353                    }
2354                    catch (Exception e) {
2355                            throw processException(e);
2356                    }
2357                    finally {
2358                            closeSession(session);
2359                    }
2360            }
2361    
2362            /**
2363             * Returns all the asset tags where groupId = any &#63;.
2364             *
2365             * <p>
2366             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. 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.
2367             * </p>
2368             *
2369             * @param groupIds the group IDs
2370             * @return the matching asset tags
2371             */
2372            @Override
2373            public List<AssetTag> findByGroupId(long[] groupIds) {
2374                    return findByGroupId(groupIds, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2375                            null);
2376            }
2377    
2378            /**
2379             * Returns a range of all the asset tags where groupId = any &#63;.
2380             *
2381             * <p>
2382             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. 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.
2383             * </p>
2384             *
2385             * @param groupIds the group IDs
2386             * @param start the lower bound of the range of asset tags
2387             * @param end the upper bound of the range of asset tags (not inclusive)
2388             * @return the range of matching asset tags
2389             */
2390            @Override
2391            public List<AssetTag> findByGroupId(long[] groupIds, int start, int end) {
2392                    return findByGroupId(groupIds, start, end, null);
2393            }
2394    
2395            /**
2396             * Returns an ordered range of all the asset tags where groupId = any &#63;.
2397             *
2398             * <p>
2399             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. 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.
2400             * </p>
2401             *
2402             * @param groupIds the group IDs
2403             * @param start the lower bound of the range of asset tags
2404             * @param end the upper bound of the range of asset tags (not inclusive)
2405             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2406             * @return the ordered range of matching asset tags
2407             */
2408            @Override
2409            public List<AssetTag> findByGroupId(long[] groupIds, int start, int end,
2410                    OrderByComparator<AssetTag> orderByComparator) {
2411                    return findByGroupId(groupIds, start, end, orderByComparator, true);
2412            }
2413    
2414            /**
2415             * Returns an ordered range of all the asset tags where groupId = &#63;, optionally using the finder cache.
2416             *
2417             * <p>
2418             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. 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.
2419             * </p>
2420             *
2421             * @param groupId the group ID
2422             * @param start the lower bound of the range of asset tags
2423             * @param end the upper bound of the range of asset tags (not inclusive)
2424             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2425             * @param retrieveFromCache whether to retrieve from the finder cache
2426             * @return the ordered range of matching asset tags
2427             */
2428            @Override
2429            public List<AssetTag> findByGroupId(long[] groupIds, int start, int end,
2430                    OrderByComparator<AssetTag> orderByComparator, boolean retrieveFromCache) {
2431                    if (groupIds == null) {
2432                            groupIds = new long[0];
2433                    }
2434                    else if (groupIds.length > 1) {
2435                            groupIds = ArrayUtil.unique(groupIds);
2436    
2437                            Arrays.sort(groupIds);
2438                    }
2439    
2440                    if (groupIds.length == 1) {
2441                            return findByGroupId(groupIds[0], start, end, orderByComparator);
2442                    }
2443    
2444                    boolean pagination = true;
2445                    Object[] finderArgs = null;
2446    
2447                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2448                                    (orderByComparator == null)) {
2449                            pagination = false;
2450                            finderArgs = new Object[] { StringUtil.merge(groupIds) };
2451                    }
2452                    else {
2453                            finderArgs = new Object[] {
2454                                            StringUtil.merge(groupIds),
2455                                            
2456                                            start, end, orderByComparator
2457                                    };
2458                    }
2459    
2460                    List<AssetTag> list = null;
2461    
2462                    if (retrieveFromCache) {
2463                            list = (List<AssetTag>)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID,
2464                                            finderArgs, this);
2465    
2466                            if ((list != null) && !list.isEmpty()) {
2467                                    for (AssetTag assetTag : list) {
2468                                            if (!ArrayUtil.contains(groupIds, assetTag.getGroupId())) {
2469                                                    list = null;
2470    
2471                                                    break;
2472                                            }
2473                                    }
2474                            }
2475                    }
2476    
2477                    if (list == null) {
2478                            StringBundler query = new StringBundler();
2479    
2480                            query.append(_SQL_SELECT_ASSETTAG_WHERE);
2481    
2482                            if (groupIds.length > 0) {
2483                                    query.append(StringPool.OPEN_PARENTHESIS);
2484    
2485                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_7);
2486    
2487                                    query.append(StringUtil.merge(groupIds));
2488    
2489                                    query.append(StringPool.CLOSE_PARENTHESIS);
2490    
2491                                    query.append(StringPool.CLOSE_PARENTHESIS);
2492                            }
2493    
2494                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
2495                                                    1)), query.index() - 1);
2496    
2497                            if (orderByComparator != null) {
2498                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2499                                            orderByComparator);
2500                            }
2501                            else
2502                             if (pagination) {
2503                                    query.append(AssetTagModelImpl.ORDER_BY_JPQL);
2504                            }
2505    
2506                            String sql = query.toString();
2507    
2508                            Session session = null;
2509    
2510                            try {
2511                                    session = openSession();
2512    
2513                                    Query q = session.createQuery(sql);
2514    
2515                                    if (!pagination) {
2516                                            list = (List<AssetTag>)QueryUtil.list(q, getDialect(),
2517                                                            start, end, false);
2518    
2519                                            Collections.sort(list);
2520    
2521                                            list = Collections.unmodifiableList(list);
2522                                    }
2523                                    else {
2524                                            list = (List<AssetTag>)QueryUtil.list(q, getDialect(),
2525                                                            start, end);
2526                                    }
2527    
2528                                    cacheResult(list);
2529    
2530                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID,
2531                                            finderArgs, list);
2532                            }
2533                            catch (Exception e) {
2534                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID,
2535                                            finderArgs);
2536    
2537                                    throw processException(e);
2538                            }
2539                            finally {
2540                                    closeSession(session);
2541                            }
2542                    }
2543    
2544                    return list;
2545            }
2546    
2547            /**
2548             * Removes all the asset tags where groupId = &#63; from the database.
2549             *
2550             * @param groupId the group ID
2551             */
2552            @Override
2553            public void removeByGroupId(long groupId) {
2554                    for (AssetTag assetTag : findByGroupId(groupId, QueryUtil.ALL_POS,
2555                                    QueryUtil.ALL_POS, null)) {
2556                            remove(assetTag);
2557                    }
2558            }
2559    
2560            /**
2561             * Returns the number of asset tags where groupId = &#63;.
2562             *
2563             * @param groupId the group ID
2564             * @return the number of matching asset tags
2565             */
2566            @Override
2567            public int countByGroupId(long groupId) {
2568                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2569    
2570                    Object[] finderArgs = new Object[] { groupId };
2571    
2572                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2573    
2574                    if (count == null) {
2575                            StringBundler query = new StringBundler(2);
2576    
2577                            query.append(_SQL_COUNT_ASSETTAG_WHERE);
2578    
2579                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2580    
2581                            String sql = query.toString();
2582    
2583                            Session session = null;
2584    
2585                            try {
2586                                    session = openSession();
2587    
2588                                    Query q = session.createQuery(sql);
2589    
2590                                    QueryPos qPos = QueryPos.getInstance(q);
2591    
2592                                    qPos.add(groupId);
2593    
2594                                    count = (Long)q.uniqueResult();
2595    
2596                                    finderCache.putResult(finderPath, finderArgs, count);
2597                            }
2598                            catch (Exception e) {
2599                                    finderCache.removeResult(finderPath, finderArgs);
2600    
2601                                    throw processException(e);
2602                            }
2603                            finally {
2604                                    closeSession(session);
2605                            }
2606                    }
2607    
2608                    return count.intValue();
2609            }
2610    
2611            /**
2612             * Returns the number of asset tags where groupId = any &#63;.
2613             *
2614             * @param groupIds the group IDs
2615             * @return the number of matching asset tags
2616             */
2617            @Override
2618            public int countByGroupId(long[] groupIds) {
2619                    if (groupIds == null) {
2620                            groupIds = new long[0];
2621                    }
2622                    else if (groupIds.length > 1) {
2623                            groupIds = ArrayUtil.unique(groupIds);
2624    
2625                            Arrays.sort(groupIds);
2626                    }
2627    
2628                    Object[] finderArgs = new Object[] { StringUtil.merge(groupIds) };
2629    
2630                    Long count = (Long)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_GROUPID,
2631                                    finderArgs, this);
2632    
2633                    if (count == null) {
2634                            StringBundler query = new StringBundler();
2635    
2636                            query.append(_SQL_COUNT_ASSETTAG_WHERE);
2637    
2638                            if (groupIds.length > 0) {
2639                                    query.append(StringPool.OPEN_PARENTHESIS);
2640    
2641                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_7);
2642    
2643                                    query.append(StringUtil.merge(groupIds));
2644    
2645                                    query.append(StringPool.CLOSE_PARENTHESIS);
2646    
2647                                    query.append(StringPool.CLOSE_PARENTHESIS);
2648                            }
2649    
2650                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
2651                                                    1)), query.index() - 1);
2652    
2653                            String sql = query.toString();
2654    
2655                            Session session = null;
2656    
2657                            try {
2658                                    session = openSession();
2659    
2660                                    Query q = session.createQuery(sql);
2661    
2662                                    count = (Long)q.uniqueResult();
2663    
2664                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_GROUPID,
2665                                            finderArgs, count);
2666                            }
2667                            catch (Exception e) {
2668                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_GROUPID,
2669                                            finderArgs);
2670    
2671                                    throw processException(e);
2672                            }
2673                            finally {
2674                                    closeSession(session);
2675                            }
2676                    }
2677    
2678                    return count.intValue();
2679            }
2680    
2681            /**
2682             * Returns the number of asset tags that the user has permission to view where groupId = &#63;.
2683             *
2684             * @param groupId the group ID
2685             * @return the number of matching asset tags that the user has permission to view
2686             */
2687            @Override
2688            public int filterCountByGroupId(long groupId) {
2689                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2690                            return countByGroupId(groupId);
2691                    }
2692    
2693                    StringBundler query = new StringBundler(2);
2694    
2695                    query.append(_FILTER_SQL_COUNT_ASSETTAG_WHERE);
2696    
2697                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2698    
2699                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2700                                    AssetTag.class.getName(),
2701                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2702    
2703                    Session session = null;
2704    
2705                    try {
2706                            session = openSession();
2707    
2708                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
2709    
2710                            q.addScalar(COUNT_COLUMN_NAME,
2711                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2712    
2713                            QueryPos qPos = QueryPos.getInstance(q);
2714    
2715                            qPos.add(groupId);
2716    
2717                            Long count = (Long)q.uniqueResult();
2718    
2719                            return count.intValue();
2720                    }
2721                    catch (Exception e) {
2722                            throw processException(e);
2723                    }
2724                    finally {
2725                            closeSession(session);
2726                    }
2727            }
2728    
2729            /**
2730             * Returns the number of asset tags that the user has permission to view where groupId = any &#63;.
2731             *
2732             * @param groupIds the group IDs
2733             * @return the number of matching asset tags that the user has permission to view
2734             */
2735            @Override
2736            public int filterCountByGroupId(long[] groupIds) {
2737                    if (!InlineSQLHelperUtil.isEnabled(groupIds)) {
2738                            return countByGroupId(groupIds);
2739                    }
2740    
2741                    if (groupIds == null) {
2742                            groupIds = new long[0];
2743                    }
2744                    else if (groupIds.length > 1) {
2745                            groupIds = ArrayUtil.unique(groupIds);
2746    
2747                            Arrays.sort(groupIds);
2748                    }
2749    
2750                    StringBundler query = new StringBundler();
2751    
2752                    query.append(_FILTER_SQL_COUNT_ASSETTAG_WHERE);
2753    
2754                    if (groupIds.length > 0) {
2755                            query.append(StringPool.OPEN_PARENTHESIS);
2756    
2757                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_7);
2758    
2759                            query.append(StringUtil.merge(groupIds));
2760    
2761                            query.append(StringPool.CLOSE_PARENTHESIS);
2762    
2763                            query.append(StringPool.CLOSE_PARENTHESIS);
2764                    }
2765    
2766                    query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
2767                            query.index() - 1);
2768    
2769                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2770                                    AssetTag.class.getName(),
2771                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupIds);
2772    
2773                    Session session = null;
2774    
2775                    try {
2776                            session = openSession();
2777    
2778                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
2779    
2780                            q.addScalar(COUNT_COLUMN_NAME,
2781                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2782    
2783                            Long count = (Long)q.uniqueResult();
2784    
2785                            return count.intValue();
2786                    }
2787                    catch (Exception e) {
2788                            throw processException(e);
2789                    }
2790                    finally {
2791                            closeSession(session);
2792                    }
2793            }
2794    
2795            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "assetTag.groupId = ?";
2796            private static final String _FINDER_COLUMN_GROUPID_GROUPID_7 = "assetTag.groupId IN (";
2797            public static final FinderPath FINDER_PATH_FETCH_BY_G_N = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
2798                            AssetTagModelImpl.FINDER_CACHE_ENABLED, AssetTagImpl.class,
2799                            FINDER_CLASS_NAME_ENTITY, "fetchByG_N",
2800                            new String[] { Long.class.getName(), String.class.getName() },
2801                            AssetTagModelImpl.GROUPID_COLUMN_BITMASK |
2802                            AssetTagModelImpl.NAME_COLUMN_BITMASK);
2803            public static final FinderPath FINDER_PATH_COUNT_BY_G_N = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
2804                            AssetTagModelImpl.FINDER_CACHE_ENABLED, Long.class,
2805                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N",
2806                            new String[] { Long.class.getName(), String.class.getName() });
2807    
2808            /**
2809             * Returns the asset tag where groupId = &#63; and name = &#63; or throws a {@link NoSuchTagException} if it could not be found.
2810             *
2811             * @param groupId the group ID
2812             * @param name the name
2813             * @return the matching asset tag
2814             * @throws NoSuchTagException if a matching asset tag could not be found
2815             */
2816            @Override
2817            public AssetTag findByG_N(long groupId, String name)
2818                    throws NoSuchTagException {
2819                    AssetTag assetTag = fetchByG_N(groupId, name);
2820    
2821                    if (assetTag == null) {
2822                            StringBundler msg = new StringBundler(6);
2823    
2824                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2825    
2826                            msg.append("groupId=");
2827                            msg.append(groupId);
2828    
2829                            msg.append(", name=");
2830                            msg.append(name);
2831    
2832                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2833    
2834                            if (_log.isWarnEnabled()) {
2835                                    _log.warn(msg.toString());
2836                            }
2837    
2838                            throw new NoSuchTagException(msg.toString());
2839                    }
2840    
2841                    return assetTag;
2842            }
2843    
2844            /**
2845             * Returns the asset tag where groupId = &#63; and name = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
2846             *
2847             * @param groupId the group ID
2848             * @param name the name
2849             * @return the matching asset tag, or <code>null</code> if a matching asset tag could not be found
2850             */
2851            @Override
2852            public AssetTag fetchByG_N(long groupId, String name) {
2853                    return fetchByG_N(groupId, name, true);
2854            }
2855    
2856            /**
2857             * Returns the asset tag where groupId = &#63; and name = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
2858             *
2859             * @param groupId the group ID
2860             * @param name the name
2861             * @param retrieveFromCache whether to retrieve from the finder cache
2862             * @return the matching asset tag, or <code>null</code> if a matching asset tag could not be found
2863             */
2864            @Override
2865            public AssetTag fetchByG_N(long groupId, String name,
2866                    boolean retrieveFromCache) {
2867                    Object[] finderArgs = new Object[] { groupId, name };
2868    
2869                    Object result = null;
2870    
2871                    if (retrieveFromCache) {
2872                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_G_N,
2873                                            finderArgs, this);
2874                    }
2875    
2876                    if (result instanceof AssetTag) {
2877                            AssetTag assetTag = (AssetTag)result;
2878    
2879                            if ((groupId != assetTag.getGroupId()) ||
2880                                            !Validator.equals(name, assetTag.getName())) {
2881                                    result = null;
2882                            }
2883                    }
2884    
2885                    if (result == null) {
2886                            StringBundler query = new StringBundler(4);
2887    
2888                            query.append(_SQL_SELECT_ASSETTAG_WHERE);
2889    
2890                            query.append(_FINDER_COLUMN_G_N_GROUPID_2);
2891    
2892                            boolean bindName = false;
2893    
2894                            if (name == null) {
2895                                    query.append(_FINDER_COLUMN_G_N_NAME_1);
2896                            }
2897                            else if (name.equals(StringPool.BLANK)) {
2898                                    query.append(_FINDER_COLUMN_G_N_NAME_3);
2899                            }
2900                            else {
2901                                    bindName = true;
2902    
2903                                    query.append(_FINDER_COLUMN_G_N_NAME_2);
2904                            }
2905    
2906                            String sql = query.toString();
2907    
2908                            Session session = null;
2909    
2910                            try {
2911                                    session = openSession();
2912    
2913                                    Query q = session.createQuery(sql);
2914    
2915                                    QueryPos qPos = QueryPos.getInstance(q);
2916    
2917                                    qPos.add(groupId);
2918    
2919                                    if (bindName) {
2920                                            qPos.add(name);
2921                                    }
2922    
2923                                    List<AssetTag> list = q.list();
2924    
2925                                    if (list.isEmpty()) {
2926                                            finderCache.putResult(FINDER_PATH_FETCH_BY_G_N, finderArgs,
2927                                                    list);
2928                                    }
2929                                    else {
2930                                            AssetTag assetTag = list.get(0);
2931    
2932                                            result = assetTag;
2933    
2934                                            cacheResult(assetTag);
2935    
2936                                            if ((assetTag.getGroupId() != groupId) ||
2937                                                            (assetTag.getName() == null) ||
2938                                                            !assetTag.getName().equals(name)) {
2939                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_G_N,
2940                                                            finderArgs, assetTag);
2941                                            }
2942                                    }
2943                            }
2944                            catch (Exception e) {
2945                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_G_N, finderArgs);
2946    
2947                                    throw processException(e);
2948                            }
2949                            finally {
2950                                    closeSession(session);
2951                            }
2952                    }
2953    
2954                    if (result instanceof List<?>) {
2955                            return null;
2956                    }
2957                    else {
2958                            return (AssetTag)result;
2959                    }
2960            }
2961    
2962            /**
2963             * Removes the asset tag where groupId = &#63; and name = &#63; from the database.
2964             *
2965             * @param groupId the group ID
2966             * @param name the name
2967             * @return the asset tag that was removed
2968             */
2969            @Override
2970            public AssetTag removeByG_N(long groupId, String name)
2971                    throws NoSuchTagException {
2972                    AssetTag assetTag = findByG_N(groupId, name);
2973    
2974                    return remove(assetTag);
2975            }
2976    
2977            /**
2978             * Returns the number of asset tags where groupId = &#63; and name = &#63;.
2979             *
2980             * @param groupId the group ID
2981             * @param name the name
2982             * @return the number of matching asset tags
2983             */
2984            @Override
2985            public int countByG_N(long groupId, String name) {
2986                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_N;
2987    
2988                    Object[] finderArgs = new Object[] { groupId, name };
2989    
2990                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2991    
2992                    if (count == null) {
2993                            StringBundler query = new StringBundler(3);
2994    
2995                            query.append(_SQL_COUNT_ASSETTAG_WHERE);
2996    
2997                            query.append(_FINDER_COLUMN_G_N_GROUPID_2);
2998    
2999                            boolean bindName = false;
3000    
3001                            if (name == null) {
3002                                    query.append(_FINDER_COLUMN_G_N_NAME_1);
3003                            }
3004                            else if (name.equals(StringPool.BLANK)) {
3005                                    query.append(_FINDER_COLUMN_G_N_NAME_3);
3006                            }
3007                            else {
3008                                    bindName = true;
3009    
3010                                    query.append(_FINDER_COLUMN_G_N_NAME_2);
3011                            }
3012    
3013                            String sql = query.toString();
3014    
3015                            Session session = null;
3016    
3017                            try {
3018                                    session = openSession();
3019    
3020                                    Query q = session.createQuery(sql);
3021    
3022                                    QueryPos qPos = QueryPos.getInstance(q);
3023    
3024                                    qPos.add(groupId);
3025    
3026                                    if (bindName) {
3027                                            qPos.add(name);
3028                                    }
3029    
3030                                    count = (Long)q.uniqueResult();
3031    
3032                                    finderCache.putResult(finderPath, finderArgs, count);
3033                            }
3034                            catch (Exception e) {
3035                                    finderCache.removeResult(finderPath, finderArgs);
3036    
3037                                    throw processException(e);
3038                            }
3039                            finally {
3040                                    closeSession(session);
3041                            }
3042                    }
3043    
3044                    return count.intValue();
3045            }
3046    
3047            private static final String _FINDER_COLUMN_G_N_GROUPID_2 = "assetTag.groupId = ? AND ";
3048            private static final String _FINDER_COLUMN_G_N_NAME_1 = "assetTag.name IS NULL";
3049            private static final String _FINDER_COLUMN_G_N_NAME_2 = "assetTag.name = ?";
3050            private static final String _FINDER_COLUMN_G_N_NAME_3 = "(assetTag.name IS NULL OR assetTag.name = '')";
3051            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_LIKEN = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
3052                            AssetTagModelImpl.FINDER_CACHE_ENABLED, AssetTagImpl.class,
3053                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_LikeN",
3054                            new String[] {
3055                                    Long.class.getName(), String.class.getName(),
3056                                    
3057                            Integer.class.getName(), Integer.class.getName(),
3058                                    OrderByComparator.class.getName()
3059                            });
3060            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_LIKEN = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
3061                            AssetTagModelImpl.FINDER_CACHE_ENABLED, Long.class,
3062                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_LikeN",
3063                            new String[] { Long.class.getName(), String.class.getName() });
3064    
3065            /**
3066             * Returns all the asset tags where groupId = &#63; and name LIKE &#63;.
3067             *
3068             * @param groupId the group ID
3069             * @param name the name
3070             * @return the matching asset tags
3071             */
3072            @Override
3073            public List<AssetTag> findByG_LikeN(long groupId, String name) {
3074                    return findByG_LikeN(groupId, name, QueryUtil.ALL_POS,
3075                            QueryUtil.ALL_POS, null);
3076            }
3077    
3078            /**
3079             * Returns a range of all the asset tags where groupId = &#63; and name LIKE &#63;.
3080             *
3081             * <p>
3082             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. 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.
3083             * </p>
3084             *
3085             * @param groupId the group ID
3086             * @param name the name
3087             * @param start the lower bound of the range of asset tags
3088             * @param end the upper bound of the range of asset tags (not inclusive)
3089             * @return the range of matching asset tags
3090             */
3091            @Override
3092            public List<AssetTag> findByG_LikeN(long groupId, String name, int start,
3093                    int end) {
3094                    return findByG_LikeN(groupId, name, start, end, null);
3095            }
3096    
3097            /**
3098             * Returns an ordered range of all the asset tags where groupId = &#63; and name LIKE &#63;.
3099             *
3100             * <p>
3101             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. 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.
3102             * </p>
3103             *
3104             * @param groupId the group ID
3105             * @param name the name
3106             * @param start the lower bound of the range of asset tags
3107             * @param end the upper bound of the range of asset tags (not inclusive)
3108             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3109             * @return the ordered range of matching asset tags
3110             */
3111            @Override
3112            public List<AssetTag> findByG_LikeN(long groupId, String name, int start,
3113                    int end, OrderByComparator<AssetTag> orderByComparator) {
3114                    return findByG_LikeN(groupId, name, start, end, orderByComparator, true);
3115            }
3116    
3117            /**
3118             * Returns an ordered range of all the asset tags where groupId = &#63; and name LIKE &#63;.
3119             *
3120             * <p>
3121             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. 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.
3122             * </p>
3123             *
3124             * @param groupId the group ID
3125             * @param name the name
3126             * @param start the lower bound of the range of asset tags
3127             * @param end the upper bound of the range of asset tags (not inclusive)
3128             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3129             * @param retrieveFromCache whether to retrieve from the finder cache
3130             * @return the ordered range of matching asset tags
3131             */
3132            @Override
3133            public List<AssetTag> findByG_LikeN(long groupId, String name, int start,
3134                    int end, OrderByComparator<AssetTag> orderByComparator,
3135                    boolean retrieveFromCache) {
3136                    boolean pagination = true;
3137                    FinderPath finderPath = null;
3138                    Object[] finderArgs = null;
3139    
3140                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_LIKEN;
3141                    finderArgs = new Object[] { groupId, name, start, end, orderByComparator };
3142    
3143                    List<AssetTag> list = null;
3144    
3145                    if (retrieveFromCache) {
3146                            list = (List<AssetTag>)finderCache.getResult(finderPath,
3147                                            finderArgs, this);
3148    
3149                            if ((list != null) && !list.isEmpty()) {
3150                                    for (AssetTag assetTag : list) {
3151                                            if ((groupId != assetTag.getGroupId()) ||
3152                                                            !StringUtil.wildcardMatches(assetTag.getName(),
3153                                                                    name, CharPool.UNDERLINE, CharPool.PERCENT,
3154                                                                    CharPool.BACK_SLASH, true)) {
3155                                                    list = null;
3156    
3157                                                    break;
3158                                            }
3159                                    }
3160                            }
3161                    }
3162    
3163                    if (list == null) {
3164                            StringBundler query = null;
3165    
3166                            if (orderByComparator != null) {
3167                                    query = new StringBundler(4 +
3168                                                    (orderByComparator.getOrderByFields().length * 3));
3169                            }
3170                            else {
3171                                    query = new StringBundler(4);
3172                            }
3173    
3174                            query.append(_SQL_SELECT_ASSETTAG_WHERE);
3175    
3176                            query.append(_FINDER_COLUMN_G_LIKEN_GROUPID_2);
3177    
3178                            boolean bindName = false;
3179    
3180                            if (name == null) {
3181                                    query.append(_FINDER_COLUMN_G_LIKEN_NAME_1);
3182                            }
3183                            else if (name.equals(StringPool.BLANK)) {
3184                                    query.append(_FINDER_COLUMN_G_LIKEN_NAME_3);
3185                            }
3186                            else {
3187                                    bindName = true;
3188    
3189                                    query.append(_FINDER_COLUMN_G_LIKEN_NAME_2);
3190                            }
3191    
3192                            if (orderByComparator != null) {
3193                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3194                                            orderByComparator);
3195                            }
3196                            else
3197                             if (pagination) {
3198                                    query.append(AssetTagModelImpl.ORDER_BY_JPQL);
3199                            }
3200    
3201                            String sql = query.toString();
3202    
3203                            Session session = null;
3204    
3205                            try {
3206                                    session = openSession();
3207    
3208                                    Query q = session.createQuery(sql);
3209    
3210                                    QueryPos qPos = QueryPos.getInstance(q);
3211    
3212                                    qPos.add(groupId);
3213    
3214                                    if (bindName) {
3215                                            qPos.add(name);
3216                                    }
3217    
3218                                    if (!pagination) {
3219                                            list = (List<AssetTag>)QueryUtil.list(q, getDialect(),
3220                                                            start, end, false);
3221    
3222                                            Collections.sort(list);
3223    
3224                                            list = Collections.unmodifiableList(list);
3225                                    }
3226                                    else {
3227                                            list = (List<AssetTag>)QueryUtil.list(q, getDialect(),
3228                                                            start, end);
3229                                    }
3230    
3231                                    cacheResult(list);
3232    
3233                                    finderCache.putResult(finderPath, finderArgs, list);
3234                            }
3235                            catch (Exception e) {
3236                                    finderCache.removeResult(finderPath, finderArgs);
3237    
3238                                    throw processException(e);
3239                            }
3240                            finally {
3241                                    closeSession(session);
3242                            }
3243                    }
3244    
3245                    return list;
3246            }
3247    
3248            /**
3249             * Returns the first asset tag in the ordered set where groupId = &#63; and name LIKE &#63;.
3250             *
3251             * @param groupId the group ID
3252             * @param name the name
3253             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3254             * @return the first matching asset tag
3255             * @throws NoSuchTagException if a matching asset tag could not be found
3256             */
3257            @Override
3258            public AssetTag findByG_LikeN_First(long groupId, String name,
3259                    OrderByComparator<AssetTag> orderByComparator)
3260                    throws NoSuchTagException {
3261                    AssetTag assetTag = fetchByG_LikeN_First(groupId, name,
3262                                    orderByComparator);
3263    
3264                    if (assetTag != null) {
3265                            return assetTag;
3266                    }
3267    
3268                    StringBundler msg = new StringBundler(6);
3269    
3270                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3271    
3272                    msg.append("groupId=");
3273                    msg.append(groupId);
3274    
3275                    msg.append(", name=");
3276                    msg.append(name);
3277    
3278                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3279    
3280                    throw new NoSuchTagException(msg.toString());
3281            }
3282    
3283            /**
3284             * Returns the first asset tag in the ordered set where groupId = &#63; and name LIKE &#63;.
3285             *
3286             * @param groupId the group ID
3287             * @param name the name
3288             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3289             * @return the first matching asset tag, or <code>null</code> if a matching asset tag could not be found
3290             */
3291            @Override
3292            public AssetTag fetchByG_LikeN_First(long groupId, String name,
3293                    OrderByComparator<AssetTag> orderByComparator) {
3294                    List<AssetTag> list = findByG_LikeN(groupId, name, 0, 1,
3295                                    orderByComparator);
3296    
3297                    if (!list.isEmpty()) {
3298                            return list.get(0);
3299                    }
3300    
3301                    return null;
3302            }
3303    
3304            /**
3305             * Returns the last asset tag in the ordered set where groupId = &#63; and name LIKE &#63;.
3306             *
3307             * @param groupId the group ID
3308             * @param name the name
3309             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3310             * @return the last matching asset tag
3311             * @throws NoSuchTagException if a matching asset tag could not be found
3312             */
3313            @Override
3314            public AssetTag findByG_LikeN_Last(long groupId, String name,
3315                    OrderByComparator<AssetTag> orderByComparator)
3316                    throws NoSuchTagException {
3317                    AssetTag assetTag = fetchByG_LikeN_Last(groupId, name, orderByComparator);
3318    
3319                    if (assetTag != null) {
3320                            return assetTag;
3321                    }
3322    
3323                    StringBundler msg = new StringBundler(6);
3324    
3325                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3326    
3327                    msg.append("groupId=");
3328                    msg.append(groupId);
3329    
3330                    msg.append(", name=");
3331                    msg.append(name);
3332    
3333                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3334    
3335                    throw new NoSuchTagException(msg.toString());
3336            }
3337    
3338            /**
3339             * Returns the last asset tag in the ordered set where groupId = &#63; and name LIKE &#63;.
3340             *
3341             * @param groupId the group ID
3342             * @param name the name
3343             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3344             * @return the last matching asset tag, or <code>null</code> if a matching asset tag could not be found
3345             */
3346            @Override
3347            public AssetTag fetchByG_LikeN_Last(long groupId, String name,
3348                    OrderByComparator<AssetTag> orderByComparator) {
3349                    int count = countByG_LikeN(groupId, name);
3350    
3351                    if (count == 0) {
3352                            return null;
3353                    }
3354    
3355                    List<AssetTag> list = findByG_LikeN(groupId, name, count - 1, count,
3356                                    orderByComparator);
3357    
3358                    if (!list.isEmpty()) {
3359                            return list.get(0);
3360                    }
3361    
3362                    return null;
3363            }
3364    
3365            /**
3366             * Returns the asset tags before and after the current asset tag in the ordered set where groupId = &#63; and name LIKE &#63;.
3367             *
3368             * @param tagId the primary key of the current asset tag
3369             * @param groupId the group ID
3370             * @param name the name
3371             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3372             * @return the previous, current, and next asset tag
3373             * @throws NoSuchTagException if a asset tag with the primary key could not be found
3374             */
3375            @Override
3376            public AssetTag[] findByG_LikeN_PrevAndNext(long tagId, long groupId,
3377                    String name, OrderByComparator<AssetTag> orderByComparator)
3378                    throws NoSuchTagException {
3379                    AssetTag assetTag = findByPrimaryKey(tagId);
3380    
3381                    Session session = null;
3382    
3383                    try {
3384                            session = openSession();
3385    
3386                            AssetTag[] array = new AssetTagImpl[3];
3387    
3388                            array[0] = getByG_LikeN_PrevAndNext(session, assetTag, groupId,
3389                                            name, orderByComparator, true);
3390    
3391                            array[1] = assetTag;
3392    
3393                            array[2] = getByG_LikeN_PrevAndNext(session, assetTag, groupId,
3394                                            name, orderByComparator, false);
3395    
3396                            return array;
3397                    }
3398                    catch (Exception e) {
3399                            throw processException(e);
3400                    }
3401                    finally {
3402                            closeSession(session);
3403                    }
3404            }
3405    
3406            protected AssetTag getByG_LikeN_PrevAndNext(Session session,
3407                    AssetTag assetTag, long groupId, String name,
3408                    OrderByComparator<AssetTag> orderByComparator, boolean previous) {
3409                    StringBundler query = null;
3410    
3411                    if (orderByComparator != null) {
3412                            query = new StringBundler(6 +
3413                                            (orderByComparator.getOrderByFields().length * 6));
3414                    }
3415                    else {
3416                            query = new StringBundler(3);
3417                    }
3418    
3419                    query.append(_SQL_SELECT_ASSETTAG_WHERE);
3420    
3421                    query.append(_FINDER_COLUMN_G_LIKEN_GROUPID_2);
3422    
3423                    boolean bindName = false;
3424    
3425                    if (name == null) {
3426                            query.append(_FINDER_COLUMN_G_LIKEN_NAME_1);
3427                    }
3428                    else if (name.equals(StringPool.BLANK)) {
3429                            query.append(_FINDER_COLUMN_G_LIKEN_NAME_3);
3430                    }
3431                    else {
3432                            bindName = true;
3433    
3434                            query.append(_FINDER_COLUMN_G_LIKEN_NAME_2);
3435                    }
3436    
3437                    if (orderByComparator != null) {
3438                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3439    
3440                            if (orderByConditionFields.length > 0) {
3441                                    query.append(WHERE_AND);
3442                            }
3443    
3444                            for (int i = 0; i < orderByConditionFields.length; i++) {
3445                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3446                                    query.append(orderByConditionFields[i]);
3447    
3448                                    if ((i + 1) < orderByConditionFields.length) {
3449                                            if (orderByComparator.isAscending() ^ previous) {
3450                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3451                                            }
3452                                            else {
3453                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3454                                            }
3455                                    }
3456                                    else {
3457                                            if (orderByComparator.isAscending() ^ previous) {
3458                                                    query.append(WHERE_GREATER_THAN);
3459                                            }
3460                                            else {
3461                                                    query.append(WHERE_LESSER_THAN);
3462                                            }
3463                                    }
3464                            }
3465    
3466                            query.append(ORDER_BY_CLAUSE);
3467    
3468                            String[] orderByFields = orderByComparator.getOrderByFields();
3469    
3470                            for (int i = 0; i < orderByFields.length; i++) {
3471                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3472                                    query.append(orderByFields[i]);
3473    
3474                                    if ((i + 1) < orderByFields.length) {
3475                                            if (orderByComparator.isAscending() ^ previous) {
3476                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3477                                            }
3478                                            else {
3479                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3480                                            }
3481                                    }
3482                                    else {
3483                                            if (orderByComparator.isAscending() ^ previous) {
3484                                                    query.append(ORDER_BY_ASC);
3485                                            }
3486                                            else {
3487                                                    query.append(ORDER_BY_DESC);
3488                                            }
3489                                    }
3490                            }
3491                    }
3492                    else {
3493                            query.append(AssetTagModelImpl.ORDER_BY_JPQL);
3494                    }
3495    
3496                    String sql = query.toString();
3497    
3498                    Query q = session.createQuery(sql);
3499    
3500                    q.setFirstResult(0);
3501                    q.setMaxResults(2);
3502    
3503                    QueryPos qPos = QueryPos.getInstance(q);
3504    
3505                    qPos.add(groupId);
3506    
3507                    if (bindName) {
3508                            qPos.add(name);
3509                    }
3510    
3511                    if (orderByComparator != null) {
3512                            Object[] values = orderByComparator.getOrderByConditionValues(assetTag);
3513    
3514                            for (Object value : values) {
3515                                    qPos.add(value);
3516                            }
3517                    }
3518    
3519                    List<AssetTag> list = q.list();
3520    
3521                    if (list.size() == 2) {
3522                            return list.get(1);
3523                    }
3524                    else {
3525                            return null;
3526                    }
3527            }
3528    
3529            /**
3530             * Returns all the asset tags that the user has permission to view where groupId = &#63; and name LIKE &#63;.
3531             *
3532             * @param groupId the group ID
3533             * @param name the name
3534             * @return the matching asset tags that the user has permission to view
3535             */
3536            @Override
3537            public List<AssetTag> filterFindByG_LikeN(long groupId, String name) {
3538                    return filterFindByG_LikeN(groupId, name, QueryUtil.ALL_POS,
3539                            QueryUtil.ALL_POS, null);
3540            }
3541    
3542            /**
3543             * Returns a range of all the asset tags that the user has permission to view where groupId = &#63; and name LIKE &#63;.
3544             *
3545             * <p>
3546             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. 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.
3547             * </p>
3548             *
3549             * @param groupId the group ID
3550             * @param name the name
3551             * @param start the lower bound of the range of asset tags
3552             * @param end the upper bound of the range of asset tags (not inclusive)
3553             * @return the range of matching asset tags that the user has permission to view
3554             */
3555            @Override
3556            public List<AssetTag> filterFindByG_LikeN(long groupId, String name,
3557                    int start, int end) {
3558                    return filterFindByG_LikeN(groupId, name, start, end, null);
3559            }
3560    
3561            /**
3562             * Returns an ordered range of all the asset tags that the user has permissions to view where groupId = &#63; and name LIKE &#63;.
3563             *
3564             * <p>
3565             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. 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.
3566             * </p>
3567             *
3568             * @param groupId the group ID
3569             * @param name the name
3570             * @param start the lower bound of the range of asset tags
3571             * @param end the upper bound of the range of asset tags (not inclusive)
3572             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3573             * @return the ordered range of matching asset tags that the user has permission to view
3574             */
3575            @Override
3576            public List<AssetTag> filterFindByG_LikeN(long groupId, String name,
3577                    int start, int end, OrderByComparator<AssetTag> orderByComparator) {
3578                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3579                            return findByG_LikeN(groupId, name, start, end, orderByComparator);
3580                    }
3581    
3582                    StringBundler query = null;
3583    
3584                    if (orderByComparator != null) {
3585                            query = new StringBundler(4 +
3586                                            (orderByComparator.getOrderByFields().length * 3));
3587                    }
3588                    else {
3589                            query = new StringBundler(4);
3590                    }
3591    
3592                    if (getDB().isSupportsInlineDistinct()) {
3593                            query.append(_FILTER_SQL_SELECT_ASSETTAG_WHERE);
3594                    }
3595                    else {
3596                            query.append(_FILTER_SQL_SELECT_ASSETTAG_NO_INLINE_DISTINCT_WHERE_1);
3597                    }
3598    
3599                    query.append(_FINDER_COLUMN_G_LIKEN_GROUPID_2);
3600    
3601                    boolean bindName = false;
3602    
3603                    if (name == null) {
3604                            query.append(_FINDER_COLUMN_G_LIKEN_NAME_1);
3605                    }
3606                    else if (name.equals(StringPool.BLANK)) {
3607                            query.append(_FINDER_COLUMN_G_LIKEN_NAME_3);
3608                    }
3609                    else {
3610                            bindName = true;
3611    
3612                            query.append(_FINDER_COLUMN_G_LIKEN_NAME_2);
3613                    }
3614    
3615                    if (!getDB().isSupportsInlineDistinct()) {
3616                            query.append(_FILTER_SQL_SELECT_ASSETTAG_NO_INLINE_DISTINCT_WHERE_2);
3617                    }
3618    
3619                    if (orderByComparator != null) {
3620                            if (getDB().isSupportsInlineDistinct()) {
3621                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3622                                            orderByComparator, true);
3623                            }
3624                            else {
3625                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3626                                            orderByComparator, true);
3627                            }
3628                    }
3629                    else {
3630                            if (getDB().isSupportsInlineDistinct()) {
3631                                    query.append(AssetTagModelImpl.ORDER_BY_JPQL);
3632                            }
3633                            else {
3634                                    query.append(AssetTagModelImpl.ORDER_BY_SQL);
3635                            }
3636                    }
3637    
3638                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3639                                    AssetTag.class.getName(),
3640                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3641    
3642                    Session session = null;
3643    
3644                    try {
3645                            session = openSession();
3646    
3647                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
3648    
3649                            if (getDB().isSupportsInlineDistinct()) {
3650                                    q.addEntity(_FILTER_ENTITY_ALIAS, AssetTagImpl.class);
3651                            }
3652                            else {
3653                                    q.addEntity(_FILTER_ENTITY_TABLE, AssetTagImpl.class);
3654                            }
3655    
3656                            QueryPos qPos = QueryPos.getInstance(q);
3657    
3658                            qPos.add(groupId);
3659    
3660                            if (bindName) {
3661                                    qPos.add(name);
3662                            }
3663    
3664                            return (List<AssetTag>)QueryUtil.list(q, getDialect(), start, end);
3665                    }
3666                    catch (Exception e) {
3667                            throw processException(e);
3668                    }
3669                    finally {
3670                            closeSession(session);
3671                    }
3672            }
3673    
3674            /**
3675             * Returns the asset tags before and after the current asset tag in the ordered set of asset tags that the user has permission to view where groupId = &#63; and name LIKE &#63;.
3676             *
3677             * @param tagId the primary key of the current asset tag
3678             * @param groupId the group ID
3679             * @param name the name
3680             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3681             * @return the previous, current, and next asset tag
3682             * @throws NoSuchTagException if a asset tag with the primary key could not be found
3683             */
3684            @Override
3685            public AssetTag[] filterFindByG_LikeN_PrevAndNext(long tagId, long groupId,
3686                    String name, OrderByComparator<AssetTag> orderByComparator)
3687                    throws NoSuchTagException {
3688                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3689                            return findByG_LikeN_PrevAndNext(tagId, groupId, name,
3690                                    orderByComparator);
3691                    }
3692    
3693                    AssetTag assetTag = findByPrimaryKey(tagId);
3694    
3695                    Session session = null;
3696    
3697                    try {
3698                            session = openSession();
3699    
3700                            AssetTag[] array = new AssetTagImpl[3];
3701    
3702                            array[0] = filterGetByG_LikeN_PrevAndNext(session, assetTag,
3703                                            groupId, name, orderByComparator, true);
3704    
3705                            array[1] = assetTag;
3706    
3707                            array[2] = filterGetByG_LikeN_PrevAndNext(session, assetTag,
3708                                            groupId, name, orderByComparator, false);
3709    
3710                            return array;
3711                    }
3712                    catch (Exception e) {
3713                            throw processException(e);
3714                    }
3715                    finally {
3716                            closeSession(session);
3717                    }
3718            }
3719    
3720            protected AssetTag filterGetByG_LikeN_PrevAndNext(Session session,
3721                    AssetTag assetTag, long groupId, String name,
3722                    OrderByComparator<AssetTag> orderByComparator, boolean previous) {
3723                    StringBundler query = null;
3724    
3725                    if (orderByComparator != null) {
3726                            query = new StringBundler(6 +
3727                                            (orderByComparator.getOrderByFields().length * 6));
3728                    }
3729                    else {
3730                            query = new StringBundler(3);
3731                    }
3732    
3733                    if (getDB().isSupportsInlineDistinct()) {
3734                            query.append(_FILTER_SQL_SELECT_ASSETTAG_WHERE);
3735                    }
3736                    else {
3737                            query.append(_FILTER_SQL_SELECT_ASSETTAG_NO_INLINE_DISTINCT_WHERE_1);
3738                    }
3739    
3740                    query.append(_FINDER_COLUMN_G_LIKEN_GROUPID_2);
3741    
3742                    boolean bindName = false;
3743    
3744                    if (name == null) {
3745                            query.append(_FINDER_COLUMN_G_LIKEN_NAME_1);
3746                    }
3747                    else if (name.equals(StringPool.BLANK)) {
3748                            query.append(_FINDER_COLUMN_G_LIKEN_NAME_3);
3749                    }
3750                    else {
3751                            bindName = true;
3752    
3753                            query.append(_FINDER_COLUMN_G_LIKEN_NAME_2);
3754                    }
3755    
3756                    if (!getDB().isSupportsInlineDistinct()) {
3757                            query.append(_FILTER_SQL_SELECT_ASSETTAG_NO_INLINE_DISTINCT_WHERE_2);
3758                    }
3759    
3760                    if (orderByComparator != null) {
3761                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3762    
3763                            if (orderByConditionFields.length > 0) {
3764                                    query.append(WHERE_AND);
3765                            }
3766    
3767                            for (int i = 0; i < orderByConditionFields.length; i++) {
3768                                    if (getDB().isSupportsInlineDistinct()) {
3769                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3770                                    }
3771                                    else {
3772                                            query.append(_ORDER_BY_ENTITY_TABLE);
3773                                    }
3774    
3775                                    query.append(orderByConditionFields[i]);
3776    
3777                                    if ((i + 1) < orderByConditionFields.length) {
3778                                            if (orderByComparator.isAscending() ^ previous) {
3779                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3780                                            }
3781                                            else {
3782                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3783                                            }
3784                                    }
3785                                    else {
3786                                            if (orderByComparator.isAscending() ^ previous) {
3787                                                    query.append(WHERE_GREATER_THAN);
3788                                            }
3789                                            else {
3790                                                    query.append(WHERE_LESSER_THAN);
3791                                            }
3792                                    }
3793                            }
3794    
3795                            query.append(ORDER_BY_CLAUSE);
3796    
3797                            String[] orderByFields = orderByComparator.getOrderByFields();
3798    
3799                            for (int i = 0; i < orderByFields.length; i++) {
3800                                    if (getDB().isSupportsInlineDistinct()) {
3801                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3802                                    }
3803                                    else {
3804                                            query.append(_ORDER_BY_ENTITY_TABLE);
3805                                    }
3806    
3807                                    query.append(orderByFields[i]);
3808    
3809                                    if ((i + 1) < orderByFields.length) {
3810                                            if (orderByComparator.isAscending() ^ previous) {
3811                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3812                                            }
3813                                            else {
3814                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3815                                            }
3816                                    }
3817                                    else {
3818                                            if (orderByComparator.isAscending() ^ previous) {
3819                                                    query.append(ORDER_BY_ASC);
3820                                            }
3821                                            else {
3822                                                    query.append(ORDER_BY_DESC);
3823                                            }
3824                                    }
3825                            }
3826                    }
3827                    else {
3828                            if (getDB().isSupportsInlineDistinct()) {
3829                                    query.append(AssetTagModelImpl.ORDER_BY_JPQL);
3830                            }
3831                            else {
3832                                    query.append(AssetTagModelImpl.ORDER_BY_SQL);
3833                            }
3834                    }
3835    
3836                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3837                                    AssetTag.class.getName(),
3838                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3839    
3840                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
3841    
3842                    q.setFirstResult(0);
3843                    q.setMaxResults(2);
3844    
3845                    if (getDB().isSupportsInlineDistinct()) {
3846                            q.addEntity(_FILTER_ENTITY_ALIAS, AssetTagImpl.class);
3847                    }
3848                    else {
3849                            q.addEntity(_FILTER_ENTITY_TABLE, AssetTagImpl.class);
3850                    }
3851    
3852                    QueryPos qPos = QueryPos.getInstance(q);
3853    
3854                    qPos.add(groupId);
3855    
3856                    if (bindName) {
3857                            qPos.add(name);
3858                    }
3859    
3860                    if (orderByComparator != null) {
3861                            Object[] values = orderByComparator.getOrderByConditionValues(assetTag);
3862    
3863                            for (Object value : values) {
3864                                    qPos.add(value);
3865                            }
3866                    }
3867    
3868                    List<AssetTag> list = q.list();
3869    
3870                    if (list.size() == 2) {
3871                            return list.get(1);
3872                    }
3873                    else {
3874                            return null;
3875                    }
3876            }
3877    
3878            /**
3879             * Returns all the asset tags that the user has permission to view where groupId = any &#63; and name LIKE &#63;.
3880             *
3881             * @param groupIds the group IDs
3882             * @param name the name
3883             * @return the matching asset tags that the user has permission to view
3884             */
3885            @Override
3886            public List<AssetTag> filterFindByG_LikeN(long[] groupIds, String name) {
3887                    return filterFindByG_LikeN(groupIds, name, QueryUtil.ALL_POS,
3888                            QueryUtil.ALL_POS, null);
3889            }
3890    
3891            /**
3892             * Returns a range of all the asset tags that the user has permission to view where groupId = any &#63; and name LIKE &#63;.
3893             *
3894             * <p>
3895             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. 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.
3896             * </p>
3897             *
3898             * @param groupIds the group IDs
3899             * @param name the name
3900             * @param start the lower bound of the range of asset tags
3901             * @param end the upper bound of the range of asset tags (not inclusive)
3902             * @return the range of matching asset tags that the user has permission to view
3903             */
3904            @Override
3905            public List<AssetTag> filterFindByG_LikeN(long[] groupIds, String name,
3906                    int start, int end) {
3907                    return filterFindByG_LikeN(groupIds, name, start, end, null);
3908            }
3909    
3910            /**
3911             * Returns an ordered range of all the asset tags that the user has permission to view where groupId = any &#63; and name LIKE &#63;.
3912             *
3913             * <p>
3914             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. 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.
3915             * </p>
3916             *
3917             * @param groupIds the group IDs
3918             * @param name the name
3919             * @param start the lower bound of the range of asset tags
3920             * @param end the upper bound of the range of asset tags (not inclusive)
3921             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3922             * @return the ordered range of matching asset tags that the user has permission to view
3923             */
3924            @Override
3925            public List<AssetTag> filterFindByG_LikeN(long[] groupIds, String name,
3926                    int start, int end, OrderByComparator<AssetTag> orderByComparator) {
3927                    if (!InlineSQLHelperUtil.isEnabled(groupIds)) {
3928                            return findByG_LikeN(groupIds, name, start, end, orderByComparator);
3929                    }
3930    
3931                    if (groupIds == null) {
3932                            groupIds = new long[0];
3933                    }
3934                    else if (groupIds.length > 1) {
3935                            groupIds = ArrayUtil.unique(groupIds);
3936    
3937                            Arrays.sort(groupIds);
3938                    }
3939    
3940                    StringBundler query = new StringBundler();
3941    
3942                    if (getDB().isSupportsInlineDistinct()) {
3943                            query.append(_FILTER_SQL_SELECT_ASSETTAG_WHERE);
3944                    }
3945                    else {
3946                            query.append(_FILTER_SQL_SELECT_ASSETTAG_NO_INLINE_DISTINCT_WHERE_1);
3947                    }
3948    
3949                    if (groupIds.length > 0) {
3950                            query.append(StringPool.OPEN_PARENTHESIS);
3951    
3952                            query.append(_FINDER_COLUMN_G_LIKEN_GROUPID_7);
3953    
3954                            query.append(StringUtil.merge(groupIds));
3955    
3956                            query.append(StringPool.CLOSE_PARENTHESIS);
3957    
3958                            query.append(StringPool.CLOSE_PARENTHESIS);
3959    
3960                            query.append(WHERE_AND);
3961                    }
3962    
3963                    boolean bindName = false;
3964    
3965                    if (name == null) {
3966                            query.append(_FINDER_COLUMN_G_LIKEN_NAME_1);
3967                    }
3968                    else if (name.equals(StringPool.BLANK)) {
3969                            query.append(_FINDER_COLUMN_G_LIKEN_NAME_3);
3970                    }
3971                    else {
3972                            bindName = true;
3973    
3974                            query.append(_FINDER_COLUMN_G_LIKEN_NAME_2);
3975                    }
3976    
3977                    query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
3978                            query.index() - 1);
3979    
3980                    if (!getDB().isSupportsInlineDistinct()) {
3981                            query.append(_FILTER_SQL_SELECT_ASSETTAG_NO_INLINE_DISTINCT_WHERE_2);
3982                    }
3983    
3984                    if (orderByComparator != null) {
3985                            if (getDB().isSupportsInlineDistinct()) {
3986                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3987                                            orderByComparator, true);
3988                            }
3989                            else {
3990                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3991                                            orderByComparator, true);
3992                            }
3993                    }
3994                    else {
3995                            if (getDB().isSupportsInlineDistinct()) {
3996                                    query.append(AssetTagModelImpl.ORDER_BY_JPQL);
3997                            }
3998                            else {
3999                                    query.append(AssetTagModelImpl.ORDER_BY_SQL);
4000                            }
4001                    }
4002    
4003                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4004                                    AssetTag.class.getName(),
4005                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupIds);
4006    
4007                    Session session = null;
4008    
4009                    try {
4010                            session = openSession();
4011    
4012                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
4013    
4014                            if (getDB().isSupportsInlineDistinct()) {
4015                                    q.addEntity(_FILTER_ENTITY_ALIAS, AssetTagImpl.class);
4016                            }
4017                            else {
4018                                    q.addEntity(_FILTER_ENTITY_TABLE, AssetTagImpl.class);
4019                            }
4020    
4021                            QueryPos qPos = QueryPos.getInstance(q);
4022    
4023                            if (bindName) {
4024                                    qPos.add(name);
4025                            }
4026    
4027                            return (List<AssetTag>)QueryUtil.list(q, getDialect(), start, end);
4028                    }
4029                    catch (Exception e) {
4030                            throw processException(e);
4031                    }
4032                    finally {
4033                            closeSession(session);
4034                    }
4035            }
4036    
4037            /**
4038             * Returns all the asset tags where groupId = any &#63; and name LIKE &#63;.
4039             *
4040             * <p>
4041             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. 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.
4042             * </p>
4043             *
4044             * @param groupIds the group IDs
4045             * @param name the name
4046             * @return the matching asset tags
4047             */
4048            @Override
4049            public List<AssetTag> findByG_LikeN(long[] groupIds, String name) {
4050                    return findByG_LikeN(groupIds, name, QueryUtil.ALL_POS,
4051                            QueryUtil.ALL_POS, null);
4052            }
4053    
4054            /**
4055             * Returns a range of all the asset tags where groupId = any &#63; and name LIKE &#63;.
4056             *
4057             * <p>
4058             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. 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.
4059             * </p>
4060             *
4061             * @param groupIds the group IDs
4062             * @param name the name
4063             * @param start the lower bound of the range of asset tags
4064             * @param end the upper bound of the range of asset tags (not inclusive)
4065             * @return the range of matching asset tags
4066             */
4067            @Override
4068            public List<AssetTag> findByG_LikeN(long[] groupIds, String name,
4069                    int start, int end) {
4070                    return findByG_LikeN(groupIds, name, start, end, null);
4071            }
4072    
4073            /**
4074             * Returns an ordered range of all the asset tags where groupId = any &#63; and name LIKE &#63;.
4075             *
4076             * <p>
4077             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. 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.
4078             * </p>
4079             *
4080             * @param groupIds the group IDs
4081             * @param name the name
4082             * @param start the lower bound of the range of asset tags
4083             * @param end the upper bound of the range of asset tags (not inclusive)
4084             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4085             * @return the ordered range of matching asset tags
4086             */
4087            @Override
4088            public List<AssetTag> findByG_LikeN(long[] groupIds, String name,
4089                    int start, int end, OrderByComparator<AssetTag> orderByComparator) {
4090                    return findByG_LikeN(groupIds, name, start, end, orderByComparator, true);
4091            }
4092    
4093            /**
4094             * Returns an ordered range of all the asset tags where groupId = &#63; and name LIKE &#63;, optionally using the finder cache.
4095             *
4096             * <p>
4097             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. 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.
4098             * </p>
4099             *
4100             * @param groupId the group ID
4101             * @param name the name
4102             * @param start the lower bound of the range of asset tags
4103             * @param end the upper bound of the range of asset tags (not inclusive)
4104             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4105             * @param retrieveFromCache whether to retrieve from the finder cache
4106             * @return the ordered range of matching asset tags
4107             */
4108            @Override
4109            public List<AssetTag> findByG_LikeN(long[] groupIds, String name,
4110                    int start, int end, OrderByComparator<AssetTag> orderByComparator,
4111                    boolean retrieveFromCache) {
4112                    if (groupIds == null) {
4113                            groupIds = new long[0];
4114                    }
4115                    else if (groupIds.length > 1) {
4116                            groupIds = ArrayUtil.unique(groupIds);
4117    
4118                            Arrays.sort(groupIds);
4119                    }
4120    
4121                    if (groupIds.length == 1) {
4122                            return findByG_LikeN(groupIds[0], name, start, end,
4123                                    orderByComparator);
4124                    }
4125    
4126                    boolean pagination = true;
4127                    Object[] finderArgs = null;
4128    
4129                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4130                                    (orderByComparator == null)) {
4131                            pagination = false;
4132                            finderArgs = new Object[] { StringUtil.merge(groupIds), name };
4133                    }
4134                    else {
4135                            finderArgs = new Object[] {
4136                                            StringUtil.merge(groupIds), name,
4137                                            
4138                                            start, end, orderByComparator
4139                                    };
4140                    }
4141    
4142                    List<AssetTag> list = null;
4143    
4144                    if (retrieveFromCache) {
4145                            list = (List<AssetTag>)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_LIKEN,
4146                                            finderArgs, this);
4147    
4148                            if ((list != null) && !list.isEmpty()) {
4149                                    for (AssetTag assetTag : list) {
4150                                            if (!ArrayUtil.contains(groupIds, assetTag.getGroupId()) ||
4151                                                            !StringUtil.wildcardMatches(assetTag.getName(),
4152                                                                    name, CharPool.UNDERLINE, CharPool.PERCENT,
4153                                                                    CharPool.BACK_SLASH, true)) {
4154                                                    list = null;
4155    
4156                                                    break;
4157                                            }
4158                                    }
4159                            }
4160                    }
4161    
4162                    if (list == null) {
4163                            StringBundler query = new StringBundler();
4164    
4165                            query.append(_SQL_SELECT_ASSETTAG_WHERE);
4166    
4167                            if (groupIds.length > 0) {
4168                                    query.append(StringPool.OPEN_PARENTHESIS);
4169    
4170                                    query.append(_FINDER_COLUMN_G_LIKEN_GROUPID_7);
4171    
4172                                    query.append(StringUtil.merge(groupIds));
4173    
4174                                    query.append(StringPool.CLOSE_PARENTHESIS);
4175    
4176                                    query.append(StringPool.CLOSE_PARENTHESIS);
4177    
4178                                    query.append(WHERE_AND);
4179                            }
4180    
4181                            boolean bindName = false;
4182    
4183                            if (name == null) {
4184                                    query.append(_FINDER_COLUMN_G_LIKEN_NAME_1);
4185                            }
4186                            else if (name.equals(StringPool.BLANK)) {
4187                                    query.append(_FINDER_COLUMN_G_LIKEN_NAME_3);
4188                            }
4189                            else {
4190                                    bindName = true;
4191    
4192                                    query.append(_FINDER_COLUMN_G_LIKEN_NAME_2);
4193                            }
4194    
4195                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
4196                                                    1)), query.index() - 1);
4197    
4198                            if (orderByComparator != null) {
4199                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4200                                            orderByComparator);
4201                            }
4202                            else
4203                             if (pagination) {
4204                                    query.append(AssetTagModelImpl.ORDER_BY_JPQL);
4205                            }
4206    
4207                            String sql = query.toString();
4208    
4209                            Session session = null;
4210    
4211                            try {
4212                                    session = openSession();
4213    
4214                                    Query q = session.createQuery(sql);
4215    
4216                                    QueryPos qPos = QueryPos.getInstance(q);
4217    
4218                                    if (bindName) {
4219                                            qPos.add(name);
4220                                    }
4221    
4222                                    if (!pagination) {
4223                                            list = (List<AssetTag>)QueryUtil.list(q, getDialect(),
4224                                                            start, end, false);
4225    
4226                                            Collections.sort(list);
4227    
4228                                            list = Collections.unmodifiableList(list);
4229                                    }
4230                                    else {
4231                                            list = (List<AssetTag>)QueryUtil.list(q, getDialect(),
4232                                                            start, end);
4233                                    }
4234    
4235                                    cacheResult(list);
4236    
4237                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_LIKEN,
4238                                            finderArgs, list);
4239                            }
4240                            catch (Exception e) {
4241                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_LIKEN,
4242                                            finderArgs);
4243    
4244                                    throw processException(e);
4245                            }
4246                            finally {
4247                                    closeSession(session);
4248                            }
4249                    }
4250    
4251                    return list;
4252            }
4253    
4254            /**
4255             * Removes all the asset tags where groupId = &#63; and name LIKE &#63; from the database.
4256             *
4257             * @param groupId the group ID
4258             * @param name the name
4259             */
4260            @Override
4261            public void removeByG_LikeN(long groupId, String name) {
4262                    for (AssetTag assetTag : findByG_LikeN(groupId, name,
4263                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4264                            remove(assetTag);
4265                    }
4266            }
4267    
4268            /**
4269             * Returns the number of asset tags where groupId = &#63; and name LIKE &#63;.
4270             *
4271             * @param groupId the group ID
4272             * @param name the name
4273             * @return the number of matching asset tags
4274             */
4275            @Override
4276            public int countByG_LikeN(long groupId, String name) {
4277                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_LIKEN;
4278    
4279                    Object[] finderArgs = new Object[] { groupId, name };
4280    
4281                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
4282    
4283                    if (count == null) {
4284                            StringBundler query = new StringBundler(3);
4285    
4286                            query.append(_SQL_COUNT_ASSETTAG_WHERE);
4287    
4288                            query.append(_FINDER_COLUMN_G_LIKEN_GROUPID_2);
4289    
4290                            boolean bindName = false;
4291    
4292                            if (name == null) {
4293                                    query.append(_FINDER_COLUMN_G_LIKEN_NAME_1);
4294                            }
4295                            else if (name.equals(StringPool.BLANK)) {
4296                                    query.append(_FINDER_COLUMN_G_LIKEN_NAME_3);
4297                            }
4298                            else {
4299                                    bindName = true;
4300    
4301                                    query.append(_FINDER_COLUMN_G_LIKEN_NAME_2);
4302                            }
4303    
4304                            String sql = query.toString();
4305    
4306                            Session session = null;
4307    
4308                            try {
4309                                    session = openSession();
4310    
4311                                    Query q = session.createQuery(sql);
4312    
4313                                    QueryPos qPos = QueryPos.getInstance(q);
4314    
4315                                    qPos.add(groupId);
4316    
4317                                    if (bindName) {
4318                                            qPos.add(name);
4319                                    }
4320    
4321                                    count = (Long)q.uniqueResult();
4322    
4323                                    finderCache.putResult(finderPath, finderArgs, count);
4324                            }
4325                            catch (Exception e) {
4326                                    finderCache.removeResult(finderPath, finderArgs);
4327    
4328                                    throw processException(e);
4329                            }
4330                            finally {
4331                                    closeSession(session);
4332                            }
4333                    }
4334    
4335                    return count.intValue();
4336            }
4337    
4338            /**
4339             * Returns the number of asset tags where groupId = any &#63; and name LIKE &#63;.
4340             *
4341             * @param groupIds the group IDs
4342             * @param name the name
4343             * @return the number of matching asset tags
4344             */
4345            @Override
4346            public int countByG_LikeN(long[] groupIds, String name) {
4347                    if (groupIds == null) {
4348                            groupIds = new long[0];
4349                    }
4350                    else if (groupIds.length > 1) {
4351                            groupIds = ArrayUtil.unique(groupIds);
4352    
4353                            Arrays.sort(groupIds);
4354                    }
4355    
4356                    Object[] finderArgs = new Object[] { StringUtil.merge(groupIds), name };
4357    
4358                    Long count = (Long)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_LIKEN,
4359                                    finderArgs, this);
4360    
4361                    if (count == null) {
4362                            StringBundler query = new StringBundler();
4363    
4364                            query.append(_SQL_COUNT_ASSETTAG_WHERE);
4365    
4366                            if (groupIds.length > 0) {
4367                                    query.append(StringPool.OPEN_PARENTHESIS);
4368    
4369                                    query.append(_FINDER_COLUMN_G_LIKEN_GROUPID_7);
4370    
4371                                    query.append(StringUtil.merge(groupIds));
4372    
4373                                    query.append(StringPool.CLOSE_PARENTHESIS);
4374    
4375                                    query.append(StringPool.CLOSE_PARENTHESIS);
4376    
4377                                    query.append(WHERE_AND);
4378                            }
4379    
4380                            boolean bindName = false;
4381    
4382                            if (name == null) {
4383                                    query.append(_FINDER_COLUMN_G_LIKEN_NAME_1);
4384                            }
4385                            else if (name.equals(StringPool.BLANK)) {
4386                                    query.append(_FINDER_COLUMN_G_LIKEN_NAME_3);
4387                            }
4388                            else {
4389                                    bindName = true;
4390    
4391                                    query.append(_FINDER_COLUMN_G_LIKEN_NAME_2);
4392                            }
4393    
4394                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
4395                                                    1)), query.index() - 1);
4396    
4397                            String sql = query.toString();
4398    
4399                            Session session = null;
4400    
4401                            try {
4402                                    session = openSession();
4403    
4404                                    Query q = session.createQuery(sql);
4405    
4406                                    QueryPos qPos = QueryPos.getInstance(q);
4407    
4408                                    if (bindName) {
4409                                            qPos.add(name);
4410                                    }
4411    
4412                                    count = (Long)q.uniqueResult();
4413    
4414                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_LIKEN,
4415                                            finderArgs, count);
4416                            }
4417                            catch (Exception e) {
4418                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_LIKEN,
4419                                            finderArgs);
4420    
4421                                    throw processException(e);
4422                            }
4423                            finally {
4424                                    closeSession(session);
4425                            }
4426                    }
4427    
4428                    return count.intValue();
4429            }
4430    
4431            /**
4432             * Returns the number of asset tags that the user has permission to view where groupId = &#63; and name LIKE &#63;.
4433             *
4434             * @param groupId the group ID
4435             * @param name the name
4436             * @return the number of matching asset tags that the user has permission to view
4437             */
4438            @Override
4439            public int filterCountByG_LikeN(long groupId, String name) {
4440                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4441                            return countByG_LikeN(groupId, name);
4442                    }
4443    
4444                    StringBundler query = new StringBundler(3);
4445    
4446                    query.append(_FILTER_SQL_COUNT_ASSETTAG_WHERE);
4447    
4448                    query.append(_FINDER_COLUMN_G_LIKEN_GROUPID_2);
4449    
4450                    boolean bindName = false;
4451    
4452                    if (name == null) {
4453                            query.append(_FINDER_COLUMN_G_LIKEN_NAME_1);
4454                    }
4455                    else if (name.equals(StringPool.BLANK)) {
4456                            query.append(_FINDER_COLUMN_G_LIKEN_NAME_3);
4457                    }
4458                    else {
4459                            bindName = true;
4460    
4461                            query.append(_FINDER_COLUMN_G_LIKEN_NAME_2);
4462                    }
4463    
4464                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4465                                    AssetTag.class.getName(),
4466                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4467    
4468                    Session session = null;
4469    
4470                    try {
4471                            session = openSession();
4472    
4473                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
4474    
4475                            q.addScalar(COUNT_COLUMN_NAME,
4476                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
4477    
4478                            QueryPos qPos = QueryPos.getInstance(q);
4479    
4480                            qPos.add(groupId);
4481    
4482                            if (bindName) {
4483                                    qPos.add(name);
4484                            }
4485    
4486                            Long count = (Long)q.uniqueResult();
4487    
4488                            return count.intValue();
4489                    }
4490                    catch (Exception e) {
4491                            throw processException(e);
4492                    }
4493                    finally {
4494                            closeSession(session);
4495                    }
4496            }
4497    
4498            /**
4499             * Returns the number of asset tags that the user has permission to view where groupId = any &#63; and name LIKE &#63;.
4500             *
4501             * @param groupIds the group IDs
4502             * @param name the name
4503             * @return the number of matching asset tags that the user has permission to view
4504             */
4505            @Override
4506            public int filterCountByG_LikeN(long[] groupIds, String name) {
4507                    if (!InlineSQLHelperUtil.isEnabled(groupIds)) {
4508                            return countByG_LikeN(groupIds, name);
4509                    }
4510    
4511                    if (groupIds == null) {
4512                            groupIds = new long[0];
4513                    }
4514                    else if (groupIds.length > 1) {
4515                            groupIds = ArrayUtil.unique(groupIds);
4516    
4517                            Arrays.sort(groupIds);
4518                    }
4519    
4520                    StringBundler query = new StringBundler();
4521    
4522                    query.append(_FILTER_SQL_COUNT_ASSETTAG_WHERE);
4523    
4524                    if (groupIds.length > 0) {
4525                            query.append(StringPool.OPEN_PARENTHESIS);
4526    
4527                            query.append(_FINDER_COLUMN_G_LIKEN_GROUPID_7);
4528    
4529                            query.append(StringUtil.merge(groupIds));
4530    
4531                            query.append(StringPool.CLOSE_PARENTHESIS);
4532    
4533                            query.append(StringPool.CLOSE_PARENTHESIS);
4534    
4535                            query.append(WHERE_AND);
4536                    }
4537    
4538                    boolean bindName = false;
4539    
4540                    if (name == null) {
4541                            query.append(_FINDER_COLUMN_G_LIKEN_NAME_1);
4542                    }
4543                    else if (name.equals(StringPool.BLANK)) {
4544                            query.append(_FINDER_COLUMN_G_LIKEN_NAME_3);
4545                    }
4546                    else {
4547                            bindName = true;
4548    
4549                            query.append(_FINDER_COLUMN_G_LIKEN_NAME_2);
4550                    }
4551    
4552                    query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
4553                            query.index() - 1);
4554    
4555                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4556                                    AssetTag.class.getName(),
4557                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupIds);
4558    
4559                    Session session = null;
4560    
4561                    try {
4562                            session = openSession();
4563    
4564                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
4565    
4566                            q.addScalar(COUNT_COLUMN_NAME,
4567                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
4568    
4569                            QueryPos qPos = QueryPos.getInstance(q);
4570    
4571                            if (bindName) {
4572                                    qPos.add(name);
4573                            }
4574    
4575                            Long count = (Long)q.uniqueResult();
4576    
4577                            return count.intValue();
4578                    }
4579                    catch (Exception e) {
4580                            throw processException(e);
4581                    }
4582                    finally {
4583                            closeSession(session);
4584                    }
4585            }
4586    
4587            private static final String _FINDER_COLUMN_G_LIKEN_GROUPID_2 = "assetTag.groupId = ? AND ";
4588            private static final String _FINDER_COLUMN_G_LIKEN_GROUPID_7 = "assetTag.groupId IN (";
4589            private static final String _FINDER_COLUMN_G_LIKEN_NAME_1 = "assetTag.name IS NULL";
4590            private static final String _FINDER_COLUMN_G_LIKEN_NAME_2 = "assetTag.name LIKE ?";
4591            private static final String _FINDER_COLUMN_G_LIKEN_NAME_3 = "(assetTag.name IS NULL OR assetTag.name LIKE '')";
4592    
4593            public AssetTagPersistenceImpl() {
4594                    setModelClass(AssetTag.class);
4595            }
4596    
4597            /**
4598             * Caches the asset tag in the entity cache if it is enabled.
4599             *
4600             * @param assetTag the asset tag
4601             */
4602            @Override
4603            public void cacheResult(AssetTag assetTag) {
4604                    entityCache.putResult(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
4605                            AssetTagImpl.class, assetTag.getPrimaryKey(), assetTag);
4606    
4607                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
4608                            new Object[] { assetTag.getUuid(), assetTag.getGroupId() }, assetTag);
4609    
4610                    finderCache.putResult(FINDER_PATH_FETCH_BY_G_N,
4611                            new Object[] { assetTag.getGroupId(), assetTag.getName() }, assetTag);
4612    
4613                    assetTag.resetOriginalValues();
4614            }
4615    
4616            /**
4617             * Caches the asset tags in the entity cache if it is enabled.
4618             *
4619             * @param assetTags the asset tags
4620             */
4621            @Override
4622            public void cacheResult(List<AssetTag> assetTags) {
4623                    for (AssetTag assetTag : assetTags) {
4624                            if (entityCache.getResult(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
4625                                                    AssetTagImpl.class, assetTag.getPrimaryKey()) == null) {
4626                                    cacheResult(assetTag);
4627                            }
4628                            else {
4629                                    assetTag.resetOriginalValues();
4630                            }
4631                    }
4632            }
4633    
4634            /**
4635             * Clears the cache for all asset tags.
4636             *
4637             * <p>
4638             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
4639             * </p>
4640             */
4641            @Override
4642            public void clearCache() {
4643                    entityCache.clearCache(AssetTagImpl.class);
4644    
4645                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
4646                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4647                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4648            }
4649    
4650            /**
4651             * Clears the cache for the asset tag.
4652             *
4653             * <p>
4654             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
4655             * </p>
4656             */
4657            @Override
4658            public void clearCache(AssetTag assetTag) {
4659                    entityCache.removeResult(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
4660                            AssetTagImpl.class, assetTag.getPrimaryKey());
4661    
4662                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4663                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4664    
4665                    clearUniqueFindersCache((AssetTagModelImpl)assetTag);
4666            }
4667    
4668            @Override
4669            public void clearCache(List<AssetTag> assetTags) {
4670                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4671                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4672    
4673                    for (AssetTag assetTag : assetTags) {
4674                            entityCache.removeResult(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
4675                                    AssetTagImpl.class, assetTag.getPrimaryKey());
4676    
4677                            clearUniqueFindersCache((AssetTagModelImpl)assetTag);
4678                    }
4679            }
4680    
4681            protected void cacheUniqueFindersCache(
4682                    AssetTagModelImpl assetTagModelImpl, boolean isNew) {
4683                    if (isNew) {
4684                            Object[] args = new Object[] {
4685                                            assetTagModelImpl.getUuid(), assetTagModelImpl.getGroupId()
4686                                    };
4687    
4688                            finderCache.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
4689                                    Long.valueOf(1));
4690                            finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
4691                                    assetTagModelImpl);
4692    
4693                            args = new Object[] {
4694                                            assetTagModelImpl.getGroupId(), assetTagModelImpl.getName()
4695                                    };
4696    
4697                            finderCache.putResult(FINDER_PATH_COUNT_BY_G_N, args,
4698                                    Long.valueOf(1));
4699                            finderCache.putResult(FINDER_PATH_FETCH_BY_G_N, args,
4700                                    assetTagModelImpl);
4701                    }
4702                    else {
4703                            if ((assetTagModelImpl.getColumnBitmask() &
4704                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
4705                                    Object[] args = new Object[] {
4706                                                    assetTagModelImpl.getUuid(),
4707                                                    assetTagModelImpl.getGroupId()
4708                                            };
4709    
4710                                    finderCache.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
4711                                            Long.valueOf(1));
4712                                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
4713                                            assetTagModelImpl);
4714                            }
4715    
4716                            if ((assetTagModelImpl.getColumnBitmask() &
4717                                            FINDER_PATH_FETCH_BY_G_N.getColumnBitmask()) != 0) {
4718                                    Object[] args = new Object[] {
4719                                                    assetTagModelImpl.getGroupId(),
4720                                                    assetTagModelImpl.getName()
4721                                            };
4722    
4723                                    finderCache.putResult(FINDER_PATH_COUNT_BY_G_N, args,
4724                                            Long.valueOf(1));
4725                                    finderCache.putResult(FINDER_PATH_FETCH_BY_G_N, args,
4726                                            assetTagModelImpl);
4727                            }
4728                    }
4729            }
4730    
4731            protected void clearUniqueFindersCache(AssetTagModelImpl assetTagModelImpl) {
4732                    Object[] args = new Object[] {
4733                                    assetTagModelImpl.getUuid(), assetTagModelImpl.getGroupId()
4734                            };
4735    
4736                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
4737                    finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
4738    
4739                    if ((assetTagModelImpl.getColumnBitmask() &
4740                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
4741                            args = new Object[] {
4742                                            assetTagModelImpl.getOriginalUuid(),
4743                                            assetTagModelImpl.getOriginalGroupId()
4744                                    };
4745    
4746                            finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
4747                            finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
4748                    }
4749    
4750                    args = new Object[] {
4751                                    assetTagModelImpl.getGroupId(), assetTagModelImpl.getName()
4752                            };
4753    
4754                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_N, args);
4755                    finderCache.removeResult(FINDER_PATH_FETCH_BY_G_N, args);
4756    
4757                    if ((assetTagModelImpl.getColumnBitmask() &
4758                                    FINDER_PATH_FETCH_BY_G_N.getColumnBitmask()) != 0) {
4759                            args = new Object[] {
4760                                            assetTagModelImpl.getOriginalGroupId(),
4761                                            assetTagModelImpl.getOriginalName()
4762                                    };
4763    
4764                            finderCache.removeResult(FINDER_PATH_COUNT_BY_G_N, args);
4765                            finderCache.removeResult(FINDER_PATH_FETCH_BY_G_N, args);
4766                    }
4767            }
4768    
4769            /**
4770             * Creates a new asset tag with the primary key. Does not add the asset tag to the database.
4771             *
4772             * @param tagId the primary key for the new asset tag
4773             * @return the new asset tag
4774             */
4775            @Override
4776            public AssetTag create(long tagId) {
4777                    AssetTag assetTag = new AssetTagImpl();
4778    
4779                    assetTag.setNew(true);
4780                    assetTag.setPrimaryKey(tagId);
4781    
4782                    String uuid = PortalUUIDUtil.generate();
4783    
4784                    assetTag.setUuid(uuid);
4785    
4786                    return assetTag;
4787            }
4788    
4789            /**
4790             * Removes the asset tag with the primary key from the database. Also notifies the appropriate model listeners.
4791             *
4792             * @param tagId the primary key of the asset tag
4793             * @return the asset tag that was removed
4794             * @throws NoSuchTagException if a asset tag with the primary key could not be found
4795             */
4796            @Override
4797            public AssetTag remove(long tagId) throws NoSuchTagException {
4798                    return remove((Serializable)tagId);
4799            }
4800    
4801            /**
4802             * Removes the asset tag with the primary key from the database. Also notifies the appropriate model listeners.
4803             *
4804             * @param primaryKey the primary key of the asset tag
4805             * @return the asset tag that was removed
4806             * @throws NoSuchTagException if a asset tag with the primary key could not be found
4807             */
4808            @Override
4809            public AssetTag remove(Serializable primaryKey) throws NoSuchTagException {
4810                    Session session = null;
4811    
4812                    try {
4813                            session = openSession();
4814    
4815                            AssetTag assetTag = (AssetTag)session.get(AssetTagImpl.class,
4816                                            primaryKey);
4817    
4818                            if (assetTag == null) {
4819                                    if (_log.isWarnEnabled()) {
4820                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
4821                                    }
4822    
4823                                    throw new NoSuchTagException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
4824                                            primaryKey);
4825                            }
4826    
4827                            return remove(assetTag);
4828                    }
4829                    catch (NoSuchTagException nsee) {
4830                            throw nsee;
4831                    }
4832                    catch (Exception e) {
4833                            throw processException(e);
4834                    }
4835                    finally {
4836                            closeSession(session);
4837                    }
4838            }
4839    
4840            @Override
4841            protected AssetTag removeImpl(AssetTag assetTag) {
4842                    assetTag = toUnwrappedModel(assetTag);
4843    
4844                    assetTagToAssetEntryTableMapper.deleteLeftPrimaryKeyTableMappings(0,
4845                            assetTag.getPrimaryKey());
4846    
4847                    Session session = null;
4848    
4849                    try {
4850                            session = openSession();
4851    
4852                            if (!session.contains(assetTag)) {
4853                                    assetTag = (AssetTag)session.get(AssetTagImpl.class,
4854                                                    assetTag.getPrimaryKeyObj());
4855                            }
4856    
4857                            if (assetTag != null) {
4858                                    session.delete(assetTag);
4859                            }
4860                    }
4861                    catch (Exception e) {
4862                            throw processException(e);
4863                    }
4864                    finally {
4865                            closeSession(session);
4866                    }
4867    
4868                    if (assetTag != null) {
4869                            clearCache(assetTag);
4870                    }
4871    
4872                    return assetTag;
4873            }
4874    
4875            @Override
4876            public AssetTag updateImpl(AssetTag assetTag) {
4877                    assetTag = toUnwrappedModel(assetTag);
4878    
4879                    boolean isNew = assetTag.isNew();
4880    
4881                    AssetTagModelImpl assetTagModelImpl = (AssetTagModelImpl)assetTag;
4882    
4883                    if (Validator.isNull(assetTag.getUuid())) {
4884                            String uuid = PortalUUIDUtil.generate();
4885    
4886                            assetTag.setUuid(uuid);
4887                    }
4888    
4889                    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
4890    
4891                    Date now = new Date();
4892    
4893                    if (isNew && (assetTag.getCreateDate() == null)) {
4894                            if (serviceContext == null) {
4895                                    assetTag.setCreateDate(now);
4896                            }
4897                            else {
4898                                    assetTag.setCreateDate(serviceContext.getCreateDate(now));
4899                            }
4900                    }
4901    
4902                    if (!assetTagModelImpl.hasSetModifiedDate()) {
4903                            if (serviceContext == null) {
4904                                    assetTag.setModifiedDate(now);
4905                            }
4906                            else {
4907                                    assetTag.setModifiedDate(serviceContext.getModifiedDate(now));
4908                            }
4909                    }
4910    
4911                    Session session = null;
4912    
4913                    try {
4914                            session = openSession();
4915    
4916                            if (assetTag.isNew()) {
4917                                    session.save(assetTag);
4918    
4919                                    assetTag.setNew(false);
4920                            }
4921                            else {
4922                                    assetTag = (AssetTag)session.merge(assetTag);
4923                            }
4924                    }
4925                    catch (Exception e) {
4926                            throw processException(e);
4927                    }
4928                    finally {
4929                            closeSession(session);
4930                    }
4931    
4932                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4933    
4934                    if (isNew || !AssetTagModelImpl.COLUMN_BITMASK_ENABLED) {
4935                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4936                    }
4937    
4938                    else {
4939                            if ((assetTagModelImpl.getColumnBitmask() &
4940                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
4941                                    Object[] args = new Object[] { assetTagModelImpl.getOriginalUuid() };
4942    
4943                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
4944                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
4945                                            args);
4946    
4947                                    args = new Object[] { assetTagModelImpl.getUuid() };
4948    
4949                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
4950                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
4951                                            args);
4952                            }
4953    
4954                            if ((assetTagModelImpl.getColumnBitmask() &
4955                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
4956                                    Object[] args = new Object[] {
4957                                                    assetTagModelImpl.getOriginalUuid(),
4958                                                    assetTagModelImpl.getOriginalCompanyId()
4959                                            };
4960    
4961                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
4962                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
4963                                            args);
4964    
4965                                    args = new Object[] {
4966                                                    assetTagModelImpl.getUuid(),
4967                                                    assetTagModelImpl.getCompanyId()
4968                                            };
4969    
4970                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
4971                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
4972                                            args);
4973                            }
4974    
4975                            if ((assetTagModelImpl.getColumnBitmask() &
4976                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
4977                                    Object[] args = new Object[] {
4978                                                    assetTagModelImpl.getOriginalGroupId()
4979                                            };
4980    
4981                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
4982                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
4983                                            args);
4984    
4985                                    args = new Object[] { assetTagModelImpl.getGroupId() };
4986    
4987                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
4988                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
4989                                            args);
4990                            }
4991                    }
4992    
4993                    entityCache.putResult(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
4994                            AssetTagImpl.class, assetTag.getPrimaryKey(), assetTag, false);
4995    
4996                    clearUniqueFindersCache(assetTagModelImpl);
4997                    cacheUniqueFindersCache(assetTagModelImpl, isNew);
4998    
4999                    assetTag.resetOriginalValues();
5000    
5001                    return assetTag;
5002            }
5003    
5004            protected AssetTag toUnwrappedModel(AssetTag assetTag) {
5005                    if (assetTag instanceof AssetTagImpl) {
5006                            return assetTag;
5007                    }
5008    
5009                    AssetTagImpl assetTagImpl = new AssetTagImpl();
5010    
5011                    assetTagImpl.setNew(assetTag.isNew());
5012                    assetTagImpl.setPrimaryKey(assetTag.getPrimaryKey());
5013    
5014                    assetTagImpl.setUuid(assetTag.getUuid());
5015                    assetTagImpl.setTagId(assetTag.getTagId());
5016                    assetTagImpl.setGroupId(assetTag.getGroupId());
5017                    assetTagImpl.setCompanyId(assetTag.getCompanyId());
5018                    assetTagImpl.setUserId(assetTag.getUserId());
5019                    assetTagImpl.setUserName(assetTag.getUserName());
5020                    assetTagImpl.setCreateDate(assetTag.getCreateDate());
5021                    assetTagImpl.setModifiedDate(assetTag.getModifiedDate());
5022                    assetTagImpl.setName(assetTag.getName());
5023                    assetTagImpl.setAssetCount(assetTag.getAssetCount());
5024                    assetTagImpl.setLastPublishDate(assetTag.getLastPublishDate());
5025    
5026                    return assetTagImpl;
5027            }
5028    
5029            /**
5030             * Returns the asset tag with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
5031             *
5032             * @param primaryKey the primary key of the asset tag
5033             * @return the asset tag
5034             * @throws NoSuchTagException if a asset tag with the primary key could not be found
5035             */
5036            @Override
5037            public AssetTag findByPrimaryKey(Serializable primaryKey)
5038                    throws NoSuchTagException {
5039                    AssetTag assetTag = fetchByPrimaryKey(primaryKey);
5040    
5041                    if (assetTag == null) {
5042                            if (_log.isWarnEnabled()) {
5043                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
5044                            }
5045    
5046                            throw new NoSuchTagException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
5047                                    primaryKey);
5048                    }
5049    
5050                    return assetTag;
5051            }
5052    
5053            /**
5054             * Returns the asset tag with the primary key or throws a {@link NoSuchTagException} if it could not be found.
5055             *
5056             * @param tagId the primary key of the asset tag
5057             * @return the asset tag
5058             * @throws NoSuchTagException if a asset tag with the primary key could not be found
5059             */
5060            @Override
5061            public AssetTag findByPrimaryKey(long tagId) throws NoSuchTagException {
5062                    return findByPrimaryKey((Serializable)tagId);
5063            }
5064    
5065            /**
5066             * Returns the asset tag with the primary key or returns <code>null</code> if it could not be found.
5067             *
5068             * @param primaryKey the primary key of the asset tag
5069             * @return the asset tag, or <code>null</code> if a asset tag with the primary key could not be found
5070             */
5071            @Override
5072            public AssetTag fetchByPrimaryKey(Serializable primaryKey) {
5073                    AssetTag assetTag = (AssetTag)entityCache.getResult(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
5074                                    AssetTagImpl.class, primaryKey);
5075    
5076                    if (assetTag == _nullAssetTag) {
5077                            return null;
5078                    }
5079    
5080                    if (assetTag == null) {
5081                            Session session = null;
5082    
5083                            try {
5084                                    session = openSession();
5085    
5086                                    assetTag = (AssetTag)session.get(AssetTagImpl.class, primaryKey);
5087    
5088                                    if (assetTag != null) {
5089                                            cacheResult(assetTag);
5090                                    }
5091                                    else {
5092                                            entityCache.putResult(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
5093                                                    AssetTagImpl.class, primaryKey, _nullAssetTag);
5094                                    }
5095                            }
5096                            catch (Exception e) {
5097                                    entityCache.removeResult(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
5098                                            AssetTagImpl.class, primaryKey);
5099    
5100                                    throw processException(e);
5101                            }
5102                            finally {
5103                                    closeSession(session);
5104                            }
5105                    }
5106    
5107                    return assetTag;
5108            }
5109    
5110            /**
5111             * Returns the asset tag with the primary key or returns <code>null</code> if it could not be found.
5112             *
5113             * @param tagId the primary key of the asset tag
5114             * @return the asset tag, or <code>null</code> if a asset tag with the primary key could not be found
5115             */
5116            @Override
5117            public AssetTag fetchByPrimaryKey(long tagId) {
5118                    return fetchByPrimaryKey((Serializable)tagId);
5119            }
5120    
5121            @Override
5122            public Map<Serializable, AssetTag> fetchByPrimaryKeys(
5123                    Set<Serializable> primaryKeys) {
5124                    if (primaryKeys.isEmpty()) {
5125                            return Collections.emptyMap();
5126                    }
5127    
5128                    Map<Serializable, AssetTag> map = new HashMap<Serializable, AssetTag>();
5129    
5130                    if (primaryKeys.size() == 1) {
5131                            Iterator<Serializable> iterator = primaryKeys.iterator();
5132    
5133                            Serializable primaryKey = iterator.next();
5134    
5135                            AssetTag assetTag = fetchByPrimaryKey(primaryKey);
5136    
5137                            if (assetTag != null) {
5138                                    map.put(primaryKey, assetTag);
5139                            }
5140    
5141                            return map;
5142                    }
5143    
5144                    Set<Serializable> uncachedPrimaryKeys = null;
5145    
5146                    for (Serializable primaryKey : primaryKeys) {
5147                            AssetTag assetTag = (AssetTag)entityCache.getResult(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
5148                                            AssetTagImpl.class, primaryKey);
5149    
5150                            if (assetTag == null) {
5151                                    if (uncachedPrimaryKeys == null) {
5152                                            uncachedPrimaryKeys = new HashSet<Serializable>();
5153                                    }
5154    
5155                                    uncachedPrimaryKeys.add(primaryKey);
5156                            }
5157                            else {
5158                                    map.put(primaryKey, assetTag);
5159                            }
5160                    }
5161    
5162                    if (uncachedPrimaryKeys == null) {
5163                            return map;
5164                    }
5165    
5166                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
5167                                    1);
5168    
5169                    query.append(_SQL_SELECT_ASSETTAG_WHERE_PKS_IN);
5170    
5171                    for (Serializable primaryKey : uncachedPrimaryKeys) {
5172                            query.append(String.valueOf(primaryKey));
5173    
5174                            query.append(StringPool.COMMA);
5175                    }
5176    
5177                    query.setIndex(query.index() - 1);
5178    
5179                    query.append(StringPool.CLOSE_PARENTHESIS);
5180    
5181                    String sql = query.toString();
5182    
5183                    Session session = null;
5184    
5185                    try {
5186                            session = openSession();
5187    
5188                            Query q = session.createQuery(sql);
5189    
5190                            for (AssetTag assetTag : (List<AssetTag>)q.list()) {
5191                                    map.put(assetTag.getPrimaryKeyObj(), assetTag);
5192    
5193                                    cacheResult(assetTag);
5194    
5195                                    uncachedPrimaryKeys.remove(assetTag.getPrimaryKeyObj());
5196                            }
5197    
5198                            for (Serializable primaryKey : uncachedPrimaryKeys) {
5199                                    entityCache.putResult(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
5200                                            AssetTagImpl.class, primaryKey, _nullAssetTag);
5201                            }
5202                    }
5203                    catch (Exception e) {
5204                            throw processException(e);
5205                    }
5206                    finally {
5207                            closeSession(session);
5208                    }
5209    
5210                    return map;
5211            }
5212    
5213            /**
5214             * Returns all the asset tags.
5215             *
5216             * @return the asset tags
5217             */
5218            @Override
5219            public List<AssetTag> findAll() {
5220                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5221            }
5222    
5223            /**
5224             * Returns a range of all the asset tags.
5225             *
5226             * <p>
5227             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. 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.
5228             * </p>
5229             *
5230             * @param start the lower bound of the range of asset tags
5231             * @param end the upper bound of the range of asset tags (not inclusive)
5232             * @return the range of asset tags
5233             */
5234            @Override
5235            public List<AssetTag> findAll(int start, int end) {
5236                    return findAll(start, end, null);
5237            }
5238    
5239            /**
5240             * Returns an ordered range of all the asset tags.
5241             *
5242             * <p>
5243             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. 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.
5244             * </p>
5245             *
5246             * @param start the lower bound of the range of asset tags
5247             * @param end the upper bound of the range of asset tags (not inclusive)
5248             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5249             * @return the ordered range of asset tags
5250             */
5251            @Override
5252            public List<AssetTag> findAll(int start, int end,
5253                    OrderByComparator<AssetTag> orderByComparator) {
5254                    return findAll(start, end, orderByComparator, true);
5255            }
5256    
5257            /**
5258             * Returns an ordered range of all the asset tags.
5259             *
5260             * <p>
5261             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. 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.
5262             * </p>
5263             *
5264             * @param start the lower bound of the range of asset tags
5265             * @param end the upper bound of the range of asset tags (not inclusive)
5266             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5267             * @param retrieveFromCache whether to retrieve from the finder cache
5268             * @return the ordered range of asset tags
5269             */
5270            @Override
5271            public List<AssetTag> findAll(int start, int end,
5272                    OrderByComparator<AssetTag> orderByComparator, boolean retrieveFromCache) {
5273                    boolean pagination = true;
5274                    FinderPath finderPath = null;
5275                    Object[] finderArgs = null;
5276    
5277                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5278                                    (orderByComparator == null)) {
5279                            pagination = false;
5280                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
5281                            finderArgs = FINDER_ARGS_EMPTY;
5282                    }
5283                    else {
5284                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
5285                            finderArgs = new Object[] { start, end, orderByComparator };
5286                    }
5287    
5288                    List<AssetTag> list = null;
5289    
5290                    if (retrieveFromCache) {
5291                            list = (List<AssetTag>)finderCache.getResult(finderPath,
5292                                            finderArgs, this);
5293                    }
5294    
5295                    if (list == null) {
5296                            StringBundler query = null;
5297                            String sql = null;
5298    
5299                            if (orderByComparator != null) {
5300                                    query = new StringBundler(2 +
5301                                                    (orderByComparator.getOrderByFields().length * 3));
5302    
5303                                    query.append(_SQL_SELECT_ASSETTAG);
5304    
5305                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5306                                            orderByComparator);
5307    
5308                                    sql = query.toString();
5309                            }
5310                            else {
5311                                    sql = _SQL_SELECT_ASSETTAG;
5312    
5313                                    if (pagination) {
5314                                            sql = sql.concat(AssetTagModelImpl.ORDER_BY_JPQL);
5315                                    }
5316                            }
5317    
5318                            Session session = null;
5319    
5320                            try {
5321                                    session = openSession();
5322    
5323                                    Query q = session.createQuery(sql);
5324    
5325                                    if (!pagination) {
5326                                            list = (List<AssetTag>)QueryUtil.list(q, getDialect(),
5327                                                            start, end, false);
5328    
5329                                            Collections.sort(list);
5330    
5331                                            list = Collections.unmodifiableList(list);
5332                                    }
5333                                    else {
5334                                            list = (List<AssetTag>)QueryUtil.list(q, getDialect(),
5335                                                            start, end);
5336                                    }
5337    
5338                                    cacheResult(list);
5339    
5340                                    finderCache.putResult(finderPath, finderArgs, list);
5341                            }
5342                            catch (Exception e) {
5343                                    finderCache.removeResult(finderPath, finderArgs);
5344    
5345                                    throw processException(e);
5346                            }
5347                            finally {
5348                                    closeSession(session);
5349                            }
5350                    }
5351    
5352                    return list;
5353            }
5354    
5355            /**
5356             * Removes all the asset tags from the database.
5357             *
5358             */
5359            @Override
5360            public void removeAll() {
5361                    for (AssetTag assetTag : findAll()) {
5362                            remove(assetTag);
5363                    }
5364            }
5365    
5366            /**
5367             * Returns the number of asset tags.
5368             *
5369             * @return the number of asset tags
5370             */
5371            @Override
5372            public int countAll() {
5373                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
5374                                    FINDER_ARGS_EMPTY, this);
5375    
5376                    if (count == null) {
5377                            Session session = null;
5378    
5379                            try {
5380                                    session = openSession();
5381    
5382                                    Query q = session.createQuery(_SQL_COUNT_ASSETTAG);
5383    
5384                                    count = (Long)q.uniqueResult();
5385    
5386                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
5387                                            count);
5388                            }
5389                            catch (Exception e) {
5390                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
5391                                            FINDER_ARGS_EMPTY);
5392    
5393                                    throw processException(e);
5394                            }
5395                            finally {
5396                                    closeSession(session);
5397                            }
5398                    }
5399    
5400                    return count.intValue();
5401            }
5402    
5403            /**
5404             * Returns the primaryKeys of asset entries associated with the asset tag.
5405             *
5406             * @param pk the primary key of the asset tag
5407             * @return long[] of the primaryKeys of asset entries associated with the asset tag
5408             */
5409            @Override
5410            public long[] getAssetEntryPrimaryKeys(long pk) {
5411                    long[] pks = assetTagToAssetEntryTableMapper.getRightPrimaryKeys(0, pk);
5412    
5413                    return pks.clone();
5414            }
5415    
5416            /**
5417             * Returns all the asset entries associated with the asset tag.
5418             *
5419             * @param pk the primary key of the asset tag
5420             * @return the asset entries associated with the asset tag
5421             */
5422            @Override
5423            public List<com.liferay.portlet.asset.model.AssetEntry> getAssetEntries(
5424                    long pk) {
5425                    return getAssetEntries(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
5426            }
5427    
5428            /**
5429             * Returns a range of all the asset entries associated with the asset tag.
5430             *
5431             * <p>
5432             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. 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.
5433             * </p>
5434             *
5435             * @param pk the primary key of the asset tag
5436             * @param start the lower bound of the range of asset tags
5437             * @param end the upper bound of the range of asset tags (not inclusive)
5438             * @return the range of asset entries associated with the asset tag
5439             */
5440            @Override
5441            public List<com.liferay.portlet.asset.model.AssetEntry> getAssetEntries(
5442                    long pk, int start, int end) {
5443                    return getAssetEntries(pk, start, end, null);
5444            }
5445    
5446            /**
5447             * Returns an ordered range of all the asset entries associated with the asset tag.
5448             *
5449             * <p>
5450             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link AssetTagModelImpl}. 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.
5451             * </p>
5452             *
5453             * @param pk the primary key of the asset tag
5454             * @param start the lower bound of the range of asset tags
5455             * @param end the upper bound of the range of asset tags (not inclusive)
5456             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5457             * @return the ordered range of asset entries associated with the asset tag
5458             */
5459            @Override
5460            public List<com.liferay.portlet.asset.model.AssetEntry> getAssetEntries(
5461                    long pk, int start, int end,
5462                    OrderByComparator<com.liferay.portlet.asset.model.AssetEntry> orderByComparator) {
5463                    return assetTagToAssetEntryTableMapper.getRightBaseModels(0, pk, start,
5464                            end, orderByComparator);
5465            }
5466    
5467            /**
5468             * Returns the number of asset entries associated with the asset tag.
5469             *
5470             * @param pk the primary key of the asset tag
5471             * @return the number of asset entries associated with the asset tag
5472             */
5473            @Override
5474            public int getAssetEntriesSize(long pk) {
5475                    long[] pks = assetTagToAssetEntryTableMapper.getRightPrimaryKeys(0, pk);
5476    
5477                    return pks.length;
5478            }
5479    
5480            /**
5481             * Returns <code>true</code> if the asset entry is associated with the asset tag.
5482             *
5483             * @param pk the primary key of the asset tag
5484             * @param assetEntryPK the primary key of the asset entry
5485             * @return <code>true</code> if the asset entry is associated with the asset tag; <code>false</code> otherwise
5486             */
5487            @Override
5488            public boolean containsAssetEntry(long pk, long assetEntryPK) {
5489                    return assetTagToAssetEntryTableMapper.containsTableMapping(0, pk,
5490                            assetEntryPK);
5491            }
5492    
5493            /**
5494             * Returns <code>true</code> if the asset tag has any asset entries associated with it.
5495             *
5496             * @param pk the primary key of the asset tag to check for associations with asset entries
5497             * @return <code>true</code> if the asset tag has any asset entries associated with it; <code>false</code> otherwise
5498             */
5499            @Override
5500            public boolean containsAssetEntries(long pk) {
5501                    if (getAssetEntriesSize(pk) > 0) {
5502                            return true;
5503                    }
5504                    else {
5505                            return false;
5506                    }
5507            }
5508    
5509            /**
5510             * Adds an association between the asset tag and the asset entry. Also notifies the appropriate model listeners and clears the mapping table finder cache.
5511             *
5512             * @param pk the primary key of the asset tag
5513             * @param assetEntryPK the primary key of the asset entry
5514             */
5515            @Override
5516            public void addAssetEntry(long pk, long assetEntryPK) {
5517                    assetTagToAssetEntryTableMapper.addTableMapping(0, pk, assetEntryPK);
5518            }
5519    
5520            /**
5521             * Adds an association between the asset tag and the asset entry. Also notifies the appropriate model listeners and clears the mapping table finder cache.
5522             *
5523             * @param pk the primary key of the asset tag
5524             * @param assetEntry the asset entry
5525             */
5526            @Override
5527            public void addAssetEntry(long pk,
5528                    com.liferay.portlet.asset.model.AssetEntry assetEntry) {
5529                    assetTagToAssetEntryTableMapper.addTableMapping(0, pk,
5530                            assetEntry.getPrimaryKey());
5531            }
5532    
5533            /**
5534             * Adds an association between the asset tag and the asset entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
5535             *
5536             * @param pk the primary key of the asset tag
5537             * @param assetEntryPKs the primary keys of the asset entries
5538             */
5539            @Override
5540            public void addAssetEntries(long pk, long[] assetEntryPKs) {
5541                    for (long assetEntryPK : assetEntryPKs) {
5542                            assetTagToAssetEntryTableMapper.addTableMapping(0, pk, assetEntryPK);
5543                    }
5544            }
5545    
5546            /**
5547             * Adds an association between the asset tag and the asset entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
5548             *
5549             * @param pk the primary key of the asset tag
5550             * @param assetEntries the asset entries
5551             */
5552            @Override
5553            public void addAssetEntries(long pk,
5554                    List<com.liferay.portlet.asset.model.AssetEntry> assetEntries) {
5555                    for (com.liferay.portlet.asset.model.AssetEntry assetEntry : assetEntries) {
5556                            assetTagToAssetEntryTableMapper.addTableMapping(0, pk,
5557                                    assetEntry.getPrimaryKey());
5558                    }
5559            }
5560    
5561            /**
5562             * Clears all associations between the asset tag and its asset entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
5563             *
5564             * @param pk the primary key of the asset tag to clear the associated asset entries from
5565             */
5566            @Override
5567            public void clearAssetEntries(long pk) {
5568                    assetTagToAssetEntryTableMapper.deleteLeftPrimaryKeyTableMappings(0, pk);
5569            }
5570    
5571            /**
5572             * Removes the association between the asset tag and the asset entry. Also notifies the appropriate model listeners and clears the mapping table finder cache.
5573             *
5574             * @param pk the primary key of the asset tag
5575             * @param assetEntryPK the primary key of the asset entry
5576             */
5577            @Override
5578            public void removeAssetEntry(long pk, long assetEntryPK) {
5579                    assetTagToAssetEntryTableMapper.deleteTableMapping(0, pk, assetEntryPK);
5580            }
5581    
5582            /**
5583             * Removes the association between the asset tag and the asset entry. Also notifies the appropriate model listeners and clears the mapping table finder cache.
5584             *
5585             * @param pk the primary key of the asset tag
5586             * @param assetEntry the asset entry
5587             */
5588            @Override
5589            public void removeAssetEntry(long pk,
5590                    com.liferay.portlet.asset.model.AssetEntry assetEntry) {
5591                    assetTagToAssetEntryTableMapper.deleteTableMapping(0, pk,
5592                            assetEntry.getPrimaryKey());
5593            }
5594    
5595            /**
5596             * Removes the association between the asset tag and the asset entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
5597             *
5598             * @param pk the primary key of the asset tag
5599             * @param assetEntryPKs the primary keys of the asset entries
5600             */
5601            @Override
5602            public void removeAssetEntries(long pk, long[] assetEntryPKs) {
5603                    for (long assetEntryPK : assetEntryPKs) {
5604                            assetTagToAssetEntryTableMapper.deleteTableMapping(0, pk,
5605                                    assetEntryPK);
5606                    }
5607            }
5608    
5609            /**
5610             * Removes the association between the asset tag and the asset entries. Also notifies the appropriate model listeners and clears the mapping table finder cache.
5611             *
5612             * @param pk the primary key of the asset tag
5613             * @param assetEntries the asset entries
5614             */
5615            @Override
5616            public void removeAssetEntries(long pk,
5617                    List<com.liferay.portlet.asset.model.AssetEntry> assetEntries) {
5618                    for (com.liferay.portlet.asset.model.AssetEntry assetEntry : assetEntries) {
5619                            assetTagToAssetEntryTableMapper.deleteTableMapping(0, pk,
5620                                    assetEntry.getPrimaryKey());
5621                    }
5622            }
5623    
5624            /**
5625             * Sets the asset entries associated with the asset tag, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
5626             *
5627             * @param pk the primary key of the asset tag
5628             * @param assetEntryPKs the primary keys of the asset entries to be associated with the asset tag
5629             */
5630            @Override
5631            public void setAssetEntries(long pk, long[] assetEntryPKs) {
5632                    Set<Long> newAssetEntryPKsSet = SetUtil.fromArray(assetEntryPKs);
5633                    Set<Long> oldAssetEntryPKsSet = SetUtil.fromArray(assetTagToAssetEntryTableMapper.getRightPrimaryKeys(
5634                                            0, pk));
5635    
5636                    Set<Long> removeAssetEntryPKsSet = new HashSet<Long>(oldAssetEntryPKsSet);
5637    
5638                    removeAssetEntryPKsSet.removeAll(newAssetEntryPKsSet);
5639    
5640                    for (long removeAssetEntryPK : removeAssetEntryPKsSet) {
5641                            assetTagToAssetEntryTableMapper.deleteTableMapping(0, pk,
5642                                    removeAssetEntryPK);
5643                    }
5644    
5645                    newAssetEntryPKsSet.removeAll(oldAssetEntryPKsSet);
5646    
5647                    for (long newAssetEntryPK : newAssetEntryPKsSet) {
5648                            assetTagToAssetEntryTableMapper.addTableMapping(0, pk,
5649                                    newAssetEntryPK);
5650                    }
5651            }
5652    
5653            /**
5654             * Sets the asset entries associated with the asset tag, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
5655             *
5656             * @param pk the primary key of the asset tag
5657             * @param assetEntries the asset entries to be associated with the asset tag
5658             */
5659            @Override
5660            public void setAssetEntries(long pk,
5661                    List<com.liferay.portlet.asset.model.AssetEntry> assetEntries) {
5662                    try {
5663                            long[] assetEntryPKs = new long[assetEntries.size()];
5664    
5665                            for (int i = 0; i < assetEntries.size(); i++) {
5666                                    com.liferay.portlet.asset.model.AssetEntry assetEntry = assetEntries.get(i);
5667    
5668                                    assetEntryPKs[i] = assetEntry.getPrimaryKey();
5669                            }
5670    
5671                            setAssetEntries(pk, assetEntryPKs);
5672                    }
5673                    catch (Exception e) {
5674                            throw processException(e);
5675                    }
5676            }
5677    
5678            @Override
5679            public Set<String> getBadColumnNames() {
5680                    return _badColumnNames;
5681            }
5682    
5683            @Override
5684            protected Map<String, Integer> getTableColumnsMap() {
5685                    return AssetTagModelImpl.TABLE_COLUMNS_MAP;
5686            }
5687    
5688            /**
5689             * Initializes the asset tag persistence.
5690             */
5691            public void afterPropertiesSet() {
5692                    assetTagToAssetEntryTableMapper = TableMapperFactory.getTableMapper("AssetEntries_AssetTags",
5693                                    "companyId", "tagId", "entryId", this, assetEntryPersistence);
5694            }
5695    
5696            public void destroy() {
5697                    entityCache.removeCache(AssetTagImpl.class.getName());
5698                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
5699                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
5700                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5701    
5702                    TableMapperFactory.removeTableMapper("AssetEntries_AssetTags");
5703            }
5704    
5705            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
5706            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
5707            @BeanReference(type = AssetEntryPersistence.class)
5708            protected AssetEntryPersistence assetEntryPersistence;
5709            protected TableMapper<AssetTag, com.liferay.portlet.asset.model.AssetEntry> assetTagToAssetEntryTableMapper;
5710            private static final String _SQL_SELECT_ASSETTAG = "SELECT assetTag FROM AssetTag assetTag";
5711            private static final String _SQL_SELECT_ASSETTAG_WHERE_PKS_IN = "SELECT assetTag FROM AssetTag assetTag WHERE tagId IN (";
5712            private static final String _SQL_SELECT_ASSETTAG_WHERE = "SELECT assetTag FROM AssetTag assetTag WHERE ";
5713            private static final String _SQL_COUNT_ASSETTAG = "SELECT COUNT(assetTag) FROM AssetTag assetTag";
5714            private static final String _SQL_COUNT_ASSETTAG_WHERE = "SELECT COUNT(assetTag) FROM AssetTag assetTag WHERE ";
5715            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "assetTag.tagId";
5716            private static final String _FILTER_SQL_SELECT_ASSETTAG_WHERE = "SELECT DISTINCT {assetTag.*} FROM AssetTag assetTag WHERE ";
5717            private static final String _FILTER_SQL_SELECT_ASSETTAG_NO_INLINE_DISTINCT_WHERE_1 =
5718                    "SELECT {AssetTag.*} FROM (SELECT DISTINCT assetTag.tagId FROM AssetTag assetTag WHERE ";
5719            private static final String _FILTER_SQL_SELECT_ASSETTAG_NO_INLINE_DISTINCT_WHERE_2 =
5720                    ") TEMP_TABLE INNER JOIN AssetTag ON TEMP_TABLE.tagId = AssetTag.tagId";
5721            private static final String _FILTER_SQL_COUNT_ASSETTAG_WHERE = "SELECT COUNT(DISTINCT assetTag.tagId) AS COUNT_VALUE FROM AssetTag assetTag WHERE ";
5722            private static final String _FILTER_ENTITY_ALIAS = "assetTag";
5723            private static final String _FILTER_ENTITY_TABLE = "AssetTag";
5724            private static final String _ORDER_BY_ENTITY_ALIAS = "assetTag.";
5725            private static final String _ORDER_BY_ENTITY_TABLE = "AssetTag.";
5726            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AssetTag exists with the primary key ";
5727            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AssetTag exists with the key {";
5728            private static final Log _log = LogFactoryUtil.getLog(AssetTagPersistenceImpl.class);
5729            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
5730                                    "uuid"
5731                            });
5732            private static final AssetTag _nullAssetTag = new AssetTagImpl() {
5733                            @Override
5734                            public Object clone() {
5735                                    return this;
5736                            }
5737    
5738                            @Override
5739                            public CacheModel<AssetTag> toCacheModel() {
5740                                    return _nullAssetTagCacheModel;
5741                            }
5742                    };
5743    
5744            private static final CacheModel<AssetTag> _nullAssetTagCacheModel = new CacheModel<AssetTag>() {
5745                            @Override
5746                            public AssetTag toEntityModel() {
5747                                    return _nullAssetTag;
5748                            }
5749                    };
5750    }