001    /**
002     * Copyright (c) 2000-2010 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;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.annotation.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.kernel.util.Validator;
037    import com.liferay.portal.model.ModelListener;
038    import com.liferay.portal.service.persistence.BatchSessionUtil;
039    import com.liferay.portal.service.persistence.ResourcePersistence;
040    import com.liferay.portal.service.persistence.UserPersistence;
041    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042    
043    import com.liferay.portlet.asset.NoSuchCategoryPropertyException;
044    import com.liferay.portlet.asset.model.AssetCategoryProperty;
045    import com.liferay.portlet.asset.model.impl.AssetCategoryPropertyImpl;
046    import com.liferay.portlet.asset.model.impl.AssetCategoryPropertyModelImpl;
047    
048    import java.io.Serializable;
049    
050    import java.util.ArrayList;
051    import java.util.Collections;
052    import java.util.List;
053    
054    /**
055     * @author    Brian Wing Shun Chan
056     * @see       AssetCategoryPropertyPersistence
057     * @see       AssetCategoryPropertyUtil
058     * @generated
059     */
060    public class AssetCategoryPropertyPersistenceImpl extends BasePersistenceImpl<AssetCategoryProperty>
061            implements AssetCategoryPropertyPersistence {
062            public static final String FINDER_CLASS_NAME_ENTITY = AssetCategoryPropertyImpl.class.getName();
063            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
064                    ".List";
065            public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(AssetCategoryPropertyModelImpl.ENTITY_CACHE_ENABLED,
066                            AssetCategoryPropertyModelImpl.FINDER_CACHE_ENABLED,
067                            FINDER_CLASS_NAME_LIST, "findByCompanyId",
068                            new String[] {
069                                    Long.class.getName(),
070                                    
071                            "java.lang.Integer", "java.lang.Integer",
072                                    "com.liferay.portal.kernel.util.OrderByComparator"
073                            });
074            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(AssetCategoryPropertyModelImpl.ENTITY_CACHE_ENABLED,
075                            AssetCategoryPropertyModelImpl.FINDER_CACHE_ENABLED,
076                            FINDER_CLASS_NAME_LIST, "countByCompanyId",
077                            new String[] { Long.class.getName() });
078            public static final FinderPath FINDER_PATH_FIND_BY_CATEGORYID = new FinderPath(AssetCategoryPropertyModelImpl.ENTITY_CACHE_ENABLED,
079                            AssetCategoryPropertyModelImpl.FINDER_CACHE_ENABLED,
080                            FINDER_CLASS_NAME_LIST, "findByCategoryId",
081                            new String[] {
082                                    Long.class.getName(),
083                                    
084                            "java.lang.Integer", "java.lang.Integer",
085                                    "com.liferay.portal.kernel.util.OrderByComparator"
086                            });
087            public static final FinderPath FINDER_PATH_COUNT_BY_CATEGORYID = new FinderPath(AssetCategoryPropertyModelImpl.ENTITY_CACHE_ENABLED,
088                            AssetCategoryPropertyModelImpl.FINDER_CACHE_ENABLED,
089                            FINDER_CLASS_NAME_LIST, "countByCategoryId",
090                            new String[] { Long.class.getName() });
091            public static final FinderPath FINDER_PATH_FIND_BY_C_K = new FinderPath(AssetCategoryPropertyModelImpl.ENTITY_CACHE_ENABLED,
092                            AssetCategoryPropertyModelImpl.FINDER_CACHE_ENABLED,
093                            FINDER_CLASS_NAME_LIST, "findByC_K",
094                            new String[] {
095                                    Long.class.getName(), String.class.getName(),
096                                    
097                            "java.lang.Integer", "java.lang.Integer",
098                                    "com.liferay.portal.kernel.util.OrderByComparator"
099                            });
100            public static final FinderPath FINDER_PATH_COUNT_BY_C_K = new FinderPath(AssetCategoryPropertyModelImpl.ENTITY_CACHE_ENABLED,
101                            AssetCategoryPropertyModelImpl.FINDER_CACHE_ENABLED,
102                            FINDER_CLASS_NAME_LIST, "countByC_K",
103                            new String[] { Long.class.getName(), String.class.getName() });
104            public static final FinderPath FINDER_PATH_FETCH_BY_CA_K = new FinderPath(AssetCategoryPropertyModelImpl.ENTITY_CACHE_ENABLED,
105                            AssetCategoryPropertyModelImpl.FINDER_CACHE_ENABLED,
106                            FINDER_CLASS_NAME_ENTITY, "fetchByCA_K",
107                            new String[] { Long.class.getName(), String.class.getName() });
108            public static final FinderPath FINDER_PATH_COUNT_BY_CA_K = new FinderPath(AssetCategoryPropertyModelImpl.ENTITY_CACHE_ENABLED,
109                            AssetCategoryPropertyModelImpl.FINDER_CACHE_ENABLED,
110                            FINDER_CLASS_NAME_LIST, "countByCA_K",
111                            new String[] { Long.class.getName(), String.class.getName() });
112            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(AssetCategoryPropertyModelImpl.ENTITY_CACHE_ENABLED,
113                            AssetCategoryPropertyModelImpl.FINDER_CACHE_ENABLED,
114                            FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
115            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AssetCategoryPropertyModelImpl.ENTITY_CACHE_ENABLED,
116                            AssetCategoryPropertyModelImpl.FINDER_CACHE_ENABLED,
117                            FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
118    
119            public void cacheResult(AssetCategoryProperty assetCategoryProperty) {
120                    EntityCacheUtil.putResult(AssetCategoryPropertyModelImpl.ENTITY_CACHE_ENABLED,
121                            AssetCategoryPropertyImpl.class,
122                            assetCategoryProperty.getPrimaryKey(), assetCategoryProperty);
123    
124                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CA_K,
125                            new Object[] {
126                                    new Long(assetCategoryProperty.getCategoryId()),
127                                    
128                            assetCategoryProperty.getKey()
129                            }, assetCategoryProperty);
130            }
131    
132            public void cacheResult(List<AssetCategoryProperty> assetCategoryProperties) {
133                    for (AssetCategoryProperty assetCategoryProperty : assetCategoryProperties) {
134                            if (EntityCacheUtil.getResult(
135                                                    AssetCategoryPropertyModelImpl.ENTITY_CACHE_ENABLED,
136                                                    AssetCategoryPropertyImpl.class,
137                                                    assetCategoryProperty.getPrimaryKey(), this) == null) {
138                                    cacheResult(assetCategoryProperty);
139                            }
140                    }
141            }
142    
143            public void clearCache() {
144                    CacheRegistryUtil.clear(AssetCategoryPropertyImpl.class.getName());
145                    EntityCacheUtil.clearCache(AssetCategoryPropertyImpl.class.getName());
146                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
147                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
148            }
149    
150            public void clearCache(AssetCategoryProperty assetCategoryProperty) {
151                    EntityCacheUtil.removeResult(AssetCategoryPropertyModelImpl.ENTITY_CACHE_ENABLED,
152                            AssetCategoryPropertyImpl.class,
153                            assetCategoryProperty.getPrimaryKey());
154    
155                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_CA_K,
156                            new Object[] {
157                                    new Long(assetCategoryProperty.getCategoryId()),
158                                    
159                            assetCategoryProperty.getKey()
160                            });
161            }
162    
163            public AssetCategoryProperty create(long categoryPropertyId) {
164                    AssetCategoryProperty assetCategoryProperty = new AssetCategoryPropertyImpl();
165    
166                    assetCategoryProperty.setNew(true);
167                    assetCategoryProperty.setPrimaryKey(categoryPropertyId);
168    
169                    return assetCategoryProperty;
170            }
171    
172            public AssetCategoryProperty remove(Serializable primaryKey)
173                    throws NoSuchModelException, SystemException {
174                    return remove(((Long)primaryKey).longValue());
175            }
176    
177            public AssetCategoryProperty remove(long categoryPropertyId)
178                    throws NoSuchCategoryPropertyException, SystemException {
179                    Session session = null;
180    
181                    try {
182                            session = openSession();
183    
184                            AssetCategoryProperty assetCategoryProperty = (AssetCategoryProperty)session.get(AssetCategoryPropertyImpl.class,
185                                            new Long(categoryPropertyId));
186    
187                            if (assetCategoryProperty == null) {
188                                    if (_log.isWarnEnabled()) {
189                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
190                                                    categoryPropertyId);
191                                    }
192    
193                                    throw new NoSuchCategoryPropertyException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
194                                            categoryPropertyId);
195                            }
196    
197                            return remove(assetCategoryProperty);
198                    }
199                    catch (NoSuchCategoryPropertyException nsee) {
200                            throw nsee;
201                    }
202                    catch (Exception e) {
203                            throw processException(e);
204                    }
205                    finally {
206                            closeSession(session);
207                    }
208            }
209    
210            protected AssetCategoryProperty removeImpl(
211                    AssetCategoryProperty assetCategoryProperty) throws SystemException {
212                    assetCategoryProperty = toUnwrappedModel(assetCategoryProperty);
213    
214                    Session session = null;
215    
216                    try {
217                            session = openSession();
218    
219                            if (assetCategoryProperty.isCachedModel() ||
220                                            BatchSessionUtil.isEnabled()) {
221                                    Object staleObject = session.get(AssetCategoryPropertyImpl.class,
222                                                    assetCategoryProperty.getPrimaryKeyObj());
223    
224                                    if (staleObject != null) {
225                                            session.evict(staleObject);
226                                    }
227                            }
228    
229                            session.delete(assetCategoryProperty);
230    
231                            session.flush();
232                    }
233                    catch (Exception e) {
234                            throw processException(e);
235                    }
236                    finally {
237                            closeSession(session);
238                    }
239    
240                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
241    
242                    AssetCategoryPropertyModelImpl assetCategoryPropertyModelImpl = (AssetCategoryPropertyModelImpl)assetCategoryProperty;
243    
244                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_CA_K,
245                            new Object[] {
246                                    new Long(assetCategoryPropertyModelImpl.getOriginalCategoryId()),
247                                    
248                            assetCategoryPropertyModelImpl.getOriginalKey()
249                            });
250    
251                    EntityCacheUtil.removeResult(AssetCategoryPropertyModelImpl.ENTITY_CACHE_ENABLED,
252                            AssetCategoryPropertyImpl.class,
253                            assetCategoryProperty.getPrimaryKey());
254    
255                    return assetCategoryProperty;
256            }
257    
258            public AssetCategoryProperty updateImpl(
259                    com.liferay.portlet.asset.model.AssetCategoryProperty assetCategoryProperty,
260                    boolean merge) throws SystemException {
261                    assetCategoryProperty = toUnwrappedModel(assetCategoryProperty);
262    
263                    boolean isNew = assetCategoryProperty.isNew();
264    
265                    AssetCategoryPropertyModelImpl assetCategoryPropertyModelImpl = (AssetCategoryPropertyModelImpl)assetCategoryProperty;
266    
267                    Session session = null;
268    
269                    try {
270                            session = openSession();
271    
272                            BatchSessionUtil.update(session, assetCategoryProperty, merge);
273    
274                            assetCategoryProperty.setNew(false);
275                    }
276                    catch (Exception e) {
277                            throw processException(e);
278                    }
279                    finally {
280                            closeSession(session);
281                    }
282    
283                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
284    
285                    EntityCacheUtil.putResult(AssetCategoryPropertyModelImpl.ENTITY_CACHE_ENABLED,
286                            AssetCategoryPropertyImpl.class,
287                            assetCategoryProperty.getPrimaryKey(), assetCategoryProperty);
288    
289                    if (!isNew &&
290                                    ((assetCategoryProperty.getCategoryId() != assetCategoryPropertyModelImpl.getOriginalCategoryId()) ||
291                                    !Validator.equals(assetCategoryProperty.getKey(),
292                                            assetCategoryPropertyModelImpl.getOriginalKey()))) {
293                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_CA_K,
294                                    new Object[] {
295                                            new Long(assetCategoryPropertyModelImpl.getOriginalCategoryId()),
296                                            
297                                    assetCategoryPropertyModelImpl.getOriginalKey()
298                                    });
299                    }
300    
301                    if (isNew ||
302                                    ((assetCategoryProperty.getCategoryId() != assetCategoryPropertyModelImpl.getOriginalCategoryId()) ||
303                                    !Validator.equals(assetCategoryProperty.getKey(),
304                                            assetCategoryPropertyModelImpl.getOriginalKey()))) {
305                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CA_K,
306                                    new Object[] {
307                                            new Long(assetCategoryProperty.getCategoryId()),
308                                            
309                                    assetCategoryProperty.getKey()
310                                    }, assetCategoryProperty);
311                    }
312    
313                    return assetCategoryProperty;
314            }
315    
316            protected AssetCategoryProperty toUnwrappedModel(
317                    AssetCategoryProperty assetCategoryProperty) {
318                    if (assetCategoryProperty instanceof AssetCategoryPropertyImpl) {
319                            return assetCategoryProperty;
320                    }
321    
322                    AssetCategoryPropertyImpl assetCategoryPropertyImpl = new AssetCategoryPropertyImpl();
323    
324                    assetCategoryPropertyImpl.setNew(assetCategoryProperty.isNew());
325                    assetCategoryPropertyImpl.setPrimaryKey(assetCategoryProperty.getPrimaryKey());
326    
327                    assetCategoryPropertyImpl.setCategoryPropertyId(assetCategoryProperty.getCategoryPropertyId());
328                    assetCategoryPropertyImpl.setCompanyId(assetCategoryProperty.getCompanyId());
329                    assetCategoryPropertyImpl.setUserId(assetCategoryProperty.getUserId());
330                    assetCategoryPropertyImpl.setUserName(assetCategoryProperty.getUserName());
331                    assetCategoryPropertyImpl.setCreateDate(assetCategoryProperty.getCreateDate());
332                    assetCategoryPropertyImpl.setModifiedDate(assetCategoryProperty.getModifiedDate());
333                    assetCategoryPropertyImpl.setCategoryId(assetCategoryProperty.getCategoryId());
334                    assetCategoryPropertyImpl.setKey(assetCategoryProperty.getKey());
335                    assetCategoryPropertyImpl.setValue(assetCategoryProperty.getValue());
336    
337                    return assetCategoryPropertyImpl;
338            }
339    
340            public AssetCategoryProperty findByPrimaryKey(Serializable primaryKey)
341                    throws NoSuchModelException, SystemException {
342                    return findByPrimaryKey(((Long)primaryKey).longValue());
343            }
344    
345            public AssetCategoryProperty findByPrimaryKey(long categoryPropertyId)
346                    throws NoSuchCategoryPropertyException, SystemException {
347                    AssetCategoryProperty assetCategoryProperty = fetchByPrimaryKey(categoryPropertyId);
348    
349                    if (assetCategoryProperty == null) {
350                            if (_log.isWarnEnabled()) {
351                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
352                                            categoryPropertyId);
353                            }
354    
355                            throw new NoSuchCategoryPropertyException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
356                                    categoryPropertyId);
357                    }
358    
359                    return assetCategoryProperty;
360            }
361    
362            public AssetCategoryProperty fetchByPrimaryKey(Serializable primaryKey)
363                    throws SystemException {
364                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
365            }
366    
367            public AssetCategoryProperty fetchByPrimaryKey(long categoryPropertyId)
368                    throws SystemException {
369                    AssetCategoryProperty assetCategoryProperty = (AssetCategoryProperty)EntityCacheUtil.getResult(AssetCategoryPropertyModelImpl.ENTITY_CACHE_ENABLED,
370                                    AssetCategoryPropertyImpl.class, categoryPropertyId, this);
371    
372                    if (assetCategoryProperty == null) {
373                            Session session = null;
374    
375                            try {
376                                    session = openSession();
377    
378                                    assetCategoryProperty = (AssetCategoryProperty)session.get(AssetCategoryPropertyImpl.class,
379                                                    new Long(categoryPropertyId));
380                            }
381                            catch (Exception e) {
382                                    throw processException(e);
383                            }
384                            finally {
385                                    if (assetCategoryProperty != null) {
386                                            cacheResult(assetCategoryProperty);
387                                    }
388    
389                                    closeSession(session);
390                            }
391                    }
392    
393                    return assetCategoryProperty;
394            }
395    
396            public List<AssetCategoryProperty> findByCompanyId(long companyId)
397                    throws SystemException {
398                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
399                            null);
400            }
401    
402            public List<AssetCategoryProperty> findByCompanyId(long companyId,
403                    int start, int end) throws SystemException {
404                    return findByCompanyId(companyId, start, end, null);
405            }
406    
407            public List<AssetCategoryProperty> findByCompanyId(long companyId,
408                    int start, int end, OrderByComparator orderByComparator)
409                    throws SystemException {
410                    Object[] finderArgs = new Object[] {
411                                    companyId,
412                                    
413                                    String.valueOf(start), String.valueOf(end),
414                                    String.valueOf(orderByComparator)
415                            };
416    
417                    List<AssetCategoryProperty> list = (List<AssetCategoryProperty>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
418                                    finderArgs, this);
419    
420                    if (list == null) {
421                            Session session = null;
422    
423                            try {
424                                    session = openSession();
425    
426                                    StringBundler query = null;
427    
428                                    if (orderByComparator != null) {
429                                            query = new StringBundler(3 +
430                                                            (orderByComparator.getOrderByFields().length * 3));
431                                    }
432                                    else {
433                                            query = new StringBundler(3);
434                                    }
435    
436                                    query.append(_SQL_SELECT_ASSETCATEGORYPROPERTY_WHERE);
437    
438                                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
439    
440                                    if (orderByComparator != null) {
441                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
442                                                    orderByComparator);
443                                    }
444    
445                                    else {
446                                            query.append(AssetCategoryPropertyModelImpl.ORDER_BY_JPQL);
447                                    }
448    
449                                    String sql = query.toString();
450    
451                                    Query q = session.createQuery(sql);
452    
453                                    QueryPos qPos = QueryPos.getInstance(q);
454    
455                                    qPos.add(companyId);
456    
457                                    list = (List<AssetCategoryProperty>)QueryUtil.list(q,
458                                                    getDialect(), start, end);
459                            }
460                            catch (Exception e) {
461                                    throw processException(e);
462                            }
463                            finally {
464                                    if (list == null) {
465                                            list = new ArrayList<AssetCategoryProperty>();
466                                    }
467    
468                                    cacheResult(list);
469    
470                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
471                                            finderArgs, list);
472    
473                                    closeSession(session);
474                            }
475                    }
476    
477                    return list;
478            }
479    
480            public AssetCategoryProperty findByCompanyId_First(long companyId,
481                    OrderByComparator orderByComparator)
482                    throws NoSuchCategoryPropertyException, SystemException {
483                    List<AssetCategoryProperty> list = findByCompanyId(companyId, 0, 1,
484                                    orderByComparator);
485    
486                    if (list.isEmpty()) {
487                            StringBundler msg = new StringBundler(4);
488    
489                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
490    
491                            msg.append("companyId=");
492                            msg.append(companyId);
493    
494                            msg.append(StringPool.CLOSE_CURLY_BRACE);
495    
496                            throw new NoSuchCategoryPropertyException(msg.toString());
497                    }
498                    else {
499                            return list.get(0);
500                    }
501            }
502    
503            public AssetCategoryProperty findByCompanyId_Last(long companyId,
504                    OrderByComparator orderByComparator)
505                    throws NoSuchCategoryPropertyException, SystemException {
506                    int count = countByCompanyId(companyId);
507    
508                    List<AssetCategoryProperty> list = findByCompanyId(companyId,
509                                    count - 1, count, orderByComparator);
510    
511                    if (list.isEmpty()) {
512                            StringBundler msg = new StringBundler(4);
513    
514                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
515    
516                            msg.append("companyId=");
517                            msg.append(companyId);
518    
519                            msg.append(StringPool.CLOSE_CURLY_BRACE);
520    
521                            throw new NoSuchCategoryPropertyException(msg.toString());
522                    }
523                    else {
524                            return list.get(0);
525                    }
526            }
527    
528            public AssetCategoryProperty[] findByCompanyId_PrevAndNext(
529                    long categoryPropertyId, long companyId,
530                    OrderByComparator orderByComparator)
531                    throws NoSuchCategoryPropertyException, SystemException {
532                    AssetCategoryProperty assetCategoryProperty = findByPrimaryKey(categoryPropertyId);
533    
534                    Session session = null;
535    
536                    try {
537                            session = openSession();
538    
539                            AssetCategoryProperty[] array = new AssetCategoryPropertyImpl[3];
540    
541                            array[0] = getByCompanyId_PrevAndNext(session,
542                                            assetCategoryProperty, companyId, orderByComparator, true);
543    
544                            array[1] = assetCategoryProperty;
545    
546                            array[2] = getByCompanyId_PrevAndNext(session,
547                                            assetCategoryProperty, companyId, orderByComparator, false);
548    
549                            return array;
550                    }
551                    catch (Exception e) {
552                            throw processException(e);
553                    }
554                    finally {
555                            closeSession(session);
556                    }
557            }
558    
559            protected AssetCategoryProperty getByCompanyId_PrevAndNext(
560                    Session session, AssetCategoryProperty assetCategoryProperty,
561                    long companyId, OrderByComparator orderByComparator, boolean previous) {
562                    StringBundler query = null;
563    
564                    if (orderByComparator != null) {
565                            query = new StringBundler(6 +
566                                            (orderByComparator.getOrderByFields().length * 6));
567                    }
568                    else {
569                            query = new StringBundler(3);
570                    }
571    
572                    query.append(_SQL_SELECT_ASSETCATEGORYPROPERTY_WHERE);
573    
574                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
575    
576                    if (orderByComparator != null) {
577                            String[] orderByFields = orderByComparator.getOrderByFields();
578    
579                            if (orderByFields.length > 0) {
580                                    query.append(WHERE_AND);
581                            }
582    
583                            for (int i = 0; i < orderByFields.length; i++) {
584                                    query.append(_ORDER_BY_ENTITY_ALIAS);
585                                    query.append(orderByFields[i]);
586    
587                                    if ((i + 1) < orderByFields.length) {
588                                            if (orderByComparator.isAscending() ^ previous) {
589                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
590                                            }
591                                            else {
592                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
593                                            }
594                                    }
595                                    else {
596                                            if (orderByComparator.isAscending() ^ previous) {
597                                                    query.append(WHERE_GREATER_THAN);
598                                            }
599                                            else {
600                                                    query.append(WHERE_LESSER_THAN);
601                                            }
602                                    }
603                            }
604    
605                            query.append(ORDER_BY_CLAUSE);
606    
607                            for (int i = 0; i < orderByFields.length; i++) {
608                                    query.append(_ORDER_BY_ENTITY_ALIAS);
609                                    query.append(orderByFields[i]);
610    
611                                    if ((i + 1) < orderByFields.length) {
612                                            if (orderByComparator.isAscending() ^ previous) {
613                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
614                                            }
615                                            else {
616                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
617                                            }
618                                    }
619                                    else {
620                                            if (orderByComparator.isAscending() ^ previous) {
621                                                    query.append(ORDER_BY_ASC);
622                                            }
623                                            else {
624                                                    query.append(ORDER_BY_DESC);
625                                            }
626                                    }
627                            }
628                    }
629    
630                    else {
631                            query.append(AssetCategoryPropertyModelImpl.ORDER_BY_JPQL);
632                    }
633    
634                    String sql = query.toString();
635    
636                    Query q = session.createQuery(sql);
637    
638                    q.setFirstResult(0);
639                    q.setMaxResults(2);
640    
641                    QueryPos qPos = QueryPos.getInstance(q);
642    
643                    qPos.add(companyId);
644    
645                    if (orderByComparator != null) {
646                            Object[] values = orderByComparator.getOrderByValues(assetCategoryProperty);
647    
648                            for (Object value : values) {
649                                    qPos.add(value);
650                            }
651                    }
652    
653                    List<AssetCategoryProperty> list = q.list();
654    
655                    if (list.size() == 2) {
656                            return list.get(1);
657                    }
658                    else {
659                            return null;
660                    }
661            }
662    
663            public List<AssetCategoryProperty> findByCategoryId(long categoryId)
664                    throws SystemException {
665                    return findByCategoryId(categoryId, QueryUtil.ALL_POS,
666                            QueryUtil.ALL_POS, null);
667            }
668    
669            public List<AssetCategoryProperty> findByCategoryId(long categoryId,
670                    int start, int end) throws SystemException {
671                    return findByCategoryId(categoryId, start, end, null);
672            }
673    
674            public List<AssetCategoryProperty> findByCategoryId(long categoryId,
675                    int start, int end, OrderByComparator orderByComparator)
676                    throws SystemException {
677                    Object[] finderArgs = new Object[] {
678                                    categoryId,
679                                    
680                                    String.valueOf(start), String.valueOf(end),
681                                    String.valueOf(orderByComparator)
682                            };
683    
684                    List<AssetCategoryProperty> list = (List<AssetCategoryProperty>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_CATEGORYID,
685                                    finderArgs, this);
686    
687                    if (list == null) {
688                            Session session = null;
689    
690                            try {
691                                    session = openSession();
692    
693                                    StringBundler query = null;
694    
695                                    if (orderByComparator != null) {
696                                            query = new StringBundler(3 +
697                                                            (orderByComparator.getOrderByFields().length * 3));
698                                    }
699                                    else {
700                                            query = new StringBundler(3);
701                                    }
702    
703                                    query.append(_SQL_SELECT_ASSETCATEGORYPROPERTY_WHERE);
704    
705                                    query.append(_FINDER_COLUMN_CATEGORYID_CATEGORYID_2);
706    
707                                    if (orderByComparator != null) {
708                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
709                                                    orderByComparator);
710                                    }
711    
712                                    else {
713                                            query.append(AssetCategoryPropertyModelImpl.ORDER_BY_JPQL);
714                                    }
715    
716                                    String sql = query.toString();
717    
718                                    Query q = session.createQuery(sql);
719    
720                                    QueryPos qPos = QueryPos.getInstance(q);
721    
722                                    qPos.add(categoryId);
723    
724                                    list = (List<AssetCategoryProperty>)QueryUtil.list(q,
725                                                    getDialect(), start, end);
726                            }
727                            catch (Exception e) {
728                                    throw processException(e);
729                            }
730                            finally {
731                                    if (list == null) {
732                                            list = new ArrayList<AssetCategoryProperty>();
733                                    }
734    
735                                    cacheResult(list);
736    
737                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_CATEGORYID,
738                                            finderArgs, list);
739    
740                                    closeSession(session);
741                            }
742                    }
743    
744                    return list;
745            }
746    
747            public AssetCategoryProperty findByCategoryId_First(long categoryId,
748                    OrderByComparator orderByComparator)
749                    throws NoSuchCategoryPropertyException, SystemException {
750                    List<AssetCategoryProperty> list = findByCategoryId(categoryId, 0, 1,
751                                    orderByComparator);
752    
753                    if (list.isEmpty()) {
754                            StringBundler msg = new StringBundler(4);
755    
756                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
757    
758                            msg.append("categoryId=");
759                            msg.append(categoryId);
760    
761                            msg.append(StringPool.CLOSE_CURLY_BRACE);
762    
763                            throw new NoSuchCategoryPropertyException(msg.toString());
764                    }
765                    else {
766                            return list.get(0);
767                    }
768            }
769    
770            public AssetCategoryProperty findByCategoryId_Last(long categoryId,
771                    OrderByComparator orderByComparator)
772                    throws NoSuchCategoryPropertyException, SystemException {
773                    int count = countByCategoryId(categoryId);
774    
775                    List<AssetCategoryProperty> list = findByCategoryId(categoryId,
776                                    count - 1, count, orderByComparator);
777    
778                    if (list.isEmpty()) {
779                            StringBundler msg = new StringBundler(4);
780    
781                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
782    
783                            msg.append("categoryId=");
784                            msg.append(categoryId);
785    
786                            msg.append(StringPool.CLOSE_CURLY_BRACE);
787    
788                            throw new NoSuchCategoryPropertyException(msg.toString());
789                    }
790                    else {
791                            return list.get(0);
792                    }
793            }
794    
795            public AssetCategoryProperty[] findByCategoryId_PrevAndNext(
796                    long categoryPropertyId, long categoryId,
797                    OrderByComparator orderByComparator)
798                    throws NoSuchCategoryPropertyException, SystemException {
799                    AssetCategoryProperty assetCategoryProperty = findByPrimaryKey(categoryPropertyId);
800    
801                    Session session = null;
802    
803                    try {
804                            session = openSession();
805    
806                            AssetCategoryProperty[] array = new AssetCategoryPropertyImpl[3];
807    
808                            array[0] = getByCategoryId_PrevAndNext(session,
809                                            assetCategoryProperty, categoryId, orderByComparator, true);
810    
811                            array[1] = assetCategoryProperty;
812    
813                            array[2] = getByCategoryId_PrevAndNext(session,
814                                            assetCategoryProperty, categoryId, orderByComparator, false);
815    
816                            return array;
817                    }
818                    catch (Exception e) {
819                            throw processException(e);
820                    }
821                    finally {
822                            closeSession(session);
823                    }
824            }
825    
826            protected AssetCategoryProperty getByCategoryId_PrevAndNext(
827                    Session session, AssetCategoryProperty assetCategoryProperty,
828                    long categoryId, OrderByComparator orderByComparator, boolean previous) {
829                    StringBundler query = null;
830    
831                    if (orderByComparator != null) {
832                            query = new StringBundler(6 +
833                                            (orderByComparator.getOrderByFields().length * 6));
834                    }
835                    else {
836                            query = new StringBundler(3);
837                    }
838    
839                    query.append(_SQL_SELECT_ASSETCATEGORYPROPERTY_WHERE);
840    
841                    query.append(_FINDER_COLUMN_CATEGORYID_CATEGORYID_2);
842    
843                    if (orderByComparator != null) {
844                            String[] orderByFields = orderByComparator.getOrderByFields();
845    
846                            if (orderByFields.length > 0) {
847                                    query.append(WHERE_AND);
848                            }
849    
850                            for (int i = 0; i < orderByFields.length; i++) {
851                                    query.append(_ORDER_BY_ENTITY_ALIAS);
852                                    query.append(orderByFields[i]);
853    
854                                    if ((i + 1) < orderByFields.length) {
855                                            if (orderByComparator.isAscending() ^ previous) {
856                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
857                                            }
858                                            else {
859                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
860                                            }
861                                    }
862                                    else {
863                                            if (orderByComparator.isAscending() ^ previous) {
864                                                    query.append(WHERE_GREATER_THAN);
865                                            }
866                                            else {
867                                                    query.append(WHERE_LESSER_THAN);
868                                            }
869                                    }
870                            }
871    
872                            query.append(ORDER_BY_CLAUSE);
873    
874                            for (int i = 0; i < orderByFields.length; i++) {
875                                    query.append(_ORDER_BY_ENTITY_ALIAS);
876                                    query.append(orderByFields[i]);
877    
878                                    if ((i + 1) < orderByFields.length) {
879                                            if (orderByComparator.isAscending() ^ previous) {
880                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
881                                            }
882                                            else {
883                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
884                                            }
885                                    }
886                                    else {
887                                            if (orderByComparator.isAscending() ^ previous) {
888                                                    query.append(ORDER_BY_ASC);
889                                            }
890                                            else {
891                                                    query.append(ORDER_BY_DESC);
892                                            }
893                                    }
894                            }
895                    }
896    
897                    else {
898                            query.append(AssetCategoryPropertyModelImpl.ORDER_BY_JPQL);
899                    }
900    
901                    String sql = query.toString();
902    
903                    Query q = session.createQuery(sql);
904    
905                    q.setFirstResult(0);
906                    q.setMaxResults(2);
907    
908                    QueryPos qPos = QueryPos.getInstance(q);
909    
910                    qPos.add(categoryId);
911    
912                    if (orderByComparator != null) {
913                            Object[] values = orderByComparator.getOrderByValues(assetCategoryProperty);
914    
915                            for (Object value : values) {
916                                    qPos.add(value);
917                            }
918                    }
919    
920                    List<AssetCategoryProperty> list = q.list();
921    
922                    if (list.size() == 2) {
923                            return list.get(1);
924                    }
925                    else {
926                            return null;
927                    }
928            }
929    
930            public List<AssetCategoryProperty> findByC_K(long companyId, String key)
931                    throws SystemException {
932                    return findByC_K(companyId, key, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
933                            null);
934            }
935    
936            public List<AssetCategoryProperty> findByC_K(long companyId, String key,
937                    int start, int end) throws SystemException {
938                    return findByC_K(companyId, key, start, end, null);
939            }
940    
941            public List<AssetCategoryProperty> findByC_K(long companyId, String key,
942                    int start, int end, OrderByComparator orderByComparator)
943                    throws SystemException {
944                    Object[] finderArgs = new Object[] {
945                                    companyId, key,
946                                    
947                                    String.valueOf(start), String.valueOf(end),
948                                    String.valueOf(orderByComparator)
949                            };
950    
951                    List<AssetCategoryProperty> list = (List<AssetCategoryProperty>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_K,
952                                    finderArgs, this);
953    
954                    if (list == null) {
955                            Session session = null;
956    
957                            try {
958                                    session = openSession();
959    
960                                    StringBundler query = null;
961    
962                                    if (orderByComparator != null) {
963                                            query = new StringBundler(4 +
964                                                            (orderByComparator.getOrderByFields().length * 3));
965                                    }
966                                    else {
967                                            query = new StringBundler(4);
968                                    }
969    
970                                    query.append(_SQL_SELECT_ASSETCATEGORYPROPERTY_WHERE);
971    
972                                    query.append(_FINDER_COLUMN_C_K_COMPANYID_2);
973    
974                                    if (key == null) {
975                                            query.append(_FINDER_COLUMN_C_K_KEY_1);
976                                    }
977                                    else {
978                                            if (key.equals(StringPool.BLANK)) {
979                                                    query.append(_FINDER_COLUMN_C_K_KEY_3);
980                                            }
981                                            else {
982                                                    query.append(_FINDER_COLUMN_C_K_KEY_2);
983                                            }
984                                    }
985    
986                                    if (orderByComparator != null) {
987                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
988                                                    orderByComparator);
989                                    }
990    
991                                    else {
992                                            query.append(AssetCategoryPropertyModelImpl.ORDER_BY_JPQL);
993                                    }
994    
995                                    String sql = query.toString();
996    
997                                    Query q = session.createQuery(sql);
998    
999                                    QueryPos qPos = QueryPos.getInstance(q);
1000    
1001                                    qPos.add(companyId);
1002    
1003                                    if (key != null) {
1004                                            qPos.add(key);
1005                                    }
1006    
1007                                    list = (List<AssetCategoryProperty>)QueryUtil.list(q,
1008                                                    getDialect(), start, end);
1009                            }
1010                            catch (Exception e) {
1011                                    throw processException(e);
1012                            }
1013                            finally {
1014                                    if (list == null) {
1015                                            list = new ArrayList<AssetCategoryProperty>();
1016                                    }
1017    
1018                                    cacheResult(list);
1019    
1020                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_K, finderArgs,
1021                                            list);
1022    
1023                                    closeSession(session);
1024                            }
1025                    }
1026    
1027                    return list;
1028            }
1029    
1030            public AssetCategoryProperty findByC_K_First(long companyId, String key,
1031                    OrderByComparator orderByComparator)
1032                    throws NoSuchCategoryPropertyException, SystemException {
1033                    List<AssetCategoryProperty> list = findByC_K(companyId, key, 0, 1,
1034                                    orderByComparator);
1035    
1036                    if (list.isEmpty()) {
1037                            StringBundler msg = new StringBundler(6);
1038    
1039                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1040    
1041                            msg.append("companyId=");
1042                            msg.append(companyId);
1043    
1044                            msg.append(", key=");
1045                            msg.append(key);
1046    
1047                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1048    
1049                            throw new NoSuchCategoryPropertyException(msg.toString());
1050                    }
1051                    else {
1052                            return list.get(0);
1053                    }
1054            }
1055    
1056            public AssetCategoryProperty findByC_K_Last(long companyId, String key,
1057                    OrderByComparator orderByComparator)
1058                    throws NoSuchCategoryPropertyException, SystemException {
1059                    int count = countByC_K(companyId, key);
1060    
1061                    List<AssetCategoryProperty> list = findByC_K(companyId, key, count - 1,
1062                                    count, orderByComparator);
1063    
1064                    if (list.isEmpty()) {
1065                            StringBundler msg = new StringBundler(6);
1066    
1067                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1068    
1069                            msg.append("companyId=");
1070                            msg.append(companyId);
1071    
1072                            msg.append(", key=");
1073                            msg.append(key);
1074    
1075                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1076    
1077                            throw new NoSuchCategoryPropertyException(msg.toString());
1078                    }
1079                    else {
1080                            return list.get(0);
1081                    }
1082            }
1083    
1084            public AssetCategoryProperty[] findByC_K_PrevAndNext(
1085                    long categoryPropertyId, long companyId, String key,
1086                    OrderByComparator orderByComparator)
1087                    throws NoSuchCategoryPropertyException, SystemException {
1088                    AssetCategoryProperty assetCategoryProperty = findByPrimaryKey(categoryPropertyId);
1089    
1090                    Session session = null;
1091    
1092                    try {
1093                            session = openSession();
1094    
1095                            AssetCategoryProperty[] array = new AssetCategoryPropertyImpl[3];
1096    
1097                            array[0] = getByC_K_PrevAndNext(session, assetCategoryProperty,
1098                                            companyId, key, orderByComparator, true);
1099    
1100                            array[1] = assetCategoryProperty;
1101    
1102                            array[2] = getByC_K_PrevAndNext(session, assetCategoryProperty,
1103                                            companyId, key, orderByComparator, false);
1104    
1105                            return array;
1106                    }
1107                    catch (Exception e) {
1108                            throw processException(e);
1109                    }
1110                    finally {
1111                            closeSession(session);
1112                    }
1113            }
1114    
1115            protected AssetCategoryProperty getByC_K_PrevAndNext(Session session,
1116                    AssetCategoryProperty assetCategoryProperty, long companyId,
1117                    String key, OrderByComparator orderByComparator, boolean previous) {
1118                    StringBundler query = null;
1119    
1120                    if (orderByComparator != null) {
1121                            query = new StringBundler(6 +
1122                                            (orderByComparator.getOrderByFields().length * 6));
1123                    }
1124                    else {
1125                            query = new StringBundler(3);
1126                    }
1127    
1128                    query.append(_SQL_SELECT_ASSETCATEGORYPROPERTY_WHERE);
1129    
1130                    query.append(_FINDER_COLUMN_C_K_COMPANYID_2);
1131    
1132                    if (key == null) {
1133                            query.append(_FINDER_COLUMN_C_K_KEY_1);
1134                    }
1135                    else {
1136                            if (key.equals(StringPool.BLANK)) {
1137                                    query.append(_FINDER_COLUMN_C_K_KEY_3);
1138                            }
1139                            else {
1140                                    query.append(_FINDER_COLUMN_C_K_KEY_2);
1141                            }
1142                    }
1143    
1144                    if (orderByComparator != null) {
1145                            String[] orderByFields = orderByComparator.getOrderByFields();
1146    
1147                            if (orderByFields.length > 0) {
1148                                    query.append(WHERE_AND);
1149                            }
1150    
1151                            for (int i = 0; i < orderByFields.length; i++) {
1152                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1153                                    query.append(orderByFields[i]);
1154    
1155                                    if ((i + 1) < orderByFields.length) {
1156                                            if (orderByComparator.isAscending() ^ previous) {
1157                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1158                                            }
1159                                            else {
1160                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1161                                            }
1162                                    }
1163                                    else {
1164                                            if (orderByComparator.isAscending() ^ previous) {
1165                                                    query.append(WHERE_GREATER_THAN);
1166                                            }
1167                                            else {
1168                                                    query.append(WHERE_LESSER_THAN);
1169                                            }
1170                                    }
1171                            }
1172    
1173                            query.append(ORDER_BY_CLAUSE);
1174    
1175                            for (int i = 0; i < orderByFields.length; i++) {
1176                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1177                                    query.append(orderByFields[i]);
1178    
1179                                    if ((i + 1) < orderByFields.length) {
1180                                            if (orderByComparator.isAscending() ^ previous) {
1181                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1182                                            }
1183                                            else {
1184                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1185                                            }
1186                                    }
1187                                    else {
1188                                            if (orderByComparator.isAscending() ^ previous) {
1189                                                    query.append(ORDER_BY_ASC);
1190                                            }
1191                                            else {
1192                                                    query.append(ORDER_BY_DESC);
1193                                            }
1194                                    }
1195                            }
1196                    }
1197    
1198                    else {
1199                            query.append(AssetCategoryPropertyModelImpl.ORDER_BY_JPQL);
1200                    }
1201    
1202                    String sql = query.toString();
1203    
1204                    Query q = session.createQuery(sql);
1205    
1206                    q.setFirstResult(0);
1207                    q.setMaxResults(2);
1208    
1209                    QueryPos qPos = QueryPos.getInstance(q);
1210    
1211                    qPos.add(companyId);
1212    
1213                    if (key != null) {
1214                            qPos.add(key);
1215                    }
1216    
1217                    if (orderByComparator != null) {
1218                            Object[] values = orderByComparator.getOrderByValues(assetCategoryProperty);
1219    
1220                            for (Object value : values) {
1221                                    qPos.add(value);
1222                            }
1223                    }
1224    
1225                    List<AssetCategoryProperty> list = q.list();
1226    
1227                    if (list.size() == 2) {
1228                            return list.get(1);
1229                    }
1230                    else {
1231                            return null;
1232                    }
1233            }
1234    
1235            public AssetCategoryProperty findByCA_K(long categoryId, String key)
1236                    throws NoSuchCategoryPropertyException, SystemException {
1237                    AssetCategoryProperty assetCategoryProperty = fetchByCA_K(categoryId,
1238                                    key);
1239    
1240                    if (assetCategoryProperty == null) {
1241                            StringBundler msg = new StringBundler(6);
1242    
1243                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1244    
1245                            msg.append("categoryId=");
1246                            msg.append(categoryId);
1247    
1248                            msg.append(", key=");
1249                            msg.append(key);
1250    
1251                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1252    
1253                            if (_log.isWarnEnabled()) {
1254                                    _log.warn(msg.toString());
1255                            }
1256    
1257                            throw new NoSuchCategoryPropertyException(msg.toString());
1258                    }
1259    
1260                    return assetCategoryProperty;
1261            }
1262    
1263            public AssetCategoryProperty fetchByCA_K(long categoryId, String key)
1264                    throws SystemException {
1265                    return fetchByCA_K(categoryId, key, true);
1266            }
1267    
1268            public AssetCategoryProperty fetchByCA_K(long categoryId, String key,
1269                    boolean retrieveFromCache) throws SystemException {
1270                    Object[] finderArgs = new Object[] { categoryId, key };
1271    
1272                    Object result = null;
1273    
1274                    if (retrieveFromCache) {
1275                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_CA_K,
1276                                            finderArgs, this);
1277                    }
1278    
1279                    if (result == null) {
1280                            Session session = null;
1281    
1282                            try {
1283                                    session = openSession();
1284    
1285                                    StringBundler query = new StringBundler(4);
1286    
1287                                    query.append(_SQL_SELECT_ASSETCATEGORYPROPERTY_WHERE);
1288    
1289                                    query.append(_FINDER_COLUMN_CA_K_CATEGORYID_2);
1290    
1291                                    if (key == null) {
1292                                            query.append(_FINDER_COLUMN_CA_K_KEY_1);
1293                                    }
1294                                    else {
1295                                            if (key.equals(StringPool.BLANK)) {
1296                                                    query.append(_FINDER_COLUMN_CA_K_KEY_3);
1297                                            }
1298                                            else {
1299                                                    query.append(_FINDER_COLUMN_CA_K_KEY_2);
1300                                            }
1301                                    }
1302    
1303                                    query.append(AssetCategoryPropertyModelImpl.ORDER_BY_JPQL);
1304    
1305                                    String sql = query.toString();
1306    
1307                                    Query q = session.createQuery(sql);
1308    
1309                                    QueryPos qPos = QueryPos.getInstance(q);
1310    
1311                                    qPos.add(categoryId);
1312    
1313                                    if (key != null) {
1314                                            qPos.add(key);
1315                                    }
1316    
1317                                    List<AssetCategoryProperty> list = q.list();
1318    
1319                                    result = list;
1320    
1321                                    AssetCategoryProperty assetCategoryProperty = null;
1322    
1323                                    if (list.isEmpty()) {
1324                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CA_K,
1325                                                    finderArgs, list);
1326                                    }
1327                                    else {
1328                                            assetCategoryProperty = list.get(0);
1329    
1330                                            cacheResult(assetCategoryProperty);
1331    
1332                                            if ((assetCategoryProperty.getCategoryId() != categoryId) ||
1333                                                            (assetCategoryProperty.getKey() == null) ||
1334                                                            !assetCategoryProperty.getKey().equals(key)) {
1335                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CA_K,
1336                                                            finderArgs, assetCategoryProperty);
1337                                            }
1338                                    }
1339    
1340                                    return assetCategoryProperty;
1341                            }
1342                            catch (Exception e) {
1343                                    throw processException(e);
1344                            }
1345                            finally {
1346                                    if (result == null) {
1347                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CA_K,
1348                                                    finderArgs, new ArrayList<AssetCategoryProperty>());
1349                                    }
1350    
1351                                    closeSession(session);
1352                            }
1353                    }
1354                    else {
1355                            if (result instanceof List<?>) {
1356                                    return null;
1357                            }
1358                            else {
1359                                    return (AssetCategoryProperty)result;
1360                            }
1361                    }
1362            }
1363    
1364            public List<AssetCategoryProperty> findAll() throws SystemException {
1365                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1366            }
1367    
1368            public List<AssetCategoryProperty> findAll(int start, int end)
1369                    throws SystemException {
1370                    return findAll(start, end, null);
1371            }
1372    
1373            public List<AssetCategoryProperty> findAll(int start, int end,
1374                    OrderByComparator orderByComparator) throws SystemException {
1375                    Object[] finderArgs = new Object[] {
1376                                    String.valueOf(start), String.valueOf(end),
1377                                    String.valueOf(orderByComparator)
1378                            };
1379    
1380                    List<AssetCategoryProperty> list = (List<AssetCategoryProperty>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1381                                    finderArgs, this);
1382    
1383                    if (list == null) {
1384                            Session session = null;
1385    
1386                            try {
1387                                    session = openSession();
1388    
1389                                    StringBundler query = null;
1390                                    String sql = null;
1391    
1392                                    if (orderByComparator != null) {
1393                                            query = new StringBundler(2 +
1394                                                            (orderByComparator.getOrderByFields().length * 3));
1395    
1396                                            query.append(_SQL_SELECT_ASSETCATEGORYPROPERTY);
1397    
1398                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1399                                                    orderByComparator);
1400    
1401                                            sql = query.toString();
1402                                    }
1403                                    else {
1404                                            sql = _SQL_SELECT_ASSETCATEGORYPROPERTY.concat(AssetCategoryPropertyModelImpl.ORDER_BY_JPQL);
1405                                    }
1406    
1407                                    Query q = session.createQuery(sql);
1408    
1409                                    if (orderByComparator == null) {
1410                                            list = (List<AssetCategoryProperty>)QueryUtil.list(q,
1411                                                            getDialect(), start, end, false);
1412    
1413                                            Collections.sort(list);
1414                                    }
1415                                    else {
1416                                            list = (List<AssetCategoryProperty>)QueryUtil.list(q,
1417                                                            getDialect(), start, end);
1418                                    }
1419                            }
1420                            catch (Exception e) {
1421                                    throw processException(e);
1422                            }
1423                            finally {
1424                                    if (list == null) {
1425                                            list = new ArrayList<AssetCategoryProperty>();
1426                                    }
1427    
1428                                    cacheResult(list);
1429    
1430                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1431    
1432                                    closeSession(session);
1433                            }
1434                    }
1435    
1436                    return list;
1437            }
1438    
1439            public void removeByCompanyId(long companyId) throws SystemException {
1440                    for (AssetCategoryProperty assetCategoryProperty : findByCompanyId(
1441                                    companyId)) {
1442                            remove(assetCategoryProperty);
1443                    }
1444            }
1445    
1446            public void removeByCategoryId(long categoryId) throws SystemException {
1447                    for (AssetCategoryProperty assetCategoryProperty : findByCategoryId(
1448                                    categoryId)) {
1449                            remove(assetCategoryProperty);
1450                    }
1451            }
1452    
1453            public void removeByC_K(long companyId, String key)
1454                    throws SystemException {
1455                    for (AssetCategoryProperty assetCategoryProperty : findByC_K(
1456                                    companyId, key)) {
1457                            remove(assetCategoryProperty);
1458                    }
1459            }
1460    
1461            public void removeByCA_K(long categoryId, String key)
1462                    throws NoSuchCategoryPropertyException, SystemException {
1463                    AssetCategoryProperty assetCategoryProperty = findByCA_K(categoryId, key);
1464    
1465                    remove(assetCategoryProperty);
1466            }
1467    
1468            public void removeAll() throws SystemException {
1469                    for (AssetCategoryProperty assetCategoryProperty : findAll()) {
1470                            remove(assetCategoryProperty);
1471                    }
1472            }
1473    
1474            public int countByCompanyId(long companyId) throws SystemException {
1475                    Object[] finderArgs = new Object[] { companyId };
1476    
1477                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
1478                                    finderArgs, this);
1479    
1480                    if (count == null) {
1481                            Session session = null;
1482    
1483                            try {
1484                                    session = openSession();
1485    
1486                                    StringBundler query = new StringBundler(2);
1487    
1488                                    query.append(_SQL_COUNT_ASSETCATEGORYPROPERTY_WHERE);
1489    
1490                                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1491    
1492                                    String sql = query.toString();
1493    
1494                                    Query q = session.createQuery(sql);
1495    
1496                                    QueryPos qPos = QueryPos.getInstance(q);
1497    
1498                                    qPos.add(companyId);
1499    
1500                                    count = (Long)q.uniqueResult();
1501                            }
1502                            catch (Exception e) {
1503                                    throw processException(e);
1504                            }
1505                            finally {
1506                                    if (count == null) {
1507                                            count = Long.valueOf(0);
1508                                    }
1509    
1510                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
1511                                            finderArgs, count);
1512    
1513                                    closeSession(session);
1514                            }
1515                    }
1516    
1517                    return count.intValue();
1518            }
1519    
1520            public int countByCategoryId(long categoryId) throws SystemException {
1521                    Object[] finderArgs = new Object[] { categoryId };
1522    
1523                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_CATEGORYID,
1524                                    finderArgs, this);
1525    
1526                    if (count == null) {
1527                            Session session = null;
1528    
1529                            try {
1530                                    session = openSession();
1531    
1532                                    StringBundler query = new StringBundler(2);
1533    
1534                                    query.append(_SQL_COUNT_ASSETCATEGORYPROPERTY_WHERE);
1535    
1536                                    query.append(_FINDER_COLUMN_CATEGORYID_CATEGORYID_2);
1537    
1538                                    String sql = query.toString();
1539    
1540                                    Query q = session.createQuery(sql);
1541    
1542                                    QueryPos qPos = QueryPos.getInstance(q);
1543    
1544                                    qPos.add(categoryId);
1545    
1546                                    count = (Long)q.uniqueResult();
1547                            }
1548                            catch (Exception e) {
1549                                    throw processException(e);
1550                            }
1551                            finally {
1552                                    if (count == null) {
1553                                            count = Long.valueOf(0);
1554                                    }
1555    
1556                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_CATEGORYID,
1557                                            finderArgs, count);
1558    
1559                                    closeSession(session);
1560                            }
1561                    }
1562    
1563                    return count.intValue();
1564            }
1565    
1566            public int countByC_K(long companyId, String key) throws SystemException {
1567                    Object[] finderArgs = new Object[] { companyId, key };
1568    
1569                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_K,
1570                                    finderArgs, this);
1571    
1572                    if (count == null) {
1573                            Session session = null;
1574    
1575                            try {
1576                                    session = openSession();
1577    
1578                                    StringBundler query = new StringBundler(3);
1579    
1580                                    query.append(_SQL_COUNT_ASSETCATEGORYPROPERTY_WHERE);
1581    
1582                                    query.append(_FINDER_COLUMN_C_K_COMPANYID_2);
1583    
1584                                    if (key == null) {
1585                                            query.append(_FINDER_COLUMN_C_K_KEY_1);
1586                                    }
1587                                    else {
1588                                            if (key.equals(StringPool.BLANK)) {
1589                                                    query.append(_FINDER_COLUMN_C_K_KEY_3);
1590                                            }
1591                                            else {
1592                                                    query.append(_FINDER_COLUMN_C_K_KEY_2);
1593                                            }
1594                                    }
1595    
1596                                    String sql = query.toString();
1597    
1598                                    Query q = session.createQuery(sql);
1599    
1600                                    QueryPos qPos = QueryPos.getInstance(q);
1601    
1602                                    qPos.add(companyId);
1603    
1604                                    if (key != null) {
1605                                            qPos.add(key);
1606                                    }
1607    
1608                                    count = (Long)q.uniqueResult();
1609                            }
1610                            catch (Exception e) {
1611                                    throw processException(e);
1612                            }
1613                            finally {
1614                                    if (count == null) {
1615                                            count = Long.valueOf(0);
1616                                    }
1617    
1618                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_K, finderArgs,
1619                                            count);
1620    
1621                                    closeSession(session);
1622                            }
1623                    }
1624    
1625                    return count.intValue();
1626            }
1627    
1628            public int countByCA_K(long categoryId, String key)
1629                    throws SystemException {
1630                    Object[] finderArgs = new Object[] { categoryId, key };
1631    
1632                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_CA_K,
1633                                    finderArgs, this);
1634    
1635                    if (count == null) {
1636                            Session session = null;
1637    
1638                            try {
1639                                    session = openSession();
1640    
1641                                    StringBundler query = new StringBundler(3);
1642    
1643                                    query.append(_SQL_COUNT_ASSETCATEGORYPROPERTY_WHERE);
1644    
1645                                    query.append(_FINDER_COLUMN_CA_K_CATEGORYID_2);
1646    
1647                                    if (key == null) {
1648                                            query.append(_FINDER_COLUMN_CA_K_KEY_1);
1649                                    }
1650                                    else {
1651                                            if (key.equals(StringPool.BLANK)) {
1652                                                    query.append(_FINDER_COLUMN_CA_K_KEY_3);
1653                                            }
1654                                            else {
1655                                                    query.append(_FINDER_COLUMN_CA_K_KEY_2);
1656                                            }
1657                                    }
1658    
1659                                    String sql = query.toString();
1660    
1661                                    Query q = session.createQuery(sql);
1662    
1663                                    QueryPos qPos = QueryPos.getInstance(q);
1664    
1665                                    qPos.add(categoryId);
1666    
1667                                    if (key != null) {
1668                                            qPos.add(key);
1669                                    }
1670    
1671                                    count = (Long)q.uniqueResult();
1672                            }
1673                            catch (Exception e) {
1674                                    throw processException(e);
1675                            }
1676                            finally {
1677                                    if (count == null) {
1678                                            count = Long.valueOf(0);
1679                                    }
1680    
1681                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_CA_K,
1682                                            finderArgs, count);
1683    
1684                                    closeSession(session);
1685                            }
1686                    }
1687    
1688                    return count.intValue();
1689            }
1690    
1691            public int countAll() throws SystemException {
1692                    Object[] finderArgs = new Object[0];
1693    
1694                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1695                                    finderArgs, this);
1696    
1697                    if (count == null) {
1698                            Session session = null;
1699    
1700                            try {
1701                                    session = openSession();
1702    
1703                                    Query q = session.createQuery(_SQL_COUNT_ASSETCATEGORYPROPERTY);
1704    
1705                                    count = (Long)q.uniqueResult();
1706                            }
1707                            catch (Exception e) {
1708                                    throw processException(e);
1709                            }
1710                            finally {
1711                                    if (count == null) {
1712                                            count = Long.valueOf(0);
1713                                    }
1714    
1715                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1716                                            count);
1717    
1718                                    closeSession(session);
1719                            }
1720                    }
1721    
1722                    return count.intValue();
1723            }
1724    
1725            public void afterPropertiesSet() {
1726                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1727                                            com.liferay.portal.util.PropsUtil.get(
1728                                                    "value.object.listener.com.liferay.portlet.asset.model.AssetCategoryProperty")));
1729    
1730                    if (listenerClassNames.length > 0) {
1731                            try {
1732                                    List<ModelListener<AssetCategoryProperty>> listenersList = new ArrayList<ModelListener<AssetCategoryProperty>>();
1733    
1734                                    for (String listenerClassName : listenerClassNames) {
1735                                            listenersList.add((ModelListener<AssetCategoryProperty>)InstanceFactory.newInstance(
1736                                                            listenerClassName));
1737                                    }
1738    
1739                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1740                            }
1741                            catch (Exception e) {
1742                                    _log.error(e);
1743                            }
1744                    }
1745            }
1746    
1747            @BeanReference(type = AssetCategoryPersistence.class)
1748            protected AssetCategoryPersistence assetCategoryPersistence;
1749            @BeanReference(type = AssetCategoryPropertyPersistence.class)
1750            protected AssetCategoryPropertyPersistence assetCategoryPropertyPersistence;
1751            @BeanReference(type = AssetEntryPersistence.class)
1752            protected AssetEntryPersistence assetEntryPersistence;
1753            @BeanReference(type = AssetLinkPersistence.class)
1754            protected AssetLinkPersistence assetLinkPersistence;
1755            @BeanReference(type = AssetTagPersistence.class)
1756            protected AssetTagPersistence assetTagPersistence;
1757            @BeanReference(type = AssetTagPropertyPersistence.class)
1758            protected AssetTagPropertyPersistence assetTagPropertyPersistence;
1759            @BeanReference(type = AssetTagStatsPersistence.class)
1760            protected AssetTagStatsPersistence assetTagStatsPersistence;
1761            @BeanReference(type = AssetVocabularyPersistence.class)
1762            protected AssetVocabularyPersistence assetVocabularyPersistence;
1763            @BeanReference(type = ResourcePersistence.class)
1764            protected ResourcePersistence resourcePersistence;
1765            @BeanReference(type = UserPersistence.class)
1766            protected UserPersistence userPersistence;
1767            private static final String _SQL_SELECT_ASSETCATEGORYPROPERTY = "SELECT assetCategoryProperty FROM AssetCategoryProperty assetCategoryProperty";
1768            private static final String _SQL_SELECT_ASSETCATEGORYPROPERTY_WHERE = "SELECT assetCategoryProperty FROM AssetCategoryProperty assetCategoryProperty WHERE ";
1769            private static final String _SQL_COUNT_ASSETCATEGORYPROPERTY = "SELECT COUNT(assetCategoryProperty) FROM AssetCategoryProperty assetCategoryProperty";
1770            private static final String _SQL_COUNT_ASSETCATEGORYPROPERTY_WHERE = "SELECT COUNT(assetCategoryProperty) FROM AssetCategoryProperty assetCategoryProperty WHERE ";
1771            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "assetCategoryProperty.companyId = ?";
1772            private static final String _FINDER_COLUMN_CATEGORYID_CATEGORYID_2 = "assetCategoryProperty.categoryId = ?";
1773            private static final String _FINDER_COLUMN_C_K_COMPANYID_2 = "assetCategoryProperty.companyId = ? AND ";
1774            private static final String _FINDER_COLUMN_C_K_KEY_1 = "assetCategoryProperty.key IS NULL";
1775            private static final String _FINDER_COLUMN_C_K_KEY_2 = "assetCategoryProperty.key = ?";
1776            private static final String _FINDER_COLUMN_C_K_KEY_3 = "(assetCategoryProperty.key IS NULL OR assetCategoryProperty.key = ?)";
1777            private static final String _FINDER_COLUMN_CA_K_CATEGORYID_2 = "assetCategoryProperty.categoryId = ? AND ";
1778            private static final String _FINDER_COLUMN_CA_K_KEY_1 = "assetCategoryProperty.key IS NULL";
1779            private static final String _FINDER_COLUMN_CA_K_KEY_2 = "assetCategoryProperty.key = ?";
1780            private static final String _FINDER_COLUMN_CA_K_KEY_3 = "(assetCategoryProperty.key IS NULL OR assetCategoryProperty.key = ?)";
1781            private static final String _ORDER_BY_ENTITY_ALIAS = "assetCategoryProperty.";
1782            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AssetCategoryProperty exists with the primary key ";
1783            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AssetCategoryProperty exists with the key {";
1784            private static Log _log = LogFactoryUtil.getLog(AssetCategoryPropertyPersistenceImpl.class);
1785    }