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