Package org.xulfaces.rubis.admin.dao.jdbc

Source Code of org.xulfaces.rubis.admin.dao.jdbc.JDBCRegionDAO

/*
*   xulfaces : bring XUL power to Java
*  
*  Copyright (C) 2005  Olivier SCHMITT
*  This library is free software; you can redistribute it and/or
*  modify it under the terms of the GNU Lesser General Public
*  License as published by the Free Software Foundation; either
*  version 2.1 of the License, or (at your option) any later version.
*
*  This library is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
*  Lesser General Public License for more details.
*
*  You should have received a copy of the GNU Lesser General Public
*  License along with this library; if not, write to the Free Software
*  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

package org.xulfaces.rubis.admin.dao.jdbc;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;

import org.xulfaces.rubis.admin.dao.RegionDAO;
import org.xulfaces.rubis.admin.dao.RegionNotFoundException;
import org.xulfaces.rubis.model.Region;

public class JDBCRegionDAO extends JDBCAbstractDAO implements RegionDAO {

  public JDBCRegionDAO() throws Exception {
    super();
  }

  public Collection<Region> getRegions() {
   
    Collection<Region> regions = new ArrayList<Region>();
    StringBuffer sqlBuffer = new StringBuffer();
    sqlBuffer.append("SELECT * FROM regions");
    ResultSet resultSet = null;
    try {
      resultSet = excecuteScrollableQuery(sqlBuffer.toString());
      while (resultSet.next()) {
        Region region = new Region();
        region.setId(new Integer(resultSet.getInt("ID")));
        region.setName(resultSet.getString("NAME"));
        regions.add(region);
      }
    } catch (SQLException e) {
      throw new RuntimeException(e);
    }
    finally {
      closeConnection(resultSet);
    }
    return regions;
  }

  public Region loadRegion(Integer id) throws RegionNotFoundException {
   
    Region region = null;
    StringBuffer sqlBuffer = new StringBuffer();
    sqlBuffer.append("SELECT * FROM regions WHERE ID=");
    sqlBuffer.append(id);
    ResultSet resultSet = null;
    try {
      resultSet = excecuteQuery(sqlBuffer.toString());
      if(resultSet.next()) {
        region = new Region();
        region.setId(new Integer(resultSet.getInt("ID")));
        region.setName(resultSet.getString("NAME"));       
      }
    } catch (SQLException e) {
      throw new RegionNotFoundException("Region " + id + " not found",e);
    }
    finally {
      closeConnection(resultSet);
    }
    return region;
  }

}
TOP

Related Classes of org.xulfaces.rubis.admin.dao.jdbc.JDBCRegionDAO

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.