Java tutorial
/** * Copyright (c) 2001-2012 "Redbasin Networks, INC" [http://redbasin.org] * * This file is part of Redbasin OpenDocShare community project. * * Redbasin OpenDocShare is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package dao; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.HashSet; import java.util.Vector; import model.Directory; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import util.DbConstants; /** * This class is used by spring to populate a <code>Directory</code> bean. * This class implements DirectoryListAuthorQuery * This class is used by DirectoryAuthorDao to list all the authors for a directory * **/ /** * @param conn the connection * @param directoryId the directory id * @return HashSet the set that has the list of authors for this directory. * @throws BaseDaoException * @author Smitha Gudur (smitha@redbasin.com) * @version $Revision: 1.1 $ */ class DirectoryListAuthorQuery extends BasicDirectQuery { protected final Log logger = LogFactory.getLog(getClass()); /** * This method lists all the authors for a directory * @param conn the connection * @param directoryId the directory id * @return HashSet the set that has the list of authors for this directory. * @throws BaseDaoException * @author Smitha Gudur (smitha@redbasin.com) * @version $Revision: 1.1 $ */ /* Uses tables - directory, diradmin, hdlogin */ public HashSet run(Connection conn, String directoryid) throws BaseDaoException { String sqlQuery = "select distinct CONCAT(hd.fname,' ',hd.lname) AS membername, " + "hd.login, hd.loginid, d1.directoryid, d1.dirname from directory d1, " + "diradmin d2, hdlogin hd where d2.ownerid=hd.loginid " + "and d1.directoryid=d2.directoryid and d1.directoryid=" + directoryid + " order by hd.login ASC"; logger.info("sqlQuery = " + sqlQuery); try { PreparedStatement stmt = conn.prepareStatement(sqlQuery); ResultSet rs = stmt.executeQuery(); Vector columnNames = null; Directory directory = null; HashSet dirSet = new HashSet(); if (rs != null) { // get column names and types from rsmd and save to local array in object //DbUtils dbutils = new DbUtils(); columnNames = dbutils.getColumnNames(rs); } else { return null; } while (rs.next()) { directory = (Directory) eop.newObject(DbConstants.DIRECTORY); for (int j = 0; j < columnNames.size(); j++) { directory.setValue((String) columnNames.elementAt(j), (String) rs.getString((String) columnNames.elementAt(j))); } dirSet.add(directory); } return dirSet; } catch (Exception e) { throw new BaseDaoException( "Error occured while executing directory moderatorslist run query " + sqlQuery, e); } } }