001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.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                            if (className.isCachedModel() || BatchSessionUtil.isEnabled()) {
219                                    Object staleObject = session.get(ClassNameImpl.class,
220                                                    className.getPrimaryKeyObj());
221    
222                                    if (staleObject != null) {
223                                            session.evict(staleObject);
224                                    }
225                            }
226    
227                            session.delete(className);
228    
229                            session.flush();
230                    }
231                    catch (Exception e) {
232                            throw processException(e);
233                    }
234                    finally {
235                            closeSession(session);
236                    }
237    
238                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
239    
240                    ClassNameModelImpl classNameModelImpl = (ClassNameModelImpl)className;
241    
242                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_VALUE,
243                            new Object[] { classNameModelImpl.getOriginalValue() });
244    
245                    EntityCacheUtil.removeResult(ClassNameModelImpl.ENTITY_CACHE_ENABLED,
246                            ClassNameImpl.class, className.getPrimaryKey());
247    
248                    return className;
249            }
250    
251            public ClassName updateImpl(com.liferay.portal.model.ClassName className,
252                    boolean merge) throws SystemException {
253                    className = toUnwrappedModel(className);
254    
255                    boolean isNew = className.isNew();
256    
257                    ClassNameModelImpl classNameModelImpl = (ClassNameModelImpl)className;
258    
259                    Session session = null;
260    
261                    try {
262                            session = openSession();
263    
264                            BatchSessionUtil.update(session, className, merge);
265    
266                            className.setNew(false);
267                    }
268                    catch (Exception e) {
269                            throw processException(e);
270                    }
271                    finally {
272                            closeSession(session);
273                    }
274    
275                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
276    
277                    EntityCacheUtil.putResult(ClassNameModelImpl.ENTITY_CACHE_ENABLED,
278                            ClassNameImpl.class, className.getPrimaryKey(), className);
279    
280                    if (!isNew &&
281                                    (!Validator.equals(className.getValue(),
282                                            classNameModelImpl.getOriginalValue()))) {
283                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_VALUE,
284                                    new Object[] { classNameModelImpl.getOriginalValue() });
285                    }
286    
287                    if (isNew ||
288                                    (!Validator.equals(className.getValue(),
289                                            classNameModelImpl.getOriginalValue()))) {
290                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VALUE,
291                                    new Object[] { className.getValue() }, className);
292                    }
293    
294                    return className;
295            }
296    
297            protected ClassName toUnwrappedModel(ClassName className) {
298                    if (className instanceof ClassNameImpl) {
299                            return className;
300                    }
301    
302                    ClassNameImpl classNameImpl = new ClassNameImpl();
303    
304                    classNameImpl.setNew(className.isNew());
305                    classNameImpl.setPrimaryKey(className.getPrimaryKey());
306    
307                    classNameImpl.setClassNameId(className.getClassNameId());
308                    classNameImpl.setValue(className.getValue());
309    
310                    return classNameImpl;
311            }
312    
313            /**
314             * Finds the class name with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
315             *
316             * @param primaryKey the primary key of the class name to find
317             * @return the class name
318             * @throws com.liferay.portal.NoSuchModelException if a class name with the primary key could not be found
319             * @throws SystemException if a system exception occurred
320             */
321            public ClassName findByPrimaryKey(Serializable primaryKey)
322                    throws NoSuchModelException, SystemException {
323                    return findByPrimaryKey(((Long)primaryKey).longValue());
324            }
325    
326            /**
327             * Finds the class name with the primary key or throws a {@link com.liferay.portal.NoSuchClassNameException} if it could not be found.
328             *
329             * @param classNameId the primary key of the class name to find
330             * @return the class name
331             * @throws com.liferay.portal.NoSuchClassNameException if a class name with the primary key could not be found
332             * @throws SystemException if a system exception occurred
333             */
334            public ClassName findByPrimaryKey(long classNameId)
335                    throws NoSuchClassNameException, SystemException {
336                    ClassName className = fetchByPrimaryKey(classNameId);
337    
338                    if (className == null) {
339                            if (_log.isWarnEnabled()) {
340                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + classNameId);
341                            }
342    
343                            throw new NoSuchClassNameException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
344                                    classNameId);
345                    }
346    
347                    return className;
348            }
349    
350            /**
351             * Finds the class name with the primary key or returns <code>null</code> if it could not be found.
352             *
353             * @param primaryKey the primary key of the class name to find
354             * @return the class name, or <code>null</code> if a class name with the primary key could not be found
355             * @throws SystemException if a system exception occurred
356             */
357            public ClassName fetchByPrimaryKey(Serializable primaryKey)
358                    throws SystemException {
359                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
360            }
361    
362            /**
363             * Finds the class name with the primary key or returns <code>null</code> if it could not be found.
364             *
365             * @param classNameId the primary key of the class name to find
366             * @return the class name, or <code>null</code> if a class name with the primary key could not be found
367             * @throws SystemException if a system exception occurred
368             */
369            public ClassName fetchByPrimaryKey(long classNameId)
370                    throws SystemException {
371                    ClassName className = (ClassName)EntityCacheUtil.getResult(ClassNameModelImpl.ENTITY_CACHE_ENABLED,
372                                    ClassNameImpl.class, classNameId, this);
373    
374                    if (className == null) {
375                            Session session = null;
376    
377                            try {
378                                    session = openSession();
379    
380                                    className = (ClassName)session.get(ClassNameImpl.class,
381                                                    new Long(classNameId));
382                            }
383                            catch (Exception e) {
384                                    throw processException(e);
385                            }
386                            finally {
387                                    if (className != null) {
388                                            cacheResult(className);
389                                    }
390    
391                                    closeSession(session);
392                            }
393                    }
394    
395                    return className;
396            }
397    
398            /**
399             * Finds the class name where value = &#63; or throws a {@link com.liferay.portal.NoSuchClassNameException} if it could not be found.
400             *
401             * @param value the value to search with
402             * @return the matching class name
403             * @throws com.liferay.portal.NoSuchClassNameException if a matching class name could not be found
404             * @throws SystemException if a system exception occurred
405             */
406            public ClassName findByValue(String value)
407                    throws NoSuchClassNameException, SystemException {
408                    ClassName className = fetchByValue(value);
409    
410                    if (className == null) {
411                            StringBundler msg = new StringBundler(4);
412    
413                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
414    
415                            msg.append("value=");
416                            msg.append(value);
417    
418                            msg.append(StringPool.CLOSE_CURLY_BRACE);
419    
420                            if (_log.isWarnEnabled()) {
421                                    _log.warn(msg.toString());
422                            }
423    
424                            throw new NoSuchClassNameException(msg.toString());
425                    }
426    
427                    return className;
428            }
429    
430            /**
431             * Finds the class name where value = &#63; or returns <code>null</code> if it could not be found. Uses 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) throws SystemException {
438                    return fetchByValue(value, true);
439            }
440    
441            /**
442             * Finds the class name where value = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
443             *
444             * @param value the value to search with
445             * @return the matching class name, or <code>null</code> if a matching class name could not be found
446             * @throws SystemException if a system exception occurred
447             */
448            public ClassName fetchByValue(String value, boolean retrieveFromCache)
449                    throws SystemException {
450                    Object[] finderArgs = new Object[] { value };
451    
452                    Object result = null;
453    
454                    if (retrieveFromCache) {
455                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_VALUE,
456                                            finderArgs, this);
457                    }
458    
459                    if (result == null) {
460                            Session session = null;
461    
462                            try {
463                                    session = openSession();
464    
465                                    StringBundler query = new StringBundler(2);
466    
467                                    query.append(_SQL_SELECT_CLASSNAME_WHERE);
468    
469                                    if (value == null) {
470                                            query.append(_FINDER_COLUMN_VALUE_VALUE_1);
471                                    }
472                                    else {
473                                            if (value.equals(StringPool.BLANK)) {
474                                                    query.append(_FINDER_COLUMN_VALUE_VALUE_3);
475                                            }
476                                            else {
477                                                    query.append(_FINDER_COLUMN_VALUE_VALUE_2);
478                                            }
479                                    }
480    
481                                    String sql = query.toString();
482    
483                                    Query q = session.createQuery(sql);
484    
485                                    QueryPos qPos = QueryPos.getInstance(q);
486    
487                                    if (value != null) {
488                                            qPos.add(value);
489                                    }
490    
491                                    List<ClassName> list = q.list();
492    
493                                    result = list;
494    
495                                    ClassName className = null;
496    
497                                    if (list.isEmpty()) {
498                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VALUE,
499                                                    finderArgs, list);
500                                    }
501                                    else {
502                                            className = list.get(0);
503    
504                                            cacheResult(className);
505    
506                                            if ((className.getValue() == null) ||
507                                                            !className.getValue().equals(value)) {
508                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VALUE,
509                                                            finderArgs, className);
510                                            }
511                                    }
512    
513                                    return className;
514                            }
515                            catch (Exception e) {
516                                    throw processException(e);
517                            }
518                            finally {
519                                    if (result == null) {
520                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_VALUE,
521                                                    finderArgs, new ArrayList<ClassName>());
522                                    }
523    
524                                    closeSession(session);
525                            }
526                    }
527                    else {
528                            if (result instanceof List<?>) {
529                                    return null;
530                            }
531                            else {
532                                    return (ClassName)result;
533                            }
534                    }
535            }
536    
537            /**
538             * Finds all the class names.
539             *
540             * @return the class names
541             * @throws SystemException if a system exception occurred
542             */
543            public List<ClassName> findAll() throws SystemException {
544                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
545            }
546    
547            /**
548             * Finds a range of all the class names.
549             *
550             * <p>
551             * 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.
552             * </p>
553             *
554             * @param start the lower bound of the range of class names to return
555             * @param end the upper bound of the range of class names to return (not inclusive)
556             * @return the range of class names
557             * @throws SystemException if a system exception occurred
558             */
559            public List<ClassName> findAll(int start, int end)
560                    throws SystemException {
561                    return findAll(start, end, null);
562            }
563    
564            /**
565             * Finds an ordered range of all the class names.
566             *
567             * <p>
568             * 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.
569             * </p>
570             *
571             * @param start the lower bound of the range of class names to return
572             * @param end the upper bound of the range of class names to return (not inclusive)
573             * @param orderByComparator the comparator to order the results by
574             * @return the ordered range of class names
575             * @throws SystemException if a system exception occurred
576             */
577            public List<ClassName> findAll(int start, int end,
578                    OrderByComparator orderByComparator) throws SystemException {
579                    Object[] finderArgs = new Object[] {
580                                    String.valueOf(start), String.valueOf(end),
581                                    String.valueOf(orderByComparator)
582                            };
583    
584                    List<ClassName> list = (List<ClassName>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
585                                    finderArgs, this);
586    
587                    if (list == null) {
588                            Session session = null;
589    
590                            try {
591                                    session = openSession();
592    
593                                    StringBundler query = null;
594                                    String sql = null;
595    
596                                    if (orderByComparator != null) {
597                                            query = new StringBundler(2 +
598                                                            (orderByComparator.getOrderByFields().length * 3));
599    
600                                            query.append(_SQL_SELECT_CLASSNAME);
601    
602                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
603                                                    orderByComparator);
604    
605                                            sql = query.toString();
606                                    }
607                                    else {
608                                            sql = _SQL_SELECT_CLASSNAME;
609                                    }
610    
611                                    Query q = session.createQuery(sql);
612    
613                                    if (orderByComparator == null) {
614                                            list = (List<ClassName>)QueryUtil.list(q, getDialect(),
615                                                            start, end, false);
616    
617                                            Collections.sort(list);
618                                    }
619                                    else {
620                                            list = (List<ClassName>)QueryUtil.list(q, getDialect(),
621                                                            start, end);
622                                    }
623                            }
624                            catch (Exception e) {
625                                    throw processException(e);
626                            }
627                            finally {
628                                    if (list == null) {
629                                            list = new ArrayList<ClassName>();
630                                    }
631    
632                                    cacheResult(list);
633    
634                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
635    
636                                    closeSession(session);
637                            }
638                    }
639    
640                    return list;
641            }
642    
643            /**
644             * Removes the class name where value = &#63; from the database.
645             *
646             * @param value the value to search with
647             * @throws SystemException if a system exception occurred
648             */
649            public void removeByValue(String value)
650                    throws NoSuchClassNameException, SystemException {
651                    ClassName className = findByValue(value);
652    
653                    remove(className);
654            }
655    
656            /**
657             * Removes all the class names from the database.
658             *
659             * @throws SystemException if a system exception occurred
660             */
661            public void removeAll() throws SystemException {
662                    for (ClassName className : findAll()) {
663                            remove(className);
664                    }
665            }
666    
667            /**
668             * Counts all the class names where value = &#63;.
669             *
670             * @param value the value to search with
671             * @return the number of matching class names
672             * @throws SystemException if a system exception occurred
673             */
674            public int countByValue(String value) throws SystemException {
675                    Object[] finderArgs = new Object[] { value };
676    
677                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_VALUE,
678                                    finderArgs, this);
679    
680                    if (count == null) {
681                            Session session = null;
682    
683                            try {
684                                    session = openSession();
685    
686                                    StringBundler query = new StringBundler(2);
687    
688                                    query.append(_SQL_COUNT_CLASSNAME_WHERE);
689    
690                                    if (value == null) {
691                                            query.append(_FINDER_COLUMN_VALUE_VALUE_1);
692                                    }
693                                    else {
694                                            if (value.equals(StringPool.BLANK)) {
695                                                    query.append(_FINDER_COLUMN_VALUE_VALUE_3);
696                                            }
697                                            else {
698                                                    query.append(_FINDER_COLUMN_VALUE_VALUE_2);
699                                            }
700                                    }
701    
702                                    String sql = query.toString();
703    
704                                    Query q = session.createQuery(sql);
705    
706                                    QueryPos qPos = QueryPos.getInstance(q);
707    
708                                    if (value != null) {
709                                            qPos.add(value);
710                                    }
711    
712                                    count = (Long)q.uniqueResult();
713                            }
714                            catch (Exception e) {
715                                    throw processException(e);
716                            }
717                            finally {
718                                    if (count == null) {
719                                            count = Long.valueOf(0);
720                                    }
721    
722                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_VALUE,
723                                            finderArgs, count);
724    
725                                    closeSession(session);
726                            }
727                    }
728    
729                    return count.intValue();
730            }
731    
732            /**
733             * Counts all the class names.
734             *
735             * @return the number of class names
736             * @throws SystemException if a system exception occurred
737             */
738            public int countAll() throws SystemException {
739                    Object[] finderArgs = new Object[0];
740    
741                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
742                                    finderArgs, this);
743    
744                    if (count == null) {
745                            Session session = null;
746    
747                            try {
748                                    session = openSession();
749    
750                                    Query q = session.createQuery(_SQL_COUNT_CLASSNAME);
751    
752                                    count = (Long)q.uniqueResult();
753                            }
754                            catch (Exception e) {
755                                    throw processException(e);
756                            }
757                            finally {
758                                    if (count == null) {
759                                            count = Long.valueOf(0);
760                                    }
761    
762                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
763                                            count);
764    
765                                    closeSession(session);
766                            }
767                    }
768    
769                    return count.intValue();
770            }
771    
772            /**
773             * Initializes the class name persistence.
774             */
775            public void afterPropertiesSet() {
776                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
777                                            com.liferay.portal.util.PropsUtil.get(
778                                                    "value.object.listener.com.liferay.portal.model.ClassName")));
779    
780                    if (listenerClassNames.length > 0) {
781                            try {
782                                    List<ModelListener<ClassName>> listenersList = new ArrayList<ModelListener<ClassName>>();
783    
784                                    for (String listenerClassName : listenerClassNames) {
785                                            listenersList.add((ModelListener<ClassName>)InstanceFactory.newInstance(
786                                                            listenerClassName));
787                                    }
788    
789                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
790                            }
791                            catch (Exception e) {
792                                    _log.error(e);
793                            }
794                    }
795            }
796    
797            @BeanReference(type = AccountPersistence.class)
798            protected AccountPersistence accountPersistence;
799            @BeanReference(type = AddressPersistence.class)
800            protected AddressPersistence addressPersistence;
801            @BeanReference(type = BrowserTrackerPersistence.class)
802            protected BrowserTrackerPersistence browserTrackerPersistence;
803            @BeanReference(type = ClassNamePersistence.class)
804            protected ClassNamePersistence classNamePersistence;
805            @BeanReference(type = ClusterGroupPersistence.class)
806            protected ClusterGroupPersistence clusterGroupPersistence;
807            @BeanReference(type = CompanyPersistence.class)
808            protected CompanyPersistence companyPersistence;
809            @BeanReference(type = ContactPersistence.class)
810            protected ContactPersistence contactPersistence;
811            @BeanReference(type = CountryPersistence.class)
812            protected CountryPersistence countryPersistence;
813            @BeanReference(type = EmailAddressPersistence.class)
814            protected EmailAddressPersistence emailAddressPersistence;
815            @BeanReference(type = GroupPersistence.class)
816            protected GroupPersistence groupPersistence;
817            @BeanReference(type = ImagePersistence.class)
818            protected ImagePersistence imagePersistence;
819            @BeanReference(type = LayoutPersistence.class)
820            protected LayoutPersistence layoutPersistence;
821            @BeanReference(type = LayoutPrototypePersistence.class)
822            protected LayoutPrototypePersistence layoutPrototypePersistence;
823            @BeanReference(type = LayoutSetPersistence.class)
824            protected LayoutSetPersistence layoutSetPersistence;
825            @BeanReference(type = LayoutSetPrototypePersistence.class)
826            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
827            @BeanReference(type = ListTypePersistence.class)
828            protected ListTypePersistence listTypePersistence;
829            @BeanReference(type = LockPersistence.class)
830            protected LockPersistence lockPersistence;
831            @BeanReference(type = MembershipRequestPersistence.class)
832            protected MembershipRequestPersistence membershipRequestPersistence;
833            @BeanReference(type = OrganizationPersistence.class)
834            protected OrganizationPersistence organizationPersistence;
835            @BeanReference(type = OrgGroupPermissionPersistence.class)
836            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
837            @BeanReference(type = OrgGroupRolePersistence.class)
838            protected OrgGroupRolePersistence orgGroupRolePersistence;
839            @BeanReference(type = OrgLaborPersistence.class)
840            protected OrgLaborPersistence orgLaborPersistence;
841            @BeanReference(type = PasswordPolicyPersistence.class)
842            protected PasswordPolicyPersistence passwordPolicyPersistence;
843            @BeanReference(type = PasswordPolicyRelPersistence.class)
844            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
845            @BeanReference(type = PasswordTrackerPersistence.class)
846            protected PasswordTrackerPersistence passwordTrackerPersistence;
847            @BeanReference(type = PermissionPersistence.class)
848            protected PermissionPersistence permissionPersistence;
849            @BeanReference(type = PhonePersistence.class)
850            protected PhonePersistence phonePersistence;
851            @BeanReference(type = PluginSettingPersistence.class)
852            protected PluginSettingPersistence pluginSettingPersistence;
853            @BeanReference(type = PortletPersistence.class)
854            protected PortletPersistence portletPersistence;
855            @BeanReference(type = PortletItemPersistence.class)
856            protected PortletItemPersistence portletItemPersistence;
857            @BeanReference(type = PortletPreferencesPersistence.class)
858            protected PortletPreferencesPersistence portletPreferencesPersistence;
859            @BeanReference(type = RegionPersistence.class)
860            protected RegionPersistence regionPersistence;
861            @BeanReference(type = ReleasePersistence.class)
862            protected ReleasePersistence releasePersistence;
863            @BeanReference(type = ResourcePersistence.class)
864            protected ResourcePersistence resourcePersistence;
865            @BeanReference(type = ResourceActionPersistence.class)
866            protected ResourceActionPersistence resourceActionPersistence;
867            @BeanReference(type = ResourceCodePersistence.class)
868            protected ResourceCodePersistence resourceCodePersistence;
869            @BeanReference(type = ResourcePermissionPersistence.class)
870            protected ResourcePermissionPersistence resourcePermissionPersistence;
871            @BeanReference(type = RolePersistence.class)
872            protected RolePersistence rolePersistence;
873            @BeanReference(type = ServiceComponentPersistence.class)
874            protected ServiceComponentPersistence serviceComponentPersistence;
875            @BeanReference(type = ShardPersistence.class)
876            protected ShardPersistence shardPersistence;
877            @BeanReference(type = SubscriptionPersistence.class)
878            protected SubscriptionPersistence subscriptionPersistence;
879            @BeanReference(type = TicketPersistence.class)
880            protected TicketPersistence ticketPersistence;
881            @BeanReference(type = TeamPersistence.class)
882            protected TeamPersistence teamPersistence;
883            @BeanReference(type = UserPersistence.class)
884            protected UserPersistence userPersistence;
885            @BeanReference(type = UserGroupPersistence.class)
886            protected UserGroupPersistence userGroupPersistence;
887            @BeanReference(type = UserGroupGroupRolePersistence.class)
888            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
889            @BeanReference(type = UserGroupRolePersistence.class)
890            protected UserGroupRolePersistence userGroupRolePersistence;
891            @BeanReference(type = UserIdMapperPersistence.class)
892            protected UserIdMapperPersistence userIdMapperPersistence;
893            @BeanReference(type = UserTrackerPersistence.class)
894            protected UserTrackerPersistence userTrackerPersistence;
895            @BeanReference(type = UserTrackerPathPersistence.class)
896            protected UserTrackerPathPersistence userTrackerPathPersistence;
897            @BeanReference(type = WebDAVPropsPersistence.class)
898            protected WebDAVPropsPersistence webDAVPropsPersistence;
899            @BeanReference(type = WebsitePersistence.class)
900            protected WebsitePersistence websitePersistence;
901            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
902            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
903            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
904            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
905            private static final String _SQL_SELECT_CLASSNAME = "SELECT className FROM ClassName className";
906            private static final String _SQL_SELECT_CLASSNAME_WHERE = "SELECT className FROM ClassName className WHERE ";
907            private static final String _SQL_COUNT_CLASSNAME = "SELECT COUNT(className) FROM ClassName className";
908            private static final String _SQL_COUNT_CLASSNAME_WHERE = "SELECT COUNT(className) FROM ClassName className WHERE ";
909            private static final String _FINDER_COLUMN_VALUE_VALUE_1 = "className.value IS NULL";
910            private static final String _FINDER_COLUMN_VALUE_VALUE_2 = "className.value = ?";
911            private static final String _FINDER_COLUMN_VALUE_VALUE_3 = "(className.value IS NULL OR className.value = ?)";
912            private static final String _ORDER_BY_ENTITY_ALIAS = "className.";
913            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ClassName exists with the primary key ";
914            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ClassName exists with the key {";
915            private static Log _log = LogFactoryUtil.getLog(ClassNamePersistenceImpl.class);
916    }