Modifier and Type | Method and Description |
---|---|
static void |
closeStatementIfOpen(Statement s)
Close a statement, if not closed already Note: This does not throw any a SQLException, because it is always
called inside a finally-clause.
|
static void |
executeSQL(Connection connection,
String... updates)
Update a database by executing all the statements in the updates String array.
|
static Date |
getDateMaybeNull(ResultSet rs,
int columnIndex)
Get a Date from a column in the resultset.
|
static long |
getGeneratedID(PreparedStatement s)
Get the automatically generated key that was created with the just-executed statement.
|
static Integer |
getIntegerMaybeNull(ResultSet rs,
int i)
Get an Integer from the resultSet in column i.
|
static Long |
getLongMaybeNull(ResultSet rs,
int i)
Get a Long from the resultSet in column i.
|
static int |
getTableVersion(Connection connection,
String tablename)
Returns the version of a table according to schemaversions, or 0 for the initial, unnumbered version.
|
static String |
getUsages(Connection connection,
String select,
Object victim,
Object... args)
Return a description of where an object is used elsewhere in the database, or null.
|
static String |
makeSQLGlob(String glob)
Translate a "normal" glob (with * and .) into SQL syntax.
|
static PreparedStatement |
prepareStatement(Connection c,
int fetchSize,
String query,
Object... args)
Prepare a statement for iteration given a query string, fetch size and some args.
|
static PreparedStatement |
prepareStatement(Connection c,
String query,
Object... args)
Prepare a statement given a query string and some args.
|
static void |
rollbackIfNeeded(Connection c,
String action,
Object o)
Method to perform a rollback of complex DB updates.
|
static boolean |
selectAny(Connection connection,
String query,
Object... args)
Execute an SQL query and return whether the result contains any rows.
|
static Long |
selectFirstLongValueIfAny(Connection connection,
String query,
Object... args)
Execute an SQL statement and return the first long in the result set, or null if resultset is empty.
|
static Integer |
selectIntValue(Connection connection,
String query,
Object... args)
Execute an SQL statement and return the single int in the result set.
|
static Integer |
selectIntValue(PreparedStatement s)
Execute an SQL statement and return the single integer in the result set.
|
static Iterator<Long> |
selectLongIterator(Connection connection,
String query,
Object... args)
Return an iterator to a list of Longs.
|
static List<Long> |
selectLongList(Connection connection,
String query,
Object... args)
Execute an SQL statement and return the list of Long-objects in its result set.
|
static Set<Long> |
selectLongSet(Connection connection,
String query,
Object... args)
Execute an SQL statement and return the set of Long-objects in its result set.
|
static Long |
selectLongValue(Connection connection,
String query,
Object... args)
Execute an SQL statement and return the single long in the result set.
|
static Long |
selectLongValue(PreparedStatement s)
Execute an SQL statement and return the single long in the result set.
|
static List<String> |
selectStringList(Connection connection,
String query,
Object... args)
Execute an SQL statement and return the list of strings in its result set.
|
static Map<String,Long> |
selectStringLongMap(Connection connection,
String query,
Object... args)
Execute an SQL statement and return the list of strings -> id mappings in its result set.
|
static String |
selectStringValue(Connection connection,
String query,
Object... args)
Execute an SQL statement and return the single string in the result set.
|
static String |
selectStringValue(PreparedStatement s)
Execute an SQL statement and return the single string in the result set.
|
static void |
setClobMaxLength(PreparedStatement s,
int fieldNum,
String contents,
long maxSize,
Object o,
String fieldName)
Set the CLOB maxlength.
|
static void |
setComments(PreparedStatement s,
int fieldNum,
Named o,
int maxFieldSize)
Set the comments of a Named object into the given field of statement.
|
static void |
setDateMaybeNull(PreparedStatement s,
int fieldNum,
Date date)
Set the Date into the given field of a statement.
|
static void |
setIntegerMaybeNull(PreparedStatement s,
int i,
Integer value)
Insert an Integer in prepared statement.
|
static void |
setLongMaybeNull(PreparedStatement s,
int i,
Long value)
Insert a long value (which could be null) into the given field of a statement.
|
static void |
setName(PreparedStatement s,
int fieldNum,
Named o,
int maxFieldSize)
Set the name of a Named object into the given field.
|
static void |
setStringMaxLength(PreparedStatement s,
int fieldNum,
String contents,
int maxSize,
Object o,
String fieldname)
Set String Max Length.
|
public static Integer selectIntValue(PreparedStatement s)
s
- A prepared statementIOFailure
- if the statement didn't result in exactly one integer.public static Integer selectIntValue(Connection connection, String query, Object... args)
NB: the method does not close the provided connection.
connection
- connection to database.query
- a query with ? for parameters (must not be null or empty string)args
- parameters of type string, int, long or booleanIOFailure
- if the statement didn't result in exactly one integerpublic static Long selectLongValue(PreparedStatement s)
s
- A prepared statementIOFailure
- if the statement didn't result in exactly one row with a long or null valuepublic static Long selectLongValue(Connection connection, String query, Object... args)
NB: the provided connection is not closed.
connection
- connection to database.query
- a query with ? for parameters (must not be null or empty string)args
- parameters of type string, int, long or booleanIOFailure
- if the statement didn't result in exactly one long valuepublic static Long selectFirstLongValueIfAny(Connection connection, String query, Object... args)
NB: the provided connection is not closed.
connection
- connection to database.query
- a query with ? for parameters (must not be null or empty string)args
- parameters of type string, int, long or booleanIOFailure
- on SQL errors.public static PreparedStatement prepareStatement(Connection c, String query, Object... args) throws SQLException
NB: the provided connection is not closed.
c
- a Database connectionquery
- a query string (must not be null or empty)args
- some args to insert into this query string (must not be null)SQLException
- If unable to prepare a statementArgumentNotValid
- If unable to handle type of one the args, or the arguments are either null or an empty
String.public static PreparedStatement prepareStatement(Connection c, int fetchSize, String query, Object... args) throws SQLException
NB: the provided connection is not closed.
c
- a Database connectionfetchSize
- hint to JDBC driver on number of results to cachequery
- a query string (must not be null or empty)args
- some args to insert into this query string (must not be null)SQLException
- If unable to prepare a statementArgumentNotValid
- If unable to handle type of one the args, or the arguments are either null or an empty
String.public static List<String> selectStringList(Connection connection, String query, Object... args)
NB: the provided connection is not closed.
connection
- connection to the database.query
- the given sql-query (must not be null or empty)args
- The arguments to insert into this query (must not be null)IOFailure
- If this query failspublic static Map<String,Long> selectStringLongMap(Connection connection, String query, Object... args) throws SQLException
NB: the provided connection is not closed.
connection
- connection to the database.query
- the given sql-query (must not be null or empty string)args
- The arguments to insert into this querySQLException
- If this query failspublic static List<Long> selectLongList(Connection connection, String query, Object... args)
connection
- connection to the database.query
- the given sql-query (must not be null or empty string)args
- The arguments to insert into this querypublic static Iterator<Long> selectLongIterator(Connection connection, String query, Object... args)
connection
- an open connection to the databasequery
- The given sql-query (must not be null or empty string)args
- The arguments to insert into this querypublic static Set<Long> selectLongSet(Connection connection, String query, Object... args)
NB: the provided connection is not closed.
connection
- connection to the database.query
- the given sql-query (must not be null or empty string)args
- The arguments to insert into this querypublic static long getGeneratedID(PreparedStatement s) throws SQLException
s
- A statement created with Statement.RETURN_GENERATED_KEYSSQLException
- If a database access error occurs or the PreparedStatement is closed, or the JDBC driver
does not support the setGeneratedKeys() methodpublic static int getTableVersion(Connection connection, String tablename) throws IOFailure
NB: the provided connection is not closed
connection
- connection to the database.tablename
- The name of a table in the database.IOFailure
- if DB table schemaversions does not existpublic static void setStringMaxLength(PreparedStatement s, int fieldNum, String contents, int maxSize, Object o, String fieldname) throws SQLException
s
- a Prepared StatementfieldNum
- a index into the above statementcontents
- the contentsmaxSize
- the maximum size of field: fieldNameo
- the Object, which is assumed to have a field named fieldNamefieldname
- the name of a given fieldSQLException
- if set operation failspublic static void setComments(PreparedStatement s, int fieldNum, Named o, int maxFieldSize) throws SQLException
s
- a prepared statementfieldNum
- the index of the given field to be seto
- the Named objectmaxFieldSize
- max size of the comments fieldSQLException
- If any trouble accessing the database during the operationPermissionDenied
- If length of o.getComments() is larger than Constants.MAX_COMMENT_SIZEpublic static void setName(PreparedStatement s, int fieldNum, Named o, int maxFieldSize) throws SQLException
s
- a prepared statementfieldNum
- the index of the given field to be seto
- the Named objectmaxFieldSize
- max size of the name fieldSQLException
- If any trouble accessing the database during the operationPermissionDenied
- If length of o.getName() is larger than Constants.MAX_NAME_SIZEpublic static void setDateMaybeNull(PreparedStatement s, int fieldNum, Date date) throws SQLException
s
- a prepared statementfieldNum
- the index of the given field to be setdate
- the date (may be null)SQLException
- If any trouble accessing the database during the operationpublic static Date getDateMaybeNull(ResultSet rs, int columnIndex) throws SQLException
rs
- the resultSetcolumnIndex
- The given column, where the Date residesSQLException
- If columnIndex does not correspond to a parameter marker in the ResultSet, or a database
access error occurs or this method is called on a closed ResultSetpublic static void rollbackIfNeeded(Connection c, String action, Object o)
NB: the provided connection is not closed.
c
- the db-connectionaction
- The action going on, before calling this methodo
- The Object being acted upon by this actionpublic static void setClobMaxLength(PreparedStatement s, int fieldNum, String contents, long maxSize, Object o, String fieldName) throws SQLException
s
- a prepared statementfieldNum
- the field-index, where the contents are insertedcontents
- the contentsmaxSize
- the maxsize for this contentso
- the Object, which is assumed to have a field named fieldNamefieldName
- a given field (Assumed to present in Object o)SQLException
- If fieldNum does not correspond to a parameter marker in the PreparedStatement, or a
database access error occurs or this method is called on a closed PreparedStatementpublic static void setLongMaybeNull(PreparedStatement s, int i, Long value) throws SQLException
s
- a prepared Statementi
- the number of a given field in the prepared statementvalue
- the long value to insert (maybe null)SQLException
- If i does not correspond to a parameter marker in the PreparedStatement, or a database
access error occurs or this method is called on a closed PreparedStatementpublic static void setIntegerMaybeNull(PreparedStatement s, int i, Integer value) throws SQLException
s
- a prepared statementi
- the index of the statement, where the Integer should be insertedvalue
- The Integer to insert (maybe null)SQLException
- If i does not correspond to a parameter marker in the PreparedStatement, or a database
access error occurs or this method is called on a closed PreparedStatementpublic static Integer getIntegerMaybeNull(ResultSet rs, int i) throws SQLException
rs
- the resultseti
- the column where the wanted Integer residesSQLException
- If the columnIndex is not valid, or a database access error occurs or this method is called
on a closed result setpublic static Long getLongMaybeNull(ResultSet rs, int i) throws SQLException
rs
- the resultseti
- the column where the wanted Long residesSQLException
- If the columnIndex is not valid, or a database access error occurs or this method is called
on a closed result setpublic static String getUsages(Connection connection, String select, Object victim, Object... args)
NB: the provided connection is not closed.
connection
- connection to the database.select
- A select statement finding the names of other uses. The statement should result in exactly one
column of string values.victim
- The object being used.args
- Any objects that may be used to prepare the select statement.public static String selectStringValue(Connection connection, String query, Object... args)
This assumes the connection is to the harvester database.
connection
- connection to the database.query
- a query with ? for parameters (must not be null or an empty string)args
- parameters of type string, int, long or booleanIOFailure
- if the statement didn't result in exactly one string valuepublic static String selectStringValue(PreparedStatement s)
s
- A prepared statementIOFailure
- if the statement didn't result in exactly one row with a string or null valuepublic static boolean selectAny(Connection connection, String query, Object... args)
NB: the provided connection is not closed.
connection
- connection to the database.query
- a query with ? for parameters (must not be null or an empty String)args
- parameters of type string, int, long or booleanIOFailure
- if there were problems with the SQL querypublic static String makeSQLGlob(String glob)
glob
- A shell-like glob string (must not be null)public static void executeSQL(Connection connection, String... updates)
NB: the method does not close the provided connection.
connection
- connection to the database.updates
- The SQL statements that makes the necessary updates.IOFailure
- in case of problems in interacting with the databasepublic static void closeStatementIfOpen(Statement s)
s
- a statementCopyright © 2005–2016 The Royal Danish Library, the Danish State and University Library, the National Library of France and the Austrian National Library.. All rights reserved.