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