DataHandler angepasst
[staff/due1/sed-hs15-srs-purple.git] / src / main / java / ch / bfh / ti / srs / noTest / DataHandlerForExcel.java
index 94d8e2f..0addfbb 100644 (file)
@@ -14,115 +14,106 @@ import ch.bfh.ti.srs.datahandler.DataHandler;
 import ch.bfh.ti.srs.dataschema.Reservation;
 import ch.bfh.ti.srs.dataschema.Resource;
 import ch.bfh.ti.srs.dataschema.User;
+
 /**
  * @author Michael Grossen
  */
-public class DataHandlerForExcel implements DataHandler{
+public class DataHandlerForExcel implements DataHandler {
        String filePath;
        Set<User> userList = new HashSet<User>();
-       
-       static
-       {
-               try  { 
-            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
-        } 
-        catch (Exception e) {
-            System.err.println(e);
-        }
+
+       static {
+               try {
+                       Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
+               } catch (Exception e) {
+                       System.err.println(e);
+               }
        }
-       
-       public DataHandlerForExcel(String filePath) throws Exception{
+
+       public DataHandlerForExcel(String filePath) throws Exception {
                this.filePath = filePath;
                updateUserList();
        }
-       
+
        @Override
        public User findUser(String userName) {
-               if(userName == null) throw new IllegalArgumentException("Username must not be null");
+               if (userName == null)
+                       throw new IllegalArgumentException("Username must not be null");
                for (User user : userList) {
-                       if(user.getUserName().equals(userName)) return user;
+                       if (user.getUserName().equals(userName))
+                               return user;
                }
                return null;
        }
 
        @Override
        public void addUser(User user) throws Exception {
-               if(findUser(user.getUserName()) != null) throw new Exception("User already exists!");
+               if (findUser(user.getUserName()) != null)
+                       throw new Exception("User already exists!");
                insertNewUser(user);
                updateUserList();
        }
 
-       private void updateUserList() throws Exception
-       {
-               Connection conn=null;
-        Statement stmt=null;
-        String sql="";
-        ResultSet rs=null;
-        userList.clear();
-        
-        try {
-            conn=DriverManager.getConnection("jdbc:odbc:excel","","");
-            stmt=conn.createStatement();
-            sql="select * from [User$]";
-            rs=stmt.executeQuery(sql);
-
-            while(rs.next()){
-               User user = new User(rs.getString("USERNAME"),
-                               rs.getString("PASSWORD"),
-                               rs.getString("MAIL"),
-                               rs.getString("NAME"),
-                               rs.getString("LASTNAME"));
-                userList.add(user);
-            }
-        } 
-        catch (Exception e){
-            System.err.println(e);
-        } 
-        finally {
-            try{
-                rs.close();
-                stmt.close();
-                conn.close();
-                rs=null;
-                stmt=null;
-                conn=null; 
-            }
-            catch(Exception e){}
-        }
+       private void updateUserList() throws Exception {
+               Connection conn = null;
+               Statement stmt = null;
+               String sql = "";
+               ResultSet rs = null;
+
+               userList.clear();
+
+               try {
+                       conn = DriverManager.getConnection("jdbc:odbc:excel", "", "");
+                       stmt = conn.createStatement();
+                       sql = "select * from [User$]";
+                       rs = stmt.executeQuery(sql);
+
+                       while (rs.next()) {
+                               User user = new User(rs.getString("USERNAME"), rs.getString("PASSWORD"), rs.getString("MAIL"),
+                                               rs.getString("NAME"), rs.getString("LASTNAME"));
+                               userList.add(user);
+                       }
+               } catch (Exception e) {
+                       System.err.println(e);
+               } finally {
+                       try {
+                               rs.close();
+                               stmt.close();
+                               conn.close();
+                               rs = null;
+                               stmt = null;
+                               conn = null;
+                       } catch (Exception e) {
+                       }
+               }
        }
 
-       private void insertNewUser(User user) throws Exception{
-               Connection conn=null;
-        Statement stmt=null;
-        String sql="";
-        ResultSet rs=null;
-        sql = "insert into [User$] values (" +         user.getUserName() + "," +
-                                                                                       user.getEncryptedPassword() + "," +
-                                                                                       user.getMail() + "," +
-                                                                                       user.getName() + "," +
-                                                                                       user.getLastname() + ")";
-        
-        try {
-            conn=DriverManager.getConnection("jdbc:odbc:excel","","");
-            stmt=conn.createStatement();
-            stmt.executeQuery(sql);
-        } 
-        catch (Exception e){
-            System.err.println(e);
-        } 
-        finally {
-            try{
-                rs.close();
-                stmt.close();
-                conn.close();
-                rs=null;
-                stmt=null;
-                conn=null; 
-            }
-            catch(Exception e){}
-        }
+       private void insertNewUser(User user) throws Exception {
+               Connection conn = null;
+               Statement stmt = null;
+               String sql = "";
+               ResultSet rs = null;
+
+               sql = "insert into [User$] values (" + user.getUserName() + "," + user.getEncryptedPassword() + ","
+                               + user.getMail() + "," + user.getName() + "," + user.getLastname() + ")";
+
+               try {
+                       conn = DriverManager.getConnection("jdbc:odbc:excel", "", "");
+                       stmt = conn.createStatement();
+                       stmt.executeQuery(sql);
+               } catch (Exception e) {
+                       System.err.println(e);
+               } finally {
+                       try {
+                               rs.close();
+                               stmt.close();
+                               conn.close();
+                               rs = null;
+                               stmt = null;
+                               conn = null;
+                       } catch (Exception e) {
+                       }
+               }
        }
 
        @Override
@@ -134,13 +125,13 @@ public class DataHandlerForExcel implements DataHandler{
        @Override
        public void addResource(Resource resource) throws Exception {
                // TODO Auto-generated method stub
-               
+
        }
 
        @Override
        public void addReservation(Reservation reservation) throws Exception {
                // TODO Auto-generated method stub
-               
+
        }
 
        @Override