001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.NoSuchClassNameException;
018    import com.liferay.portal.NoSuchModelException;
019    import com.liferay.portal.kernel.annotation.BeanReference;
020    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderPath;
024    import com.liferay.portal.kernel.dao.orm.Query;
025    import com.liferay.portal.kernel.dao.orm.QueryPos;
026    import com.liferay.portal.kernel.dao.orm.QueryUtil;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.kernel.util.Validator;
038    import com.liferay.portal.model.ClassName;
039    import com.liferay.portal.model.ModelListener;
040    import com.liferay.portal.model.impl.ClassNameImpl;
041    import com.liferay.portal.model.impl.ClassNameModelImpl;
042    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043    
044    import java.io.Serializable;
045    
046    import java.util.ArrayList;
047    import java.util.Collections;
048    import java.util.List;
049    
050    /**
051     * The persistence implementation for the class name service.
052     *
053     * <p>
054     * Never modify or reference this class directly. Always use {@link ClassNameUtil} to access the class name persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
055     * </p>
056     *
057     * <p>
058     * Caching information and settings can be found in <code>portal.properties</code>
059     * </p>
060     *
061     * @author Brian Wing Shun Chan
062     * @see ClassNamePersistence
063     * @see ClassNameUtil
064     * @generated
065     */
066    public class ClassNamePersistenceImpl extends BasePersistenceImpl<ClassName>
067            implements ClassNamePersistence {
068            public static final String FINDER_CLASS_NAME_ENTITY = ClassNameImpl.class.getName();
069            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
070                    ".List";
071            public static final FinderPath FINDER_PATH_FETCH_BY_VALUE = new FinderPath(ClassNameModelImpl.ENTITY_CACHE_ENABLED,
072                            ClassNameModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
073                            "fetchByValue", new String[] { String.class.getName() });
074            public static final FinderPath FINDER_PATH_COUNT_BY_VALUE = new FinderPath(ClassNameModelImpl.ENTITY_CACHE_ENABLED,
075                            ClassNameModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
076                            "countByValue", new String[] { String.class.getName() });
077            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(ClassNameModelImpl.ENTITY_CACHE_ENABLED,
078                            ClassNameModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
079                            "findAll", new String[0]);
080            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ClassNameModelImpl.ENTITY_CACHE_ENABLED,
081                            ClassNameModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
082                            "countAll", new String[0]);
083    
084            /**
085             * Caches the class name in the entity cache if it is enabled.
086             *
087             * @param className the class name to cache
088             */
089            public void cacheResult(ClassName className) {
090                    EntityCacheUtil.putResult(ClassNameModelImpl.ENTITY_CACHE_ENABLED,
091                            ClassNameImpl.class, className.getPrimaryKey(), className);
092    
093                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VALUE,
094                            new Object[] { className.getValue() }, className);
095            }
096    
097            /**
098             * Caches the class names in the entity cache if it is enabled.
099             *
100             * @param classNames the class names to cache
101             */
102            public void cacheResult(List<ClassName> classNames) {
103                    for (ClassName className : classNames) {
104                            if (EntityCacheUtil.getResult(
105                                                    ClassNameModelImpl.ENTITY_CACHE_ENABLED,
106                                                    ClassNameImpl.class, className.getPrimaryKey(), this) == null) {
107                                    cacheResult(className);
108                            }
109                    }
110            }
111    
112            /**
113             * Clears the cache for all class names.
114             *
115             * <p>
116             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
117             * </p>
118             */
119            public void clearCache() {
120                    CacheRegistryUtil.clear(ClassNameImpl.class.getName());
121                    EntityCacheUtil.clearCache(ClassNameImpl.class.getName());
122                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
123                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
124            }
125    
126            /**
127             * Clears the cache for the class name.
128             *
129             * <p>
130             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
131             * </p>
132             */
133            public void clearCache(ClassName className) {
134                    EntityCacheUtil.removeResult(ClassNameModelImpl.ENTITY_CACHE_ENABLED,
135                            ClassNameImpl.class, className.getPrimaryKey());
136    
137                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_VALUE,
138                            new Object[] { className.getValue() });
139            }
140    
141            /**
142             * Creates a new class name with the primary key. Does not add the class name to the database.
143             *
144             * @param classNameId the primary key for the new class name
145             * @return the new class name
146             */
147            public ClassName create(long classNameId) {
148                    ClassName className = new ClassNameImpl();
149    
150                    className.setNew(true);
151                    className.setPrimaryKey(classNameId);
152    
153                    return className;
154            }
155    
156            /**
157             * Removes the class name with the primary key from the database. Also notifies the appropriate model listeners.
158             *
159             * @param primaryKey the primary key of the class name to remove
160             * @return the class name that was removed
161             * @throws com.liferay.portal.NoSuchModelException if a class name with the primary key could not be found
162             * @throws SystemException if a system exception occurred
163             */
164            public ClassName remove(Serializable primaryKey)
165                    throws NoSuchModelException, SystemException {
166                    return remove(((Long)primaryKey).longValue());
167            }
168    
169            /**
170             * Removes the class name with the primary key from the database. Also notifies the appropriate model listeners.
171             *
172             * @param classNameId the primary key of the class name to remove
173             * @return the class name that was removed
174             * @throws com.liferay.portal.NoSuchClassNameException if a class name with the primary key could not be found
175             * @throws SystemException if a system exception occurred
176             */
177            public ClassName remove(long classNameId)
178                    throws NoSuchClassNameException, SystemException {
179                    Session session = null;
180    
181                    try {
182                            session = openSession();
183    
184                            ClassName className = (ClassName)session.get(ClassNameImpl.class,
185                                            new Long(classNameId));
186    
187                            if (className == null) {
188                                    if (_log.isWarnEnabled()) {
189                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + classNameId);
190                                    }
191    
192                                    throw new NoSuchClassNameException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
193                                            classNameId);
194                            }
195    
196                            return remove(className);
197                    }
198                    catch (NoSuchClassNameException nsee) {
199                            throw nsee;
200                    }
201                    catch (Exception e) {
202                            throw processException(e);
203                    }
204                    finally {
205                            closeSession(session);
206                    }
207            }
208    
209            protected ClassName removeImpl(ClassName className)
210                    throws SystemException {
211                    className = toUnwrappedModel(className);
212    
213                    Session session = null;
214    
215                    try {
216                            session = openSession();
217    
218                            BatchSessionUtil.delete(session, className);
219                    }
220                    catch (Exception e) {
221                            throw processException(e);
222                    }
223                    finally {
224                            closeSession(session);
225                    }
226    
227                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
228    
229                    ClassNameModelImpl classNameModelImpl = (ClassNameModelImpl)className;
230    
231                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_VALUE,
232                            new Object[] { classNameModelImpl.getOriginalValue() });
233    
234                    EntityCacheUtil.removeResult(ClassNameModelImpl.ENTITY_CACHE_ENABLED,
235                            ClassNameImpl.class, className.getPrimaryKey());
236    
237                    return className;
238            }
239    
240            public ClassName updateImpl(com.liferay.portal.model.ClassName className,
241                    boolean merge) throws SystemException {
242                    className = toUnwrappedModel(className);
243    
244                    boolean isNew = className.isNew();
245    
246                    ClassNameModelImpl classNameModelImpl = (ClassNameModelImpl)className;
247    
248                    Session session = null;
249    
250                    try {
251                            session = openSession();
252    
253                            BatchSessionUtil.update(session, className, merge);
254    
255                            className.setNew(false);
256                    }
257                    catch (Exception e) {
258                            throw processException(e);
259                    }
260                    finally {
261                            closeSession(session);
262                    }
263    
264                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
265    
266                    EntityCacheUtil.putResult(ClassNameModelImpl.ENTITY_CACHE_ENABLED,
267                            ClassNameImpl.class, className.getPrimaryKey(), className);
268    
269                    if (!isNew &&
270                                    (!Validator.equals(className.getValue(),
271                                            classNameModelImpl.getOriginalValue()))) {
272                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_VALUE,
273                                    new Object[] { classNameModelImpl.getOriginalValue() });
274                    }
275    
276                    if (isNew ||
277                                    (!Validator.equals(className.getValue(),
278                                            classNameModelImpl.getOriginalValue()))) {
279                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VALUE,
280                                    new Object[] { className.getValue() }, className);
281                    }
282    
283                    return className;
284            }
285    
286            protected ClassName toUnwrappedModel(ClassName className) {
287                    if (className instanceof ClassNameImpl) {
288                            return className;
289                    }
290    
291                    ClassNameImpl classNameImpl = new ClassNameImpl();
292    
293                    classNameImpl.setNew(className.isNew());
294                    classNameImpl.setPrimaryKey(className.getPrimaryKey());
295    
296                    classNameImpl.setClassNameId(className.getClassNameId());
297                    classNameImpl.setValue(className.getValue());
298    
299                    return classNameImpl;
300            }
301    
302            /**
303             * Finds the class name with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
304             *
305             * @param primaryKey the primary key of the class name to find
306             * @return the class name
307             * @throws com.liferay.portal.NoSuchModelException if a class name with the primary key could not be found
308             * @throws SystemException if a system exception occurred
309             */
310            public ClassName findByPrimaryKey(Serializable primaryKey)
311                    throws NoSuchModelException, SystemException {
312                    return findByPrimaryKey(((Long)primaryKey).longValue());
313            }
314    
315            /**
316             * Finds the class name with the primary key or throws a {@link com.liferay.portal.NoSuchClassNameException} if it could not be found.
317             *
318             * @param classNameId the primary key of the class name to find
319             * @return the class name
320             * @throws com.liferay.portal.NoSuchClassNameException if a class name with the primary key could not be found
321             * @throws SystemException if a system exception occurred
322             */
323            public ClassName findByPrimaryKey(long classNameId)
324                    throws NoSuchClassNameException, SystemException {
325                    ClassName className = fetchByPrimaryKey(classNameId);
326    
327                    if (className == null) {
328                            if (_log.isWarnEnabled()) {
329                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + classNameId);
330                            }
331    
332                            throw new NoSuchClassNameException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
333                                    classNameId);
334                    }
335    
336                    return className;
337            }
338    
339            /**
340             * Finds the class name with the primary key or returns <code>null</code> if it could not be found.
341             *
342             * @param primaryKey the primary key of the class name to find
343             * @return the class name, or <code>null</code> if a class name with the primary key could not be found
344             * @throws SystemException if a system exception occurred
345             */
346            public ClassName fetchByPrimaryKey(Serializable primaryKey)
347                    throws SystemException {
348                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
349            }
350    
351            /**
352             * Finds the class name with the primary key or returns <code>null</code> if it could not be found.
353             *
354             * @param classNameId the primary key of the class name to find
355             * @return the class name, or <code>null</code> if a class name with the primary key could not be found
356             * @throws SystemException if a system exception occurred
357             */
358            public ClassName fetchByPrimaryKey(long classNameId)
359                    throws SystemException {
360                    ClassName className = (ClassName)EntityCacheUtil.getResult(ClassNameModelImpl.ENTITY_CACHE_ENABLED,
361                                    ClassNameImpl.class, classNameId, this);
362    
363                    if (className == null) {
364                            Session session = null;
365    
366                            try {
367                                    session = openSession();
368    
369                                    className = (ClassName)session.get(ClassNameImpl.class,
370                                                    new Long(classNameId));
371                            }
372                            catch (Exception e) {
373                                    throw processException(e);
374                            }
375                            finally {
376                                    if (className != null) {
377                                            cacheResult(className);
378                                    }
379    
380                                    closeSession(session);
381                            }
382                    }
383    
384                    return className;
385            }
386    
387            /**
388             * Finds the class name where value = &#63; or throws a {@link com.liferay.portal.NoSuchClassNameException} if it could not be found.
389             *
390             * @param value the value to search with
391             * @return the matching class name
392             * @throws com.liferay.portal.NoSuchClassNameException if a matching class name could not be found
393             * @throws SystemException if a system exception occurred
394             */
395            public ClassName findByValue(String value)
396                    throws NoSuchClassNameException, SystemException {
397                    ClassName className = fetchByValue(value);
398    
399                    if (className == null) {
400                            StringBundler msg = new StringBundler(4);
401    
402                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
403    
404                            msg.append("value=");
405                            msg.append(value);
406    
407                            msg.append(StringPool.CLOSE_CURLY_BRACE);
408    
409                            if (_log.isWarnEnabled()) {
410                                    _log.warn(msg.toString());
411                            }
412    
413                            throw new NoSuchClassNameException(msg.toString());
414                    }
415    
416                    return className;
417            }
418    
419            /**
420             * Finds the class name where value = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
421             *
422             * @param value the value to search with
423             * @return the matching class name, or <code>null</code> if a matching class name could not be found
424             * @throws SystemException if a system exception occurred
425             */
426            public ClassName fetchByValue(String value) throws SystemException {
427                    return fetchByValue(value, true);
428            }
429    
430            /**
431             * Finds the class name where value = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
432             *
433             * @param value the value to search with
434             * @return the matching class name, or <code>null</code> if a matching class name could not be found
435             * @throws SystemException if a system exception occurred
436             */
437            public ClassName fetchByValue(String value, boolean retrieveFromCache)
438                    throws SystemException {
439                    Object[] finderArgs = new Object[] { value };
440    
441                    Object result = null;
442    
443                    if (retrieveFromCache) {
444                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_VALUE,
445                                            finderArgs, this);
446                    }
447    
448                    if (result == null) {
449                            Session session = null;
450    
451                            try {
452                                    session = openSession();
453    
454                                    StringBundler query = new StringBundler(2);
455    
456                                    query.append(_SQL_SELECT_CLASSNAME_WHERE);
457    
458                                    if (value == null) {
459                                            query.append(_FINDER_COLUMN_VALUE_VALUE_1);
460                                    }
461                                    else {
462                                            if (value.equals(StringPool.BLANK)) {
463                                                    query.append(_FINDER_COLUMN_VALUE_VALUE_3);
464                                            }
465                                            else {
466                                                    query.append(_FINDER_COLUMN_VALUE_VALUE_2);
467                                            }
468                                    }
469    
470                                    String sql = query.toString();
471    
472                                    Query q = session.createQuery(sql);
473    
474                                    QueryPos qPos = QueryPos.getInstance(q);
475    
476                                    if (value != null) {
477                                            qPos.add(value);
478                                    }
479    
480                                    List<ClassName> list = q.list();
481    
482                                    result = list;
483    
484                                    ClassName className = null;
485    
486                                    if (list.isEmpty()) {
487                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VALUE,
488                                                    finderArgs, list);
489                                    }
490                                    else {
491                                            className = list.get(0);
492    
493                                            cacheResult(className);
494    
495                                            if ((className.getValue() == null) ||
496                                                            !className.getValue().equals(value)) {
497                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VALUE,
498                                                            finderArgs, className);
499                                            }
500                                    }
501    
502                                    return className;
503                            }
504                            catch (Exception e) {
505                                    throw processException(e);
506                            }
507                            finally {
508                                    if (result == null) {
509                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VALUE,
510                                                    finderArgs, new ArrayList<ClassName>());
511                                    }
512    
513                                    closeSession(session);
514                            }
515                    }
516                    else {
517                            if (result instanceof List<?>) {
518                                    return null;
519                            }
520                            else {
521                                    return (ClassName)result;
522                            }
523                    }
524            }
525    
526            /**
527             * Finds all the class names.
528             *
529             * @return the class names
530             * @throws SystemException if a system exception occurred
531             */
532            public List<ClassName> findAll() throws SystemException {
533                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
534            }
535    
536            /**
537             * Finds a range of all the class names.
538             *
539             * <p>
540             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
541             * </p>
542             *
543             * @param start the lower bound of the range of class names to return
544             * @param end the upper bound of the range of class names to return (not inclusive)
545             * @return the range of class names
546             * @throws SystemException if a system exception occurred
547             */
548            public List<ClassName> findAll(int start, int end)
549                    throws SystemException {
550                    return findAll(start, end, null);
551            }
552    
553            /**
554             * Finds an ordered range of all the class names.
555             *
556             * <p>
557             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
558             * </p>
559             *
560             * @param start the lower bound of the range of class names to return
561             * @param end the upper bound of the range of class names to return (not inclusive)
562             * @param orderByComparator the comparator to order the results by
563             * @return the ordered range of class names
564             * @throws SystemException if a system exception occurred
565             */
566            public List<ClassName> findAll(int start, int end,
567                    OrderByComparator orderByComparator) throws SystemException {
568                    Object[] finderArgs = new Object[] {
569                                    String.valueOf(start), String.valueOf(end),
570                                    String.valueOf(orderByComparator)
571                            };
572    
573                    List<ClassName> list = (List<ClassName>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
574                                    finderArgs, this);
575    
576                    if (list == null) {
577                            Session session = null;
578    
579                            try {
580                                    session = openSession();
581    
582                                    StringBundler query = null;
583                                    String sql = null;
584    
585                                    if (orderByComparator != null) {
586                                            query = new StringBundler(2 +
587                                                            (orderByComparator.getOrderByFields().length * 3));
588    
589                                            query.append(_SQL_SELECT_CLASSNAME);
590    
591                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
592                                                    orderByComparator);
593    
594                                            sql = query.toString();
595                                    }
596                                    else {
597                                            sql = _SQL_SELECT_CLASSNAME;
598                                    }
599    
600                                    Query q = session.createQuery(sql);
601    
602                                    if (orderByComparator == null) {
603                                            list = (List<ClassName>)QueryUtil.list(q, getDialect(),
604                                                            start, end, false);
605    
606                                            Collections.sort(list);
607                                    }
608                                    else {
609                                            list = (List<ClassName>)QueryUtil.list(q, getDialect(),
610                                                            start, end);
611                                    }
612                            }
613                            catch (Exception e) {
614                                    throw processException(e);
615                            }
616                            finally {
617                                    if (list == null) {
618                                            list = new ArrayList<ClassName>();
619                                    }
620    
621                                    cacheResult(list);
622    
623                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
624    
625                                    closeSession(session);
626                            }
627                    }
628    
629                    return list;
630            }
631    
632            /**
633             * Removes the class name where value = &#63; from the database.
634             *
635             * @param value the value to search with
636             * @throws SystemException if a system exception occurred
637             */
638            public void removeByValue(String value)
639                    throws NoSuchClassNameException, SystemException {
640                    ClassName className = findByValue(value);
641    
642                    remove(className);
643            }
644    
645            /**
646             * Removes all the class names from the database.
647             *
648             * @throws SystemException if a system exception occurred
649             */
650            public void removeAll() throws SystemException {
651                    for (ClassName className : findAll()) {
652                            remove(className);
653                    }
654            }
655    
656            /**
657             * Counts all the class names where value = &#63;.
658             *
659             * @param value the value to search with
660             * @return the number of matching class names
661             * @throws SystemException if a system exception occurred
662             */
663            public int countByValue(String value) throws SystemException {
664                    Object[] finderArgs = new Object[] { value };
665    
666                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_VALUE,
667                                    finderArgs, this);
668    
669                    if (count == null) {
670                            Session session = null;
671    
672                            try {
673                                    session = openSession();
674    
675                                    StringBundler query = new StringBundler(2);
676    
677                                    query.append(_SQL_COUNT_CLASSNAME_WHERE);
678    
679                                    if (value == null) {
680                                            query.append(_FINDER_COLUMN_VALUE_VALUE_1);
681                                    }
682                                    else {
683                                            if (value.equals(StringPool.BLANK)) {
684                                                    query.append(_FINDER_COLUMN_VALUE_VALUE_3);
685                                            }
686                                            else {
687                                                    query.append(_FINDER_COLUMN_VALUE_VALUE_2);
688                                            }
689                                    }
690    
691                                    String sql = query.toString();
692    
693                                    Query q = session.createQuery(sql);
694    
695                                    QueryPos qPos = QueryPos.getInstance(q);
696    
697                                    if (value != null) {
698                                            qPos.add(value);
699                                    }
700    
701                                    count = (Long)q.uniqueResult();
702                            }
703                            catch (Exception e) {
704                                    throw processException(e);
705                            }
706                            finally {
707                                    if (count == null) {
708                                            count = Long.valueOf(0);
709                                    }
710    
711                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_VALUE,
712                                            finderArgs, count);
713    
714                                    closeSession(session);
715                            }
716                    }
717    
718                    return count.intValue();
719            }
720    
721            /**
722             * Counts all the class names.
723             *
724             * @return the number of class names
725             * @throws SystemException if a system exception occurred
726             */
727            public int countAll() throws SystemException {
728                    Object[] finderArgs = new Object[0];
729    
730                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
731                                    finderArgs, this);
732    
733                    if (count == null) {
734                            Session session = null;
735    
736                            try {
737                                    session = openSession();
738    
739                                    Query q = session.createQuery(_SQL_COUNT_CLASSNAME);
740    
741                                    count = (Long)q.uniqueResult();
742                            }
743                            catch (Exception e) {
744                                    throw processException(e);
745                            }
746                            finally {
747                                    if (count == null) {
748                                            count = Long.valueOf(0);
749                                    }
750    
751                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
752                                            count);
753    
754                                    closeSession(session);
755                            }
756                    }
757    
758                    return count.intValue();
759            }
760    
761            /**
762             * Initializes the class name persistence.
763             */
764            public void afterPropertiesSet() {
765                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
766                                            com.liferay.portal.util.PropsUtil.get(
767                                                    "value.object.listener.com.liferay.portal.model.ClassName")));
768    
769                    if (listenerClassNames.length > 0) {
770                            try {
771                                    List<ModelListener<ClassName>> listenersList = new ArrayList<ModelListener<ClassName>>();
772    
773                                    for (String listenerClassName : listenerClassNames) {
774                                            listenersList.add((ModelListener<ClassName>)InstanceFactory.newInstance(
775                                                            listenerClassName));
776                                    }
777    
778                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
779                            }
780                            catch (Exception e) {
781                                    _log.error(e);
782                            }
783                    }
784            }
785    
786            public void destroy() {
787                    EntityCacheUtil.removeCache(ClassNameImpl.class.getName());
788                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
789                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
790            }
791    
792            @BeanReference(type = AccountPersistence.class)
793            protected AccountPersistence accountPersistence;
794            @BeanReference(type = AddressPersistence.class)
795            protected AddressPersistence addressPersistence;
796            @BeanReference(type = BrowserTrackerPersistence.class)
797            protected BrowserTrackerPersistence browserTrackerPersistence;
798            @BeanReference(type = ClassNamePersistence.class)
799            protected ClassNamePersistence classNamePersistence;
800            @BeanReference(type = ClusterGroupPersistence.class)
801            protected ClusterGroupPersistence clusterGroupPersistence;
802            @BeanReference(type = CompanyPersistence.class)
803            protected CompanyPersistence companyPersistence;
804            @BeanReference(type = ContactPersistence.class)
805            protected ContactPersistence contactPersistence;
806            @BeanReference(type = CountryPersistence.class)
807            protected CountryPersistence countryPersistence;
808            @BeanReference(type = EmailAddressPersistence.class)
809            protected EmailAddressPersistence emailAddressPersistence;
810            @BeanReference(type = GroupPersistence.class)
811            protected GroupPersistence groupPersistence;
812            @BeanReference(type = ImagePersistence.class)
813            protected ImagePersistence imagePersistence;
814            @BeanReference(type = LayoutPersistence.class)
815            protected LayoutPersistence layoutPersistence;
816            @BeanReference(type = LayoutPrototypePersistence.class)
817            protected LayoutPrototypePersistence layoutPrototypePersistence;
818            @BeanReference(type = LayoutSetPersistence.class)
819            protected LayoutSetPersistence layoutSetPersistence;
820            @BeanReference(type = LayoutSetPrototypePersistence.class)
821            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
822            @BeanReference(type = ListTypePersistence.class)
823            protected ListTypePersistence listTypePersistence;
824            @BeanReference(type = LockPersistence.class)
825            protected LockPersistence lockPersistence;
826            @BeanReference(type = MembershipRequestPersistence.class)
827            protected MembershipRequestPersistence membershipRequestPersistence;
828            @BeanReference(type = OrganizationPersistence.class)
829            protected OrganizationPersistence organizationPersistence;
830            @BeanReference(type = OrgGroupPermissionPersistence.class)
831            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
832            @BeanReference(type = OrgGroupRolePersistence.class)
833            protected OrgGroupRolePersistence orgGroupRolePersistence;
834            @BeanReference(type = OrgLaborPersistence.class)
835            protected OrgLaborPersistence orgLaborPersistence;
836            @BeanReference(type = PasswordPolicyPersistence.class)
837            protected PasswordPolicyPersistence passwordPolicyPersistence;
838            @BeanReference(type = PasswordPolicyRelPersistence.class)
839            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
840            @BeanReference(type = PasswordTrackerPersistence.class)
841            protected PasswordTrackerPersistence passwordTrackerPersistence;
842            @BeanReference(type = PermissionPersistence.class)
843            protected PermissionPersistence permissionPersistence;
844            @BeanReference(type = PhonePersistence.class)
845            protected PhonePersistence phonePersistence;
846            @BeanReference(type = PluginSettingPersistence.class)
847            protected PluginSettingPersistence pluginSettingPersistence;
848            @BeanReference(type = PortletPersistence.class)
849            protected PortletPersistence portletPersistence;
850            @BeanReference(type = PortletItemPersistence.class)
851            protected PortletItemPersistence portletItemPersistence;
852            @BeanReference(type = PortletPreferencesPersistence.class)
853            protected PortletPreferencesPersistence portletPreferencesPersistence;
854            @BeanReference(type = RegionPersistence.class)
855            protected RegionPersistence regionPersistence;
856            @BeanReference(type = ReleasePersistence.class)
857            protected ReleasePersistence releasePersistence;
858            @BeanReference(type = ResourcePersistence.class)
859            protected ResourcePersistence resourcePersistence;
860            @BeanReference(type = ResourceActionPersistence.class)
861            protected ResourceActionPersistence resourceActionPersistence;
862            @BeanReference(type = ResourceCodePersistence.class)
863            protected ResourceCodePersistence resourceCodePersistence;
864            @BeanReference(type = ResourcePermissionPersistence.class)
865            protected ResourcePermissionPersistence resourcePermissionPersistence;
866            @BeanReference(type = RolePersistence.class)
867            protected RolePersistence rolePersistence;
868            @BeanReference(type = ServiceComponentPersistence.class)
869            protected ServiceComponentPersistence serviceComponentPersistence;
870            @BeanReference(type = ShardPersistence.class)
871            protected ShardPersistence shardPersistence;
872            @BeanReference(type = SubscriptionPersistence.class)
873            protected SubscriptionPersistence subscriptionPersistence;
874            @BeanReference(type = TicketPersistence.class)
875            protected TicketPersistence ticketPersistence;
876            @BeanReference(type = TeamPersistence.class)
877            protected TeamPersistence teamPersistence;
878            @BeanReference(type = UserPersistence.class)
879            protected UserPersistence userPersistence;
880            @BeanReference(type = UserGroupPersistence.class)
881            protected UserGroupPersistence userGroupPersistence;
882            @BeanReference(type = UserGroupGroupRolePersistence.class)
883            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
884            @BeanReference(type = UserGroupRolePersistence.class)
885            protected UserGroupRolePersistence userGroupRolePersistence;
886            @BeanReference(type = UserIdMapperPersistence.class)
887            protected UserIdMapperPersistence userIdMapperPersistence;
888            @BeanReference(type = UserTrackerPersistence.class)
889            protected UserTrackerPersistence userTrackerPersistence;
890            @BeanReference(type = UserTrackerPathPersistence.class)
891            protected UserTrackerPathPersistence userTrackerPathPersistence;
892            @BeanReference(type = WebDAVPropsPersistence.class)
893            protected WebDAVPropsPersistence webDAVPropsPersistence;
894            @BeanReference(type = WebsitePersistence.class)
895            protected WebsitePersistence websitePersistence;
896            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
897            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
898            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
899            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
900            private static final String _SQL_SELECT_CLASSNAME = "SELECT className FROM ClassName className";
901            private static final String _SQL_SELECT_CLASSNAME_WHERE = "SELECT className FROM ClassName className WHERE ";
902            private static final String _SQL_COUNT_CLASSNAME = "SELECT COUNT(className) FROM ClassName className";
903            private static final String _SQL_COUNT_CLASSNAME_WHERE = "SELECT COUNT(className) FROM ClassName className WHERE ";
904            private static final String _FINDER_COLUMN_VALUE_VALUE_1 = "className.value IS NULL";
905            private static final String _FINDER_COLUMN_VALUE_VALUE_2 = "className.value = ?";
906            private static final String _FINDER_COLUMN_VALUE_VALUE_3 = "(className.value IS NULL OR className.value = ?)";
907            private static final String _ORDER_BY_ENTITY_ALIAS = "className.";
908            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ClassName exists with the primary key ";
909            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ClassName exists with the key {";
910            private static Log _log = LogFactoryUtil.getLog(ClassNamePersistenceImpl.class);
911    }