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