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