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