001    /**
002     * Copyright (c) 2000-2011 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.NoSuchTagPropertyException;
044    import com.liferay.portlet.asset.model.AssetTagProperty;
045    import com.liferay.portlet.asset.model.impl.AssetTagPropertyImpl;
046    import com.liferay.portlet.asset.model.impl.AssetTagPropertyModelImpl;
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     * The persistence implementation for the asset tag property service.
056     *
057     * <p>
058     * Never modify or reference this class directly. Always use {@link AssetTagPropertyUtil} to access the asset tag property persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
059     * </p>
060     *
061     * <p>
062     * Caching information and settings can be found in <code>portal.properties</code>
063     * </p>
064     *
065     * @author Brian Wing Shun Chan
066     * @see AssetTagPropertyPersistence
067     * @see AssetTagPropertyUtil
068     * @generated
069     */
070    public class AssetTagPropertyPersistenceImpl extends BasePersistenceImpl<AssetTagProperty>
071            implements AssetTagPropertyPersistence {
072            public static final String FINDER_CLASS_NAME_ENTITY = AssetTagPropertyImpl.class.getName();
073            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
074                    ".List";
075            public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
076                            AssetTagPropertyModelImpl.FINDER_CACHE_ENABLED,
077                            FINDER_CLASS_NAME_LIST, "findByCompanyId",
078                            new String[] {
079                                    Long.class.getName(),
080                                    
081                            "java.lang.Integer", "java.lang.Integer",
082                                    "com.liferay.portal.kernel.util.OrderByComparator"
083                            });
084            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
085                            AssetTagPropertyModelImpl.FINDER_CACHE_ENABLED,
086                            FINDER_CLASS_NAME_LIST, "countByCompanyId",
087                            new String[] { Long.class.getName() });
088            public static final FinderPath FINDER_PATH_FIND_BY_TAGID = new FinderPath(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
089                            AssetTagPropertyModelImpl.FINDER_CACHE_ENABLED,
090                            FINDER_CLASS_NAME_LIST, "findByTagId",
091                            new String[] {
092                                    Long.class.getName(),
093                                    
094                            "java.lang.Integer", "java.lang.Integer",
095                                    "com.liferay.portal.kernel.util.OrderByComparator"
096                            });
097            public static final FinderPath FINDER_PATH_COUNT_BY_TAGID = new FinderPath(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
098                            AssetTagPropertyModelImpl.FINDER_CACHE_ENABLED,
099                            FINDER_CLASS_NAME_LIST, "countByTagId",
100                            new String[] { Long.class.getName() });
101            public static final FinderPath FINDER_PATH_FIND_BY_C_K = new FinderPath(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
102                            AssetTagPropertyModelImpl.FINDER_CACHE_ENABLED,
103                            FINDER_CLASS_NAME_LIST, "findByC_K",
104                            new String[] {
105                                    Long.class.getName(), String.class.getName(),
106                                    
107                            "java.lang.Integer", "java.lang.Integer",
108                                    "com.liferay.portal.kernel.util.OrderByComparator"
109                            });
110            public static final FinderPath FINDER_PATH_COUNT_BY_C_K = new FinderPath(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
111                            AssetTagPropertyModelImpl.FINDER_CACHE_ENABLED,
112                            FINDER_CLASS_NAME_LIST, "countByC_K",
113                            new String[] { Long.class.getName(), String.class.getName() });
114            public static final FinderPath FINDER_PATH_FETCH_BY_T_K = new FinderPath(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
115                            AssetTagPropertyModelImpl.FINDER_CACHE_ENABLED,
116                            FINDER_CLASS_NAME_ENTITY, "fetchByT_K",
117                            new String[] { Long.class.getName(), String.class.getName() });
118            public static final FinderPath FINDER_PATH_COUNT_BY_T_K = new FinderPath(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
119                            AssetTagPropertyModelImpl.FINDER_CACHE_ENABLED,
120                            FINDER_CLASS_NAME_LIST, "countByT_K",
121                            new String[] { Long.class.getName(), String.class.getName() });
122            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
123                            AssetTagPropertyModelImpl.FINDER_CACHE_ENABLED,
124                            FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
125            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
126                            AssetTagPropertyModelImpl.FINDER_CACHE_ENABLED,
127                            FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
128    
129            /**
130             * Caches the asset tag property in the entity cache if it is enabled.
131             *
132             * @param assetTagProperty the asset tag property to cache
133             */
134            public void cacheResult(AssetTagProperty assetTagProperty) {
135                    EntityCacheUtil.putResult(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
136                            AssetTagPropertyImpl.class, assetTagProperty.getPrimaryKey(),
137                            assetTagProperty);
138    
139                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_K,
140                            new Object[] {
141                                    new Long(assetTagProperty.getTagId()),
142                                    
143                            assetTagProperty.getKey()
144                            }, assetTagProperty);
145            }
146    
147            /**
148             * Caches the asset tag properties in the entity cache if it is enabled.
149             *
150             * @param assetTagProperties the asset tag properties to cache
151             */
152            public void cacheResult(List<AssetTagProperty> assetTagProperties) {
153                    for (AssetTagProperty assetTagProperty : assetTagProperties) {
154                            if (EntityCacheUtil.getResult(
155                                                    AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
156                                                    AssetTagPropertyImpl.class,
157                                                    assetTagProperty.getPrimaryKey(), this) == null) {
158                                    cacheResult(assetTagProperty);
159                            }
160                    }
161            }
162    
163            /**
164             * Clears the cache for all asset tag properties.
165             *
166             * <p>
167             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
168             * </p>
169             */
170            public void clearCache() {
171                    CacheRegistryUtil.clear(AssetTagPropertyImpl.class.getName());
172                    EntityCacheUtil.clearCache(AssetTagPropertyImpl.class.getName());
173                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
174                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
175            }
176    
177            /**
178             * Clears the cache for the asset tag property.
179             *
180             * <p>
181             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
182             * </p>
183             */
184            public void clearCache(AssetTagProperty assetTagProperty) {
185                    EntityCacheUtil.removeResult(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
186                            AssetTagPropertyImpl.class, assetTagProperty.getPrimaryKey());
187    
188                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_K,
189                            new Object[] {
190                                    new Long(assetTagProperty.getTagId()),
191                                    
192                            assetTagProperty.getKey()
193                            });
194            }
195    
196            /**
197             * Creates a new asset tag property with the primary key. Does not add the asset tag property to the database.
198             *
199             * @param tagPropertyId the primary key for the new asset tag property
200             * @return the new asset tag property
201             */
202            public AssetTagProperty create(long tagPropertyId) {
203                    AssetTagProperty assetTagProperty = new AssetTagPropertyImpl();
204    
205                    assetTagProperty.setNew(true);
206                    assetTagProperty.setPrimaryKey(tagPropertyId);
207    
208                    return assetTagProperty;
209            }
210    
211            /**
212             * Removes the asset tag property with the primary key from the database. Also notifies the appropriate model listeners.
213             *
214             * @param primaryKey the primary key of the asset tag property to remove
215             * @return the asset tag property that was removed
216             * @throws com.liferay.portal.NoSuchModelException if a asset tag property with the primary key could not be found
217             * @throws SystemException if a system exception occurred
218             */
219            public AssetTagProperty remove(Serializable primaryKey)
220                    throws NoSuchModelException, SystemException {
221                    return remove(((Long)primaryKey).longValue());
222            }
223    
224            /**
225             * Removes the asset tag property with the primary key from the database. Also notifies the appropriate model listeners.
226             *
227             * @param tagPropertyId the primary key of the asset tag property to remove
228             * @return the asset tag property that was removed
229             * @throws com.liferay.portlet.asset.NoSuchTagPropertyException if a asset tag property with the primary key could not be found
230             * @throws SystemException if a system exception occurred
231             */
232            public AssetTagProperty remove(long tagPropertyId)
233                    throws NoSuchTagPropertyException, SystemException {
234                    Session session = null;
235    
236                    try {
237                            session = openSession();
238    
239                            AssetTagProperty assetTagProperty = (AssetTagProperty)session.get(AssetTagPropertyImpl.class,
240                                            new Long(tagPropertyId));
241    
242                            if (assetTagProperty == null) {
243                                    if (_log.isWarnEnabled()) {
244                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + tagPropertyId);
245                                    }
246    
247                                    throw new NoSuchTagPropertyException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
248                                            tagPropertyId);
249                            }
250    
251                            return remove(assetTagProperty);
252                    }
253                    catch (NoSuchTagPropertyException nsee) {
254                            throw nsee;
255                    }
256                    catch (Exception e) {
257                            throw processException(e);
258                    }
259                    finally {
260                            closeSession(session);
261                    }
262            }
263    
264            protected AssetTagProperty removeImpl(AssetTagProperty assetTagProperty)
265                    throws SystemException {
266                    assetTagProperty = toUnwrappedModel(assetTagProperty);
267    
268                    Session session = null;
269    
270                    try {
271                            session = openSession();
272    
273                            BatchSessionUtil.delete(session, assetTagProperty);
274                    }
275                    catch (Exception e) {
276                            throw processException(e);
277                    }
278                    finally {
279                            closeSession(session);
280                    }
281    
282                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
283    
284                    AssetTagPropertyModelImpl assetTagPropertyModelImpl = (AssetTagPropertyModelImpl)assetTagProperty;
285    
286                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_K,
287                            new Object[] {
288                                    new Long(assetTagPropertyModelImpl.getTagId()),
289                                    
290                            assetTagPropertyModelImpl.getKey()
291                            });
292    
293                    EntityCacheUtil.removeResult(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
294                            AssetTagPropertyImpl.class, assetTagProperty.getPrimaryKey());
295    
296                    return assetTagProperty;
297            }
298    
299            public AssetTagProperty updateImpl(
300                    com.liferay.portlet.asset.model.AssetTagProperty assetTagProperty,
301                    boolean merge) throws SystemException {
302                    assetTagProperty = toUnwrappedModel(assetTagProperty);
303    
304                    boolean isNew = assetTagProperty.isNew();
305    
306                    AssetTagPropertyModelImpl assetTagPropertyModelImpl = (AssetTagPropertyModelImpl)assetTagProperty;
307    
308                    Session session = null;
309    
310                    try {
311                            session = openSession();
312    
313                            BatchSessionUtil.update(session, assetTagProperty, merge);
314    
315                            assetTagProperty.setNew(false);
316                    }
317                    catch (Exception e) {
318                            throw processException(e);
319                    }
320                    finally {
321                            closeSession(session);
322                    }
323    
324                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
325    
326                    EntityCacheUtil.putResult(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
327                            AssetTagPropertyImpl.class, assetTagProperty.getPrimaryKey(),
328                            assetTagProperty);
329    
330                    if (!isNew &&
331                                    ((assetTagProperty.getTagId() != assetTagPropertyModelImpl.getOriginalTagId()) ||
332                                    !Validator.equals(assetTagProperty.getKey(),
333                                            assetTagPropertyModelImpl.getOriginalKey()))) {
334                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_K,
335                                    new Object[] {
336                                            new Long(assetTagPropertyModelImpl.getOriginalTagId()),
337                                            
338                                    assetTagPropertyModelImpl.getOriginalKey()
339                                    });
340                    }
341    
342                    if (isNew ||
343                                    ((assetTagProperty.getTagId() != assetTagPropertyModelImpl.getOriginalTagId()) ||
344                                    !Validator.equals(assetTagProperty.getKey(),
345                                            assetTagPropertyModelImpl.getOriginalKey()))) {
346                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_K,
347                                    new Object[] {
348                                            new Long(assetTagProperty.getTagId()),
349                                            
350                                    assetTagProperty.getKey()
351                                    }, assetTagProperty);
352                    }
353    
354                    return assetTagProperty;
355            }
356    
357            protected AssetTagProperty toUnwrappedModel(
358                    AssetTagProperty assetTagProperty) {
359                    if (assetTagProperty instanceof AssetTagPropertyImpl) {
360                            return assetTagProperty;
361                    }
362    
363                    AssetTagPropertyImpl assetTagPropertyImpl = new AssetTagPropertyImpl();
364    
365                    assetTagPropertyImpl.setNew(assetTagProperty.isNew());
366                    assetTagPropertyImpl.setPrimaryKey(assetTagProperty.getPrimaryKey());
367    
368                    assetTagPropertyImpl.setTagPropertyId(assetTagProperty.getTagPropertyId());
369                    assetTagPropertyImpl.setCompanyId(assetTagProperty.getCompanyId());
370                    assetTagPropertyImpl.setUserId(assetTagProperty.getUserId());
371                    assetTagPropertyImpl.setUserName(assetTagProperty.getUserName());
372                    assetTagPropertyImpl.setCreateDate(assetTagProperty.getCreateDate());
373                    assetTagPropertyImpl.setModifiedDate(assetTagProperty.getModifiedDate());
374                    assetTagPropertyImpl.setTagId(assetTagProperty.getTagId());
375                    assetTagPropertyImpl.setKey(assetTagProperty.getKey());
376                    assetTagPropertyImpl.setValue(assetTagProperty.getValue());
377    
378                    return assetTagPropertyImpl;
379            }
380    
381            /**
382             * Finds the asset tag property with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
383             *
384             * @param primaryKey the primary key of the asset tag property to find
385             * @return the asset tag property
386             * @throws com.liferay.portal.NoSuchModelException if a asset tag property with the primary key could not be found
387             * @throws SystemException if a system exception occurred
388             */
389            public AssetTagProperty findByPrimaryKey(Serializable primaryKey)
390                    throws NoSuchModelException, SystemException {
391                    return findByPrimaryKey(((Long)primaryKey).longValue());
392            }
393    
394            /**
395             * Finds the asset tag property with the primary key or throws a {@link com.liferay.portlet.asset.NoSuchTagPropertyException} if it could not be found.
396             *
397             * @param tagPropertyId the primary key of the asset tag property to find
398             * @return the asset tag property
399             * @throws com.liferay.portlet.asset.NoSuchTagPropertyException if a asset tag property with the primary key could not be found
400             * @throws SystemException if a system exception occurred
401             */
402            public AssetTagProperty findByPrimaryKey(long tagPropertyId)
403                    throws NoSuchTagPropertyException, SystemException {
404                    AssetTagProperty assetTagProperty = fetchByPrimaryKey(tagPropertyId);
405    
406                    if (assetTagProperty == null) {
407                            if (_log.isWarnEnabled()) {
408                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + tagPropertyId);
409                            }
410    
411                            throw new NoSuchTagPropertyException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
412                                    tagPropertyId);
413                    }
414    
415                    return assetTagProperty;
416            }
417    
418            /**
419             * Finds the asset tag property with the primary key or returns <code>null</code> if it could not be found.
420             *
421             * @param primaryKey the primary key of the asset tag property to find
422             * @return the asset tag property, or <code>null</code> if a asset tag property with the primary key could not be found
423             * @throws SystemException if a system exception occurred
424             */
425            public AssetTagProperty fetchByPrimaryKey(Serializable primaryKey)
426                    throws SystemException {
427                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
428            }
429    
430            /**
431             * Finds the asset tag property with the primary key or returns <code>null</code> if it could not be found.
432             *
433             * @param tagPropertyId the primary key of the asset tag property to find
434             * @return the asset tag property, or <code>null</code> if a asset tag property with the primary key could not be found
435             * @throws SystemException if a system exception occurred
436             */
437            public AssetTagProperty fetchByPrimaryKey(long tagPropertyId)
438                    throws SystemException {
439                    AssetTagProperty assetTagProperty = (AssetTagProperty)EntityCacheUtil.getResult(AssetTagPropertyModelImpl.ENTITY_CACHE_ENABLED,
440                                    AssetTagPropertyImpl.class, tagPropertyId, this);
441    
442                    if (assetTagProperty == null) {
443                            Session session = null;
444    
445                            try {
446                                    session = openSession();
447    
448                                    assetTagProperty = (AssetTagProperty)session.get(AssetTagPropertyImpl.class,
449                                                    new Long(tagPropertyId));
450                            }
451                            catch (Exception e) {
452                                    throw processException(e);
453                            }
454                            finally {
455                                    if (assetTagProperty != null) {
456                                            cacheResult(assetTagProperty);
457                                    }
458    
459                                    closeSession(session);
460                            }
461                    }
462    
463                    return assetTagProperty;
464            }
465    
466            /**
467             * Finds all the asset tag properties where companyId = &#63;.
468             *
469             * @param companyId the company id to search with
470             * @return the matching asset tag properties
471             * @throws SystemException if a system exception occurred
472             */
473            public List<AssetTagProperty> findByCompanyId(long companyId)
474                    throws SystemException {
475                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
476                            null);
477            }
478    
479            /**
480             * Finds a range of all the asset tag properties where companyId = &#63;.
481             *
482             * <p>
483             * 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
484             * </p>
485             *
486             * @param companyId the company id to search with
487             * @param start the lower bound of the range of asset tag properties to return
488             * @param end the upper bound of the range of asset tag properties to return (not inclusive)
489             * @return the range of matching asset tag properties
490             * @throws SystemException if a system exception occurred
491             */
492            public List<AssetTagProperty> findByCompanyId(long companyId, int start,
493                    int end) throws SystemException {
494                    return findByCompanyId(companyId, start, end, null);
495            }
496    
497            /**
498             * Finds an ordered range of all the asset tag properties where companyId = &#63;.
499             *
500             * <p>
501             * 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
502             * </p>
503             *
504             * @param companyId the company id to search with
505             * @param start the lower bound of the range of asset tag properties to return
506             * @param end the upper bound of the range of asset tag properties to return (not inclusive)
507             * @param orderByComparator the comparator to order the results by
508             * @return the ordered range of matching asset tag properties
509             * @throws SystemException if a system exception occurred
510             */
511            public List<AssetTagProperty> findByCompanyId(long companyId, int start,
512                    int end, OrderByComparator orderByComparator) throws SystemException {
513                    Object[] finderArgs = new Object[] {
514                                    companyId,
515                                    
516                                    String.valueOf(start), String.valueOf(end),
517                                    String.valueOf(orderByComparator)
518                            };
519    
520                    List<AssetTagProperty> list = (List<AssetTagProperty>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
521                                    finderArgs, this);
522    
523                    if (list == null) {
524                            StringBundler query = null;
525    
526                            if (orderByComparator != null) {
527                                    query = new StringBundler(3 +
528                                                    (orderByComparator.getOrderByFields().length * 3));
529                            }
530                            else {
531                                    query = new StringBundler(3);
532                            }
533    
534                            query.append(_SQL_SELECT_ASSETTAGPROPERTY_WHERE);
535    
536                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
537    
538                            if (orderByComparator != null) {
539                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
540                                            orderByComparator);
541                            }
542    
543                            else {
544                                    query.append(AssetTagPropertyModelImpl.ORDER_BY_JPQL);
545                            }
546    
547                            String sql = query.toString();
548    
549                            Session session = null;
550    
551                            try {
552                                    session = openSession();
553    
554                                    Query q = session.createQuery(sql);
555    
556                                    QueryPos qPos = QueryPos.getInstance(q);
557    
558                                    qPos.add(companyId);
559    
560                                    list = (List<AssetTagProperty>)QueryUtil.list(q, getDialect(),
561                                                    start, end);
562                            }
563                            catch (Exception e) {
564                                    throw processException(e);
565                            }
566                            finally {
567                                    if (list == null) {
568                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_COMPANYID,
569                                                    finderArgs);
570                                    }
571                                    else {
572                                            cacheResult(list);
573    
574                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
575                                                    finderArgs, list);
576                                    }
577    
578                                    closeSession(session);
579                            }
580                    }
581    
582                    return list;
583            }
584    
585            /**
586             * Finds the first asset tag property in the ordered set where companyId = &#63;.
587             *
588             * <p>
589             * 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
590             * </p>
591             *
592             * @param companyId the company id to search with
593             * @param orderByComparator the comparator to order the set by
594             * @return the first matching asset tag property
595             * @throws com.liferay.portlet.asset.NoSuchTagPropertyException if a matching asset tag property could not be found
596             * @throws SystemException if a system exception occurred
597             */
598            public AssetTagProperty findByCompanyId_First(long companyId,
599                    OrderByComparator orderByComparator)
600                    throws NoSuchTagPropertyException, SystemException {
601                    List<AssetTagProperty> list = findByCompanyId(companyId, 0, 1,
602                                    orderByComparator);
603    
604                    if (list.isEmpty()) {
605                            StringBundler msg = new StringBundler(4);
606    
607                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
608    
609                            msg.append("companyId=");
610                            msg.append(companyId);
611    
612                            msg.append(StringPool.CLOSE_CURLY_BRACE);
613    
614                            throw new NoSuchTagPropertyException(msg.toString());
615                    }
616                    else {
617                            return list.get(0);
618                    }
619            }
620    
621            /**
622             * Finds the last asset tag property in the ordered set where companyId = &#63;.
623             *
624             * <p>
625             * 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
626             * </p>
627             *
628             * @param companyId the company id to search with
629             * @param orderByComparator the comparator to order the set by
630             * @return the last matching asset tag property
631             * @throws com.liferay.portlet.asset.NoSuchTagPropertyException if a matching asset tag property could not be found
632             * @throws SystemException if a system exception occurred
633             */
634            public AssetTagProperty findByCompanyId_Last(long companyId,
635                    OrderByComparator orderByComparator)
636                    throws NoSuchTagPropertyException, SystemException {
637                    int count = countByCompanyId(companyId);
638    
639                    List<AssetTagProperty> list = findByCompanyId(companyId, count - 1,
640                                    count, orderByComparator);
641    
642                    if (list.isEmpty()) {
643                            StringBundler msg = new StringBundler(4);
644    
645                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
646    
647                            msg.append("companyId=");
648                            msg.append(companyId);
649    
650                            msg.append(StringPool.CLOSE_CURLY_BRACE);
651    
652                            throw new NoSuchTagPropertyException(msg.toString());
653                    }
654                    else {
655                            return list.get(0);
656                    }
657            }
658    
659            /**
660             * Finds the asset tag properties before and after the current asset tag property in the ordered set where companyId = &#63;.
661             *
662             * <p>
663             * 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
664             * </p>
665             *
666             * @param tagPropertyId the primary key of the current asset tag property
667             * @param companyId the company id to search with
668             * @param orderByComparator the comparator to order the set by
669             * @return the previous, current, and next asset tag property
670             * @throws com.liferay.portlet.asset.NoSuchTagPropertyException if a asset tag property with the primary key could not be found
671             * @throws SystemException if a system exception occurred
672             */
673            public AssetTagProperty[] findByCompanyId_PrevAndNext(long tagPropertyId,
674                    long companyId, OrderByComparator orderByComparator)
675                    throws NoSuchTagPropertyException, SystemException {
676                    AssetTagProperty assetTagProperty = findByPrimaryKey(tagPropertyId);
677    
678                    Session session = null;
679    
680                    try {
681                            session = openSession();
682    
683                            AssetTagProperty[] array = new AssetTagPropertyImpl[3];
684    
685                            array[0] = getByCompanyId_PrevAndNext(session, assetTagProperty,
686                                            companyId, orderByComparator, true);
687    
688                            array[1] = assetTagProperty;
689    
690                            array[2] = getByCompanyId_PrevAndNext(session, assetTagProperty,
691                                            companyId, orderByComparator, false);
692    
693                            return array;
694                    }
695                    catch (Exception e) {
696                            throw processException(e);
697                    }
698                    finally {
699                            closeSession(session);
700                    }
701            }
702    
703            protected AssetTagProperty getByCompanyId_PrevAndNext(Session session,
704                    AssetTagProperty assetTagProperty, long companyId,
705                    OrderByComparator orderByComparator, boolean previous) {
706                    StringBundler query = null;
707    
708                    if (orderByComparator != null) {
709                            query = new StringBundler(6 +
710                                            (orderByComparator.getOrderByFields().length * 6));
711                    }
712                    else {
713                            query = new StringBundler(3);
714                    }
715    
716                    query.append(_SQL_SELECT_ASSETTAGPROPERTY_WHERE);
717    
718                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
719    
720                    if (orderByComparator != null) {
721                            String[] orderByFields = orderByComparator.getOrderByFields();
722    
723                            if (orderByFields.length > 0) {
724                                    query.append(WHERE_AND);
725                            }
726    
727                            for (int i = 0; i < orderByFields.length; i++) {
728                                    query.append(_ORDER_BY_ENTITY_ALIAS);
729                                    query.append(orderByFields[i]);
730    
731                                    if ((i + 1) < orderByFields.length) {
732                                            if (orderByComparator.isAscending() ^ previous) {
733                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
734                                            }
735                                            else {
736                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
737                                            }
738                                    }
739                                    else {
740                                            if (orderByComparator.isAscending() ^ previous) {
741                                                    query.append(WHERE_GREATER_THAN);
742                                            }
743                                            else {
744                                                    query.append(WHERE_LESSER_THAN);
745                                            }
746                                    }
747                            }
748    
749                            query.append(ORDER_BY_CLAUSE);
750    
751                            for (int i = 0; i < orderByFields.length; i++) {
752                                    query.append(_ORDER_BY_ENTITY_ALIAS);
753                                    query.append(orderByFields[i]);
754    
755                                    if ((i + 1) < orderByFields.length) {
756                                            if (orderByComparator.isAscending() ^ previous) {
757                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
758                                            }
759                                            else {
760                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
761                                            }
762                                    }
763                                    else {
764                                            if (orderByComparator.isAscending() ^ previous) {
765                                                    query.append(ORDER_BY_ASC);
766                                            }
767                                            else {
768                                                    query.append(ORDER_BY_DESC);
769                                            }
770                                    }
771                            }
772                    }
773    
774                    else {
775                            query.append(AssetTagPropertyModelImpl.ORDER_BY_JPQL);
776                    }
777    
778                    String sql = query.toString();
779    
780                    Query q = session.createQuery(sql);
781    
782                    q.setFirstResult(0);
783                    q.setMaxResults(2);
784    
785                    QueryPos qPos = QueryPos.getInstance(q);
786    
787                    qPos.add(companyId);
788    
789                    if (orderByComparator != null) {
790                            Object[] values = orderByComparator.getOrderByValues(assetTagProperty);
791    
792                            for (Object value : values) {
793                                    qPos.add(value);
794                            }
795                    }
796    
797                    List<AssetTagProperty> list = q.list();
798    
799                    if (list.size() == 2) {
800                            return list.get(1);
801                    }
802                    else {
803                            return null;
804                    }
805            }
806    
807            /**
808             * Finds all the asset tag properties where tagId = &#63;.
809             *
810             * @param tagId the tag id to search with
811             * @return the matching asset tag properties
812             * @throws SystemException if a system exception occurred
813             */
814            public List<AssetTagProperty> findByTagId(long tagId)
815                    throws SystemException {
816                    return findByTagId(tagId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
817            }
818    
819            /**
820             * Finds a range of all the asset tag properties where tagId = &#63;.
821             *
822             * <p>
823             * 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
824             * </p>
825             *
826             * @param tagId the tag id to search with
827             * @param start the lower bound of the range of asset tag properties to return
828             * @param end the upper bound of the range of asset tag properties to return (not inclusive)
829             * @return the range of matching asset tag properties
830             * @throws SystemException if a system exception occurred
831             */
832            public List<AssetTagProperty> findByTagId(long tagId, int start, int end)
833                    throws SystemException {
834                    return findByTagId(tagId, start, end, null);
835            }
836    
837            /**
838             * Finds an ordered range of all the asset tag properties where tagId = &#63;.
839             *
840             * <p>
841             * 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
842             * </p>
843             *
844             * @param tagId the tag id to search with
845             * @param start the lower bound of the range of asset tag properties to return
846             * @param end the upper bound of the range of asset tag properties to return (not inclusive)
847             * @param orderByComparator the comparator to order the results by
848             * @return the ordered range of matching asset tag properties
849             * @throws SystemException if a system exception occurred
850             */
851            public List<AssetTagProperty> findByTagId(long tagId, int start, int end,
852                    OrderByComparator orderByComparator) throws SystemException {
853                    Object[] finderArgs = new Object[] {
854                                    tagId,
855                                    
856                                    String.valueOf(start), String.valueOf(end),
857                                    String.valueOf(orderByComparator)
858                            };
859    
860                    List<AssetTagProperty> list = (List<AssetTagProperty>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_TAGID,
861                                    finderArgs, this);
862    
863                    if (list == null) {
864                            StringBundler query = null;
865    
866                            if (orderByComparator != null) {
867                                    query = new StringBundler(3 +
868                                                    (orderByComparator.getOrderByFields().length * 3));
869                            }
870                            else {
871                                    query = new StringBundler(3);
872                            }
873    
874                            query.append(_SQL_SELECT_ASSETTAGPROPERTY_WHERE);
875    
876                            query.append(_FINDER_COLUMN_TAGID_TAGID_2);
877    
878                            if (orderByComparator != null) {
879                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
880                                            orderByComparator);
881                            }
882    
883                            else {
884                                    query.append(AssetTagPropertyModelImpl.ORDER_BY_JPQL);
885                            }
886    
887                            String sql = query.toString();
888    
889                            Session session = null;
890    
891                            try {
892                                    session = openSession();
893    
894                                    Query q = session.createQuery(sql);
895    
896                                    QueryPos qPos = QueryPos.getInstance(q);
897    
898                                    qPos.add(tagId);
899    
900                                    list = (List<AssetTagProperty>)QueryUtil.list(q, getDialect(),
901                                                    start, end);
902                            }
903                            catch (Exception e) {
904                                    throw processException(e);
905                            }
906                            finally {
907                                    if (list == null) {
908                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_TAGID,
909                                                    finderArgs);
910                                    }
911                                    else {
912                                            cacheResult(list);
913    
914                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_TAGID,
915                                                    finderArgs, list);
916                                    }
917    
918                                    closeSession(session);
919                            }
920                    }
921    
922                    return list;
923            }
924    
925            /**
926             * Finds the first asset tag property in the ordered set where tagId = &#63;.
927             *
928             * <p>
929             * 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
930             * </p>
931             *
932             * @param tagId the tag id to search with
933             * @param orderByComparator the comparator to order the set by
934             * @return the first matching asset tag property
935             * @throws com.liferay.portlet.asset.NoSuchTagPropertyException if a matching asset tag property could not be found
936             * @throws SystemException if a system exception occurred
937             */
938            public AssetTagProperty findByTagId_First(long tagId,
939                    OrderByComparator orderByComparator)
940                    throws NoSuchTagPropertyException, SystemException {
941                    List<AssetTagProperty> list = findByTagId(tagId, 0, 1, orderByComparator);
942    
943                    if (list.isEmpty()) {
944                            StringBundler msg = new StringBundler(4);
945    
946                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
947    
948                            msg.append("tagId=");
949                            msg.append(tagId);
950    
951                            msg.append(StringPool.CLOSE_CURLY_BRACE);
952    
953                            throw new NoSuchTagPropertyException(msg.toString());
954                    }
955                    else {
956                            return list.get(0);
957                    }
958            }
959    
960            /**
961             * Finds the last asset tag property in the ordered set where tagId = &#63;.
962             *
963             * <p>
964             * 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
965             * </p>
966             *
967             * @param tagId the tag id to search with
968             * @param orderByComparator the comparator to order the set by
969             * @return the last matching asset tag property
970             * @throws com.liferay.portlet.asset.NoSuchTagPropertyException if a matching asset tag property could not be found
971             * @throws SystemException if a system exception occurred
972             */
973            public AssetTagProperty findByTagId_Last(long tagId,
974                    OrderByComparator orderByComparator)
975                    throws NoSuchTagPropertyException, SystemException {
976                    int count = countByTagId(tagId);
977    
978                    List<AssetTagProperty> list = findByTagId(tagId, count - 1, count,
979                                    orderByComparator);
980    
981                    if (list.isEmpty()) {
982                            StringBundler msg = new StringBundler(4);
983    
984                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
985    
986                            msg.append("tagId=");
987                            msg.append(tagId);
988    
989                            msg.append(StringPool.CLOSE_CURLY_BRACE);
990    
991                            throw new NoSuchTagPropertyException(msg.toString());
992                    }
993                    else {
994                            return list.get(0);
995                    }
996            }
997    
998            /**
999             * Finds the asset tag properties before and after the current asset tag property in the ordered set where tagId = &#63;.
1000             *
1001             * <p>
1002             * 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1003             * </p>
1004             *
1005             * @param tagPropertyId the primary key of the current asset tag property
1006             * @param tagId the tag id to search with
1007             * @param orderByComparator the comparator to order the set by
1008             * @return the previous, current, and next asset tag property
1009             * @throws com.liferay.portlet.asset.NoSuchTagPropertyException if a asset tag property with the primary key could not be found
1010             * @throws SystemException if a system exception occurred
1011             */
1012            public AssetTagProperty[] findByTagId_PrevAndNext(long tagPropertyId,
1013                    long tagId, OrderByComparator orderByComparator)
1014                    throws NoSuchTagPropertyException, SystemException {
1015                    AssetTagProperty assetTagProperty = findByPrimaryKey(tagPropertyId);
1016    
1017                    Session session = null;
1018    
1019                    try {
1020                            session = openSession();
1021    
1022                            AssetTagProperty[] array = new AssetTagPropertyImpl[3];
1023    
1024                            array[0] = getByTagId_PrevAndNext(session, assetTagProperty, tagId,
1025                                            orderByComparator, true);
1026    
1027                            array[1] = assetTagProperty;
1028    
1029                            array[2] = getByTagId_PrevAndNext(session, assetTagProperty, tagId,
1030                                            orderByComparator, false);
1031    
1032                            return array;
1033                    }
1034                    catch (Exception e) {
1035                            throw processException(e);
1036                    }
1037                    finally {
1038                            closeSession(session);
1039                    }
1040            }
1041    
1042            protected AssetTagProperty getByTagId_PrevAndNext(Session session,
1043                    AssetTagProperty assetTagProperty, long tagId,
1044                    OrderByComparator orderByComparator, boolean previous) {
1045                    StringBundler query = null;
1046    
1047                    if (orderByComparator != null) {
1048                            query = new StringBundler(6 +
1049                                            (orderByComparator.getOrderByFields().length * 6));
1050                    }
1051                    else {
1052                            query = new StringBundler(3);
1053                    }
1054    
1055                    query.append(_SQL_SELECT_ASSETTAGPROPERTY_WHERE);
1056    
1057                    query.append(_FINDER_COLUMN_TAGID_TAGID_2);
1058    
1059                    if (orderByComparator != null) {
1060                            String[] orderByFields = orderByComparator.getOrderByFields();
1061    
1062                            if (orderByFields.length > 0) {
1063                                    query.append(WHERE_AND);
1064                            }
1065    
1066                            for (int i = 0; i < orderByFields.length; i++) {
1067                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1068                                    query.append(orderByFields[i]);
1069    
1070                                    if ((i + 1) < orderByFields.length) {
1071                                            if (orderByComparator.isAscending() ^ previous) {
1072                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1073                                            }
1074                                            else {
1075                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1076                                            }
1077                                    }
1078                                    else {
1079                                            if (orderByComparator.isAscending() ^ previous) {
1080                                                    query.append(WHERE_GREATER_THAN);
1081                                            }
1082                                            else {
1083                                                    query.append(WHERE_LESSER_THAN);
1084                                            }
1085                                    }
1086                            }
1087    
1088                            query.append(ORDER_BY_CLAUSE);
1089    
1090                            for (int i = 0; i < orderByFields.length; i++) {
1091                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1092                                    query.append(orderByFields[i]);
1093    
1094                                    if ((i + 1) < orderByFields.length) {
1095                                            if (orderByComparator.isAscending() ^ previous) {
1096                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1097                                            }
1098                                            else {
1099                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1100                                            }
1101                                    }
1102                                    else {
1103                                            if (orderByComparator.isAscending() ^ previous) {
1104                                                    query.append(ORDER_BY_ASC);
1105                                            }
1106                                            else {
1107                                                    query.append(ORDER_BY_DESC);
1108                                            }
1109                                    }
1110                            }
1111                    }
1112    
1113                    else {
1114                            query.append(AssetTagPropertyModelImpl.ORDER_BY_JPQL);
1115                    }
1116    
1117                    String sql = query.toString();
1118    
1119                    Query q = session.createQuery(sql);
1120    
1121                    q.setFirstResult(0);
1122                    q.setMaxResults(2);
1123    
1124                    QueryPos qPos = QueryPos.getInstance(q);
1125    
1126                    qPos.add(tagId);
1127    
1128                    if (orderByComparator != null) {
1129                            Object[] values = orderByComparator.getOrderByValues(assetTagProperty);
1130    
1131                            for (Object value : values) {
1132                                    qPos.add(value);
1133                            }
1134                    }
1135    
1136                    List<AssetTagProperty> list = q.list();
1137    
1138                    if (list.size() == 2) {
1139                            return list.get(1);
1140                    }
1141                    else {
1142                            return null;
1143                    }
1144            }
1145    
1146            /**
1147             * Finds all the asset tag properties where companyId = &#63; and key = &#63;.
1148             *
1149             * @param companyId the company id to search with
1150             * @param key the key to search with
1151             * @return the matching asset tag properties
1152             * @throws SystemException if a system exception occurred
1153             */
1154            public List<AssetTagProperty> findByC_K(long companyId, String key)
1155                    throws SystemException {
1156                    return findByC_K(companyId, key, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1157                            null);
1158            }
1159    
1160            /**
1161             * Finds a range of all the asset tag properties where companyId = &#63; and key = &#63;.
1162             *
1163             * <p>
1164             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1165             * </p>
1166             *
1167             * @param companyId the company id to search with
1168             * @param key the key to search with
1169             * @param start the lower bound of the range of asset tag properties to return
1170             * @param end the upper bound of the range of asset tag properties to return (not inclusive)
1171             * @return the range of matching asset tag properties
1172             * @throws SystemException if a system exception occurred
1173             */
1174            public List<AssetTagProperty> findByC_K(long companyId, String key,
1175                    int start, int end) throws SystemException {
1176                    return findByC_K(companyId, key, start, end, null);
1177            }
1178    
1179            /**
1180             * Finds an ordered range of all the asset tag properties where companyId = &#63; and key = &#63;.
1181             *
1182             * <p>
1183             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1184             * </p>
1185             *
1186             * @param companyId the company id to search with
1187             * @param key the key to search with
1188             * @param start the lower bound of the range of asset tag properties to return
1189             * @param end the upper bound of the range of asset tag properties to return (not inclusive)
1190             * @param orderByComparator the comparator to order the results by
1191             * @return the ordered range of matching asset tag properties
1192             * @throws SystemException if a system exception occurred
1193             */
1194            public List<AssetTagProperty> findByC_K(long companyId, String key,
1195                    int start, int end, OrderByComparator orderByComparator)
1196                    throws SystemException {
1197                    Object[] finderArgs = new Object[] {
1198                                    companyId, key,
1199                                    
1200                                    String.valueOf(start), String.valueOf(end),
1201                                    String.valueOf(orderByComparator)
1202                            };
1203    
1204                    List<AssetTagProperty> list = (List<AssetTagProperty>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_K,
1205                                    finderArgs, this);
1206    
1207                    if (list == null) {
1208                            StringBundler query = null;
1209    
1210                            if (orderByComparator != null) {
1211                                    query = new StringBundler(4 +
1212                                                    (orderByComparator.getOrderByFields().length * 3));
1213                            }
1214                            else {
1215                                    query = new StringBundler(4);
1216                            }
1217    
1218                            query.append(_SQL_SELECT_ASSETTAGPROPERTY_WHERE);
1219    
1220                            query.append(_FINDER_COLUMN_C_K_COMPANYID_2);
1221    
1222                            if (key == null) {
1223                                    query.append(_FINDER_COLUMN_C_K_KEY_1);
1224                            }
1225                            else {
1226                                    if (key.equals(StringPool.BLANK)) {
1227                                            query.append(_FINDER_COLUMN_C_K_KEY_3);
1228                                    }
1229                                    else {
1230                                            query.append(_FINDER_COLUMN_C_K_KEY_2);
1231                                    }
1232                            }
1233    
1234                            if (orderByComparator != null) {
1235                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1236                                            orderByComparator);
1237                            }
1238    
1239                            else {
1240                                    query.append(AssetTagPropertyModelImpl.ORDER_BY_JPQL);
1241                            }
1242    
1243                            String sql = query.toString();
1244    
1245                            Session session = null;
1246    
1247                            try {
1248                                    session = openSession();
1249    
1250                                    Query q = session.createQuery(sql);
1251    
1252                                    QueryPos qPos = QueryPos.getInstance(q);
1253    
1254                                    qPos.add(companyId);
1255    
1256                                    if (key != null) {
1257                                            qPos.add(key);
1258                                    }
1259    
1260                                    list = (List<AssetTagProperty>)QueryUtil.list(q, getDialect(),
1261                                                    start, end);
1262                            }
1263                            catch (Exception e) {
1264                                    throw processException(e);
1265                            }
1266                            finally {
1267                                    if (list == null) {
1268                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_C_K,
1269                                                    finderArgs);
1270                                    }
1271                                    else {
1272                                            cacheResult(list);
1273    
1274                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_K,
1275                                                    finderArgs, list);
1276                                    }
1277    
1278                                    closeSession(session);
1279                            }
1280                    }
1281    
1282                    return list;
1283            }
1284    
1285            /**
1286             * Finds the first asset tag property in the ordered set where companyId = &#63; and key = &#63;.
1287             *
1288             * <p>
1289             * 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1290             * </p>
1291             *
1292             * @param companyId the company id to search with
1293             * @param key the key to search with
1294             * @param orderByComparator the comparator to order the set by
1295             * @return the first matching asset tag property
1296             * @throws com.liferay.portlet.asset.NoSuchTagPropertyException if a matching asset tag property could not be found
1297             * @throws SystemException if a system exception occurred
1298             */
1299            public AssetTagProperty findByC_K_First(long companyId, String key,
1300                    OrderByComparator orderByComparator)
1301                    throws NoSuchTagPropertyException, SystemException {
1302                    List<AssetTagProperty> list = findByC_K(companyId, key, 0, 1,
1303                                    orderByComparator);
1304    
1305                    if (list.isEmpty()) {
1306                            StringBundler msg = new StringBundler(6);
1307    
1308                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1309    
1310                            msg.append("companyId=");
1311                            msg.append(companyId);
1312    
1313                            msg.append(", key=");
1314                            msg.append(key);
1315    
1316                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1317    
1318                            throw new NoSuchTagPropertyException(msg.toString());
1319                    }
1320                    else {
1321                            return list.get(0);
1322                    }
1323            }
1324    
1325            /**
1326             * Finds the last asset tag property in the ordered set where companyId = &#63; and key = &#63;.
1327             *
1328             * <p>
1329             * 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1330             * </p>
1331             *
1332             * @param companyId the company id to search with
1333             * @param key the key to search with
1334             * @param orderByComparator the comparator to order the set by
1335             * @return the last matching asset tag property
1336             * @throws com.liferay.portlet.asset.NoSuchTagPropertyException if a matching asset tag property could not be found
1337             * @throws SystemException if a system exception occurred
1338             */
1339            public AssetTagProperty findByC_K_Last(long companyId, String key,
1340                    OrderByComparator orderByComparator)
1341                    throws NoSuchTagPropertyException, SystemException {
1342                    int count = countByC_K(companyId, key);
1343    
1344                    List<AssetTagProperty> list = findByC_K(companyId, key, count - 1,
1345                                    count, orderByComparator);
1346    
1347                    if (list.isEmpty()) {
1348                            StringBundler msg = new StringBundler(6);
1349    
1350                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1351    
1352                            msg.append("companyId=");
1353                            msg.append(companyId);
1354    
1355                            msg.append(", key=");
1356                            msg.append(key);
1357    
1358                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1359    
1360                            throw new NoSuchTagPropertyException(msg.toString());
1361                    }
1362                    else {
1363                            return list.get(0);
1364                    }
1365            }
1366    
1367            /**
1368             * Finds the asset tag properties before and after the current asset tag property in the ordered set where companyId = &#63; and key = &#63;.
1369             *
1370             * <p>
1371             * 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1372             * </p>
1373             *
1374             * @param tagPropertyId the primary key of the current asset tag property
1375             * @param companyId the company id to search with
1376             * @param key the key to search with
1377             * @param orderByComparator the comparator to order the set by
1378             * @return the previous, current, and next asset tag property
1379             * @throws com.liferay.portlet.asset.NoSuchTagPropertyException if a asset tag property with the primary key could not be found
1380             * @throws SystemException if a system exception occurred
1381             */
1382            public AssetTagProperty[] findByC_K_PrevAndNext(long tagPropertyId,
1383                    long companyId, String key, OrderByComparator orderByComparator)
1384                    throws NoSuchTagPropertyException, SystemException {
1385                    AssetTagProperty assetTagProperty = findByPrimaryKey(tagPropertyId);
1386    
1387                    Session session = null;
1388    
1389                    try {
1390                            session = openSession();
1391    
1392                            AssetTagProperty[] array = new AssetTagPropertyImpl[3];
1393    
1394                            array[0] = getByC_K_PrevAndNext(session, assetTagProperty,
1395                                            companyId, key, orderByComparator, true);
1396    
1397                            array[1] = assetTagProperty;
1398    
1399                            array[2] = getByC_K_PrevAndNext(session, assetTagProperty,
1400                                            companyId, key, orderByComparator, false);
1401    
1402                            return array;
1403                    }
1404                    catch (Exception e) {
1405                            throw processException(e);
1406                    }
1407                    finally {
1408                            closeSession(session);
1409                    }
1410            }
1411    
1412            protected AssetTagProperty getByC_K_PrevAndNext(Session session,
1413                    AssetTagProperty assetTagProperty, long companyId, String key,
1414                    OrderByComparator orderByComparator, boolean previous) {
1415                    StringBundler query = null;
1416    
1417                    if (orderByComparator != null) {
1418                            query = new StringBundler(6 +
1419                                            (orderByComparator.getOrderByFields().length * 6));
1420                    }
1421                    else {
1422                            query = new StringBundler(3);
1423                    }
1424    
1425                    query.append(_SQL_SELECT_ASSETTAGPROPERTY_WHERE);
1426    
1427                    query.append(_FINDER_COLUMN_C_K_COMPANYID_2);
1428    
1429                    if (key == null) {
1430                            query.append(_FINDER_COLUMN_C_K_KEY_1);
1431                    }
1432                    else {
1433                            if (key.equals(StringPool.BLANK)) {
1434                                    query.append(_FINDER_COLUMN_C_K_KEY_3);
1435                            }
1436                            else {
1437                                    query.append(_FINDER_COLUMN_C_K_KEY_2);
1438                            }
1439                    }
1440    
1441                    if (orderByComparator != null) {
1442                            String[] orderByFields = orderByComparator.getOrderByFields();
1443    
1444                            if (orderByFields.length > 0) {
1445                                    query.append(WHERE_AND);
1446                            }
1447    
1448                            for (int i = 0; i < orderByFields.length; i++) {
1449                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1450                                    query.append(orderByFields[i]);
1451    
1452                                    if ((i + 1) < orderByFields.length) {
1453                                            if (orderByComparator.isAscending() ^ previous) {
1454                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1455                                            }
1456                                            else {
1457                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1458                                            }
1459                                    }
1460                                    else {
1461                                            if (orderByComparator.isAscending() ^ previous) {
1462                                                    query.append(WHERE_GREATER_THAN);
1463                                            }
1464                                            else {
1465                                                    query.append(WHERE_LESSER_THAN);
1466                                            }
1467                                    }
1468                            }
1469    
1470                            query.append(ORDER_BY_CLAUSE);
1471    
1472                            for (int i = 0; i < orderByFields.length; i++) {
1473                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1474                                    query.append(orderByFields[i]);
1475    
1476                                    if ((i + 1) < orderByFields.length) {
1477                                            if (orderByComparator.isAscending() ^ previous) {
1478                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1479                                            }
1480                                            else {
1481                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1482                                            }
1483                                    }
1484                                    else {
1485                                            if (orderByComparator.isAscending() ^ previous) {
1486                                                    query.append(ORDER_BY_ASC);
1487                                            }
1488                                            else {
1489                                                    query.append(ORDER_BY_DESC);
1490                                            }
1491                                    }
1492                            }
1493                    }
1494    
1495                    else {
1496                            query.append(AssetTagPropertyModelImpl.ORDER_BY_JPQL);
1497                    }
1498    
1499                    String sql = query.toString();
1500    
1501                    Query q = session.createQuery(sql);
1502    
1503                    q.setFirstResult(0);
1504                    q.setMaxResults(2);
1505    
1506                    QueryPos qPos = QueryPos.getInstance(q);
1507    
1508                    qPos.add(companyId);
1509    
1510                    if (key != null) {
1511                            qPos.add(key);
1512                    }
1513    
1514                    if (orderByComparator != null) {
1515                            Object[] values = orderByComparator.getOrderByValues(assetTagProperty);
1516    
1517                            for (Object value : values) {
1518                                    qPos.add(value);
1519                            }
1520                    }
1521    
1522                    List<AssetTagProperty> list = q.list();
1523    
1524                    if (list.size() == 2) {
1525                            return list.get(1);
1526                    }
1527                    else {
1528                            return null;
1529                    }
1530            }
1531    
1532            /**
1533             * Finds the asset tag property where tagId = &#63; and key = &#63; or throws a {@link com.liferay.portlet.asset.NoSuchTagPropertyException} if it could not be found.
1534             *
1535             * @param tagId the tag id to search with
1536             * @param key the key to search with
1537             * @return the matching asset tag property
1538             * @throws com.liferay.portlet.asset.NoSuchTagPropertyException if a matching asset tag property could not be found
1539             * @throws SystemException if a system exception occurred
1540             */
1541            public AssetTagProperty findByT_K(long tagId, String key)
1542                    throws NoSuchTagPropertyException, SystemException {
1543                    AssetTagProperty assetTagProperty = fetchByT_K(tagId, key);
1544    
1545                    if (assetTagProperty == null) {
1546                            StringBundler msg = new StringBundler(6);
1547    
1548                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1549    
1550                            msg.append("tagId=");
1551                            msg.append(tagId);
1552    
1553                            msg.append(", key=");
1554                            msg.append(key);
1555    
1556                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1557    
1558                            if (_log.isWarnEnabled()) {
1559                                    _log.warn(msg.toString());
1560                            }
1561    
1562                            throw new NoSuchTagPropertyException(msg.toString());
1563                    }
1564    
1565                    return assetTagProperty;
1566            }
1567    
1568            /**
1569             * Finds the asset tag property where tagId = &#63; and key = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1570             *
1571             * @param tagId the tag id to search with
1572             * @param key the key to search with
1573             * @return the matching asset tag property, or <code>null</code> if a matching asset tag property could not be found
1574             * @throws SystemException if a system exception occurred
1575             */
1576            public AssetTagProperty fetchByT_K(long tagId, String key)
1577                    throws SystemException {
1578                    return fetchByT_K(tagId, key, true);
1579            }
1580    
1581            /**
1582             * Finds the asset tag property where tagId = &#63; and key = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1583             *
1584             * @param tagId the tag id to search with
1585             * @param key the key to search with
1586             * @return the matching asset tag property, or <code>null</code> if a matching asset tag property could not be found
1587             * @throws SystemException if a system exception occurred
1588             */
1589            public AssetTagProperty fetchByT_K(long tagId, String key,
1590                    boolean retrieveFromCache) throws SystemException {
1591                    Object[] finderArgs = new Object[] { tagId, key };
1592    
1593                    Object result = null;
1594    
1595                    if (retrieveFromCache) {
1596                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_T_K,
1597                                            finderArgs, this);
1598                    }
1599    
1600                    if (result == null) {
1601                            StringBundler query = new StringBundler(4);
1602    
1603                            query.append(_SQL_SELECT_ASSETTAGPROPERTY_WHERE);
1604    
1605                            query.append(_FINDER_COLUMN_T_K_TAGID_2);
1606    
1607                            if (key == null) {
1608                                    query.append(_FINDER_COLUMN_T_K_KEY_1);
1609                            }
1610                            else {
1611                                    if (key.equals(StringPool.BLANK)) {
1612                                            query.append(_FINDER_COLUMN_T_K_KEY_3);
1613                                    }
1614                                    else {
1615                                            query.append(_FINDER_COLUMN_T_K_KEY_2);
1616                                    }
1617                            }
1618    
1619                            query.append(AssetTagPropertyModelImpl.ORDER_BY_JPQL);
1620    
1621                            String sql = query.toString();
1622    
1623                            Session session = null;
1624    
1625                            try {
1626                                    session = openSession();
1627    
1628                                    Query q = session.createQuery(sql);
1629    
1630                                    QueryPos qPos = QueryPos.getInstance(q);
1631    
1632                                    qPos.add(tagId);
1633    
1634                                    if (key != null) {
1635                                            qPos.add(key);
1636                                    }
1637    
1638                                    List<AssetTagProperty> list = q.list();
1639    
1640                                    result = list;
1641    
1642                                    AssetTagProperty assetTagProperty = null;
1643    
1644                                    if (list.isEmpty()) {
1645                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_K,
1646                                                    finderArgs, list);
1647                                    }
1648                                    else {
1649                                            assetTagProperty = list.get(0);
1650    
1651                                            cacheResult(assetTagProperty);
1652    
1653                                            if ((assetTagProperty.getTagId() != tagId) ||
1654                                                            (assetTagProperty.getKey() == null) ||
1655                                                            !assetTagProperty.getKey().equals(key)) {
1656                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_T_K,
1657                                                            finderArgs, assetTagProperty);
1658                                            }
1659                                    }
1660    
1661                                    return assetTagProperty;
1662                            }
1663                            catch (Exception e) {
1664                                    throw processException(e);
1665                            }
1666                            finally {
1667                                    if (result == null) {
1668                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_T_K,
1669                                                    finderArgs);
1670                                    }
1671    
1672                                    closeSession(session);
1673                            }
1674                    }
1675                    else {
1676                            if (result instanceof List<?>) {
1677                                    return null;
1678                            }
1679                            else {
1680                                    return (AssetTagProperty)result;
1681                            }
1682                    }
1683            }
1684    
1685            /**
1686             * Finds all the asset tag properties.
1687             *
1688             * @return the asset tag properties
1689             * @throws SystemException if a system exception occurred
1690             */
1691            public List<AssetTagProperty> findAll() throws SystemException {
1692                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1693            }
1694    
1695            /**
1696             * Finds a range of all the asset tag properties.
1697             *
1698             * <p>
1699             * 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1700             * </p>
1701             *
1702             * @param start the lower bound of the range of asset tag properties to return
1703             * @param end the upper bound of the range of asset tag properties to return (not inclusive)
1704             * @return the range of asset tag properties
1705             * @throws SystemException if a system exception occurred
1706             */
1707            public List<AssetTagProperty> findAll(int start, int end)
1708                    throws SystemException {
1709                    return findAll(start, end, null);
1710            }
1711    
1712            /**
1713             * Finds an ordered range of all the asset tag properties.
1714             *
1715             * <p>
1716             * 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1717             * </p>
1718             *
1719             * @param start the lower bound of the range of asset tag properties to return
1720             * @param end the upper bound of the range of asset tag properties to return (not inclusive)
1721             * @param orderByComparator the comparator to order the results by
1722             * @return the ordered range of asset tag properties
1723             * @throws SystemException if a system exception occurred
1724             */
1725            public List<AssetTagProperty> findAll(int start, int end,
1726                    OrderByComparator orderByComparator) throws SystemException {
1727                    Object[] finderArgs = new Object[] {
1728                                    String.valueOf(start), String.valueOf(end),
1729                                    String.valueOf(orderByComparator)
1730                            };
1731    
1732                    List<AssetTagProperty> list = (List<AssetTagProperty>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1733                                    finderArgs, this);
1734    
1735                    if (list == null) {
1736                            StringBundler query = null;
1737                            String sql = null;
1738    
1739                            if (orderByComparator != null) {
1740                                    query = new StringBundler(2 +
1741                                                    (orderByComparator.getOrderByFields().length * 3));
1742    
1743                                    query.append(_SQL_SELECT_ASSETTAGPROPERTY);
1744    
1745                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1746                                            orderByComparator);
1747    
1748                                    sql = query.toString();
1749                            }
1750                            else {
1751                                    sql = _SQL_SELECT_ASSETTAGPROPERTY.concat(AssetTagPropertyModelImpl.ORDER_BY_JPQL);
1752                            }
1753    
1754                            Session session = null;
1755    
1756                            try {
1757                                    session = openSession();
1758    
1759                                    Query q = session.createQuery(sql);
1760    
1761                                    if (orderByComparator == null) {
1762                                            list = (List<AssetTagProperty>)QueryUtil.list(q,
1763                                                            getDialect(), start, end, false);
1764    
1765                                            Collections.sort(list);
1766                                    }
1767                                    else {
1768                                            list = (List<AssetTagProperty>)QueryUtil.list(q,
1769                                                            getDialect(), start, end);
1770                                    }
1771                            }
1772                            catch (Exception e) {
1773                                    throw processException(e);
1774                            }
1775                            finally {
1776                                    if (list == null) {
1777                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_ALL,
1778                                                    finderArgs);
1779                                    }
1780                                    else {
1781                                            cacheResult(list);
1782    
1783                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs,
1784                                                    list);
1785                                    }
1786    
1787                                    closeSession(session);
1788                            }
1789                    }
1790    
1791                    return list;
1792            }
1793    
1794            /**
1795             * Removes all the asset tag properties where companyId = &#63; from the database.
1796             *
1797             * @param companyId the company id to search with
1798             * @throws SystemException if a system exception occurred
1799             */
1800            public void removeByCompanyId(long companyId) throws SystemException {
1801                    for (AssetTagProperty assetTagProperty : findByCompanyId(companyId)) {
1802                            remove(assetTagProperty);
1803                    }
1804            }
1805    
1806            /**
1807             * Removes all the asset tag properties where tagId = &#63; from the database.
1808             *
1809             * @param tagId the tag id to search with
1810             * @throws SystemException if a system exception occurred
1811             */
1812            public void removeByTagId(long tagId) throws SystemException {
1813                    for (AssetTagProperty assetTagProperty : findByTagId(tagId)) {
1814                            remove(assetTagProperty);
1815                    }
1816            }
1817    
1818            /**
1819             * Removes all the asset tag properties where companyId = &#63; and key = &#63; from the database.
1820             *
1821             * @param companyId the company id to search with
1822             * @param key the key to search with
1823             * @throws SystemException if a system exception occurred
1824             */
1825            public void removeByC_K(long companyId, String key)
1826                    throws SystemException {
1827                    for (AssetTagProperty assetTagProperty : findByC_K(companyId, key)) {
1828                            remove(assetTagProperty);
1829                    }
1830            }
1831    
1832            /**
1833             * Removes the asset tag property where tagId = &#63; and key = &#63; from the database.
1834             *
1835             * @param tagId the tag id to search with
1836             * @param key the key to search with
1837             * @throws SystemException if a system exception occurred
1838             */
1839            public void removeByT_K(long tagId, String key)
1840                    throws NoSuchTagPropertyException, SystemException {
1841                    AssetTagProperty assetTagProperty = findByT_K(tagId, key);
1842    
1843                    remove(assetTagProperty);
1844            }
1845    
1846            /**
1847             * Removes all the asset tag properties from the database.
1848             *
1849             * @throws SystemException if a system exception occurred
1850             */
1851            public void removeAll() throws SystemException {
1852                    for (AssetTagProperty assetTagProperty : findAll()) {
1853                            remove(assetTagProperty);
1854                    }
1855            }
1856    
1857            /**
1858             * Counts all the asset tag properties where companyId = &#63;.
1859             *
1860             * @param companyId the company id to search with
1861             * @return the number of matching asset tag properties
1862             * @throws SystemException if a system exception occurred
1863             */
1864            public int countByCompanyId(long companyId) throws SystemException {
1865                    Object[] finderArgs = new Object[] { companyId };
1866    
1867                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
1868                                    finderArgs, this);
1869    
1870                    if (count == null) {
1871                            StringBundler query = new StringBundler(2);
1872    
1873                            query.append(_SQL_COUNT_ASSETTAGPROPERTY_WHERE);
1874    
1875                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1876    
1877                            String sql = query.toString();
1878    
1879                            Session session = null;
1880    
1881                            try {
1882                                    session = openSession();
1883    
1884                                    Query q = session.createQuery(sql);
1885    
1886                                    QueryPos qPos = QueryPos.getInstance(q);
1887    
1888                                    qPos.add(companyId);
1889    
1890                                    count = (Long)q.uniqueResult();
1891                            }
1892                            catch (Exception e) {
1893                                    throw processException(e);
1894                            }
1895                            finally {
1896                                    if (count == null) {
1897                                            count = Long.valueOf(0);
1898                                    }
1899    
1900                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
1901                                            finderArgs, count);
1902    
1903                                    closeSession(session);
1904                            }
1905                    }
1906    
1907                    return count.intValue();
1908            }
1909    
1910            /**
1911             * Counts all the asset tag properties where tagId = &#63;.
1912             *
1913             * @param tagId the tag id to search with
1914             * @return the number of matching asset tag properties
1915             * @throws SystemException if a system exception occurred
1916             */
1917            public int countByTagId(long tagId) throws SystemException {
1918                    Object[] finderArgs = new Object[] { tagId };
1919    
1920                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_TAGID,
1921                                    finderArgs, this);
1922    
1923                    if (count == null) {
1924                            StringBundler query = new StringBundler(2);
1925    
1926                            query.append(_SQL_COUNT_ASSETTAGPROPERTY_WHERE);
1927    
1928                            query.append(_FINDER_COLUMN_TAGID_TAGID_2);
1929    
1930                            String sql = query.toString();
1931    
1932                            Session session = null;
1933    
1934                            try {
1935                                    session = openSession();
1936    
1937                                    Query q = session.createQuery(sql);
1938    
1939                                    QueryPos qPos = QueryPos.getInstance(q);
1940    
1941                                    qPos.add(tagId);
1942    
1943                                    count = (Long)q.uniqueResult();
1944                            }
1945                            catch (Exception e) {
1946                                    throw processException(e);
1947                            }
1948                            finally {
1949                                    if (count == null) {
1950                                            count = Long.valueOf(0);
1951                                    }
1952    
1953                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_TAGID,
1954                                            finderArgs, count);
1955    
1956                                    closeSession(session);
1957                            }
1958                    }
1959    
1960                    return count.intValue();
1961            }
1962    
1963            /**
1964             * Counts all the asset tag properties where companyId = &#63; and key = &#63;.
1965             *
1966             * @param companyId the company id to search with
1967             * @param key the key to search with
1968             * @return the number of matching asset tag properties
1969             * @throws SystemException if a system exception occurred
1970             */
1971            public int countByC_K(long companyId, String key) throws SystemException {
1972                    Object[] finderArgs = new Object[] { companyId, key };
1973    
1974                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_K,
1975                                    finderArgs, this);
1976    
1977                    if (count == null) {
1978                            StringBundler query = new StringBundler(3);
1979    
1980                            query.append(_SQL_COUNT_ASSETTAGPROPERTY_WHERE);
1981    
1982                            query.append(_FINDER_COLUMN_C_K_COMPANYID_2);
1983    
1984                            if (key == null) {
1985                                    query.append(_FINDER_COLUMN_C_K_KEY_1);
1986                            }
1987                            else {
1988                                    if (key.equals(StringPool.BLANK)) {
1989                                            query.append(_FINDER_COLUMN_C_K_KEY_3);
1990                                    }
1991                                    else {
1992                                            query.append(_FINDER_COLUMN_C_K_KEY_2);
1993                                    }
1994                            }
1995    
1996                            String sql = query.toString();
1997    
1998                            Session session = null;
1999    
2000                            try {
2001                                    session = openSession();
2002    
2003                                    Query q = session.createQuery(sql);
2004    
2005                                    QueryPos qPos = QueryPos.getInstance(q);
2006    
2007                                    qPos.add(companyId);
2008    
2009                                    if (key != null) {
2010                                            qPos.add(key);
2011                                    }
2012    
2013                                    count = (Long)q.uniqueResult();
2014                            }
2015                            catch (Exception e) {
2016                                    throw processException(e);
2017                            }
2018                            finally {
2019                                    if (count == null) {
2020                                            count = Long.valueOf(0);
2021                                    }
2022    
2023                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_K, finderArgs,
2024                                            count);
2025    
2026                                    closeSession(session);
2027                            }
2028                    }
2029    
2030                    return count.intValue();
2031            }
2032    
2033            /**
2034             * Counts all the asset tag properties where tagId = &#63; and key = &#63;.
2035             *
2036             * @param tagId the tag id to search with
2037             * @param key the key to search with
2038             * @return the number of matching asset tag properties
2039             * @throws SystemException if a system exception occurred
2040             */
2041            public int countByT_K(long tagId, String key) throws SystemException {
2042                    Object[] finderArgs = new Object[] { tagId, key };
2043    
2044                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_K,
2045                                    finderArgs, this);
2046    
2047                    if (count == null) {
2048                            StringBundler query = new StringBundler(3);
2049    
2050                            query.append(_SQL_COUNT_ASSETTAGPROPERTY_WHERE);
2051    
2052                            query.append(_FINDER_COLUMN_T_K_TAGID_2);
2053    
2054                            if (key == null) {
2055                                    query.append(_FINDER_COLUMN_T_K_KEY_1);
2056                            }
2057                            else {
2058                                    if (key.equals(StringPool.BLANK)) {
2059                                            query.append(_FINDER_COLUMN_T_K_KEY_3);
2060                                    }
2061                                    else {
2062                                            query.append(_FINDER_COLUMN_T_K_KEY_2);
2063                                    }
2064                            }
2065    
2066                            String sql = query.toString();
2067    
2068                            Session session = null;
2069    
2070                            try {
2071                                    session = openSession();
2072    
2073                                    Query q = session.createQuery(sql);
2074    
2075                                    QueryPos qPos = QueryPos.getInstance(q);
2076    
2077                                    qPos.add(tagId);
2078    
2079                                    if (key != null) {
2080                                            qPos.add(key);
2081                                    }
2082    
2083                                    count = (Long)q.uniqueResult();
2084                            }
2085                            catch (Exception e) {
2086                                    throw processException(e);
2087                            }
2088                            finally {
2089                                    if (count == null) {
2090                                            count = Long.valueOf(0);
2091                                    }
2092    
2093                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_K, finderArgs,
2094                                            count);
2095    
2096                                    closeSession(session);
2097                            }
2098                    }
2099    
2100                    return count.intValue();
2101            }
2102    
2103            /**
2104             * Counts all the asset tag properties.
2105             *
2106             * @return the number of asset tag properties
2107             * @throws SystemException if a system exception occurred
2108             */
2109            public int countAll() throws SystemException {
2110                    Object[] finderArgs = new Object[0];
2111    
2112                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2113                                    finderArgs, this);
2114    
2115                    if (count == null) {
2116                            Session session = null;
2117    
2118                            try {
2119                                    session = openSession();
2120    
2121                                    Query q = session.createQuery(_SQL_COUNT_ASSETTAGPROPERTY);
2122    
2123                                    count = (Long)q.uniqueResult();
2124                            }
2125                            catch (Exception e) {
2126                                    throw processException(e);
2127                            }
2128                            finally {
2129                                    if (count == null) {
2130                                            count = Long.valueOf(0);
2131                                    }
2132    
2133                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2134                                            count);
2135    
2136                                    closeSession(session);
2137                            }
2138                    }
2139    
2140                    return count.intValue();
2141            }
2142    
2143            /**
2144             * Initializes the asset tag property persistence.
2145             */
2146            public void afterPropertiesSet() {
2147                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2148                                            com.liferay.portal.util.PropsUtil.get(
2149                                                    "value.object.listener.com.liferay.portlet.asset.model.AssetTagProperty")));
2150    
2151                    if (listenerClassNames.length > 0) {
2152                            try {
2153                                    List<ModelListener<AssetTagProperty>> listenersList = new ArrayList<ModelListener<AssetTagProperty>>();
2154    
2155                                    for (String listenerClassName : listenerClassNames) {
2156                                            listenersList.add((ModelListener<AssetTagProperty>)InstanceFactory.newInstance(
2157                                                            listenerClassName));
2158                                    }
2159    
2160                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2161                            }
2162                            catch (Exception e) {
2163                                    _log.error(e);
2164                            }
2165                    }
2166            }
2167    
2168            public void destroy() {
2169                    EntityCacheUtil.removeCache(AssetTagPropertyImpl.class.getName());
2170                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2171                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
2172            }
2173    
2174            @BeanReference(type = AssetCategoryPersistence.class)
2175            protected AssetCategoryPersistence assetCategoryPersistence;
2176            @BeanReference(type = AssetCategoryPropertyPersistence.class)
2177            protected AssetCategoryPropertyPersistence assetCategoryPropertyPersistence;
2178            @BeanReference(type = AssetEntryPersistence.class)
2179            protected AssetEntryPersistence assetEntryPersistence;
2180            @BeanReference(type = AssetLinkPersistence.class)
2181            protected AssetLinkPersistence assetLinkPersistence;
2182            @BeanReference(type = AssetTagPersistence.class)
2183            protected AssetTagPersistence assetTagPersistence;
2184            @BeanReference(type = AssetTagPropertyPersistence.class)
2185            protected AssetTagPropertyPersistence assetTagPropertyPersistence;
2186            @BeanReference(type = AssetTagStatsPersistence.class)
2187            protected AssetTagStatsPersistence assetTagStatsPersistence;
2188            @BeanReference(type = AssetVocabularyPersistence.class)
2189            protected AssetVocabularyPersistence assetVocabularyPersistence;
2190            @BeanReference(type = ResourcePersistence.class)
2191            protected ResourcePersistence resourcePersistence;
2192            @BeanReference(type = UserPersistence.class)
2193            protected UserPersistence userPersistence;
2194            private static final String _SQL_SELECT_ASSETTAGPROPERTY = "SELECT assetTagProperty FROM AssetTagProperty assetTagProperty";
2195            private static final String _SQL_SELECT_ASSETTAGPROPERTY_WHERE = "SELECT assetTagProperty FROM AssetTagProperty assetTagProperty WHERE ";
2196            private static final String _SQL_COUNT_ASSETTAGPROPERTY = "SELECT COUNT(assetTagProperty) FROM AssetTagProperty assetTagProperty";
2197            private static final String _SQL_COUNT_ASSETTAGPROPERTY_WHERE = "SELECT COUNT(assetTagProperty) FROM AssetTagProperty assetTagProperty WHERE ";
2198            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "assetTagProperty.companyId = ?";
2199            private static final String _FINDER_COLUMN_TAGID_TAGID_2 = "assetTagProperty.tagId = ?";
2200            private static final String _FINDER_COLUMN_C_K_COMPANYID_2 = "assetTagProperty.companyId = ? AND ";
2201            private static final String _FINDER_COLUMN_C_K_KEY_1 = "assetTagProperty.key IS NULL";
2202            private static final String _FINDER_COLUMN_C_K_KEY_2 = "assetTagProperty.key = ?";
2203            private static final String _FINDER_COLUMN_C_K_KEY_3 = "(assetTagProperty.key IS NULL OR assetTagProperty.key = ?)";
2204            private static final String _FINDER_COLUMN_T_K_TAGID_2 = "assetTagProperty.tagId = ? AND ";
2205            private static final String _FINDER_COLUMN_T_K_KEY_1 = "assetTagProperty.key IS NULL";
2206            private static final String _FINDER_COLUMN_T_K_KEY_2 = "assetTagProperty.key = ?";
2207            private static final String _FINDER_COLUMN_T_K_KEY_3 = "(assetTagProperty.key IS NULL OR assetTagProperty.key = ?)";
2208            private static final String _ORDER_BY_ENTITY_ALIAS = "assetTagProperty.";
2209            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AssetTagProperty exists with the primary key ";
2210            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AssetTagProperty exists with the key {";
2211            private static Log _log = LogFactoryUtil.getLog(AssetTagPropertyPersistenceImpl.class);
2212    }