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