001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.asset.service.persistence.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.log.Log;
028    import com.liferay.portal.kernel.log.LogFactoryUtil;
029    import com.liferay.portal.kernel.util.OrderByComparator;
030    import com.liferay.portal.kernel.util.SetUtil;
031    import com.liferay.portal.kernel.util.StringBundler;
032    import com.liferay.portal.kernel.util.StringPool;
033    import com.liferay.portal.kernel.util.Validator;
034    import com.liferay.portal.model.CacheModel;
035    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
036    
037    import com.liferay.portlet.asset.NoSuchTagPropertyException;
038    import com.liferay.portlet.asset.model.AssetTagProperty;
039    import com.liferay.portlet.asset.model.impl.AssetTagPropertyImpl;
040    import com.liferay.portlet.asset.model.impl.AssetTagPropertyModelImpl;
041    import com.liferay.portlet.asset.service.persistence.AssetTagPropertyPersistence;
042    
043    import java.io.Serializable;
044    
045    import java.util.Collections;
046    import java.util.HashMap;
047    import java.util.HashSet;
048    import java.util.Iterator;
049    import java.util.List;
050    import java.util.Map;
051    import java.util.Set;
052    
053    /**
054     * The persistence implementation for the asset tag property service.
055     *
056     * <p>
057     * Caching information and settings can be found in <code>portal.properties</code>
058     * </p>
059     *
060     * @author Brian Wing Shun Chan
061     * @see AssetTagPropertyPersistence
062     * @see AssetTagPropertyUtil
063     * @generated
064     */
065    @ProviderType
066    public class AssetTagPropertyPersistenceImpl extends BasePersistenceImpl<AssetTagProperty>
067            implements AssetTagPropertyPersistence {
068            /*
069             * NOTE FOR DEVELOPERS:
070             *
071             * Never modify or reference this class directly. Always use {@link AssetTagPropertyUtil} to access the asset tag property persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
072             */
073            public static final String FINDER_CLASS_NAME_ENTITY = AssetTagPropertyImpl.class.getName();
074            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075                    ".List1";
076            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077                    ".List2";
078            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
079                            AssetTagPropertyModelImpl.FINDER_CACHE_ENABLED,
080                            AssetTagPropertyImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
081                            "findAll", new String[0]);
082            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
083                            AssetTagPropertyModelImpl.FINDER_CACHE_ENABLED,
084                            AssetTagPropertyImpl.class,
085                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
086            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
087                            AssetTagPropertyModelImpl.FINDER_CACHE_ENABLED, Long.class,
088                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
089            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
090                    new FinderPath(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
091                            AssetTagPropertyModelImpl.FINDER_CACHE_ENABLED,
092                            AssetTagPropertyImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
093                            "findByCompanyId",
094                            new String[] {
095                                    Long.class.getName(),
096                                    
097                            Integer.class.getName(), Integer.class.getName(),
098                                    OrderByComparator.class.getName()
099                            });
100            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
101                    new FinderPath(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
102                            AssetTagPropertyModelImpl.FINDER_CACHE_ENABLED,
103                            AssetTagPropertyImpl.class,
104                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
105                            new String[] { Long.class.getName() },
106                            AssetTagPropertyModelImpl.COMPANYID_COLUMN_BITMASK |
107                            AssetTagPropertyModelImpl.KEY_COLUMN_BITMASK);
108            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
109                            AssetTagPropertyModelImpl.FINDER_CACHE_ENABLED, Long.class,
110                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
111                            new String[] { Long.class.getName() });
112    
113            /**
114             * Returns all the asset tag properties where companyId = &#63;.
115             *
116             * @param companyId the company ID
117             * @return the matching asset tag properties
118             */
119            @Override
120            public List<AssetTagProperty> findByCompanyId(long companyId) {
121                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
122                            null);
123            }
124    
125            /**
126             * Returns a range of all the asset tag properties where companyId = &#63;.
127             *
128             * <p>
129             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetTagPropertyModelImpl}. 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.
130             * </p>
131             *
132             * @param companyId the company ID
133             * @param start the lower bound of the range of asset tag properties
134             * @param end the upper bound of the range of asset tag properties (not inclusive)
135             * @return the range of matching asset tag properties
136             */
137            @Override
138            public List<AssetTagProperty> findByCompanyId(long companyId, int start,
139                    int end) {
140                    return findByCompanyId(companyId, start, end, null);
141            }
142    
143            /**
144             * Returns an ordered range of all the asset tag properties where companyId = &#63;.
145             *
146             * <p>
147             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetTagPropertyModelImpl}. 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.
148             * </p>
149             *
150             * @param companyId the company ID
151             * @param start the lower bound of the range of asset tag properties
152             * @param end the upper bound of the range of asset tag properties (not inclusive)
153             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
154             * @return the ordered range of matching asset tag properties
155             */
156            @Override
157            public List<AssetTagProperty> findByCompanyId(long companyId, int start,
158                    int end, OrderByComparator<AssetTagProperty> orderByComparator) {
159                    boolean pagination = true;
160                    FinderPath finderPath = null;
161                    Object[] finderArgs = null;
162    
163                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
164                                    (orderByComparator == null)) {
165                            pagination = false;
166                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
167                            finderArgs = new Object[] { companyId };
168                    }
169                    else {
170                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
171                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
172                    }
173    
174                    List<AssetTagProperty> list = (List<AssetTagProperty>)FinderCacheUtil.getResult(finderPath,
175                                    finderArgs, this);
176    
177                    if ((list != null) && !list.isEmpty()) {
178                            for (AssetTagProperty assetTagProperty : list) {
179                                    if ((companyId != assetTagProperty.getCompanyId())) {
180                                            list = null;
181    
182                                            break;
183                                    }
184                            }
185                    }
186    
187                    if (list == null) {
188                            StringBundler query = null;
189    
190                            if (orderByComparator != null) {
191                                    query = new StringBundler(3 +
192                                                    (orderByComparator.getOrderByFields().length * 3));
193                            }
194                            else {
195                                    query = new StringBundler(3);
196                            }
197    
198                            query.append(_SQL_SELECT_ASSETTAGPROPERTY_WHERE);
199    
200                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
201    
202                            if (orderByComparator != null) {
203                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
204                                            orderByComparator);
205                            }
206                            else
207                             if (pagination) {
208                                    query.append(AssetTagPropertyModelImpl.ORDER_BY_JPQL);
209                            }
210    
211                            String sql = query.toString();
212    
213                            Session session = null;
214    
215                            try {
216                                    session = openSession();
217    
218                                    Query q = session.createQuery(sql);
219    
220                                    QueryPos qPos = QueryPos.getInstance(q);
221    
222                                    qPos.add(companyId);
223    
224                                    if (!pagination) {
225                                            list = (List<AssetTagProperty>)QueryUtil.list(q,
226                                                            getDialect(), start, end, false);
227    
228                                            Collections.sort(list);
229    
230                                            list = Collections.unmodifiableList(list);
231                                    }
232                                    else {
233                                            list = (List<AssetTagProperty>)QueryUtil.list(q,
234                                                            getDialect(), start, end);
235                                    }
236    
237                                    cacheResult(list);
238    
239                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
240                            }
241                            catch (Exception e) {
242                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
243    
244                                    throw processException(e);
245                            }
246                            finally {
247                                    closeSession(session);
248                            }
249                    }
250    
251                    return list;
252            }
253    
254            /**
255             * Returns the first asset tag property in the ordered set where companyId = &#63;.
256             *
257             * @param companyId the company ID
258             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
259             * @return the first matching asset tag property
260             * @throws com.liferay.portlet.asset.NoSuchTagPropertyException if a matching asset tag property could not be found
261             */
262            @Override
263            public AssetTagProperty findByCompanyId_First(long companyId,
264                    OrderByComparator<AssetTagProperty> orderByComparator)
265                    throws NoSuchTagPropertyException {
266                    AssetTagProperty assetTagProperty = fetchByCompanyId_First(companyId,
267                                    orderByComparator);
268    
269                    if (assetTagProperty != null) {
270                            return assetTagProperty;
271                    }
272    
273                    StringBundler msg = new StringBundler(4);
274    
275                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
276    
277                    msg.append("companyId=");
278                    msg.append(companyId);
279    
280                    msg.append(StringPool.CLOSE_CURLY_BRACE);
281    
282                    throw new NoSuchTagPropertyException(msg.toString());
283            }
284    
285            /**
286             * Returns the first asset tag property in the ordered set where companyId = &#63;.
287             *
288             * @param companyId the company ID
289             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
290             * @return the first matching asset tag property, or <code>null</code> if a matching asset tag property could not be found
291             */
292            @Override
293            public AssetTagProperty fetchByCompanyId_First(long companyId,
294                    OrderByComparator<AssetTagProperty> orderByComparator) {
295                    List<AssetTagProperty> list = findByCompanyId(companyId, 0, 1,
296                                    orderByComparator);
297    
298                    if (!list.isEmpty()) {
299                            return list.get(0);
300                    }
301    
302                    return null;
303            }
304    
305            /**
306             * Returns the last asset tag property in the ordered set where companyId = &#63;.
307             *
308             * @param companyId the company ID
309             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
310             * @return the last matching asset tag property
311             * @throws com.liferay.portlet.asset.NoSuchTagPropertyException if a matching asset tag property could not be found
312             */
313            @Override
314            public AssetTagProperty findByCompanyId_Last(long companyId,
315                    OrderByComparator<AssetTagProperty> orderByComparator)
316                    throws NoSuchTagPropertyException {
317                    AssetTagProperty assetTagProperty = fetchByCompanyId_Last(companyId,
318                                    orderByComparator);
319    
320                    if (assetTagProperty != null) {
321                            return assetTagProperty;
322                    }
323    
324                    StringBundler msg = new StringBundler(4);
325    
326                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
327    
328                    msg.append("companyId=");
329                    msg.append(companyId);
330    
331                    msg.append(StringPool.CLOSE_CURLY_BRACE);
332    
333                    throw new NoSuchTagPropertyException(msg.toString());
334            }
335    
336            /**
337             * Returns the last asset tag property in the ordered set where companyId = &#63;.
338             *
339             * @param companyId the company ID
340             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
341             * @return the last matching asset tag property, or <code>null</code> if a matching asset tag property could not be found
342             */
343            @Override
344            public AssetTagProperty fetchByCompanyId_Last(long companyId,
345                    OrderByComparator<AssetTagProperty> orderByComparator) {
346                    int count = countByCompanyId(companyId);
347    
348                    if (count == 0) {
349                            return null;
350                    }
351    
352                    List<AssetTagProperty> list = findByCompanyId(companyId, count - 1,
353                                    count, orderByComparator);
354    
355                    if (!list.isEmpty()) {
356                            return list.get(0);
357                    }
358    
359                    return null;
360            }
361    
362            /**
363             * Returns the asset tag properties before and after the current asset tag property in the ordered set where companyId = &#63;.
364             *
365             * @param tagPropertyId the primary key of the current asset tag property
366             * @param companyId the company ID
367             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
368             * @return the previous, current, and next asset tag property
369             * @throws com.liferay.portlet.asset.NoSuchTagPropertyException if a asset tag property with the primary key could not be found
370             */
371            @Override
372            public AssetTagProperty[] findByCompanyId_PrevAndNext(long tagPropertyId,
373                    long companyId, OrderByComparator<AssetTagProperty> orderByComparator)
374                    throws NoSuchTagPropertyException {
375                    AssetTagProperty assetTagProperty = findByPrimaryKey(tagPropertyId);
376    
377                    Session session = null;
378    
379                    try {
380                            session = openSession();
381    
382                            AssetTagProperty[] array = new AssetTagPropertyImpl[3];
383    
384                            array[0] = getByCompanyId_PrevAndNext(session, assetTagProperty,
385                                            companyId, orderByComparator, true);
386    
387                            array[1] = assetTagProperty;
388    
389                            array[2] = getByCompanyId_PrevAndNext(session, assetTagProperty,
390                                            companyId, orderByComparator, false);
391    
392                            return array;
393                    }
394                    catch (Exception e) {
395                            throw processException(e);
396                    }
397                    finally {
398                            closeSession(session);
399                    }
400            }
401    
402            protected AssetTagProperty getByCompanyId_PrevAndNext(Session session,
403                    AssetTagProperty assetTagProperty, long companyId,
404                    OrderByComparator<AssetTagProperty> orderByComparator, boolean previous) {
405                    StringBundler query = null;
406    
407                    if (orderByComparator != null) {
408                            query = new StringBundler(6 +
409                                            (orderByComparator.getOrderByFields().length * 6));
410                    }
411                    else {
412                            query = new StringBundler(3);
413                    }
414    
415                    query.append(_SQL_SELECT_ASSETTAGPROPERTY_WHERE);
416    
417                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
418    
419                    if (orderByComparator != null) {
420                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
421    
422                            if (orderByConditionFields.length > 0) {
423                                    query.append(WHERE_AND);
424                            }
425    
426                            for (int i = 0; i < orderByConditionFields.length; i++) {
427                                    query.append(_ORDER_BY_ENTITY_ALIAS);
428                                    query.append(orderByConditionFields[i]);
429    
430                                    if ((i + 1) < orderByConditionFields.length) {
431                                            if (orderByComparator.isAscending() ^ previous) {
432                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
433                                            }
434                                            else {
435                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
436                                            }
437                                    }
438                                    else {
439                                            if (orderByComparator.isAscending() ^ previous) {
440                                                    query.append(WHERE_GREATER_THAN);
441                                            }
442                                            else {
443                                                    query.append(WHERE_LESSER_THAN);
444                                            }
445                                    }
446                            }
447    
448                            query.append(ORDER_BY_CLAUSE);
449    
450                            String[] orderByFields = orderByComparator.getOrderByFields();
451    
452                            for (int i = 0; i < orderByFields.length; i++) {
453                                    query.append(_ORDER_BY_ENTITY_ALIAS);
454                                    query.append(orderByFields[i]);
455    
456                                    if ((i + 1) < orderByFields.length) {
457                                            if (orderByComparator.isAscending() ^ previous) {
458                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
459                                            }
460                                            else {
461                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
462                                            }
463                                    }
464                                    else {
465                                            if (orderByComparator.isAscending() ^ previous) {
466                                                    query.append(ORDER_BY_ASC);
467                                            }
468                                            else {
469                                                    query.append(ORDER_BY_DESC);
470                                            }
471                                    }
472                            }
473                    }
474                    else {
475                            query.append(AssetTagPropertyModelImpl.ORDER_BY_JPQL);
476                    }
477    
478                    String sql = query.toString();
479    
480                    Query q = session.createQuery(sql);
481    
482                    q.setFirstResult(0);
483                    q.setMaxResults(2);
484    
485                    QueryPos qPos = QueryPos.getInstance(q);
486    
487                    qPos.add(companyId);
488    
489                    if (orderByComparator != null) {
490                            Object[] values = orderByComparator.getOrderByConditionValues(assetTagProperty);
491    
492                            for (Object value : values) {
493                                    qPos.add(value);
494                            }
495                    }
496    
497                    List<AssetTagProperty> list = q.list();
498    
499                    if (list.size() == 2) {
500                            return list.get(1);
501                    }
502                    else {
503                            return null;
504                    }
505            }
506    
507            /**
508             * Removes all the asset tag properties where companyId = &#63; from the database.
509             *
510             * @param companyId the company ID
511             */
512            @Override
513            public void removeByCompanyId(long companyId) {
514                    for (AssetTagProperty assetTagProperty : findByCompanyId(companyId,
515                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
516                            remove(assetTagProperty);
517                    }
518            }
519    
520            /**
521             * Returns the number of asset tag properties where companyId = &#63;.
522             *
523             * @param companyId the company ID
524             * @return the number of matching asset tag properties
525             */
526            @Override
527            public int countByCompanyId(long companyId) {
528                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
529    
530                    Object[] finderArgs = new Object[] { companyId };
531    
532                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
533                                    this);
534    
535                    if (count == null) {
536                            StringBundler query = new StringBundler(2);
537    
538                            query.append(_SQL_COUNT_ASSETTAGPROPERTY_WHERE);
539    
540                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
541    
542                            String sql = query.toString();
543    
544                            Session session = null;
545    
546                            try {
547                                    session = openSession();
548    
549                                    Query q = session.createQuery(sql);
550    
551                                    QueryPos qPos = QueryPos.getInstance(q);
552    
553                                    qPos.add(companyId);
554    
555                                    count = (Long)q.uniqueResult();
556    
557                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
558                            }
559                            catch (Exception e) {
560                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
561    
562                                    throw processException(e);
563                            }
564                            finally {
565                                    closeSession(session);
566                            }
567                    }
568    
569                    return count.intValue();
570            }
571    
572            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "assetTagProperty.companyId = ?";
573            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TAGID = new FinderPath(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
574                            AssetTagPropertyModelImpl.FINDER_CACHE_ENABLED,
575                            AssetTagPropertyImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
576                            "findByTagId",
577                            new String[] {
578                                    Long.class.getName(),
579                                    
580                            Integer.class.getName(), Integer.class.getName(),
581                                    OrderByComparator.class.getName()
582                            });
583            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TAGID = new FinderPath(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
584                            AssetTagPropertyModelImpl.FINDER_CACHE_ENABLED,
585                            AssetTagPropertyImpl.class,
586                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByTagId",
587                            new String[] { Long.class.getName() },
588                            AssetTagPropertyModelImpl.TAGID_COLUMN_BITMASK |
589                            AssetTagPropertyModelImpl.KEY_COLUMN_BITMASK);
590            public static final FinderPath FINDER_PATH_COUNT_BY_TAGID = new FinderPath(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
591                            AssetTagPropertyModelImpl.FINDER_CACHE_ENABLED, Long.class,
592                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByTagId",
593                            new String[] { Long.class.getName() });
594    
595            /**
596             * Returns all the asset tag properties where tagId = &#63;.
597             *
598             * @param tagId the tag ID
599             * @return the matching asset tag properties
600             */
601            @Override
602            public List<AssetTagProperty> findByTagId(long tagId) {
603                    return findByTagId(tagId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
604            }
605    
606            /**
607             * Returns a range of all the asset tag properties where tagId = &#63;.
608             *
609             * <p>
610             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetTagPropertyModelImpl}. 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.
611             * </p>
612             *
613             * @param tagId the tag ID
614             * @param start the lower bound of the range of asset tag properties
615             * @param end the upper bound of the range of asset tag properties (not inclusive)
616             * @return the range of matching asset tag properties
617             */
618            @Override
619            public List<AssetTagProperty> findByTagId(long tagId, int start, int end) {
620                    return findByTagId(tagId, start, end, null);
621            }
622    
623            /**
624             * Returns an ordered range of all the asset tag properties where tagId = &#63;.
625             *
626             * <p>
627             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetTagPropertyModelImpl}. 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.
628             * </p>
629             *
630             * @param tagId the tag ID
631             * @param start the lower bound of the range of asset tag properties
632             * @param end the upper bound of the range of asset tag properties (not inclusive)
633             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
634             * @return the ordered range of matching asset tag properties
635             */
636            @Override
637            public List<AssetTagProperty> findByTagId(long tagId, int start, int end,
638                    OrderByComparator<AssetTagProperty> orderByComparator) {
639                    boolean pagination = true;
640                    FinderPath finderPath = null;
641                    Object[] finderArgs = null;
642    
643                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
644                                    (orderByComparator == null)) {
645                            pagination = false;
646                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TAGID;
647                            finderArgs = new Object[] { tagId };
648                    }
649                    else {
650                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TAGID;
651                            finderArgs = new Object[] { tagId, start, end, orderByComparator };
652                    }
653    
654                    List<AssetTagProperty> list = (List<AssetTagProperty>)FinderCacheUtil.getResult(finderPath,
655                                    finderArgs, this);
656    
657                    if ((list != null) && !list.isEmpty()) {
658                            for (AssetTagProperty assetTagProperty : list) {
659                                    if ((tagId != assetTagProperty.getTagId())) {
660                                            list = null;
661    
662                                            break;
663                                    }
664                            }
665                    }
666    
667                    if (list == null) {
668                            StringBundler query = null;
669    
670                            if (orderByComparator != null) {
671                                    query = new StringBundler(3 +
672                                                    (orderByComparator.getOrderByFields().length * 3));
673                            }
674                            else {
675                                    query = new StringBundler(3);
676                            }
677    
678                            query.append(_SQL_SELECT_ASSETTAGPROPERTY_WHERE);
679    
680                            query.append(_FINDER_COLUMN_TAGID_TAGID_2);
681    
682                            if (orderByComparator != null) {
683                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
684                                            orderByComparator);
685                            }
686                            else
687                             if (pagination) {
688                                    query.append(AssetTagPropertyModelImpl.ORDER_BY_JPQL);
689                            }
690    
691                            String sql = query.toString();
692    
693                            Session session = null;
694    
695                            try {
696                                    session = openSession();
697    
698                                    Query q = session.createQuery(sql);
699    
700                                    QueryPos qPos = QueryPos.getInstance(q);
701    
702                                    qPos.add(tagId);
703    
704                                    if (!pagination) {
705                                            list = (List<AssetTagProperty>)QueryUtil.list(q,
706                                                            getDialect(), start, end, false);
707    
708                                            Collections.sort(list);
709    
710                                            list = Collections.unmodifiableList(list);
711                                    }
712                                    else {
713                                            list = (List<AssetTagProperty>)QueryUtil.list(q,
714                                                            getDialect(), start, end);
715                                    }
716    
717                                    cacheResult(list);
718    
719                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
720                            }
721                            catch (Exception e) {
722                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
723    
724                                    throw processException(e);
725                            }
726                            finally {
727                                    closeSession(session);
728                            }
729                    }
730    
731                    return list;
732            }
733    
734            /**
735             * Returns the first asset tag property in the ordered set where tagId = &#63;.
736             *
737             * @param tagId the tag ID
738             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
739             * @return the first matching asset tag property
740             * @throws com.liferay.portlet.asset.NoSuchTagPropertyException if a matching asset tag property could not be found
741             */
742            @Override
743            public AssetTagProperty findByTagId_First(long tagId,
744                    OrderByComparator<AssetTagProperty> orderByComparator)
745                    throws NoSuchTagPropertyException {
746                    AssetTagProperty assetTagProperty = fetchByTagId_First(tagId,
747                                    orderByComparator);
748    
749                    if (assetTagProperty != null) {
750                            return assetTagProperty;
751                    }
752    
753                    StringBundler msg = new StringBundler(4);
754    
755                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
756    
757                    msg.append("tagId=");
758                    msg.append(tagId);
759    
760                    msg.append(StringPool.CLOSE_CURLY_BRACE);
761    
762                    throw new NoSuchTagPropertyException(msg.toString());
763            }
764    
765            /**
766             * Returns the first asset tag property in the ordered set where tagId = &#63;.
767             *
768             * @param tagId the tag ID
769             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
770             * @return the first matching asset tag property, or <code>null</code> if a matching asset tag property could not be found
771             */
772            @Override
773            public AssetTagProperty fetchByTagId_First(long tagId,
774                    OrderByComparator<AssetTagProperty> orderByComparator) {
775                    List<AssetTagProperty> list = findByTagId(tagId, 0, 1, orderByComparator);
776    
777                    if (!list.isEmpty()) {
778                            return list.get(0);
779                    }
780    
781                    return null;
782            }
783    
784            /**
785             * Returns the last asset tag property in the ordered set where tagId = &#63;.
786             *
787             * @param tagId the tag ID
788             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
789             * @return the last matching asset tag property
790             * @throws com.liferay.portlet.asset.NoSuchTagPropertyException if a matching asset tag property could not be found
791             */
792            @Override
793            public AssetTagProperty findByTagId_Last(long tagId,
794                    OrderByComparator<AssetTagProperty> orderByComparator)
795                    throws NoSuchTagPropertyException {
796                    AssetTagProperty assetTagProperty = fetchByTagId_Last(tagId,
797                                    orderByComparator);
798    
799                    if (assetTagProperty != null) {
800                            return assetTagProperty;
801                    }
802    
803                    StringBundler msg = new StringBundler(4);
804    
805                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
806    
807                    msg.append("tagId=");
808                    msg.append(tagId);
809    
810                    msg.append(StringPool.CLOSE_CURLY_BRACE);
811    
812                    throw new NoSuchTagPropertyException(msg.toString());
813            }
814    
815            /**
816             * Returns the last asset tag property in the ordered set where tagId = &#63;.
817             *
818             * @param tagId the tag ID
819             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
820             * @return the last matching asset tag property, or <code>null</code> if a matching asset tag property could not be found
821             */
822            @Override
823            public AssetTagProperty fetchByTagId_Last(long tagId,
824                    OrderByComparator<AssetTagProperty> orderByComparator) {
825                    int count = countByTagId(tagId);
826    
827                    if (count == 0) {
828                            return null;
829                    }
830    
831                    List<AssetTagProperty> list = findByTagId(tagId, count - 1, count,
832                                    orderByComparator);
833    
834                    if (!list.isEmpty()) {
835                            return list.get(0);
836                    }
837    
838                    return null;
839            }
840    
841            /**
842             * Returns the asset tag properties before and after the current asset tag property in the ordered set where tagId = &#63;.
843             *
844             * @param tagPropertyId the primary key of the current asset tag property
845             * @param tagId the tag ID
846             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
847             * @return the previous, current, and next asset tag property
848             * @throws com.liferay.portlet.asset.NoSuchTagPropertyException if a asset tag property with the primary key could not be found
849             */
850            @Override
851            public AssetTagProperty[] findByTagId_PrevAndNext(long tagPropertyId,
852                    long tagId, OrderByComparator<AssetTagProperty> orderByComparator)
853                    throws NoSuchTagPropertyException {
854                    AssetTagProperty assetTagProperty = findByPrimaryKey(tagPropertyId);
855    
856                    Session session = null;
857    
858                    try {
859                            session = openSession();
860    
861                            AssetTagProperty[] array = new AssetTagPropertyImpl[3];
862    
863                            array[0] = getByTagId_PrevAndNext(session, assetTagProperty, tagId,
864                                            orderByComparator, true);
865    
866                            array[1] = assetTagProperty;
867    
868                            array[2] = getByTagId_PrevAndNext(session, assetTagProperty, tagId,
869                                            orderByComparator, false);
870    
871                            return array;
872                    }
873                    catch (Exception e) {
874                            throw processException(e);
875                    }
876                    finally {
877                            closeSession(session);
878                    }
879            }
880    
881            protected AssetTagProperty getByTagId_PrevAndNext(Session session,
882                    AssetTagProperty assetTagProperty, long tagId,
883                    OrderByComparator<AssetTagProperty> orderByComparator, boolean previous) {
884                    StringBundler query = null;
885    
886                    if (orderByComparator != null) {
887                            query = new StringBundler(6 +
888                                            (orderByComparator.getOrderByFields().length * 6));
889                    }
890                    else {
891                            query = new StringBundler(3);
892                    }
893    
894                    query.append(_SQL_SELECT_ASSETTAGPROPERTY_WHERE);
895    
896                    query.append(_FINDER_COLUMN_TAGID_TAGID_2);
897    
898                    if (orderByComparator != null) {
899                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
900    
901                            if (orderByConditionFields.length > 0) {
902                                    query.append(WHERE_AND);
903                            }
904    
905                            for (int i = 0; i < orderByConditionFields.length; i++) {
906                                    query.append(_ORDER_BY_ENTITY_ALIAS);
907                                    query.append(orderByConditionFields[i]);
908    
909                                    if ((i + 1) < orderByConditionFields.length) {
910                                            if (orderByComparator.isAscending() ^ previous) {
911                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
912                                            }
913                                            else {
914                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
915                                            }
916                                    }
917                                    else {
918                                            if (orderByComparator.isAscending() ^ previous) {
919                                                    query.append(WHERE_GREATER_THAN);
920                                            }
921                                            else {
922                                                    query.append(WHERE_LESSER_THAN);
923                                            }
924                                    }
925                            }
926    
927                            query.append(ORDER_BY_CLAUSE);
928    
929                            String[] orderByFields = orderByComparator.getOrderByFields();
930    
931                            for (int i = 0; i < orderByFields.length; i++) {
932                                    query.append(_ORDER_BY_ENTITY_ALIAS);
933                                    query.append(orderByFields[i]);
934    
935                                    if ((i + 1) < orderByFields.length) {
936                                            if (orderByComparator.isAscending() ^ previous) {
937                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
938                                            }
939                                            else {
940                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
941                                            }
942                                    }
943                                    else {
944                                            if (orderByComparator.isAscending() ^ previous) {
945                                                    query.append(ORDER_BY_ASC);
946                                            }
947                                            else {
948                                                    query.append(ORDER_BY_DESC);
949                                            }
950                                    }
951                            }
952                    }
953                    else {
954                            query.append(AssetTagPropertyModelImpl.ORDER_BY_JPQL);
955                    }
956    
957                    String sql = query.toString();
958    
959                    Query q = session.createQuery(sql);
960    
961                    q.setFirstResult(0);
962                    q.setMaxResults(2);
963    
964                    QueryPos qPos = QueryPos.getInstance(q);
965    
966                    qPos.add(tagId);
967    
968                    if (orderByComparator != null) {
969                            Object[] values = orderByComparator.getOrderByConditionValues(assetTagProperty);
970    
971                            for (Object value : values) {
972                                    qPos.add(value);
973                            }
974                    }
975    
976                    List<AssetTagProperty> list = q.list();
977    
978                    if (list.size() == 2) {
979                            return list.get(1);
980                    }
981                    else {
982                            return null;
983                    }
984            }
985    
986            /**
987             * Removes all the asset tag properties where tagId = &#63; from the database.
988             *
989             * @param tagId the tag ID
990             */
991            @Override
992            public void removeByTagId(long tagId) {
993                    for (AssetTagProperty assetTagProperty : findByTagId(tagId,
994                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
995                            remove(assetTagProperty);
996                    }
997            }
998    
999            /**
1000             * Returns the number of asset tag properties where tagId = &#63;.
1001             *
1002             * @param tagId the tag ID
1003             * @return the number of matching asset tag properties
1004             */
1005            @Override
1006            public int countByTagId(long tagId) {
1007                    FinderPath finderPath = FINDER_PATH_COUNT_BY_TAGID;
1008    
1009                    Object[] finderArgs = new Object[] { tagId };
1010    
1011                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1012                                    this);
1013    
1014                    if (count == null) {
1015                            StringBundler query = new StringBundler(2);
1016    
1017                            query.append(_SQL_COUNT_ASSETTAGPROPERTY_WHERE);
1018    
1019                            query.append(_FINDER_COLUMN_TAGID_TAGID_2);
1020    
1021                            String sql = query.toString();
1022    
1023                            Session session = null;
1024    
1025                            try {
1026                                    session = openSession();
1027    
1028                                    Query q = session.createQuery(sql);
1029    
1030                                    QueryPos qPos = QueryPos.getInstance(q);
1031    
1032                                    qPos.add(tagId);
1033    
1034                                    count = (Long)q.uniqueResult();
1035    
1036                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1037                            }
1038                            catch (Exception e) {
1039                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1040    
1041                                    throw processException(e);
1042                            }
1043                            finally {
1044                                    closeSession(session);
1045                            }
1046                    }
1047    
1048                    return count.intValue();
1049            }
1050    
1051            private static final String _FINDER_COLUMN_TAGID_TAGID_2 = "assetTagProperty.tagId = ?";
1052            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_K = new FinderPath(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
1053                            AssetTagPropertyModelImpl.FINDER_CACHE_ENABLED,
1054                            AssetTagPropertyImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1055                            "findByC_K",
1056                            new String[] {
1057                                    Long.class.getName(), String.class.getName(),
1058                                    
1059                            Integer.class.getName(), Integer.class.getName(),
1060                                    OrderByComparator.class.getName()
1061                            });
1062            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_K = new FinderPath(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
1063                            AssetTagPropertyModelImpl.FINDER_CACHE_ENABLED,
1064                            AssetTagPropertyImpl.class,
1065                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_K",
1066                            new String[] { Long.class.getName(), String.class.getName() },
1067                            AssetTagPropertyModelImpl.COMPANYID_COLUMN_BITMASK |
1068                            AssetTagPropertyModelImpl.KEY_COLUMN_BITMASK);
1069            public static final FinderPath FINDER_PATH_COUNT_BY_C_K = new FinderPath(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
1070                            AssetTagPropertyModelImpl.FINDER_CACHE_ENABLED, Long.class,
1071                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_K",
1072                            new String[] { Long.class.getName(), String.class.getName() });
1073    
1074            /**
1075             * Returns all the asset tag properties where companyId = &#63; and key = &#63;.
1076             *
1077             * @param companyId the company ID
1078             * @param key the key
1079             * @return the matching asset tag properties
1080             */
1081            @Override
1082            public List<AssetTagProperty> findByC_K(long companyId, String key) {
1083                    return findByC_K(companyId, key, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1084                            null);
1085            }
1086    
1087            /**
1088             * Returns a range of all the asset tag properties where companyId = &#63; and key = &#63;.
1089             *
1090             * <p>
1091             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetTagPropertyModelImpl}. 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.
1092             * </p>
1093             *
1094             * @param companyId the company ID
1095             * @param key the key
1096             * @param start the lower bound of the range of asset tag properties
1097             * @param end the upper bound of the range of asset tag properties (not inclusive)
1098             * @return the range of matching asset tag properties
1099             */
1100            @Override
1101            public List<AssetTagProperty> findByC_K(long companyId, String key,
1102                    int start, int end) {
1103                    return findByC_K(companyId, key, start, end, null);
1104            }
1105    
1106            /**
1107             * Returns an ordered range of all the asset tag properties where companyId = &#63; and key = &#63;.
1108             *
1109             * <p>
1110             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetTagPropertyModelImpl}. 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.
1111             * </p>
1112             *
1113             * @param companyId the company ID
1114             * @param key the key
1115             * @param start the lower bound of the range of asset tag properties
1116             * @param end the upper bound of the range of asset tag properties (not inclusive)
1117             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1118             * @return the ordered range of matching asset tag properties
1119             */
1120            @Override
1121            public List<AssetTagProperty> findByC_K(long companyId, String key,
1122                    int start, int end,
1123                    OrderByComparator<AssetTagProperty> orderByComparator) {
1124                    boolean pagination = true;
1125                    FinderPath finderPath = null;
1126                    Object[] finderArgs = null;
1127    
1128                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1129                                    (orderByComparator == null)) {
1130                            pagination = false;
1131                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_K;
1132                            finderArgs = new Object[] { companyId, key };
1133                    }
1134                    else {
1135                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_K;
1136                            finderArgs = new Object[] {
1137                                            companyId, key,
1138                                            
1139                                            start, end, orderByComparator
1140                                    };
1141                    }
1142    
1143                    List<AssetTagProperty> list = (List<AssetTagProperty>)FinderCacheUtil.getResult(finderPath,
1144                                    finderArgs, this);
1145    
1146                    if ((list != null) && !list.isEmpty()) {
1147                            for (AssetTagProperty assetTagProperty : list) {
1148                                    if ((companyId != assetTagProperty.getCompanyId()) ||
1149                                                    !Validator.equals(key, assetTagProperty.getKey())) {
1150                                            list = null;
1151    
1152                                            break;
1153                                    }
1154                            }
1155                    }
1156    
1157                    if (list == null) {
1158                            StringBundler query = null;
1159    
1160                            if (orderByComparator != null) {
1161                                    query = new StringBundler(4 +
1162                                                    (orderByComparator.getOrderByFields().length * 3));
1163                            }
1164                            else {
1165                                    query = new StringBundler(4);
1166                            }
1167    
1168                            query.append(_SQL_SELECT_ASSETTAGPROPERTY_WHERE);
1169    
1170                            query.append(_FINDER_COLUMN_C_K_COMPANYID_2);
1171    
1172                            boolean bindKey = false;
1173    
1174                            if (key == null) {
1175                                    query.append(_FINDER_COLUMN_C_K_KEY_1);
1176                            }
1177                            else if (key.equals(StringPool.BLANK)) {
1178                                    query.append(_FINDER_COLUMN_C_K_KEY_3);
1179                            }
1180                            else {
1181                                    bindKey = true;
1182    
1183                                    query.append(_FINDER_COLUMN_C_K_KEY_2);
1184                            }
1185    
1186                            if (orderByComparator != null) {
1187                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1188                                            orderByComparator);
1189                            }
1190                            else
1191                             if (pagination) {
1192                                    query.append(AssetTagPropertyModelImpl.ORDER_BY_JPQL);
1193                            }
1194    
1195                            String sql = query.toString();
1196    
1197                            Session session = null;
1198    
1199                            try {
1200                                    session = openSession();
1201    
1202                                    Query q = session.createQuery(sql);
1203    
1204                                    QueryPos qPos = QueryPos.getInstance(q);
1205    
1206                                    qPos.add(companyId);
1207    
1208                                    if (bindKey) {
1209                                            qPos.add(key);
1210                                    }
1211    
1212                                    if (!pagination) {
1213                                            list = (List<AssetTagProperty>)QueryUtil.list(q,
1214                                                            getDialect(), start, end, false);
1215    
1216                                            Collections.sort(list);
1217    
1218                                            list = Collections.unmodifiableList(list);
1219                                    }
1220                                    else {
1221                                            list = (List<AssetTagProperty>)QueryUtil.list(q,
1222                                                            getDialect(), start, end);
1223                                    }
1224    
1225                                    cacheResult(list);
1226    
1227                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1228                            }
1229                            catch (Exception e) {
1230                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1231    
1232                                    throw processException(e);
1233                            }
1234                            finally {
1235                                    closeSession(session);
1236                            }
1237                    }
1238    
1239                    return list;
1240            }
1241    
1242            /**
1243             * Returns the first asset tag property in the ordered set where companyId = &#63; and key = &#63;.
1244             *
1245             * @param companyId the company ID
1246             * @param key the key
1247             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1248             * @return the first matching asset tag property
1249             * @throws com.liferay.portlet.asset.NoSuchTagPropertyException if a matching asset tag property could not be found
1250             */
1251            @Override
1252            public AssetTagProperty findByC_K_First(long companyId, String key,
1253                    OrderByComparator<AssetTagProperty> orderByComparator)
1254                    throws NoSuchTagPropertyException {
1255                    AssetTagProperty assetTagProperty = fetchByC_K_First(companyId, key,
1256                                    orderByComparator);
1257    
1258                    if (assetTagProperty != null) {
1259                            return assetTagProperty;
1260                    }
1261    
1262                    StringBundler msg = new StringBundler(6);
1263    
1264                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1265    
1266                    msg.append("companyId=");
1267                    msg.append(companyId);
1268    
1269                    msg.append(", key=");
1270                    msg.append(key);
1271    
1272                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1273    
1274                    throw new NoSuchTagPropertyException(msg.toString());
1275            }
1276    
1277            /**
1278             * Returns the first asset tag property in the ordered set where companyId = &#63; and key = &#63;.
1279             *
1280             * @param companyId the company ID
1281             * @param key the key
1282             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1283             * @return the first matching asset tag property, or <code>null</code> if a matching asset tag property could not be found
1284             */
1285            @Override
1286            public AssetTagProperty fetchByC_K_First(long companyId, String key,
1287                    OrderByComparator<AssetTagProperty> orderByComparator) {
1288                    List<AssetTagProperty> list = findByC_K(companyId, key, 0, 1,
1289                                    orderByComparator);
1290    
1291                    if (!list.isEmpty()) {
1292                            return list.get(0);
1293                    }
1294    
1295                    return null;
1296            }
1297    
1298            /**
1299             * Returns the last asset tag property in the ordered set where companyId = &#63; and key = &#63;.
1300             *
1301             * @param companyId the company ID
1302             * @param key the key
1303             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1304             * @return the last matching asset tag property
1305             * @throws com.liferay.portlet.asset.NoSuchTagPropertyException if a matching asset tag property could not be found
1306             */
1307            @Override
1308            public AssetTagProperty findByC_K_Last(long companyId, String key,
1309                    OrderByComparator<AssetTagProperty> orderByComparator)
1310                    throws NoSuchTagPropertyException {
1311                    AssetTagProperty assetTagProperty = fetchByC_K_Last(companyId, key,
1312                                    orderByComparator);
1313    
1314                    if (assetTagProperty != null) {
1315                            return assetTagProperty;
1316                    }
1317    
1318                    StringBundler msg = new StringBundler(6);
1319    
1320                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1321    
1322                    msg.append("companyId=");
1323                    msg.append(companyId);
1324    
1325                    msg.append(", key=");
1326                    msg.append(key);
1327    
1328                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1329    
1330                    throw new NoSuchTagPropertyException(msg.toString());
1331            }
1332    
1333            /**
1334             * Returns the last asset tag property in the ordered set where companyId = &#63; and key = &#63;.
1335             *
1336             * @param companyId the company ID
1337             * @param key the key
1338             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1339             * @return the last matching asset tag property, or <code>null</code> if a matching asset tag property could not be found
1340             */
1341            @Override
1342            public AssetTagProperty fetchByC_K_Last(long companyId, String key,
1343                    OrderByComparator<AssetTagProperty> orderByComparator) {
1344                    int count = countByC_K(companyId, key);
1345    
1346                    if (count == 0) {
1347                            return null;
1348                    }
1349    
1350                    List<AssetTagProperty> list = findByC_K(companyId, key, count - 1,
1351                                    count, orderByComparator);
1352    
1353                    if (!list.isEmpty()) {
1354                            return list.get(0);
1355                    }
1356    
1357                    return null;
1358            }
1359    
1360            /**
1361             * Returns the asset tag properties before and after the current asset tag property in the ordered set where companyId = &#63; and key = &#63;.
1362             *
1363             * @param tagPropertyId the primary key of the current asset tag property
1364             * @param companyId the company ID
1365             * @param key the key
1366             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1367             * @return the previous, current, and next asset tag property
1368             * @throws com.liferay.portlet.asset.NoSuchTagPropertyException if a asset tag property with the primary key could not be found
1369             */
1370            @Override
1371            public AssetTagProperty[] findByC_K_PrevAndNext(long tagPropertyId,
1372                    long companyId, String key,
1373                    OrderByComparator<AssetTagProperty> orderByComparator)
1374                    throws NoSuchTagPropertyException {
1375                    AssetTagProperty assetTagProperty = findByPrimaryKey(tagPropertyId);
1376    
1377                    Session session = null;
1378    
1379                    try {
1380                            session = openSession();
1381    
1382                            AssetTagProperty[] array = new AssetTagPropertyImpl[3];
1383    
1384                            array[0] = getByC_K_PrevAndNext(session, assetTagProperty,
1385                                            companyId, key, orderByComparator, true);
1386    
1387                            array[1] = assetTagProperty;
1388    
1389                            array[2] = getByC_K_PrevAndNext(session, assetTagProperty,
1390                                            companyId, key, orderByComparator, false);
1391    
1392                            return array;
1393                    }
1394                    catch (Exception e) {
1395                            throw processException(e);
1396                    }
1397                    finally {
1398                            closeSession(session);
1399                    }
1400            }
1401    
1402            protected AssetTagProperty getByC_K_PrevAndNext(Session session,
1403                    AssetTagProperty assetTagProperty, long companyId, String key,
1404                    OrderByComparator<AssetTagProperty> orderByComparator, boolean previous) {
1405                    StringBundler query = null;
1406    
1407                    if (orderByComparator != null) {
1408                            query = new StringBundler(6 +
1409                                            (orderByComparator.getOrderByFields().length * 6));
1410                    }
1411                    else {
1412                            query = new StringBundler(3);
1413                    }
1414    
1415                    query.append(_SQL_SELECT_ASSETTAGPROPERTY_WHERE);
1416    
1417                    query.append(_FINDER_COLUMN_C_K_COMPANYID_2);
1418    
1419                    boolean bindKey = false;
1420    
1421                    if (key == null) {
1422                            query.append(_FINDER_COLUMN_C_K_KEY_1);
1423                    }
1424                    else if (key.equals(StringPool.BLANK)) {
1425                            query.append(_FINDER_COLUMN_C_K_KEY_3);
1426                    }
1427                    else {
1428                            bindKey = true;
1429    
1430                            query.append(_FINDER_COLUMN_C_K_KEY_2);
1431                    }
1432    
1433                    if (orderByComparator != null) {
1434                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1435    
1436                            if (orderByConditionFields.length > 0) {
1437                                    query.append(WHERE_AND);
1438                            }
1439    
1440                            for (int i = 0; i < orderByConditionFields.length; i++) {
1441                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1442                                    query.append(orderByConditionFields[i]);
1443    
1444                                    if ((i + 1) < orderByConditionFields.length) {
1445                                            if (orderByComparator.isAscending() ^ previous) {
1446                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1447                                            }
1448                                            else {
1449                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1450                                            }
1451                                    }
1452                                    else {
1453                                            if (orderByComparator.isAscending() ^ previous) {
1454                                                    query.append(WHERE_GREATER_THAN);
1455                                            }
1456                                            else {
1457                                                    query.append(WHERE_LESSER_THAN);
1458                                            }
1459                                    }
1460                            }
1461    
1462                            query.append(ORDER_BY_CLAUSE);
1463    
1464                            String[] orderByFields = orderByComparator.getOrderByFields();
1465    
1466                            for (int i = 0; i < orderByFields.length; i++) {
1467                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1468                                    query.append(orderByFields[i]);
1469    
1470                                    if ((i + 1) < orderByFields.length) {
1471                                            if (orderByComparator.isAscending() ^ previous) {
1472                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1473                                            }
1474                                            else {
1475                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1476                                            }
1477                                    }
1478                                    else {
1479                                            if (orderByComparator.isAscending() ^ previous) {
1480                                                    query.append(ORDER_BY_ASC);
1481                                            }
1482                                            else {
1483                                                    query.append(ORDER_BY_DESC);
1484                                            }
1485                                    }
1486                            }
1487                    }
1488                    else {
1489                            query.append(AssetTagPropertyModelImpl.ORDER_BY_JPQL);
1490                    }
1491    
1492                    String sql = query.toString();
1493    
1494                    Query q = session.createQuery(sql);
1495    
1496                    q.setFirstResult(0);
1497                    q.setMaxResults(2);
1498    
1499                    QueryPos qPos = QueryPos.getInstance(q);
1500    
1501                    qPos.add(companyId);
1502    
1503                    if (bindKey) {
1504                            qPos.add(key);
1505                    }
1506    
1507                    if (orderByComparator != null) {
1508                            Object[] values = orderByComparator.getOrderByConditionValues(assetTagProperty);
1509    
1510                            for (Object value : values) {
1511                                    qPos.add(value);
1512                            }
1513                    }
1514    
1515                    List<AssetTagProperty> list = q.list();
1516    
1517                    if (list.size() == 2) {
1518                            return list.get(1);
1519                    }
1520                    else {
1521                            return null;
1522                    }
1523            }
1524    
1525            /**
1526             * Removes all the asset tag properties where companyId = &#63; and key = &#63; from the database.
1527             *
1528             * @param companyId the company ID
1529             * @param key the key
1530             */
1531            @Override
1532            public void removeByC_K(long companyId, String key) {
1533                    for (AssetTagProperty assetTagProperty : findByC_K(companyId, key,
1534                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1535                            remove(assetTagProperty);
1536                    }
1537            }
1538    
1539            /**
1540             * Returns the number of asset tag properties where companyId = &#63; and key = &#63;.
1541             *
1542             * @param companyId the company ID
1543             * @param key the key
1544             * @return the number of matching asset tag properties
1545             */
1546            @Override
1547            public int countByC_K(long companyId, String key) {
1548                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_K;
1549    
1550                    Object[] finderArgs = new Object[] { companyId, key };
1551    
1552                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1553                                    this);
1554    
1555                    if (count == null) {
1556                            StringBundler query = new StringBundler(3);
1557    
1558                            query.append(_SQL_COUNT_ASSETTAGPROPERTY_WHERE);
1559    
1560                            query.append(_FINDER_COLUMN_C_K_COMPANYID_2);
1561    
1562                            boolean bindKey = false;
1563    
1564                            if (key == null) {
1565                                    query.append(_FINDER_COLUMN_C_K_KEY_1);
1566                            }
1567                            else if (key.equals(StringPool.BLANK)) {
1568                                    query.append(_FINDER_COLUMN_C_K_KEY_3);
1569                            }
1570                            else {
1571                                    bindKey = true;
1572    
1573                                    query.append(_FINDER_COLUMN_C_K_KEY_2);
1574                            }
1575    
1576                            String sql = query.toString();
1577    
1578                            Session session = null;
1579    
1580                            try {
1581                                    session = openSession();
1582    
1583                                    Query q = session.createQuery(sql);
1584    
1585                                    QueryPos qPos = QueryPos.getInstance(q);
1586    
1587                                    qPos.add(companyId);
1588    
1589                                    if (bindKey) {
1590                                            qPos.add(key);
1591                                    }
1592    
1593                                    count = (Long)q.uniqueResult();
1594    
1595                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1596                            }
1597                            catch (Exception e) {
1598                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1599    
1600                                    throw processException(e);
1601                            }
1602                            finally {
1603                                    closeSession(session);
1604                            }
1605                    }
1606    
1607                    return count.intValue();
1608            }
1609    
1610            private static final String _FINDER_COLUMN_C_K_COMPANYID_2 = "assetTagProperty.companyId = ? AND ";
1611            private static final String _FINDER_COLUMN_C_K_KEY_1 = "assetTagProperty.key IS NULL";
1612            private static final String _FINDER_COLUMN_C_K_KEY_2 = "assetTagProperty.key = ?";
1613            private static final String _FINDER_COLUMN_C_K_KEY_3 = "(assetTagProperty.key IS NULL OR assetTagProperty.key = '')";
1614            public static final FinderPath FINDER_PATH_FETCH_BY_T_K = new FinderPath(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
1615                            AssetTagPropertyModelImpl.FINDER_CACHE_ENABLED,
1616                            AssetTagPropertyImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByT_K",
1617                            new String[] { Long.class.getName(), String.class.getName() },
1618                            AssetTagPropertyModelImpl.TAGID_COLUMN_BITMASK |
1619                            AssetTagPropertyModelImpl.KEY_COLUMN_BITMASK);
1620            public static final FinderPath FINDER_PATH_COUNT_BY_T_K = new FinderPath(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
1621                            AssetTagPropertyModelImpl.FINDER_CACHE_ENABLED, Long.class,
1622                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_K",
1623                            new String[] { Long.class.getName(), String.class.getName() });
1624    
1625            /**
1626             * Returns the asset tag property where tagId = &#63; and key = &#63; or throws a {@link com.liferay.portlet.asset.NoSuchTagPropertyException} if it could not be found.
1627             *
1628             * @param tagId the tag ID
1629             * @param key the key
1630             * @return the matching asset tag property
1631             * @throws com.liferay.portlet.asset.NoSuchTagPropertyException if a matching asset tag property could not be found
1632             */
1633            @Override
1634            public AssetTagProperty findByT_K(long tagId, String key)
1635                    throws NoSuchTagPropertyException {
1636                    AssetTagProperty assetTagProperty = fetchByT_K(tagId, key);
1637    
1638                    if (assetTagProperty == null) {
1639                            StringBundler msg = new StringBundler(6);
1640    
1641                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1642    
1643                            msg.append("tagId=");
1644                            msg.append(tagId);
1645    
1646                            msg.append(", key=");
1647                            msg.append(key);
1648    
1649                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1650    
1651                            if (_log.isWarnEnabled()) {
1652                                    _log.warn(msg.toString());
1653                            }
1654    
1655                            throw new NoSuchTagPropertyException(msg.toString());
1656                    }
1657    
1658                    return assetTagProperty;
1659            }
1660    
1661            /**
1662             * Returns the asset tag property where tagId = &#63; and key = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1663             *
1664             * @param tagId the tag ID
1665             * @param key the key
1666             * @return the matching asset tag property, or <code>null</code> if a matching asset tag property could not be found
1667             */
1668            @Override
1669            public AssetTagProperty fetchByT_K(long tagId, String key) {
1670                    return fetchByT_K(tagId, key, true);
1671            }
1672    
1673            /**
1674             * Returns the asset tag property where tagId = &#63; and key = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1675             *
1676             * @param tagId the tag ID
1677             * @param key the key
1678             * @param retrieveFromCache whether to use the finder cache
1679             * @return the matching asset tag property, or <code>null</code> if a matching asset tag property could not be found
1680             */
1681            @Override
1682            public AssetTagProperty fetchByT_K(long tagId, String key,
1683                    boolean retrieveFromCache) {
1684                    Object[] finderArgs = new Object[] { tagId, key };
1685    
1686                    Object result = null;
1687    
1688                    if (retrieveFromCache) {
1689                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_T_K,
1690                                            finderArgs, this);
1691                    }
1692    
1693                    if (result instanceof AssetTagProperty) {
1694                            AssetTagProperty assetTagProperty = (AssetTagProperty)result;
1695    
1696                            if ((tagId != assetTagProperty.getTagId()) ||
1697                                            !Validator.equals(key, assetTagProperty.getKey())) {
1698                                    result = null;
1699                            }
1700                    }
1701    
1702                    if (result == null) {
1703                            StringBundler query = new StringBundler(4);
1704    
1705                            query.append(_SQL_SELECT_ASSETTAGPROPERTY_WHERE);
1706    
1707                            query.append(_FINDER_COLUMN_T_K_TAGID_2);
1708    
1709                            boolean bindKey = false;
1710    
1711                            if (key == null) {
1712                                    query.append(_FINDER_COLUMN_T_K_KEY_1);
1713                            }
1714                            else if (key.equals(StringPool.BLANK)) {
1715                                    query.append(_FINDER_COLUMN_T_K_KEY_3);
1716                            }
1717                            else {
1718                                    bindKey = true;
1719    
1720                                    query.append(_FINDER_COLUMN_T_K_KEY_2);
1721                            }
1722    
1723                            String sql = query.toString();
1724    
1725                            Session session = null;
1726    
1727                            try {
1728                                    session = openSession();
1729    
1730                                    Query q = session.createQuery(sql);
1731    
1732                                    QueryPos qPos = QueryPos.getInstance(q);
1733    
1734                                    qPos.add(tagId);
1735    
1736                                    if (bindKey) {
1737                                            qPos.add(key);
1738                                    }
1739    
1740                                    List<AssetTagProperty> list = q.list();
1741    
1742                                    if (list.isEmpty()) {
1743                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_K,
1744                                                    finderArgs, list);
1745                                    }
1746                                    else {
1747                                            AssetTagProperty assetTagProperty = list.get(0);
1748    
1749                                            result = assetTagProperty;
1750    
1751                                            cacheResult(assetTagProperty);
1752    
1753                                            if ((assetTagProperty.getTagId() != tagId) ||
1754                                                            (assetTagProperty.getKey() == null) ||
1755                                                            !assetTagProperty.getKey().equals(key)) {
1756                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_K,
1757                                                            finderArgs, assetTagProperty);
1758                                            }
1759                                    }
1760                            }
1761                            catch (Exception e) {
1762                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_K,
1763                                            finderArgs);
1764    
1765                                    throw processException(e);
1766                            }
1767                            finally {
1768                                    closeSession(session);
1769                            }
1770                    }
1771    
1772                    if (result instanceof List<?>) {
1773                            return null;
1774                    }
1775                    else {
1776                            return (AssetTagProperty)result;
1777                    }
1778            }
1779    
1780            /**
1781             * Removes the asset tag property where tagId = &#63; and key = &#63; from the database.
1782             *
1783             * @param tagId the tag ID
1784             * @param key the key
1785             * @return the asset tag property that was removed
1786             */
1787            @Override
1788            public AssetTagProperty removeByT_K(long tagId, String key)
1789                    throws NoSuchTagPropertyException {
1790                    AssetTagProperty assetTagProperty = findByT_K(tagId, key);
1791    
1792                    return remove(assetTagProperty);
1793            }
1794    
1795            /**
1796             * Returns the number of asset tag properties where tagId = &#63; and key = &#63;.
1797             *
1798             * @param tagId the tag ID
1799             * @param key the key
1800             * @return the number of matching asset tag properties
1801             */
1802            @Override
1803            public int countByT_K(long tagId, String key) {
1804                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_K;
1805    
1806                    Object[] finderArgs = new Object[] { tagId, key };
1807    
1808                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1809                                    this);
1810    
1811                    if (count == null) {
1812                            StringBundler query = new StringBundler(3);
1813    
1814                            query.append(_SQL_COUNT_ASSETTAGPROPERTY_WHERE);
1815    
1816                            query.append(_FINDER_COLUMN_T_K_TAGID_2);
1817    
1818                            boolean bindKey = false;
1819    
1820                            if (key == null) {
1821                                    query.append(_FINDER_COLUMN_T_K_KEY_1);
1822                            }
1823                            else if (key.equals(StringPool.BLANK)) {
1824                                    query.append(_FINDER_COLUMN_T_K_KEY_3);
1825                            }
1826                            else {
1827                                    bindKey = true;
1828    
1829                                    query.append(_FINDER_COLUMN_T_K_KEY_2);
1830                            }
1831    
1832                            String sql = query.toString();
1833    
1834                            Session session = null;
1835    
1836                            try {
1837                                    session = openSession();
1838    
1839                                    Query q = session.createQuery(sql);
1840    
1841                                    QueryPos qPos = QueryPos.getInstance(q);
1842    
1843                                    qPos.add(tagId);
1844    
1845                                    if (bindKey) {
1846                                            qPos.add(key);
1847                                    }
1848    
1849                                    count = (Long)q.uniqueResult();
1850    
1851                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1852                            }
1853                            catch (Exception e) {
1854                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1855    
1856                                    throw processException(e);
1857                            }
1858                            finally {
1859                                    closeSession(session);
1860                            }
1861                    }
1862    
1863                    return count.intValue();
1864            }
1865    
1866            private static final String _FINDER_COLUMN_T_K_TAGID_2 = "assetTagProperty.tagId = ? AND ";
1867            private static final String _FINDER_COLUMN_T_K_KEY_1 = "assetTagProperty.key IS NULL";
1868            private static final String _FINDER_COLUMN_T_K_KEY_2 = "assetTagProperty.key = ?";
1869            private static final String _FINDER_COLUMN_T_K_KEY_3 = "(assetTagProperty.key IS NULL OR assetTagProperty.key = '')";
1870    
1871            public AssetTagPropertyPersistenceImpl() {
1872                    setModelClass(AssetTagProperty.class);
1873            }
1874    
1875            /**
1876             * Caches the asset tag property in the entity cache if it is enabled.
1877             *
1878             * @param assetTagProperty the asset tag property
1879             */
1880            @Override
1881            public void cacheResult(AssetTagProperty assetTagProperty) {
1882                    EntityCacheUtil.putResult(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
1883                            AssetTagPropertyImpl.class, assetTagProperty.getPrimaryKey(),
1884                            assetTagProperty);
1885    
1886                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_K,
1887                            new Object[] { assetTagProperty.getTagId(), assetTagProperty.getKey() },
1888                            assetTagProperty);
1889    
1890                    assetTagProperty.resetOriginalValues();
1891            }
1892    
1893            /**
1894             * Caches the asset tag properties in the entity cache if it is enabled.
1895             *
1896             * @param assetTagProperties the asset tag properties
1897             */
1898            @Override
1899            public void cacheResult(List<AssetTagProperty> assetTagProperties) {
1900                    for (AssetTagProperty assetTagProperty : assetTagProperties) {
1901                            if (EntityCacheUtil.getResult(
1902                                                    AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
1903                                                    AssetTagPropertyImpl.class,
1904                                                    assetTagProperty.getPrimaryKey()) == null) {
1905                                    cacheResult(assetTagProperty);
1906                            }
1907                            else {
1908                                    assetTagProperty.resetOriginalValues();
1909                            }
1910                    }
1911            }
1912    
1913            /**
1914             * Clears the cache for all asset tag properties.
1915             *
1916             * <p>
1917             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1918             * </p>
1919             */
1920            @Override
1921            public void clearCache() {
1922                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1923                            CacheRegistryUtil.clear(AssetTagPropertyImpl.class.getName());
1924                    }
1925    
1926                    EntityCacheUtil.clearCache(AssetTagPropertyImpl.class);
1927    
1928                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1929                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1930                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1931            }
1932    
1933            /**
1934             * Clears the cache for the asset tag property.
1935             *
1936             * <p>
1937             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1938             * </p>
1939             */
1940            @Override
1941            public void clearCache(AssetTagProperty assetTagProperty) {
1942                    EntityCacheUtil.removeResult(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
1943                            AssetTagPropertyImpl.class, assetTagProperty.getPrimaryKey());
1944    
1945                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1946                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1947    
1948                    clearUniqueFindersCache(assetTagProperty);
1949            }
1950    
1951            @Override
1952            public void clearCache(List<AssetTagProperty> assetTagProperties) {
1953                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1954                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1955    
1956                    for (AssetTagProperty assetTagProperty : assetTagProperties) {
1957                            EntityCacheUtil.removeResult(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
1958                                    AssetTagPropertyImpl.class, assetTagProperty.getPrimaryKey());
1959    
1960                            clearUniqueFindersCache(assetTagProperty);
1961                    }
1962            }
1963    
1964            protected void cacheUniqueFindersCache(AssetTagProperty assetTagProperty) {
1965                    if (assetTagProperty.isNew()) {
1966                            Object[] args = new Object[] {
1967                                            assetTagProperty.getTagId(), assetTagProperty.getKey()
1968                                    };
1969    
1970                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_K, args,
1971                                    Long.valueOf(1));
1972                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_K, args,
1973                                    assetTagProperty);
1974                    }
1975                    else {
1976                            AssetTagPropertyModelImpl assetTagPropertyModelImpl = (AssetTagPropertyModelImpl)assetTagProperty;
1977    
1978                            if ((assetTagPropertyModelImpl.getColumnBitmask() &
1979                                            FINDER_PATH_FETCH_BY_T_K.getColumnBitmask()) != 0) {
1980                                    Object[] args = new Object[] {
1981                                                    assetTagProperty.getTagId(), assetTagProperty.getKey()
1982                                            };
1983    
1984                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_K, args,
1985                                            Long.valueOf(1));
1986                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_K, args,
1987                                            assetTagProperty);
1988                            }
1989                    }
1990            }
1991    
1992            protected void clearUniqueFindersCache(AssetTagProperty assetTagProperty) {
1993                    AssetTagPropertyModelImpl assetTagPropertyModelImpl = (AssetTagPropertyModelImpl)assetTagProperty;
1994    
1995                    Object[] args = new Object[] {
1996                                    assetTagProperty.getTagId(), assetTagProperty.getKey()
1997                            };
1998    
1999                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_K, args);
2000                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_K, args);
2001    
2002                    if ((assetTagPropertyModelImpl.getColumnBitmask() &
2003                                    FINDER_PATH_FETCH_BY_T_K.getColumnBitmask()) != 0) {
2004                            args = new Object[] {
2005                                            assetTagPropertyModelImpl.getOriginalTagId(),
2006                                            assetTagPropertyModelImpl.getOriginalKey()
2007                                    };
2008    
2009                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_K, args);
2010                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_K, args);
2011                    }
2012            }
2013    
2014            /**
2015             * Creates a new asset tag property with the primary key. Does not add the asset tag property to the database.
2016             *
2017             * @param tagPropertyId the primary key for the new asset tag property
2018             * @return the new asset tag property
2019             */
2020            @Override
2021            public AssetTagProperty create(long tagPropertyId) {
2022                    AssetTagProperty assetTagProperty = new AssetTagPropertyImpl();
2023    
2024                    assetTagProperty.setNew(true);
2025                    assetTagProperty.setPrimaryKey(tagPropertyId);
2026    
2027                    return assetTagProperty;
2028            }
2029    
2030            /**
2031             * Removes the asset tag property with the primary key from the database. Also notifies the appropriate model listeners.
2032             *
2033             * @param tagPropertyId the primary key of the asset tag property
2034             * @return the asset tag property that was removed
2035             * @throws com.liferay.portlet.asset.NoSuchTagPropertyException if a asset tag property with the primary key could not be found
2036             */
2037            @Override
2038            public AssetTagProperty remove(long tagPropertyId)
2039                    throws NoSuchTagPropertyException {
2040                    return remove((Serializable)tagPropertyId);
2041            }
2042    
2043            /**
2044             * Removes the asset tag property with the primary key from the database. Also notifies the appropriate model listeners.
2045             *
2046             * @param primaryKey the primary key of the asset tag property
2047             * @return the asset tag property that was removed
2048             * @throws com.liferay.portlet.asset.NoSuchTagPropertyException if a asset tag property with the primary key could not be found
2049             */
2050            @Override
2051            public AssetTagProperty remove(Serializable primaryKey)
2052                    throws NoSuchTagPropertyException {
2053                    Session session = null;
2054    
2055                    try {
2056                            session = openSession();
2057    
2058                            AssetTagProperty assetTagProperty = (AssetTagProperty)session.get(AssetTagPropertyImpl.class,
2059                                            primaryKey);
2060    
2061                            if (assetTagProperty == null) {
2062                                    if (_log.isWarnEnabled()) {
2063                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2064                                    }
2065    
2066                                    throw new NoSuchTagPropertyException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2067                                            primaryKey);
2068                            }
2069    
2070                            return remove(assetTagProperty);
2071                    }
2072                    catch (NoSuchTagPropertyException nsee) {
2073                            throw nsee;
2074                    }
2075                    catch (Exception e) {
2076                            throw processException(e);
2077                    }
2078                    finally {
2079                            closeSession(session);
2080                    }
2081            }
2082    
2083            @Override
2084            protected AssetTagProperty removeImpl(AssetTagProperty assetTagProperty) {
2085                    assetTagProperty = toUnwrappedModel(assetTagProperty);
2086    
2087                    Session session = null;
2088    
2089                    try {
2090                            session = openSession();
2091    
2092                            if (!session.contains(assetTagProperty)) {
2093                                    assetTagProperty = (AssetTagProperty)session.get(AssetTagPropertyImpl.class,
2094                                                    assetTagProperty.getPrimaryKeyObj());
2095                            }
2096    
2097                            if (assetTagProperty != null) {
2098                                    session.delete(assetTagProperty);
2099                            }
2100                    }
2101                    catch (Exception e) {
2102                            throw processException(e);
2103                    }
2104                    finally {
2105                            closeSession(session);
2106                    }
2107    
2108                    if (assetTagProperty != null) {
2109                            clearCache(assetTagProperty);
2110                    }
2111    
2112                    return assetTagProperty;
2113            }
2114    
2115            @Override
2116            public AssetTagProperty updateImpl(
2117                    com.liferay.portlet.asset.model.AssetTagProperty assetTagProperty) {
2118                    assetTagProperty = toUnwrappedModel(assetTagProperty);
2119    
2120                    boolean isNew = assetTagProperty.isNew();
2121    
2122                    AssetTagPropertyModelImpl assetTagPropertyModelImpl = (AssetTagPropertyModelImpl)assetTagProperty;
2123    
2124                    Session session = null;
2125    
2126                    try {
2127                            session = openSession();
2128    
2129                            if (assetTagProperty.isNew()) {
2130                                    session.save(assetTagProperty);
2131    
2132                                    assetTagProperty.setNew(false);
2133                            }
2134                            else {
2135                                    session.merge(assetTagProperty);
2136                            }
2137                    }
2138                    catch (Exception e) {
2139                            throw processException(e);
2140                    }
2141                    finally {
2142                            closeSession(session);
2143                    }
2144    
2145                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2146    
2147                    if (isNew || !AssetTagPropertyModelImpl.COLUMN_BITMASK_ENABLED) {
2148                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2149                    }
2150    
2151                    else {
2152                            if ((assetTagPropertyModelImpl.getColumnBitmask() &
2153                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
2154                                    Object[] args = new Object[] {
2155                                                    assetTagPropertyModelImpl.getOriginalCompanyId()
2156                                            };
2157    
2158                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
2159                                            args);
2160                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
2161                                            args);
2162    
2163                                    args = new Object[] { assetTagPropertyModelImpl.getCompanyId() };
2164    
2165                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
2166                                            args);
2167                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
2168                                            args);
2169                            }
2170    
2171                            if ((assetTagPropertyModelImpl.getColumnBitmask() &
2172                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TAGID.getColumnBitmask()) != 0) {
2173                                    Object[] args = new Object[] {
2174                                                    assetTagPropertyModelImpl.getOriginalTagId()
2175                                            };
2176    
2177                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TAGID, args);
2178                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TAGID,
2179                                            args);
2180    
2181                                    args = new Object[] { assetTagPropertyModelImpl.getTagId() };
2182    
2183                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TAGID, args);
2184                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TAGID,
2185                                            args);
2186                            }
2187    
2188                            if ((assetTagPropertyModelImpl.getColumnBitmask() &
2189                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_K.getColumnBitmask()) != 0) {
2190                                    Object[] args = new Object[] {
2191                                                    assetTagPropertyModelImpl.getOriginalCompanyId(),
2192                                                    assetTagPropertyModelImpl.getOriginalKey()
2193                                            };
2194    
2195                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_K, args);
2196                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_K,
2197                                            args);
2198    
2199                                    args = new Object[] {
2200                                                    assetTagPropertyModelImpl.getCompanyId(),
2201                                                    assetTagPropertyModelImpl.getKey()
2202                                            };
2203    
2204                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_K, args);
2205                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_K,
2206                                            args);
2207                            }
2208                    }
2209    
2210                    EntityCacheUtil.putResult(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
2211                            AssetTagPropertyImpl.class, assetTagProperty.getPrimaryKey(),
2212                            assetTagProperty, false);
2213    
2214                    clearUniqueFindersCache(assetTagProperty);
2215                    cacheUniqueFindersCache(assetTagProperty);
2216    
2217                    assetTagProperty.resetOriginalValues();
2218    
2219                    return assetTagProperty;
2220            }
2221    
2222            protected AssetTagProperty toUnwrappedModel(
2223                    AssetTagProperty assetTagProperty) {
2224                    if (assetTagProperty instanceof AssetTagPropertyImpl) {
2225                            return assetTagProperty;
2226                    }
2227    
2228                    AssetTagPropertyImpl assetTagPropertyImpl = new AssetTagPropertyImpl();
2229    
2230                    assetTagPropertyImpl.setNew(assetTagProperty.isNew());
2231                    assetTagPropertyImpl.setPrimaryKey(assetTagProperty.getPrimaryKey());
2232    
2233                    assetTagPropertyImpl.setTagPropertyId(assetTagProperty.getTagPropertyId());
2234                    assetTagPropertyImpl.setCompanyId(assetTagProperty.getCompanyId());
2235                    assetTagPropertyImpl.setUserId(assetTagProperty.getUserId());
2236                    assetTagPropertyImpl.setUserName(assetTagProperty.getUserName());
2237                    assetTagPropertyImpl.setCreateDate(assetTagProperty.getCreateDate());
2238                    assetTagPropertyImpl.setModifiedDate(assetTagProperty.getModifiedDate());
2239                    assetTagPropertyImpl.setTagId(assetTagProperty.getTagId());
2240                    assetTagPropertyImpl.setKey(assetTagProperty.getKey());
2241                    assetTagPropertyImpl.setValue(assetTagProperty.getValue());
2242    
2243                    return assetTagPropertyImpl;
2244            }
2245    
2246            /**
2247             * Returns the asset tag property with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
2248             *
2249             * @param primaryKey the primary key of the asset tag property
2250             * @return the asset tag property
2251             * @throws com.liferay.portlet.asset.NoSuchTagPropertyException if a asset tag property with the primary key could not be found
2252             */
2253            @Override
2254            public AssetTagProperty findByPrimaryKey(Serializable primaryKey)
2255                    throws NoSuchTagPropertyException {
2256                    AssetTagProperty assetTagProperty = fetchByPrimaryKey(primaryKey);
2257    
2258                    if (assetTagProperty == null) {
2259                            if (_log.isWarnEnabled()) {
2260                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2261                            }
2262    
2263                            throw new NoSuchTagPropertyException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2264                                    primaryKey);
2265                    }
2266    
2267                    return assetTagProperty;
2268            }
2269    
2270            /**
2271             * Returns the asset tag property with the primary key or throws a {@link com.liferay.portlet.asset.NoSuchTagPropertyException} if it could not be found.
2272             *
2273             * @param tagPropertyId the primary key of the asset tag property
2274             * @return the asset tag property
2275             * @throws com.liferay.portlet.asset.NoSuchTagPropertyException if a asset tag property with the primary key could not be found
2276             */
2277            @Override
2278            public AssetTagProperty findByPrimaryKey(long tagPropertyId)
2279                    throws NoSuchTagPropertyException {
2280                    return findByPrimaryKey((Serializable)tagPropertyId);
2281            }
2282    
2283            /**
2284             * Returns the asset tag property with the primary key or returns <code>null</code> if it could not be found.
2285             *
2286             * @param primaryKey the primary key of the asset tag property
2287             * @return the asset tag property, or <code>null</code> if a asset tag property with the primary key could not be found
2288             */
2289            @Override
2290            public AssetTagProperty fetchByPrimaryKey(Serializable primaryKey) {
2291                    AssetTagProperty assetTagProperty = (AssetTagProperty)EntityCacheUtil.getResult(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
2292                                    AssetTagPropertyImpl.class, primaryKey);
2293    
2294                    if (assetTagProperty == _nullAssetTagProperty) {
2295                            return null;
2296                    }
2297    
2298                    if (assetTagProperty == null) {
2299                            Session session = null;
2300    
2301                            try {
2302                                    session = openSession();
2303    
2304                                    assetTagProperty = (AssetTagProperty)session.get(AssetTagPropertyImpl.class,
2305                                                    primaryKey);
2306    
2307                                    if (assetTagProperty != null) {
2308                                            cacheResult(assetTagProperty);
2309                                    }
2310                                    else {
2311                                            EntityCacheUtil.putResult(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
2312                                                    AssetTagPropertyImpl.class, primaryKey,
2313                                                    _nullAssetTagProperty);
2314                                    }
2315                            }
2316                            catch (Exception e) {
2317                                    EntityCacheUtil.removeResult(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
2318                                            AssetTagPropertyImpl.class, primaryKey);
2319    
2320                                    throw processException(e);
2321                            }
2322                            finally {
2323                                    closeSession(session);
2324                            }
2325                    }
2326    
2327                    return assetTagProperty;
2328            }
2329    
2330            /**
2331             * Returns the asset tag property with the primary key or returns <code>null</code> if it could not be found.
2332             *
2333             * @param tagPropertyId the primary key of the asset tag property
2334             * @return the asset tag property, or <code>null</code> if a asset tag property with the primary key could not be found
2335             */
2336            @Override
2337            public AssetTagProperty fetchByPrimaryKey(long tagPropertyId) {
2338                    return fetchByPrimaryKey((Serializable)tagPropertyId);
2339            }
2340    
2341            @Override
2342            public Map<Serializable, AssetTagProperty> fetchByPrimaryKeys(
2343                    Set<Serializable> primaryKeys) {
2344                    if (primaryKeys.isEmpty()) {
2345                            return Collections.emptyMap();
2346                    }
2347    
2348                    Map<Serializable, AssetTagProperty> map = new HashMap<Serializable, AssetTagProperty>();
2349    
2350                    if (primaryKeys.size() == 1) {
2351                            Iterator<Serializable> iterator = primaryKeys.iterator();
2352    
2353                            Serializable primaryKey = iterator.next();
2354    
2355                            AssetTagProperty assetTagProperty = fetchByPrimaryKey(primaryKey);
2356    
2357                            if (assetTagProperty != null) {
2358                                    map.put(primaryKey, assetTagProperty);
2359                            }
2360    
2361                            return map;
2362                    }
2363    
2364                    Set<Serializable> uncachedPrimaryKeys = null;
2365    
2366                    for (Serializable primaryKey : primaryKeys) {
2367                            AssetTagProperty assetTagProperty = (AssetTagProperty)EntityCacheUtil.getResult(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
2368                                            AssetTagPropertyImpl.class, primaryKey);
2369    
2370                            if (assetTagProperty == null) {
2371                                    if (uncachedPrimaryKeys == null) {
2372                                            uncachedPrimaryKeys = new HashSet<Serializable>();
2373                                    }
2374    
2375                                    uncachedPrimaryKeys.add(primaryKey);
2376                            }
2377                            else {
2378                                    map.put(primaryKey, assetTagProperty);
2379                            }
2380                    }
2381    
2382                    if (uncachedPrimaryKeys == null) {
2383                            return map;
2384                    }
2385    
2386                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
2387                                    1);
2388    
2389                    query.append(_SQL_SELECT_ASSETTAGPROPERTY_WHERE_PKS_IN);
2390    
2391                    for (Serializable primaryKey : uncachedPrimaryKeys) {
2392                            query.append(String.valueOf(primaryKey));
2393    
2394                            query.append(StringPool.COMMA);
2395                    }
2396    
2397                    query.setIndex(query.index() - 1);
2398    
2399                    query.append(StringPool.CLOSE_PARENTHESIS);
2400    
2401                    String sql = query.toString();
2402    
2403                    Session session = null;
2404    
2405                    try {
2406                            session = openSession();
2407    
2408                            Query q = session.createQuery(sql);
2409    
2410                            for (AssetTagProperty assetTagProperty : (List<AssetTagProperty>)q.list()) {
2411                                    map.put(assetTagProperty.getPrimaryKeyObj(), assetTagProperty);
2412    
2413                                    cacheResult(assetTagProperty);
2414    
2415                                    uncachedPrimaryKeys.remove(assetTagProperty.getPrimaryKeyObj());
2416                            }
2417    
2418                            for (Serializable primaryKey : uncachedPrimaryKeys) {
2419                                    EntityCacheUtil.putResult(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
2420                                            AssetTagPropertyImpl.class, primaryKey,
2421                                            _nullAssetTagProperty);
2422                            }
2423                    }
2424                    catch (Exception e) {
2425                            throw processException(e);
2426                    }
2427                    finally {
2428                            closeSession(session);
2429                    }
2430    
2431                    return map;
2432            }
2433    
2434            /**
2435             * Returns all the asset tag properties.
2436             *
2437             * @return the asset tag properties
2438             */
2439            @Override
2440            public List<AssetTagProperty> findAll() {
2441                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2442            }
2443    
2444            /**
2445             * Returns a range of all the asset tag properties.
2446             *
2447             * <p>
2448             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetTagPropertyModelImpl}. 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.
2449             * </p>
2450             *
2451             * @param start the lower bound of the range of asset tag properties
2452             * @param end the upper bound of the range of asset tag properties (not inclusive)
2453             * @return the range of asset tag properties
2454             */
2455            @Override
2456            public List<AssetTagProperty> findAll(int start, int end) {
2457                    return findAll(start, end, null);
2458            }
2459    
2460            /**
2461             * Returns an ordered range of all the asset tag properties.
2462             *
2463             * <p>
2464             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.asset.model.impl.AssetTagPropertyModelImpl}. 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.
2465             * </p>
2466             *
2467             * @param start the lower bound of the range of asset tag properties
2468             * @param end the upper bound of the range of asset tag properties (not inclusive)
2469             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2470             * @return the ordered range of asset tag properties
2471             */
2472            @Override
2473            public List<AssetTagProperty> findAll(int start, int end,
2474                    OrderByComparator<AssetTagProperty> orderByComparator) {
2475                    boolean pagination = true;
2476                    FinderPath finderPath = null;
2477                    Object[] finderArgs = null;
2478    
2479                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2480                                    (orderByComparator == null)) {
2481                            pagination = false;
2482                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2483                            finderArgs = FINDER_ARGS_EMPTY;
2484                    }
2485                    else {
2486                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2487                            finderArgs = new Object[] { start, end, orderByComparator };
2488                    }
2489    
2490                    List<AssetTagProperty> list = (List<AssetTagProperty>)FinderCacheUtil.getResult(finderPath,
2491                                    finderArgs, this);
2492    
2493                    if (list == null) {
2494                            StringBundler query = null;
2495                            String sql = null;
2496    
2497                            if (orderByComparator != null) {
2498                                    query = new StringBundler(2 +
2499                                                    (orderByComparator.getOrderByFields().length * 3));
2500    
2501                                    query.append(_SQL_SELECT_ASSETTAGPROPERTY);
2502    
2503                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2504                                            orderByComparator);
2505    
2506                                    sql = query.toString();
2507                            }
2508                            else {
2509                                    sql = _SQL_SELECT_ASSETTAGPROPERTY;
2510    
2511                                    if (pagination) {
2512                                            sql = sql.concat(AssetTagPropertyModelImpl.ORDER_BY_JPQL);
2513                                    }
2514                            }
2515    
2516                            Session session = null;
2517    
2518                            try {
2519                                    session = openSession();
2520    
2521                                    Query q = session.createQuery(sql);
2522    
2523                                    if (!pagination) {
2524                                            list = (List<AssetTagProperty>)QueryUtil.list(q,
2525                                                            getDialect(), start, end, false);
2526    
2527                                            Collections.sort(list);
2528    
2529                                            list = Collections.unmodifiableList(list);
2530                                    }
2531                                    else {
2532                                            list = (List<AssetTagProperty>)QueryUtil.list(q,
2533                                                            getDialect(), start, end);
2534                                    }
2535    
2536                                    cacheResult(list);
2537    
2538                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2539                            }
2540                            catch (Exception e) {
2541                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2542    
2543                                    throw processException(e);
2544                            }
2545                            finally {
2546                                    closeSession(session);
2547                            }
2548                    }
2549    
2550                    return list;
2551            }
2552    
2553            /**
2554             * Removes all the asset tag properties from the database.
2555             *
2556             */
2557            @Override
2558            public void removeAll() {
2559                    for (AssetTagProperty assetTagProperty : findAll()) {
2560                            remove(assetTagProperty);
2561                    }
2562            }
2563    
2564            /**
2565             * Returns the number of asset tag properties.
2566             *
2567             * @return the number of asset tag properties
2568             */
2569            @Override
2570            public int countAll() {
2571                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2572                                    FINDER_ARGS_EMPTY, this);
2573    
2574                    if (count == null) {
2575                            Session session = null;
2576    
2577                            try {
2578                                    session = openSession();
2579    
2580                                    Query q = session.createQuery(_SQL_COUNT_ASSETTAGPROPERTY);
2581    
2582                                    count = (Long)q.uniqueResult();
2583    
2584                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2585                                            FINDER_ARGS_EMPTY, count);
2586                            }
2587                            catch (Exception e) {
2588                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2589                                            FINDER_ARGS_EMPTY);
2590    
2591                                    throw processException(e);
2592                            }
2593                            finally {
2594                                    closeSession(session);
2595                            }
2596                    }
2597    
2598                    return count.intValue();
2599            }
2600    
2601            @Override
2602            protected Set<String> getBadColumnNames() {
2603                    return _badColumnNames;
2604            }
2605    
2606            /**
2607             * Initializes the asset tag property persistence.
2608             */
2609            public void afterPropertiesSet() {
2610            }
2611    
2612            public void destroy() {
2613                    EntityCacheUtil.removeCache(AssetTagPropertyImpl.class.getName());
2614                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2615                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2616                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2617            }
2618    
2619            private static final String _SQL_SELECT_ASSETTAGPROPERTY = "SELECT assetTagProperty FROM AssetTagProperty assetTagProperty";
2620            private static final String _SQL_SELECT_ASSETTAGPROPERTY_WHERE_PKS_IN = "SELECT assetTagProperty FROM AssetTagProperty assetTagProperty WHERE tagPropertyId IN (";
2621            private static final String _SQL_SELECT_ASSETTAGPROPERTY_WHERE = "SELECT assetTagProperty FROM AssetTagProperty assetTagProperty WHERE ";
2622            private static final String _SQL_COUNT_ASSETTAGPROPERTY = "SELECT COUNT(assetTagProperty) FROM AssetTagProperty assetTagProperty";
2623            private static final String _SQL_COUNT_ASSETTAGPROPERTY_WHERE = "SELECT COUNT(assetTagProperty) FROM AssetTagProperty assetTagProperty WHERE ";
2624            private static final String _ORDER_BY_ENTITY_ALIAS = "assetTagProperty.";
2625            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AssetTagProperty exists with the primary key ";
2626            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AssetTagProperty exists with the key {";
2627            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2628            private static final Log _log = LogFactoryUtil.getLog(AssetTagPropertyPersistenceImpl.class);
2629            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
2630                                    "key"
2631                            });
2632            private static final AssetTagProperty _nullAssetTagProperty = new AssetTagPropertyImpl() {
2633                            @Override
2634                            public Object clone() {
2635                                    return this;
2636                            }
2637    
2638                            @Override
2639                            public CacheModel<AssetTagProperty> toCacheModel() {
2640                                    return _nullAssetTagPropertyCacheModel;
2641                            }
2642                    };
2643    
2644            private static final CacheModel<AssetTagProperty> _nullAssetTagPropertyCacheModel =
2645                    new CacheModel<AssetTagProperty>() {
2646                            @Override
2647                            public AssetTagProperty toEntityModel() {
2648                                    return _nullAssetTagProperty;
2649                            }
2650                    };
2651    }