001    /**
002     * Copyright (c) 2000-present 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.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.NoSuchWebDAVPropsException;
020    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderPath;
024    import com.liferay.portal.kernel.dao.orm.Query;
025    import com.liferay.portal.kernel.dao.orm.QueryPos;
026    import com.liferay.portal.kernel.dao.orm.QueryUtil;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.OrderByComparator;
031    import com.liferay.portal.kernel.util.StringBundler;
032    import com.liferay.portal.kernel.util.StringPool;
033    import com.liferay.portal.model.CacheModel;
034    import com.liferay.portal.model.MVCCModel;
035    import com.liferay.portal.model.WebDAVProps;
036    import com.liferay.portal.model.impl.WebDAVPropsImpl;
037    import com.liferay.portal.model.impl.WebDAVPropsModelImpl;
038    import com.liferay.portal.service.persistence.WebDAVPropsPersistence;
039    
040    import java.io.Serializable;
041    
042    import java.util.Collections;
043    import java.util.HashMap;
044    import java.util.HashSet;
045    import java.util.Iterator;
046    import java.util.List;
047    import java.util.Map;
048    import java.util.Set;
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    @ProviderType
063    public class WebDAVPropsPersistenceImpl extends BasePersistenceImpl<WebDAVProps>
064            implements WebDAVPropsPersistence {
065            /*
066             * NOTE FOR DEVELOPERS:
067             *
068             * 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.
069             */
070            public static final String FINDER_CLASS_NAME_ENTITY = WebDAVPropsImpl.class.getName();
071            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
072                    ".List1";
073            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074                    ".List2";
075            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
076                            WebDAVPropsModelImpl.FINDER_CACHE_ENABLED, WebDAVPropsImpl.class,
077                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
078            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
079                            WebDAVPropsModelImpl.FINDER_CACHE_ENABLED, WebDAVPropsImpl.class,
080                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
081            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
082                            WebDAVPropsModelImpl.FINDER_CACHE_ENABLED, Long.class,
083                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
084            public static final FinderPath FINDER_PATH_FETCH_BY_C_C = new FinderPath(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
085                            WebDAVPropsModelImpl.FINDER_CACHE_ENABLED, WebDAVPropsImpl.class,
086                            FINDER_CLASS_NAME_ENTITY, "fetchByC_C",
087                            new String[] { Long.class.getName(), Long.class.getName() },
088                            WebDAVPropsModelImpl.CLASSNAMEID_COLUMN_BITMASK |
089                            WebDAVPropsModelImpl.CLASSPK_COLUMN_BITMASK);
090            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
091                            WebDAVPropsModelImpl.FINDER_CACHE_ENABLED, Long.class,
092                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
093                            new String[] { Long.class.getName(), Long.class.getName() });
094    
095            /**
096             * 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.
097             *
098             * @param classNameId the class name ID
099             * @param classPK the class p k
100             * @return the matching web d a v props
101             * @throws com.liferay.portal.NoSuchWebDAVPropsException if a matching web d a v props could not be found
102             */
103            @Override
104            public WebDAVProps findByC_C(long classNameId, long classPK)
105                    throws NoSuchWebDAVPropsException {
106                    WebDAVProps webDAVProps = fetchByC_C(classNameId, classPK);
107    
108                    if (webDAVProps == null) {
109                            StringBundler msg = new StringBundler(6);
110    
111                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
112    
113                            msg.append("classNameId=");
114                            msg.append(classNameId);
115    
116                            msg.append(", classPK=");
117                            msg.append(classPK);
118    
119                            msg.append(StringPool.CLOSE_CURLY_BRACE);
120    
121                            if (_log.isWarnEnabled()) {
122                                    _log.warn(msg.toString());
123                            }
124    
125                            throw new NoSuchWebDAVPropsException(msg.toString());
126                    }
127    
128                    return webDAVProps;
129            }
130    
131            /**
132             * 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.
133             *
134             * @param classNameId the class name ID
135             * @param classPK the class p k
136             * @return the matching web d a v props, or <code>null</code> if a matching web d a v props could not be found
137             */
138            @Override
139            public WebDAVProps fetchByC_C(long classNameId, long classPK) {
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             */
151            @Override
152            public WebDAVProps fetchByC_C(long classNameId, long classPK,
153                    boolean retrieveFromCache) {
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             */
242            @Override
243            public WebDAVProps removeByC_C(long classNameId, long classPK)
244                    throws NoSuchWebDAVPropsException {
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             */
257            @Override
258            public int countByC_C(long classNameId, long classPK) {
259                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
260    
261                    Object[] finderArgs = new Object[] { classNameId, classPK };
262    
263                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
264                                    this);
265    
266                    if (count == null) {
267                            StringBundler query = new StringBundler(3);
268    
269                            query.append(_SQL_COUNT_WEBDAVPROPS_WHERE);
270    
271                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
272    
273                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
274    
275                            String sql = query.toString();
276    
277                            Session session = null;
278    
279                            try {
280                                    session = openSession();
281    
282                                    Query q = session.createQuery(sql);
283    
284                                    QueryPos qPos = QueryPos.getInstance(q);
285    
286                                    qPos.add(classNameId);
287    
288                                    qPos.add(classPK);
289    
290                                    count = (Long)q.uniqueResult();
291    
292                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
293                            }
294                            catch (Exception e) {
295                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
296    
297                                    throw processException(e);
298                            }
299                            finally {
300                                    closeSession(session);
301                            }
302                    }
303    
304                    return count.intValue();
305            }
306    
307            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "webDAVProps.classNameId = ? AND ";
308            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "webDAVProps.classPK = ?";
309    
310            public WebDAVPropsPersistenceImpl() {
311                    setModelClass(WebDAVProps.class);
312            }
313    
314            /**
315             * Caches the web d a v props in the entity cache if it is enabled.
316             *
317             * @param webDAVProps the web d a v props
318             */
319            @Override
320            public void cacheResult(WebDAVProps webDAVProps) {
321                    EntityCacheUtil.putResult(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
322                            WebDAVPropsImpl.class, webDAVProps.getPrimaryKey(), webDAVProps);
323    
324                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
325                            new Object[] { webDAVProps.getClassNameId(), webDAVProps.getClassPK() },
326                            webDAVProps);
327    
328                    webDAVProps.resetOriginalValues();
329            }
330    
331            /**
332             * Caches the web d a v propses in the entity cache if it is enabled.
333             *
334             * @param webDAVPropses the web d a v propses
335             */
336            @Override
337            public void cacheResult(List<WebDAVProps> webDAVPropses) {
338                    for (WebDAVProps webDAVProps : webDAVPropses) {
339                            if (EntityCacheUtil.getResult(
340                                                    WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
341                                                    WebDAVPropsImpl.class, webDAVProps.getPrimaryKey()) == null) {
342                                    cacheResult(webDAVProps);
343                            }
344                            else {
345                                    webDAVProps.resetOriginalValues();
346                            }
347                    }
348            }
349    
350            /**
351             * Clears the cache for all web d a v propses.
352             *
353             * <p>
354             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
355             * </p>
356             */
357            @Override
358            public void clearCache() {
359                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
360                            CacheRegistryUtil.clear(WebDAVPropsImpl.class.getName());
361                    }
362    
363                    EntityCacheUtil.clearCache(WebDAVPropsImpl.class);
364    
365                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
366                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
367                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
368            }
369    
370            /**
371             * Clears the cache for the web d a v props.
372             *
373             * <p>
374             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
375             * </p>
376             */
377            @Override
378            public void clearCache(WebDAVProps webDAVProps) {
379                    EntityCacheUtil.removeResult(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
380                            WebDAVPropsImpl.class, webDAVProps.getPrimaryKey());
381    
382                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
383                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
384    
385                    clearUniqueFindersCache(webDAVProps);
386            }
387    
388            @Override
389            public void clearCache(List<WebDAVProps> webDAVPropses) {
390                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
391                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
392    
393                    for (WebDAVProps webDAVProps : webDAVPropses) {
394                            EntityCacheUtil.removeResult(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
395                                    WebDAVPropsImpl.class, webDAVProps.getPrimaryKey());
396    
397                            clearUniqueFindersCache(webDAVProps);
398                    }
399            }
400    
401            protected void cacheUniqueFindersCache(WebDAVProps webDAVProps) {
402                    if (webDAVProps.isNew()) {
403                            Object[] args = new Object[] {
404                                            webDAVProps.getClassNameId(), webDAVProps.getClassPK()
405                                    };
406    
407                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, args,
408                                    Long.valueOf(1));
409                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C, args,
410                                    webDAVProps);
411                    }
412                    else {
413                            WebDAVPropsModelImpl webDAVPropsModelImpl = (WebDAVPropsModelImpl)webDAVProps;
414    
415                            if ((webDAVPropsModelImpl.getColumnBitmask() &
416                                            FINDER_PATH_FETCH_BY_C_C.getColumnBitmask()) != 0) {
417                                    Object[] args = new Object[] {
418                                                    webDAVProps.getClassNameId(), webDAVProps.getClassPK()
419                                            };
420    
421                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, args,
422                                            Long.valueOf(1));
423                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C, args,
424                                            webDAVProps);
425                            }
426                    }
427            }
428    
429            protected void clearUniqueFindersCache(WebDAVProps webDAVProps) {
430                    WebDAVPropsModelImpl webDAVPropsModelImpl = (WebDAVPropsModelImpl)webDAVProps;
431    
432                    Object[] args = new Object[] {
433                                    webDAVProps.getClassNameId(), 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                                            webDAVPropsModelImpl.getOriginalClassNameId(),
443                                            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            @Override
458            public WebDAVProps create(long webDavPropsId) {
459                    WebDAVProps webDAVProps = new WebDAVPropsImpl();
460    
461                    webDAVProps.setNew(true);
462                    webDAVProps.setPrimaryKey(webDavPropsId);
463    
464                    return webDAVProps;
465            }
466    
467            /**
468             * Removes the web d a v props with the primary key from the database. Also notifies the appropriate model listeners.
469             *
470             * @param webDavPropsId the primary key of the web d a v props
471             * @return the web d a v props that was removed
472             * @throws com.liferay.portal.NoSuchWebDAVPropsException if a web d a v props with the primary key could not be found
473             */
474            @Override
475            public WebDAVProps remove(long webDavPropsId)
476                    throws NoSuchWebDAVPropsException {
477                    return remove((Serializable)webDavPropsId);
478            }
479    
480            /**
481             * Removes the web d a v props with the primary key from the database. Also notifies the appropriate model listeners.
482             *
483             * @param primaryKey the primary key of the web d a v props
484             * @return the web d a v props that was removed
485             * @throws com.liferay.portal.NoSuchWebDAVPropsException if a web d a v props with the primary key could not be found
486             */
487            @Override
488            public WebDAVProps remove(Serializable primaryKey)
489                    throws NoSuchWebDAVPropsException {
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                    webDAVProps = toUnwrappedModel(webDAVProps);
523    
524                    Session session = null;
525    
526                    try {
527                            session = openSession();
528    
529                            if (!session.contains(webDAVProps)) {
530                                    webDAVProps = (WebDAVProps)session.get(WebDAVPropsImpl.class,
531                                                    webDAVProps.getPrimaryKeyObj());
532                            }
533    
534                            if (webDAVProps != null) {
535                                    session.delete(webDAVProps);
536                            }
537                    }
538                    catch (Exception e) {
539                            throw processException(e);
540                    }
541                    finally {
542                            closeSession(session);
543                    }
544    
545                    if (webDAVProps != null) {
546                            clearCache(webDAVProps);
547                    }
548    
549                    return webDAVProps;
550            }
551    
552            @Override
553            public WebDAVProps updateImpl(
554                    com.liferay.portal.model.WebDAVProps webDAVProps) {
555                    webDAVProps = toUnwrappedModel(webDAVProps);
556    
557                    boolean isNew = webDAVProps.isNew();
558    
559                    Session session = null;
560    
561                    try {
562                            session = openSession();
563    
564                            if (webDAVProps.isNew()) {
565                                    session.save(webDAVProps);
566    
567                                    webDAVProps.setNew(false);
568                            }
569                            else {
570                                    session.merge(webDAVProps);
571                            }
572                    }
573                    catch (Exception e) {
574                            throw processException(e);
575                    }
576                    finally {
577                            closeSession(session);
578                    }
579    
580                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
581    
582                    if (isNew || !WebDAVPropsModelImpl.COLUMN_BITMASK_ENABLED) {
583                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
584                    }
585    
586                    EntityCacheUtil.putResult(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
587                            WebDAVPropsImpl.class, webDAVProps.getPrimaryKey(), webDAVProps,
588                            false);
589    
590                    clearUniqueFindersCache(webDAVProps);
591                    cacheUniqueFindersCache(webDAVProps);
592    
593                    webDAVProps.resetOriginalValues();
594    
595                    return webDAVProps;
596            }
597    
598            protected WebDAVProps toUnwrappedModel(WebDAVProps webDAVProps) {
599                    if (webDAVProps instanceof WebDAVPropsImpl) {
600                            return webDAVProps;
601                    }
602    
603                    WebDAVPropsImpl webDAVPropsImpl = new WebDAVPropsImpl();
604    
605                    webDAVPropsImpl.setNew(webDAVProps.isNew());
606                    webDAVPropsImpl.setPrimaryKey(webDAVProps.getPrimaryKey());
607    
608                    webDAVPropsImpl.setMvccVersion(webDAVProps.getMvccVersion());
609                    webDAVPropsImpl.setWebDavPropsId(webDAVProps.getWebDavPropsId());
610                    webDAVPropsImpl.setCompanyId(webDAVProps.getCompanyId());
611                    webDAVPropsImpl.setCreateDate(webDAVProps.getCreateDate());
612                    webDAVPropsImpl.setModifiedDate(webDAVProps.getModifiedDate());
613                    webDAVPropsImpl.setClassNameId(webDAVProps.getClassNameId());
614                    webDAVPropsImpl.setClassPK(webDAVProps.getClassPK());
615                    webDAVPropsImpl.setProps(webDAVProps.getProps());
616    
617                    return webDAVPropsImpl;
618            }
619    
620            /**
621             * 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.
622             *
623             * @param primaryKey the primary key of the web d a v props
624             * @return the web d a v props
625             * @throws com.liferay.portal.NoSuchWebDAVPropsException if a web d a v props with the primary key could not be found
626             */
627            @Override
628            public WebDAVProps findByPrimaryKey(Serializable primaryKey)
629                    throws NoSuchWebDAVPropsException {
630                    WebDAVProps webDAVProps = fetchByPrimaryKey(primaryKey);
631    
632                    if (webDAVProps == null) {
633                            if (_log.isWarnEnabled()) {
634                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
635                            }
636    
637                            throw new NoSuchWebDAVPropsException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
638                                    primaryKey);
639                    }
640    
641                    return webDAVProps;
642            }
643    
644            /**
645             * 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.
646             *
647             * @param webDavPropsId the primary key of the web d a v props
648             * @return the web d a v props
649             * @throws com.liferay.portal.NoSuchWebDAVPropsException if a web d a v props with the primary key could not be found
650             */
651            @Override
652            public WebDAVProps findByPrimaryKey(long webDavPropsId)
653                    throws NoSuchWebDAVPropsException {
654                    return findByPrimaryKey((Serializable)webDavPropsId);
655            }
656    
657            /**
658             * Returns the web d a v props with the primary key or returns <code>null</code> if it could not be found.
659             *
660             * @param primaryKey the primary key of the web d a v props
661             * @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
662             */
663            @Override
664            public WebDAVProps fetchByPrimaryKey(Serializable primaryKey) {
665                    WebDAVProps webDAVProps = (WebDAVProps)EntityCacheUtil.getResult(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
666                                    WebDAVPropsImpl.class, primaryKey);
667    
668                    if (webDAVProps == _nullWebDAVProps) {
669                            return null;
670                    }
671    
672                    if (webDAVProps == null) {
673                            Session session = null;
674    
675                            try {
676                                    session = openSession();
677    
678                                    webDAVProps = (WebDAVProps)session.get(WebDAVPropsImpl.class,
679                                                    primaryKey);
680    
681                                    if (webDAVProps != null) {
682                                            cacheResult(webDAVProps);
683                                    }
684                                    else {
685                                            EntityCacheUtil.putResult(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
686                                                    WebDAVPropsImpl.class, primaryKey, _nullWebDAVProps);
687                                    }
688                            }
689                            catch (Exception e) {
690                                    EntityCacheUtil.removeResult(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
691                                            WebDAVPropsImpl.class, primaryKey);
692    
693                                    throw processException(e);
694                            }
695                            finally {
696                                    closeSession(session);
697                            }
698                    }
699    
700                    return webDAVProps;
701            }
702    
703            /**
704             * Returns the web d a v props with the primary key or returns <code>null</code> if it could not be found.
705             *
706             * @param webDavPropsId the primary key of the web d a v props
707             * @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
708             */
709            @Override
710            public WebDAVProps fetchByPrimaryKey(long webDavPropsId) {
711                    return fetchByPrimaryKey((Serializable)webDavPropsId);
712            }
713    
714            @Override
715            public Map<Serializable, WebDAVProps> fetchByPrimaryKeys(
716                    Set<Serializable> primaryKeys) {
717                    if (primaryKeys.isEmpty()) {
718                            return Collections.emptyMap();
719                    }
720    
721                    Map<Serializable, WebDAVProps> map = new HashMap<Serializable, WebDAVProps>();
722    
723                    if (primaryKeys.size() == 1) {
724                            Iterator<Serializable> iterator = primaryKeys.iterator();
725    
726                            Serializable primaryKey = iterator.next();
727    
728                            WebDAVProps webDAVProps = fetchByPrimaryKey(primaryKey);
729    
730                            if (webDAVProps != null) {
731                                    map.put(primaryKey, webDAVProps);
732                            }
733    
734                            return map;
735                    }
736    
737                    Set<Serializable> uncachedPrimaryKeys = null;
738    
739                    for (Serializable primaryKey : primaryKeys) {
740                            WebDAVProps webDAVProps = (WebDAVProps)EntityCacheUtil.getResult(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
741                                            WebDAVPropsImpl.class, primaryKey);
742    
743                            if (webDAVProps == null) {
744                                    if (uncachedPrimaryKeys == null) {
745                                            uncachedPrimaryKeys = new HashSet<Serializable>();
746                                    }
747    
748                                    uncachedPrimaryKeys.add(primaryKey);
749                            }
750                            else {
751                                    map.put(primaryKey, webDAVProps);
752                            }
753                    }
754    
755                    if (uncachedPrimaryKeys == null) {
756                            return map;
757                    }
758    
759                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
760                                    1);
761    
762                    query.append(_SQL_SELECT_WEBDAVPROPS_WHERE_PKS_IN);
763    
764                    for (Serializable primaryKey : uncachedPrimaryKeys) {
765                            query.append(String.valueOf(primaryKey));
766    
767                            query.append(StringPool.COMMA);
768                    }
769    
770                    query.setIndex(query.index() - 1);
771    
772                    query.append(StringPool.CLOSE_PARENTHESIS);
773    
774                    String sql = query.toString();
775    
776                    Session session = null;
777    
778                    try {
779                            session = openSession();
780    
781                            Query q = session.createQuery(sql);
782    
783                            for (WebDAVProps webDAVProps : (List<WebDAVProps>)q.list()) {
784                                    map.put(webDAVProps.getPrimaryKeyObj(), webDAVProps);
785    
786                                    cacheResult(webDAVProps);
787    
788                                    uncachedPrimaryKeys.remove(webDAVProps.getPrimaryKeyObj());
789                            }
790    
791                            for (Serializable primaryKey : uncachedPrimaryKeys) {
792                                    EntityCacheUtil.putResult(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
793                                            WebDAVPropsImpl.class, primaryKey, _nullWebDAVProps);
794                            }
795                    }
796                    catch (Exception e) {
797                            throw processException(e);
798                    }
799                    finally {
800                            closeSession(session);
801                    }
802    
803                    return map;
804            }
805    
806            /**
807             * Returns all the web d a v propses.
808             *
809             * @return the web d a v propses
810             */
811            @Override
812            public List<WebDAVProps> findAll() {
813                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
814            }
815    
816            /**
817             * Returns a range of all the web d a v propses.
818             *
819             * <p>
820             * 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.
821             * </p>
822             *
823             * @param start the lower bound of the range of web d a v propses
824             * @param end the upper bound of the range of web d a v propses (not inclusive)
825             * @return the range of web d a v propses
826             */
827            @Override
828            public List<WebDAVProps> findAll(int start, int end) {
829                    return findAll(start, end, null);
830            }
831    
832            /**
833             * Returns an ordered range of all the web d a v propses.
834             *
835             * <p>
836             * 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.
837             * </p>
838             *
839             * @param start the lower bound of the range of web d a v propses
840             * @param end the upper bound of the range of web d a v propses (not inclusive)
841             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
842             * @return the ordered range of web d a v propses
843             */
844            @Override
845            public List<WebDAVProps> findAll(int start, int end,
846                    OrderByComparator<WebDAVProps> orderByComparator) {
847                    boolean pagination = true;
848                    FinderPath finderPath = null;
849                    Object[] finderArgs = null;
850    
851                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
852                                    (orderByComparator == null)) {
853                            pagination = false;
854                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
855                            finderArgs = FINDER_ARGS_EMPTY;
856                    }
857                    else {
858                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
859                            finderArgs = new Object[] { start, end, orderByComparator };
860                    }
861    
862                    List<WebDAVProps> list = (List<WebDAVProps>)FinderCacheUtil.getResult(finderPath,
863                                    finderArgs, this);
864    
865                    if (list == null) {
866                            StringBundler query = null;
867                            String sql = null;
868    
869                            if (orderByComparator != null) {
870                                    query = new StringBundler(2 +
871                                                    (orderByComparator.getOrderByFields().length * 3));
872    
873                                    query.append(_SQL_SELECT_WEBDAVPROPS);
874    
875                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
876                                            orderByComparator);
877    
878                                    sql = query.toString();
879                            }
880                            else {
881                                    sql = _SQL_SELECT_WEBDAVPROPS;
882    
883                                    if (pagination) {
884                                            sql = sql.concat(WebDAVPropsModelImpl.ORDER_BY_JPQL);
885                                    }
886                            }
887    
888                            Session session = null;
889    
890                            try {
891                                    session = openSession();
892    
893                                    Query q = session.createQuery(sql);
894    
895                                    if (!pagination) {
896                                            list = (List<WebDAVProps>)QueryUtil.list(q, getDialect(),
897                                                            start, end, false);
898    
899                                            Collections.sort(list);
900    
901                                            list = Collections.unmodifiableList(list);
902                                    }
903                                    else {
904                                            list = (List<WebDAVProps>)QueryUtil.list(q, getDialect(),
905                                                            start, end);
906                                    }
907    
908                                    cacheResult(list);
909    
910                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
911                            }
912                            catch (Exception e) {
913                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
914    
915                                    throw processException(e);
916                            }
917                            finally {
918                                    closeSession(session);
919                            }
920                    }
921    
922                    return list;
923            }
924    
925            /**
926             * Removes all the web d a v propses from the database.
927             *
928             */
929            @Override
930            public void removeAll() {
931                    for (WebDAVProps webDAVProps : findAll()) {
932                            remove(webDAVProps);
933                    }
934            }
935    
936            /**
937             * Returns the number of web d a v propses.
938             *
939             * @return the number of web d a v propses
940             */
941            @Override
942            public int countAll() {
943                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
944                                    FINDER_ARGS_EMPTY, this);
945    
946                    if (count == null) {
947                            Session session = null;
948    
949                            try {
950                                    session = openSession();
951    
952                                    Query q = session.createQuery(_SQL_COUNT_WEBDAVPROPS);
953    
954                                    count = (Long)q.uniqueResult();
955    
956                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
957                                            FINDER_ARGS_EMPTY, count);
958                            }
959                            catch (Exception e) {
960                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
961                                            FINDER_ARGS_EMPTY);
962    
963                                    throw processException(e);
964                            }
965                            finally {
966                                    closeSession(session);
967                            }
968                    }
969    
970                    return count.intValue();
971            }
972    
973            /**
974             * Initializes the web d a v props persistence.
975             */
976            public void afterPropertiesSet() {
977            }
978    
979            public void destroy() {
980                    EntityCacheUtil.removeCache(WebDAVPropsImpl.class.getName());
981                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
982                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
983                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
984            }
985    
986            private static final String _SQL_SELECT_WEBDAVPROPS = "SELECT webDAVProps FROM WebDAVProps webDAVProps";
987            private static final String _SQL_SELECT_WEBDAVPROPS_WHERE_PKS_IN = "SELECT webDAVProps FROM WebDAVProps webDAVProps WHERE webDavPropsId IN (";
988            private static final String _SQL_SELECT_WEBDAVPROPS_WHERE = "SELECT webDAVProps FROM WebDAVProps webDAVProps WHERE ";
989            private static final String _SQL_COUNT_WEBDAVPROPS = "SELECT COUNT(webDAVProps) FROM WebDAVProps webDAVProps";
990            private static final String _SQL_COUNT_WEBDAVPROPS_WHERE = "SELECT COUNT(webDAVProps) FROM WebDAVProps webDAVProps WHERE ";
991            private static final String _ORDER_BY_ENTITY_ALIAS = "webDAVProps.";
992            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No WebDAVProps exists with the primary key ";
993            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No WebDAVProps exists with the key {";
994            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
995            private static final Log _log = LogFactoryUtil.getLog(WebDAVPropsPersistenceImpl.class);
996            private static final WebDAVProps _nullWebDAVProps = new WebDAVPropsImpl() {
997                            @Override
998                            public Object clone() {
999                                    return this;
1000                            }
1001    
1002                            @Override
1003                            public CacheModel<WebDAVProps> toCacheModel() {
1004                                    return _nullWebDAVPropsCacheModel;
1005                            }
1006                    };
1007    
1008            private static final CacheModel<WebDAVProps> _nullWebDAVPropsCacheModel = new NullCacheModel();
1009    
1010            private static class NullCacheModel implements CacheModel<WebDAVProps>,
1011                    MVCCModel {
1012                    @Override
1013                    public long getMvccVersion() {
1014                            return -1;
1015                    }
1016    
1017                    @Override
1018                    public void setMvccVersion(long mvccVersion) {
1019                    }
1020    
1021                    @Override
1022                    public WebDAVProps toEntityModel() {
1023                            return _nullWebDAVProps;
1024                    }
1025            }
1026    }