public class JDBCDictionary extends Object implements Dictionary
Dictionary
backed by a database table.Modifier and Type | Field and Description |
---|---|
protected DataSource |
dataSource
JDBC data source.
|
protected String |
searchStatement
SQL search statement.
|
protected String |
sizeStatement
SQL size statement.
|
Constructor and Description |
---|
JDBCDictionary(DataSource source,
String searchSql,
String sizeSql)
Creates a new JDBC dictionary.
|
Modifier and Type | Method and Description |
---|---|
protected <T> T |
executeStatement(String statement,
Class<T> type,
Object... params)
Executes a prepared statement against the database.
|
protected Connection |
getConnection()
Returns a connection that is ready for use.
|
boolean |
search(String word)
Returns whether the supplied word exists in the dictionary.
|
long |
size()
Returns the number of words in this dictionary
|
protected DataSource dataSource
protected String searchStatement
protected String sizeStatement
public JDBCDictionary(DataSource source, String searchSql, String sizeSql)
source
- connection data sourcesearchSql
- prepared statement to query for words; first parameter is the wordsizeSql
- prepared statement to query for size; no parameters are providedpublic boolean search(String word)
Dictionary
search
in interface Dictionary
word
- to search forpublic long size()
Dictionary
size
in interface Dictionary
protected <T> T executeStatement(String statement, Class<T> type, Object... params) throws SQLException
T
- return typestatement
- to executetype
- of object to returnparams
- to set on the prepared statementSQLException
- if the statement execution failsprotected Connection getConnection() throws SQLException
SQLException
- if a connection is not availableCopyright © 2003-2024 Virginia Tech. All Rights Reserved.