package com.ferienclub.util;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import org.apache.log4j.Logger;

public class IDGenerator {

	public static Logger logger = Logger.getLogger(IDGenerator.class);
	
	/**
	 * Return a new generated GUID from the sqlserver
	 */
	public static String fetchNewId(){
		try {
			Connection con = DriverManager.getConnection();
			Statement stmt = con.createStatement();
			String sql = "SELECT newId()";
			ResultSet rs = stmt.executeQuery(sql);
			rs.next();
			String newId = rs.getString(1);
			logger.debug("Retrieved new Id: " + newId + " from Database");
			rs.close();
			return newId;
		} catch (SQLException e){
			e.printStackTrace();
		}
		return null;
	}

}
