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