001    /**
002     * Copyright (c) 2000-2013 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.bookmarks.service.persistence;
016    
017    import com.liferay.portal.kernel.dao.orm.QueryPos;
018    import com.liferay.portal.kernel.dao.orm.SQLQuery;
019    import com.liferay.portal.kernel.dao.orm.Session;
020    import com.liferay.portal.kernel.exception.SystemException;
021    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
022    import com.liferay.portlet.bookmarks.model.BookmarksEntry;
023    import com.liferay.portlet.bookmarks.model.impl.BookmarksEntryImpl;
024    import com.liferay.util.dao.orm.CustomSQLUtil;
025    
026    import java.util.List;
027    
028    /**
029     * @author Brian Wing Shun Chan
030     */
031    public class BookmarksEntryFinderImpl
032            extends BasePersistenceImpl<BookmarksEntry>
033            implements BookmarksEntryFinder {
034    
035            public static final String FIND_BY_NO_ASSETS =
036                    BookmarksEntryFinder.class.getName() + ".findByNoAssets";
037    
038            public static final String FIND_BY_NO_RESOURCE_BLOCKS =
039                    BookmarksEntryFinder.class.getName() + ".findByNoResourceBlocks";
040    
041            @Override
042            public List<BookmarksEntry> findByNoAssets() throws SystemException {
043                    Session session = null;
044    
045                    try {
046                            session = openSession();
047    
048                            String sql = CustomSQLUtil.get(FIND_BY_NO_ASSETS);
049    
050                            SQLQuery q = session.createSQLQuery(sql);
051    
052                            q.addEntity("BookmarksEntry", BookmarksEntryImpl.class);
053    
054                            return q.list(true);
055                    }
056                    catch (Exception e) {
057                            throw new SystemException(e);
058                    }
059                    finally {
060                            closeSession(session);
061                    }
062            }
063    
064            @Override
065            public List<BookmarksEntry> findByNoResourceBlocks()
066                    throws SystemException {
067    
068                    Session session = null;
069    
070                    try {
071                            session = openSession();
072    
073                            String sql = CustomSQLUtil.get(FIND_BY_NO_RESOURCE_BLOCKS);
074    
075                            SQLQuery q = session.createSQLQuery(sql);
076    
077                            q.addEntity("BookmarksEntry", BookmarksEntryImpl.class);
078    
079                            QueryPos qPos = QueryPos.getInstance(q);
080    
081                            qPos.add(BookmarksEntry.class.getName());
082    
083                            return q.list(true);
084                    }
085                    catch (Exception e) {
086                            throw new SystemException(e);
087                    }
088                    finally {
089                            closeSession(session);
090                    }
091            }
092    
093    }