UserDAOpublic abstract class UserDAO extends Object
Fields Summary |
---|
private static final String | AUTH | private static final int | A_UID | private static final int | A_PW | private static final String | CPW | private static final int | C_NPW | private static final int | C_UID | private static final int | C_OPW | private static final String | LOAD | private static final int | L_UID | private static final int | L_AUTH | private static final int | L_EMAIL | private static final int | L_FIRST_NAME | private static final int | L_LAST_NAME | private static final int | L_NICKNAME | private static final int | L_WEB_PAGE |
Methods Summary |
---|
static void | authenticate(java.lang.String uid, java.lang.String pw)
PreparedStatement stmt = null;
Connection conn = null;
ResultSet rs = null;
try {
InitialContext ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("jdbc/kyra");
conn = ds.getConnection();
stmt = conn.prepareStatement(AUTH);
stmt.setString(A_UID, uid);
stmt.setString(A_PW, pw);
rs = stmt.executeQuery();
if( !rs.next() ) {
throw new AuthenticationException("Invalid ID or password.");
}
}
catch( NamingException e ) {
throw new PersistenceException(e);
}
catch( SQLException e ) {
throw new PersistenceException(e);
}
finally {
if( rs != null ) {
try { rs.close(); }
catch( SQLException e ) { }
}
if( stmt != null ) {
try { stmt.close(); }
catch( SQLException e ) { }
}
if( conn != null ) {
try { conn.close(); }
catch( SQLException e ) { }
}
}
| static boolean | changePassword(java.lang.String uid, java.lang.String opw, java.lang.String npw)
PreparedStatement stmt = null;
Connection conn = null;
try {
InitialContext ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("jdbc/kyra");
conn = ds.getConnection();
stmt = conn.prepareStatement(CPW);
stmt.setString(C_NPW, npw);
stmt.setString(C_UID, uid);
stmt.setString(C_OPW, opw);
return (stmt.executeUpdate() == 1);
}
catch( NamingException e ) {
throw new PersistenceException(e);
}
catch( SQLException e ) {
throw new PersistenceException(e);
}
finally {
if( stmt != null ) {
try { stmt.close(); }
catch( SQLException e ) { }
}
if( conn != null ) {
try { conn.close(); }
catch( SQLException e ) { }
}
}
| static java.util.HashMap | load(java.lang.String uid)
PreparedStatement stmt = null;
Connection conn = null;
ResultSet rs = null;
try {
InitialContext ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("jdbc/kyra");
HashMap data = new HashMap();
String tmp;
conn = ds.getConnection();
stmt = conn.prepareStatement(LOAD);
stmt.setString(L_UID, uid);
rs = stmt.executeQuery();
if( !rs.next() ) {
throw new PersistenceException("No such user.");
}
data.put(SharedUser.AUTHORIZATION, new Integer(rs.getInt(L_AUTH)));
data.put(SharedUser.EMAIL, rs.getString(L_EMAIL).trim());
data.put(SharedUser.FIRST_NAME, rs.getString(L_FIRST_NAME).trim());
data.put(SharedUser.LAST_NAME, rs.getString(L_LAST_NAME).trim());
data.put(SharedUser.NICKNAME, rs.getString(L_NICKNAME).trim());
tmp = rs.getString(L_WEB_PAGE);
if( rs.wasNull() ) {
data.put(SharedUser.WEB_PAGE, null);
}
else {
data.put(SharedUser.WEB_PAGE, tmp.trim());
}
return data;
}
catch( NamingException e ) {
throw new PersistenceException(e);
}
catch( SQLException e ) {
throw new PersistenceException(e);
}
finally {
if( rs != null ) {
try { rs.close(); }
catch( SQLException e ) { }
}
if( stmt != null ) {
try { stmt.close(); }
catch( SQLException e ) { }
}
if( conn != null ) {
try { conn.close(); }
catch( SQLException e ) { }
}
}
| static void | logout(java.lang.String uid)
|
|