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