|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.avalon.framework.logger.AbstractLogEnabled | +--org.apache.james.userrepository.AbstractUsersRepository | +--org.apache.james.userrepository.AbstractJdbcUsersRepository
An abstract base class for creating UserRepository implementations which use a database for persistence. To implement a new UserRepository using by extending this class, you need to implement the 3 abstract methods defined below, and define the required SQL statements in an SQLResources file. The SQL statements used by this implementation are:
Required | |
select | Select all users. |
insert | Insert a user. |
update | Update a user. |
delete | Delete a user by name. |
createTable | Create the users table. | Optional |
selectByLowercaseName | Select a user by name (case-insensitive lowercase). |
Field Summary | |
protected Context |
context
The Avalon context used by the instance |
protected Map |
m_sqlParameters
|
Fields inherited from interface org.apache.james.services.UsersRepository |
ROLE, USER |
Constructor Summary | |
AbstractJdbcUsersRepository()
|
Method Summary | |
void |
compose(ComponentManager componentManager)
|
void |
configure(Configuration configuration)
Configures the UserRepository for JDBC access. |
void |
contextualize(Context context)
|
protected void |
doAddUser(User user)
Adds a user to the underlying Repository. |
protected void |
doRemoveUser(User user)
Removes a user from the underlying repository. |
protected void |
doUpdateUser(User user)
Updates a user record to match the supplied User. |
protected User |
getUserByName(String name,
boolean ignoreCase)
Gets a user by name, ignoring case if specified. |
void |
initialize()
Initialises the JDBC repository. |
protected Iterator |
listAllUsers()
Returns a list populated with all of the Users in the repository. |
protected abstract User |
readUserFromResultSet(ResultSet rsUsers)
Reads properties for a User from an open ResultSet. |
protected abstract void |
setUserForInsertStatement(User user,
PreparedStatement userInsert)
Set parameters of a PreparedStatement object with property values from a User instance. |
protected abstract void |
setUserForUpdateStatement(User user,
PreparedStatement userUpdate)
Set parameters of a PreparedStatement object with property values from a User instance. |
Methods inherited from class org.apache.james.userrepository.AbstractUsersRepository |
addUser, addUser, contains, containsCaseInsensitive, countUsers, getAttributes, getRealName, getUserByName, getUserByNameCaseInsensitive, list, listUserNames, removeUser, test, test, updateUser |
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled |
enableLogging, getLogger, setupLogger, setupLogger, setupLogger |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected Context context
protected Map m_sqlParameters
Constructor Detail |
public AbstractJdbcUsersRepository()
Method Detail |
public void contextualize(Context context) throws ContextException
contextualize
in interface Contextualizable
ContextException
Contextualizable.contextualize(Context)
public void compose(ComponentManager componentManager) throws ComponentException
compose
in interface Composable
ComponentException
Composable.compose(ComponentManager)
public void configure(Configuration configuration) throws ConfigurationException
<repository name="LocalUsers" class="org.apache.james.userrepository.JamesUsersJdbcRepository"> <!-- Name of the datasource to use --> <data-source>MailDb</data-source> <!-- File to load the SQL definitions from --> <sqlFile>dist/conf/sqlResources.xml</sqlFile> <!-- replacement parameters for the sql file --> <sqlParameters table="JamesUsers"/> </repository>
configure
in interface Configurable
ConfigurationException
public void initialize() throws Exception
Initialises the JDBC repository.
1) Tests the connection to the database.
2) Loads SQL strings from the SQL definition file, choosing the appropriate SQL for this connection, and performing parameter substitution,
3) Initialises the database with the required tables, if necessary.
initialize
in interface Initializable
Exception
- if an error occursprotected Iterator listAllUsers()
listAllUsers
in class AbstractUsersRepository
Iterator
of JamesUser
s.protected void doAddUser(User user)
doAddUser
in class AbstractUsersRepository
user
- the user to be addedprotected void doRemoveUser(User user)
doRemoveUser
in class AbstractUsersRepository
user
- the user to be removedprotected void doUpdateUser(User user)
doUpdateUser
in class AbstractUsersRepository
user
- the updated user recordprotected User getUserByName(String name, boolean ignoreCase)
getUserByName
in class AbstractUsersRepository
name
- the name of the user being retrievedignoreCase
- whether the name is regarded as case-insensitive
protected abstract User readUserFromResultSet(ResultSet rsUsers) throws SQLException
rsUsers
- A ResultSet with a User record in the current row.
SQLException
- if an exception occurs reading from the ResultSetprotected abstract void setUserForInsertStatement(User user, PreparedStatement userInsert) throws SQLException
user
- a User instance, which should be an implementation class which
is handled by this Repostory implementation.userInsert
- a PreparedStatement initialised with SQL taken from the "insert" SQL definition.
SQLException
- if an exception occurs while setting parameter values.protected abstract void setUserForUpdateStatement(User user, PreparedStatement userUpdate) throws SQLException
user
- a User instance, which should be an implementation class which
is handled by this Repostory implementation.userUpdate
- a PreparedStatement initialised with SQL taken from the "update" SQL definition.
SQLException
- if an exception occurs while setting parameter values.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |