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