vooga.engine.resource
Class DBHandler

java.lang.Object
  extended by vooga.engine.resource.DBHandler

public class DBHandler
extends java.lang.Object

DBHandler is a class that allows static access to a database for reading and writing data. The DBHandler class allows for basic interactions with an SQLite database. Currently, its functionality includes creating tables, fetching columns, and adding and deleting table rows. Different types of data can be stored in the database columns as dictated by the built-in data type constants in the Column class. As SQLite is loosely typed, it is usually fine to use the "NONE" data type for all columns.


Constructor Summary
DBHandler()
           
 
Method Summary
static boolean addRow(Entry<?>... entries)
          Adds a row of data to the database
static boolean createTable(java.lang.String tableName, Column... columns)
          Creates a new table in the database with the specified name and columns
static boolean createTable(java.lang.String tableName, java.lang.String... columnNames)
          Creates a new table in the database with the specified name and columns of the BLOB data type
static boolean deleteRow(Entry<?>... entries)
          Deletes a row of data from the database
static java.util.List<java.lang.String> getColumn(java.lang.String fieldName)
          Retrieves a column of information from the database as strings
static
<T> java.util.List<T>
getColumn(java.lang.String fieldName, T t)
          Retrieves a column of information from the database in the specified format
static boolean open(java.lang.String dbFileName)
          Opens a connection to the database file specified.
static boolean setTable(java.lang.String tableName)
          Sets the active table on which other operations are performed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DBHandler

public DBHandler()
Method Detail

open

public static boolean open(java.lang.String dbFileName)
Opens a connection to the database file specified.

Parameters:
dbFileName - Path to database file.
Returns:
true if operation successful

createTable

public static boolean createTable(java.lang.String tableName,
                                  Column... columns)
Creates a new table in the database with the specified name and columns

Parameters:
tableName - Name of table
columns - The columns the table will have
Returns:
true if operation successful

createTable

public static boolean createTable(java.lang.String tableName,
                                  java.lang.String... columnNames)
Creates a new table in the database with the specified name and columns of the BLOB data type

Parameters:
tableName - Name of table
columnNames - Names of columns
Returns:
true if operation successful

setTable

public static boolean setTable(java.lang.String tableName)
Sets the active table on which other operations are performed.

Parameters:
tableName - Name of table
Returns:
true if operation successful

getColumn

public static java.util.List<java.lang.String> getColumn(java.lang.String fieldName)
Retrieves a column of information from the database as strings

Parameters:
fieldName - Name of field to fetch
Returns:
A list containing the contents of the column

getColumn

public static <T> java.util.List<T> getColumn(java.lang.String fieldName,
                                              T t)
Retrieves a column of information from the database in the specified format

Type Parameters:
T - A class which extends Integer, String, Double, Boolean
Parameters:
fieldName - Name of field to fetch
t - An object of the class of the desired output
Returns:
A list containing the contents of the column

addRow

public static boolean addRow(Entry<?>... entries)
Adds a row of data to the database

Parameters:
entries - A set of field,data pairs
Returns:
true if operation was successful

deleteRow

public static boolean deleteRow(Entry<?>... entries)
Deletes a row of data from the database

Parameters:
entries - A set of field,data pairs a row must satisfy (via LIKE operator) to be deleted
Returns:
true if operation was successful