Package org.passay.dictionary
Class JDBCDictionary
java.lang.Object
org.passay.dictionary.JDBCDictionary
- All Implemented Interfaces:
Dictionary
Provides a
Dictionary backed by a database table.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final DataSourceJDBC data source.protected final StringSQL search statement.protected final StringSQL size statement. -
Constructor Summary
ConstructorsConstructorDescriptionJDBCDictionary(DataSource source, String searchSql, String sizeSql) Creates a new JDBC dictionary. -
Method Summary
Modifier and TypeMethodDescriptionprotected <T> TexecuteStatement(String statement, Class<T> type, Object... params) Executes a prepared statement against the database.protected ConnectionReturns a connection that is ready for use.booleansearch(CharSequence word) Returns whether the supplied word exists in the dictionary.longsize()Returns the number of words in this dictionary
-
Field Details
-
dataSource
JDBC data source. -
searchStatement
SQL search statement. -
sizeStatement
SQL size statement.
-
-
Constructor Details
-
JDBCDictionary
Creates a new JDBC dictionary.- Parameters:
source- connection data sourcesearchSql- prepared statement to query for words; first parameter is the wordsizeSql- prepared statement to query for size; no parameters are provided
-
-
Method Details
-
search
Description copied from interface:DictionaryReturns whether the supplied word exists in the dictionary.- Specified by:
searchin interfaceDictionary- Parameters:
word- to search for- Returns:
- whether word was found
-
size
public long size()Description copied from interface:DictionaryReturns the number of words in this dictionary- Specified by:
sizein interfaceDictionary- Returns:
- total number of words to search
-
executeStatement
protected <T> T executeStatement(String statement, Class<T> type, Object... params) throws SQLException Executes a prepared statement against the database. Only the first result is returned.- Type Parameters:
T- return type- Parameters:
statement- to executetype- of object to returnparams- to set on the prepared statement- Returns:
- first result of the prepared statement
- Throws:
SQLException- if the statement execution fails
-
getConnection
Returns a connection that is ready for use.- Returns:
- database connection.
- Throws:
SQLException- if a connection is not available
-