001    /**
002     * Copyright (c) 2000-2011 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.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.getValue() });
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                            StringBundler query = new StringBundler(2);
450    
451                            query.append(_SQL_SELECT_CLASSNAME_WHERE);
452    
453                            if (value == null) {
454                                    query.append(_FINDER_COLUMN_VALUE_VALUE_1);
455                            }
456                            else {
457                                    if (value.equals(StringPool.BLANK)) {
458                                            query.append(_FINDER_COLUMN_VALUE_VALUE_3);
459                                    }
460                                    else {
461                                            query.append(_FINDER_COLUMN_VALUE_VALUE_2);
462                                    }
463                            }
464    
465                            String sql = query.toString();
466    
467                            Session session = null;
468    
469                            try {
470                                    session = openSession();
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.removeResult(FINDER_PATH_FETCH_BY_VALUE,
510                                                    finderArgs);
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                            StringBundler query = null;
578                            String sql = null;
579    
580                            if (orderByComparator != null) {
581                                    query = new StringBundler(2 +
582                                                    (orderByComparator.getOrderByFields().length * 3));
583    
584                                    query.append(_SQL_SELECT_CLASSNAME);
585    
586                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
587                                            orderByComparator);
588    
589                                    sql = query.toString();
590                            }
591                            else {
592                                    sql = _SQL_SELECT_CLASSNAME;
593                            }
594    
595                            Session session = null;
596    
597                            try {
598                                    session = openSession();
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                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_ALL,
619                                                    finderArgs);
620                                    }
621                                    else {
622                                            cacheResult(list);
623    
624                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs,
625                                                    list);
626                                    }
627    
628                                    closeSession(session);
629                            }
630                    }
631    
632                    return list;
633            }
634    
635            /**
636             * Removes the class name where value = &#63; from the database.
637             *
638             * @param value the value to search with
639             * @throws SystemException if a system exception occurred
640             */
641            public void removeByValue(String value)
642                    throws NoSuchClassNameException, SystemException {
643                    ClassName className = findByValue(value);
644    
645                    remove(className);
646            }
647    
648            /**
649             * Removes all the class names from the database.
650             *
651             * @throws SystemException if a system exception occurred
652             */
653            public void removeAll() throws SystemException {
654                    for (ClassName className : findAll()) {
655                            remove(className);
656                    }
657            }
658    
659            /**
660             * Counts all the class names where value = &#63;.
661             *
662             * @param value the value to search with
663             * @return the number of matching class names
664             * @throws SystemException if a system exception occurred
665             */
666            public int countByValue(String value) throws SystemException {
667                    Object[] finderArgs = new Object[] { value };
668    
669                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_VALUE,
670                                    finderArgs, this);
671    
672                    if (count == null) {
673                            StringBundler query = new StringBundler(2);
674    
675                            query.append(_SQL_COUNT_CLASSNAME_WHERE);
676    
677                            if (value == null) {
678                                    query.append(_FINDER_COLUMN_VALUE_VALUE_1);
679                            }
680                            else {
681                                    if (value.equals(StringPool.BLANK)) {
682                                            query.append(_FINDER_COLUMN_VALUE_VALUE_3);
683                                    }
684                                    else {
685                                            query.append(_FINDER_COLUMN_VALUE_VALUE_2);
686                                    }
687                            }
688    
689                            String sql = query.toString();
690    
691                            Session session = null;
692    
693                            try {
694                                    session = openSession();
695    
696                                    Query q = session.createQuery(sql);
697    
698                                    QueryPos qPos = QueryPos.getInstance(q);
699    
700                                    if (value != null) {
701                                            qPos.add(value);
702                                    }
703    
704                                    count = (Long)q.uniqueResult();
705                            }
706                            catch (Exception e) {
707                                    throw processException(e);
708                            }
709                            finally {
710                                    if (count == null) {
711                                            count = Long.valueOf(0);
712                                    }
713    
714                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_VALUE,
715                                            finderArgs, count);
716    
717                                    closeSession(session);
718                            }
719                    }
720    
721                    return count.intValue();
722            }
723    
724            /**
725             * Counts all the class names.
726             *
727             * @return the number of class names
728             * @throws SystemException if a system exception occurred
729             */
730            public int countAll() throws SystemException {
731                    Object[] finderArgs = new Object[0];
732    
733                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
734                                    finderArgs, this);
735    
736                    if (count == null) {
737                            Session session = null;
738    
739                            try {
740                                    session = openSession();
741    
742                                    Query q = session.createQuery(_SQL_COUNT_CLASSNAME);
743    
744                                    count = (Long)q.uniqueResult();
745                            }
746                            catch (Exception e) {
747                                    throw processException(e);
748                            }
749                            finally {
750                                    if (count == null) {
751                                            count = Long.valueOf(0);
752                                    }
753    
754                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
755                                            count);
756    
757                                    closeSession(session);
758                            }
759                    }
760    
761                    return count.intValue();
762            }
763    
764            /**
765             * Initializes the class name persistence.
766             */
767            public void afterPropertiesSet() {
768                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
769                                            com.liferay.portal.util.PropsUtil.get(
770                                                    "value.object.listener.com.liferay.portal.model.ClassName")));
771    
772                    if (listenerClassNames.length > 0) {
773                            try {
774                                    List<ModelListener<ClassName>> listenersList = new ArrayList<ModelListener<ClassName>>();
775    
776                                    for (String listenerClassName : listenerClassNames) {
777                                            listenersList.add((ModelListener<ClassName>)InstanceFactory.newInstance(
778                                                            listenerClassName));
779                                    }
780    
781                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
782                            }
783                            catch (Exception e) {
784                                    _log.error(e);
785                            }
786                    }
787            }
788    
789            public void destroy() {
790                    EntityCacheUtil.removeCache(ClassNameImpl.class.getName());
791                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
792                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
793            }
794    
795            @BeanReference(type = AccountPersistence.class)
796            protected AccountPersistence accountPersistence;
797            @BeanReference(type = AddressPersistence.class)
798            protected AddressPersistence addressPersistence;
799            @BeanReference(type = BrowserTrackerPersistence.class)
800            protected BrowserTrackerPersistence browserTrackerPersistence;
801            @BeanReference(type = ClassNamePersistence.class)
802            protected ClassNamePersistence classNamePersistence;
803            @BeanReference(type = ClusterGroupPersistence.class)
804            protected ClusterGroupPersistence clusterGroupPersistence;
805            @BeanReference(type = CompanyPersistence.class)
806            protected CompanyPersistence companyPersistence;
807            @BeanReference(type = ContactPersistence.class)
808            protected ContactPersistence contactPersistence;
809            @BeanReference(type = CountryPersistence.class)
810            protected CountryPersistence countryPersistence;
811            @BeanReference(type = EmailAddressPersistence.class)
812            protected EmailAddressPersistence emailAddressPersistence;
813            @BeanReference(type = GroupPersistence.class)
814            protected GroupPersistence groupPersistence;
815            @BeanReference(type = ImagePersistence.class)
816            protected ImagePersistence imagePersistence;
817            @BeanReference(type = LayoutPersistence.class)
818            protected LayoutPersistence layoutPersistence;
819            @BeanReference(type = LayoutPrototypePersistence.class)
820            protected LayoutPrototypePersistence layoutPrototypePersistence;
821            @BeanReference(type = LayoutSetPersistence.class)
822            protected LayoutSetPersistence layoutSetPersistence;
823            @BeanReference(type = LayoutSetPrototypePersistence.class)
824            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
825            @BeanReference(type = ListTypePersistence.class)
826            protected ListTypePersistence listTypePersistence;
827            @BeanReference(type = LockPersistence.class)
828            protected LockPersistence lockPersistence;
829            @BeanReference(type = MembershipRequestPersistence.class)
830            protected MembershipRequestPersistence membershipRequestPersistence;
831            @BeanReference(type = OrganizationPersistence.class)
832            protected OrganizationPersistence organizationPersistence;
833            @BeanReference(type = OrgGroupPermissionPersistence.class)
834            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
835            @BeanReference(type = OrgGroupRolePersistence.class)
836            protected OrgGroupRolePersistence orgGroupRolePersistence;
837            @BeanReference(type = OrgLaborPersistence.class)
838            protected OrgLaborPersistence orgLaborPersistence;
839            @BeanReference(type = PasswordPolicyPersistence.class)
840            protected PasswordPolicyPersistence passwordPolicyPersistence;
841            @BeanReference(type = PasswordPolicyRelPersistence.class)
842            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
843            @BeanReference(type = PasswordTrackerPersistence.class)
844            protected PasswordTrackerPersistence passwordTrackerPersistence;
845            @BeanReference(type = PermissionPersistence.class)
846            protected PermissionPersistence permissionPersistence;
847            @BeanReference(type = PhonePersistence.class)
848            protected PhonePersistence phonePersistence;
849            @BeanReference(type = PluginSettingPersistence.class)
850            protected PluginSettingPersistence pluginSettingPersistence;
851            @BeanReference(type = PortletPersistence.class)
852            protected PortletPersistence portletPersistence;
853            @BeanReference(type = PortletItemPersistence.class)
854            protected PortletItemPersistence portletItemPersistence;
855            @BeanReference(type = PortletPreferencesPersistence.class)
856            protected PortletPreferencesPersistence portletPreferencesPersistence;
857            @BeanReference(type = RegionPersistence.class)
858            protected RegionPersistence regionPersistence;
859            @BeanReference(type = ReleasePersistence.class)
860            protected ReleasePersistence releasePersistence;
861            @BeanReference(type = ResourcePersistence.class)
862            protected ResourcePersistence resourcePersistence;
863            @BeanReference(type = ResourceActionPersistence.class)
864            protected ResourceActionPersistence resourceActionPersistence;
865            @BeanReference(type = ResourceCodePersistence.class)
866            protected ResourceCodePersistence resourceCodePersistence;
867            @BeanReference(type = ResourcePermissionPersistence.class)
868            protected ResourcePermissionPersistence resourcePermissionPersistence;
869            @BeanReference(type = RolePersistence.class)
870            protected RolePersistence rolePersistence;
871            @BeanReference(type = ServiceComponentPersistence.class)
872            protected ServiceComponentPersistence serviceComponentPersistence;
873            @BeanReference(type = ShardPersistence.class)
874            protected ShardPersistence shardPersistence;
875            @BeanReference(type = SubscriptionPersistence.class)
876            protected SubscriptionPersistence subscriptionPersistence;
877            @BeanReference(type = TicketPersistence.class)
878            protected TicketPersistence ticketPersistence;
879            @BeanReference(type = TeamPersistence.class)
880            protected TeamPersistence teamPersistence;
881            @BeanReference(type = UserPersistence.class)
882            protected UserPersistence userPersistence;
883            @BeanReference(type = UserGroupPersistence.class)
884            protected UserGroupPersistence userGroupPersistence;
885            @BeanReference(type = UserGroupGroupRolePersistence.class)
886            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
887            @BeanReference(type = UserGroupRolePersistence.class)
888            protected UserGroupRolePersistence userGroupRolePersistence;
889            @BeanReference(type = UserIdMapperPersistence.class)
890            protected UserIdMapperPersistence userIdMapperPersistence;
891            @BeanReference(type = UserTrackerPersistence.class)
892            protected UserTrackerPersistence userTrackerPersistence;
893            @BeanReference(type = UserTrackerPathPersistence.class)
894            protected UserTrackerPathPersistence userTrackerPathPersistence;
895            @BeanReference(type = WebDAVPropsPersistence.class)
896            protected WebDAVPropsPersistence webDAVPropsPersistence;
897            @BeanReference(type = WebsitePersistence.class)
898            protected WebsitePersistence websitePersistence;
899            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
900            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
901            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
902            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
903            private static final String _SQL_SELECT_CLASSNAME = "SELECT className FROM ClassName className";
904            private static final String _SQL_SELECT_CLASSNAME_WHERE = "SELECT className FROM ClassName className WHERE ";
905            private static final String _SQL_COUNT_CLASSNAME = "SELECT COUNT(className) FROM ClassName className";
906            private static final String _SQL_COUNT_CLASSNAME_WHERE = "SELECT COUNT(className) FROM ClassName className WHERE ";
907            private static final String _FINDER_COLUMN_VALUE_VALUE_1 = "className.value IS NULL";
908            private static final String _FINDER_COLUMN_VALUE_VALUE_2 = "className.value = ?";
909            private static final String _FINDER_COLUMN_VALUE_VALUE_3 = "(className.value IS NULL OR className.value = ?)";
910            private static final String _ORDER_BY_ENTITY_ALIAS = "className.";
911            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ClassName exists with the primary key ";
912            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ClassName exists with the key {";
913            private static Log _log = LogFactoryUtil.getLog(ClassNamePersistenceImpl.class);
914    }