001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.shopping.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.annotation.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.model.ModelListener;
037    import com.liferay.portal.service.persistence.BatchSessionUtil;
038    import com.liferay.portal.service.persistence.ResourcePersistence;
039    import com.liferay.portal.service.persistence.UserPersistence;
040    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
041    
042    import com.liferay.portlet.shopping.NoSuchItemFieldException;
043    import com.liferay.portlet.shopping.model.ShoppingItemField;
044    import com.liferay.portlet.shopping.model.impl.ShoppingItemFieldImpl;
045    import com.liferay.portlet.shopping.model.impl.ShoppingItemFieldModelImpl;
046    
047    import java.io.Serializable;
048    
049    import java.util.ArrayList;
050    import java.util.Collections;
051    import java.util.List;
052    
053    /**
054     * @author    Brian Wing Shun Chan
055     * @see       ShoppingItemFieldPersistence
056     * @see       ShoppingItemFieldUtil
057     * @generated
058     */
059    public class ShoppingItemFieldPersistenceImpl extends BasePersistenceImpl<ShoppingItemField>
060            implements ShoppingItemFieldPersistence {
061            public static final String FINDER_CLASS_NAME_ENTITY = ShoppingItemFieldImpl.class.getName();
062            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
063                    ".List";
064            public static final FinderPath FINDER_PATH_FIND_BY_ITEMID = new FinderPath(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
065                            ShoppingItemFieldModelImpl.FINDER_CACHE_ENABLED,
066                            FINDER_CLASS_NAME_LIST, "findByItemId",
067                            new String[] {
068                                    Long.class.getName(),
069                                    
070                            "java.lang.Integer", "java.lang.Integer",
071                                    "com.liferay.portal.kernel.util.OrderByComparator"
072                            });
073            public static final FinderPath FINDER_PATH_COUNT_BY_ITEMID = new FinderPath(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
074                            ShoppingItemFieldModelImpl.FINDER_CACHE_ENABLED,
075                            FINDER_CLASS_NAME_LIST, "countByItemId",
076                            new String[] { Long.class.getName() });
077            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
078                            ShoppingItemFieldModelImpl.FINDER_CACHE_ENABLED,
079                            FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
080            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
081                            ShoppingItemFieldModelImpl.FINDER_CACHE_ENABLED,
082                            FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
083    
084            public void cacheResult(ShoppingItemField shoppingItemField) {
085                    EntityCacheUtil.putResult(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
086                            ShoppingItemFieldImpl.class, shoppingItemField.getPrimaryKey(),
087                            shoppingItemField);
088            }
089    
090            public void cacheResult(List<ShoppingItemField> shoppingItemFields) {
091                    for (ShoppingItemField shoppingItemField : shoppingItemFields) {
092                            if (EntityCacheUtil.getResult(
093                                                    ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
094                                                    ShoppingItemFieldImpl.class,
095                                                    shoppingItemField.getPrimaryKey(), this) == null) {
096                                    cacheResult(shoppingItemField);
097                            }
098                    }
099            }
100    
101            public void clearCache() {
102                    CacheRegistryUtil.clear(ShoppingItemFieldImpl.class.getName());
103                    EntityCacheUtil.clearCache(ShoppingItemFieldImpl.class.getName());
104                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
105                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
106            }
107    
108            public void clearCache(ShoppingItemField shoppingItemField) {
109                    EntityCacheUtil.removeResult(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
110                            ShoppingItemFieldImpl.class, shoppingItemField.getPrimaryKey());
111            }
112    
113            public ShoppingItemField create(long itemFieldId) {
114                    ShoppingItemField shoppingItemField = new ShoppingItemFieldImpl();
115    
116                    shoppingItemField.setNew(true);
117                    shoppingItemField.setPrimaryKey(itemFieldId);
118    
119                    return shoppingItemField;
120            }
121    
122            public ShoppingItemField remove(Serializable primaryKey)
123                    throws NoSuchModelException, SystemException {
124                    return remove(((Long)primaryKey).longValue());
125            }
126    
127            public ShoppingItemField remove(long itemFieldId)
128                    throws NoSuchItemFieldException, SystemException {
129                    Session session = null;
130    
131                    try {
132                            session = openSession();
133    
134                            ShoppingItemField shoppingItemField = (ShoppingItemField)session.get(ShoppingItemFieldImpl.class,
135                                            new Long(itemFieldId));
136    
137                            if (shoppingItemField == null) {
138                                    if (_log.isWarnEnabled()) {
139                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + itemFieldId);
140                                    }
141    
142                                    throw new NoSuchItemFieldException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
143                                            itemFieldId);
144                            }
145    
146                            return remove(shoppingItemField);
147                    }
148                    catch (NoSuchItemFieldException nsee) {
149                            throw nsee;
150                    }
151                    catch (Exception e) {
152                            throw processException(e);
153                    }
154                    finally {
155                            closeSession(session);
156                    }
157            }
158    
159            protected ShoppingItemField removeImpl(ShoppingItemField shoppingItemField)
160                    throws SystemException {
161                    shoppingItemField = toUnwrappedModel(shoppingItemField);
162    
163                    Session session = null;
164    
165                    try {
166                            session = openSession();
167    
168                            if (shoppingItemField.isCachedModel() ||
169                                            BatchSessionUtil.isEnabled()) {
170                                    Object staleObject = session.get(ShoppingItemFieldImpl.class,
171                                                    shoppingItemField.getPrimaryKeyObj());
172    
173                                    if (staleObject != null) {
174                                            session.evict(staleObject);
175                                    }
176                            }
177    
178                            session.delete(shoppingItemField);
179    
180                            session.flush();
181                    }
182                    catch (Exception e) {
183                            throw processException(e);
184                    }
185                    finally {
186                            closeSession(session);
187                    }
188    
189                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
190    
191                    EntityCacheUtil.removeResult(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
192                            ShoppingItemFieldImpl.class, shoppingItemField.getPrimaryKey());
193    
194                    return shoppingItemField;
195            }
196    
197            public ShoppingItemField updateImpl(
198                    com.liferay.portlet.shopping.model.ShoppingItemField shoppingItemField,
199                    boolean merge) throws SystemException {
200                    shoppingItemField = toUnwrappedModel(shoppingItemField);
201    
202                    Session session = null;
203    
204                    try {
205                            session = openSession();
206    
207                            BatchSessionUtil.update(session, shoppingItemField, merge);
208    
209                            shoppingItemField.setNew(false);
210                    }
211                    catch (Exception e) {
212                            throw processException(e);
213                    }
214                    finally {
215                            closeSession(session);
216                    }
217    
218                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
219    
220                    EntityCacheUtil.putResult(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
221                            ShoppingItemFieldImpl.class, shoppingItemField.getPrimaryKey(),
222                            shoppingItemField);
223    
224                    return shoppingItemField;
225            }
226    
227            protected ShoppingItemField toUnwrappedModel(
228                    ShoppingItemField shoppingItemField) {
229                    if (shoppingItemField instanceof ShoppingItemFieldImpl) {
230                            return shoppingItemField;
231                    }
232    
233                    ShoppingItemFieldImpl shoppingItemFieldImpl = new ShoppingItemFieldImpl();
234    
235                    shoppingItemFieldImpl.setNew(shoppingItemField.isNew());
236                    shoppingItemFieldImpl.setPrimaryKey(shoppingItemField.getPrimaryKey());
237    
238                    shoppingItemFieldImpl.setItemFieldId(shoppingItemField.getItemFieldId());
239                    shoppingItemFieldImpl.setItemId(shoppingItemField.getItemId());
240                    shoppingItemFieldImpl.setName(shoppingItemField.getName());
241                    shoppingItemFieldImpl.setValues(shoppingItemField.getValues());
242                    shoppingItemFieldImpl.setDescription(shoppingItemField.getDescription());
243    
244                    return shoppingItemFieldImpl;
245            }
246    
247            public ShoppingItemField findByPrimaryKey(Serializable primaryKey)
248                    throws NoSuchModelException, SystemException {
249                    return findByPrimaryKey(((Long)primaryKey).longValue());
250            }
251    
252            public ShoppingItemField findByPrimaryKey(long itemFieldId)
253                    throws NoSuchItemFieldException, SystemException {
254                    ShoppingItemField shoppingItemField = fetchByPrimaryKey(itemFieldId);
255    
256                    if (shoppingItemField == null) {
257                            if (_log.isWarnEnabled()) {
258                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + itemFieldId);
259                            }
260    
261                            throw new NoSuchItemFieldException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
262                                    itemFieldId);
263                    }
264    
265                    return shoppingItemField;
266            }
267    
268            public ShoppingItemField fetchByPrimaryKey(Serializable primaryKey)
269                    throws SystemException {
270                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
271            }
272    
273            public ShoppingItemField fetchByPrimaryKey(long itemFieldId)
274                    throws SystemException {
275                    ShoppingItemField shoppingItemField = (ShoppingItemField)EntityCacheUtil.getResult(ShoppingItemFieldModelImpl.ENTITY_CACHE_ENABLED,
276                                    ShoppingItemFieldImpl.class, itemFieldId, this);
277    
278                    if (shoppingItemField == null) {
279                            Session session = null;
280    
281                            try {
282                                    session = openSession();
283    
284                                    shoppingItemField = (ShoppingItemField)session.get(ShoppingItemFieldImpl.class,
285                                                    new Long(itemFieldId));
286                            }
287                            catch (Exception e) {
288                                    throw processException(e);
289                            }
290                            finally {
291                                    if (shoppingItemField != null) {
292                                            cacheResult(shoppingItemField);
293                                    }
294    
295                                    closeSession(session);
296                            }
297                    }
298    
299                    return shoppingItemField;
300            }
301    
302            public List<ShoppingItemField> findByItemId(long itemId)
303                    throws SystemException {
304                    return findByItemId(itemId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
305            }
306    
307            public List<ShoppingItemField> findByItemId(long itemId, int start, int end)
308                    throws SystemException {
309                    return findByItemId(itemId, start, end, null);
310            }
311    
312            public List<ShoppingItemField> findByItemId(long itemId, int start,
313                    int end, OrderByComparator orderByComparator) throws SystemException {
314                    Object[] finderArgs = new Object[] {
315                                    itemId,
316                                    
317                                    String.valueOf(start), String.valueOf(end),
318                                    String.valueOf(orderByComparator)
319                            };
320    
321                    List<ShoppingItemField> list = (List<ShoppingItemField>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_ITEMID,
322                                    finderArgs, this);
323    
324                    if (list == null) {
325                            Session session = null;
326    
327                            try {
328                                    session = openSession();
329    
330                                    StringBundler query = null;
331    
332                                    if (orderByComparator != null) {
333                                            query = new StringBundler(3 +
334                                                            (orderByComparator.getOrderByFields().length * 3));
335                                    }
336                                    else {
337                                            query = new StringBundler(3);
338                                    }
339    
340                                    query.append(_SQL_SELECT_SHOPPINGITEMFIELD_WHERE);
341    
342                                    query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
343    
344                                    if (orderByComparator != null) {
345                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
346                                                    orderByComparator);
347                                    }
348    
349                                    else {
350                                            query.append(ShoppingItemFieldModelImpl.ORDER_BY_JPQL);
351                                    }
352    
353                                    String sql = query.toString();
354    
355                                    Query q = session.createQuery(sql);
356    
357                                    QueryPos qPos = QueryPos.getInstance(q);
358    
359                                    qPos.add(itemId);
360    
361                                    list = (List<ShoppingItemField>)QueryUtil.list(q, getDialect(),
362                                                    start, end);
363                            }
364                            catch (Exception e) {
365                                    throw processException(e);
366                            }
367                            finally {
368                                    if (list == null) {
369                                            list = new ArrayList<ShoppingItemField>();
370                                    }
371    
372                                    cacheResult(list);
373    
374                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_ITEMID,
375                                            finderArgs, list);
376    
377                                    closeSession(session);
378                            }
379                    }
380    
381                    return list;
382            }
383    
384            public ShoppingItemField findByItemId_First(long itemId,
385                    OrderByComparator orderByComparator)
386                    throws NoSuchItemFieldException, SystemException {
387                    List<ShoppingItemField> list = findByItemId(itemId, 0, 1,
388                                    orderByComparator);
389    
390                    if (list.isEmpty()) {
391                            StringBundler msg = new StringBundler(4);
392    
393                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
394    
395                            msg.append("itemId=");
396                            msg.append(itemId);
397    
398                            msg.append(StringPool.CLOSE_CURLY_BRACE);
399    
400                            throw new NoSuchItemFieldException(msg.toString());
401                    }
402                    else {
403                            return list.get(0);
404                    }
405            }
406    
407            public ShoppingItemField findByItemId_Last(long itemId,
408                    OrderByComparator orderByComparator)
409                    throws NoSuchItemFieldException, SystemException {
410                    int count = countByItemId(itemId);
411    
412                    List<ShoppingItemField> list = findByItemId(itemId, count - 1, count,
413                                    orderByComparator);
414    
415                    if (list.isEmpty()) {
416                            StringBundler msg = new StringBundler(4);
417    
418                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
419    
420                            msg.append("itemId=");
421                            msg.append(itemId);
422    
423                            msg.append(StringPool.CLOSE_CURLY_BRACE);
424    
425                            throw new NoSuchItemFieldException(msg.toString());
426                    }
427                    else {
428                            return list.get(0);
429                    }
430            }
431    
432            public ShoppingItemField[] findByItemId_PrevAndNext(long itemFieldId,
433                    long itemId, OrderByComparator orderByComparator)
434                    throws NoSuchItemFieldException, SystemException {
435                    ShoppingItemField shoppingItemField = findByPrimaryKey(itemFieldId);
436    
437                    Session session = null;
438    
439                    try {
440                            session = openSession();
441    
442                            ShoppingItemField[] array = new ShoppingItemFieldImpl[3];
443    
444                            array[0] = getByItemId_PrevAndNext(session, shoppingItemField,
445                                            itemId, orderByComparator, true);
446    
447                            array[1] = shoppingItemField;
448    
449                            array[2] = getByItemId_PrevAndNext(session, shoppingItemField,
450                                            itemId, orderByComparator, false);
451    
452                            return array;
453                    }
454                    catch (Exception e) {
455                            throw processException(e);
456                    }
457                    finally {
458                            closeSession(session);
459                    }
460            }
461    
462            protected ShoppingItemField getByItemId_PrevAndNext(Session session,
463                    ShoppingItemField shoppingItemField, long itemId,
464                    OrderByComparator orderByComparator, boolean previous) {
465                    StringBundler query = null;
466    
467                    if (orderByComparator != null) {
468                            query = new StringBundler(6 +
469                                            (orderByComparator.getOrderByFields().length * 6));
470                    }
471                    else {
472                            query = new StringBundler(3);
473                    }
474    
475                    query.append(_SQL_SELECT_SHOPPINGITEMFIELD_WHERE);
476    
477                    query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
478    
479                    if (orderByComparator != null) {
480                            String[] orderByFields = orderByComparator.getOrderByFields();
481    
482                            if (orderByFields.length > 0) {
483                                    query.append(WHERE_AND);
484                            }
485    
486                            for (int i = 0; i < orderByFields.length; i++) {
487                                    query.append(_ORDER_BY_ENTITY_ALIAS);
488                                    query.append(orderByFields[i]);
489    
490                                    if ((i + 1) < orderByFields.length) {
491                                            if (orderByComparator.isAscending() ^ previous) {
492                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
493                                            }
494                                            else {
495                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
496                                            }
497                                    }
498                                    else {
499                                            if (orderByComparator.isAscending() ^ previous) {
500                                                    query.append(WHERE_GREATER_THAN);
501                                            }
502                                            else {
503                                                    query.append(WHERE_LESSER_THAN);
504                                            }
505                                    }
506                            }
507    
508                            query.append(ORDER_BY_CLAUSE);
509    
510                            for (int i = 0; i < orderByFields.length; i++) {
511                                    query.append(_ORDER_BY_ENTITY_ALIAS);
512                                    query.append(orderByFields[i]);
513    
514                                    if ((i + 1) < orderByFields.length) {
515                                            if (orderByComparator.isAscending() ^ previous) {
516                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
517                                            }
518                                            else {
519                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
520                                            }
521                                    }
522                                    else {
523                                            if (orderByComparator.isAscending() ^ previous) {
524                                                    query.append(ORDER_BY_ASC);
525                                            }
526                                            else {
527                                                    query.append(ORDER_BY_DESC);
528                                            }
529                                    }
530                            }
531                    }
532    
533                    else {
534                            query.append(ShoppingItemFieldModelImpl.ORDER_BY_JPQL);
535                    }
536    
537                    String sql = query.toString();
538    
539                    Query q = session.createQuery(sql);
540    
541                    q.setFirstResult(0);
542                    q.setMaxResults(2);
543    
544                    QueryPos qPos = QueryPos.getInstance(q);
545    
546                    qPos.add(itemId);
547    
548                    if (orderByComparator != null) {
549                            Object[] values = orderByComparator.getOrderByValues(shoppingItemField);
550    
551                            for (Object value : values) {
552                                    qPos.add(value);
553                            }
554                    }
555    
556                    List<ShoppingItemField> list = q.list();
557    
558                    if (list.size() == 2) {
559                            return list.get(1);
560                    }
561                    else {
562                            return null;
563                    }
564            }
565    
566            public List<ShoppingItemField> findAll() throws SystemException {
567                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
568            }
569    
570            public List<ShoppingItemField> findAll(int start, int end)
571                    throws SystemException {
572                    return findAll(start, end, null);
573            }
574    
575            public List<ShoppingItemField> findAll(int start, int end,
576                    OrderByComparator orderByComparator) throws SystemException {
577                    Object[] finderArgs = new Object[] {
578                                    String.valueOf(start), String.valueOf(end),
579                                    String.valueOf(orderByComparator)
580                            };
581    
582                    List<ShoppingItemField> list = (List<ShoppingItemField>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
583                                    finderArgs, this);
584    
585                    if (list == null) {
586                            Session session = null;
587    
588                            try {
589                                    session = openSession();
590    
591                                    StringBundler query = null;
592                                    String sql = null;
593    
594                                    if (orderByComparator != null) {
595                                            query = new StringBundler(2 +
596                                                            (orderByComparator.getOrderByFields().length * 3));
597    
598                                            query.append(_SQL_SELECT_SHOPPINGITEMFIELD);
599    
600                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
601                                                    orderByComparator);
602    
603                                            sql = query.toString();
604                                    }
605                                    else {
606                                            sql = _SQL_SELECT_SHOPPINGITEMFIELD.concat(ShoppingItemFieldModelImpl.ORDER_BY_JPQL);
607                                    }
608    
609                                    Query q = session.createQuery(sql);
610    
611                                    if (orderByComparator == null) {
612                                            list = (List<ShoppingItemField>)QueryUtil.list(q,
613                                                            getDialect(), start, end, false);
614    
615                                            Collections.sort(list);
616                                    }
617                                    else {
618                                            list = (List<ShoppingItemField>)QueryUtil.list(q,
619                                                            getDialect(), start, end);
620                                    }
621                            }
622                            catch (Exception e) {
623                                    throw processException(e);
624                            }
625                            finally {
626                                    if (list == null) {
627                                            list = new ArrayList<ShoppingItemField>();
628                                    }
629    
630                                    cacheResult(list);
631    
632                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
633    
634                                    closeSession(session);
635                            }
636                    }
637    
638                    return list;
639            }
640    
641            public void removeByItemId(long itemId) throws SystemException {
642                    for (ShoppingItemField shoppingItemField : findByItemId(itemId)) {
643                            remove(shoppingItemField);
644                    }
645            }
646    
647            public void removeAll() throws SystemException {
648                    for (ShoppingItemField shoppingItemField : findAll()) {
649                            remove(shoppingItemField);
650                    }
651            }
652    
653            public int countByItemId(long itemId) throws SystemException {
654                    Object[] finderArgs = new Object[] { itemId };
655    
656                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ITEMID,
657                                    finderArgs, this);
658    
659                    if (count == null) {
660                            Session session = null;
661    
662                            try {
663                                    session = openSession();
664    
665                                    StringBundler query = new StringBundler(2);
666    
667                                    query.append(_SQL_COUNT_SHOPPINGITEMFIELD_WHERE);
668    
669                                    query.append(_FINDER_COLUMN_ITEMID_ITEMID_2);
670    
671                                    String sql = query.toString();
672    
673                                    Query q = session.createQuery(sql);
674    
675                                    QueryPos qPos = QueryPos.getInstance(q);
676    
677                                    qPos.add(itemId);
678    
679                                    count = (Long)q.uniqueResult();
680                            }
681                            catch (Exception e) {
682                                    throw processException(e);
683                            }
684                            finally {
685                                    if (count == null) {
686                                            count = Long.valueOf(0);
687                                    }
688    
689                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ITEMID,
690                                            finderArgs, count);
691    
692                                    closeSession(session);
693                            }
694                    }
695    
696                    return count.intValue();
697            }
698    
699            public int countAll() throws SystemException {
700                    Object[] finderArgs = new Object[0];
701    
702                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
703                                    finderArgs, this);
704    
705                    if (count == null) {
706                            Session session = null;
707    
708                            try {
709                                    session = openSession();
710    
711                                    Query q = session.createQuery(_SQL_COUNT_SHOPPINGITEMFIELD);
712    
713                                    count = (Long)q.uniqueResult();
714                            }
715                            catch (Exception e) {
716                                    throw processException(e);
717                            }
718                            finally {
719                                    if (count == null) {
720                                            count = Long.valueOf(0);
721                                    }
722    
723                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
724                                            count);
725    
726                                    closeSession(session);
727                            }
728                    }
729    
730                    return count.intValue();
731            }
732    
733            public void afterPropertiesSet() {
734                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
735                                            com.liferay.portal.util.PropsUtil.get(
736                                                    "value.object.listener.com.liferay.portlet.shopping.model.ShoppingItemField")));
737    
738                    if (listenerClassNames.length > 0) {
739                            try {
740                                    List<ModelListener<ShoppingItemField>> listenersList = new ArrayList<ModelListener<ShoppingItemField>>();
741    
742                                    for (String listenerClassName : listenerClassNames) {
743                                            listenersList.add((ModelListener<ShoppingItemField>)InstanceFactory.newInstance(
744                                                            listenerClassName));
745                                    }
746    
747                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
748                            }
749                            catch (Exception e) {
750                                    _log.error(e);
751                            }
752                    }
753            }
754    
755            @BeanReference(type = ShoppingCartPersistence.class)
756            protected ShoppingCartPersistence shoppingCartPersistence;
757            @BeanReference(type = ShoppingCategoryPersistence.class)
758            protected ShoppingCategoryPersistence shoppingCategoryPersistence;
759            @BeanReference(type = ShoppingCouponPersistence.class)
760            protected ShoppingCouponPersistence shoppingCouponPersistence;
761            @BeanReference(type = ShoppingItemPersistence.class)
762            protected ShoppingItemPersistence shoppingItemPersistence;
763            @BeanReference(type = ShoppingItemFieldPersistence.class)
764            protected ShoppingItemFieldPersistence shoppingItemFieldPersistence;
765            @BeanReference(type = ShoppingItemPricePersistence.class)
766            protected ShoppingItemPricePersistence shoppingItemPricePersistence;
767            @BeanReference(type = ShoppingOrderPersistence.class)
768            protected ShoppingOrderPersistence shoppingOrderPersistence;
769            @BeanReference(type = ShoppingOrderItemPersistence.class)
770            protected ShoppingOrderItemPersistence shoppingOrderItemPersistence;
771            @BeanReference(type = ResourcePersistence.class)
772            protected ResourcePersistence resourcePersistence;
773            @BeanReference(type = UserPersistence.class)
774            protected UserPersistence userPersistence;
775            private static final String _SQL_SELECT_SHOPPINGITEMFIELD = "SELECT shoppingItemField FROM ShoppingItemField shoppingItemField";
776            private static final String _SQL_SELECT_SHOPPINGITEMFIELD_WHERE = "SELECT shoppingItemField FROM ShoppingItemField shoppingItemField WHERE ";
777            private static final String _SQL_COUNT_SHOPPINGITEMFIELD = "SELECT COUNT(shoppingItemField) FROM ShoppingItemField shoppingItemField";
778            private static final String _SQL_COUNT_SHOPPINGITEMFIELD_WHERE = "SELECT COUNT(shoppingItemField) FROM ShoppingItemField shoppingItemField WHERE ";
779            private static final String _FINDER_COLUMN_ITEMID_ITEMID_2 = "shoppingItemField.itemId = ?";
780            private static final String _ORDER_BY_ENTITY_ALIAS = "shoppingItemField.";
781            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ShoppingItemField exists with the primary key ";
782            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ShoppingItemField exists with the key {";
783            private static Log _log = LogFactoryUtil.getLog(ShoppingItemFieldPersistenceImpl.class);
784    }