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            public AssetTagPropertyPersistenceImpl() {
1911                    setModelClass(AssetTagProperty.class);
1912            }
1913    
1914            /**
1915             * Caches the asset tag property in the entity cache if it is enabled.
1916             *
1917             * @param assetTagProperty the asset tag property
1918             */
1919            @Override
1920            public void cacheResult(AssetTagProperty assetTagProperty) {
1921                    EntityCacheUtil.putResult(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
1922                            AssetTagPropertyImpl.class, assetTagProperty.getPrimaryKey(),
1923                            assetTagProperty);
1924    
1925                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_K,
1926                            new Object[] { assetTagProperty.getTagId(), assetTagProperty.getKey() },
1927                            assetTagProperty);
1928    
1929                    assetTagProperty.resetOriginalValues();
1930            }
1931    
1932            /**
1933             * Caches the asset tag properties in the entity cache if it is enabled.
1934             *
1935             * @param assetTagProperties the asset tag properties
1936             */
1937            @Override
1938            public void cacheResult(List<AssetTagProperty> assetTagProperties) {
1939                    for (AssetTagProperty assetTagProperty : assetTagProperties) {
1940                            if (EntityCacheUtil.getResult(
1941                                                    AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
1942                                                    AssetTagPropertyImpl.class,
1943                                                    assetTagProperty.getPrimaryKey()) == null) {
1944                                    cacheResult(assetTagProperty);
1945                            }
1946                            else {
1947                                    assetTagProperty.resetOriginalValues();
1948                            }
1949                    }
1950            }
1951    
1952            /**
1953             * Clears the cache for all asset tag properties.
1954             *
1955             * <p>
1956             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1957             * </p>
1958             */
1959            @Override
1960            public void clearCache() {
1961                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1962                            CacheRegistryUtil.clear(AssetTagPropertyImpl.class.getName());
1963                    }
1964    
1965                    EntityCacheUtil.clearCache(AssetTagPropertyImpl.class.getName());
1966    
1967                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1968                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1969                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1970            }
1971    
1972            /**
1973             * Clears the cache for the asset tag property.
1974             *
1975             * <p>
1976             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1977             * </p>
1978             */
1979            @Override
1980            public void clearCache(AssetTagProperty assetTagProperty) {
1981                    EntityCacheUtil.removeResult(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
1982                            AssetTagPropertyImpl.class, assetTagProperty.getPrimaryKey());
1983    
1984                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1985                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1986    
1987                    clearUniqueFindersCache(assetTagProperty);
1988            }
1989    
1990            @Override
1991            public void clearCache(List<AssetTagProperty> assetTagProperties) {
1992                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1993                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1994    
1995                    for (AssetTagProperty assetTagProperty : assetTagProperties) {
1996                            EntityCacheUtil.removeResult(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
1997                                    AssetTagPropertyImpl.class, assetTagProperty.getPrimaryKey());
1998    
1999                            clearUniqueFindersCache(assetTagProperty);
2000                    }
2001            }
2002    
2003            protected void cacheUniqueFindersCache(AssetTagProperty assetTagProperty) {
2004                    if (assetTagProperty.isNew()) {
2005                            Object[] args = new Object[] {
2006                                            assetTagProperty.getTagId(), assetTagProperty.getKey()
2007                                    };
2008    
2009                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_K, args,
2010                                    Long.valueOf(1));
2011                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_K, args,
2012                                    assetTagProperty);
2013                    }
2014                    else {
2015                            AssetTagPropertyModelImpl assetTagPropertyModelImpl = (AssetTagPropertyModelImpl)assetTagProperty;
2016    
2017                            if ((assetTagPropertyModelImpl.getColumnBitmask() &
2018                                            FINDER_PATH_FETCH_BY_T_K.getColumnBitmask()) != 0) {
2019                                    Object[] args = new Object[] {
2020                                                    assetTagProperty.getTagId(), assetTagProperty.getKey()
2021                                            };
2022    
2023                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_K, args,
2024                                            Long.valueOf(1));
2025                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_K, args,
2026                                            assetTagProperty);
2027                            }
2028                    }
2029            }
2030    
2031            protected void clearUniqueFindersCache(AssetTagProperty assetTagProperty) {
2032                    AssetTagPropertyModelImpl assetTagPropertyModelImpl = (AssetTagPropertyModelImpl)assetTagProperty;
2033    
2034                    Object[] args = new Object[] {
2035                                    assetTagProperty.getTagId(), assetTagProperty.getKey()
2036                            };
2037    
2038                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_K, args);
2039                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_K, args);
2040    
2041                    if ((assetTagPropertyModelImpl.getColumnBitmask() &
2042                                    FINDER_PATH_FETCH_BY_T_K.getColumnBitmask()) != 0) {
2043                            args = new Object[] {
2044                                            assetTagPropertyModelImpl.getOriginalTagId(),
2045                                            assetTagPropertyModelImpl.getOriginalKey()
2046                                    };
2047    
2048                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_K, args);
2049                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_K, args);
2050                    }
2051            }
2052    
2053            /**
2054             * Creates a new asset tag property with the primary key. Does not add the asset tag property to the database.
2055             *
2056             * @param tagPropertyId the primary key for the new asset tag property
2057             * @return the new asset tag property
2058             */
2059            @Override
2060            public AssetTagProperty create(long tagPropertyId) {
2061                    AssetTagProperty assetTagProperty = new AssetTagPropertyImpl();
2062    
2063                    assetTagProperty.setNew(true);
2064                    assetTagProperty.setPrimaryKey(tagPropertyId);
2065    
2066                    return assetTagProperty;
2067            }
2068    
2069            /**
2070             * Removes the asset tag property with the primary key from the database. Also notifies the appropriate model listeners.
2071             *
2072             * @param tagPropertyId the primary key of the asset tag property
2073             * @return the asset tag property that was removed
2074             * @throws com.liferay.portlet.asset.NoSuchTagPropertyException if a asset tag property with the primary key could not be found
2075             * @throws SystemException if a system exception occurred
2076             */
2077            @Override
2078            public AssetTagProperty remove(long tagPropertyId)
2079                    throws NoSuchTagPropertyException, SystemException {
2080                    return remove((Serializable)tagPropertyId);
2081            }
2082    
2083            /**
2084             * Removes the asset tag property with the primary key from the database. Also notifies the appropriate model listeners.
2085             *
2086             * @param primaryKey the primary key of the asset tag property
2087             * @return the asset tag property that was removed
2088             * @throws com.liferay.portlet.asset.NoSuchTagPropertyException if a asset tag property with the primary key could not be found
2089             * @throws SystemException if a system exception occurred
2090             */
2091            @Override
2092            public AssetTagProperty remove(Serializable primaryKey)
2093                    throws NoSuchTagPropertyException, SystemException {
2094                    Session session = null;
2095    
2096                    try {
2097                            session = openSession();
2098    
2099                            AssetTagProperty assetTagProperty = (AssetTagProperty)session.get(AssetTagPropertyImpl.class,
2100                                            primaryKey);
2101    
2102                            if (assetTagProperty == null) {
2103                                    if (_log.isWarnEnabled()) {
2104                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2105                                    }
2106    
2107                                    throw new NoSuchTagPropertyException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2108                                            primaryKey);
2109                            }
2110    
2111                            return remove(assetTagProperty);
2112                    }
2113                    catch (NoSuchTagPropertyException nsee) {
2114                            throw nsee;
2115                    }
2116                    catch (Exception e) {
2117                            throw processException(e);
2118                    }
2119                    finally {
2120                            closeSession(session);
2121                    }
2122            }
2123    
2124            @Override
2125            protected AssetTagProperty removeImpl(AssetTagProperty assetTagProperty)
2126                    throws SystemException {
2127                    assetTagProperty = toUnwrappedModel(assetTagProperty);
2128    
2129                    Session session = null;
2130    
2131                    try {
2132                            session = openSession();
2133    
2134                            if (!session.contains(assetTagProperty)) {
2135                                    assetTagProperty = (AssetTagProperty)session.get(AssetTagPropertyImpl.class,
2136                                                    assetTagProperty.getPrimaryKeyObj());
2137                            }
2138    
2139                            if (assetTagProperty != null) {
2140                                    session.delete(assetTagProperty);
2141                            }
2142                    }
2143                    catch (Exception e) {
2144                            throw processException(e);
2145                    }
2146                    finally {
2147                            closeSession(session);
2148                    }
2149    
2150                    if (assetTagProperty != null) {
2151                            clearCache(assetTagProperty);
2152                    }
2153    
2154                    return assetTagProperty;
2155            }
2156    
2157            @Override
2158            public AssetTagProperty updateImpl(
2159                    com.liferay.portlet.asset.model.AssetTagProperty assetTagProperty)
2160                    throws SystemException {
2161                    assetTagProperty = toUnwrappedModel(assetTagProperty);
2162    
2163                    boolean isNew = assetTagProperty.isNew();
2164    
2165                    AssetTagPropertyModelImpl assetTagPropertyModelImpl = (AssetTagPropertyModelImpl)assetTagProperty;
2166    
2167                    Session session = null;
2168    
2169                    try {
2170                            session = openSession();
2171    
2172                            if (assetTagProperty.isNew()) {
2173                                    session.save(assetTagProperty);
2174    
2175                                    assetTagProperty.setNew(false);
2176                            }
2177                            else {
2178                                    session.merge(assetTagProperty);
2179                            }
2180                    }
2181                    catch (Exception e) {
2182                            throw processException(e);
2183                    }
2184                    finally {
2185                            closeSession(session);
2186                    }
2187    
2188                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2189    
2190                    if (isNew || !AssetTagPropertyModelImpl.COLUMN_BITMASK_ENABLED) {
2191                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2192                    }
2193    
2194                    else {
2195                            if ((assetTagPropertyModelImpl.getColumnBitmask() &
2196                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
2197                                    Object[] args = new Object[] {
2198                                                    assetTagPropertyModelImpl.getOriginalCompanyId()
2199                                            };
2200    
2201                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
2202                                            args);
2203                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
2204                                            args);
2205    
2206                                    args = new Object[] { assetTagPropertyModelImpl.getCompanyId() };
2207    
2208                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
2209                                            args);
2210                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
2211                                            args);
2212                            }
2213    
2214                            if ((assetTagPropertyModelImpl.getColumnBitmask() &
2215                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TAGID.getColumnBitmask()) != 0) {
2216                                    Object[] args = new Object[] {
2217                                                    assetTagPropertyModelImpl.getOriginalTagId()
2218                                            };
2219    
2220                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TAGID, args);
2221                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TAGID,
2222                                            args);
2223    
2224                                    args = new Object[] { assetTagPropertyModelImpl.getTagId() };
2225    
2226                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TAGID, args);
2227                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TAGID,
2228                                            args);
2229                            }
2230    
2231                            if ((assetTagPropertyModelImpl.getColumnBitmask() &
2232                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_K.getColumnBitmask()) != 0) {
2233                                    Object[] args = new Object[] {
2234                                                    assetTagPropertyModelImpl.getOriginalCompanyId(),
2235                                                    assetTagPropertyModelImpl.getOriginalKey()
2236                                            };
2237    
2238                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_K, args);
2239                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_K,
2240                                            args);
2241    
2242                                    args = new Object[] {
2243                                                    assetTagPropertyModelImpl.getCompanyId(),
2244                                                    assetTagPropertyModelImpl.getKey()
2245                                            };
2246    
2247                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_K, args);
2248                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_K,
2249                                            args);
2250                            }
2251                    }
2252    
2253                    EntityCacheUtil.putResult(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
2254                            AssetTagPropertyImpl.class, assetTagProperty.getPrimaryKey(),
2255                            assetTagProperty);
2256    
2257                    clearUniqueFindersCache(assetTagProperty);
2258                    cacheUniqueFindersCache(assetTagProperty);
2259    
2260                    return assetTagProperty;
2261            }
2262    
2263            protected AssetTagProperty toUnwrappedModel(
2264                    AssetTagProperty assetTagProperty) {
2265                    if (assetTagProperty instanceof AssetTagPropertyImpl) {
2266                            return assetTagProperty;
2267                    }
2268    
2269                    AssetTagPropertyImpl assetTagPropertyImpl = new AssetTagPropertyImpl();
2270    
2271                    assetTagPropertyImpl.setNew(assetTagProperty.isNew());
2272                    assetTagPropertyImpl.setPrimaryKey(assetTagProperty.getPrimaryKey());
2273    
2274                    assetTagPropertyImpl.setTagPropertyId(assetTagProperty.getTagPropertyId());
2275                    assetTagPropertyImpl.setCompanyId(assetTagProperty.getCompanyId());
2276                    assetTagPropertyImpl.setUserId(assetTagProperty.getUserId());
2277                    assetTagPropertyImpl.setUserName(assetTagProperty.getUserName());
2278                    assetTagPropertyImpl.setCreateDate(assetTagProperty.getCreateDate());
2279                    assetTagPropertyImpl.setModifiedDate(assetTagProperty.getModifiedDate());
2280                    assetTagPropertyImpl.setTagId(assetTagProperty.getTagId());
2281                    assetTagPropertyImpl.setKey(assetTagProperty.getKey());
2282                    assetTagPropertyImpl.setValue(assetTagProperty.getValue());
2283    
2284                    return assetTagPropertyImpl;
2285            }
2286    
2287            /**
2288             * Returns the asset tag property with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
2289             *
2290             * @param primaryKey the primary key of the asset tag property
2291             * @return the asset tag property
2292             * @throws com.liferay.portlet.asset.NoSuchTagPropertyException if a asset tag property with the primary key could not be found
2293             * @throws SystemException if a system exception occurred
2294             */
2295            @Override
2296            public AssetTagProperty findByPrimaryKey(Serializable primaryKey)
2297                    throws NoSuchTagPropertyException, SystemException {
2298                    AssetTagProperty assetTagProperty = fetchByPrimaryKey(primaryKey);
2299    
2300                    if (assetTagProperty == null) {
2301                            if (_log.isWarnEnabled()) {
2302                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2303                            }
2304    
2305                            throw new NoSuchTagPropertyException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2306                                    primaryKey);
2307                    }
2308    
2309                    return assetTagProperty;
2310            }
2311    
2312            /**
2313             * Returns the asset tag property with the primary key or throws a {@link com.liferay.portlet.asset.NoSuchTagPropertyException} if it could not be found.
2314             *
2315             * @param tagPropertyId the primary key of the asset tag property
2316             * @return the asset tag property
2317             * @throws com.liferay.portlet.asset.NoSuchTagPropertyException if a asset tag property with the primary key could not be found
2318             * @throws SystemException if a system exception occurred
2319             */
2320            @Override
2321            public AssetTagProperty findByPrimaryKey(long tagPropertyId)
2322                    throws NoSuchTagPropertyException, SystemException {
2323                    return findByPrimaryKey((Serializable)tagPropertyId);
2324            }
2325    
2326            /**
2327             * Returns the asset tag property with the primary key or returns <code>null</code> if it could not be found.
2328             *
2329             * @param primaryKey the primary key of the asset tag property
2330             * @return the asset tag property, or <code>null</code> if a asset tag property with the primary key could not be found
2331             * @throws SystemException if a system exception occurred
2332             */
2333            @Override
2334            public AssetTagProperty fetchByPrimaryKey(Serializable primaryKey)
2335                    throws SystemException {
2336                    AssetTagProperty assetTagProperty = (AssetTagProperty)EntityCacheUtil.getResult(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
2337                                    AssetTagPropertyImpl.class, primaryKey);
2338    
2339                    if (assetTagProperty == _nullAssetTagProperty) {
2340                            return null;
2341                    }
2342    
2343                    if (assetTagProperty == null) {
2344                            Session session = null;
2345    
2346                            try {
2347                                    session = openSession();
2348    
2349                                    assetTagProperty = (AssetTagProperty)session.get(AssetTagPropertyImpl.class,
2350                                                    primaryKey);
2351    
2352                                    if (assetTagProperty != null) {
2353                                            cacheResult(assetTagProperty);
2354                                    }
2355                                    else {
2356                                            EntityCacheUtil.putResult(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
2357                                                    AssetTagPropertyImpl.class, primaryKey,
2358                                                    _nullAssetTagProperty);
2359                                    }
2360                            }
2361                            catch (Exception e) {
2362                                    EntityCacheUtil.removeResult(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
2363                                            AssetTagPropertyImpl.class, primaryKey);
2364    
2365                                    throw processException(e);
2366                            }
2367                            finally {
2368                                    closeSession(session);
2369                            }
2370                    }
2371    
2372                    return assetTagProperty;
2373            }
2374    
2375            /**
2376             * Returns the asset tag property with the primary key or returns <code>null</code> if it could not be found.
2377             *
2378             * @param tagPropertyId the primary key of the asset tag property
2379             * @return the asset tag property, or <code>null</code> if a asset tag property with the primary key could not be found
2380             * @throws SystemException if a system exception occurred
2381             */
2382            @Override
2383            public AssetTagProperty fetchByPrimaryKey(long tagPropertyId)
2384                    throws SystemException {
2385                    return fetchByPrimaryKey((Serializable)tagPropertyId);
2386            }
2387    
2388            /**
2389             * Returns all the asset tag properties.
2390             *
2391             * @return the asset tag properties
2392             * @throws SystemException if a system exception occurred
2393             */
2394            @Override
2395            public List<AssetTagProperty> findAll() throws SystemException {
2396                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2397            }
2398    
2399            /**
2400             * Returns a range of all the asset tag properties.
2401             *
2402             * <p>
2403             * 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.
2404             * </p>
2405             *
2406             * @param start the lower bound of the range of asset tag properties
2407             * @param end the upper bound of the range of asset tag properties (not inclusive)
2408             * @return the range of asset tag properties
2409             * @throws SystemException if a system exception occurred
2410             */
2411            @Override
2412            public List<AssetTagProperty> findAll(int start, int end)
2413                    throws SystemException {
2414                    return findAll(start, end, null);
2415            }
2416    
2417            /**
2418             * Returns an ordered range of all the asset tag properties.
2419             *
2420             * <p>
2421             * 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.
2422             * </p>
2423             *
2424             * @param start the lower bound of the range of asset tag properties
2425             * @param end the upper bound of the range of asset tag properties (not inclusive)
2426             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2427             * @return the ordered range of asset tag properties
2428             * @throws SystemException if a system exception occurred
2429             */
2430            @Override
2431            public List<AssetTagProperty> findAll(int start, int end,
2432                    OrderByComparator orderByComparator) throws SystemException {
2433                    boolean pagination = true;
2434                    FinderPath finderPath = null;
2435                    Object[] finderArgs = null;
2436    
2437                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2438                                    (orderByComparator == null)) {
2439                            pagination = false;
2440                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2441                            finderArgs = FINDER_ARGS_EMPTY;
2442                    }
2443                    else {
2444                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2445                            finderArgs = new Object[] { start, end, orderByComparator };
2446                    }
2447    
2448                    List<AssetTagProperty> list = (List<AssetTagProperty>)FinderCacheUtil.getResult(finderPath,
2449                                    finderArgs, this);
2450    
2451                    if (list == null) {
2452                            StringBundler query = null;
2453                            String sql = null;
2454    
2455                            if (orderByComparator != null) {
2456                                    query = new StringBundler(2 +
2457                                                    (orderByComparator.getOrderByFields().length * 3));
2458    
2459                                    query.append(_SQL_SELECT_ASSETTAGPROPERTY);
2460    
2461                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2462                                            orderByComparator);
2463    
2464                                    sql = query.toString();
2465                            }
2466                            else {
2467                                    sql = _SQL_SELECT_ASSETTAGPROPERTY;
2468    
2469                                    if (pagination) {
2470                                            sql = sql.concat(AssetTagPropertyModelImpl.ORDER_BY_JPQL);
2471                                    }
2472                            }
2473    
2474                            Session session = null;
2475    
2476                            try {
2477                                    session = openSession();
2478    
2479                                    Query q = session.createQuery(sql);
2480    
2481                                    if (!pagination) {
2482                                            list = (List<AssetTagProperty>)QueryUtil.list(q,
2483                                                            getDialect(), start, end, false);
2484    
2485                                            Collections.sort(list);
2486    
2487                                            list = new UnmodifiableList<AssetTagProperty>(list);
2488                                    }
2489                                    else {
2490                                            list = (List<AssetTagProperty>)QueryUtil.list(q,
2491                                                            getDialect(), start, end);
2492                                    }
2493    
2494                                    cacheResult(list);
2495    
2496                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2497                            }
2498                            catch (Exception e) {
2499                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2500    
2501                                    throw processException(e);
2502                            }
2503                            finally {
2504                                    closeSession(session);
2505                            }
2506                    }
2507    
2508                    return list;
2509            }
2510    
2511            /**
2512             * Removes all the asset tag properties from the database.
2513             *
2514             * @throws SystemException if a system exception occurred
2515             */
2516            @Override
2517            public void removeAll() throws SystemException {
2518                    for (AssetTagProperty assetTagProperty : findAll()) {
2519                            remove(assetTagProperty);
2520                    }
2521            }
2522    
2523            /**
2524             * Returns the number of asset tag properties.
2525             *
2526             * @return the number of asset tag properties
2527             * @throws SystemException if a system exception occurred
2528             */
2529            @Override
2530            public int countAll() throws SystemException {
2531                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2532                                    FINDER_ARGS_EMPTY, this);
2533    
2534                    if (count == null) {
2535                            Session session = null;
2536    
2537                            try {
2538                                    session = openSession();
2539    
2540                                    Query q = session.createQuery(_SQL_COUNT_ASSETTAGPROPERTY);
2541    
2542                                    count = (Long)q.uniqueResult();
2543    
2544                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2545                                            FINDER_ARGS_EMPTY, count);
2546                            }
2547                            catch (Exception e) {
2548                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2549                                            FINDER_ARGS_EMPTY);
2550    
2551                                    throw processException(e);
2552                            }
2553                            finally {
2554                                    closeSession(session);
2555                            }
2556                    }
2557    
2558                    return count.intValue();
2559            }
2560    
2561            @Override
2562            protected Set<String> getBadColumnNames() {
2563                    return _badColumnNames;
2564            }
2565    
2566            /**
2567             * Initializes the asset tag property persistence.
2568             */
2569            public void afterPropertiesSet() {
2570                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2571                                            com.liferay.portal.util.PropsUtil.get(
2572                                                    "value.object.listener.com.liferay.portlet.asset.model.AssetTagProperty")));
2573    
2574                    if (listenerClassNames.length > 0) {
2575                            try {
2576                                    List<ModelListener<AssetTagProperty>> listenersList = new ArrayList<ModelListener<AssetTagProperty>>();
2577    
2578                                    for (String listenerClassName : listenerClassNames) {
2579                                            listenersList.add((ModelListener<AssetTagProperty>)InstanceFactory.newInstance(
2580                                                            getClassLoader(), listenerClassName));
2581                                    }
2582    
2583                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2584                            }
2585                            catch (Exception e) {
2586                                    _log.error(e);
2587                            }
2588                    }
2589            }
2590    
2591            public void destroy() {
2592                    EntityCacheUtil.removeCache(AssetTagPropertyImpl.class.getName());
2593                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2594                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2595                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2596            }
2597    
2598            private static final String _SQL_SELECT_ASSETTAGPROPERTY = "SELECT assetTagProperty FROM AssetTagProperty assetTagProperty";
2599            private static final String _SQL_SELECT_ASSETTAGPROPERTY_WHERE = "SELECT assetTagProperty FROM AssetTagProperty assetTagProperty WHERE ";
2600            private static final String _SQL_COUNT_ASSETTAGPROPERTY = "SELECT COUNT(assetTagProperty) FROM AssetTagProperty assetTagProperty";
2601            private static final String _SQL_COUNT_ASSETTAGPROPERTY_WHERE = "SELECT COUNT(assetTagProperty) FROM AssetTagProperty assetTagProperty WHERE ";
2602            private static final String _ORDER_BY_ENTITY_ALIAS = "assetTagProperty.";
2603            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AssetTagProperty exists with the primary key ";
2604            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AssetTagProperty exists with the key {";
2605            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2606            private static Log _log = LogFactoryUtil.getLog(AssetTagPropertyPersistenceImpl.class);
2607            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
2608                                    "key"
2609                            });
2610            private static AssetTagProperty _nullAssetTagProperty = new AssetTagPropertyImpl() {
2611                            @Override
2612                            public Object clone() {
2613                                    return this;
2614                            }
2615    
2616                            @Override
2617                            public CacheModel<AssetTagProperty> toCacheModel() {
2618                                    return _nullAssetTagPropertyCacheModel;
2619                            }
2620                    };
2621    
2622            private static CacheModel<AssetTagProperty> _nullAssetTagPropertyCacheModel = new CacheModel<AssetTagProperty>() {
2623                            @Override
2624                            public AssetTagProperty toEntityModel() {
2625                                    return _nullAssetTagProperty;
2626                            }
2627                    };
2628    }