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