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