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