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