001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.asset.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.annotation.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
021    import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
022    import com.liferay.portal.kernel.dao.jdbc.RowMapper;
023    import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
024    import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
025    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
026    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
027    import com.liferay.portal.kernel.dao.orm.FinderPath;
028    import com.liferay.portal.kernel.dao.orm.Query;
029    import com.liferay.portal.kernel.dao.orm.QueryPos;
030    import com.liferay.portal.kernel.dao.orm.QueryUtil;
031    import com.liferay.portal.kernel.dao.orm.SQLQuery;
032    import com.liferay.portal.kernel.dao.orm.Session;
033    import com.liferay.portal.kernel.exception.SystemException;
034    import com.liferay.portal.kernel.log.Log;
035    import com.liferay.portal.kernel.log.LogFactoryUtil;
036    import com.liferay.portal.kernel.util.GetterUtil;
037    import com.liferay.portal.kernel.util.InstanceFactory;
038    import com.liferay.portal.kernel.util.OrderByComparator;
039    import com.liferay.portal.kernel.util.SetUtil;
040    import com.liferay.portal.kernel.util.StringBundler;
041    import com.liferay.portal.kernel.util.StringPool;
042    import com.liferay.portal.kernel.util.StringUtil;
043    import com.liferay.portal.model.ModelListener;
044    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
045    import com.liferay.portal.service.persistence.BatchSessionUtil;
046    import com.liferay.portal.service.persistence.ResourcePersistence;
047    import com.liferay.portal.service.persistence.UserPersistence;
048    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
049    
050    import com.liferay.portlet.asset.NoSuchTagException;
051    import com.liferay.portlet.asset.model.AssetTag;
052    import com.liferay.portlet.asset.model.impl.AssetTagImpl;
053    import com.liferay.portlet.asset.model.impl.AssetTagModelImpl;
054    
055    import java.io.Serializable;
056    
057    import java.util.ArrayList;
058    import java.util.Collections;
059    import java.util.List;
060    import java.util.Set;
061    
062    /**
063     * @author    Brian Wing Shun Chan
064     * @see       AssetTagPersistence
065     * @see       AssetTagUtil
066     * @generated
067     */
068    public class AssetTagPersistenceImpl extends BasePersistenceImpl<AssetTag>
069            implements AssetTagPersistence {
070            public static final String FINDER_CLASS_NAME_ENTITY = AssetTagImpl.class.getName();
071            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
072                    ".List";
073            public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
074                            AssetTagModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
075                            "findByGroupId",
076                            new String[] {
077                                    Long.class.getName(),
078                                    
079                            "java.lang.Integer", "java.lang.Integer",
080                                    "com.liferay.portal.kernel.util.OrderByComparator"
081                            });
082            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
083                            AssetTagModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
084                            "countByGroupId", new String[] { Long.class.getName() });
085            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
086                            AssetTagModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
087                            "findAll", new String[0]);
088            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
089                            AssetTagModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
090                            "countAll", new String[0]);
091    
092            public void cacheResult(AssetTag assetTag) {
093                    EntityCacheUtil.putResult(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
094                            AssetTagImpl.class, assetTag.getPrimaryKey(), assetTag);
095            }
096    
097            public void cacheResult(List<AssetTag> assetTags) {
098                    for (AssetTag assetTag : assetTags) {
099                            if (EntityCacheUtil.getResult(
100                                                    AssetTagModelImpl.ENTITY_CACHE_ENABLED,
101                                                    AssetTagImpl.class, assetTag.getPrimaryKey(), this) == null) {
102                                    cacheResult(assetTag);
103                            }
104                    }
105            }
106    
107            public void clearCache() {
108                    CacheRegistryUtil.clear(AssetTagImpl.class.getName());
109                    EntityCacheUtil.clearCache(AssetTagImpl.class.getName());
110                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
111                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
112            }
113    
114            public void clearCache(AssetTag assetTag) {
115                    EntityCacheUtil.removeResult(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
116                            AssetTagImpl.class, assetTag.getPrimaryKey());
117            }
118    
119            public AssetTag create(long tagId) {
120                    AssetTag assetTag = new AssetTagImpl();
121    
122                    assetTag.setNew(true);
123                    assetTag.setPrimaryKey(tagId);
124    
125                    return assetTag;
126            }
127    
128            public AssetTag remove(Serializable primaryKey)
129                    throws NoSuchModelException, SystemException {
130                    return remove(((Long)primaryKey).longValue());
131            }
132    
133            public AssetTag remove(long tagId)
134                    throws NoSuchTagException, SystemException {
135                    Session session = null;
136    
137                    try {
138                            session = openSession();
139    
140                            AssetTag assetTag = (AssetTag)session.get(AssetTagImpl.class,
141                                            new Long(tagId));
142    
143                            if (assetTag == null) {
144                                    if (_log.isWarnEnabled()) {
145                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + tagId);
146                                    }
147    
148                                    throw new NoSuchTagException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
149                                            tagId);
150                            }
151    
152                            return remove(assetTag);
153                    }
154                    catch (NoSuchTagException nsee) {
155                            throw nsee;
156                    }
157                    catch (Exception e) {
158                            throw processException(e);
159                    }
160                    finally {
161                            closeSession(session);
162                    }
163            }
164    
165            protected AssetTag removeImpl(AssetTag assetTag) throws SystemException {
166                    assetTag = toUnwrappedModel(assetTag);
167    
168                    try {
169                            clearAssetEntries.clear(assetTag.getPrimaryKey());
170                    }
171                    catch (Exception e) {
172                            throw processException(e);
173                    }
174                    finally {
175                            FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
176                    }
177    
178                    Session session = null;
179    
180                    try {
181                            session = openSession();
182    
183                            if (assetTag.isCachedModel() || BatchSessionUtil.isEnabled()) {
184                                    Object staleObject = session.get(AssetTagImpl.class,
185                                                    assetTag.getPrimaryKeyObj());
186    
187                                    if (staleObject != null) {
188                                            session.evict(staleObject);
189                                    }
190                            }
191    
192                            session.delete(assetTag);
193    
194                            session.flush();
195                    }
196                    catch (Exception e) {
197                            throw processException(e);
198                    }
199                    finally {
200                            closeSession(session);
201                    }
202    
203                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
204    
205                    EntityCacheUtil.removeResult(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
206                            AssetTagImpl.class, assetTag.getPrimaryKey());
207    
208                    return assetTag;
209            }
210    
211            public AssetTag updateImpl(
212                    com.liferay.portlet.asset.model.AssetTag assetTag, boolean merge)
213                    throws SystemException {
214                    assetTag = toUnwrappedModel(assetTag);
215    
216                    Session session = null;
217    
218                    try {
219                            session = openSession();
220    
221                            BatchSessionUtil.update(session, assetTag, merge);
222    
223                            assetTag.setNew(false);
224                    }
225                    catch (Exception e) {
226                            throw processException(e);
227                    }
228                    finally {
229                            closeSession(session);
230                    }
231    
232                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
233    
234                    EntityCacheUtil.putResult(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
235                            AssetTagImpl.class, assetTag.getPrimaryKey(), assetTag);
236    
237                    return assetTag;
238            }
239    
240            protected AssetTag toUnwrappedModel(AssetTag assetTag) {
241                    if (assetTag instanceof AssetTagImpl) {
242                            return assetTag;
243                    }
244    
245                    AssetTagImpl assetTagImpl = new AssetTagImpl();
246    
247                    assetTagImpl.setNew(assetTag.isNew());
248                    assetTagImpl.setPrimaryKey(assetTag.getPrimaryKey());
249    
250                    assetTagImpl.setTagId(assetTag.getTagId());
251                    assetTagImpl.setGroupId(assetTag.getGroupId());
252                    assetTagImpl.setCompanyId(assetTag.getCompanyId());
253                    assetTagImpl.setUserId(assetTag.getUserId());
254                    assetTagImpl.setUserName(assetTag.getUserName());
255                    assetTagImpl.setCreateDate(assetTag.getCreateDate());
256                    assetTagImpl.setModifiedDate(assetTag.getModifiedDate());
257                    assetTagImpl.setName(assetTag.getName());
258                    assetTagImpl.setAssetCount(assetTag.getAssetCount());
259    
260                    return assetTagImpl;
261            }
262    
263            public AssetTag findByPrimaryKey(Serializable primaryKey)
264                    throws NoSuchModelException, SystemException {
265                    return findByPrimaryKey(((Long)primaryKey).longValue());
266            }
267    
268            public AssetTag findByPrimaryKey(long tagId)
269                    throws NoSuchTagException, SystemException {
270                    AssetTag assetTag = fetchByPrimaryKey(tagId);
271    
272                    if (assetTag == null) {
273                            if (_log.isWarnEnabled()) {
274                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + tagId);
275                            }
276    
277                            throw new NoSuchTagException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
278                                    tagId);
279                    }
280    
281                    return assetTag;
282            }
283    
284            public AssetTag fetchByPrimaryKey(Serializable primaryKey)
285                    throws SystemException {
286                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
287            }
288    
289            public AssetTag fetchByPrimaryKey(long tagId) throws SystemException {
290                    AssetTag assetTag = (AssetTag)EntityCacheUtil.getResult(AssetTagModelImpl.ENTITY_CACHE_ENABLED,
291                                    AssetTagImpl.class, tagId, this);
292    
293                    if (assetTag == null) {
294                            Session session = null;
295    
296                            try {
297                                    session = openSession();
298    
299                                    assetTag = (AssetTag)session.get(AssetTagImpl.class,
300                                                    new Long(tagId));
301                            }
302                            catch (Exception e) {
303                                    throw processException(e);
304                            }
305                            finally {
306                                    if (assetTag != null) {
307                                            cacheResult(assetTag);
308                                    }
309    
310                                    closeSession(session);
311                            }
312                    }
313    
314                    return assetTag;
315            }
316    
317            public List<AssetTag> findByGroupId(long groupId) throws SystemException {
318                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
319            }
320    
321            public List<AssetTag> findByGroupId(long groupId, int start, int end)
322                    throws SystemException {
323                    return findByGroupId(groupId, start, end, null);
324            }
325    
326            public List<AssetTag> findByGroupId(long groupId, int start, int end,
327                    OrderByComparator orderByComparator) throws SystemException {
328                    Object[] finderArgs = new Object[] {
329                                    groupId,
330                                    
331                                    String.valueOf(start), String.valueOf(end),
332                                    String.valueOf(orderByComparator)
333                            };
334    
335                    List<AssetTag> list = (List<AssetTag>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
336                                    finderArgs, this);
337    
338                    if (list == null) {
339                            Session session = null;
340    
341                            try {
342                                    session = openSession();
343    
344                                    StringBundler query = null;
345    
346                                    if (orderByComparator != null) {
347                                            query = new StringBundler(3 +
348                                                            (orderByComparator.getOrderByFields().length * 3));
349                                    }
350                                    else {
351                                            query = new StringBundler(3);
352                                    }
353    
354                                    query.append(_SQL_SELECT_ASSETTAG_WHERE);
355    
356                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
357    
358                                    if (orderByComparator != null) {
359                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
360                                                    orderByComparator);
361                                    }
362    
363                                    else {
364                                            query.append(AssetTagModelImpl.ORDER_BY_JPQL);
365                                    }
366    
367                                    String sql = query.toString();
368    
369                                    Query q = session.createQuery(sql);
370    
371                                    QueryPos qPos = QueryPos.getInstance(q);
372    
373                                    qPos.add(groupId);
374    
375                                    list = (List<AssetTag>)QueryUtil.list(q, getDialect(), start,
376                                                    end);
377                            }
378                            catch (Exception e) {
379                                    throw processException(e);
380                            }
381                            finally {
382                                    if (list == null) {
383                                            list = new ArrayList<AssetTag>();
384                                    }
385    
386                                    cacheResult(list);
387    
388                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
389                                            finderArgs, list);
390    
391                                    closeSession(session);
392                            }
393                    }
394    
395                    return list;
396            }
397    
398            public AssetTag findByGroupId_First(long groupId,
399                    OrderByComparator orderByComparator)
400                    throws NoSuchTagException, SystemException {
401                    List<AssetTag> list = findByGroupId(groupId, 0, 1, orderByComparator);
402    
403                    if (list.isEmpty()) {
404                            StringBundler msg = new StringBundler(4);
405    
406                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
407    
408                            msg.append("groupId=");
409                            msg.append(groupId);
410    
411                            msg.append(StringPool.CLOSE_CURLY_BRACE);
412    
413                            throw new NoSuchTagException(msg.toString());
414                    }
415                    else {
416                            return list.get(0);
417                    }
418            }
419    
420            public AssetTag findByGroupId_Last(long groupId,
421                    OrderByComparator orderByComparator)
422                    throws NoSuchTagException, SystemException {
423                    int count = countByGroupId(groupId);
424    
425                    List<AssetTag> list = findByGroupId(groupId, count - 1, count,
426                                    orderByComparator);
427    
428                    if (list.isEmpty()) {
429                            StringBundler msg = new StringBundler(4);
430    
431                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
432    
433                            msg.append("groupId=");
434                            msg.append(groupId);
435    
436                            msg.append(StringPool.CLOSE_CURLY_BRACE);
437    
438                            throw new NoSuchTagException(msg.toString());
439                    }
440                    else {
441                            return list.get(0);
442                    }
443            }
444    
445            public AssetTag[] findByGroupId_PrevAndNext(long tagId, long groupId,
446                    OrderByComparator orderByComparator)
447                    throws NoSuchTagException, SystemException {
448                    AssetTag assetTag = findByPrimaryKey(tagId);
449    
450                    Session session = null;
451    
452                    try {
453                            session = openSession();
454    
455                            AssetTag[] array = new AssetTagImpl[3];
456    
457                            array[0] = getByGroupId_PrevAndNext(session, assetTag, groupId,
458                                            orderByComparator, true);
459    
460                            array[1] = assetTag;
461    
462                            array[2] = getByGroupId_PrevAndNext(session, assetTag, groupId,
463                                            orderByComparator, false);
464    
465                            return array;
466                    }
467                    catch (Exception e) {
468                            throw processException(e);
469                    }
470                    finally {
471                            closeSession(session);
472                    }
473            }
474    
475            protected AssetTag getByGroupId_PrevAndNext(Session session,
476                    AssetTag assetTag, long groupId, OrderByComparator orderByComparator,
477                    boolean previous) {
478                    StringBundler query = null;
479    
480                    if (orderByComparator != null) {
481                            query = new StringBundler(6 +
482                                            (orderByComparator.getOrderByFields().length * 6));
483                    }
484                    else {
485                            query = new StringBundler(3);
486                    }
487    
488                    query.append(_SQL_SELECT_ASSETTAG_WHERE);
489    
490                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
491    
492                    if (orderByComparator != null) {
493                            String[] orderByFields = orderByComparator.getOrderByFields();
494    
495                            if (orderByFields.length > 0) {
496                                    query.append(WHERE_AND);
497                            }
498    
499                            for (int i = 0; i < orderByFields.length; i++) {
500                                    query.append(_ORDER_BY_ENTITY_ALIAS);
501                                    query.append(orderByFields[i]);
502    
503                                    if ((i + 1) < orderByFields.length) {
504                                            if (orderByComparator.isAscending() ^ previous) {
505                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
506                                            }
507                                            else {
508                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
509                                            }
510                                    }
511                                    else {
512                                            if (orderByComparator.isAscending() ^ previous) {
513                                                    query.append(WHERE_GREATER_THAN);
514                                            }
515                                            else {
516                                                    query.append(WHERE_LESSER_THAN);
517                                            }
518                                    }
519                            }
520    
521                            query.append(ORDER_BY_CLAUSE);
522    
523                            for (int i = 0; i < orderByFields.length; i++) {
524                                    query.append(_ORDER_BY_ENTITY_ALIAS);
525                                    query.append(orderByFields[i]);
526    
527                                    if ((i + 1) < orderByFields.length) {
528                                            if (orderByComparator.isAscending() ^ previous) {
529                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
530                                            }
531                                            else {
532                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
533                                            }
534                                    }
535                                    else {
536                                            if (orderByComparator.isAscending() ^ previous) {
537                                                    query.append(ORDER_BY_ASC);
538                                            }
539                                            else {
540                                                    query.append(ORDER_BY_DESC);
541                                            }
542                                    }
543                            }
544                    }
545    
546                    else {
547                            query.append(AssetTagModelImpl.ORDER_BY_JPQL);
548                    }
549    
550                    String sql = query.toString();
551    
552                    Query q = session.createQuery(sql);
553    
554                    q.setFirstResult(0);
555                    q.setMaxResults(2);
556    
557                    QueryPos qPos = QueryPos.getInstance(q);
558    
559                    qPos.add(groupId);
560    
561                    if (orderByComparator != null) {
562                            Object[] values = orderByComparator.getOrderByValues(assetTag);
563    
564                            for (Object value : values) {
565                                    qPos.add(value);
566                            }
567                    }
568    
569                    List<AssetTag> list = q.list();
570    
571                    if (list.size() == 2) {
572                            return list.get(1);
573                    }
574                    else {
575                            return null;
576                    }
577            }
578    
579            public List<AssetTag> filterFindByGroupId(long groupId)
580                    throws SystemException {
581                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
582                            QueryUtil.ALL_POS, null);
583            }
584    
585            public List<AssetTag> filterFindByGroupId(long groupId, int start, int end)
586                    throws SystemException {
587                    return filterFindByGroupId(groupId, start, end, null);
588            }
589    
590            public List<AssetTag> filterFindByGroupId(long groupId, int start, int end,
591                    OrderByComparator orderByComparator) throws SystemException {
592                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
593                            return findByGroupId(groupId, start, end, orderByComparator);
594                    }
595    
596                    Session session = null;
597    
598                    try {
599                            session = openSession();
600    
601                            StringBundler query = null;
602    
603                            if (orderByComparator != null) {
604                                    query = new StringBundler(3 +
605                                                    (orderByComparator.getOrderByFields().length * 3));
606                            }
607                            else {
608                                    query = new StringBundler(3);
609                            }
610    
611                            query.append(_FILTER_SQL_SELECT_ASSETTAG_WHERE);
612    
613                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
614    
615                            if (orderByComparator != null) {
616                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
617                                            orderByComparator);
618                            }
619    
620                            else {
621                                    query.append(AssetTagModelImpl.ORDER_BY_JPQL);
622                            }
623    
624                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
625                                            AssetTag.class.getName(), _FILTER_COLUMN_PK,
626                                            _FILTER_COLUMN_USERID, groupId);
627    
628                            SQLQuery q = session.createSQLQuery(sql);
629    
630                            q.addEntity(_FILTER_ENTITY_ALIAS, AssetTagImpl.class);
631    
632                            QueryPos qPos = QueryPos.getInstance(q);
633    
634                            qPos.add(groupId);
635    
636                            return (List<AssetTag>)QueryUtil.list(q, getDialect(), start, end);
637                    }
638                    catch (Exception e) {
639                            throw processException(e);
640                    }
641                    finally {
642                            closeSession(session);
643                    }
644            }
645    
646            public List<AssetTag> findAll() throws SystemException {
647                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
648            }
649    
650            public List<AssetTag> findAll(int start, int end) throws SystemException {
651                    return findAll(start, end, null);
652            }
653    
654            public List<AssetTag> findAll(int start, int end,
655                    OrderByComparator orderByComparator) throws SystemException {
656                    Object[] finderArgs = new Object[] {
657                                    String.valueOf(start), String.valueOf(end),
658                                    String.valueOf(orderByComparator)
659                            };
660    
661                    List<AssetTag> list = (List<AssetTag>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
662                                    finderArgs, this);
663    
664                    if (list == null) {
665                            Session session = null;
666    
667                            try {
668                                    session = openSession();
669    
670                                    StringBundler query = null;
671                                    String sql = null;
672    
673                                    if (orderByComparator != null) {
674                                            query = new StringBundler(2 +
675                                                            (orderByComparator.getOrderByFields().length * 3));
676    
677                                            query.append(_SQL_SELECT_ASSETTAG);
678    
679                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
680                                                    orderByComparator);
681    
682                                            sql = query.toString();
683                                    }
684                                    else {
685                                            sql = _SQL_SELECT_ASSETTAG.concat(AssetTagModelImpl.ORDER_BY_JPQL);
686                                    }
687    
688                                    Query q = session.createQuery(sql);
689    
690                                    if (orderByComparator == null) {
691                                            list = (List<AssetTag>)QueryUtil.list(q, getDialect(),
692                                                            start, end, false);
693    
694                                            Collections.sort(list);
695                                    }
696                                    else {
697                                            list = (List<AssetTag>)QueryUtil.list(q, getDialect(),
698                                                            start, end);
699                                    }
700                            }
701                            catch (Exception e) {
702                                    throw processException(e);
703                            }
704                            finally {
705                                    if (list == null) {
706                                            list = new ArrayList<AssetTag>();
707                                    }
708    
709                                    cacheResult(list);
710    
711                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
712    
713                                    closeSession(session);
714                            }
715                    }
716    
717                    return list;
718            }
719    
720            public void removeByGroupId(long groupId) throws SystemException {
721                    for (AssetTag assetTag : findByGroupId(groupId)) {
722                            remove(assetTag);
723                    }
724            }
725    
726            public void removeAll() throws SystemException {
727                    for (AssetTag assetTag : findAll()) {
728                            remove(assetTag);
729                    }
730            }
731    
732            public int countByGroupId(long groupId) throws SystemException {
733                    Object[] finderArgs = new Object[] { groupId };
734    
735                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
736                                    finderArgs, this);
737    
738                    if (count == null) {
739                            Session session = null;
740    
741                            try {
742                                    session = openSession();
743    
744                                    StringBundler query = new StringBundler(2);
745    
746                                    query.append(_SQL_COUNT_ASSETTAG_WHERE);
747    
748                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
749    
750                                    String sql = query.toString();
751    
752                                    Query q = session.createQuery(sql);
753    
754                                    QueryPos qPos = QueryPos.getInstance(q);
755    
756                                    qPos.add(groupId);
757    
758                                    count = (Long)q.uniqueResult();
759                            }
760                            catch (Exception e) {
761                                    throw processException(e);
762                            }
763                            finally {
764                                    if (count == null) {
765                                            count = Long.valueOf(0);
766                                    }
767    
768                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
769                                            finderArgs, count);
770    
771                                    closeSession(session);
772                            }
773                    }
774    
775                    return count.intValue();
776            }
777    
778            public int filterCountByGroupId(long groupId) throws SystemException {
779                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
780                            return countByGroupId(groupId);
781                    }
782    
783                    Session session = null;
784    
785                    try {
786                            session = openSession();
787    
788                            StringBundler query = new StringBundler(2);
789    
790                            query.append(_FILTER_SQL_COUNT_ASSETTAG_WHERE);
791    
792                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
793    
794                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
795                                            AssetTag.class.getName(), _FILTER_COLUMN_PK,
796                                            _FILTER_COLUMN_USERID, groupId);
797    
798                            SQLQuery q = session.createSQLQuery(sql);
799    
800                            q.addScalar(COUNT_COLUMN_NAME,
801                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
802    
803                            QueryPos qPos = QueryPos.getInstance(q);
804    
805                            qPos.add(groupId);
806    
807                            Long count = (Long)q.uniqueResult();
808    
809                            return count.intValue();
810                    }
811                    catch (Exception e) {
812                            throw processException(e);
813                    }
814                    finally {
815                            closeSession(session);
816                    }
817            }
818    
819            public int countAll() throws SystemException {
820                    Object[] finderArgs = new Object[0];
821    
822                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
823                                    finderArgs, this);
824    
825                    if (count == null) {
826                            Session session = null;
827    
828                            try {
829                                    session = openSession();
830    
831                                    Query q = session.createQuery(_SQL_COUNT_ASSETTAG);
832    
833                                    count = (Long)q.uniqueResult();
834                            }
835                            catch (Exception e) {
836                                    throw processException(e);
837                            }
838                            finally {
839                                    if (count == null) {
840                                            count = Long.valueOf(0);
841                                    }
842    
843                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
844                                            count);
845    
846                                    closeSession(session);
847                            }
848                    }
849    
850                    return count.intValue();
851            }
852    
853            public List<com.liferay.portlet.asset.model.AssetEntry> getAssetEntries(
854                    long pk) throws SystemException {
855                    return getAssetEntries(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
856            }
857    
858            public List<com.liferay.portlet.asset.model.AssetEntry> getAssetEntries(
859                    long pk, int start, int end) throws SystemException {
860                    return getAssetEntries(pk, start, end, null);
861            }
862    
863            public static final FinderPath FINDER_PATH_GET_ASSETENTRIES = new FinderPath(com.liferay.portlet.asset.model.impl.AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
864                            AssetTagModelImpl.FINDER_CACHE_ENABLED_ASSETENTRIES_ASSETTAGS,
865                            AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME,
866                            "getAssetEntries",
867                            new String[] {
868                                    Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
869                                    "com.liferay.portal.kernel.util.OrderByComparator"
870                            });
871    
872            public List<com.liferay.portlet.asset.model.AssetEntry> getAssetEntries(
873                    long pk, int start, int end, OrderByComparator orderByComparator)
874                    throws SystemException {
875                    Object[] finderArgs = new Object[] {
876                                    pk, String.valueOf(start), String.valueOf(end),
877                                    String.valueOf(orderByComparator)
878                            };
879    
880                    List<com.liferay.portlet.asset.model.AssetEntry> list = (List<com.liferay.portlet.asset.model.AssetEntry>)FinderCacheUtil.getResult(FINDER_PATH_GET_ASSETENTRIES,
881                                    finderArgs, this);
882    
883                    if (list == null) {
884                            Session session = null;
885    
886                            try {
887                                    session = openSession();
888    
889                                    String sql = null;
890    
891                                    if (orderByComparator != null) {
892                                            sql = _SQL_GETASSETENTRIES.concat(ORDER_BY_CLAUSE)
893                                                                                              .concat(orderByComparator.getOrderBy());
894                                    }
895                                    else {
896                                            sql = _SQL_GETASSETENTRIES;
897                                    }
898    
899                                    SQLQuery q = session.createSQLQuery(sql);
900    
901                                    q.addEntity("AssetEntry",
902                                            com.liferay.portlet.asset.model.impl.AssetEntryImpl.class);
903    
904                                    QueryPos qPos = QueryPos.getInstance(q);
905    
906                                    qPos.add(pk);
907    
908                                    list = (List<com.liferay.portlet.asset.model.AssetEntry>)QueryUtil.list(q,
909                                                    getDialect(), start, end);
910                            }
911                            catch (Exception e) {
912                                    throw processException(e);
913                            }
914                            finally {
915                                    if (list == null) {
916                                            list = new ArrayList<com.liferay.portlet.asset.model.AssetEntry>();
917                                    }
918    
919                                    assetEntryPersistence.cacheResult(list);
920    
921                                    FinderCacheUtil.putResult(FINDER_PATH_GET_ASSETENTRIES,
922                                            finderArgs, list);
923    
924                                    closeSession(session);
925                            }
926                    }
927    
928                    return list;
929            }
930    
931            public static final FinderPath FINDER_PATH_GET_ASSETENTRIES_SIZE = new FinderPath(com.liferay.portlet.asset.model.impl.AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
932                            AssetTagModelImpl.FINDER_CACHE_ENABLED_ASSETENTRIES_ASSETTAGS,
933                            AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME,
934                            "getAssetEntriesSize", new String[] { Long.class.getName() });
935    
936            public int getAssetEntriesSize(long pk) throws SystemException {
937                    Object[] finderArgs = new Object[] { pk };
938    
939                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_ASSETENTRIES_SIZE,
940                                    finderArgs, this);
941    
942                    if (count == null) {
943                            Session session = null;
944    
945                            try {
946                                    session = openSession();
947    
948                                    SQLQuery q = session.createSQLQuery(_SQL_GETASSETENTRIESSIZE);
949    
950                                    q.addScalar(COUNT_COLUMN_NAME,
951                                            com.liferay.portal.kernel.dao.orm.Type.LONG);
952    
953                                    QueryPos qPos = QueryPos.getInstance(q);
954    
955                                    qPos.add(pk);
956    
957                                    count = (Long)q.uniqueResult();
958                            }
959                            catch (Exception e) {
960                                    throw processException(e);
961                            }
962                            finally {
963                                    if (count == null) {
964                                            count = Long.valueOf(0);
965                                    }
966    
967                                    FinderCacheUtil.putResult(FINDER_PATH_GET_ASSETENTRIES_SIZE,
968                                            finderArgs, count);
969    
970                                    closeSession(session);
971                            }
972                    }
973    
974                    return count.intValue();
975            }
976    
977            public static final FinderPath FINDER_PATH_CONTAINS_ASSETENTRY = new FinderPath(com.liferay.portlet.asset.model.impl.AssetEntryModelImpl.ENTITY_CACHE_ENABLED,
978                            AssetTagModelImpl.FINDER_CACHE_ENABLED_ASSETENTRIES_ASSETTAGS,
979                            AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME,
980                            "containsAssetEntry",
981                            new String[] { Long.class.getName(), Long.class.getName() });
982    
983            public boolean containsAssetEntry(long pk, long assetEntryPK)
984                    throws SystemException {
985                    Object[] finderArgs = new Object[] { pk, assetEntryPK };
986    
987                    Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_ASSETENTRY,
988                                    finderArgs, this);
989    
990                    if (value == null) {
991                            try {
992                                    value = Boolean.valueOf(containsAssetEntry.contains(pk,
993                                                            assetEntryPK));
994                            }
995                            catch (Exception e) {
996                                    throw processException(e);
997                            }
998                            finally {
999                                    if (value == null) {
1000                                            value = Boolean.FALSE;
1001                                    }
1002    
1003                                    FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_ASSETENTRY,
1004                                            finderArgs, value);
1005                            }
1006                    }
1007    
1008                    return value.booleanValue();
1009            }
1010    
1011            public boolean containsAssetEntries(long pk) throws SystemException {
1012                    if (getAssetEntriesSize(pk) > 0) {
1013                            return true;
1014                    }
1015                    else {
1016                            return false;
1017                    }
1018            }
1019    
1020            public void addAssetEntry(long pk, long assetEntryPK)
1021                    throws SystemException {
1022                    try {
1023                            addAssetEntry.add(pk, assetEntryPK);
1024                    }
1025                    catch (Exception e) {
1026                            throw processException(e);
1027                    }
1028                    finally {
1029                            FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
1030                    }
1031            }
1032    
1033            public void addAssetEntry(long pk,
1034                    com.liferay.portlet.asset.model.AssetEntry assetEntry)
1035                    throws SystemException {
1036                    try {
1037                            addAssetEntry.add(pk, assetEntry.getPrimaryKey());
1038                    }
1039                    catch (Exception e) {
1040                            throw processException(e);
1041                    }
1042                    finally {
1043                            FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
1044                    }
1045            }
1046    
1047            public void addAssetEntries(long pk, long[] assetEntryPKs)
1048                    throws SystemException {
1049                    try {
1050                            for (long assetEntryPK : assetEntryPKs) {
1051                                    addAssetEntry.add(pk, assetEntryPK);
1052                            }
1053                    }
1054                    catch (Exception e) {
1055                            throw processException(e);
1056                    }
1057                    finally {
1058                            FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
1059                    }
1060            }
1061    
1062            public void addAssetEntries(long pk,
1063                    List<com.liferay.portlet.asset.model.AssetEntry> assetEntries)
1064                    throws SystemException {
1065                    try {
1066                            for (com.liferay.portlet.asset.model.AssetEntry assetEntry : assetEntries) {
1067                                    addAssetEntry.add(pk, assetEntry.getPrimaryKey());
1068                            }
1069                    }
1070                    catch (Exception e) {
1071                            throw processException(e);
1072                    }
1073                    finally {
1074                            FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
1075                    }
1076            }
1077    
1078            public void clearAssetEntries(long pk) throws SystemException {
1079                    try {
1080                            clearAssetEntries.clear(pk);
1081                    }
1082                    catch (Exception e) {
1083                            throw processException(e);
1084                    }
1085                    finally {
1086                            FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
1087                    }
1088            }
1089    
1090            public void removeAssetEntry(long pk, long assetEntryPK)
1091                    throws SystemException {
1092                    try {
1093                            removeAssetEntry.remove(pk, assetEntryPK);
1094                    }
1095                    catch (Exception e) {
1096                            throw processException(e);
1097                    }
1098                    finally {
1099                            FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
1100                    }
1101            }
1102    
1103            public void removeAssetEntry(long pk,
1104                    com.liferay.portlet.asset.model.AssetEntry assetEntry)
1105                    throws SystemException {
1106                    try {
1107                            removeAssetEntry.remove(pk, assetEntry.getPrimaryKey());
1108                    }
1109                    catch (Exception e) {
1110                            throw processException(e);
1111                    }
1112                    finally {
1113                            FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
1114                    }
1115            }
1116    
1117            public void removeAssetEntries(long pk, long[] assetEntryPKs)
1118                    throws SystemException {
1119                    try {
1120                            for (long assetEntryPK : assetEntryPKs) {
1121                                    removeAssetEntry.remove(pk, assetEntryPK);
1122                            }
1123                    }
1124                    catch (Exception e) {
1125                            throw processException(e);
1126                    }
1127                    finally {
1128                            FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
1129                    }
1130            }
1131    
1132            public void removeAssetEntries(long pk,
1133                    List<com.liferay.portlet.asset.model.AssetEntry> assetEntries)
1134                    throws SystemException {
1135                    try {
1136                            for (com.liferay.portlet.asset.model.AssetEntry assetEntry : assetEntries) {
1137                                    removeAssetEntry.remove(pk, assetEntry.getPrimaryKey());
1138                            }
1139                    }
1140                    catch (Exception e) {
1141                            throw processException(e);
1142                    }
1143                    finally {
1144                            FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
1145                    }
1146            }
1147    
1148            public void setAssetEntries(long pk, long[] assetEntryPKs)
1149                    throws SystemException {
1150                    try {
1151                            Set<Long> assetEntryPKSet = SetUtil.fromArray(assetEntryPKs);
1152    
1153                            List<com.liferay.portlet.asset.model.AssetEntry> assetEntries = getAssetEntries(pk);
1154    
1155                            for (com.liferay.portlet.asset.model.AssetEntry assetEntry : assetEntries) {
1156                                    if (!assetEntryPKSet.contains(assetEntry.getPrimaryKey())) {
1157                                            removeAssetEntry.remove(pk, assetEntry.getPrimaryKey());
1158                                    }
1159                                    else {
1160                                            assetEntryPKSet.remove(assetEntry.getPrimaryKey());
1161                                    }
1162                            }
1163    
1164                            for (Long assetEntryPK : assetEntryPKSet) {
1165                                    addAssetEntry.add(pk, assetEntryPK);
1166                            }
1167                    }
1168                    catch (Exception e) {
1169                            throw processException(e);
1170                    }
1171                    finally {
1172                            FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
1173                    }
1174            }
1175    
1176            public void setAssetEntries(long pk,
1177                    List<com.liferay.portlet.asset.model.AssetEntry> assetEntries)
1178                    throws SystemException {
1179                    try {
1180                            long[] assetEntryPKs = new long[assetEntries.size()];
1181    
1182                            for (int i = 0; i < assetEntries.size(); i++) {
1183                                    com.liferay.portlet.asset.model.AssetEntry assetEntry = assetEntries.get(i);
1184    
1185                                    assetEntryPKs[i] = assetEntry.getPrimaryKey();
1186                            }
1187    
1188                            setAssetEntries(pk, assetEntryPKs);
1189                    }
1190                    catch (Exception e) {
1191                            throw processException(e);
1192                    }
1193                    finally {
1194                            FinderCacheUtil.clearCache(AssetTagModelImpl.MAPPING_TABLE_ASSETENTRIES_ASSETTAGS_NAME);
1195                    }
1196            }
1197    
1198            public void afterPropertiesSet() {
1199                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1200                                            com.liferay.portal.util.PropsUtil.get(
1201                                                    "value.object.listener.com.liferay.portlet.asset.model.AssetTag")));
1202    
1203                    if (listenerClassNames.length > 0) {
1204                            try {
1205                                    List<ModelListener<AssetTag>> listenersList = new ArrayList<ModelListener<AssetTag>>();
1206    
1207                                    for (String listenerClassName : listenerClassNames) {
1208                                            listenersList.add((ModelListener<AssetTag>)InstanceFactory.newInstance(
1209                                                            listenerClassName));
1210                                    }
1211    
1212                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1213                            }
1214                            catch (Exception e) {
1215                                    _log.error(e);
1216                            }
1217                    }
1218    
1219                    containsAssetEntry = new ContainsAssetEntry(this);
1220    
1221                    addAssetEntry = new AddAssetEntry(this);
1222                    clearAssetEntries = new ClearAssetEntries(this);
1223                    removeAssetEntry = new RemoveAssetEntry(this);
1224            }
1225    
1226            @BeanReference(type = AssetCategoryPersistence.class)
1227            protected AssetCategoryPersistence assetCategoryPersistence;
1228            @BeanReference(type = AssetCategoryPropertyPersistence.class)
1229            protected AssetCategoryPropertyPersistence assetCategoryPropertyPersistence;
1230            @BeanReference(type = AssetEntryPersistence.class)
1231            protected AssetEntryPersistence assetEntryPersistence;
1232            @BeanReference(type = AssetLinkPersistence.class)
1233            protected AssetLinkPersistence assetLinkPersistence;
1234            @BeanReference(type = AssetTagPersistence.class)
1235            protected AssetTagPersistence assetTagPersistence;
1236            @BeanReference(type = AssetTagPropertyPersistence.class)
1237            protected AssetTagPropertyPersistence assetTagPropertyPersistence;
1238            @BeanReference(type = AssetTagStatsPersistence.class)
1239            protected AssetTagStatsPersistence assetTagStatsPersistence;
1240            @BeanReference(type = AssetVocabularyPersistence.class)
1241            protected AssetVocabularyPersistence assetVocabularyPersistence;
1242            @BeanReference(type = ResourcePersistence.class)
1243            protected ResourcePersistence resourcePersistence;
1244            @BeanReference(type = UserPersistence.class)
1245            protected UserPersistence userPersistence;
1246            protected ContainsAssetEntry containsAssetEntry;
1247            protected AddAssetEntry addAssetEntry;
1248            protected ClearAssetEntries clearAssetEntries;
1249            protected RemoveAssetEntry removeAssetEntry;
1250    
1251            protected class ContainsAssetEntry {
1252                    protected ContainsAssetEntry(AssetTagPersistenceImpl persistenceImpl) {
1253                            super();
1254    
1255                            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
1256                                            _SQL_CONTAINSASSETENTRY,
1257                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
1258                                            RowMapper.COUNT);
1259                    }
1260    
1261                    protected boolean contains(long tagId, long entryId) {
1262                            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
1263                                                    new Long(tagId), new Long(entryId)
1264                                            });
1265    
1266                            if (results.size() > 0) {
1267                                    Integer count = results.get(0);
1268    
1269                                    if (count.intValue() > 0) {
1270                                            return true;
1271                                    }
1272                            }
1273    
1274                            return false;
1275                    }
1276    
1277                    private MappingSqlQuery<Integer> _mappingSqlQuery;
1278            }
1279    
1280            protected class AddAssetEntry {
1281                    protected AddAssetEntry(AssetTagPersistenceImpl persistenceImpl) {
1282                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1283                                            "INSERT INTO AssetEntries_AssetTags (tagId, entryId) VALUES (?, ?)",
1284                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
1285                            _persistenceImpl = persistenceImpl;
1286                    }
1287    
1288                    protected void add(long tagId, long entryId) throws SystemException {
1289                            if (!_persistenceImpl.containsAssetEntry.contains(tagId, entryId)) {
1290                                    ModelListener<com.liferay.portlet.asset.model.AssetEntry>[] assetEntryListeners =
1291                                            assetEntryPersistence.getListeners();
1292    
1293                                    for (ModelListener<AssetTag> listener : listeners) {
1294                                            listener.onBeforeAddAssociation(tagId,
1295                                                    com.liferay.portlet.asset.model.AssetEntry.class.getName(),
1296                                                    entryId);
1297                                    }
1298    
1299                                    for (ModelListener<com.liferay.portlet.asset.model.AssetEntry> listener : assetEntryListeners) {
1300                                            listener.onBeforeAddAssociation(entryId,
1301                                                    AssetTag.class.getName(), tagId);
1302                                    }
1303    
1304                                    _sqlUpdate.update(new Object[] {
1305                                                    new Long(tagId), new Long(entryId)
1306                                            });
1307    
1308                                    for (ModelListener<AssetTag> listener : listeners) {
1309                                            listener.onAfterAddAssociation(tagId,
1310                                                    com.liferay.portlet.asset.model.AssetEntry.class.getName(),
1311                                                    entryId);
1312                                    }
1313    
1314                                    for (ModelListener<com.liferay.portlet.asset.model.AssetEntry> listener : assetEntryListeners) {
1315                                            listener.onAfterAddAssociation(entryId,
1316                                                    AssetTag.class.getName(), tagId);
1317                                    }
1318                            }
1319                    }
1320    
1321                    private SqlUpdate _sqlUpdate;
1322                    private AssetTagPersistenceImpl _persistenceImpl;
1323            }
1324    
1325            protected class ClearAssetEntries {
1326                    protected ClearAssetEntries(AssetTagPersistenceImpl persistenceImpl) {
1327                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1328                                            "DELETE FROM AssetEntries_AssetTags WHERE tagId = ?",
1329                                            new int[] { java.sql.Types.BIGINT });
1330                    }
1331    
1332                    protected void clear(long tagId) throws SystemException {
1333                            ModelListener<com.liferay.portlet.asset.model.AssetEntry>[] assetEntryListeners =
1334                                    assetEntryPersistence.getListeners();
1335    
1336                            List<com.liferay.portlet.asset.model.AssetEntry> assetEntries = null;
1337    
1338                            if ((listeners.length > 0) || (assetEntryListeners.length > 0)) {
1339                                    assetEntries = getAssetEntries(tagId);
1340    
1341                                    for (com.liferay.portlet.asset.model.AssetEntry assetEntry : assetEntries) {
1342                                            for (ModelListener<AssetTag> listener : listeners) {
1343                                                    listener.onBeforeRemoveAssociation(tagId,
1344                                                            com.liferay.portlet.asset.model.AssetEntry.class.getName(),
1345                                                            assetEntry.getPrimaryKey());
1346                                            }
1347    
1348                                            for (ModelListener<com.liferay.portlet.asset.model.AssetEntry> listener : assetEntryListeners) {
1349                                                    listener.onBeforeRemoveAssociation(assetEntry.getPrimaryKey(),
1350                                                            AssetTag.class.getName(), tagId);
1351                                            }
1352                                    }
1353                            }
1354    
1355                            _sqlUpdate.update(new Object[] { new Long(tagId) });
1356    
1357                            if ((listeners.length > 0) || (assetEntryListeners.length > 0)) {
1358                                    for (com.liferay.portlet.asset.model.AssetEntry assetEntry : assetEntries) {
1359                                            for (ModelListener<AssetTag> listener : listeners) {
1360                                                    listener.onAfterRemoveAssociation(tagId,
1361                                                            com.liferay.portlet.asset.model.AssetEntry.class.getName(),
1362                                                            assetEntry.getPrimaryKey());
1363                                            }
1364    
1365                                            for (ModelListener<com.liferay.portlet.asset.model.AssetEntry> listener : assetEntryListeners) {
1366                                                    listener.onAfterRemoveAssociation(assetEntry.getPrimaryKey(),
1367                                                            AssetTag.class.getName(), tagId);
1368                                            }
1369                                    }
1370                            }
1371                    }
1372    
1373                    private SqlUpdate _sqlUpdate;
1374            }
1375    
1376            protected class RemoveAssetEntry {
1377                    protected RemoveAssetEntry(AssetTagPersistenceImpl persistenceImpl) {
1378                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1379                                            "DELETE FROM AssetEntries_AssetTags WHERE tagId = ? AND entryId = ?",
1380                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
1381                            _persistenceImpl = persistenceImpl;
1382                    }
1383    
1384                    protected void remove(long tagId, long entryId)
1385                            throws SystemException {
1386                            if (_persistenceImpl.containsAssetEntry.contains(tagId, entryId)) {
1387                                    ModelListener<com.liferay.portlet.asset.model.AssetEntry>[] assetEntryListeners =
1388                                            assetEntryPersistence.getListeners();
1389    
1390                                    for (ModelListener<AssetTag> listener : listeners) {
1391                                            listener.onBeforeRemoveAssociation(tagId,
1392                                                    com.liferay.portlet.asset.model.AssetEntry.class.getName(),
1393                                                    entryId);
1394                                    }
1395    
1396                                    for (ModelListener<com.liferay.portlet.asset.model.AssetEntry> listener : assetEntryListeners) {
1397                                            listener.onBeforeRemoveAssociation(entryId,
1398                                                    AssetTag.class.getName(), tagId);
1399                                    }
1400    
1401                                    _sqlUpdate.update(new Object[] {
1402                                                    new Long(tagId), new Long(entryId)
1403                                            });
1404    
1405                                    for (ModelListener<AssetTag> listener : listeners) {
1406                                            listener.onAfterRemoveAssociation(tagId,
1407                                                    com.liferay.portlet.asset.model.AssetEntry.class.getName(),
1408                                                    entryId);
1409                                    }
1410    
1411                                    for (ModelListener<com.liferay.portlet.asset.model.AssetEntry> listener : assetEntryListeners) {
1412                                            listener.onAfterRemoveAssociation(entryId,
1413                                                    AssetTag.class.getName(), tagId);
1414                                    }
1415                            }
1416                    }
1417    
1418                    private SqlUpdate _sqlUpdate;
1419                    private AssetTagPersistenceImpl _persistenceImpl;
1420            }
1421    
1422            private static final String _SQL_SELECT_ASSETTAG = "SELECT assetTag FROM AssetTag assetTag";
1423            private static final String _SQL_SELECT_ASSETTAG_WHERE = "SELECT assetTag FROM AssetTag assetTag WHERE ";
1424            private static final String _SQL_COUNT_ASSETTAG = "SELECT COUNT(assetTag) FROM AssetTag assetTag";
1425            private static final String _SQL_COUNT_ASSETTAG_WHERE = "SELECT COUNT(assetTag) FROM AssetTag assetTag WHERE ";
1426            private static final String _SQL_GETASSETENTRIES = "SELECT {AssetEntry.*} FROM AssetEntry INNER JOIN AssetEntries_AssetTags ON (AssetEntries_AssetTags.entryId = AssetEntry.entryId) WHERE (AssetEntries_AssetTags.tagId = ?)";
1427            private static final String _SQL_GETASSETENTRIESSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM AssetEntries_AssetTags WHERE tagId = ?";
1428            private static final String _SQL_CONTAINSASSETENTRY = "SELECT COUNT(*) AS COUNT_VALUE FROM AssetEntries_AssetTags WHERE tagId = ? AND entryId = ?";
1429            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "assetTag.groupId = ?";
1430            private static final String _FILTER_SQL_SELECT_ASSETTAG_WHERE = "SELECT DISTINCT {assetTag.*} FROM AssetTag assetTag WHERE ";
1431            private static final String _FILTER_SQL_COUNT_ASSETTAG_WHERE = "SELECT COUNT(DISTINCT assetTag.tagId) AS COUNT_VALUE FROM AssetTag assetTag WHERE ";
1432            private static final String _FILTER_COLUMN_PK = "assetTag.tagId";
1433            private static final String _FILTER_COLUMN_USERID = "assetTag.userId";
1434            private static final String _FILTER_ENTITY_ALIAS = "assetTag";
1435            private static final String _ORDER_BY_ENTITY_ALIAS = "assetTag.";
1436            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AssetTag exists with the primary key ";
1437            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AssetTag exists with the key {";
1438            private static Log _log = LogFactoryUtil.getLog(AssetTagPersistenceImpl.class);
1439    }