comparison artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java @ 413:f5ecca16f601

Implement method to find/get a user by its account name artifacts/trunk@5260 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Bjoern Ricks <bjoern.ricks@intevation.de>
date Fri, 24 Aug 2012 14:04:38 +0000
parents f456d9d55541
children da33275fb765
comparison
equal deleted inserted replaced
412:f4b14240ffa3 413:f5ecca16f601
94 94
95 public String SQL_USERS_NEXT_ID; 95 public String SQL_USERS_NEXT_ID;
96 public String SQL_USERS_INSERT; 96 public String SQL_USERS_INSERT;
97 public String SQL_USERS_SELECT_ID_BY_GID; 97 public String SQL_USERS_SELECT_ID_BY_GID;
98 public String SQL_USERS_SELECT_GID; 98 public String SQL_USERS_SELECT_GID;
99 public String SQL_USERS_SELECT_ACCOUNT;
99 public String SQL_USERS_DELETE_ID; 100 public String SQL_USERS_DELETE_ID;
100 public String SQL_USERS_DELETE_COLLECTIONS; 101 public String SQL_USERS_DELETE_COLLECTIONS;
101 public String SQL_USERS_SELECT_ALL; 102 public String SQL_USERS_SELECT_ALL;
102 public String SQL_USERS_COLLECTIONS; 103 public String SQL_USERS_COLLECTIONS;
103 public String SQL_USERS_COLLECTION_IDS; 104 public String SQL_USERS_COLLECTION_IDS;
309 SQL_REPLACE = sql.get("artifacts.replace"); 310 SQL_REPLACE = sql.get("artifacts.replace");
310 SQL_USERS_NEXT_ID = sql.get("users.id.nextval"); 311 SQL_USERS_NEXT_ID = sql.get("users.id.nextval");
311 SQL_USERS_INSERT = sql.get("users.insert"); 312 SQL_USERS_INSERT = sql.get("users.insert");
312 SQL_USERS_SELECT_ID_BY_GID = sql.get("users.select.id.by.gid"); 313 SQL_USERS_SELECT_ID_BY_GID = sql.get("users.select.id.by.gid");
313 SQL_USERS_SELECT_GID = sql.get("users.select.gid"); 314 SQL_USERS_SELECT_GID = sql.get("users.select.gid");
315 SQL_USERS_SELECT_ACCOUNT = sql.get("users.select.account");
314 SQL_USERS_DELETE_ID = sql.get("users.delete.id"); 316 SQL_USERS_DELETE_ID = sql.get("users.delete.id");
315 SQL_USERS_DELETE_COLLECTIONS = sql.get("users.delete.collections"); 317 SQL_USERS_DELETE_COLLECTIONS = sql.get("users.delete.collections");
316 SQL_USERS_SELECT_ALL = sql.get("users.select.all"); 318 SQL_USERS_SELECT_ALL = sql.get("users.select.all");
317 SQL_USERS_COLLECTIONS = sql.get("users.collections"); 319 SQL_USERS_COLLECTIONS = sql.get("users.collections");
318 SQL_USERS_COLLECTION_IDS = sql.get("users.collection.ids"); 320 SQL_USERS_COLLECTION_IDS = sql.get("users.collection.ids");
979 }; 981 };
980 982
981 return exec.runRead() ? user[0] : null; 983 return exec.runRead() ? user[0] : null;
982 } 984 }
983 985
986 /**
987 * Find/Get user by account
988 */
989 public User findUser(
990 final String account,
991 final UserFactory factory,
992 final Object context
993 ) {
994
995 final User [] user = new User[1];
996 logger.debug("Tying to find user by account " + account);
997
998 SQLExecutor.Instance exec = sqlExecutor.new Instance() {
999 public boolean doIt() throws SQLException {
1000 prepareStatement(SQL_USERS_SELECT_ACCOUNT);
1001 stmnt.setString(1, account);
1002 result = stmnt.executeQuery();
1003 if (!result.next()) { // no such user
1004 logger.debug("No user found.");
1005 return false;
1006 }
1007 String identifier = result.getString(1);
1008 String name = result.getString(2);
1009 String account = result.getString(3);
1010 byte [] roleData = result.getBytes(4);
1011
1012 Document role = XMLUtils.fromByteArray(roleData, true);
1013
1014 user[0] = factory.createUser(
1015 identifier, name, account, role, context);
1016 return true;
1017 }
1018 };
1019
1020 return exec.runRead() ? user[0] : null;
1021 }
1022
984 public User [] getUsers( 1023 public User [] getUsers(
985 final UserFactory factory, 1024 final UserFactory factory,
986 final Object context 1025 final Object context
987 ) { 1026 ) {
988 final ArrayList<User> users = new ArrayList<User>(); 1027 final ArrayList<User> users = new ArrayList<User>();

http://dive4elements.wald.intevation.org