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