|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.ObjectDBLocalAcctMgr
An implementation of the AcctMgrSpec interface that uses a postgres backend. TODO: Add invalidation support ala closeMgr(). TODO: Reconnection managing. TODO: Add AcctMgrSpec.init()/destroy() ? TODO: Better error handling. TODO: AcctMgrSpec.addUser() doctation += 'fails if user exists'.
| Field Summary | |
private ConfigMgr |
configMgr
The ConfigMgr to get our configuration data from. |
private Connection |
conn
The connection to the database. |
private boolean |
connected
Whether or not the class has a valid connection to the database. |
private String |
db
The database to connect to. |
private String |
host
The database server's hostname. |
private String |
imapHost
The IMAP host to authenticate users against. |
private DrinkLoggerSpec |
log
The DrinkLoggerSpec to log information/errors/aborts to. |
private String |
pass
The password for the database username |
private String |
user
The username of the database user to authenticate as. |
| Constructor Summary | |
DBLocalAcctMgr(DrinkLoggerSpec inLog,
ConfigMgr inConfigMgr)
Pulls the configuration data (host, db, user, pass) from the given ConfigMgr object. |
|
DBLocalAcctMgr(DrinkLoggerSpec log,
String host,
String db,
String user,
String pass)
Construct the account manager by trying to connect to the db server. |
|
| Method Summary | |
boolean |
addUser(String username,
String password)
Adds a user from the system. |
boolean |
addUser(String username,
String password,
int balance,
boolean adminStatus)
Adds a user to the database of known users using the supplied values to initialize the account. |
void |
closeMgr()
Causes the account manager to invalidate itself and close all database connections. |
boolean |
decreaseUserBalance(String username,
int amount)
Decrements a users balance |
Vector |
dump()
TODO: This is not a set anymore. |
private int |
execUpdate(String query)
Executes an update of the database, eg INSERT, DELETE, UPDATE. |
int |
getUserBalance(String username)
Queries the DB for the given users balance. |
boolean |
increaseUserBalance(String username,
int amount)
Updates the database with the given users balance. |
private boolean |
initialize(String host,
String db,
String user,
String pass)
Performs the common part of the class construction. |
boolean |
isSystemReady()
Returns whether or not the database backend is ready to process requests. |
boolean |
isUserAdmin(String username)
Tests to see if the given user is an administrator. |
boolean |
isValidUser(String username)
Checks to see if the user is registered in the database. |
boolean |
isValidUser(String username,
String password)
Authenticates a user. |
void |
purgeDatabase()
WARNING: USE WITH CAUTION. |
boolean |
removeUser(String username)
Removes a user from the database. |
boolean |
setUserAdmin(String username,
boolean admin)
Updates a users admin status. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
private Connection conn
private boolean connected
private String host
private String db
private String user
private String pass
private ConfigMgr configMgr
private DrinkLoggerSpec log
private String imapHost
| Constructor Detail |
public DBLocalAcctMgr(DrinkLoggerSpec inLog,
ConfigMgr inConfigMgr)
inLog - Where to send log messages.inConfigMgr - Where to get our runtime configuration data from.
public DBLocalAcctMgr(DrinkLoggerSpec log,
String host,
String db,
String user,
String pass)
log - The DrinkLoggerSpec we're to use for logging errors.host - The host machine to connect to.db - The database to open.user - The username of the account to authenticate as.pass - The password of the account to authenticate as.| Method Detail |
private boolean initialize(String host,
String db,
String user,
String pass)
public void closeMgr()
public boolean addUser(String username,
String password)
addUser in interface AcctMgrSpecusername - The username of the user to be registered.password - The password of the user.
LocalAcctMgr.isValidUser(String,String)
public boolean addUser(String username,
String password,
int balance,
boolean adminStatus)
addUser in interface AcctMgrSpecusername - The username of the account to add.password - The password for the new account.balance - The accounts initial balance.adminStatus - Whether or not the new user is to be an admin.
public boolean removeUser(String username)
removeUser in interface AcctMgrSpecusername - The username of the account to delete
public boolean isValidUser(String username)
isValidUser in interface AcctMgrSpecusername - The user to verify
public boolean increaseUserBalance(String username,
int amount)
increaseUserBalance in interface AcctMgrSpecusername - The user whose account is to be incremented.amount - The amount to increase the users account
AcctMgrSpec.decreaseUserBalance(String, int)
public boolean decreaseUserBalance(String username,
int amount)
decreaseUserBalance in interface AcctMgrSpecusername - The user whose account is to be decrementedamount - The amount, in credits, to decrement the users account.
AcctMgrSpec.increaseUserBalance(String, int)public int getUserBalance(String username)
getUserBalance in interface AcctMgrSpecusername - The username whose balance is desired
public boolean isValidUser(String username,
String password)
isValidUser in interface AcctMgrSpecusername - The user to authenticate.password - The users password.
public boolean isUserAdmin(String username)
isUserAdmin in interface AcctMgrSpecusername - The user to be verified
public boolean setUserAdmin(String username,
boolean admin)
setUserAdmin in interface AcctMgrSpecusername - The user to editadmin - The value to set the flag to.
public boolean isSystemReady()
isSystemReady in interface AcctMgrSpecpublic Vector dump()
dump in interface AcctMgrSpecpublic void purgeDatabase()
purgeDatabase in interface AcctMgrSpecprivate int execUpdate(String query)
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||