01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: org_h2_Driver.java 3726 2007-04-30 18:20:33Z gbevin $
07: */
08: package com.uwyn.rife.authentication.credentialsmanagers.databasedrivers;
09:
10: import com.uwyn.rife.authentication.credentialsmanagers.DatabaseUsers;
11: import com.uwyn.rife.authentication.credentialsmanagers.RoleUserAttributes;
12: import com.uwyn.rife.authentication.credentialsmanagers.exceptions.DuplicateLoginException;
13: import com.uwyn.rife.authentication.credentialsmanagers.exceptions.DuplicateRoleException;
14: import com.uwyn.rife.authentication.credentialsmanagers.exceptions.DuplicateUserIdException;
15: import com.uwyn.rife.authentication.exceptions.CredentialsManagerException;
16: import com.uwyn.rife.database.Datasource;
17:
18: public class org_h2_Driver extends generic {
19: public org_h2_Driver(Datasource datasource) {
20: super (datasource);
21: }
22:
23: public DatabaseUsers addRole(String role)
24: throws CredentialsManagerException {
25: try {
26: _addRole(mGetNewRoleId, mAddRole, role);
27: } catch (CredentialsManagerException e) {
28: if (null != e.getCause() && null != e.getCause().getCause()) {
29: String message = e.getCause().getCause().getMessage()
30: .toUpperCase();
31: if (-1 != message.indexOf("AUTHROLE_NAME_UQ_INDEX")) {
32: throw new DuplicateRoleException(role);
33: }
34: }
35:
36: throw e;
37: }
38:
39: return this ;
40: }
41:
42: public DatabaseUsers addUser(String login,
43: RoleUserAttributes attributes)
44: throws CredentialsManagerException {
45: try {
46: _addUser(mAddUserWithId, mGetFreeUserId, mGetRoleId,
47: mAddRoleLink, login, attributes);
48: } catch (CredentialsManagerException e) {
49: if (null != e.getCause() && null != e.getCause().getCause()) {
50: String message = e.getCause().getCause().getMessage()
51: .toUpperCase();
52: if (-1 != message.indexOf("PRIMARY_KEY")) {
53: throw new DuplicateUserIdException(attributes
54: .getUserId());
55: }
56: if (-1 != message.indexOf("AUTHUSER_LOGIN_UQ_INDEX")) {
57: throw new DuplicateLoginException(login);
58: }
59: }
60:
61: throw e;
62: }
63:
64: return this;
65: }
66: }
|