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.dao.orm.EntityCache;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCache;
023    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
024    import com.liferay.portal.kernel.dao.orm.FinderPath;
025    import com.liferay.portal.kernel.dao.orm.Query;
026    import com.liferay.portal.kernel.dao.orm.QueryPos;
027    import com.liferay.portal.kernel.dao.orm.QueryUtil;
028    import com.liferay.portal.kernel.dao.orm.Session;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.OrderByComparator;
032    import com.liferay.portal.kernel.util.StringBundler;
033    import com.liferay.portal.kernel.util.StringPool;
034    import com.liferay.portal.model.CacheModel;
035    import com.liferay.portal.model.MVCCModel;
036    import com.liferay.portal.model.WebDAVProps;
037    import com.liferay.portal.model.impl.WebDAVPropsImpl;
038    import com.liferay.portal.model.impl.WebDAVPropsModelImpl;
039    import com.liferay.portal.service.ServiceContext;
040    import com.liferay.portal.service.ServiceContextThreadLocal;
041    import com.liferay.portal.service.persistence.WebDAVPropsPersistence;
042    
043    import java.io.Serializable;
044    
045    import java.util.Collections;
046    import java.util.Date;
047    import java.util.HashMap;
048    import java.util.HashSet;
049    import java.util.Iterator;
050    import java.util.List;
051    import java.util.Map;
052    import java.util.Set;
053    
054    /**
055     * The persistence implementation for the web d a v props service.
056     *
057     * <p>
058     * Caching information and settings can be found in <code>portal.properties</code>
059     * </p>
060     *
061     * @author Brian Wing Shun Chan
062     * @see WebDAVPropsPersistence
063     * @see com.liferay.portal.service.persistence.WebDAVPropsUtil
064     * @generated
065     */
066    @ProviderType
067    public class WebDAVPropsPersistenceImpl extends BasePersistenceImpl<WebDAVProps>
068            implements WebDAVPropsPersistence {
069            /*
070             * NOTE FOR DEVELOPERS:
071             *
072             * 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.
073             */
074            public static final String FINDER_CLASS_NAME_ENTITY = WebDAVPropsImpl.class.getName();
075            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076                    ".List1";
077            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
078                    ".List2";
079            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
080                            WebDAVPropsModelImpl.FINDER_CACHE_ENABLED, WebDAVPropsImpl.class,
081                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
082            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
083                            WebDAVPropsModelImpl.FINDER_CACHE_ENABLED, WebDAVPropsImpl.class,
084                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
085            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
086                            WebDAVPropsModelImpl.FINDER_CACHE_ENABLED, Long.class,
087                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
088            public static final FinderPath FINDER_PATH_FETCH_BY_C_C = new FinderPath(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
089                            WebDAVPropsModelImpl.FINDER_CACHE_ENABLED, WebDAVPropsImpl.class,
090                            FINDER_CLASS_NAME_ENTITY, "fetchByC_C",
091                            new String[] { Long.class.getName(), Long.class.getName() },
092                            WebDAVPropsModelImpl.CLASSNAMEID_COLUMN_BITMASK |
093                            WebDAVPropsModelImpl.CLASSPK_COLUMN_BITMASK);
094            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
095                            WebDAVPropsModelImpl.FINDER_CACHE_ENABLED, Long.class,
096                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
097                            new String[] { Long.class.getName(), Long.class.getName() });
098    
099            /**
100             * Returns the web d a v props where classNameId = &#63; and classPK = &#63; or throws a {@link NoSuchWebDAVPropsException} if it could not be found.
101             *
102             * @param classNameId the class name ID
103             * @param classPK the class p k
104             * @return the matching web d a v props
105             * @throws NoSuchWebDAVPropsException if a matching web d a v props could not be found
106             */
107            @Override
108            public WebDAVProps findByC_C(long classNameId, long classPK)
109                    throws NoSuchWebDAVPropsException {
110                    WebDAVProps webDAVProps = fetchByC_C(classNameId, classPK);
111    
112                    if (webDAVProps == null) {
113                            StringBundler msg = new StringBundler(6);
114    
115                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
116    
117                            msg.append("classNameId=");
118                            msg.append(classNameId);
119    
120                            msg.append(", classPK=");
121                            msg.append(classPK);
122    
123                            msg.append(StringPool.CLOSE_CURLY_BRACE);
124    
125                            if (_log.isWarnEnabled()) {
126                                    _log.warn(msg.toString());
127                            }
128    
129                            throw new NoSuchWebDAVPropsException(msg.toString());
130                    }
131    
132                    return webDAVProps;
133            }
134    
135            /**
136             * 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.
137             *
138             * @param classNameId the class name ID
139             * @param classPK the class p k
140             * @return the matching web d a v props, or <code>null</code> if a matching web d a v props could not be found
141             */
142            @Override
143            public WebDAVProps fetchByC_C(long classNameId, long classPK) {
144                    return fetchByC_C(classNameId, classPK, true);
145            }
146    
147            /**
148             * 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.
149             *
150             * @param classNameId the class name ID
151             * @param classPK the class p k
152             * @param retrieveFromCache whether to retrieve from the finder cache
153             * @return the matching web d a v props, or <code>null</code> if a matching web d a v props could not be found
154             */
155            @Override
156            public WebDAVProps fetchByC_C(long classNameId, long classPK,
157                    boolean retrieveFromCache) {
158                    Object[] finderArgs = new Object[] { classNameId, classPK };
159    
160                    Object result = null;
161    
162                    if (retrieveFromCache) {
163                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_C_C,
164                                            finderArgs, this);
165                    }
166    
167                    if (result instanceof WebDAVProps) {
168                            WebDAVProps webDAVProps = (WebDAVProps)result;
169    
170                            if ((classNameId != webDAVProps.getClassNameId()) ||
171                                            (classPK != webDAVProps.getClassPK())) {
172                                    result = null;
173                            }
174                    }
175    
176                    if (result == null) {
177                            StringBundler query = new StringBundler(4);
178    
179                            query.append(_SQL_SELECT_WEBDAVPROPS_WHERE);
180    
181                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
182    
183                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
184    
185                            String sql = query.toString();
186    
187                            Session session = null;
188    
189                            try {
190                                    session = openSession();
191    
192                                    Query q = session.createQuery(sql);
193    
194                                    QueryPos qPos = QueryPos.getInstance(q);
195    
196                                    qPos.add(classNameId);
197    
198                                    qPos.add(classPK);
199    
200                                    List<WebDAVProps> list = q.list();
201    
202                                    if (list.isEmpty()) {
203                                            finderCache.putResult(FINDER_PATH_FETCH_BY_C_C, finderArgs,
204                                                    list);
205                                    }
206                                    else {
207                                            WebDAVProps webDAVProps = list.get(0);
208    
209                                            result = webDAVProps;
210    
211                                            cacheResult(webDAVProps);
212    
213                                            if ((webDAVProps.getClassNameId() != classNameId) ||
214                                                            (webDAVProps.getClassPK() != classPK)) {
215                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_C_C,
216                                                            finderArgs, webDAVProps);
217                                            }
218                                    }
219                            }
220                            catch (Exception e) {
221                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_C_C, finderArgs);
222    
223                                    throw processException(e);
224                            }
225                            finally {
226                                    closeSession(session);
227                            }
228                    }
229    
230                    if (result instanceof List<?>) {
231                            return null;
232                    }
233                    else {
234                            return (WebDAVProps)result;
235                    }
236            }
237    
238            /**
239             * Removes the web d a v props where classNameId = &#63; and classPK = &#63; from the database.
240             *
241             * @param classNameId the class name ID
242             * @param classPK the class p k
243             * @return the web d a v props that was removed
244             */
245            @Override
246            public WebDAVProps removeByC_C(long classNameId, long classPK)
247                    throws NoSuchWebDAVPropsException {
248                    WebDAVProps webDAVProps = findByC_C(classNameId, classPK);
249    
250                    return remove(webDAVProps);
251            }
252    
253            /**
254             * Returns the number of web d a v propses where classNameId = &#63; and classPK = &#63;.
255             *
256             * @param classNameId the class name ID
257             * @param classPK the class p k
258             * @return the number of matching web d a v propses
259             */
260            @Override
261            public int countByC_C(long classNameId, long classPK) {
262                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
263    
264                    Object[] finderArgs = new Object[] { classNameId, classPK };
265    
266                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
267    
268                    if (count == null) {
269                            StringBundler query = new StringBundler(3);
270    
271                            query.append(_SQL_COUNT_WEBDAVPROPS_WHERE);
272    
273                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
274    
275                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
276    
277                            String sql = query.toString();
278    
279                            Session session = null;
280    
281                            try {
282                                    session = openSession();
283    
284                                    Query q = session.createQuery(sql);
285    
286                                    QueryPos qPos = QueryPos.getInstance(q);
287    
288                                    qPos.add(classNameId);
289    
290                                    qPos.add(classPK);
291    
292                                    count = (Long)q.uniqueResult();
293    
294                                    finderCache.putResult(finderPath, finderArgs, count);
295                            }
296                            catch (Exception e) {
297                                    finderCache.removeResult(finderPath, finderArgs);
298    
299                                    throw processException(e);
300                            }
301                            finally {
302                                    closeSession(session);
303                            }
304                    }
305    
306                    return count.intValue();
307            }
308    
309            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "webDAVProps.classNameId = ? AND ";
310            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "webDAVProps.classPK = ?";
311    
312            public WebDAVPropsPersistenceImpl() {
313                    setModelClass(WebDAVProps.class);
314            }
315    
316            /**
317             * Caches the web d a v props in the entity cache if it is enabled.
318             *
319             * @param webDAVProps the web d a v props
320             */
321            @Override
322            public void cacheResult(WebDAVProps webDAVProps) {
323                    entityCache.putResult(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
324                            WebDAVPropsImpl.class, webDAVProps.getPrimaryKey(), webDAVProps);
325    
326                    finderCache.putResult(FINDER_PATH_FETCH_BY_C_C,
327                            new Object[] { webDAVProps.getClassNameId(), webDAVProps.getClassPK() },
328                            webDAVProps);
329    
330                    webDAVProps.resetOriginalValues();
331            }
332    
333            /**
334             * Caches the web d a v propses in the entity cache if it is enabled.
335             *
336             * @param webDAVPropses the web d a v propses
337             */
338            @Override
339            public void cacheResult(List<WebDAVProps> webDAVPropses) {
340                    for (WebDAVProps webDAVProps : webDAVPropses) {
341                            if (entityCache.getResult(
342                                                    WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
343                                                    WebDAVPropsImpl.class, webDAVProps.getPrimaryKey()) == null) {
344                                    cacheResult(webDAVProps);
345                            }
346                            else {
347                                    webDAVProps.resetOriginalValues();
348                            }
349                    }
350            }
351    
352            /**
353             * Clears the cache for all web d a v propses.
354             *
355             * <p>
356             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
357             * </p>
358             */
359            @Override
360            public void clearCache() {
361                    entityCache.clearCache(WebDAVPropsImpl.class);
362    
363                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
364                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
365                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
366            }
367    
368            /**
369             * Clears the cache for the web d a v props.
370             *
371             * <p>
372             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
373             * </p>
374             */
375            @Override
376            public void clearCache(WebDAVProps webDAVProps) {
377                    entityCache.removeResult(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
378                            WebDAVPropsImpl.class, webDAVProps.getPrimaryKey());
379    
380                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
381                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
382    
383                    clearUniqueFindersCache((WebDAVPropsModelImpl)webDAVProps);
384            }
385    
386            @Override
387            public void clearCache(List<WebDAVProps> webDAVPropses) {
388                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
389                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
390    
391                    for (WebDAVProps webDAVProps : webDAVPropses) {
392                            entityCache.removeResult(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
393                                    WebDAVPropsImpl.class, webDAVProps.getPrimaryKey());
394    
395                            clearUniqueFindersCache((WebDAVPropsModelImpl)webDAVProps);
396                    }
397            }
398    
399            protected void cacheUniqueFindersCache(
400                    WebDAVPropsModelImpl webDAVPropsModelImpl, boolean isNew) {
401                    if (isNew) {
402                            Object[] args = new Object[] {
403                                            webDAVPropsModelImpl.getClassNameId(),
404                                            webDAVPropsModelImpl.getClassPK()
405                                    };
406    
407                            finderCache.putResult(FINDER_PATH_COUNT_BY_C_C, args,
408                                    Long.valueOf(1));
409                            finderCache.putResult(FINDER_PATH_FETCH_BY_C_C, args,
410                                    webDAVPropsModelImpl);
411                    }
412                    else {
413                            if ((webDAVPropsModelImpl.getColumnBitmask() &
414                                            FINDER_PATH_FETCH_BY_C_C.getColumnBitmask()) != 0) {
415                                    Object[] args = new Object[] {
416                                                    webDAVPropsModelImpl.getClassNameId(),
417                                                    webDAVPropsModelImpl.getClassPK()
418                                            };
419    
420                                    finderCache.putResult(FINDER_PATH_COUNT_BY_C_C, args,
421                                            Long.valueOf(1));
422                                    finderCache.putResult(FINDER_PATH_FETCH_BY_C_C, args,
423                                            webDAVPropsModelImpl);
424                            }
425                    }
426            }
427    
428            protected void clearUniqueFindersCache(
429                    WebDAVPropsModelImpl webDAVPropsModelImpl) {
430                    Object[] args = new Object[] {
431                                    webDAVPropsModelImpl.getClassNameId(),
432                                    webDAVPropsModelImpl.getClassPK()
433                            };
434    
435                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
436                    finderCache.removeResult(FINDER_PATH_FETCH_BY_C_C, args);
437    
438                    if ((webDAVPropsModelImpl.getColumnBitmask() &
439                                    FINDER_PATH_FETCH_BY_C_C.getColumnBitmask()) != 0) {
440                            args = new Object[] {
441                                            webDAVPropsModelImpl.getOriginalClassNameId(),
442                                            webDAVPropsModelImpl.getOriginalClassPK()
443                                    };
444    
445                            finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
446                            finderCache.removeResult(FINDER_PATH_FETCH_BY_C_C, args);
447                    }
448            }
449    
450            /**
451             * Creates a new web d a v props with the primary key. Does not add the web d a v props to the database.
452             *
453             * @param webDavPropsId the primary key for the new web d a v props
454             * @return the new web d a v props
455             */
456            @Override
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 NoSuchWebDAVPropsException if a web d a v props with the primary key could not be found
472             */
473            @Override
474            public WebDAVProps remove(long webDavPropsId)
475                    throws NoSuchWebDAVPropsException {
476                    return remove((Serializable)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 NoSuchWebDAVPropsException if a web d a v props with the primary key could not be found
485             */
486            @Override
487            public WebDAVProps remove(Serializable primaryKey)
488                    throws NoSuchWebDAVPropsException {
489                    Session session = null;
490    
491                    try {
492                            session = openSession();
493    
494                            WebDAVProps webDAVProps = (WebDAVProps)session.get(WebDAVPropsImpl.class,
495                                            primaryKey);
496    
497                            if (webDAVProps == null) {
498                                    if (_log.isWarnEnabled()) {
499                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
500                                    }
501    
502                                    throw new NoSuchWebDAVPropsException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
503                                            primaryKey);
504                            }
505    
506                            return remove(webDAVProps);
507                    }
508                    catch (NoSuchWebDAVPropsException nsee) {
509                            throw nsee;
510                    }
511                    catch (Exception e) {
512                            throw processException(e);
513                    }
514                    finally {
515                            closeSession(session);
516                    }
517            }
518    
519            @Override
520            protected WebDAVProps removeImpl(WebDAVProps webDAVProps) {
521                    webDAVProps = toUnwrappedModel(webDAVProps);
522    
523                    Session session = null;
524    
525                    try {
526                            session = openSession();
527    
528                            if (!session.contains(webDAVProps)) {
529                                    webDAVProps = (WebDAVProps)session.get(WebDAVPropsImpl.class,
530                                                    webDAVProps.getPrimaryKeyObj());
531                            }
532    
533                            if (webDAVProps != null) {
534                                    session.delete(webDAVProps);
535                            }
536                    }
537                    catch (Exception e) {
538                            throw processException(e);
539                    }
540                    finally {
541                            closeSession(session);
542                    }
543    
544                    if (webDAVProps != null) {
545                            clearCache(webDAVProps);
546                    }
547    
548                    return webDAVProps;
549            }
550    
551            @Override
552            public WebDAVProps updateImpl(WebDAVProps webDAVProps) {
553                    webDAVProps = toUnwrappedModel(webDAVProps);
554    
555                    boolean isNew = webDAVProps.isNew();
556    
557                    WebDAVPropsModelImpl webDAVPropsModelImpl = (WebDAVPropsModelImpl)webDAVProps;
558    
559                    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
560    
561                    Date now = new Date();
562    
563                    if (isNew && (webDAVProps.getCreateDate() == null)) {
564                            if (serviceContext == null) {
565                                    webDAVProps.setCreateDate(now);
566                            }
567                            else {
568                                    webDAVProps.setCreateDate(serviceContext.getCreateDate(now));
569                            }
570                    }
571    
572                    if (!webDAVPropsModelImpl.hasSetModifiedDate()) {
573                            if (serviceContext == null) {
574                                    webDAVProps.setModifiedDate(now);
575                            }
576                            else {
577                                    webDAVProps.setModifiedDate(serviceContext.getModifiedDate(now));
578                            }
579                    }
580    
581                    Session session = null;
582    
583                    try {
584                            session = openSession();
585    
586                            if (webDAVProps.isNew()) {
587                                    session.save(webDAVProps);
588    
589                                    webDAVProps.setNew(false);
590                            }
591                            else {
592                                    webDAVProps = (WebDAVProps)session.merge(webDAVProps);
593                            }
594                    }
595                    catch (Exception e) {
596                            throw processException(e);
597                    }
598                    finally {
599                            closeSession(session);
600                    }
601    
602                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
603    
604                    if (isNew || !WebDAVPropsModelImpl.COLUMN_BITMASK_ENABLED) {
605                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
606                    }
607    
608                    entityCache.putResult(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
609                            WebDAVPropsImpl.class, webDAVProps.getPrimaryKey(), webDAVProps,
610                            false);
611    
612                    clearUniqueFindersCache(webDAVPropsModelImpl);
613                    cacheUniqueFindersCache(webDAVPropsModelImpl, isNew);
614    
615                    webDAVProps.resetOriginalValues();
616    
617                    return webDAVProps;
618            }
619    
620            protected WebDAVProps toUnwrappedModel(WebDAVProps webDAVProps) {
621                    if (webDAVProps instanceof WebDAVPropsImpl) {
622                            return webDAVProps;
623                    }
624    
625                    WebDAVPropsImpl webDAVPropsImpl = new WebDAVPropsImpl();
626    
627                    webDAVPropsImpl.setNew(webDAVProps.isNew());
628                    webDAVPropsImpl.setPrimaryKey(webDAVProps.getPrimaryKey());
629    
630                    webDAVPropsImpl.setMvccVersion(webDAVProps.getMvccVersion());
631                    webDAVPropsImpl.setWebDavPropsId(webDAVProps.getWebDavPropsId());
632                    webDAVPropsImpl.setCompanyId(webDAVProps.getCompanyId());
633                    webDAVPropsImpl.setCreateDate(webDAVProps.getCreateDate());
634                    webDAVPropsImpl.setModifiedDate(webDAVProps.getModifiedDate());
635                    webDAVPropsImpl.setClassNameId(webDAVProps.getClassNameId());
636                    webDAVPropsImpl.setClassPK(webDAVProps.getClassPK());
637                    webDAVPropsImpl.setProps(webDAVProps.getProps());
638    
639                    return webDAVPropsImpl;
640            }
641    
642            /**
643             * 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.
644             *
645             * @param primaryKey the primary key of the web d a v props
646             * @return the web d a v props
647             * @throws NoSuchWebDAVPropsException if a web d a v props with the primary key could not be found
648             */
649            @Override
650            public WebDAVProps findByPrimaryKey(Serializable primaryKey)
651                    throws NoSuchWebDAVPropsException {
652                    WebDAVProps webDAVProps = fetchByPrimaryKey(primaryKey);
653    
654                    if (webDAVProps == null) {
655                            if (_log.isWarnEnabled()) {
656                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
657                            }
658    
659                            throw new NoSuchWebDAVPropsException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
660                                    primaryKey);
661                    }
662    
663                    return webDAVProps;
664            }
665    
666            /**
667             * Returns the web d a v props with the primary key or throws a {@link NoSuchWebDAVPropsException} if it could not be found.
668             *
669             * @param webDavPropsId the primary key of the web d a v props
670             * @return the web d a v props
671             * @throws NoSuchWebDAVPropsException if a web d a v props with the primary key could not be found
672             */
673            @Override
674            public WebDAVProps findByPrimaryKey(long webDavPropsId)
675                    throws NoSuchWebDAVPropsException {
676                    return findByPrimaryKey((Serializable)webDavPropsId);
677            }
678    
679            /**
680             * Returns the web d a v props with the primary key or returns <code>null</code> if it could not be found.
681             *
682             * @param primaryKey the primary key of the web d a v props
683             * @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
684             */
685            @Override
686            public WebDAVProps fetchByPrimaryKey(Serializable primaryKey) {
687                    WebDAVProps webDAVProps = (WebDAVProps)entityCache.getResult(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
688                                    WebDAVPropsImpl.class, primaryKey);
689    
690                    if (webDAVProps == _nullWebDAVProps) {
691                            return null;
692                    }
693    
694                    if (webDAVProps == null) {
695                            Session session = null;
696    
697                            try {
698                                    session = openSession();
699    
700                                    webDAVProps = (WebDAVProps)session.get(WebDAVPropsImpl.class,
701                                                    primaryKey);
702    
703                                    if (webDAVProps != null) {
704                                            cacheResult(webDAVProps);
705                                    }
706                                    else {
707                                            entityCache.putResult(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
708                                                    WebDAVPropsImpl.class, primaryKey, _nullWebDAVProps);
709                                    }
710                            }
711                            catch (Exception e) {
712                                    entityCache.removeResult(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
713                                            WebDAVPropsImpl.class, primaryKey);
714    
715                                    throw processException(e);
716                            }
717                            finally {
718                                    closeSession(session);
719                            }
720                    }
721    
722                    return webDAVProps;
723            }
724    
725            /**
726             * Returns the web d a v props with the primary key or returns <code>null</code> if it could not be found.
727             *
728             * @param webDavPropsId the primary key of the web d a v props
729             * @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
730             */
731            @Override
732            public WebDAVProps fetchByPrimaryKey(long webDavPropsId) {
733                    return fetchByPrimaryKey((Serializable)webDavPropsId);
734            }
735    
736            @Override
737            public Map<Serializable, WebDAVProps> fetchByPrimaryKeys(
738                    Set<Serializable> primaryKeys) {
739                    if (primaryKeys.isEmpty()) {
740                            return Collections.emptyMap();
741                    }
742    
743                    Map<Serializable, WebDAVProps> map = new HashMap<Serializable, WebDAVProps>();
744    
745                    if (primaryKeys.size() == 1) {
746                            Iterator<Serializable> iterator = primaryKeys.iterator();
747    
748                            Serializable primaryKey = iterator.next();
749    
750                            WebDAVProps webDAVProps = fetchByPrimaryKey(primaryKey);
751    
752                            if (webDAVProps != null) {
753                                    map.put(primaryKey, webDAVProps);
754                            }
755    
756                            return map;
757                    }
758    
759                    Set<Serializable> uncachedPrimaryKeys = null;
760    
761                    for (Serializable primaryKey : primaryKeys) {
762                            WebDAVProps webDAVProps = (WebDAVProps)entityCache.getResult(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
763                                            WebDAVPropsImpl.class, primaryKey);
764    
765                            if (webDAVProps == null) {
766                                    if (uncachedPrimaryKeys == null) {
767                                            uncachedPrimaryKeys = new HashSet<Serializable>();
768                                    }
769    
770                                    uncachedPrimaryKeys.add(primaryKey);
771                            }
772                            else {
773                                    map.put(primaryKey, webDAVProps);
774                            }
775                    }
776    
777                    if (uncachedPrimaryKeys == null) {
778                            return map;
779                    }
780    
781                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
782                                    1);
783    
784                    query.append(_SQL_SELECT_WEBDAVPROPS_WHERE_PKS_IN);
785    
786                    for (Serializable primaryKey : uncachedPrimaryKeys) {
787                            query.append(String.valueOf(primaryKey));
788    
789                            query.append(StringPool.COMMA);
790                    }
791    
792                    query.setIndex(query.index() - 1);
793    
794                    query.append(StringPool.CLOSE_PARENTHESIS);
795    
796                    String sql = query.toString();
797    
798                    Session session = null;
799    
800                    try {
801                            session = openSession();
802    
803                            Query q = session.createQuery(sql);
804    
805                            for (WebDAVProps webDAVProps : (List<WebDAVProps>)q.list()) {
806                                    map.put(webDAVProps.getPrimaryKeyObj(), webDAVProps);
807    
808                                    cacheResult(webDAVProps);
809    
810                                    uncachedPrimaryKeys.remove(webDAVProps.getPrimaryKeyObj());
811                            }
812    
813                            for (Serializable primaryKey : uncachedPrimaryKeys) {
814                                    entityCache.putResult(WebDAVPropsModelImpl.ENTITY_CACHE_ENABLED,
815                                            WebDAVPropsImpl.class, primaryKey, _nullWebDAVProps);
816                            }
817                    }
818                    catch (Exception e) {
819                            throw processException(e);
820                    }
821                    finally {
822                            closeSession(session);
823                    }
824    
825                    return map;
826            }
827    
828            /**
829             * Returns all the web d a v propses.
830             *
831             * @return the web d a v propses
832             */
833            @Override
834            public List<WebDAVProps> findAll() {
835                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
836            }
837    
838            /**
839             * Returns a range of all the web d a v propses.
840             *
841             * <p>
842             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
843             * </p>
844             *
845             * @param start the lower bound of the range of web d a v propses
846             * @param end the upper bound of the range of web d a v propses (not inclusive)
847             * @return the range of web d a v propses
848             */
849            @Override
850            public List<WebDAVProps> findAll(int start, int end) {
851                    return findAll(start, end, null);
852            }
853    
854            /**
855             * Returns an ordered range of all the web d a v propses.
856             *
857             * <p>
858             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
859             * </p>
860             *
861             * @param start the lower bound of the range of web d a v propses
862             * @param end the upper bound of the range of web d a v propses (not inclusive)
863             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
864             * @return the ordered range of web d a v propses
865             */
866            @Override
867            public List<WebDAVProps> findAll(int start, int end,
868                    OrderByComparator<WebDAVProps> orderByComparator) {
869                    return findAll(start, end, orderByComparator, true);
870            }
871    
872            /**
873             * Returns an ordered range of all the web d a v propses.
874             *
875             * <p>
876             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
877             * </p>
878             *
879             * @param start the lower bound of the range of web d a v propses
880             * @param end the upper bound of the range of web d a v propses (not inclusive)
881             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
882             * @param retrieveFromCache whether to retrieve from the finder cache
883             * @return the ordered range of web d a v propses
884             */
885            @Override
886            public List<WebDAVProps> findAll(int start, int end,
887                    OrderByComparator<WebDAVProps> orderByComparator,
888                    boolean retrieveFromCache) {
889                    boolean pagination = true;
890                    FinderPath finderPath = null;
891                    Object[] finderArgs = null;
892    
893                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
894                                    (orderByComparator == null)) {
895                            pagination = false;
896                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
897                            finderArgs = FINDER_ARGS_EMPTY;
898                    }
899                    else {
900                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
901                            finderArgs = new Object[] { start, end, orderByComparator };
902                    }
903    
904                    List<WebDAVProps> list = null;
905    
906                    if (retrieveFromCache) {
907                            list = (List<WebDAVProps>)finderCache.getResult(finderPath,
908                                            finderArgs, this);
909                    }
910    
911                    if (list == null) {
912                            StringBundler query = null;
913                            String sql = null;
914    
915                            if (orderByComparator != null) {
916                                    query = new StringBundler(2 +
917                                                    (orderByComparator.getOrderByFields().length * 3));
918    
919                                    query.append(_SQL_SELECT_WEBDAVPROPS);
920    
921                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
922                                            orderByComparator);
923    
924                                    sql = query.toString();
925                            }
926                            else {
927                                    sql = _SQL_SELECT_WEBDAVPROPS;
928    
929                                    if (pagination) {
930                                            sql = sql.concat(WebDAVPropsModelImpl.ORDER_BY_JPQL);
931                                    }
932                            }
933    
934                            Session session = null;
935    
936                            try {
937                                    session = openSession();
938    
939                                    Query q = session.createQuery(sql);
940    
941                                    if (!pagination) {
942                                            list = (List<WebDAVProps>)QueryUtil.list(q, getDialect(),
943                                                            start, end, false);
944    
945                                            Collections.sort(list);
946    
947                                            list = Collections.unmodifiableList(list);
948                                    }
949                                    else {
950                                            list = (List<WebDAVProps>)QueryUtil.list(q, getDialect(),
951                                                            start, end);
952                                    }
953    
954                                    cacheResult(list);
955    
956                                    finderCache.putResult(finderPath, finderArgs, list);
957                            }
958                            catch (Exception e) {
959                                    finderCache.removeResult(finderPath, finderArgs);
960    
961                                    throw processException(e);
962                            }
963                            finally {
964                                    closeSession(session);
965                            }
966                    }
967    
968                    return list;
969            }
970    
971            /**
972             * Removes all the web d a v propses from the database.
973             *
974             */
975            @Override
976            public void removeAll() {
977                    for (WebDAVProps webDAVProps : findAll()) {
978                            remove(webDAVProps);
979                    }
980            }
981    
982            /**
983             * Returns the number of web d a v propses.
984             *
985             * @return the number of web d a v propses
986             */
987            @Override
988            public int countAll() {
989                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
990                                    FINDER_ARGS_EMPTY, this);
991    
992                    if (count == null) {
993                            Session session = null;
994    
995                            try {
996                                    session = openSession();
997    
998                                    Query q = session.createQuery(_SQL_COUNT_WEBDAVPROPS);
999    
1000                                    count = (Long)q.uniqueResult();
1001    
1002                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
1003                                            count);
1004                            }
1005                            catch (Exception e) {
1006                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
1007                                            FINDER_ARGS_EMPTY);
1008    
1009                                    throw processException(e);
1010                            }
1011                            finally {
1012                                    closeSession(session);
1013                            }
1014                    }
1015    
1016                    return count.intValue();
1017            }
1018    
1019            @Override
1020            protected Map<String, Integer> getTableColumnsMap() {
1021                    return WebDAVPropsModelImpl.TABLE_COLUMNS_MAP;
1022            }
1023    
1024            /**
1025             * Initializes the web d a v props persistence.
1026             */
1027            public void afterPropertiesSet() {
1028            }
1029    
1030            public void destroy() {
1031                    entityCache.removeCache(WebDAVPropsImpl.class.getName());
1032                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
1033                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1034                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1035            }
1036    
1037            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
1038            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
1039            private static final String _SQL_SELECT_WEBDAVPROPS = "SELECT webDAVProps FROM WebDAVProps webDAVProps";
1040            private static final String _SQL_SELECT_WEBDAVPROPS_WHERE_PKS_IN = "SELECT webDAVProps FROM WebDAVProps webDAVProps WHERE webDavPropsId IN (";
1041            private static final String _SQL_SELECT_WEBDAVPROPS_WHERE = "SELECT webDAVProps FROM WebDAVProps webDAVProps WHERE ";
1042            private static final String _SQL_COUNT_WEBDAVPROPS = "SELECT COUNT(webDAVProps) FROM WebDAVProps webDAVProps";
1043            private static final String _SQL_COUNT_WEBDAVPROPS_WHERE = "SELECT COUNT(webDAVProps) FROM WebDAVProps webDAVProps WHERE ";
1044            private static final String _ORDER_BY_ENTITY_ALIAS = "webDAVProps.";
1045            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No WebDAVProps exists with the primary key ";
1046            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No WebDAVProps exists with the key {";
1047            private static final Log _log = LogFactoryUtil.getLog(WebDAVPropsPersistenceImpl.class);
1048            private static final WebDAVProps _nullWebDAVProps = new WebDAVPropsImpl() {
1049                            @Override
1050                            public Object clone() {
1051                                    return this;
1052                            }
1053    
1054                            @Override
1055                            public CacheModel<WebDAVProps> toCacheModel() {
1056                                    return _nullWebDAVPropsCacheModel;
1057                            }
1058                    };
1059    
1060            private static final CacheModel<WebDAVProps> _nullWebDAVPropsCacheModel = new NullCacheModel();
1061    
1062            private static class NullCacheModel implements CacheModel<WebDAVProps>,
1063                    MVCCModel {
1064                    @Override
1065                    public long getMvccVersion() {
1066                            return -1;
1067                    }
1068    
1069                    @Override
1070                    public void setMvccVersion(long mvccVersion) {
1071                    }
1072    
1073                    @Override
1074                    public WebDAVProps toEntityModel() {
1075                            return _nullWebDAVProps;
1076                    }
1077            }
1078    }