00001
00025 package org.openmobileis.examples.mycrm.data.jdbc;
00026
00027 import java.sql.ResultSet;
00028
00029 import org.openmobileis.common.user.User;
00030 import org.openmobileis.common.user.UserAlreadyExistException;
00031 import org.openmobileis.common.user.UserManagerFactory;
00032 import org.openmobileis.common.user.UserNotFoundException;
00033 import org.openmobileis.common.util.exception.ServiceException;
00034 import org.openmobileis.common.util.log.LogManager;
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 public final class MyCrmJDBCUserFactory implements UserManagerFactory {
00045 private MyCrmUserManagerDBQuery userquery;
00049 public MyCrmJDBCUserFactory() {
00050 super();
00051 userquery = new MyCrmUserManagerDBQuery();
00052 }
00053
00054
00055
00056
00057 public void deleteUser(String userID) throws ServiceException, UserNotFoundException {
00058 throw new ServiceException("not implemented");
00059 }
00060
00061
00062
00063
00064 public void storeUser(User user) throws ServiceException, UserAlreadyExistException {
00065 throw new UserAlreadyExistException("not implemented");
00066 }
00067
00068
00069
00070
00071 public User getUser(String userID) throws ServiceException, UserNotFoundException {
00072 User user= null;
00073 try {
00074 String[] param = new String[]{userID};
00075 ResultSet result = userquery.getUser(param);
00076 if (result.next()) {
00077 user = new User(result.getString(1), result.getString(2), result.getString(3));
00078 user.setProfil("default");
00079 user.setGroup("default");
00080 } else {
00081 throw new UserNotFoundException();
00082 }
00083 result.close();
00084 } catch (Exception ex) {
00085 throw new ServiceException(ex);
00086 } finally {
00087 userquery.getDbManager().garbageOpenedConnection();
00088 }
00089 return user;
00090 }
00091
00092
00093
00094
00095 public String authenticateUser(String login, String pass) throws ServiceException, UserNotFoundException {
00096 try {
00097 String[] params = {login, pass};
00098 ResultSet result = userquery.getUserIDWithloginPass(params);
00099 if (result.next()) {
00100 String id = result.getString(1);
00101 result.close();
00102 return id;
00103 }
00104 } catch (Throwable ex) {
00105 LogManager.traceError(0, ex);
00106 throw new ServiceException(ex);
00107 } finally {
00108 userquery.getDbManager().garbageOpenedConnection();
00109 }
00110 throw new UserNotFoundException("User not founr for login :"+login);
00111 }
00112
00113 public void logoutUser(String userid) throws ServiceException {
00114
00115 }
00116 }