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