|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object standup.sql.SQLUtils
public class SQLUtils
This is the class that handles the connection to the PostgreSQL database. It provides a range of static methods for posting queries and retrieving results using the JDBC API. Note that no knowledge of the JDBC API is required to use these methods.
Field Summary | |
---|---|
private static PreparedStatement |
cpsSelectIdFromLexiconWhereOrtho
|
private static PreparedStatement |
cpsSelectIdFromLexiconWhereWord
|
private static PreparedStatement |
cpsSelectIdFromWordformWhereOrtho
|
private static Connection |
db
Connection object to the Postgres database. |
private static boolean |
initialized
Boolean value indicating whether or not a connection to the database has been initialized. |
private static String |
masterSQLParamsFile
|
Constructor Summary | |
---|---|
SQLUtils()
|
Method Summary | |
---|---|
(package private) static boolean |
callBooleanFunction(CallableStatement cs,
String arg)
|
(package private) static float |
callFloatFunction(CallableStatement cs,
String arg)
|
(package private) static int |
callIntFunction(CallableStatement cs,
String arg)
|
(package private) static long |
callLongFunction(CallableStatement cs,
String arg)
|
(package private) static ResultSet |
callResultSetFunction(CallableStatement cs,
String arg)
|
(package private) static String |
callStringFunction(CallableStatement cs,
String arg)
|
private static Set<standup.authoring.dbbuild.ProtoLexeme> |
convertLexemeIDStringListToSetProtoLexeme(Collection<String> lexemeIDs)
|
private static Set<standup.authoring.dbbuild.ProtoWordForm> |
convertWordFormIDStringListToSetProtoWordForm(Collection<String> wordFormIDs)
|
static String |
createTemporaryLexemeIDSetTable(LexemeSet ls)
Creates a temporary table in the SQL database, containing a single 'id' column, and populated by all the Lexeme IDs found in the given LexemeSet . |
static void |
deleteTable(String tableName)
This function deletes the SQL table with the given table name. |
private static List<String> |
doCompoundSpell(List<WordString> ws)
|
private static List<String> |
doCompoundSpell(List<WordString> ws,
String prefix)
|
static int |
executeArbitraryStatement(String stmtString)
|
static int |
executeArbitraryStatementQuietly(String stmtString)
|
static int[] |
executeArbitraryStatements(List<String> stmtStrings)
Execute a batch of SQL statements (e.g. |
static ResultSet |
executeQuery(String query)
|
private static PreparedStatement |
getCPSSelectIdFromLexiconWhereOrtho()
|
private static PreparedStatement |
getCPSSelectIdFromLexiconWhereWord()
|
private static PreparedStatement |
getCPSSelectIdFromWordformWhereOrtho()
|
static Statement |
getCursorBasedStatement()
This returns the offset-th row in the SQL table with name tableName, which must be a table of schema instantiations whose columns are those specified by schemaVars. |
static Statement |
getCursorBasedStatement(int fetchSize)
Returns a Statement that will 'fetch' rows using a cursor with given fetchSize. |
static List<List<Keyword>> |
getListNKeywordListFromQuery(int n,
String query)
This executes the SQL query provided as a parameter, and assumes that the result of the query is an n-column table of Strings, which is returned as a List of List of Keyword s. |
static List<List<String>> |
getListNStringListFromQuery(int n,
String query)
This executes the SQL query provided as a parameter, and assumes that the result of the query is an n-column table of Strings, which is returned as a List of List of Strings. |
static PreparedStatement |
getPreparedStatement(String query)
This method returns a PreparedStatement given the query. |
private static List<String> |
getPreparedStatementResult(PreparedStatement cps,
String value)
Executes the given PreparedStatement using the given parameter
value and returns the query results as a List<String> ,
or null if an error occurred. |
private static Set<String> |
getPreparedStatementResultUnion(PreparedStatement cps,
List<String> values)
Executes the given PreparedStatement using the different
parameters given in values and returns the UNION of all the query
results as a Set<String> . |
static LexemeSet |
getSpelledCompiledLexemes(WordForm w)
Returns all Lexeme s spelt with the given WordForm . |
static LexemeSet |
getSpelledCompiledLexemes(WordSequence w)
Returns all Lexeme s with the given spelling. |
static Set<WordForm> |
getSpelledCompiledWordForms(WordSequence w)
|
static Set<standup.authoring.dbbuild.ProtoLexeme> |
getSpelledProtoLexemes(standup.authoring.dbbuild.ProtoWordForm w)
|
static Set<standup.authoring.dbbuild.ProtoLexeme> |
getSpelledProtoLexemes(WordSequence w)
|
static Set<standup.authoring.dbbuild.ProtoWordForm> |
getSpelledProtoWordForms(WordSequence w)
|
(package private) static Statement |
getStatement()
Returns a Statement . |
static List<String> |
getStringListFromQuery(String query)
This executes the SQL query provided as a parameter, and assumes that the result of the query is a 1-column table of strings, which is returned as a List of Strings. |
private static List<String> |
getStringListFromResultSet(ResultSet rs)
Builds a List<String> from the given ResultSet , which is
assumed to contain String values for its first column. |
static int |
getTableCount(String tableName)
This returns the number of rows contained in the SQL table with the given table name. |
static void |
initialize()
This initializes the SQL database connection using the arguments supplied by CommandLineArguments . |
private static void |
initialize(String[] params)
A method of initializing the database connection by providing it with an array of Strings that contains the required parameters. |
static void |
initialize(URL configURL)
This initializes the SQL database connection using the arguments supplied in the given URL . |
static boolean |
isInitialized()
|
(package private) static CallableStatement |
prepareFunction(String funcName,
int arity)
This method calls an SQL function that takes a String argument and returns the single return value as a String. |
(package private) static CallableStatement |
prepareFunction(String funcName,
int returnType,
int arity)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static String masterSQLParamsFile
private static Connection db
private static boolean initialized
private static PreparedStatement cpsSelectIdFromWordformWhereOrtho
private static PreparedStatement cpsSelectIdFromLexiconWhereOrtho
private static PreparedStatement cpsSelectIdFromLexiconWhereWord
Constructor Detail |
---|
public SQLUtils()
Method Detail |
---|
public static void initialize() throws STANDUPSQLException
CommandLineArguments
. It takes whatever arguments it can, and
uses the defaults contained in 'masterSQLParamsFile' for whatever is not
supplied.
STANDUPSQLException
public static void initialize(URL configURL) throws STANDUPSQLException
URL
.
STANDUPSQLException
private static void initialize(String[] params) throws STANDUPSQLException
params
- An array of 4 Strings
STANDUPSQLException
public static boolean isInitialized()
static CallableStatement prepareFunction(String funcName, int arity)
funcName
- The name of the SQL (i.e. pl/pgsql) function, e.g.
'getwordformortho'arg
- The String value to be passed as an argument (most probably
the id field of a Lexeme or a WordForm)
String
value returned by the SQL function.static CallableStatement prepareFunction(String funcName, int returnType, int arity)
static ResultSet callResultSetFunction(CallableStatement cs, String arg)
static String callStringFunction(CallableStatement cs, String arg)
static int callIntFunction(CallableStatement cs, String arg)
static boolean callBooleanFunction(CallableStatement cs, String arg)
static long callLongFunction(CallableStatement cs, String arg)
static float callFloatFunction(CallableStatement cs, String arg)
public static PreparedStatement getPreparedStatement(String query)
private static List<String> getStringListFromResultSet(ResultSet rs)
List<String>
from the given ResultSet
, which is
assumed to contain String
values for its first column. Any other
columns are ignored.
rs
-
public static List<String> getStringListFromQuery(String query)
query
- the SQL query to be executed
List
of String
s containing the
values returned by the query.public static List<List<String>> getListNStringListFromQuery(int n, String query)
query
- the SQL query to be executed
List
of List
of
String
s containing the values returned by the
query.public static List<List<Keyword>> getListNKeywordListFromQuery(int n, String query)
Keyword
s.
query
- the SQL query to be executed
List
of List
of
Keyword
s containing the values returned by the
query.Keyword.createKeyword(String)
static Statement getStatement() throws SQLException
Statement
.
SQLException
public static Statement getCursorBasedStatement()
tableName
- The name of the SQL table containing the schema instantiations
(probably a temporary one!). The general contract is that it
contains n+m columns, where n = the number of schema variables
to be instantiated and m = the number of phonetic similarity
values.schemaVars
- The name of the schema variables to be instantiated. These
must match the colum names in the specified SQL table.phonSimVars
- The name of the phonetic similarity variables to be extracted.
These must match the colum names in the specified SQL table.offset
- The index of the row to be returned
public static Statement getCursorBasedStatement(int fetchSize)
fetchSize
-
public static ResultSet executeQuery(String query)
public static void deleteTable(String tableName) throws STANDUPSQLException
tableName
-
STANDUPSQLException
public static int getTableCount(String tableName) throws STANDUPSQLException
tableName
-
STANDUPSQLException
public static int[] executeArbitraryStatements(List<String> stmtStrings)
public static int executeArbitraryStatement(String stmtString)
public static int executeArbitraryStatementQuietly(String stmtString)
public static Set<WordForm> getSpelledCompiledWordForms(WordSequence w)
public static Set<standup.authoring.dbbuild.ProtoWordForm> getSpelledProtoWordForms(WordSequence w)
private static PreparedStatement getCPSSelectIdFromWordformWhereOrtho()
public static LexemeSet getSpelledCompiledLexemes(WordSequence w)
Lexeme
s with the given spelling. Requires access to
the SQL lexical database.
w
- The required spelt form
LexemeSet
of all CompiledLexeme
s with the
given spellingpublic static Set<standup.authoring.dbbuild.ProtoLexeme> getSpelledProtoLexemes(WordSequence w)
private static PreparedStatement getCPSSelectIdFromLexiconWhereOrtho()
public static LexemeSet getSpelledCompiledLexemes(WordForm w)
Lexeme
s spelt with the given WordForm
.
Requires access to the SQL lexical database.
w
-
public static Set<standup.authoring.dbbuild.ProtoLexeme> getSpelledProtoLexemes(standup.authoring.dbbuild.ProtoWordForm w)
private static PreparedStatement getCPSSelectIdFromLexiconWhereWord()
private static List<String> getPreparedStatementResult(PreparedStatement cps, String value)
PreparedStatement
using the given parameter
value
and returns the query results as a List<String>
,
or null
if an error occurred. Assumes that cps
takes one
String
argument, and the query result is a one-column table of
String
s.
cps
- value
-
private static Set<String> getPreparedStatementResultUnion(PreparedStatement cps, List<String> values)
PreparedStatement
using the different
parameters given in values
and returns the UNION of all the query
results as a Set<String>
. Assumes that cps
takes one
String
argument, and the query result is a one-column table of
String
s. Note that since it uses a set union, if any of the
individual results contains duplicate values these will be deleted as
well.
cps
- values
-
private static Set<standup.authoring.dbbuild.ProtoLexeme> convertLexemeIDStringListToSetProtoLexeme(Collection<String> lexemeIDs)
private static Set<standup.authoring.dbbuild.ProtoWordForm> convertWordFormIDStringListToSetProtoWordForm(Collection<String> wordFormIDs)
private static List<String> doCompoundSpell(List<WordString> ws)
private static List<String> doCompoundSpell(List<WordString> ws, String prefix)
public static String createTemporaryLexemeIDSetTable(LexemeSet ls) throws STANDUPSQLException
LexemeSet
. This is required for the instantiation of a
standup.joke.InstantiationConstraintLexicon
. The resulting table
uses the single 'id' column as its primary key.
ls
- The LexemeSet
containing the values for the
temporary table.
STANDUPSQLException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |