001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.NoSuchWebDAVPropsException;
018    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderPath;
022    import com.liferay.portal.kernel.dao.orm.Query;
023    import com.liferay.portal.kernel.dao.orm.QueryPos;
024    import com.liferay.portal.kernel.dao.orm.QueryUtil;
025    import com.liferay.portal.kernel.dao.orm.Session;
026    import com.liferay.portal.kernel.exception.SystemException;
027    import com.liferay.portal.kernel.log.Log;
028    import com.liferay.portal.kernel.log.LogFactoryUtil;
029    import com.liferay.portal.kernel.util.GetterUtil;
030    import com.liferay.portal.kernel.util.InstanceFactory;
031    import com.liferay.portal.kernel.util.OrderByComparator;
032    import com.liferay.portal.kernel.util.StringBundler;
033    import com.liferay.portal.kernel.util.StringPool;
034    import com.liferay.portal.kernel.util.StringUtil;
035    import com.liferay.portal.kernel.util.UnmodifiableList;
036    import com.liferay.portal.model.CacheModel;
037    import com.liferay.portal.model.ModelListener;
038    import com.liferay.portal.model.WebDAVProps;
039    import com.liferay.portal.model.impl.WebDAVPropsImpl;
040    import com.liferay.portal.model.impl.WebDAVPropsModelImpl;
041    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042    
043    import java.io.Serializable;
044    
045    import java.util.ArrayList;
046    import java.util.Collections;
047    import java.util.List;
048    
049    /**
050     * The persistence implementation for the web d a v props service.
051     *
052     * <p>
053     * Caching information and settings can be found in <code>portal.properties</code>
054     * </p>
055     *
056     * @author Brian Wing Shun Chan
057     * @see WebDAVPropsPersistence
058     * @see WebDAVPropsUtil
059     * @generated
060     */
061    public class WebDAVPropsPersistenceImpl extends BasePersistenceImpl<WebDAVProps>
062            implements WebDAVPropsPersistence {
063            /*
064             * NOTE FOR DEVELOPERS:
065             *
066             * Never modify or reference this class directly. Always use {@link WebDAVPropsUtil} to access the web d a v props persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
067             */
068            public static final String FINDER_CLASS_NAME_ENTITY = WebDAVPropsImpl.class.getName();
069            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
070                    ".List1";
071            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
072                    ".List2";
073            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
074                            WebDAVPropsModelImpl.FINDER_CACHE_ENABLED, WebDAVPropsImpl.class,
075                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
076            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
077                            WebDAVPropsModelImpl.FINDER_CACHE_ENABLED, WebDAVPropsImpl.class,
078                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
079            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
080                            WebDAVPropsModelImpl.FINDER_CACHE_ENABLED, Long.class,
081                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
082            public static final FinderPath FINDER_PATH_FETCH_BY_C_C = new FinderPath(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
083                            WebDAVPropsModelImpl.FINDER_CACHE_ENABLED, WebDAVPropsImpl.class,
084                            FINDER_CLASS_NAME_ENTITY, "fetchByC_C",
085                            new String[] { Long.class.getName(), Long.class.getName() },
086                            WebDAVPropsModelImpl.CLASSNAMEID_COLUMN_BITMASK |
087                            WebDAVPropsModelImpl.CLASSPK_COLUMN_BITMASK);
088            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
089                            WebDAVPropsModelImpl.FINDER_CACHE_ENABLED, Long.class,
090                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
091                            new String[] { Long.class.getName(), Long.class.getName() });
092    
093            /**
094             * Returns the web d a v props where classNameId = &#63; and classPK = &#63; or throws a {@link com.liferay.portal.NoSuchWebDAVPropsException} if it could not be found.
095             *
096             * @param classNameId the class name ID
097             * @param classPK the class p k
098             * @return the matching web d a v props
099             * @throws com.liferay.portal.NoSuchWebDAVPropsException if a matching web d a v props could not be found
100             * @throws SystemException if a system exception occurred
101             */
102            @Override
103            public WebDAVProps findByC_C(long classNameId, long classPK)
104                    throws NoSuchWebDAVPropsException, SystemException {
105                    WebDAVProps webDAVProps = fetchByC_C(classNameId, classPK);
106    
107                    if (webDAVProps == null) {
108                            StringBundler msg = new StringBundler(6);
109    
110                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
111    
112                            msg.append("classNameId=");
113                            msg.append(classNameId);
114    
115                            msg.append(", classPK=");
116                            msg.append(classPK);
117    
118                            msg.append(StringPool.CLOSE_CURLY_BRACE);
119    
120                            if (_log.isWarnEnabled()) {
121                                    _log.warn(msg.toString());
122                            }
123    
124                            throw new NoSuchWebDAVPropsException(msg.toString());
125                    }
126    
127                    return webDAVProps;
128            }
129    
130            /**
131             * Returns the web d a v props where classNameId = &#63; and classPK = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
132             *
133             * @param classNameId the class name ID
134             * @param classPK the class p k
135             * @return the matching web d a v props, or <code>null</code> if a matching web d a v props could not be found
136             * @throws SystemException if a system exception occurred
137             */
138            @Override
139            public WebDAVProps fetchByC_C(long classNameId, long classPK)
140                    throws SystemException {
141                    return fetchByC_C(classNameId, classPK, true);
142            }
143    
144            /**
145             * Returns the web d a v props where classNameId = &#63; and classPK = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
146             *
147             * @param classNameId the class name ID
148             * @param classPK the class p k
149             * @param retrieveFromCache whether to use the finder cache
150             * @return the matching web d a v props, or <code>null</code> if a matching web d a v props could not be found
151             * @throws SystemException if a system exception occurred
152             */
153            @Override
154            public WebDAVProps fetchByC_C(long classNameId, long classPK,
155                    boolean retrieveFromCache) throws SystemException {
156                    Object[] finderArgs = new Object[] { classNameId, classPK };
157    
158                    Object result = null;
159    
160                    if (retrieveFromCache) {
161                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C,
162                                            finderArgs, this);
163                    }
164    
165                    if (result instanceof WebDAVProps) {
166                            WebDAVProps webDAVProps = (WebDAVProps)result;
167    
168                            if ((classNameId != webDAVProps.getClassNameId()) ||
169                                            (classPK != webDAVProps.getClassPK())) {
170                                    result = null;
171                            }
172                    }
173    
174                    if (result == null) {
175                            StringBundler query = new StringBundler(4);
176    
177                            query.append(_SQL_SELECT_WEBDAVPROPS_WHERE);
178    
179                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
180    
181                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
182    
183                            String sql = query.toString();
184    
185                            Session session = null;
186    
187                            try {
188                                    session = openSession();
189    
190                                    Query q = session.createQuery(sql);
191    
192                                    QueryPos qPos = QueryPos.getInstance(q);
193    
194                                    qPos.add(classNameId);
195    
196                                    qPos.add(classPK);
197    
198                                    List<WebDAVProps> list = q.list();
199    
200                                    if (list.isEmpty()) {
201                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
202                                                    finderArgs, list);
203                                    }
204                                    else {
205                                            WebDAVProps webDAVProps = list.get(0);
206    
207                                            result = webDAVProps;
208    
209                                            cacheResult(webDAVProps);
210    
211                                            if ((webDAVProps.getClassNameId() != classNameId) ||
212                                                            (webDAVProps.getClassPK() != classPK)) {
213                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
214                                                            finderArgs, webDAVProps);
215                                            }
216                                    }
217                            }
218                            catch (Exception e) {
219                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
220                                            finderArgs);
221    
222                                    throw processException(e);
223                            }
224                            finally {
225                                    closeSession(session);
226                            }
227                    }
228    
229                    if (result instanceof List<?>) {
230                            return null;
231                    }
232                    else {
233                            return (WebDAVProps)result;
234                    }
235            }
236    
237            /**
238             * Removes the web d a v props where classNameId = &#63; and classPK = &#63; from the database.
239             *
240             * @param classNameId the class name ID
241             * @param classPK the class p k
242             * @return the web d a v props that was removed
243             * @throws SystemException if a system exception occurred
244             */
245            @Override
246            public WebDAVProps removeByC_C(long classNameId, long classPK)
247                    throws NoSuchWebDAVPropsException, SystemException {
248                    WebDAVProps webDAVProps = findByC_C(classNameId, classPK);
249    
250                    return remove(webDAVProps);
251            }
252    
253            /**
254             * Returns the number of web d a v propses where classNameId = &#63; and classPK = &#63;.
255             *
256             * @param classNameId the class name ID
257             * @param classPK the class p k
258             * @return the number of matching web d a v propses
259             * @throws SystemException if a system exception occurred
260             */
261            @Override
262            public int countByC_C(long classNameId, long classPK)
263                    throws SystemException {
264                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
265    
266                    Object[] finderArgs = new Object[] { classNameId, classPK };
267    
268                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
269                                    this);
270    
271                    if (count == null) {
272                            StringBundler query = new StringBundler(3);
273    
274                            query.append(_SQL_COUNT_WEBDAVPROPS_WHERE);
275    
276                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
277    
278                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
279    
280                            String sql = query.toString();
281    
282                            Session session = null;
283    
284                            try {
285                                    session = openSession();
286    
287                                    Query q = session.createQuery(sql);
288    
289                                    QueryPos qPos = QueryPos.getInstance(q);
290    
291                                    qPos.add(classNameId);
292    
293                                    qPos.add(classPK);
294    
295                                    count = (Long)q.uniqueResult();
296    
297                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
298                            }
299                            catch (Exception e) {
300                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
301    
302                                    throw processException(e);
303                            }
304                            finally {
305                                    closeSession(session);
306                            }
307                    }
308    
309                    return count.intValue();
310            }
311    
312            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "webDAVProps.classNameId = ? AND ";
313            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "webDAVProps.classPK = ?";
314    
315            public WebDAVPropsPersistenceImpl() {
316                    setModelClass(WebDAVProps.class);
317            }
318    
319            /**
320             * Caches the web d a v props in the entity cache if it is enabled.
321             *
322             * @param webDAVProps the web d a v props
323             */
324            @Override
325            public void cacheResult(WebDAVProps webDAVProps) {
326                    EntityCacheUtil.putResult(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
327                            WebDAVPropsImpl.class, webDAVProps.getPrimaryKey(), webDAVProps);
328    
329                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
330                            new Object[] { webDAVProps.getClassNameId(), webDAVProps.getClassPK() },
331                            webDAVProps);
332    
333                    webDAVProps.resetOriginalValues();
334            }
335    
336            /**
337             * Caches the web d a v propses in the entity cache if it is enabled.
338             *
339             * @param webDAVPropses the web d a v propses
340             */
341            @Override
342            public void cacheResult(List<WebDAVProps> webDAVPropses) {
343                    for (WebDAVProps webDAVProps : webDAVPropses) {
344                            if (EntityCacheUtil.getResult(
345                                                    WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
346                                                    WebDAVPropsImpl.class, webDAVProps.getPrimaryKey()) == null) {
347                                    cacheResult(webDAVProps);
348                            }
349                            else {
350                                    webDAVProps.resetOriginalValues();
351                            }
352                    }
353            }
354    
355            /**
356             * Clears the cache for all web d a v propses.
357             *
358             * <p>
359             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
360             * </p>
361             */
362            @Override
363            public void clearCache() {
364                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
365                            CacheRegistryUtil.clear(WebDAVPropsImpl.class.getName());
366                    }
367    
368                    EntityCacheUtil.clearCache(WebDAVPropsImpl.class.getName());
369    
370                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
371                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
372                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
373            }
374    
375            /**
376             * Clears the cache for the web d a v props.
377             *
378             * <p>
379             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
380             * </p>
381             */
382            @Override
383            public void clearCache(WebDAVProps webDAVProps) {
384                    EntityCacheUtil.removeResult(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
385                            WebDAVPropsImpl.class, webDAVProps.getPrimaryKey());
386    
387                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
388                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
389    
390                    clearUniqueFindersCache(webDAVProps);
391            }
392    
393            @Override
394            public void clearCache(List<WebDAVProps> webDAVPropses) {
395                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
396                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
397    
398                    for (WebDAVProps webDAVProps : webDAVPropses) {
399                            EntityCacheUtil.removeResult(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
400                                    WebDAVPropsImpl.class, webDAVProps.getPrimaryKey());
401    
402                            clearUniqueFindersCache(webDAVProps);
403                    }
404            }
405    
406            protected void cacheUniqueFindersCache(WebDAVProps webDAVProps) {
407                    if (webDAVProps.isNew()) {
408                            Object[] args = new Object[] {
409                                            webDAVProps.getClassNameId(), webDAVProps.getClassPK()
410                                    };
411    
412                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, args,
413                                    Long.valueOf(1));
414                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C, args,
415                                    webDAVProps);
416                    }
417                    else {
418                            WebDAVPropsModelImpl webDAVPropsModelImpl = (WebDAVPropsModelImpl)webDAVProps;
419    
420                            if ((webDAVPropsModelImpl.getColumnBitmask() &
421                                            FINDER_PATH_FETCH_BY_C_C.getColumnBitmask()) != 0) {
422                                    Object[] args = new Object[] {
423                                                    webDAVProps.getClassNameId(), webDAVProps.getClassPK()
424                                            };
425    
426                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, args,
427                                            Long.valueOf(1));
428                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C, args,
429                                            webDAVProps);
430                            }
431                    }
432            }
433    
434            protected void clearUniqueFindersCache(WebDAVProps webDAVProps) {
435                    WebDAVPropsModelImpl webDAVPropsModelImpl = (WebDAVPropsModelImpl)webDAVProps;
436    
437                    Object[] args = new Object[] {
438                                    webDAVProps.getClassNameId(), webDAVProps.getClassPK()
439                            };
440    
441                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
442                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C, args);
443    
444                    if ((webDAVPropsModelImpl.getColumnBitmask() &
445                                    FINDER_PATH_FETCH_BY_C_C.getColumnBitmask()) != 0) {
446                            args = new Object[] {
447                                            webDAVPropsModelImpl.getOriginalClassNameId(),
448                                            webDAVPropsModelImpl.getOriginalClassPK()
449                                    };
450    
451                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
452                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C, args);
453                    }
454            }
455    
456            /**
457             * Creates a new web d a v props with the primary key. Does not add the web d a v props to the database.
458             *
459             * @param webDavPropsId the primary key for the new web d a v props
460             * @return the new web d a v props
461             */
462            @Override
463            public WebDAVProps create(long webDavPropsId) {
464                    WebDAVProps webDAVProps = new WebDAVPropsImpl();
465    
466                    webDAVProps.setNew(true);
467                    webDAVProps.setPrimaryKey(webDavPropsId);
468    
469                    return webDAVProps;
470            }
471    
472            /**
473             * Removes the web d a v props with the primary key from the database. Also notifies the appropriate model listeners.
474             *
475             * @param webDavPropsId the primary key of the web d a v props
476             * @return the web d a v props that was removed
477             * @throws com.liferay.portal.NoSuchWebDAVPropsException if a web d a v props with the primary key could not be found
478             * @throws SystemException if a system exception occurred
479             */
480            @Override
481            public WebDAVProps remove(long webDavPropsId)
482                    throws NoSuchWebDAVPropsException, SystemException {
483                    return remove((Serializable)webDavPropsId);
484            }
485    
486            /**
487             * Removes the web d a v props with the primary key from the database. Also notifies the appropriate model listeners.
488             *
489             * @param primaryKey the primary key of the web d a v props
490             * @return the web d a v props that was removed
491             * @throws com.liferay.portal.NoSuchWebDAVPropsException if a web d a v props with the primary key could not be found
492             * @throws SystemException if a system exception occurred
493             */
494            @Override
495            public WebDAVProps remove(Serializable primaryKey)
496                    throws NoSuchWebDAVPropsException, SystemException {
497                    Session session = null;
498    
499                    try {
500                            session = openSession();
501    
502                            WebDAVProps webDAVProps = (WebDAVProps)session.get(WebDAVPropsImpl.class,
503                                            primaryKey);
504    
505                            if (webDAVProps == null) {
506                                    if (_log.isWarnEnabled()) {
507                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
508                                    }
509    
510                                    throw new NoSuchWebDAVPropsException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
511                                            primaryKey);
512                            }
513    
514                            return remove(webDAVProps);
515                    }
516                    catch (NoSuchWebDAVPropsException nsee) {
517                            throw nsee;
518                    }
519                    catch (Exception e) {
520                            throw processException(e);
521                    }
522                    finally {
523                            closeSession(session);
524                    }
525            }
526    
527            @Override
528            protected WebDAVProps removeImpl(WebDAVProps webDAVProps)
529                    throws SystemException {
530                    webDAVProps = toUnwrappedModel(webDAVProps);
531    
532                    Session session = null;
533    
534                    try {
535                            session = openSession();
536    
537                            if (!session.contains(webDAVProps)) {
538                                    webDAVProps = (WebDAVProps)session.get(WebDAVPropsImpl.class,
539                                                    webDAVProps.getPrimaryKeyObj());
540                            }
541    
542                            if (webDAVProps != null) {
543                                    session.delete(webDAVProps);
544                            }
545                    }
546                    catch (Exception e) {
547                            throw processException(e);
548                    }
549                    finally {
550                            closeSession(session);
551                    }
552    
553                    if (webDAVProps != null) {
554                            clearCache(webDAVProps);
555                    }
556    
557                    return webDAVProps;
558            }
559    
560            @Override
561            public WebDAVProps updateImpl(
562                    com.liferay.portal.model.WebDAVProps webDAVProps)
563                    throws SystemException {
564                    webDAVProps = toUnwrappedModel(webDAVProps);
565    
566                    boolean isNew = webDAVProps.isNew();
567    
568                    Session session = null;
569    
570                    try {
571                            session = openSession();
572    
573                            if (webDAVProps.isNew()) {
574                                    session.save(webDAVProps);
575    
576                                    webDAVProps.setNew(false);
577                            }
578                            else {
579                                    session.merge(webDAVProps);
580                            }
581                    }
582                    catch (Exception e) {
583                            throw processException(e);
584                    }
585                    finally {
586                            closeSession(session);
587                    }
588    
589                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
590    
591                    if (isNew || !WebDAVPropsModelImpl.COLUMN_BITMASK_ENABLED) {
592                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
593                    }
594    
595                    EntityCacheUtil.putResult(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
596                            WebDAVPropsImpl.class, webDAVProps.getPrimaryKey(), webDAVProps);
597    
598                    clearUniqueFindersCache(webDAVProps);
599                    cacheUniqueFindersCache(webDAVProps);
600    
601                    return webDAVProps;
602            }
603    
604            protected WebDAVProps toUnwrappedModel(WebDAVProps webDAVProps) {
605                    if (webDAVProps instanceof WebDAVPropsImpl) {
606                            return webDAVProps;
607                    }
608    
609                    WebDAVPropsImpl webDAVPropsImpl = new WebDAVPropsImpl();
610    
611                    webDAVPropsImpl.setNew(webDAVProps.isNew());
612                    webDAVPropsImpl.setPrimaryKey(webDAVProps.getPrimaryKey());
613    
614                    webDAVPropsImpl.setWebDavPropsId(webDAVProps.getWebDavPropsId());
615                    webDAVPropsImpl.setCompanyId(webDAVProps.getCompanyId());
616                    webDAVPropsImpl.setCreateDate(webDAVProps.getCreateDate());
617                    webDAVPropsImpl.setModifiedDate(webDAVProps.getModifiedDate());
618                    webDAVPropsImpl.setClassNameId(webDAVProps.getClassNameId());
619                    webDAVPropsImpl.setClassPK(webDAVProps.getClassPK());
620                    webDAVPropsImpl.setProps(webDAVProps.getProps());
621    
622                    return webDAVPropsImpl;
623            }
624    
625            /**
626             * Returns the web d a v props with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
627             *
628             * @param primaryKey the primary key of the web d a v props
629             * @return the web d a v props
630             * @throws com.liferay.portal.NoSuchWebDAVPropsException if a web d a v props with the primary key could not be found
631             * @throws SystemException if a system exception occurred
632             */
633            @Override
634            public WebDAVProps findByPrimaryKey(Serializable primaryKey)
635                    throws NoSuchWebDAVPropsException, SystemException {
636                    WebDAVProps webDAVProps = fetchByPrimaryKey(primaryKey);
637    
638                    if (webDAVProps == null) {
639                            if (_log.isWarnEnabled()) {
640                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
641                            }
642    
643                            throw new NoSuchWebDAVPropsException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
644                                    primaryKey);
645                    }
646    
647                    return webDAVProps;
648            }
649    
650            /**
651             * Returns the web d a v props with the primary key or throws a {@link com.liferay.portal.NoSuchWebDAVPropsException} if it could not be found.
652             *
653             * @param webDavPropsId the primary key of the web d a v props
654             * @return the web d a v props
655             * @throws com.liferay.portal.NoSuchWebDAVPropsException if a web d a v props with the primary key could not be found
656             * @throws SystemException if a system exception occurred
657             */
658            @Override
659            public WebDAVProps findByPrimaryKey(long webDavPropsId)
660                    throws NoSuchWebDAVPropsException, SystemException {
661                    return findByPrimaryKey((Serializable)webDavPropsId);
662            }
663    
664            /**
665             * Returns the web d a v props with the primary key or returns <code>null</code> if it could not be found.
666             *
667             * @param primaryKey the primary key of the web d a v props
668             * @return the web d a v props, or <code>null</code> if a web d a v props with the primary key could not be found
669             * @throws SystemException if a system exception occurred
670             */
671            @Override
672            public WebDAVProps fetchByPrimaryKey(Serializable primaryKey)
673                    throws SystemException {
674                    WebDAVProps webDAVProps = (WebDAVProps)EntityCacheUtil.getResult(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
675                                    WebDAVPropsImpl.class, primaryKey);
676    
677                    if (webDAVProps == _nullWebDAVProps) {
678                            return null;
679                    }
680    
681                    if (webDAVProps == null) {
682                            Session session = null;
683    
684                            try {
685                                    session = openSession();
686    
687                                    webDAVProps = (WebDAVProps)session.get(WebDAVPropsImpl.class,
688                                                    primaryKey);
689    
690                                    if (webDAVProps != null) {
691                                            cacheResult(webDAVProps);
692                                    }
693                                    else {
694                                            EntityCacheUtil.putResult(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
695                                                    WebDAVPropsImpl.class, primaryKey, _nullWebDAVProps);
696                                    }
697                            }
698                            catch (Exception e) {
699                                    EntityCacheUtil.removeResult(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
700                                            WebDAVPropsImpl.class, primaryKey);
701    
702                                    throw processException(e);
703                            }
704                            finally {
705                                    closeSession(session);
706                            }
707                    }
708    
709                    return webDAVProps;
710            }
711    
712            /**
713             * Returns the web d a v props with the primary key or returns <code>null</code> if it could not be found.
714             *
715             * @param webDavPropsId the primary key of the web d a v props
716             * @return the web d a v props, or <code>null</code> if a web d a v props with the primary key could not be found
717             * @throws SystemException if a system exception occurred
718             */
719            @Override
720            public WebDAVProps fetchByPrimaryKey(long webDavPropsId)
721                    throws SystemException {
722                    return fetchByPrimaryKey((Serializable)webDavPropsId);
723            }
724    
725            /**
726             * Returns all the web d a v propses.
727             *
728             * @return the web d a v propses
729             * @throws SystemException if a system exception occurred
730             */
731            @Override
732            public List<WebDAVProps> findAll() throws SystemException {
733                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
734            }
735    
736            /**
737             * Returns a range of all the web d a v propses.
738             *
739             * <p>
740             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.WebDAVPropsModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
741             * </p>
742             *
743             * @param start the lower bound of the range of web d a v propses
744             * @param end the upper bound of the range of web d a v propses (not inclusive)
745             * @return the range of web d a v propses
746             * @throws SystemException if a system exception occurred
747             */
748            @Override
749            public List<WebDAVProps> findAll(int start, int end)
750                    throws SystemException {
751                    return findAll(start, end, null);
752            }
753    
754            /**
755             * Returns an ordered range of all the web d a v propses.
756             *
757             * <p>
758             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.WebDAVPropsModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
759             * </p>
760             *
761             * @param start the lower bound of the range of web d a v propses
762             * @param end the upper bound of the range of web d a v propses (not inclusive)
763             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
764             * @return the ordered range of web d a v propses
765             * @throws SystemException if a system exception occurred
766             */
767            @Override
768            public List<WebDAVProps> findAll(int start, int end,
769                    OrderByComparator orderByComparator) throws SystemException {
770                    boolean pagination = true;
771                    FinderPath finderPath = null;
772                    Object[] finderArgs = null;
773    
774                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
775                                    (orderByComparator == null)) {
776                            pagination = false;
777                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
778                            finderArgs = FINDER_ARGS_EMPTY;
779                    }
780                    else {
781                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
782                            finderArgs = new Object[] { start, end, orderByComparator };
783                    }
784    
785                    List<WebDAVProps> list = (List<WebDAVProps>)FinderCacheUtil.getResult(finderPath,
786                                    finderArgs, this);
787    
788                    if (list == null) {
789                            StringBundler query = null;
790                            String sql = null;
791    
792                            if (orderByComparator != null) {
793                                    query = new StringBundler(2 +
794                                                    (orderByComparator.getOrderByFields().length * 3));
795    
796                                    query.append(_SQL_SELECT_WEBDAVPROPS);
797    
798                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
799                                            orderByComparator);
800    
801                                    sql = query.toString();
802                            }
803                            else {
804                                    sql = _SQL_SELECT_WEBDAVPROPS;
805    
806                                    if (pagination) {
807                                            sql = sql.concat(WebDAVPropsModelImpl.ORDER_BY_JPQL);
808                                    }
809                            }
810    
811                            Session session = null;
812    
813                            try {
814                                    session = openSession();
815    
816                                    Query q = session.createQuery(sql);
817    
818                                    if (!pagination) {
819                                            list = (List<WebDAVProps>)QueryUtil.list(q, getDialect(),
820                                                            start, end, false);
821    
822                                            Collections.sort(list);
823    
824                                            list = new UnmodifiableList<WebDAVProps>(list);
825                                    }
826                                    else {
827                                            list = (List<WebDAVProps>)QueryUtil.list(q, getDialect(),
828                                                            start, end);
829                                    }
830    
831                                    cacheResult(list);
832    
833                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
834                            }
835                            catch (Exception e) {
836                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
837    
838                                    throw processException(e);
839                            }
840                            finally {
841                                    closeSession(session);
842                            }
843                    }
844    
845                    return list;
846            }
847    
848            /**
849             * Removes all the web d a v propses from the database.
850             *
851             * @throws SystemException if a system exception occurred
852             */
853            @Override
854            public void removeAll() throws SystemException {
855                    for (WebDAVProps webDAVProps : findAll()) {
856                            remove(webDAVProps);
857                    }
858            }
859    
860            /**
861             * Returns the number of web d a v propses.
862             *
863             * @return the number of web d a v propses
864             * @throws SystemException if a system exception occurred
865             */
866            @Override
867            public int countAll() throws SystemException {
868                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
869                                    FINDER_ARGS_EMPTY, this);
870    
871                    if (count == null) {
872                            Session session = null;
873    
874                            try {
875                                    session = openSession();
876    
877                                    Query q = session.createQuery(_SQL_COUNT_WEBDAVPROPS);
878    
879                                    count = (Long)q.uniqueResult();
880    
881                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
882                                            FINDER_ARGS_EMPTY, count);
883                            }
884                            catch (Exception e) {
885                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
886                                            FINDER_ARGS_EMPTY);
887    
888                                    throw processException(e);
889                            }
890                            finally {
891                                    closeSession(session);
892                            }
893                    }
894    
895                    return count.intValue();
896            }
897    
898            /**
899             * Initializes the web d a v props persistence.
900             */
901            public void afterPropertiesSet() {
902                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
903                                            com.liferay.portal.util.PropsUtil.get(
904                                                    "value.object.listener.com.liferay.portal.model.WebDAVProps")));
905    
906                    if (listenerClassNames.length > 0) {
907                            try {
908                                    List<ModelListener<WebDAVProps>> listenersList = new ArrayList<ModelListener<WebDAVProps>>();
909    
910                                    for (String listenerClassName : listenerClassNames) {
911                                            listenersList.add((ModelListener<WebDAVProps>)InstanceFactory.newInstance(
912                                                            getClassLoader(), listenerClassName));
913                                    }
914    
915                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
916                            }
917                            catch (Exception e) {
918                                    _log.error(e);
919                            }
920                    }
921            }
922    
923            public void destroy() {
924                    EntityCacheUtil.removeCache(WebDAVPropsImpl.class.getName());
925                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
926                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
927                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
928            }
929    
930            private static final String _SQL_SELECT_WEBDAVPROPS = "SELECT webDAVProps FROM WebDAVProps webDAVProps";
931            private static final String _SQL_SELECT_WEBDAVPROPS_WHERE = "SELECT webDAVProps FROM WebDAVProps webDAVProps WHERE ";
932            private static final String _SQL_COUNT_WEBDAVPROPS = "SELECT COUNT(webDAVProps) FROM WebDAVProps webDAVProps";
933            private static final String _SQL_COUNT_WEBDAVPROPS_WHERE = "SELECT COUNT(webDAVProps) FROM WebDAVProps webDAVProps WHERE ";
934            private static final String _ORDER_BY_ENTITY_ALIAS = "webDAVProps.";
935            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No WebDAVProps exists with the primary key ";
936            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No WebDAVProps exists with the key {";
937            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
938            private static Log _log = LogFactoryUtil.getLog(WebDAVPropsPersistenceImpl.class);
939            private static WebDAVProps _nullWebDAVProps = new WebDAVPropsImpl() {
940                            @Override
941                            public Object clone() {
942                                    return this;
943                            }
944    
945                            @Override
946                            public CacheModel<WebDAVProps> toCacheModel() {
947                                    return _nullWebDAVPropsCacheModel;
948                            }
949                    };
950    
951            private static CacheModel<WebDAVProps> _nullWebDAVPropsCacheModel = new CacheModel<WebDAVProps>() {
952                            @Override
953                            public WebDAVProps toEntityModel() {
954                                    return _nullWebDAVProps;
955                            }
956                    };
957    }