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