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