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