1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.tags.service.persistence;
24  
25  import com.liferay.portal.SystemException;
26  import com.liferay.portal.kernel.annotation.BeanReference;
27  import com.liferay.portal.kernel.cache.CacheRegistry;
28  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
29  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
30  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
31  import com.liferay.portal.kernel.dao.orm.FinderPath;
32  import com.liferay.portal.kernel.dao.orm.Query;
33  import com.liferay.portal.kernel.dao.orm.QueryPos;
34  import com.liferay.portal.kernel.dao.orm.QueryUtil;
35  import com.liferay.portal.kernel.dao.orm.Session;
36  import com.liferay.portal.kernel.log.Log;
37  import com.liferay.portal.kernel.log.LogFactoryUtil;
38  import com.liferay.portal.kernel.util.GetterUtil;
39  import com.liferay.portal.kernel.util.OrderByComparator;
40  import com.liferay.portal.kernel.util.StringPool;
41  import com.liferay.portal.kernel.util.StringUtil;
42  import com.liferay.portal.kernel.util.Validator;
43  import com.liferay.portal.model.ModelListener;
44  import com.liferay.portal.service.persistence.BatchSessionUtil;
45  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
46  
47  import com.liferay.portlet.tags.NoSuchPropertyException;
48  import com.liferay.portlet.tags.model.TagsProperty;
49  import com.liferay.portlet.tags.model.impl.TagsPropertyImpl;
50  import com.liferay.portlet.tags.model.impl.TagsPropertyModelImpl;
51  
52  import java.util.ArrayList;
53  import java.util.Collections;
54  import java.util.List;
55  
56  /**
57   * <a href="TagsPropertyPersistenceImpl.java.html"><b><i>View Source</i></b></a>
58   *
59   * <p>
60   * ServiceBuilder generated this class. Modifications in this class will be
61   * overwritten the next time is generated.
62   * </p>
63   *
64   * @author    Brian Wing Shun Chan
65   * @see       TagsPropertyPersistence
66   * @see       TagsPropertyUtil
67   * @generated
68   */
69  public class TagsPropertyPersistenceImpl extends BasePersistenceImpl
70      implements TagsPropertyPersistence {
71      public static final String FINDER_CLASS_NAME_ENTITY = TagsPropertyImpl.class.getName();
72      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
73          ".List";
74      public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(TagsPropertyModelImpl.ENTITY_CACHE_ENABLED,
75              TagsPropertyModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
76              "findByCompanyId", new String[] { Long.class.getName() });
77      public static final FinderPath FINDER_PATH_FIND_BY_OBC_COMPANYID = new FinderPath(TagsPropertyModelImpl.ENTITY_CACHE_ENABLED,
78              TagsPropertyModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
79              "findByCompanyId",
80              new String[] {
81                  Long.class.getName(),
82                  
83              "java.lang.Integer", "java.lang.Integer",
84                  "com.liferay.portal.kernel.util.OrderByComparator"
85              });
86      public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(TagsPropertyModelImpl.ENTITY_CACHE_ENABLED,
87              TagsPropertyModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
88              "countByCompanyId", new String[] { Long.class.getName() });
89      public static final FinderPath FINDER_PATH_FIND_BY_ENTRYID = new FinderPath(TagsPropertyModelImpl.ENTITY_CACHE_ENABLED,
90              TagsPropertyModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
91              "findByEntryId", new String[] { Long.class.getName() });
92      public static final FinderPath FINDER_PATH_FIND_BY_OBC_ENTRYID = new FinderPath(TagsPropertyModelImpl.ENTITY_CACHE_ENABLED,
93              TagsPropertyModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
94              "findByEntryId",
95              new String[] {
96                  Long.class.getName(),
97                  
98              "java.lang.Integer", "java.lang.Integer",
99                  "com.liferay.portal.kernel.util.OrderByComparator"
100             });
101     public static final FinderPath FINDER_PATH_COUNT_BY_ENTRYID = new FinderPath(TagsPropertyModelImpl.ENTITY_CACHE_ENABLED,
102             TagsPropertyModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
103             "countByEntryId", new String[] { Long.class.getName() });
104     public static final FinderPath FINDER_PATH_FIND_BY_C_K = new FinderPath(TagsPropertyModelImpl.ENTITY_CACHE_ENABLED,
105             TagsPropertyModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
106             "findByC_K",
107             new String[] { Long.class.getName(), String.class.getName() });
108     public static final FinderPath FINDER_PATH_FIND_BY_OBC_C_K = new FinderPath(TagsPropertyModelImpl.ENTITY_CACHE_ENABLED,
109             TagsPropertyModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
110             "findByC_K",
111             new String[] {
112                 Long.class.getName(), String.class.getName(),
113                 
114             "java.lang.Integer", "java.lang.Integer",
115                 "com.liferay.portal.kernel.util.OrderByComparator"
116             });
117     public static final FinderPath FINDER_PATH_COUNT_BY_C_K = new FinderPath(TagsPropertyModelImpl.ENTITY_CACHE_ENABLED,
118             TagsPropertyModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
119             "countByC_K",
120             new String[] { Long.class.getName(), String.class.getName() });
121     public static final FinderPath FINDER_PATH_FETCH_BY_E_K = new FinderPath(TagsPropertyModelImpl.ENTITY_CACHE_ENABLED,
122             TagsPropertyModelImpl.FINDER_CACHE_ENABLED,
123             FINDER_CLASS_NAME_ENTITY, "fetchByE_K",
124             new String[] { Long.class.getName(), String.class.getName() });
125     public static final FinderPath FINDER_PATH_COUNT_BY_E_K = new FinderPath(TagsPropertyModelImpl.ENTITY_CACHE_ENABLED,
126             TagsPropertyModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
127             "countByE_K",
128             new String[] { Long.class.getName(), String.class.getName() });
129     public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(TagsPropertyModelImpl.ENTITY_CACHE_ENABLED,
130             TagsPropertyModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
131             "findAll", new String[0]);
132     public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(TagsPropertyModelImpl.ENTITY_CACHE_ENABLED,
133             TagsPropertyModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
134             "countAll", new String[0]);
135 
136     public void cacheResult(TagsProperty tagsProperty) {
137         EntityCacheUtil.putResult(TagsPropertyModelImpl.ENTITY_CACHE_ENABLED,
138             TagsPropertyImpl.class, tagsProperty.getPrimaryKey(), tagsProperty);
139 
140         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_E_K,
141             new Object[] {
142                 new Long(tagsProperty.getEntryId()),
143                 
144             tagsProperty.getKey()
145             }, tagsProperty);
146     }
147 
148     public void cacheResult(List<TagsProperty> tagsProperties) {
149         for (TagsProperty tagsProperty : tagsProperties) {
150             if (EntityCacheUtil.getResult(
151                         TagsPropertyModelImpl.ENTITY_CACHE_ENABLED,
152                         TagsPropertyImpl.class, tagsProperty.getPrimaryKey(),
153                         this) == null) {
154                 cacheResult(tagsProperty);
155             }
156         }
157     }
158 
159     public void clearCache() {
160         CacheRegistry.clear(TagsPropertyImpl.class.getName());
161         EntityCacheUtil.clearCache(TagsPropertyImpl.class.getName());
162         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
163         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
164     }
165 
166     public TagsProperty create(long propertyId) {
167         TagsProperty tagsProperty = new TagsPropertyImpl();
168 
169         tagsProperty.setNew(true);
170         tagsProperty.setPrimaryKey(propertyId);
171 
172         return tagsProperty;
173     }
174 
175     public TagsProperty remove(long propertyId)
176         throws NoSuchPropertyException, SystemException {
177         Session session = null;
178 
179         try {
180             session = openSession();
181 
182             TagsProperty tagsProperty = (TagsProperty)session.get(TagsPropertyImpl.class,
183                     new Long(propertyId));
184 
185             if (tagsProperty == null) {
186                 if (_log.isWarnEnabled()) {
187                     _log.warn("No TagsProperty exists with the primary key " +
188                         propertyId);
189                 }
190 
191                 throw new NoSuchPropertyException(
192                     "No TagsProperty exists with the primary key " +
193                     propertyId);
194             }
195 
196             return remove(tagsProperty);
197         }
198         catch (NoSuchPropertyException nsee) {
199             throw nsee;
200         }
201         catch (Exception e) {
202             throw processException(e);
203         }
204         finally {
205             closeSession(session);
206         }
207     }
208 
209     public TagsProperty remove(TagsProperty tagsProperty)
210         throws SystemException {
211         for (ModelListener<TagsProperty> listener : listeners) {
212             listener.onBeforeRemove(tagsProperty);
213         }
214 
215         tagsProperty = removeImpl(tagsProperty);
216 
217         for (ModelListener<TagsProperty> listener : listeners) {
218             listener.onAfterRemove(tagsProperty);
219         }
220 
221         return tagsProperty;
222     }
223 
224     protected TagsProperty removeImpl(TagsProperty tagsProperty)
225         throws SystemException {
226         Session session = null;
227 
228         try {
229             session = openSession();
230 
231             if (tagsProperty.isCachedModel() || BatchSessionUtil.isEnabled()) {
232                 Object staleObject = session.get(TagsPropertyImpl.class,
233                         tagsProperty.getPrimaryKeyObj());
234 
235                 if (staleObject != null) {
236                     session.evict(staleObject);
237                 }
238             }
239 
240             session.delete(tagsProperty);
241 
242             session.flush();
243         }
244         catch (Exception e) {
245             throw processException(e);
246         }
247         finally {
248             closeSession(session);
249         }
250 
251         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
252 
253         TagsPropertyModelImpl tagsPropertyModelImpl = (TagsPropertyModelImpl)tagsProperty;
254 
255         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_E_K,
256             new Object[] {
257                 new Long(tagsPropertyModelImpl.getOriginalEntryId()),
258                 
259             tagsPropertyModelImpl.getOriginalKey()
260             });
261 
262         EntityCacheUtil.removeResult(TagsPropertyModelImpl.ENTITY_CACHE_ENABLED,
263             TagsPropertyImpl.class, tagsProperty.getPrimaryKey());
264 
265         return tagsProperty;
266     }
267 
268     /**
269      * @deprecated Use {@link #update(TagsProperty, boolean merge)}.
270      */
271     public TagsProperty update(TagsProperty tagsProperty)
272         throws SystemException {
273         if (_log.isWarnEnabled()) {
274             _log.warn(
275                 "Using the deprecated update(TagsProperty tagsProperty) method. Use update(TagsProperty tagsProperty, boolean merge) instead.");
276         }
277 
278         return update(tagsProperty, false);
279     }
280 
281     /**
282      * Add, update, or merge, the entity. This method also calls the model
283      * listeners to trigger the proper events associated with adding, deleting,
284      * or updating an entity.
285      *
286      * @param  tagsProperty the entity to add, update, or merge
287      * @param  merge boolean value for whether to merge the entity. The default
288      *         value is false. Setting merge to true is more expensive and
289      *         should only be true when tagsProperty is transient. See
290      *         LEP-5473 for a detailed discussion of this method.
291      * @return the entity that was added, updated, or merged
292      */
293     public TagsProperty update(TagsProperty tagsProperty, boolean merge)
294         throws SystemException {
295         boolean isNew = tagsProperty.isNew();
296 
297         for (ModelListener<TagsProperty> listener : listeners) {
298             if (isNew) {
299                 listener.onBeforeCreate(tagsProperty);
300             }
301             else {
302                 listener.onBeforeUpdate(tagsProperty);
303             }
304         }
305 
306         tagsProperty = updateImpl(tagsProperty, merge);
307 
308         for (ModelListener<TagsProperty> listener : listeners) {
309             if (isNew) {
310                 listener.onAfterCreate(tagsProperty);
311             }
312             else {
313                 listener.onAfterUpdate(tagsProperty);
314             }
315         }
316 
317         return tagsProperty;
318     }
319 
320     public TagsProperty updateImpl(
321         com.liferay.portlet.tags.model.TagsProperty tagsProperty, boolean merge)
322         throws SystemException {
323         boolean isNew = tagsProperty.isNew();
324 
325         TagsPropertyModelImpl tagsPropertyModelImpl = (TagsPropertyModelImpl)tagsProperty;
326 
327         Session session = null;
328 
329         try {
330             session = openSession();
331 
332             BatchSessionUtil.update(session, tagsProperty, merge);
333 
334             tagsProperty.setNew(false);
335         }
336         catch (Exception e) {
337             throw processException(e);
338         }
339         finally {
340             closeSession(session);
341         }
342 
343         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
344 
345         EntityCacheUtil.putResult(TagsPropertyModelImpl.ENTITY_CACHE_ENABLED,
346             TagsPropertyImpl.class, tagsProperty.getPrimaryKey(), tagsProperty);
347 
348         if (!isNew &&
349                 ((tagsProperty.getEntryId() != tagsPropertyModelImpl.getOriginalEntryId()) ||
350                 !Validator.equals(tagsProperty.getKey(),
351                     tagsPropertyModelImpl.getOriginalKey()))) {
352             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_E_K,
353                 new Object[] {
354                     new Long(tagsPropertyModelImpl.getOriginalEntryId()),
355                     
356                 tagsPropertyModelImpl.getOriginalKey()
357                 });
358         }
359 
360         if (isNew ||
361                 ((tagsProperty.getEntryId() != tagsPropertyModelImpl.getOriginalEntryId()) ||
362                 !Validator.equals(tagsProperty.getKey(),
363                     tagsPropertyModelImpl.getOriginalKey()))) {
364             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_E_K,
365                 new Object[] {
366                     new Long(tagsProperty.getEntryId()),
367                     
368                 tagsProperty.getKey()
369                 }, tagsProperty);
370         }
371 
372         return tagsProperty;
373     }
374 
375     public TagsProperty findByPrimaryKey(long propertyId)
376         throws NoSuchPropertyException, SystemException {
377         TagsProperty tagsProperty = fetchByPrimaryKey(propertyId);
378 
379         if (tagsProperty == null) {
380             if (_log.isWarnEnabled()) {
381                 _log.warn("No TagsProperty exists with the primary key " +
382                     propertyId);
383             }
384 
385             throw new NoSuchPropertyException(
386                 "No TagsProperty exists with the primary key " + propertyId);
387         }
388 
389         return tagsProperty;
390     }
391 
392     public TagsProperty fetchByPrimaryKey(long propertyId)
393         throws SystemException {
394         TagsProperty tagsProperty = (TagsProperty)EntityCacheUtil.getResult(TagsPropertyModelImpl.ENTITY_CACHE_ENABLED,
395                 TagsPropertyImpl.class, propertyId, this);
396 
397         if (tagsProperty == null) {
398             Session session = null;
399 
400             try {
401                 session = openSession();
402 
403                 tagsProperty = (TagsProperty)session.get(TagsPropertyImpl.class,
404                         new Long(propertyId));
405             }
406             catch (Exception e) {
407                 throw processException(e);
408             }
409             finally {
410                 if (tagsProperty != null) {
411                     cacheResult(tagsProperty);
412                 }
413 
414                 closeSession(session);
415             }
416         }
417 
418         return tagsProperty;
419     }
420 
421     public List<TagsProperty> findByCompanyId(long companyId)
422         throws SystemException {
423         Object[] finderArgs = new Object[] { new Long(companyId) };
424 
425         List<TagsProperty> list = (List<TagsProperty>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
426                 finderArgs, this);
427 
428         if (list == null) {
429             Session session = null;
430 
431             try {
432                 session = openSession();
433 
434                 StringBuilder query = new StringBuilder();
435 
436                 query.append(
437                     "SELECT tagsProperty FROM TagsProperty tagsProperty WHERE ");
438 
439                 query.append("tagsProperty.companyId = ?");
440 
441                 query.append(" ");
442 
443                 query.append("ORDER BY ");
444 
445                 query.append("tagsProperty.key ASC");
446 
447                 Query q = session.createQuery(query.toString());
448 
449                 QueryPos qPos = QueryPos.getInstance(q);
450 
451                 qPos.add(companyId);
452 
453                 list = q.list();
454             }
455             catch (Exception e) {
456                 throw processException(e);
457             }
458             finally {
459                 if (list == null) {
460                     list = new ArrayList<TagsProperty>();
461                 }
462 
463                 cacheResult(list);
464 
465                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
466                     finderArgs, list);
467 
468                 closeSession(session);
469             }
470         }
471 
472         return list;
473     }
474 
475     public List<TagsProperty> findByCompanyId(long companyId, int start, int end)
476         throws SystemException {
477         return findByCompanyId(companyId, start, end, null);
478     }
479 
480     public List<TagsProperty> findByCompanyId(long companyId, int start,
481         int end, OrderByComparator obc) throws SystemException {
482         Object[] finderArgs = new Object[] {
483                 new Long(companyId),
484                 
485                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
486             };
487 
488         List<TagsProperty> list = (List<TagsProperty>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
489                 finderArgs, this);
490 
491         if (list == null) {
492             Session session = null;
493 
494             try {
495                 session = openSession();
496 
497                 StringBuilder query = new StringBuilder();
498 
499                 query.append(
500                     "SELECT tagsProperty FROM TagsProperty tagsProperty WHERE ");
501 
502                 query.append("tagsProperty.companyId = ?");
503 
504                 query.append(" ");
505 
506                 if (obc != null) {
507                     query.append("ORDER BY ");
508 
509                     String[] orderByFields = obc.getOrderByFields();
510 
511                     for (int i = 0; i < orderByFields.length; i++) {
512                         query.append("tagsProperty.");
513                         query.append(orderByFields[i]);
514 
515                         if (obc.isAscending()) {
516                             query.append(" ASC");
517                         }
518                         else {
519                             query.append(" DESC");
520                         }
521 
522                         if ((i + 1) < orderByFields.length) {
523                             query.append(", ");
524                         }
525                     }
526                 }
527 
528                 else {
529                     query.append("ORDER BY ");
530 
531                     query.append("tagsProperty.key ASC");
532                 }
533 
534                 Query q = session.createQuery(query.toString());
535 
536                 QueryPos qPos = QueryPos.getInstance(q);
537 
538                 qPos.add(companyId);
539 
540                 list = (List<TagsProperty>)QueryUtil.list(q, getDialect(),
541                         start, end);
542             }
543             catch (Exception e) {
544                 throw processException(e);
545             }
546             finally {
547                 if (list == null) {
548                     list = new ArrayList<TagsProperty>();
549                 }
550 
551                 cacheResult(list);
552 
553                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
554                     finderArgs, list);
555 
556                 closeSession(session);
557             }
558         }
559 
560         return list;
561     }
562 
563     public TagsProperty findByCompanyId_First(long companyId,
564         OrderByComparator obc) throws NoSuchPropertyException, SystemException {
565         List<TagsProperty> list = findByCompanyId(companyId, 0, 1, obc);
566 
567         if (list.isEmpty()) {
568             StringBuilder msg = new StringBuilder();
569 
570             msg.append("No TagsProperty exists with the key {");
571 
572             msg.append("companyId=" + companyId);
573 
574             msg.append(StringPool.CLOSE_CURLY_BRACE);
575 
576             throw new NoSuchPropertyException(msg.toString());
577         }
578         else {
579             return list.get(0);
580         }
581     }
582 
583     public TagsProperty findByCompanyId_Last(long companyId,
584         OrderByComparator obc) throws NoSuchPropertyException, SystemException {
585         int count = countByCompanyId(companyId);
586 
587         List<TagsProperty> list = findByCompanyId(companyId, count - 1, count,
588                 obc);
589 
590         if (list.isEmpty()) {
591             StringBuilder msg = new StringBuilder();
592 
593             msg.append("No TagsProperty exists with the key {");
594 
595             msg.append("companyId=" + companyId);
596 
597             msg.append(StringPool.CLOSE_CURLY_BRACE);
598 
599             throw new NoSuchPropertyException(msg.toString());
600         }
601         else {
602             return list.get(0);
603         }
604     }
605 
606     public TagsProperty[] findByCompanyId_PrevAndNext(long propertyId,
607         long companyId, OrderByComparator obc)
608         throws NoSuchPropertyException, SystemException {
609         TagsProperty tagsProperty = findByPrimaryKey(propertyId);
610 
611         int count = countByCompanyId(companyId);
612 
613         Session session = null;
614 
615         try {
616             session = openSession();
617 
618             StringBuilder query = new StringBuilder();
619 
620             query.append(
621                 "SELECT tagsProperty FROM TagsProperty tagsProperty WHERE ");
622 
623             query.append("tagsProperty.companyId = ?");
624 
625             query.append(" ");
626 
627             if (obc != null) {
628                 query.append("ORDER BY ");
629 
630                 String[] orderByFields = obc.getOrderByFields();
631 
632                 for (int i = 0; i < orderByFields.length; i++) {
633                     query.append("tagsProperty.");
634                     query.append(orderByFields[i]);
635 
636                     if (obc.isAscending()) {
637                         query.append(" ASC");
638                     }
639                     else {
640                         query.append(" DESC");
641                     }
642 
643                     if ((i + 1) < orderByFields.length) {
644                         query.append(", ");
645                     }
646                 }
647             }
648 
649             else {
650                 query.append("ORDER BY ");
651 
652                 query.append("tagsProperty.key ASC");
653             }
654 
655             Query q = session.createQuery(query.toString());
656 
657             QueryPos qPos = QueryPos.getInstance(q);
658 
659             qPos.add(companyId);
660 
661             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
662                     tagsProperty);
663 
664             TagsProperty[] array = new TagsPropertyImpl[3];
665 
666             array[0] = (TagsProperty)objArray[0];
667             array[1] = (TagsProperty)objArray[1];
668             array[2] = (TagsProperty)objArray[2];
669 
670             return array;
671         }
672         catch (Exception e) {
673             throw processException(e);
674         }
675         finally {
676             closeSession(session);
677         }
678     }
679 
680     public List<TagsProperty> findByEntryId(long entryId)
681         throws SystemException {
682         Object[] finderArgs = new Object[] { new Long(entryId) };
683 
684         List<TagsProperty> list = (List<TagsProperty>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_ENTRYID,
685                 finderArgs, this);
686 
687         if (list == null) {
688             Session session = null;
689 
690             try {
691                 session = openSession();
692 
693                 StringBuilder query = new StringBuilder();
694 
695                 query.append(
696                     "SELECT tagsProperty FROM TagsProperty tagsProperty WHERE ");
697 
698                 query.append("tagsProperty.entryId = ?");
699 
700                 query.append(" ");
701 
702                 query.append("ORDER BY ");
703 
704                 query.append("tagsProperty.key ASC");
705 
706                 Query q = session.createQuery(query.toString());
707 
708                 QueryPos qPos = QueryPos.getInstance(q);
709 
710                 qPos.add(entryId);
711 
712                 list = q.list();
713             }
714             catch (Exception e) {
715                 throw processException(e);
716             }
717             finally {
718                 if (list == null) {
719                     list = new ArrayList<TagsProperty>();
720                 }
721 
722                 cacheResult(list);
723 
724                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_ENTRYID,
725                     finderArgs, list);
726 
727                 closeSession(session);
728             }
729         }
730 
731         return list;
732     }
733 
734     public List<TagsProperty> findByEntryId(long entryId, int start, int end)
735         throws SystemException {
736         return findByEntryId(entryId, start, end, null);
737     }
738 
739     public List<TagsProperty> findByEntryId(long entryId, int start, int end,
740         OrderByComparator obc) throws SystemException {
741         Object[] finderArgs = new Object[] {
742                 new Long(entryId),
743                 
744                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
745             };
746 
747         List<TagsProperty> list = (List<TagsProperty>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_ENTRYID,
748                 finderArgs, this);
749 
750         if (list == null) {
751             Session session = null;
752 
753             try {
754                 session = openSession();
755 
756                 StringBuilder query = new StringBuilder();
757 
758                 query.append(
759                     "SELECT tagsProperty FROM TagsProperty tagsProperty WHERE ");
760 
761                 query.append("tagsProperty.entryId = ?");
762 
763                 query.append(" ");
764 
765                 if (obc != null) {
766                     query.append("ORDER BY ");
767 
768                     String[] orderByFields = obc.getOrderByFields();
769 
770                     for (int i = 0; i < orderByFields.length; i++) {
771                         query.append("tagsProperty.");
772                         query.append(orderByFields[i]);
773 
774                         if (obc.isAscending()) {
775                             query.append(" ASC");
776                         }
777                         else {
778                             query.append(" DESC");
779                         }
780 
781                         if ((i + 1) < orderByFields.length) {
782                             query.append(", ");
783                         }
784                     }
785                 }
786 
787                 else {
788                     query.append("ORDER BY ");
789 
790                     query.append("tagsProperty.key ASC");
791                 }
792 
793                 Query q = session.createQuery(query.toString());
794 
795                 QueryPos qPos = QueryPos.getInstance(q);
796 
797                 qPos.add(entryId);
798 
799                 list = (List<TagsProperty>)QueryUtil.list(q, getDialect(),
800                         start, end);
801             }
802             catch (Exception e) {
803                 throw processException(e);
804             }
805             finally {
806                 if (list == null) {
807                     list = new ArrayList<TagsProperty>();
808                 }
809 
810                 cacheResult(list);
811 
812                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_ENTRYID,
813                     finderArgs, list);
814 
815                 closeSession(session);
816             }
817         }
818 
819         return list;
820     }
821 
822     public TagsProperty findByEntryId_First(long entryId, OrderByComparator obc)
823         throws NoSuchPropertyException, SystemException {
824         List<TagsProperty> list = findByEntryId(entryId, 0, 1, obc);
825 
826         if (list.isEmpty()) {
827             StringBuilder msg = new StringBuilder();
828 
829             msg.append("No TagsProperty exists with the key {");
830 
831             msg.append("entryId=" + entryId);
832 
833             msg.append(StringPool.CLOSE_CURLY_BRACE);
834 
835             throw new NoSuchPropertyException(msg.toString());
836         }
837         else {
838             return list.get(0);
839         }
840     }
841 
842     public TagsProperty findByEntryId_Last(long entryId, OrderByComparator obc)
843         throws NoSuchPropertyException, SystemException {
844         int count = countByEntryId(entryId);
845 
846         List<TagsProperty> list = findByEntryId(entryId, count - 1, count, obc);
847 
848         if (list.isEmpty()) {
849             StringBuilder msg = new StringBuilder();
850 
851             msg.append("No TagsProperty exists with the key {");
852 
853             msg.append("entryId=" + entryId);
854 
855             msg.append(StringPool.CLOSE_CURLY_BRACE);
856 
857             throw new NoSuchPropertyException(msg.toString());
858         }
859         else {
860             return list.get(0);
861         }
862     }
863 
864     public TagsProperty[] findByEntryId_PrevAndNext(long propertyId,
865         long entryId, OrderByComparator obc)
866         throws NoSuchPropertyException, SystemException {
867         TagsProperty tagsProperty = findByPrimaryKey(propertyId);
868 
869         int count = countByEntryId(entryId);
870 
871         Session session = null;
872 
873         try {
874             session = openSession();
875 
876             StringBuilder query = new StringBuilder();
877 
878             query.append(
879                 "SELECT tagsProperty FROM TagsProperty tagsProperty WHERE ");
880 
881             query.append("tagsProperty.entryId = ?");
882 
883             query.append(" ");
884 
885             if (obc != null) {
886                 query.append("ORDER BY ");
887 
888                 String[] orderByFields = obc.getOrderByFields();
889 
890                 for (int i = 0; i < orderByFields.length; i++) {
891                     query.append("tagsProperty.");
892                     query.append(orderByFields[i]);
893 
894                     if (obc.isAscending()) {
895                         query.append(" ASC");
896                     }
897                     else {
898                         query.append(" DESC");
899                     }
900 
901                     if ((i + 1) < orderByFields.length) {
902                         query.append(", ");
903                     }
904                 }
905             }
906 
907             else {
908                 query.append("ORDER BY ");
909 
910                 query.append("tagsProperty.key ASC");
911             }
912 
913             Query q = session.createQuery(query.toString());
914 
915             QueryPos qPos = QueryPos.getInstance(q);
916 
917             qPos.add(entryId);
918 
919             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
920                     tagsProperty);
921 
922             TagsProperty[] array = new TagsPropertyImpl[3];
923 
924             array[0] = (TagsProperty)objArray[0];
925             array[1] = (TagsProperty)objArray[1];
926             array[2] = (TagsProperty)objArray[2];
927 
928             return array;
929         }
930         catch (Exception e) {
931             throw processException(e);
932         }
933         finally {
934             closeSession(session);
935         }
936     }
937 
938     public List<TagsProperty> findByC_K(long companyId, String key)
939         throws SystemException {
940         Object[] finderArgs = new Object[] { new Long(companyId), key };
941 
942         List<TagsProperty> list = (List<TagsProperty>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_K,
943                 finderArgs, this);
944 
945         if (list == null) {
946             Session session = null;
947 
948             try {
949                 session = openSession();
950 
951                 StringBuilder query = new StringBuilder();
952 
953                 query.append(
954                     "SELECT tagsProperty FROM TagsProperty tagsProperty WHERE ");
955 
956                 query.append("tagsProperty.companyId = ?");
957 
958                 query.append(" AND ");
959 
960                 if (key == null) {
961                     query.append("tagsProperty.key IS NULL");
962                 }
963                 else {
964                     query.append("tagsProperty.key = ?");
965                 }
966 
967                 query.append(" ");
968 
969                 query.append("ORDER BY ");
970 
971                 query.append("tagsProperty.key ASC");
972 
973                 Query q = session.createQuery(query.toString());
974 
975                 QueryPos qPos = QueryPos.getInstance(q);
976 
977                 qPos.add(companyId);
978 
979                 if (key != null) {
980                     qPos.add(key);
981                 }
982 
983                 list = q.list();
984             }
985             catch (Exception e) {
986                 throw processException(e);
987             }
988             finally {
989                 if (list == null) {
990                     list = new ArrayList<TagsProperty>();
991                 }
992 
993                 cacheResult(list);
994 
995                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_K, finderArgs,
996                     list);
997 
998                 closeSession(session);
999             }
1000        }
1001
1002        return list;
1003    }
1004
1005    public List<TagsProperty> findByC_K(long companyId, String key, int start,
1006        int end) throws SystemException {
1007        return findByC_K(companyId, key, start, end, null);
1008    }
1009
1010    public List<TagsProperty> findByC_K(long companyId, String key, int start,
1011        int end, OrderByComparator obc) throws SystemException {
1012        Object[] finderArgs = new Object[] {
1013                new Long(companyId),
1014                
1015                key,
1016                
1017                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1018            };
1019
1020        List<TagsProperty> list = (List<TagsProperty>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_C_K,
1021                finderArgs, this);
1022
1023        if (list == null) {
1024            Session session = null;
1025
1026            try {
1027                session = openSession();
1028
1029                StringBuilder query = new StringBuilder();
1030
1031                query.append(
1032                    "SELECT tagsProperty FROM TagsProperty tagsProperty WHERE ");
1033
1034                query.append("tagsProperty.companyId = ?");
1035
1036                query.append(" AND ");
1037
1038                if (key == null) {
1039                    query.append("tagsProperty.key IS NULL");
1040                }
1041                else {
1042                    query.append("tagsProperty.key = ?");
1043                }
1044
1045                query.append(" ");
1046
1047                if (obc != null) {
1048                    query.append("ORDER BY ");
1049
1050                    String[] orderByFields = obc.getOrderByFields();
1051
1052                    for (int i = 0; i < orderByFields.length; i++) {
1053                        query.append("tagsProperty.");
1054                        query.append(orderByFields[i]);
1055
1056                        if (obc.isAscending()) {
1057                            query.append(" ASC");
1058                        }
1059                        else {
1060                            query.append(" DESC");
1061                        }
1062
1063                        if ((i + 1) < orderByFields.length) {
1064                            query.append(", ");
1065                        }
1066                    }
1067                }
1068
1069                else {
1070                    query.append("ORDER BY ");
1071
1072                    query.append("tagsProperty.key ASC");
1073                }
1074
1075                Query q = session.createQuery(query.toString());
1076
1077                QueryPos qPos = QueryPos.getInstance(q);
1078
1079                qPos.add(companyId);
1080
1081                if (key != null) {
1082                    qPos.add(key);
1083                }
1084
1085                list = (List<TagsProperty>)QueryUtil.list(q, getDialect(),
1086                        start, end);
1087            }
1088            catch (Exception e) {
1089                throw processException(e);
1090            }
1091            finally {
1092                if (list == null) {
1093                    list = new ArrayList<TagsProperty>();
1094                }
1095
1096                cacheResult(list);
1097
1098                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_C_K,
1099                    finderArgs, list);
1100
1101                closeSession(session);
1102            }
1103        }
1104
1105        return list;
1106    }
1107
1108    public TagsProperty findByC_K_First(long companyId, String key,
1109        OrderByComparator obc) throws NoSuchPropertyException, SystemException {
1110        List<TagsProperty> list = findByC_K(companyId, key, 0, 1, obc);
1111
1112        if (list.isEmpty()) {
1113            StringBuilder msg = new StringBuilder();
1114
1115            msg.append("No TagsProperty exists with the key {");
1116
1117            msg.append("companyId=" + companyId);
1118
1119            msg.append(", ");
1120            msg.append("key=" + key);
1121
1122            msg.append(StringPool.CLOSE_CURLY_BRACE);
1123
1124            throw new NoSuchPropertyException(msg.toString());
1125        }
1126        else {
1127            return list.get(0);
1128        }
1129    }
1130
1131    public TagsProperty findByC_K_Last(long companyId, String key,
1132        OrderByComparator obc) throws NoSuchPropertyException, SystemException {
1133        int count = countByC_K(companyId, key);
1134
1135        List<TagsProperty> list = findByC_K(companyId, key, count - 1, count,
1136                obc);
1137
1138        if (list.isEmpty()) {
1139            StringBuilder msg = new StringBuilder();
1140
1141            msg.append("No TagsProperty exists with the key {");
1142
1143            msg.append("companyId=" + companyId);
1144
1145            msg.append(", ");
1146            msg.append("key=" + key);
1147
1148            msg.append(StringPool.CLOSE_CURLY_BRACE);
1149
1150            throw new NoSuchPropertyException(msg.toString());
1151        }
1152        else {
1153            return list.get(0);
1154        }
1155    }
1156
1157    public TagsProperty[] findByC_K_PrevAndNext(long propertyId,
1158        long companyId, String key, OrderByComparator obc)
1159        throws NoSuchPropertyException, SystemException {
1160        TagsProperty tagsProperty = findByPrimaryKey(propertyId);
1161
1162        int count = countByC_K(companyId, key);
1163
1164        Session session = null;
1165
1166        try {
1167            session = openSession();
1168
1169            StringBuilder query = new StringBuilder();
1170
1171            query.append(
1172                "SELECT tagsProperty FROM TagsProperty tagsProperty WHERE ");
1173
1174            query.append("tagsProperty.companyId = ?");
1175
1176            query.append(" AND ");
1177
1178            if (key == null) {
1179                query.append("tagsProperty.key IS NULL");
1180            }
1181            else {
1182                query.append("tagsProperty.key = ?");
1183            }
1184
1185            query.append(" ");
1186
1187            if (obc != null) {
1188                query.append("ORDER BY ");
1189
1190                String[] orderByFields = obc.getOrderByFields();
1191
1192                for (int i = 0; i < orderByFields.length; i++) {
1193                    query.append("tagsProperty.");
1194                    query.append(orderByFields[i]);
1195
1196                    if (obc.isAscending()) {
1197                        query.append(" ASC");
1198                    }
1199                    else {
1200                        query.append(" DESC");
1201                    }
1202
1203                    if ((i + 1) < orderByFields.length) {
1204                        query.append(", ");
1205                    }
1206                }
1207            }
1208
1209            else {
1210                query.append("ORDER BY ");
1211
1212                query.append("tagsProperty.key ASC");
1213            }
1214
1215            Query q = session.createQuery(query.toString());
1216
1217            QueryPos qPos = QueryPos.getInstance(q);
1218
1219            qPos.add(companyId);
1220
1221            if (key != null) {
1222                qPos.add(key);
1223            }
1224
1225            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1226                    tagsProperty);
1227
1228            TagsProperty[] array = new TagsPropertyImpl[3];
1229
1230            array[0] = (TagsProperty)objArray[0];
1231            array[1] = (TagsProperty)objArray[1];
1232            array[2] = (TagsProperty)objArray[2];
1233
1234            return array;
1235        }
1236        catch (Exception e) {
1237            throw processException(e);
1238        }
1239        finally {
1240            closeSession(session);
1241        }
1242    }
1243
1244    public TagsProperty findByE_K(long entryId, String key)
1245        throws NoSuchPropertyException, SystemException {
1246        TagsProperty tagsProperty = fetchByE_K(entryId, key);
1247
1248        if (tagsProperty == null) {
1249            StringBuilder msg = new StringBuilder();
1250
1251            msg.append("No TagsProperty exists with the key {");
1252
1253            msg.append("entryId=" + entryId);
1254
1255            msg.append(", ");
1256            msg.append("key=" + key);
1257
1258            msg.append(StringPool.CLOSE_CURLY_BRACE);
1259
1260            if (_log.isWarnEnabled()) {
1261                _log.warn(msg.toString());
1262            }
1263
1264            throw new NoSuchPropertyException(msg.toString());
1265        }
1266
1267        return tagsProperty;
1268    }
1269
1270    public TagsProperty fetchByE_K(long entryId, String key)
1271        throws SystemException {
1272        return fetchByE_K(entryId, key, true);
1273    }
1274
1275    public TagsProperty fetchByE_K(long entryId, String key,
1276        boolean retrieveFromCache) throws SystemException {
1277        Object[] finderArgs = new Object[] { new Long(entryId), key };
1278
1279        Object result = null;
1280
1281        if (retrieveFromCache) {
1282            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_E_K,
1283                    finderArgs, this);
1284        }
1285
1286        if (result == null) {
1287            Session session = null;
1288
1289            try {
1290                session = openSession();
1291
1292                StringBuilder query = new StringBuilder();
1293
1294                query.append(
1295                    "SELECT tagsProperty FROM TagsProperty tagsProperty WHERE ");
1296
1297                query.append("tagsProperty.entryId = ?");
1298
1299                query.append(" AND ");
1300
1301                if (key == null) {
1302                    query.append("tagsProperty.key IS NULL");
1303                }
1304                else {
1305                    query.append("tagsProperty.key = ?");
1306                }
1307
1308                query.append(" ");
1309
1310                query.append("ORDER BY ");
1311
1312                query.append("tagsProperty.key ASC");
1313
1314                Query q = session.createQuery(query.toString());
1315
1316                QueryPos qPos = QueryPos.getInstance(q);
1317
1318                qPos.add(entryId);
1319
1320                if (key != null) {
1321                    qPos.add(key);
1322                }
1323
1324                List<TagsProperty> list = q.list();
1325
1326                result = list;
1327
1328                TagsProperty tagsProperty = null;
1329
1330                if (list.isEmpty()) {
1331                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_E_K,
1332                        finderArgs, list);
1333                }
1334                else {
1335                    tagsProperty = list.get(0);
1336
1337                    cacheResult(tagsProperty);
1338
1339                    if ((tagsProperty.getEntryId() != entryId) ||
1340                            (tagsProperty.getKey() == null) ||
1341                            !tagsProperty.getKey().equals(key)) {
1342                        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_E_K,
1343                            finderArgs, tagsProperty);
1344                    }
1345                }
1346
1347                return tagsProperty;
1348            }
1349            catch (Exception e) {
1350                throw processException(e);
1351            }
1352            finally {
1353                if (result == null) {
1354                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_E_K,
1355                        finderArgs, new ArrayList<TagsProperty>());
1356                }
1357
1358                closeSession(session);
1359            }
1360        }
1361        else {
1362            if (result instanceof List<?>) {
1363                return null;
1364            }
1365            else {
1366                return (TagsProperty)result;
1367            }
1368        }
1369    }
1370
1371    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1372        throws SystemException {
1373        Session session = null;
1374
1375        try {
1376            session = openSession();
1377
1378            dynamicQuery.compile(session);
1379
1380            return dynamicQuery.list();
1381        }
1382        catch (Exception e) {
1383            throw processException(e);
1384        }
1385        finally {
1386            closeSession(session);
1387        }
1388    }
1389
1390    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1391        int start, int end) throws SystemException {
1392        Session session = null;
1393
1394        try {
1395            session = openSession();
1396
1397            dynamicQuery.setLimit(start, end);
1398
1399            dynamicQuery.compile(session);
1400
1401            return dynamicQuery.list();
1402        }
1403        catch (Exception e) {
1404            throw processException(e);
1405        }
1406        finally {
1407            closeSession(session);
1408        }
1409    }
1410
1411    public List<TagsProperty> findAll() throws SystemException {
1412        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1413    }
1414
1415    public List<TagsProperty> findAll(int start, int end)
1416        throws SystemException {
1417        return findAll(start, end, null);
1418    }
1419
1420    public List<TagsProperty> findAll(int start, int end, OrderByComparator obc)
1421        throws SystemException {
1422        Object[] finderArgs = new Object[] {
1423                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1424            };
1425
1426        List<TagsProperty> list = (List<TagsProperty>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1427                finderArgs, this);
1428
1429        if (list == null) {
1430            Session session = null;
1431
1432            try {
1433                session = openSession();
1434
1435                StringBuilder query = new StringBuilder();
1436
1437                query.append(
1438                    "SELECT tagsProperty FROM TagsProperty tagsProperty ");
1439
1440                if (obc != null) {
1441                    query.append("ORDER BY ");
1442
1443                    String[] orderByFields = obc.getOrderByFields();
1444
1445                    for (int i = 0; i < orderByFields.length; i++) {
1446                        query.append("tagsProperty.");
1447                        query.append(orderByFields[i]);
1448
1449                        if (obc.isAscending()) {
1450                            query.append(" ASC");
1451                        }
1452                        else {
1453                            query.append(" DESC");
1454                        }
1455
1456                        if ((i + 1) < orderByFields.length) {
1457                            query.append(", ");
1458                        }
1459                    }
1460                }
1461
1462                else {
1463                    query.append("ORDER BY ");
1464
1465                    query.append("tagsProperty.key ASC");
1466                }
1467
1468                Query q = session.createQuery(query.toString());
1469
1470                if (obc == null) {
1471                    list = (List<TagsProperty>)QueryUtil.list(q, getDialect(),
1472                            start, end, false);
1473
1474                    Collections.sort(list);
1475                }
1476                else {
1477                    list = (List<TagsProperty>)QueryUtil.list(q, getDialect(),
1478                            start, end);
1479                }
1480            }
1481            catch (Exception e) {
1482                throw processException(e);
1483            }
1484            finally {
1485                if (list == null) {
1486                    list = new ArrayList<TagsProperty>();
1487                }
1488
1489                cacheResult(list);
1490
1491                FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1492
1493                closeSession(session);
1494            }
1495        }
1496
1497        return list;
1498    }
1499
1500    public void removeByCompanyId(long companyId) throws SystemException {
1501        for (TagsProperty tagsProperty : findByCompanyId(companyId)) {
1502            remove(tagsProperty);
1503        }
1504    }
1505
1506    public void removeByEntryId(long entryId) throws SystemException {
1507        for (TagsProperty tagsProperty : findByEntryId(entryId)) {
1508            remove(tagsProperty);
1509        }
1510    }
1511
1512    public void removeByC_K(long companyId, String key)
1513        throws SystemException {
1514        for (TagsProperty tagsProperty : findByC_K(companyId, key)) {
1515            remove(tagsProperty);
1516        }
1517    }
1518
1519    public void removeByE_K(long entryId, String key)
1520        throws NoSuchPropertyException, SystemException {
1521        TagsProperty tagsProperty = findByE_K(entryId, key);
1522
1523        remove(tagsProperty);
1524    }
1525
1526    public void removeAll() throws SystemException {
1527        for (TagsProperty tagsProperty : findAll()) {
1528            remove(tagsProperty);
1529        }
1530    }
1531
1532    public int countByCompanyId(long companyId) throws SystemException {
1533        Object[] finderArgs = new Object[] { new Long(companyId) };
1534
1535        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
1536                finderArgs, this);
1537
1538        if (count == null) {
1539            Session session = null;
1540
1541            try {
1542                session = openSession();
1543
1544                StringBuilder query = new StringBuilder();
1545
1546                query.append("SELECT COUNT(tagsProperty) ");
1547                query.append("FROM TagsProperty tagsProperty WHERE ");
1548
1549                query.append("tagsProperty.companyId = ?");
1550
1551                query.append(" ");
1552
1553                Query q = session.createQuery(query.toString());
1554
1555                QueryPos qPos = QueryPos.getInstance(q);
1556
1557                qPos.add(companyId);
1558
1559                count = (Long)q.uniqueResult();
1560            }
1561            catch (Exception e) {
1562                throw processException(e);
1563            }
1564            finally {
1565                if (count == null) {
1566                    count = Long.valueOf(0);
1567                }
1568
1569                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
1570                    finderArgs, count);
1571
1572                closeSession(session);
1573            }
1574        }
1575
1576        return count.intValue();
1577    }
1578
1579    public int countByEntryId(long entryId) throws SystemException {
1580        Object[] finderArgs = new Object[] { new Long(entryId) };
1581
1582        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ENTRYID,
1583                finderArgs, this);
1584
1585        if (count == null) {
1586            Session session = null;
1587
1588            try {
1589                session = openSession();
1590
1591                StringBuilder query = new StringBuilder();
1592
1593                query.append("SELECT COUNT(tagsProperty) ");
1594                query.append("FROM TagsProperty tagsProperty WHERE ");
1595
1596                query.append("tagsProperty.entryId = ?");
1597
1598                query.append(" ");
1599
1600                Query q = session.createQuery(query.toString());
1601
1602                QueryPos qPos = QueryPos.getInstance(q);
1603
1604                qPos.add(entryId);
1605
1606                count = (Long)q.uniqueResult();
1607            }
1608            catch (Exception e) {
1609                throw processException(e);
1610            }
1611            finally {
1612                if (count == null) {
1613                    count = Long.valueOf(0);
1614                }
1615
1616                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ENTRYID,
1617                    finderArgs, count);
1618
1619                closeSession(session);
1620            }
1621        }
1622
1623        return count.intValue();
1624    }
1625
1626    public int countByC_K(long companyId, String key) throws SystemException {
1627        Object[] finderArgs = new Object[] { new Long(companyId), key };
1628
1629        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_K,
1630                finderArgs, this);
1631
1632        if (count == null) {
1633            Session session = null;
1634
1635            try {
1636                session = openSession();
1637
1638                StringBuilder query = new StringBuilder();
1639
1640                query.append("SELECT COUNT(tagsProperty) ");
1641                query.append("FROM TagsProperty tagsProperty WHERE ");
1642
1643                query.append("tagsProperty.companyId = ?");
1644
1645                query.append(" AND ");
1646
1647                if (key == null) {
1648                    query.append("tagsProperty.key IS NULL");
1649                }
1650                else {
1651                    query.append("tagsProperty.key = ?");
1652                }
1653
1654                query.append(" ");
1655
1656                Query q = session.createQuery(query.toString());
1657
1658                QueryPos qPos = QueryPos.getInstance(q);
1659
1660                qPos.add(companyId);
1661
1662                if (key != null) {
1663                    qPos.add(key);
1664                }
1665
1666                count = (Long)q.uniqueResult();
1667            }
1668            catch (Exception e) {
1669                throw processException(e);
1670            }
1671            finally {
1672                if (count == null) {
1673                    count = Long.valueOf(0);
1674                }
1675
1676                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_K, finderArgs,
1677                    count);
1678
1679                closeSession(session);
1680            }
1681        }
1682
1683        return count.intValue();
1684    }
1685
1686    public int countByE_K(long entryId, String key) throws SystemException {
1687        Object[] finderArgs = new Object[] { new Long(entryId), key };
1688
1689        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_E_K,
1690                finderArgs, this);
1691
1692        if (count == null) {
1693            Session session = null;
1694
1695            try {
1696                session = openSession();
1697
1698                StringBuilder query = new StringBuilder();
1699
1700                query.append("SELECT COUNT(tagsProperty) ");
1701                query.append("FROM TagsProperty tagsProperty WHERE ");
1702
1703                query.append("tagsProperty.entryId = ?");
1704
1705                query.append(" AND ");
1706
1707                if (key == null) {
1708                    query.append("tagsProperty.key IS NULL");
1709                }
1710                else {
1711                    query.append("tagsProperty.key = ?");
1712                }
1713
1714                query.append(" ");
1715
1716                Query q = session.createQuery(query.toString());
1717
1718                QueryPos qPos = QueryPos.getInstance(q);
1719
1720                qPos.add(entryId);
1721
1722                if (key != null) {
1723                    qPos.add(key);
1724                }
1725
1726                count = (Long)q.uniqueResult();
1727            }
1728            catch (Exception e) {
1729                throw processException(e);
1730            }
1731            finally {
1732                if (count == null) {
1733                    count = Long.valueOf(0);
1734                }
1735
1736                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_E_K, finderArgs,
1737                    count);
1738
1739                closeSession(session);
1740            }
1741        }
1742
1743        return count.intValue();
1744    }
1745
1746    public int countAll() throws SystemException {
1747        Object[] finderArgs = new Object[0];
1748
1749        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1750                finderArgs, this);
1751
1752        if (count == null) {
1753            Session session = null;
1754
1755            try {
1756                session = openSession();
1757
1758                Query q = session.createQuery(
1759                        "SELECT COUNT(tagsProperty) FROM TagsProperty tagsProperty");
1760
1761                count = (Long)q.uniqueResult();
1762            }
1763            catch (Exception e) {
1764                throw processException(e);
1765            }
1766            finally {
1767                if (count == null) {
1768                    count = Long.valueOf(0);
1769                }
1770
1771                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1772                    count);
1773
1774                closeSession(session);
1775            }
1776        }
1777
1778        return count.intValue();
1779    }
1780
1781    public void afterPropertiesSet() {
1782        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1783                    com.liferay.portal.util.PropsUtil.get(
1784                        "value.object.listener.com.liferay.portlet.tags.model.TagsProperty")));
1785
1786        if (listenerClassNames.length > 0) {
1787            try {
1788                List<ModelListener<TagsProperty>> listenersList = new ArrayList<ModelListener<TagsProperty>>();
1789
1790                for (String listenerClassName : listenerClassNames) {
1791                    listenersList.add((ModelListener<TagsProperty>)Class.forName(
1792                            listenerClassName).newInstance());
1793                }
1794
1795                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1796            }
1797            catch (Exception e) {
1798                _log.error(e);
1799            }
1800        }
1801    }
1802
1803    @BeanReference(name = "com.liferay.portlet.tags.service.persistence.TagsAssetPersistence.impl")
1804    protected com.liferay.portlet.tags.service.persistence.TagsAssetPersistence tagsAssetPersistence;
1805    @BeanReference(name = "com.liferay.portlet.tags.service.persistence.TagsEntryPersistence.impl")
1806    protected com.liferay.portlet.tags.service.persistence.TagsEntryPersistence tagsEntryPersistence;
1807    @BeanReference(name = "com.liferay.portlet.tags.service.persistence.TagsPropertyPersistence.impl")
1808    protected com.liferay.portlet.tags.service.persistence.TagsPropertyPersistence tagsPropertyPersistence;
1809    @BeanReference(name = "com.liferay.portlet.tags.service.persistence.TagsSourcePersistence.impl")
1810    protected com.liferay.portlet.tags.service.persistence.TagsSourcePersistence tagsSourcePersistence;
1811    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
1812    protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
1813    @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
1814    protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1815    private static Log _log = LogFactoryUtil.getLog(TagsPropertyPersistenceImpl.class);
1816}