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