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