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