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