public abstract class DBConnector
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected java.sql.Connection |
con |
protected java.lang.String |
databaseName |
protected java.lang.String |
databaseUrl |
protected java.lang.String |
documentTableName |
protected java.lang.String |
documentTermsTableName |
static java.util.Hashtable<java.lang.String,java.lang.Class<?>> |
fieldsDocument |
static java.util.Hashtable<java.lang.String,java.lang.Class<?>> |
fieldsDocumentTerms |
static java.util.Hashtable<java.lang.String,java.lang.Class<?>> |
fieldsTerm |
protected java.lang.String |
password |
(package private) java.sql.Statement |
statement |
protected java.lang.String |
statementEndCharacter |
protected java.lang.String |
tableNamePrefix |
protected java.lang.String |
termTableName |
protected java.lang.String |
user |
Constructor and Description |
---|
DBConnector(java.lang.String databaseUrl,
java.lang.String databaseName,
java.lang.String user,
java.lang.String password,
java.lang.String tableNamePrefix) |
Modifier and Type | Method and Description |
---|---|
protected void |
checkDBConnection()
Checks whether the connection is open, and opens a new connection if needed.
|
void |
closeConnection()
Closes the DB connection.
|
boolean |
connect() |
protected void |
createTable(java.lang.String tableName,
java.util.Hashtable<java.lang.String,java.lang.Class<?>> fields,
java.lang.String primaryKey,
java.lang.String uniqueKey)
Creates a database table.
|
int |
doInsert(java.lang.String tableName,
java.lang.String[] columns,
java.lang.Object[] values)
Inserts a new row into a table.
|
int |
doInsert(java.lang.String tableName,
java.lang.String[] columns,
java.lang.Object[][] values)
Inserts multiple rows into the table.
|
int |
doInsert(java.lang.String tableName,
java.lang.String column,
java.lang.Object value) |
int |
doInsert(java.lang.String tableName,
java.lang.String column,
java.lang.String value) |
java.sql.ResultSet |
executeSelect(java.lang.String query)
Executes a SELECT Statement and returns a ResultSet
|
int |
executeUpdate(java.lang.String query)
Executes an update statement.
|
java.lang.String |
getDocumentTableName() |
java.lang.String |
getDocumentTermsTableName() |
private java.lang.StringBuffer |
getInsertQuery(java.lang.String tableName,
java.lang.String[] columns,
java.lang.Object[] values) |
private java.lang.StringBuffer |
getInsertQuery(java.lang.String tableName,
java.lang.String column,
java.lang.Object value) |
private java.lang.StringBuffer |
getInsertQuery(java.lang.String tableName,
java.lang.String column,
java.lang.String value) |
java.sql.PreparedStatement |
getPreparedStatement(java.lang.String sql)
Creates a prepared statement for the given query
|
java.lang.String |
getTermTableName() |
abstract java.sql.Connection |
openConnection() |
void |
setupTables()
Prepares the database by creating the needed tables.
|
public static java.util.Hashtable<java.lang.String,java.lang.Class<?>> fieldsDocument
public static java.util.Hashtable<java.lang.String,java.lang.Class<?>> fieldsDocumentTerms
public static java.util.Hashtable<java.lang.String,java.lang.Class<?>> fieldsTerm
java.sql.Statement statement
protected java.sql.Connection con
protected java.lang.String databaseName
protected java.lang.String databaseUrl
protected java.lang.String password
protected java.lang.String tableNamePrefix
protected java.lang.String user
protected java.lang.String documentTableName
protected java.lang.String documentTermsTableName
protected java.lang.String termTableName
protected java.lang.String statementEndCharacter
public DBConnector(java.lang.String databaseUrl, java.lang.String databaseName, java.lang.String user, java.lang.String password, java.lang.String tableNamePrefix)
protected void checkDBConnection() throws java.sql.SQLException
java.sql.SQLException
- if connection to DB failspublic boolean connect() throws java.sql.SQLException
java.sql.SQLException
public void closeConnection() throws java.sql.SQLException
java.sql.SQLException
- if the connection is closed or in auto-commit mode.public abstract java.sql.Connection openConnection() throws java.sql.SQLException
java.sql.SQLException
public int doInsert(java.lang.String tableName, java.lang.String[] columns, java.lang.Object[] values) throws java.sql.SQLException
tableName
- The table to insert.columns
- The names of the columns.values
- The values, in the same order as the column namesjava.sql.SQLException
- if the insert failspublic int doInsert(java.lang.String tableName, java.lang.String column, java.lang.Object value) throws java.sql.SQLException
java.sql.SQLException
public int doInsert(java.lang.String tableName, java.lang.String column, java.lang.String value) throws java.sql.SQLException
java.sql.SQLException
public int doInsert(java.lang.String tableName, java.lang.String[] columns, java.lang.Object[][] values) throws java.sql.SQLException
java.sql.SQLException
doInsert(String, String[], Object[])
public java.sql.PreparedStatement getPreparedStatement(java.lang.String sql) throws java.sql.SQLException
java.sql.SQLException
private java.lang.StringBuffer getInsertQuery(java.lang.String tableName, java.lang.String[] columns, java.lang.Object[] values)
private java.lang.StringBuffer getInsertQuery(java.lang.String tableName, java.lang.String column, java.lang.Object value)
private java.lang.StringBuffer getInsertQuery(java.lang.String tableName, java.lang.String column, java.lang.String value)
public java.sql.ResultSet executeSelect(java.lang.String query) throws java.sql.SQLException
query
- Stringjava.sql.SQLException
- if a db-error occures.public int executeUpdate(java.lang.String query) throws java.sql.SQLException
query
- SQL Statementjava.sql.SQLException
- if a db-error occures.public java.lang.String getDocumentTableName()
public java.lang.String getDocumentTermsTableName()
public java.lang.String getTermTableName()
protected void createTable(java.lang.String tableName, java.util.Hashtable<java.lang.String,java.lang.Class<?>> fields, java.lang.String primaryKey, java.lang.String uniqueKey) throws java.sql.SQLException
tableName
- name of the tablefields
- the columns of the tableprimaryKey
- primary keyuniqueKey
- additional unique keyjava.sql.SQLException
- if a db-error occures.public void setupTables() throws java.sql.SQLException
java.sql.SQLException
- if a db-error occures.