* @param galleryid The ID of the gallery one wants to view
* @return A bean containing gallery information and images
**/
private GalleryBean getGalleryById(int galleryid)
throws ServletException {
GalleryBean temp=null;
synchronized(this) {
try {
//select gallery details
PreparedStatement stmt=DBInterface.doQuery("SELECT g.id,g.name,g.bgcolor,g.fontcolor,u.name " +
"FROM gallery g " +
"INNER JOIN users u ON g.owner=u.id " +
"WHERE g.id=?");
stmt.setInt(1,galleryid);
ResultSet result=stmt.executeQuery();
//store information in bean
if (result.next()) {
temp=new GalleryBean();
temp.setId(result.getInt(1));
temp.setName(result.getString(2));
temp.setBgcolor(result.getString(3));
temp.setFontcolor(result.getString(4));
temp.getUserBean().setName(result.getString(5));
result.close();
stmt.close();
result=null;
stmt=null;
//get images which are shown in this gallery
stmt=DBInterface.doQuery("SELECT i.id,i.title " +
"FROM gallery_has_image ghi " +
"INNER JOIN image i ON ghi.imageid=i.id " +
"WHERE ghi.galleryid=? " +
"ORDER BY RANDOM()");
stmt.setInt(1,galleryid);
result=stmt.executeQuery();
//store image bean in bean for gallery
Vector<ImageBean> images=new Vector<ImageBean>();
while (result.next()) {
ImageBean img=new ImageBean();
img.setId(result.getInt(1));
img.setTitle(result.getString(2));
images.add(img);
}
result.close();
stmt.close();
temp.setImages(images);
}
DBInterface.close();
} catch (SQLException se) {
throw new ServletException("Could not retrieve gallery: "+se.getMessage());