001    /**
002     * Copyright (c) 2000-2010 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.calendar.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.CalendarUtil;
022    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
023    import com.liferay.portlet.calendar.model.CalEvent;
024    import com.liferay.portlet.calendar.model.impl.CalEventImpl;
025    import com.liferay.util.dao.orm.CustomSQLUtil;
026    
027    import java.sql.Timestamp;
028    
029    import java.util.Date;
030    import java.util.List;
031    
032    /**
033     * @author Brian Wing Shun Chan
034     */
035    public class CalEventFinderImpl
036            extends BasePersistenceImpl<CalEvent> implements CalEventFinder {
037    
038            public static String FIND_BY_NO_ASSETS =
039                    CalEventFinder.class.getName() + ".findByNoAssets";
040    
041            public static String FIND_BY_G_SD =
042                    CalEventFinder.class.getName() + ".findByG_SD";
043    
044            public List<CalEvent> findByNoAssets() throws SystemException {
045                    Session session = null;
046    
047                    try {
048                            session = openSession();
049    
050                            String sql = CustomSQLUtil.get(FIND_BY_NO_ASSETS);
051    
052                            SQLQuery q = session.createSQLQuery(sql);
053    
054                            q.addEntity("CalEvent", CalEventImpl.class);
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            public List<CalEvent> findByG_SD(
067                            long groupId, Date startDateGT, Date startDateLT,
068                            boolean timeZoneSensitive)
069                    throws SystemException {
070    
071                    Timestamp startDateGT_TS = CalendarUtil.getTimestamp(startDateGT);
072                    Timestamp startDateLT_TS = CalendarUtil.getTimestamp(startDateLT);
073    
074                    Session session = null;
075    
076                    try {
077                            session = openSession();
078    
079                            String sql = CustomSQLUtil.get(FIND_BY_G_SD);
080    
081                            SQLQuery q = session.createSQLQuery(sql);
082    
083                            q.addEntity("CalEvent", CalEventImpl.class);
084    
085                            QueryPos qPos = QueryPos.getInstance(q);
086    
087                            qPos.add(groupId);
088                            qPos.add(startDateGT_TS);
089                            qPos.add(startDateLT_TS);
090                            qPos.add(timeZoneSensitive);
091                            qPos.add(false);
092    
093                            return q.list();
094                    }
095                    catch (Exception e) {
096                            throw new SystemException(e);
097                    }
098                    finally {
099                            closeSession(session);
100                    }
101            }
102    
103    }