001    /**
002     * Copyright (c) 2000-2010 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.portlet.documentlibrary.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.annotation.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.kernel.util.Validator;
037    import com.liferay.portal.model.ModelListener;
038    import com.liferay.portal.service.persistence.BatchSessionUtil;
039    import com.liferay.portal.service.persistence.ResourcePersistence;
040    import com.liferay.portal.service.persistence.UserPersistence;
041    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042    
043    import com.liferay.portlet.asset.service.persistence.AssetEntryPersistence;
044    import com.liferay.portlet.documentlibrary.NoSuchFileVersionException;
045    import com.liferay.portlet.documentlibrary.model.DLFileVersion;
046    import com.liferay.portlet.documentlibrary.model.impl.DLFileVersionImpl;
047    import com.liferay.portlet.documentlibrary.model.impl.DLFileVersionModelImpl;
048    
049    import java.io.Serializable;
050    
051    import java.util.ArrayList;
052    import java.util.Collections;
053    import java.util.List;
054    
055    /**
056     * @author    Brian Wing Shun Chan
057     * @see       DLFileVersionPersistence
058     * @see       DLFileVersionUtil
059     * @generated
060     */
061    public class DLFileVersionPersistenceImpl extends BasePersistenceImpl<DLFileVersion>
062            implements DLFileVersionPersistence {
063            public static final String FINDER_CLASS_NAME_ENTITY = DLFileVersionImpl.class.getName();
064            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
065                    ".List";
066            public static final FinderPath FINDER_PATH_FIND_BY_G_F_N = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
067                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
068                            FINDER_CLASS_NAME_LIST, "findByG_F_N",
069                            new String[] {
070                                    Long.class.getName(), Long.class.getName(),
071                                    String.class.getName(),
072                                    
073                            "java.lang.Integer", "java.lang.Integer",
074                                    "com.liferay.portal.kernel.util.OrderByComparator"
075                            });
076            public static final FinderPath FINDER_PATH_COUNT_BY_G_F_N = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
077                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
078                            FINDER_CLASS_NAME_LIST, "countByG_F_N",
079                            new String[] {
080                                    Long.class.getName(), Long.class.getName(),
081                                    String.class.getName()
082                            });
083            public static final FinderPath FINDER_PATH_FETCH_BY_G_F_N_V = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
084                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
085                            FINDER_CLASS_NAME_ENTITY, "fetchByG_F_N_V",
086                            new String[] {
087                                    Long.class.getName(), Long.class.getName(),
088                                    String.class.getName(), String.class.getName()
089                            });
090            public static final FinderPath FINDER_PATH_COUNT_BY_G_F_N_V = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
091                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
092                            FINDER_CLASS_NAME_LIST, "countByG_F_N_V",
093                            new String[] {
094                                    Long.class.getName(), Long.class.getName(),
095                                    String.class.getName(), String.class.getName()
096                            });
097            public static final FinderPath FINDER_PATH_FIND_BY_G_F_N_S = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
098                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
099                            FINDER_CLASS_NAME_LIST, "findByG_F_N_S",
100                            new String[] {
101                                    Long.class.getName(), Long.class.getName(),
102                                    String.class.getName(), Integer.class.getName(),
103                                    
104                            "java.lang.Integer", "java.lang.Integer",
105                                    "com.liferay.portal.kernel.util.OrderByComparator"
106                            });
107            public static final FinderPath FINDER_PATH_COUNT_BY_G_F_N_S = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
108                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
109                            FINDER_CLASS_NAME_LIST, "countByG_F_N_S",
110                            new String[] {
111                                    Long.class.getName(), Long.class.getName(),
112                                    String.class.getName(), Integer.class.getName()
113                            });
114            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
115                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
116                            FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
117            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
118                            DLFileVersionModelImpl.FINDER_CACHE_ENABLED,
119                            FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
120    
121            public void cacheResult(DLFileVersion dlFileVersion) {
122                    EntityCacheUtil.putResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
123                            DLFileVersionImpl.class, dlFileVersion.getPrimaryKey(),
124                            dlFileVersion);
125    
126                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_F_N_V,
127                            new Object[] {
128                                    new Long(dlFileVersion.getGroupId()),
129                                    new Long(dlFileVersion.getFolderId()),
130                                    
131                            dlFileVersion.getName(),
132                                    
133                            dlFileVersion.getVersion()
134                            }, dlFileVersion);
135            }
136    
137            public void cacheResult(List<DLFileVersion> dlFileVersions) {
138                    for (DLFileVersion dlFileVersion : dlFileVersions) {
139                            if (EntityCacheUtil.getResult(
140                                                    DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
141                                                    DLFileVersionImpl.class, dlFileVersion.getPrimaryKey(),
142                                                    this) == null) {
143                                    cacheResult(dlFileVersion);
144                            }
145                    }
146            }
147    
148            public void clearCache() {
149                    CacheRegistryUtil.clear(DLFileVersionImpl.class.getName());
150                    EntityCacheUtil.clearCache(DLFileVersionImpl.class.getName());
151                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
152                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
153            }
154    
155            public void clearCache(DLFileVersion dlFileVersion) {
156                    EntityCacheUtil.removeResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
157                            DLFileVersionImpl.class, dlFileVersion.getPrimaryKey());
158    
159                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_F_N_V,
160                            new Object[] {
161                                    new Long(dlFileVersion.getGroupId()),
162                                    new Long(dlFileVersion.getFolderId()),
163                                    
164                            dlFileVersion.getName(),
165                                    
166                            dlFileVersion.getVersion()
167                            });
168            }
169    
170            public DLFileVersion create(long fileVersionId) {
171                    DLFileVersion dlFileVersion = new DLFileVersionImpl();
172    
173                    dlFileVersion.setNew(true);
174                    dlFileVersion.setPrimaryKey(fileVersionId);
175    
176                    return dlFileVersion;
177            }
178    
179            public DLFileVersion remove(Serializable primaryKey)
180                    throws NoSuchModelException, SystemException {
181                    return remove(((Long)primaryKey).longValue());
182            }
183    
184            public DLFileVersion remove(long fileVersionId)
185                    throws NoSuchFileVersionException, SystemException {
186                    Session session = null;
187    
188                    try {
189                            session = openSession();
190    
191                            DLFileVersion dlFileVersion = (DLFileVersion)session.get(DLFileVersionImpl.class,
192                                            new Long(fileVersionId));
193    
194                            if (dlFileVersion == null) {
195                                    if (_log.isWarnEnabled()) {
196                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + fileVersionId);
197                                    }
198    
199                                    throw new NoSuchFileVersionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
200                                            fileVersionId);
201                            }
202    
203                            return remove(dlFileVersion);
204                    }
205                    catch (NoSuchFileVersionException nsee) {
206                            throw nsee;
207                    }
208                    catch (Exception e) {
209                            throw processException(e);
210                    }
211                    finally {
212                            closeSession(session);
213                    }
214            }
215    
216            protected DLFileVersion removeImpl(DLFileVersion dlFileVersion)
217                    throws SystemException {
218                    dlFileVersion = toUnwrappedModel(dlFileVersion);
219    
220                    Session session = null;
221    
222                    try {
223                            session = openSession();
224    
225                            if (dlFileVersion.isCachedModel() || BatchSessionUtil.isEnabled()) {
226                                    Object staleObject = session.get(DLFileVersionImpl.class,
227                                                    dlFileVersion.getPrimaryKeyObj());
228    
229                                    if (staleObject != null) {
230                                            session.evict(staleObject);
231                                    }
232                            }
233    
234                            session.delete(dlFileVersion);
235    
236                            session.flush();
237                    }
238                    catch (Exception e) {
239                            throw processException(e);
240                    }
241                    finally {
242                            closeSession(session);
243                    }
244    
245                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
246    
247                    DLFileVersionModelImpl dlFileVersionModelImpl = (DLFileVersionModelImpl)dlFileVersion;
248    
249                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_F_N_V,
250                            new Object[] {
251                                    new Long(dlFileVersionModelImpl.getOriginalGroupId()),
252                                    new Long(dlFileVersionModelImpl.getOriginalFolderId()),
253                                    
254                            dlFileVersionModelImpl.getOriginalName(),
255                                    
256                            dlFileVersionModelImpl.getOriginalVersion()
257                            });
258    
259                    EntityCacheUtil.removeResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
260                            DLFileVersionImpl.class, dlFileVersion.getPrimaryKey());
261    
262                    return dlFileVersion;
263            }
264    
265            public DLFileVersion updateImpl(
266                    com.liferay.portlet.documentlibrary.model.DLFileVersion dlFileVersion,
267                    boolean merge) throws SystemException {
268                    dlFileVersion = toUnwrappedModel(dlFileVersion);
269    
270                    boolean isNew = dlFileVersion.isNew();
271    
272                    DLFileVersionModelImpl dlFileVersionModelImpl = (DLFileVersionModelImpl)dlFileVersion;
273    
274                    Session session = null;
275    
276                    try {
277                            session = openSession();
278    
279                            BatchSessionUtil.update(session, dlFileVersion, merge);
280    
281                            dlFileVersion.setNew(false);
282                    }
283                    catch (Exception e) {
284                            throw processException(e);
285                    }
286                    finally {
287                            closeSession(session);
288                    }
289    
290                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
291    
292                    EntityCacheUtil.putResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
293                            DLFileVersionImpl.class, dlFileVersion.getPrimaryKey(),
294                            dlFileVersion);
295    
296                    if (!isNew &&
297                                    ((dlFileVersion.getGroupId() != dlFileVersionModelImpl.getOriginalGroupId()) ||
298                                    (dlFileVersion.getFolderId() != dlFileVersionModelImpl.getOriginalFolderId()) ||
299                                    !Validator.equals(dlFileVersion.getName(),
300                                            dlFileVersionModelImpl.getOriginalName()) ||
301                                    !Validator.equals(dlFileVersion.getVersion(),
302                                            dlFileVersionModelImpl.getOriginalVersion()))) {
303                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_F_N_V,
304                                    new Object[] {
305                                            new Long(dlFileVersionModelImpl.getOriginalGroupId()),
306                                            new Long(dlFileVersionModelImpl.getOriginalFolderId()),
307                                            
308                                    dlFileVersionModelImpl.getOriginalName(),
309                                            
310                                    dlFileVersionModelImpl.getOriginalVersion()
311                                    });
312                    }
313    
314                    if (isNew ||
315                                    ((dlFileVersion.getGroupId() != dlFileVersionModelImpl.getOriginalGroupId()) ||
316                                    (dlFileVersion.getFolderId() != dlFileVersionModelImpl.getOriginalFolderId()) ||
317                                    !Validator.equals(dlFileVersion.getName(),
318                                            dlFileVersionModelImpl.getOriginalName()) ||
319                                    !Validator.equals(dlFileVersion.getVersion(),
320                                            dlFileVersionModelImpl.getOriginalVersion()))) {
321                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_F_N_V,
322                                    new Object[] {
323                                            new Long(dlFileVersion.getGroupId()),
324                                            new Long(dlFileVersion.getFolderId()),
325                                            
326                                    dlFileVersion.getName(),
327                                            
328                                    dlFileVersion.getVersion()
329                                    }, dlFileVersion);
330                    }
331    
332                    return dlFileVersion;
333            }
334    
335            protected DLFileVersion toUnwrappedModel(DLFileVersion dlFileVersion) {
336                    if (dlFileVersion instanceof DLFileVersionImpl) {
337                            return dlFileVersion;
338                    }
339    
340                    DLFileVersionImpl dlFileVersionImpl = new DLFileVersionImpl();
341    
342                    dlFileVersionImpl.setNew(dlFileVersion.isNew());
343                    dlFileVersionImpl.setPrimaryKey(dlFileVersion.getPrimaryKey());
344    
345                    dlFileVersionImpl.setFileVersionId(dlFileVersion.getFileVersionId());
346                    dlFileVersionImpl.setGroupId(dlFileVersion.getGroupId());
347                    dlFileVersionImpl.setCompanyId(dlFileVersion.getCompanyId());
348                    dlFileVersionImpl.setUserId(dlFileVersion.getUserId());
349                    dlFileVersionImpl.setUserName(dlFileVersion.getUserName());
350                    dlFileVersionImpl.setCreateDate(dlFileVersion.getCreateDate());
351                    dlFileVersionImpl.setFolderId(dlFileVersion.getFolderId());
352                    dlFileVersionImpl.setName(dlFileVersion.getName());
353                    dlFileVersionImpl.setExtension(dlFileVersion.getExtension());
354                    dlFileVersionImpl.setTitle(dlFileVersion.getTitle());
355                    dlFileVersionImpl.setDescription(dlFileVersion.getDescription());
356                    dlFileVersionImpl.setChangeLog(dlFileVersion.getChangeLog());
357                    dlFileVersionImpl.setExtraSettings(dlFileVersion.getExtraSettings());
358                    dlFileVersionImpl.setVersion(dlFileVersion.getVersion());
359                    dlFileVersionImpl.setSize(dlFileVersion.getSize());
360                    dlFileVersionImpl.setStatus(dlFileVersion.getStatus());
361                    dlFileVersionImpl.setStatusByUserId(dlFileVersion.getStatusByUserId());
362                    dlFileVersionImpl.setStatusByUserName(dlFileVersion.getStatusByUserName());
363                    dlFileVersionImpl.setStatusDate(dlFileVersion.getStatusDate());
364    
365                    return dlFileVersionImpl;
366            }
367    
368            public DLFileVersion findByPrimaryKey(Serializable primaryKey)
369                    throws NoSuchModelException, SystemException {
370                    return findByPrimaryKey(((Long)primaryKey).longValue());
371            }
372    
373            public DLFileVersion findByPrimaryKey(long fileVersionId)
374                    throws NoSuchFileVersionException, SystemException {
375                    DLFileVersion dlFileVersion = fetchByPrimaryKey(fileVersionId);
376    
377                    if (dlFileVersion == null) {
378                            if (_log.isWarnEnabled()) {
379                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + fileVersionId);
380                            }
381    
382                            throw new NoSuchFileVersionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
383                                    fileVersionId);
384                    }
385    
386                    return dlFileVersion;
387            }
388    
389            public DLFileVersion fetchByPrimaryKey(Serializable primaryKey)
390                    throws SystemException {
391                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
392            }
393    
394            public DLFileVersion fetchByPrimaryKey(long fileVersionId)
395                    throws SystemException {
396                    DLFileVersion dlFileVersion = (DLFileVersion)EntityCacheUtil.getResult(DLFileVersionModelImpl.ENTITY_CACHE_ENABLED,
397                                    DLFileVersionImpl.class, fileVersionId, this);
398    
399                    if (dlFileVersion == null) {
400                            Session session = null;
401    
402                            try {
403                                    session = openSession();
404    
405                                    dlFileVersion = (DLFileVersion)session.get(DLFileVersionImpl.class,
406                                                    new Long(fileVersionId));
407                            }
408                            catch (Exception e) {
409                                    throw processException(e);
410                            }
411                            finally {
412                                    if (dlFileVersion != null) {
413                                            cacheResult(dlFileVersion);
414                                    }
415    
416                                    closeSession(session);
417                            }
418                    }
419    
420                    return dlFileVersion;
421            }
422    
423            public List<DLFileVersion> findByG_F_N(long groupId, long folderId,
424                    String name) throws SystemException {
425                    return findByG_F_N(groupId, folderId, name, QueryUtil.ALL_POS,
426                            QueryUtil.ALL_POS, null);
427            }
428    
429            public List<DLFileVersion> findByG_F_N(long groupId, long folderId,
430                    String name, int start, int end) throws SystemException {
431                    return findByG_F_N(groupId, folderId, name, start, end, null);
432            }
433    
434            public List<DLFileVersion> findByG_F_N(long groupId, long folderId,
435                    String name, int start, int end, OrderByComparator orderByComparator)
436                    throws SystemException {
437                    Object[] finderArgs = new Object[] {
438                                    groupId, folderId, name,
439                                    
440                                    String.valueOf(start), String.valueOf(end),
441                                    String.valueOf(orderByComparator)
442                            };
443    
444                    List<DLFileVersion> list = (List<DLFileVersion>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_F_N,
445                                    finderArgs, this);
446    
447                    if (list == null) {
448                            Session session = null;
449    
450                            try {
451                                    session = openSession();
452    
453                                    StringBundler query = null;
454    
455                                    if (orderByComparator != null) {
456                                            query = new StringBundler(5 +
457                                                            (orderByComparator.getOrderByFields().length * 3));
458                                    }
459                                    else {
460                                            query = new StringBundler(5);
461                                    }
462    
463                                    query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
464    
465                                    query.append(_FINDER_COLUMN_G_F_N_GROUPID_2);
466    
467                                    query.append(_FINDER_COLUMN_G_F_N_FOLDERID_2);
468    
469                                    if (name == null) {
470                                            query.append(_FINDER_COLUMN_G_F_N_NAME_1);
471                                    }
472                                    else {
473                                            if (name.equals(StringPool.BLANK)) {
474                                                    query.append(_FINDER_COLUMN_G_F_N_NAME_3);
475                                            }
476                                            else {
477                                                    query.append(_FINDER_COLUMN_G_F_N_NAME_2);
478                                            }
479                                    }
480    
481                                    if (orderByComparator != null) {
482                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
483                                                    orderByComparator);
484                                    }
485    
486                                    else {
487                                            query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
488                                    }
489    
490                                    String sql = query.toString();
491    
492                                    Query q = session.createQuery(sql);
493    
494                                    QueryPos qPos = QueryPos.getInstance(q);
495    
496                                    qPos.add(groupId);
497    
498                                    qPos.add(folderId);
499    
500                                    if (name != null) {
501                                            qPos.add(name);
502                                    }
503    
504                                    list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
505                                                    start, end);
506                            }
507                            catch (Exception e) {
508                                    throw processException(e);
509                            }
510                            finally {
511                                    if (list == null) {
512                                            list = new ArrayList<DLFileVersion>();
513                                    }
514    
515                                    cacheResult(list);
516    
517                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_F_N,
518                                            finderArgs, list);
519    
520                                    closeSession(session);
521                            }
522                    }
523    
524                    return list;
525            }
526    
527            public DLFileVersion findByG_F_N_First(long groupId, long folderId,
528                    String name, OrderByComparator orderByComparator)
529                    throws NoSuchFileVersionException, SystemException {
530                    List<DLFileVersion> list = findByG_F_N(groupId, folderId, name, 0, 1,
531                                    orderByComparator);
532    
533                    if (list.isEmpty()) {
534                            StringBundler msg = new StringBundler(8);
535    
536                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
537    
538                            msg.append("groupId=");
539                            msg.append(groupId);
540    
541                            msg.append(", folderId=");
542                            msg.append(folderId);
543    
544                            msg.append(", name=");
545                            msg.append(name);
546    
547                            msg.append(StringPool.CLOSE_CURLY_BRACE);
548    
549                            throw new NoSuchFileVersionException(msg.toString());
550                    }
551                    else {
552                            return list.get(0);
553                    }
554            }
555    
556            public DLFileVersion findByG_F_N_Last(long groupId, long folderId,
557                    String name, OrderByComparator orderByComparator)
558                    throws NoSuchFileVersionException, SystemException {
559                    int count = countByG_F_N(groupId, folderId, name);
560    
561                    List<DLFileVersion> list = findByG_F_N(groupId, folderId, name,
562                                    count - 1, count, orderByComparator);
563    
564                    if (list.isEmpty()) {
565                            StringBundler msg = new StringBundler(8);
566    
567                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
568    
569                            msg.append("groupId=");
570                            msg.append(groupId);
571    
572                            msg.append(", folderId=");
573                            msg.append(folderId);
574    
575                            msg.append(", name=");
576                            msg.append(name);
577    
578                            msg.append(StringPool.CLOSE_CURLY_BRACE);
579    
580                            throw new NoSuchFileVersionException(msg.toString());
581                    }
582                    else {
583                            return list.get(0);
584                    }
585            }
586    
587            public DLFileVersion[] findByG_F_N_PrevAndNext(long fileVersionId,
588                    long groupId, long folderId, String name,
589                    OrderByComparator orderByComparator)
590                    throws NoSuchFileVersionException, SystemException {
591                    DLFileVersion dlFileVersion = findByPrimaryKey(fileVersionId);
592    
593                    Session session = null;
594    
595                    try {
596                            session = openSession();
597    
598                            DLFileVersion[] array = new DLFileVersionImpl[3];
599    
600                            array[0] = getByG_F_N_PrevAndNext(session, dlFileVersion, groupId,
601                                            folderId, name, orderByComparator, true);
602    
603                            array[1] = dlFileVersion;
604    
605                            array[2] = getByG_F_N_PrevAndNext(session, dlFileVersion, groupId,
606                                            folderId, name, orderByComparator, false);
607    
608                            return array;
609                    }
610                    catch (Exception e) {
611                            throw processException(e);
612                    }
613                    finally {
614                            closeSession(session);
615                    }
616            }
617    
618            protected DLFileVersion getByG_F_N_PrevAndNext(Session session,
619                    DLFileVersion dlFileVersion, long groupId, long folderId, String name,
620                    OrderByComparator orderByComparator, boolean previous) {
621                    StringBundler query = null;
622    
623                    if (orderByComparator != null) {
624                            query = new StringBundler(6 +
625                                            (orderByComparator.getOrderByFields().length * 6));
626                    }
627                    else {
628                            query = new StringBundler(3);
629                    }
630    
631                    query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
632    
633                    query.append(_FINDER_COLUMN_G_F_N_GROUPID_2);
634    
635                    query.append(_FINDER_COLUMN_G_F_N_FOLDERID_2);
636    
637                    if (name == null) {
638                            query.append(_FINDER_COLUMN_G_F_N_NAME_1);
639                    }
640                    else {
641                            if (name.equals(StringPool.BLANK)) {
642                                    query.append(_FINDER_COLUMN_G_F_N_NAME_3);
643                            }
644                            else {
645                                    query.append(_FINDER_COLUMN_G_F_N_NAME_2);
646                            }
647                    }
648    
649                    if (orderByComparator != null) {
650                            String[] orderByFields = orderByComparator.getOrderByFields();
651    
652                            if (orderByFields.length > 0) {
653                                    query.append(WHERE_AND);
654                            }
655    
656                            for (int i = 0; i < orderByFields.length; i++) {
657                                    query.append(_ORDER_BY_ENTITY_ALIAS);
658                                    query.append(orderByFields[i]);
659    
660                                    if ((i + 1) < orderByFields.length) {
661                                            if (orderByComparator.isAscending() ^ previous) {
662                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
663                                            }
664                                            else {
665                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
666                                            }
667                                    }
668                                    else {
669                                            if (orderByComparator.isAscending() ^ previous) {
670                                                    query.append(WHERE_GREATER_THAN);
671                                            }
672                                            else {
673                                                    query.append(WHERE_LESSER_THAN);
674                                            }
675                                    }
676                            }
677    
678                            query.append(ORDER_BY_CLAUSE);
679    
680                            for (int i = 0; i < orderByFields.length; i++) {
681                                    query.append(_ORDER_BY_ENTITY_ALIAS);
682                                    query.append(orderByFields[i]);
683    
684                                    if ((i + 1) < orderByFields.length) {
685                                            if (orderByComparator.isAscending() ^ previous) {
686                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
687                                            }
688                                            else {
689                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
690                                            }
691                                    }
692                                    else {
693                                            if (orderByComparator.isAscending() ^ previous) {
694                                                    query.append(ORDER_BY_ASC);
695                                            }
696                                            else {
697                                                    query.append(ORDER_BY_DESC);
698                                            }
699                                    }
700                            }
701                    }
702    
703                    else {
704                            query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
705                    }
706    
707                    String sql = query.toString();
708    
709                    Query q = session.createQuery(sql);
710    
711                    q.setFirstResult(0);
712                    q.setMaxResults(2);
713    
714                    QueryPos qPos = QueryPos.getInstance(q);
715    
716                    qPos.add(groupId);
717    
718                    qPos.add(folderId);
719    
720                    if (name != null) {
721                            qPos.add(name);
722                    }
723    
724                    if (orderByComparator != null) {
725                            Object[] values = orderByComparator.getOrderByValues(dlFileVersion);
726    
727                            for (Object value : values) {
728                                    qPos.add(value);
729                            }
730                    }
731    
732                    List<DLFileVersion> list = q.list();
733    
734                    if (list.size() == 2) {
735                            return list.get(1);
736                    }
737                    else {
738                            return null;
739                    }
740            }
741    
742            public DLFileVersion findByG_F_N_V(long groupId, long folderId,
743                    String name, String version)
744                    throws NoSuchFileVersionException, SystemException {
745                    DLFileVersion dlFileVersion = fetchByG_F_N_V(groupId, folderId, name,
746                                    version);
747    
748                    if (dlFileVersion == null) {
749                            StringBundler msg = new StringBundler(10);
750    
751                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
752    
753                            msg.append("groupId=");
754                            msg.append(groupId);
755    
756                            msg.append(", folderId=");
757                            msg.append(folderId);
758    
759                            msg.append(", name=");
760                            msg.append(name);
761    
762                            msg.append(", version=");
763                            msg.append(version);
764    
765                            msg.append(StringPool.CLOSE_CURLY_BRACE);
766    
767                            if (_log.isWarnEnabled()) {
768                                    _log.warn(msg.toString());
769                            }
770    
771                            throw new NoSuchFileVersionException(msg.toString());
772                    }
773    
774                    return dlFileVersion;
775            }
776    
777            public DLFileVersion fetchByG_F_N_V(long groupId, long folderId,
778                    String name, String version) throws SystemException {
779                    return fetchByG_F_N_V(groupId, folderId, name, version, true);
780            }
781    
782            public DLFileVersion fetchByG_F_N_V(long groupId, long folderId,
783                    String name, String version, boolean retrieveFromCache)
784                    throws SystemException {
785                    Object[] finderArgs = new Object[] { groupId, folderId, name, version };
786    
787                    Object result = null;
788    
789                    if (retrieveFromCache) {
790                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_F_N_V,
791                                            finderArgs, this);
792                    }
793    
794                    if (result == null) {
795                            Session session = null;
796    
797                            try {
798                                    session = openSession();
799    
800                                    StringBundler query = new StringBundler(6);
801    
802                                    query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
803    
804                                    query.append(_FINDER_COLUMN_G_F_N_V_GROUPID_2);
805    
806                                    query.append(_FINDER_COLUMN_G_F_N_V_FOLDERID_2);
807    
808                                    if (name == null) {
809                                            query.append(_FINDER_COLUMN_G_F_N_V_NAME_1);
810                                    }
811                                    else {
812                                            if (name.equals(StringPool.BLANK)) {
813                                                    query.append(_FINDER_COLUMN_G_F_N_V_NAME_3);
814                                            }
815                                            else {
816                                                    query.append(_FINDER_COLUMN_G_F_N_V_NAME_2);
817                                            }
818                                    }
819    
820                                    if (version == null) {
821                                            query.append(_FINDER_COLUMN_G_F_N_V_VERSION_1);
822                                    }
823                                    else {
824                                            if (version.equals(StringPool.BLANK)) {
825                                                    query.append(_FINDER_COLUMN_G_F_N_V_VERSION_3);
826                                            }
827                                            else {
828                                                    query.append(_FINDER_COLUMN_G_F_N_V_VERSION_2);
829                                            }
830                                    }
831    
832                                    query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
833    
834                                    String sql = query.toString();
835    
836                                    Query q = session.createQuery(sql);
837    
838                                    QueryPos qPos = QueryPos.getInstance(q);
839    
840                                    qPos.add(groupId);
841    
842                                    qPos.add(folderId);
843    
844                                    if (name != null) {
845                                            qPos.add(name);
846                                    }
847    
848                                    if (version != null) {
849                                            qPos.add(version);
850                                    }
851    
852                                    List<DLFileVersion> list = q.list();
853    
854                                    result = list;
855    
856                                    DLFileVersion dlFileVersion = null;
857    
858                                    if (list.isEmpty()) {
859                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_F_N_V,
860                                                    finderArgs, list);
861                                    }
862                                    else {
863                                            dlFileVersion = list.get(0);
864    
865                                            cacheResult(dlFileVersion);
866    
867                                            if ((dlFileVersion.getGroupId() != groupId) ||
868                                                            (dlFileVersion.getFolderId() != folderId) ||
869                                                            (dlFileVersion.getName() == null) ||
870                                                            !dlFileVersion.getName().equals(name) ||
871                                                            (dlFileVersion.getVersion() == null) ||
872                                                            !dlFileVersion.getVersion().equals(version)) {
873                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_F_N_V,
874                                                            finderArgs, dlFileVersion);
875                                            }
876                                    }
877    
878                                    return dlFileVersion;
879                            }
880                            catch (Exception e) {
881                                    throw processException(e);
882                            }
883                            finally {
884                                    if (result == null) {
885                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_F_N_V,
886                                                    finderArgs, new ArrayList<DLFileVersion>());
887                                    }
888    
889                                    closeSession(session);
890                            }
891                    }
892                    else {
893                            if (result instanceof List<?>) {
894                                    return null;
895                            }
896                            else {
897                                    return (DLFileVersion)result;
898                            }
899                    }
900            }
901    
902            public List<DLFileVersion> findByG_F_N_S(long groupId, long folderId,
903                    String name, int status) throws SystemException {
904                    return findByG_F_N_S(groupId, folderId, name, status,
905                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
906            }
907    
908            public List<DLFileVersion> findByG_F_N_S(long groupId, long folderId,
909                    String name, int status, int start, int end) throws SystemException {
910                    return findByG_F_N_S(groupId, folderId, name, status, start, end, null);
911            }
912    
913            public List<DLFileVersion> findByG_F_N_S(long groupId, long folderId,
914                    String name, int status, int start, int end,
915                    OrderByComparator orderByComparator) throws SystemException {
916                    Object[] finderArgs = new Object[] {
917                                    groupId, folderId, name, status,
918                                    
919                                    String.valueOf(start), String.valueOf(end),
920                                    String.valueOf(orderByComparator)
921                            };
922    
923                    List<DLFileVersion> list = (List<DLFileVersion>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_F_N_S,
924                                    finderArgs, this);
925    
926                    if (list == null) {
927                            Session session = null;
928    
929                            try {
930                                    session = openSession();
931    
932                                    StringBundler query = null;
933    
934                                    if (orderByComparator != null) {
935                                            query = new StringBundler(6 +
936                                                            (orderByComparator.getOrderByFields().length * 3));
937                                    }
938                                    else {
939                                            query = new StringBundler(6);
940                                    }
941    
942                                    query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
943    
944                                    query.append(_FINDER_COLUMN_G_F_N_S_GROUPID_2);
945    
946                                    query.append(_FINDER_COLUMN_G_F_N_S_FOLDERID_2);
947    
948                                    if (name == null) {
949                                            query.append(_FINDER_COLUMN_G_F_N_S_NAME_1);
950                                    }
951                                    else {
952                                            if (name.equals(StringPool.BLANK)) {
953                                                    query.append(_FINDER_COLUMN_G_F_N_S_NAME_3);
954                                            }
955                                            else {
956                                                    query.append(_FINDER_COLUMN_G_F_N_S_NAME_2);
957                                            }
958                                    }
959    
960                                    query.append(_FINDER_COLUMN_G_F_N_S_STATUS_2);
961    
962                                    if (orderByComparator != null) {
963                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
964                                                    orderByComparator);
965                                    }
966    
967                                    else {
968                                            query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
969                                    }
970    
971                                    String sql = query.toString();
972    
973                                    Query q = session.createQuery(sql);
974    
975                                    QueryPos qPos = QueryPos.getInstance(q);
976    
977                                    qPos.add(groupId);
978    
979                                    qPos.add(folderId);
980    
981                                    if (name != null) {
982                                            qPos.add(name);
983                                    }
984    
985                                    qPos.add(status);
986    
987                                    list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
988                                                    start, end);
989                            }
990                            catch (Exception e) {
991                                    throw processException(e);
992                            }
993                            finally {
994                                    if (list == null) {
995                                            list = new ArrayList<DLFileVersion>();
996                                    }
997    
998                                    cacheResult(list);
999    
1000                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_F_N_S,
1001                                            finderArgs, list);
1002    
1003                                    closeSession(session);
1004                            }
1005                    }
1006    
1007                    return list;
1008            }
1009    
1010            public DLFileVersion findByG_F_N_S_First(long groupId, long folderId,
1011                    String name, int status, OrderByComparator orderByComparator)
1012                    throws NoSuchFileVersionException, SystemException {
1013                    List<DLFileVersion> list = findByG_F_N_S(groupId, folderId, name,
1014                                    status, 0, 1, orderByComparator);
1015    
1016                    if (list.isEmpty()) {
1017                            StringBundler msg = new StringBundler(10);
1018    
1019                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1020    
1021                            msg.append("groupId=");
1022                            msg.append(groupId);
1023    
1024                            msg.append(", folderId=");
1025                            msg.append(folderId);
1026    
1027                            msg.append(", name=");
1028                            msg.append(name);
1029    
1030                            msg.append(", status=");
1031                            msg.append(status);
1032    
1033                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1034    
1035                            throw new NoSuchFileVersionException(msg.toString());
1036                    }
1037                    else {
1038                            return list.get(0);
1039                    }
1040            }
1041    
1042            public DLFileVersion findByG_F_N_S_Last(long groupId, long folderId,
1043                    String name, int status, OrderByComparator orderByComparator)
1044                    throws NoSuchFileVersionException, SystemException {
1045                    int count = countByG_F_N_S(groupId, folderId, name, status);
1046    
1047                    List<DLFileVersion> list = findByG_F_N_S(groupId, folderId, name,
1048                                    status, count - 1, count, orderByComparator);
1049    
1050                    if (list.isEmpty()) {
1051                            StringBundler msg = new StringBundler(10);
1052    
1053                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1054    
1055                            msg.append("groupId=");
1056                            msg.append(groupId);
1057    
1058                            msg.append(", folderId=");
1059                            msg.append(folderId);
1060    
1061                            msg.append(", name=");
1062                            msg.append(name);
1063    
1064                            msg.append(", status=");
1065                            msg.append(status);
1066    
1067                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1068    
1069                            throw new NoSuchFileVersionException(msg.toString());
1070                    }
1071                    else {
1072                            return list.get(0);
1073                    }
1074            }
1075    
1076            public DLFileVersion[] findByG_F_N_S_PrevAndNext(long fileVersionId,
1077                    long groupId, long folderId, String name, int status,
1078                    OrderByComparator orderByComparator)
1079                    throws NoSuchFileVersionException, SystemException {
1080                    DLFileVersion dlFileVersion = findByPrimaryKey(fileVersionId);
1081    
1082                    Session session = null;
1083    
1084                    try {
1085                            session = openSession();
1086    
1087                            DLFileVersion[] array = new DLFileVersionImpl[3];
1088    
1089                            array[0] = getByG_F_N_S_PrevAndNext(session, dlFileVersion,
1090                                            groupId, folderId, name, status, orderByComparator, true);
1091    
1092                            array[1] = dlFileVersion;
1093    
1094                            array[2] = getByG_F_N_S_PrevAndNext(session, dlFileVersion,
1095                                            groupId, folderId, name, status, orderByComparator, false);
1096    
1097                            return array;
1098                    }
1099                    catch (Exception e) {
1100                            throw processException(e);
1101                    }
1102                    finally {
1103                            closeSession(session);
1104                    }
1105            }
1106    
1107            protected DLFileVersion getByG_F_N_S_PrevAndNext(Session session,
1108                    DLFileVersion dlFileVersion, long groupId, long folderId, String name,
1109                    int status, OrderByComparator orderByComparator, boolean previous) {
1110                    StringBundler query = null;
1111    
1112                    if (orderByComparator != null) {
1113                            query = new StringBundler(6 +
1114                                            (orderByComparator.getOrderByFields().length * 6));
1115                    }
1116                    else {
1117                            query = new StringBundler(3);
1118                    }
1119    
1120                    query.append(_SQL_SELECT_DLFILEVERSION_WHERE);
1121    
1122                    query.append(_FINDER_COLUMN_G_F_N_S_GROUPID_2);
1123    
1124                    query.append(_FINDER_COLUMN_G_F_N_S_FOLDERID_2);
1125    
1126                    if (name == null) {
1127                            query.append(_FINDER_COLUMN_G_F_N_S_NAME_1);
1128                    }
1129                    else {
1130                            if (name.equals(StringPool.BLANK)) {
1131                                    query.append(_FINDER_COLUMN_G_F_N_S_NAME_3);
1132                            }
1133                            else {
1134                                    query.append(_FINDER_COLUMN_G_F_N_S_NAME_2);
1135                            }
1136                    }
1137    
1138                    query.append(_FINDER_COLUMN_G_F_N_S_STATUS_2);
1139    
1140                    if (orderByComparator != null) {
1141                            String[] orderByFields = orderByComparator.getOrderByFields();
1142    
1143                            if (orderByFields.length > 0) {
1144                                    query.append(WHERE_AND);
1145                            }
1146    
1147                            for (int i = 0; i < orderByFields.length; i++) {
1148                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1149                                    query.append(orderByFields[i]);
1150    
1151                                    if ((i + 1) < orderByFields.length) {
1152                                            if (orderByComparator.isAscending() ^ previous) {
1153                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1154                                            }
1155                                            else {
1156                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1157                                            }
1158                                    }
1159                                    else {
1160                                            if (orderByComparator.isAscending() ^ previous) {
1161                                                    query.append(WHERE_GREATER_THAN);
1162                                            }
1163                                            else {
1164                                                    query.append(WHERE_LESSER_THAN);
1165                                            }
1166                                    }
1167                            }
1168    
1169                            query.append(ORDER_BY_CLAUSE);
1170    
1171                            for (int i = 0; i < orderByFields.length; i++) {
1172                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1173                                    query.append(orderByFields[i]);
1174    
1175                                    if ((i + 1) < orderByFields.length) {
1176                                            if (orderByComparator.isAscending() ^ previous) {
1177                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1178                                            }
1179                                            else {
1180                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1181                                            }
1182                                    }
1183                                    else {
1184                                            if (orderByComparator.isAscending() ^ previous) {
1185                                                    query.append(ORDER_BY_ASC);
1186                                            }
1187                                            else {
1188                                                    query.append(ORDER_BY_DESC);
1189                                            }
1190                                    }
1191                            }
1192                    }
1193    
1194                    else {
1195                            query.append(DLFileVersionModelImpl.ORDER_BY_JPQL);
1196                    }
1197    
1198                    String sql = query.toString();
1199    
1200                    Query q = session.createQuery(sql);
1201    
1202                    q.setFirstResult(0);
1203                    q.setMaxResults(2);
1204    
1205                    QueryPos qPos = QueryPos.getInstance(q);
1206    
1207                    qPos.add(groupId);
1208    
1209                    qPos.add(folderId);
1210    
1211                    if (name != null) {
1212                            qPos.add(name);
1213                    }
1214    
1215                    qPos.add(status);
1216    
1217                    if (orderByComparator != null) {
1218                            Object[] values = orderByComparator.getOrderByValues(dlFileVersion);
1219    
1220                            for (Object value : values) {
1221                                    qPos.add(value);
1222                            }
1223                    }
1224    
1225                    List<DLFileVersion> list = q.list();
1226    
1227                    if (list.size() == 2) {
1228                            return list.get(1);
1229                    }
1230                    else {
1231                            return null;
1232                    }
1233            }
1234    
1235            public List<DLFileVersion> findAll() throws SystemException {
1236                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1237            }
1238    
1239            public List<DLFileVersion> findAll(int start, int end)
1240                    throws SystemException {
1241                    return findAll(start, end, null);
1242            }
1243    
1244            public List<DLFileVersion> findAll(int start, int end,
1245                    OrderByComparator orderByComparator) throws SystemException {
1246                    Object[] finderArgs = new Object[] {
1247                                    String.valueOf(start), String.valueOf(end),
1248                                    String.valueOf(orderByComparator)
1249                            };
1250    
1251                    List<DLFileVersion> list = (List<DLFileVersion>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1252                                    finderArgs, this);
1253    
1254                    if (list == null) {
1255                            Session session = null;
1256    
1257                            try {
1258                                    session = openSession();
1259    
1260                                    StringBundler query = null;
1261                                    String sql = null;
1262    
1263                                    if (orderByComparator != null) {
1264                                            query = new StringBundler(2 +
1265                                                            (orderByComparator.getOrderByFields().length * 3));
1266    
1267                                            query.append(_SQL_SELECT_DLFILEVERSION);
1268    
1269                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1270                                                    orderByComparator);
1271    
1272                                            sql = query.toString();
1273                                    }
1274                                    else {
1275                                            sql = _SQL_SELECT_DLFILEVERSION.concat(DLFileVersionModelImpl.ORDER_BY_JPQL);
1276                                    }
1277    
1278                                    Query q = session.createQuery(sql);
1279    
1280                                    if (orderByComparator == null) {
1281                                            list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
1282                                                            start, end, false);
1283    
1284                                            Collections.sort(list);
1285                                    }
1286                                    else {
1287                                            list = (List<DLFileVersion>)QueryUtil.list(q, getDialect(),
1288                                                            start, end);
1289                                    }
1290                            }
1291                            catch (Exception e) {
1292                                    throw processException(e);
1293                            }
1294                            finally {
1295                                    if (list == null) {
1296                                            list = new ArrayList<DLFileVersion>();
1297                                    }
1298    
1299                                    cacheResult(list);
1300    
1301                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1302    
1303                                    closeSession(session);
1304                            }
1305                    }
1306    
1307                    return list;
1308            }
1309    
1310            public void removeByG_F_N(long groupId, long folderId, String name)
1311                    throws SystemException {
1312                    for (DLFileVersion dlFileVersion : findByG_F_N(groupId, folderId, name)) {
1313                            remove(dlFileVersion);
1314                    }
1315            }
1316    
1317            public void removeByG_F_N_V(long groupId, long folderId, String name,
1318                    String version) throws NoSuchFileVersionException, SystemException {
1319                    DLFileVersion dlFileVersion = findByG_F_N_V(groupId, folderId, name,
1320                                    version);
1321    
1322                    remove(dlFileVersion);
1323            }
1324    
1325            public void removeByG_F_N_S(long groupId, long folderId, String name,
1326                    int status) throws SystemException {
1327                    for (DLFileVersion dlFileVersion : findByG_F_N_S(groupId, folderId,
1328                                    name, status)) {
1329                            remove(dlFileVersion);
1330                    }
1331            }
1332    
1333            public void removeAll() throws SystemException {
1334                    for (DLFileVersion dlFileVersion : findAll()) {
1335                            remove(dlFileVersion);
1336                    }
1337            }
1338    
1339            public int countByG_F_N(long groupId, long folderId, String name)
1340                    throws SystemException {
1341                    Object[] finderArgs = new Object[] { groupId, folderId, name };
1342    
1343                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_F_N,
1344                                    finderArgs, this);
1345    
1346                    if (count == null) {
1347                            Session session = null;
1348    
1349                            try {
1350                                    session = openSession();
1351    
1352                                    StringBundler query = new StringBundler(4);
1353    
1354                                    query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
1355    
1356                                    query.append(_FINDER_COLUMN_G_F_N_GROUPID_2);
1357    
1358                                    query.append(_FINDER_COLUMN_G_F_N_FOLDERID_2);
1359    
1360                                    if (name == null) {
1361                                            query.append(_FINDER_COLUMN_G_F_N_NAME_1);
1362                                    }
1363                                    else {
1364                                            if (name.equals(StringPool.BLANK)) {
1365                                                    query.append(_FINDER_COLUMN_G_F_N_NAME_3);
1366                                            }
1367                                            else {
1368                                                    query.append(_FINDER_COLUMN_G_F_N_NAME_2);
1369                                            }
1370                                    }
1371    
1372                                    String sql = query.toString();
1373    
1374                                    Query q = session.createQuery(sql);
1375    
1376                                    QueryPos qPos = QueryPos.getInstance(q);
1377    
1378                                    qPos.add(groupId);
1379    
1380                                    qPos.add(folderId);
1381    
1382                                    if (name != null) {
1383                                            qPos.add(name);
1384                                    }
1385    
1386                                    count = (Long)q.uniqueResult();
1387                            }
1388                            catch (Exception e) {
1389                                    throw processException(e);
1390                            }
1391                            finally {
1392                                    if (count == null) {
1393                                            count = Long.valueOf(0);
1394                                    }
1395    
1396                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_F_N,
1397                                            finderArgs, count);
1398    
1399                                    closeSession(session);
1400                            }
1401                    }
1402    
1403                    return count.intValue();
1404            }
1405    
1406            public int countByG_F_N_V(long groupId, long folderId, String name,
1407                    String version) throws SystemException {
1408                    Object[] finderArgs = new Object[] { groupId, folderId, name, version };
1409    
1410                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_F_N_V,
1411                                    finderArgs, this);
1412    
1413                    if (count == null) {
1414                            Session session = null;
1415    
1416                            try {
1417                                    session = openSession();
1418    
1419                                    StringBundler query = new StringBundler(5);
1420    
1421                                    query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
1422    
1423                                    query.append(_FINDER_COLUMN_G_F_N_V_GROUPID_2);
1424    
1425                                    query.append(_FINDER_COLUMN_G_F_N_V_FOLDERID_2);
1426    
1427                                    if (name == null) {
1428                                            query.append(_FINDER_COLUMN_G_F_N_V_NAME_1);
1429                                    }
1430                                    else {
1431                                            if (name.equals(StringPool.BLANK)) {
1432                                                    query.append(_FINDER_COLUMN_G_F_N_V_NAME_3);
1433                                            }
1434                                            else {
1435                                                    query.append(_FINDER_COLUMN_G_F_N_V_NAME_2);
1436                                            }
1437                                    }
1438    
1439                                    if (version == null) {
1440                                            query.append(_FINDER_COLUMN_G_F_N_V_VERSION_1);
1441                                    }
1442                                    else {
1443                                            if (version.equals(StringPool.BLANK)) {
1444                                                    query.append(_FINDER_COLUMN_G_F_N_V_VERSION_3);
1445                                            }
1446                                            else {
1447                                                    query.append(_FINDER_COLUMN_G_F_N_V_VERSION_2);
1448                                            }
1449                                    }
1450    
1451                                    String sql = query.toString();
1452    
1453                                    Query q = session.createQuery(sql);
1454    
1455                                    QueryPos qPos = QueryPos.getInstance(q);
1456    
1457                                    qPos.add(groupId);
1458    
1459                                    qPos.add(folderId);
1460    
1461                                    if (name != null) {
1462                                            qPos.add(name);
1463                                    }
1464    
1465                                    if (version != null) {
1466                                            qPos.add(version);
1467                                    }
1468    
1469                                    count = (Long)q.uniqueResult();
1470                            }
1471                            catch (Exception e) {
1472                                    throw processException(e);
1473                            }
1474                            finally {
1475                                    if (count == null) {
1476                                            count = Long.valueOf(0);
1477                                    }
1478    
1479                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_F_N_V,
1480                                            finderArgs, count);
1481    
1482                                    closeSession(session);
1483                            }
1484                    }
1485    
1486                    return count.intValue();
1487            }
1488    
1489            public int countByG_F_N_S(long groupId, long folderId, String name,
1490                    int status) throws SystemException {
1491                    Object[] finderArgs = new Object[] { groupId, folderId, name, status };
1492    
1493                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_F_N_S,
1494                                    finderArgs, this);
1495    
1496                    if (count == null) {
1497                            Session session = null;
1498    
1499                            try {
1500                                    session = openSession();
1501    
1502                                    StringBundler query = new StringBundler(5);
1503    
1504                                    query.append(_SQL_COUNT_DLFILEVERSION_WHERE);
1505    
1506                                    query.append(_FINDER_COLUMN_G_F_N_S_GROUPID_2);
1507    
1508                                    query.append(_FINDER_COLUMN_G_F_N_S_FOLDERID_2);
1509    
1510                                    if (name == null) {
1511                                            query.append(_FINDER_COLUMN_G_F_N_S_NAME_1);
1512                                    }
1513                                    else {
1514                                            if (name.equals(StringPool.BLANK)) {
1515                                                    query.append(_FINDER_COLUMN_G_F_N_S_NAME_3);
1516                                            }
1517                                            else {
1518                                                    query.append(_FINDER_COLUMN_G_F_N_S_NAME_2);
1519                                            }
1520                                    }
1521    
1522                                    query.append(_FINDER_COLUMN_G_F_N_S_STATUS_2);
1523    
1524                                    String sql = query.toString();
1525    
1526                                    Query q = session.createQuery(sql);
1527    
1528                                    QueryPos qPos = QueryPos.getInstance(q);
1529    
1530                                    qPos.add(groupId);
1531    
1532                                    qPos.add(folderId);
1533    
1534                                    if (name != null) {
1535                                            qPos.add(name);
1536                                    }
1537    
1538                                    qPos.add(status);
1539    
1540                                    count = (Long)q.uniqueResult();
1541                            }
1542                            catch (Exception e) {
1543                                    throw processException(e);
1544                            }
1545                            finally {
1546                                    if (count == null) {
1547                                            count = Long.valueOf(0);
1548                                    }
1549    
1550                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_F_N_S,
1551                                            finderArgs, count);
1552    
1553                                    closeSession(session);
1554                            }
1555                    }
1556    
1557                    return count.intValue();
1558            }
1559    
1560            public int countAll() throws SystemException {
1561                    Object[] finderArgs = new Object[0];
1562    
1563                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1564                                    finderArgs, this);
1565    
1566                    if (count == null) {
1567                            Session session = null;
1568    
1569                            try {
1570                                    session = openSession();
1571    
1572                                    Query q = session.createQuery(_SQL_COUNT_DLFILEVERSION);
1573    
1574                                    count = (Long)q.uniqueResult();
1575                            }
1576                            catch (Exception e) {
1577                                    throw processException(e);
1578                            }
1579                            finally {
1580                                    if (count == null) {
1581                                            count = Long.valueOf(0);
1582                                    }
1583    
1584                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1585                                            count);
1586    
1587                                    closeSession(session);
1588                            }
1589                    }
1590    
1591                    return count.intValue();
1592            }
1593    
1594            public void afterPropertiesSet() {
1595                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1596                                            com.liferay.portal.util.PropsUtil.get(
1597                                                    "value.object.listener.com.liferay.portlet.documentlibrary.model.DLFileVersion")));
1598    
1599                    if (listenerClassNames.length > 0) {
1600                            try {
1601                                    List<ModelListener<DLFileVersion>> listenersList = new ArrayList<ModelListener<DLFileVersion>>();
1602    
1603                                    for (String listenerClassName : listenerClassNames) {
1604                                            listenersList.add((ModelListener<DLFileVersion>)InstanceFactory.newInstance(
1605                                                            listenerClassName));
1606                                    }
1607    
1608                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1609                            }
1610                            catch (Exception e) {
1611                                    _log.error(e);
1612                            }
1613                    }
1614            }
1615    
1616            @BeanReference(type = DLFileEntryPersistence.class)
1617            protected DLFileEntryPersistence dlFileEntryPersistence;
1618            @BeanReference(type = DLFileRankPersistence.class)
1619            protected DLFileRankPersistence dlFileRankPersistence;
1620            @BeanReference(type = DLFileShortcutPersistence.class)
1621            protected DLFileShortcutPersistence dlFileShortcutPersistence;
1622            @BeanReference(type = DLFileVersionPersistence.class)
1623            protected DLFileVersionPersistence dlFileVersionPersistence;
1624            @BeanReference(type = DLFolderPersistence.class)
1625            protected DLFolderPersistence dlFolderPersistence;
1626            @BeanReference(type = ResourcePersistence.class)
1627            protected ResourcePersistence resourcePersistence;
1628            @BeanReference(type = UserPersistence.class)
1629            protected UserPersistence userPersistence;
1630            @BeanReference(type = AssetEntryPersistence.class)
1631            protected AssetEntryPersistence assetEntryPersistence;
1632            private static final String _SQL_SELECT_DLFILEVERSION = "SELECT dlFileVersion FROM DLFileVersion dlFileVersion";
1633            private static final String _SQL_SELECT_DLFILEVERSION_WHERE = "SELECT dlFileVersion FROM DLFileVersion dlFileVersion WHERE ";
1634            private static final String _SQL_COUNT_DLFILEVERSION = "SELECT COUNT(dlFileVersion) FROM DLFileVersion dlFileVersion";
1635            private static final String _SQL_COUNT_DLFILEVERSION_WHERE = "SELECT COUNT(dlFileVersion) FROM DLFileVersion dlFileVersion WHERE ";
1636            private static final String _FINDER_COLUMN_G_F_N_GROUPID_2 = "dlFileVersion.groupId = ? AND ";
1637            private static final String _FINDER_COLUMN_G_F_N_FOLDERID_2 = "dlFileVersion.folderId = ? AND ";
1638            private static final String _FINDER_COLUMN_G_F_N_NAME_1 = "dlFileVersion.name IS NULL";
1639            private static final String _FINDER_COLUMN_G_F_N_NAME_2 = "dlFileVersion.name = ?";
1640            private static final String _FINDER_COLUMN_G_F_N_NAME_3 = "(dlFileVersion.name IS NULL OR dlFileVersion.name = ?)";
1641            private static final String _FINDER_COLUMN_G_F_N_V_GROUPID_2 = "dlFileVersion.groupId = ? AND ";
1642            private static final String _FINDER_COLUMN_G_F_N_V_FOLDERID_2 = "dlFileVersion.folderId = ? AND ";
1643            private static final String _FINDER_COLUMN_G_F_N_V_NAME_1 = "dlFileVersion.name IS NULL AND ";
1644            private static final String _FINDER_COLUMN_G_F_N_V_NAME_2 = "dlFileVersion.name = ? AND ";
1645            private static final String _FINDER_COLUMN_G_F_N_V_NAME_3 = "(dlFileVersion.name IS NULL OR dlFileVersion.name = ?) AND ";
1646            private static final String _FINDER_COLUMN_G_F_N_V_VERSION_1 = "dlFileVersion.version IS NULL";
1647            private static final String _FINDER_COLUMN_G_F_N_V_VERSION_2 = "dlFileVersion.version = ?";
1648            private static final String _FINDER_COLUMN_G_F_N_V_VERSION_3 = "(dlFileVersion.version IS NULL OR dlFileVersion.version = ?)";
1649            private static final String _FINDER_COLUMN_G_F_N_S_GROUPID_2 = "dlFileVersion.groupId = ? AND ";
1650            private static final String _FINDER_COLUMN_G_F_N_S_FOLDERID_2 = "dlFileVersion.folderId = ? AND ";
1651            private static final String _FINDER_COLUMN_G_F_N_S_NAME_1 = "dlFileVersion.name IS NULL AND ";
1652            private static final String _FINDER_COLUMN_G_F_N_S_NAME_2 = "dlFileVersion.name = ? AND ";
1653            private static final String _FINDER_COLUMN_G_F_N_S_NAME_3 = "(dlFileVersion.name IS NULL OR dlFileVersion.name = ?) AND ";
1654            private static final String _FINDER_COLUMN_G_F_N_S_STATUS_2 = "dlFileVersion.status = ?";
1655            private static final String _ORDER_BY_ENTITY_ALIAS = "dlFileVersion.";
1656            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DLFileVersion exists with the primary key ";
1657            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DLFileVersion exists with the key {";
1658            private static Log _log = LogFactoryUtil.getLog(DLFileVersionPersistenceImpl.class);
1659    }