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