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