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