|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectat.tuwien.ifs.somtoolbox.database.DBConnector
public abstract class DBConnector
An abstract Database connector.
Field Summary | |
---|---|
protected Connection |
con
|
protected String |
databaseName
|
protected String |
databaseUrl
|
protected String |
documentTableName
|
protected String |
documentTermsTableName
|
static Hashtable<String,Class<?>> |
fieldsDocument
|
static Hashtable<String,Class<?>> |
fieldsDocumentTerms
|
static Hashtable<String,Class<?>> |
fieldsTerm
|
protected String |
password
|
(package private) Statement |
statement
|
protected String |
statementEndCharacter
|
protected String |
tableNamePrefix
|
protected String |
termTableName
|
protected String |
user
|
Constructor Summary | |
---|---|
DBConnector(String databaseUrl,
String databaseName,
String user,
String password,
String tableNamePrefix)
|
Method Summary | |
---|---|
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(String tableName,
Hashtable<String,Class<?>> fields,
String primaryKey,
String uniqueKey)
Creates a database table. |
int |
doInsert(String tableName,
String[] columns,
Object[] values)
Inserts a new row into a table. |
int |
doInsert(String tableName,
String[] columns,
Object[][] values)
Inserts multiple rows into the table. |
int |
doInsert(String tableName,
String column,
Object value)
|
int |
doInsert(String tableName,
String column,
String value)
|
ResultSet |
executeSelect(String query)
Executes a SELECT Statement and returns a ResultSet |
int |
executeUpdate(String query)
Executes an update statement. |
String |
getDocumentTableName()
|
String |
getDocumentTermsTableName()
|
private StringBuffer |
getInsertQuery(String tableName,
String[] columns,
Object[] values)
|
private StringBuffer |
getInsertQuery(String tableName,
String column,
Object value)
|
private StringBuffer |
getInsertQuery(String tableName,
String column,
String value)
|
PreparedStatement |
getPreparedStatement(String sql)
Creates a prepared statement for the given query |
String |
getTermTableName()
|
abstract Connection |
openConnection()
|
void |
setupTables()
Prepares the database by creating the needed tables. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static Hashtable<String,Class<?>> fieldsDocument
public static Hashtable<String,Class<?>> fieldsDocumentTerms
public static Hashtable<String,Class<?>> fieldsTerm
Statement statement
protected Connection con
protected String databaseName
protected String databaseUrl
protected String password
protected String tableNamePrefix
protected String user
protected String documentTableName
protected String documentTermsTableName
protected String termTableName
protected String statementEndCharacter
Constructor Detail |
---|
public DBConnector(String databaseUrl, String databaseName, String user, String password, String tableNamePrefix)
Method Detail |
---|
protected void checkDBConnection() throws SQLException
SQLException
- if connection to DB failspublic boolean connect() throws SQLException
SQLException
public void closeConnection() throws SQLException
SQLException
- if the connection is closed or in auto-commit mode.public abstract Connection openConnection() throws SQLException
SQLException
public int doInsert(String tableName, String[] columns, Object[] values) throws SQLException
tableName
- The table to insert.columns
- The names of the columns.values
- The values, in the same order as the column names
SQLException
- if the insert failspublic int doInsert(String tableName, String column, Object value) throws SQLException
SQLException
public int doInsert(String tableName, String column, String value) throws SQLException
SQLException
public int doInsert(String tableName, String[] columns, Object[][] values) throws SQLException
SQLException
doInsert(String, String[], Object[])
public PreparedStatement getPreparedStatement(String sql) throws SQLException
SQLException
private StringBuffer getInsertQuery(String tableName, String[] columns, Object[] values)
private StringBuffer getInsertQuery(String tableName, String column, Object value)
private StringBuffer getInsertQuery(String tableName, String column, String value)
public ResultSet executeSelect(String query) throws SQLException
query
- String
SQLException
- if a db-error occures.public int executeUpdate(String query) throws SQLException
query
- SQL Statement
SQLException
- if a db-error occures.public String getDocumentTableName()
public String getDocumentTermsTableName()
public String getTermTableName()
protected void createTable(String tableName, Hashtable<String,Class<?>> fields, String primaryKey, String uniqueKey) throws SQLException
tableName
- name of the tablefields
- the columns of the tableprimaryKey
- primary keyuniqueKey
- additional unique key
SQLException
- if a db-error occures.public void setupTables() throws SQLException
SQLException
- if a db-error occures.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |