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