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