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