org.apache.james.userrepository
Class AbstractJdbcUsersRepository
java.lang.Object
|
+--org.apache.avalon.framework.logger.AbstractLoggable
|
+--org.apache.james.userrepository.AbstractUsersRepository
|
+--org.apache.james.userrepository.AbstractJdbcUsersRepository
- All Implemented Interfaces:
- org.apache.avalon.framework.component.Component, org.apache.avalon.framework.component.Composable, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.context.Contextualizable, org.apache.avalon.framework.activity.Initializable, org.apache.avalon.framework.logger.Loggable, UsersRepository
- Direct Known Subclasses:
- DefaultUsersJdbcRepository, JamesUsersJdbcRepository, ListUsersJdbcRepository
- public abstract class AbstractJdbcUsersRepository
- extends AbstractUsersRepository
- implements UsersRepository, org.apache.avalon.framework.logger.Loggable, org.apache.avalon.framework.component.Component, org.apache.avalon.framework.context.Contextualizable, org.apache.avalon.framework.component.Composable, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.activity.Initializable
An abstract base class for creating UserRepository implementation
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). |
- Author:
- Darrell DeBoer
Field Summary |
protected org.apache.avalon.framework.context.Context |
context
|
protected java.util.Map |
m_sqlParameters
|
Method Summary |
void |
compose(org.apache.avalon.framework.component.ComponentManager componentManager)
Compose the repository with the DataSourceSelector component. |
void |
configure(org.apache.avalon.framework.configuration.Configuration configuration)
Configures the UserRepository for JDBC access. |
void |
contextualize(org.apache.avalon.framework.context.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(java.lang.String name,
boolean ignoreCase)
Gets a user by name, ignoring case if specified. |
void |
initialize()
Initialises the JDBC repository. |
protected java.util.Iterator |
listAllUsers()
Returns a list populated with all of the Users in the repository. |
protected abstract User |
readUserFromResultSet(java.sql.ResultSet rsUsers)
Reads properties for a User from an open ResultSet. |
protected abstract void |
setUserForInsertStatement(User user,
java.sql.PreparedStatement userInsert)
Set parameters of a PreparedStatement object with
property values from a User instance. |
protected abstract void |
setUserForUpdateStatement(User user,
java.sql.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.AbstractLoggable |
getLogger, setLogger, setupLogger, setupLogger, setupLogger |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.apache.james.services.UsersRepository |
addUser, addUser, contains, containsCaseInsensitive, countUsers, getAttributes, getRealName, getUserByName, getUserByNameCaseInsensitive, list, removeUser, test, test, updateUser |
Methods inherited from interface org.apache.avalon.framework.logger.Loggable |
setLogger |
context
protected org.apache.avalon.framework.context.Context context
m_sqlParameters
protected java.util.Map m_sqlParameters
AbstractJdbcUsersRepository
public AbstractJdbcUsersRepository()
contextualize
public void contextualize(org.apache.avalon.framework.context.Context context)
throws org.apache.avalon.framework.context.ContextException
- Specified by:
contextualize
in interface org.apache.avalon.framework.context.Contextualizable
compose
public void compose(org.apache.avalon.framework.component.ComponentManager componentManager)
throws org.apache.avalon.framework.component.ComponentException
- Compose the repository with the DataSourceSelector component.
- Specified by:
compose
in interface org.apache.avalon.framework.component.Composable
configure
public void configure(org.apache.avalon.framework.configuration.Configuration configuration)
throws org.apache.avalon.framework.configuration.ConfigurationException
- Configures the UserRepository for JDBC access.
Requires a configuration element in the .conf.xml file of the form:
MailDb
dist/conf/sqlResources.xml
- Specified by:
configure
in interface org.apache.avalon.framework.configuration.Configurable
initialize
public void initialize()
throws java.lang.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 paramter substitution,
3) Initialises the database with the required tables, if necessary.
- Specified by:
initialize
in interface org.apache.avalon.framework.activity.Initializable
listAllUsers
protected java.util.Iterator listAllUsers()
- Returns a list populated with all of the Users in the repository.
- Overrides:
listAllUsers
in class AbstractUsersRepository
- Returns:
- an
Iterator
of JamesUser
s.
doAddUser
protected void doAddUser(User user)
- Adds a user to the underlying Repository.
The user name must not clash with an existing user.
- Overrides:
doAddUser
in class AbstractUsersRepository
doRemoveUser
protected void doRemoveUser(User user)
- Removes a user from the underlying repository.
If the user doesn't exist, returns ok.
- Overrides:
doRemoveUser
in class AbstractUsersRepository
doUpdateUser
protected void doUpdateUser(User user)
- Updates a user record to match the supplied User.
- Overrides:
doUpdateUser
in class AbstractUsersRepository
getUserByName
protected User getUserByName(java.lang.String name,
boolean ignoreCase)
- Gets a user by name, ignoring case if specified.
If the specified SQL statement has been defined, this method
overrides the basic implementation in AbstractUsersRepository
to increase performance.
- Overrides:
getUserByName
in class AbstractUsersRepository
readUserFromResultSet
protected abstract User readUserFromResultSet(java.sql.ResultSet rsUsers)
throws java.sql.SQLException
- Reads properties for a User from an open ResultSet.
Subclass implementations of this method must have knowledge of the fields
presented by the "select" and "selectByLowercaseName" SQL statements.
These implemenations may generate a subclass-specific User instance.
- Parameters:
rsUsers
- A ResultSet with a User record in the current row.- Returns:
- A User instance
- Throws:
java.sql.SQLException
- if an exception occurs reading from the ResultSet
setUserForInsertStatement
protected abstract void setUserForInsertStatement(User user,
java.sql.PreparedStatement userInsert)
throws java.sql.SQLException
- Set parameters of a PreparedStatement object with
property values from a User instance.
Implementations of this method have knowledge of the parameter
ordering of the "insert" SQL statement definition.
- Parameters:
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.- Throws:
java.sql.SQLException
- if an exception occurs while setting parameter values.
setUserForUpdateStatement
protected abstract void setUserForUpdateStatement(User user,
java.sql.PreparedStatement userUpdate)
throws java.sql.SQLException
- Set parameters of a PreparedStatement object with
property values from a User instance.
Implementations of this method have knowledge of the parameter
ordering of the "update" SQL statement definition.
- Parameters:
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.- Throws:
java.sql.SQLException
- if an exception occurs while setting parameter values.
Copyright © 2001 Apache Jakarta Project. All Rights Reserved.