de.hs_rm.cs.lecturenotes.server.core.persistence.dao
Class AbstractDAO<T>

java.lang.Object
  extended by de.hs_rm.cs.lecturenotes.server.core.persistence.dao.AbstractDAO<T>
Type Parameters:
T - Type of entity to maintain
All Implemented Interfaces:
IDAO<T>
Direct Known Subclasses:
AnnotationDAO, ExerciseDAO, FilecardDAO, LectureDAO, ParagraphDAO, SlideDAO, UserDAO

public abstract class AbstractDAO<T>
extends java.lang.Object
implements IDAO<T>

This is the basic abstract Data Access Object that holds some basic functions for all implemented Data Access Objects. Data Access Objects in general provide logical functions for accessing any persisted entities within the system.

Version:
$LastChangedRevision: 274 $
Author:
Enrico Homann

Field Summary
static java.lang.String SQL_DELETEALL_TEMPLATE
          SQL Statement to delete all contents from table %tablename.
static java.lang.String SQL_DROP_TEMPLATE
          SQL Statement to drop table with table name %tablename.
 
Fields inherited from interface de.hs_rm.cs.lecturenotes.server.core.persistence.dao.IDAO
SQLERRORCODE_DUPLICATE_ENTRY
 
Constructor Summary
AbstractDAO(SQLConnection oDb)
          Constructor.
 
Method Summary
 java.lang.Long createEntity(T entity, java.sql.PreparedStatement preparedStatement)
          Creates an entity of type T and returns the inserted id.
 void deleteTableContents(java.lang.String tablename)
          Deletes all records from the table with String tablename from the database.
 void dropTable(java.lang.String tablename)
          Drops the table with String tablename from the database.
 long executeCreateSQL(java.lang.String sqlStmt)
          Executes a create SQL and returns the primary key.
 int executeUpdateSQL(java.lang.String sqlStmt)
          Executes a update SQL and returns the number of updated rows.
 SQLConnection getDb()
          Will return the SQL database connection provider.
 void setDb(SQLConnection oDb)
          Will set the SQL database connection provider.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface de.hs_rm.cs.lecturenotes.server.core.persistence.dao.IDAO
createEntity
 

Field Detail

SQL_DROP_TEMPLATE

public static final java.lang.String SQL_DROP_TEMPLATE
SQL Statement to drop table with table name %tablename.

See Also:
Constant Field Values

SQL_DELETEALL_TEMPLATE

public static final java.lang.String SQL_DELETEALL_TEMPLATE
SQL Statement to delete all contents from table %tablename.

See Also:
Constant Field Values
Constructor Detail

AbstractDAO

public AbstractDAO(SQLConnection oDb)
Constructor.

Parameters:
oDb - SQLConnection
Method Detail

getDb

public final SQLConnection getDb()
Will return the SQL database connection provider.

Returns:
SQLConnection

setDb

public final void setDb(SQLConnection oDb)
Will set the SQL database connection provider.

Parameters:
oDb - SQLConnection

dropTable

public final void dropTable(java.lang.String tablename)
Drops the table with String tablename from the database.

Parameters:
tablename - String

deleteTableContents

public final void deleteTableContents(java.lang.String tablename)
Deletes all records from the table with String tablename from the database.

Parameters:
tablename - String

createEntity

public final java.lang.Long createEntity(T entity,
                                         java.sql.PreparedStatement preparedStatement)
                                  throws java.sql.SQLException
Creates an entity of type T and returns the inserted id. Throws SQLException in case of a duplicated entry or other DBMS problems.

Parameters:
entity - T
preparedStatement - PreparedStatement predefined values
Returns:
Long Id of the freshly inserted row. Must be not null and should be above 0.
Throws:
java.sql.SQLException - Exception thrown. Here to indicate a duplicate entry to the outside world.

executeUpdateSQL

public final int executeUpdateSQL(java.lang.String sqlStmt)
Executes a update SQL and returns the number of updated rows.

Parameters:
sqlStmt - String
Returns:
int

executeCreateSQL

public final long executeCreateSQL(java.lang.String sqlStmt)
Executes a create SQL and returns the primary key.

Parameters:
sqlStmt - String
Returns:
long