001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.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.model.PortletPreferences;
022    import com.liferay.portal.model.impl.PortletPreferencesImpl;
023    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
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 PortletPreferencesFinderImpl
032            extends BasePersistenceImpl<PortletPreferences>
033            implements PortletPreferencesFinder {
034    
035            public static String FIND_BY_PORTLETID =
036                    PortletPreferencesFinder.class.getName() + ".findByPortletId";
037    
038            public List<PortletPreferences> findByPortletId(String portletId)
039                    throws SystemException {
040    
041                    Session session = null;
042    
043                    try {
044                            session = openSession();
045    
046                            String sql = CustomSQLUtil.get(FIND_BY_PORTLETID);
047    
048                            SQLQuery q = session.createSQLQuery(sql);
049    
050                            q.addEntity("PortletPreferences", PortletPreferencesImpl.class);
051    
052                            QueryPos qPos = QueryPos.getInstance(q);
053    
054                            qPos.add(portletId);
055    
056                            return q.list();
057                    }
058                    catch (Exception e) {
059                            throw new SystemException(e);
060                    }
061                    finally {
062                            closeSession(session);
063                    }
064            }
065    
066    }