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.portlet.documentlibrary.service.persistence.impl;
016    
017    import com.liferay.portal.kernel.dao.orm.SQLQuery;
018    import com.liferay.portal.kernel.dao.orm.Session;
019    import com.liferay.portal.kernel.exception.SystemException;
020    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
021    import com.liferay.portlet.documentlibrary.model.DLFileEntryMetadata;
022    import com.liferay.portlet.documentlibrary.model.impl.DLFileEntryMetadataImpl;
023    import com.liferay.portlet.documentlibrary.service.persistence.DLFileEntryMetadataFinder;
024    import com.liferay.util.dao.orm.CustomSQLUtil;
025    
026    import java.util.List;
027    
028    /**
029     * @author Michael C. Han
030     */
031    public class DLFileEntryMetadataFinderImpl
032            extends BasePersistenceImpl<DLFileEntryMetadata>
033            implements DLFileEntryMetadataFinder {
034    
035            public static final String FIND_BY_MISMATCHED_COMPANY_ID =
036                    DLFileEntryMetadataFinder.class.getName() +
037                            ".findByMismatchedCompanyId";
038    
039            public static final String FIND_BY_NO_STRUCTURES =
040                    DLFileEntryMetadataFinder.class.getName() + ".findByNoStructures";
041    
042            @Override
043            public List<DLFileEntryMetadata> findByMismatchedCompanyId() {
044                    Session session = null;
045    
046                    try {
047                            session = openSession();
048    
049                            String sql = CustomSQLUtil.get(FIND_BY_MISMATCHED_COMPANY_ID);
050    
051                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
052    
053                            q.addEntity(
054                                    DLFileEntryMetadataImpl.TABLE_NAME,
055                                    DLFileEntryMetadataImpl.class);
056    
057                            return q.list(true);
058                    }
059                    catch (Exception e) {
060                            throw new SystemException(e);
061                    }
062                    finally {
063                            closeSession(session);
064                    }
065            }
066    
067            @Override
068            public List<DLFileEntryMetadata> findByNoStructures() {
069                    Session session = null;
070    
071                    try {
072                            session = openSession();
073    
074                            String sql = CustomSQLUtil.get(FIND_BY_NO_STRUCTURES);
075    
076                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
077    
078                            q.addEntity(
079                                    DLFileEntryMetadataImpl.TABLE_NAME,
080                                    DLFileEntryMetadataImpl.class);
081    
082                            return q.list(true);
083                    }
084                    catch (Exception e) {
085                            throw new SystemException(e);
086                    }
087                    finally {
088                            closeSession(session);
089                    }
090            }
091    
092    }