001    /**
002     * Copyright (c) 2000-2012 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.polls.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.kernel.util.StringBundler;
022    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
023    import com.liferay.portlet.polls.NoSuchChoiceException;
024    import com.liferay.portlet.polls.model.PollsChoice;
025    import com.liferay.portlet.polls.model.impl.PollsChoiceImpl;
026    import com.liferay.util.dao.orm.CustomSQLUtil;
027    
028    import java.util.List;
029    
030    /**
031     * @author Bruno Farache
032     */
033    public class PollsChoiceFinderImpl
034            extends BasePersistenceImpl<PollsChoice> implements PollsChoiceFinder {
035    
036            public static final String FIND_BY_UUID_G =
037                    PollsChoiceFinder.class.getName() + ".findByUUID_G";
038    
039            public PollsChoice fetchByUUID_G(String uuid, long groupId)
040                    throws SystemException {
041    
042                    Session session = null;
043    
044                    try {
045                            session = openSession();
046    
047                            String sql = CustomSQLUtil.get(FIND_BY_UUID_G);
048    
049                            SQLQuery q = session.createSQLQuery(sql);
050    
051                            q.addEntity("PollsChoice", PollsChoiceImpl.class);
052    
053                            QueryPos qPos = QueryPos.getInstance(q);
054    
055                            qPos.add(uuid);
056                            qPos.add(groupId);
057    
058                            List<PollsChoice> choices = q.list();
059    
060                            if (!choices.isEmpty()) {
061                                    return choices.get(0);
062                            }
063    
064                            return null;
065                    }
066                    catch (Exception e) {
067                            throw new SystemException(e);
068                    }
069                    finally {
070                            closeSession(session);
071                    }
072            }
073    
074            public PollsChoice findByUUID_G(String uuid, long groupId)
075                    throws NoSuchChoiceException, SystemException {
076    
077                    PollsChoice choice = fetchByUUID_G(uuid, groupId);
078    
079                    if (choice != null) {
080                            return choice;
081                    }
082    
083                    StringBundler sb = new StringBundler(5);
084    
085                    sb.append("No PollsChoice exists with the key {uuid=");
086                    sb.append(uuid);
087                    sb.append(", groupId=");
088                    sb.append(groupId);
089                    sb.append("}");
090    
091                    throw new NoSuchChoiceException(sb.toString());
092            }
093    
094    }