comparison artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java @ 147:9a64e0c1c737

Added code to load user from database. artifacts/trunk@1372 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 02 Mar 2011 18:08:37 +0000
parents 967dc552455d
children 101a52d3ad08
comparison
equal deleted inserted replaced
146:967dc552455d 147:9a64e0c1c737
893 return null; 893 return null;
894 } 894 }
895 895
896 public void deleteUser(User user) { 896 public void deleteUser(User user) {
897 897
898 Connection conn = null; 898 Connection conn = null;
899 ResultSet result = null; 899 ResultSet result = null;
900 PreparedStatement stmnt = null; 900 PreparedStatement stmnt = null;
901 901
902 String identifier = user.identifier(); 902 String identifier = user.identifier();
903
904 if (!StringUtils.checkUUID(identifier)) {
905 return;
906 }
903 907
904 DataSource dataSource = DBConnection.getDataSource(); 908 DataSource dataSource = DBConnection.getDataSource();
905 try { 909 try {
906 conn = dataSource.getConnection(); 910 conn = dataSource.getConnection();
907 try { 911 try {
976 } 980 }
977 } 981 }
978 } 982 }
979 983
980 public User getUser(String identifier) { 984 public User getUser(String identifier) {
981 // TODO: implement me! 985
986 Connection conn = null;
987 ResultSet result = null;
988 PreparedStatement stmnt = null;
989
990 if (!StringUtils.checkUUID(identifier)) {
991 logger.debug("Invalid UUID: '" + identifier + "'");
992 return null;
993 }
994
995 DataSource dataSource = DBConnection.getDataSource();
996 try {
997 conn = dataSource.getConnection();
998 stmnt = conn.prepareStatement(SQL_USERS_SELECT_ID_BY_GID);
999 stmnt.setString(1, identifier);
1000 result = stmnt.executeQuery();
1001 if (!result.next()) { // no such user
1002 return null;
1003 }
1004 // omit id
1005 String name = result.getString(2);
1006 byte [] roleData = result.getBytes(3);
1007
1008 Document role = XMLUtils.fromByteArray(roleData);
1009
1010 return new DefaultUser(identifier, name, role);
1011 }
1012 catch (SQLException sqle) {
1013 logger.error(sqle.getLocalizedMessage(), sqle);
1014 }
1015 finally {
1016 if (result != null) {
1017 try { result.close(); }
1018 catch (SQLException sqle) {}
1019 }
1020 if (stmnt != null) {
1021 try { stmnt.close(); }
1022 catch (SQLException sqle) {}
1023 }
1024 if (conn != null) {
1025 try { conn.close(); }
1026 catch (SQLException sqle) {}
1027 }
1028 }
1029
982 return null; 1030 return null;
983 } 1031 }
984 1032
985 public User [] getUsers() { 1033 public User [] getUsers() {
986 // TODO: implement me! 1034 // TODO: implement me!

http://dive4elements.wald.intevation.org