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