/*
 * $Id: DocumentHelper.java,v 1.4 2004/12/08 08:50:16 jonyp Exp $
 *
 * Copyright (c) Siemens AG 2008 
 *           (c) Universität Paderborn 2008 
 * Licensed under EUPL 1.1. 
 * 
 * $Log: DocumentHelper.java,v $
 * Revision 1.4  2004/12/08 08:50:16  jonyp
 * added log comment for cvs
 *
 */

package vkc.db.helper;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.HashSet;
import java.util.Set;

import java.sql.Connection;

import vkc.exception.DBException;
import vkc.view.WebShare;

public final class DocumentHelper {
	private DocumentHelper() {
	}
	
	/**
	 * Liefert ein Set aller (java.lang.Integer) IDs der aktuellsten 
	 * Dokumentversionen
	 */
	public final static Set getMostRecentDocumentIds() throws DBException {
		Connection conn = null;
		PreparedStatement pStmt = null;
		ResultSet rs = null;
		Set set = new HashSet();

		try {
			if( WebShare.database == null ) {
				throw new DBException( "No database available" );
			}

			conn = WebShare.database.getConnection();
			
			if( conn == null ) {
				throw new DBException( "No connection available" );
			}

			pStmt = conn.prepareStatement( "SELECT DOCUMENTID FROM DOCUMENTS WHERE PREDOCID IS NULL" );
			rs = pStmt.executeQuery();

			while( rs.next() ) {
				set.add( new Integer( rs.getInt( "DOCUMENTID" ) ) );
			}
			
			return set;
		} catch( Exception ex ) {
			throw new DBException( ex );
		} finally {
			DBHelper.close( rs );
			DBHelper.close( pStmt );
			DBHelper.close( conn );
		}
	}
}