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