NOTICKET: Finish Javadoc for de.hitec.nhplus.datastorage
Signed-off-by: Dominik Säume <Dominik.Saeume@hmmh.de>
This commit is contained in:
parent
9de598ef67
commit
0ea3d92cc0
3 changed files with 52 additions and 12 deletions
|
@ -18,7 +18,7 @@ public interface Dao<T> {
|
||||||
/**
|
/**
|
||||||
* Create a Database Entry from a Model object.
|
* Create a Database Entry from a Model object.
|
||||||
*
|
*
|
||||||
* @param t The Model instance.
|
* @param t The Model-Instance.
|
||||||
*/
|
*/
|
||||||
void create(T t) throws SQLException;
|
void create(T t) throws SQLException;
|
||||||
|
|
||||||
|
@ -26,18 +26,19 @@ public interface Dao<T> {
|
||||||
* Read a Database Entry to a Model object.
|
* Read a Database Entry to a Model object.
|
||||||
*
|
*
|
||||||
* @param id The ID of the Element in the Database.
|
* @param id The ID of the Element in the Database.
|
||||||
|
* @return a Model-Instance of {@link T}.
|
||||||
*/
|
*/
|
||||||
T read(int id) throws SQLException;
|
T read(int id) throws SQLException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return All Database Entries as a {@link List} of Model instances
|
* @return All Database Entries as a {@link List} of Model-Instances.
|
||||||
*/
|
*/
|
||||||
List<T> readAll() throws SQLException;
|
List<T> readAll() throws SQLException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the Database according to the Values of the Model object.
|
* Update the Database according to the Values of the Model object.
|
||||||
*
|
*
|
||||||
* @param t The Model instance.
|
* @param t The Model-Instance.
|
||||||
*/
|
*/
|
||||||
void update(T t) throws SQLException;
|
void update(T t) throws SQLException;
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ public class DaoFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The Singleton Instance.
|
* @return The Singleton Instance of {@link DaoFactory}.
|
||||||
*/
|
*/
|
||||||
public static DaoFactory getInstance() {
|
public static DaoFactory getInstance() {
|
||||||
if (DaoFactory.instance == null) {
|
if (DaoFactory.instance == null) {
|
||||||
|
|
|
@ -20,8 +20,8 @@ public abstract class DaoImp<T> implements Dao<T> {
|
||||||
protected final Connection connection;
|
protected final Connection connection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param connection The Database Connection to use
|
* @param connection The Database {@link Connection} to use.
|
||||||
* @implSpec The Connection should be Received from the {@link ConnectionBuilder}.
|
* @implSpec The {@link Connection} should be Received from the {@link ConnectionBuilder}.
|
||||||
*/
|
*/
|
||||||
public DaoImp(Connection connection) {
|
public DaoImp(Connection connection) {
|
||||||
this.connection = connection;
|
this.connection = connection;
|
||||||
|
@ -30,7 +30,7 @@ public abstract class DaoImp<T> implements Dao<T> {
|
||||||
/**
|
/**
|
||||||
* Creates a new Database Entry from a Model object.
|
* Creates a new Database Entry from a Model object.
|
||||||
*
|
*
|
||||||
* @param t The Model instance.
|
* @param t The Model-Instance.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void create(T t) throws SQLException {
|
public void create(T t) throws SQLException {
|
||||||
|
@ -41,6 +41,7 @@ public abstract class DaoImp<T> implements Dao<T> {
|
||||||
* Read a Database Entry to a Model object.
|
* Read a Database Entry to a Model object.
|
||||||
*
|
*
|
||||||
* @param id The ID of the Element in the Database.
|
* @param id The ID of the Element in the Database.
|
||||||
|
* @return the Model-Instance of type {@link T}, which was read.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public T read(int id) throws SQLException {
|
public T read(int id) throws SQLException {
|
||||||
|
@ -54,6 +55,8 @@ public abstract class DaoImp<T> implements Dao<T> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read all Database Entries to a {@link List} of Model objects.
|
* Read all Database Entries to a {@link List} of Model objects.
|
||||||
|
*
|
||||||
|
* @return a {@link List} of Type {@link T} holding all Database Entries as Model-Instances.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<T> readAll() throws SQLException {
|
public List<T> readAll() throws SQLException {
|
||||||
|
@ -63,7 +66,7 @@ public abstract class DaoImp<T> implements Dao<T> {
|
||||||
/**
|
/**
|
||||||
* Update the Database according to the Values of the Model object.
|
* Update the Database according to the Values of the Model object.
|
||||||
*
|
*
|
||||||
* @param t The Model instance.
|
* @param t The Model-Instance.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void update(T t) throws SQLException {
|
public void update(T t) throws SQLException {
|
||||||
|
@ -80,17 +83,53 @@ public abstract class DaoImp<T> implements Dao<T> {
|
||||||
getDeleteStatement(id).executeUpdate();
|
getDeleteStatement(id).executeUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param result The {@link ResultSet} from execution of the Statement received from {@link #getReadByIDStatement}.
|
||||||
|
* @return The Model-Instance of Type {@link T}.
|
||||||
|
* @implSpec This will be called in {@link #read}.
|
||||||
|
*/
|
||||||
protected abstract T getInstanceFromResultSet(ResultSet result) throws SQLException;
|
protected abstract T getInstanceFromResultSet(ResultSet result) throws SQLException;
|
||||||
|
|
||||||
protected abstract List<T> getListFromResultSet(ResultSet result) throws SQLException;
|
/**
|
||||||
|
* @param id The ID of the Database Entry to read.
|
||||||
protected abstract PreparedStatement getCreateStatement(T t) throws SQLException;
|
* @return A {@link PreparedStatement} to read a Specific Entry by its ID.
|
||||||
|
* @implSpec This will be called in {@link #read}.
|
||||||
|
* The Output of the Execution will be used in {@link #getInstanceFromResultSet}.
|
||||||
|
*/
|
||||||
protected abstract PreparedStatement getReadByIDStatement(int id) throws SQLException;
|
protected abstract PreparedStatement getReadByIDStatement(int id) throws SQLException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param result The {@link ResultSet} from execution of the Statement received from {@link #getReadAllStatement}.
|
||||||
|
* @return A {@link List} of Type {@link T} Holding All Database Entries as Model-Instances.
|
||||||
|
* @implSpec This will be called in {@link #readAll}.
|
||||||
|
*/
|
||||||
|
protected abstract List<T> getListFromResultSet(ResultSet result) throws SQLException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return A {@link PreparedStatement} to read all Entries of this Model.
|
||||||
|
* @implSpec This will be called in {@link #readAll}.
|
||||||
|
* The Output of the Execution will be used in {@link #getListFromResultSet}.
|
||||||
|
*/
|
||||||
protected abstract PreparedStatement getReadAllStatement() throws SQLException;
|
protected abstract PreparedStatement getReadAllStatement() throws SQLException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param t The Model-Instance of Type {@link T} for which an Entry should be created.
|
||||||
|
* @return a {@link PreparedStatement} which can be used to create a new Database Entry for the Model-Instance.
|
||||||
|
* @implSpec This will be called in {@link #create}.
|
||||||
|
*/
|
||||||
|
protected abstract PreparedStatement getCreateStatement(T t) throws SQLException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param t The Model-Instance of Type {@link T} for which the Entry should be updated.
|
||||||
|
* @return a {@link PreparedStatement} which can be used to update the Database Entry for the Model-Instance.
|
||||||
|
* @implSpec This will be called in {@link #update}.
|
||||||
|
*/
|
||||||
protected abstract PreparedStatement getUpdateStatement(T t) throws SQLException;
|
protected abstract PreparedStatement getUpdateStatement(T t) throws SQLException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param id The ID of the Database Entry which should be Deleted.
|
||||||
|
* @return a {@link PreparedStatement} which can be used to delete the Database Entry.
|
||||||
|
* @implSpec This will be called in {@link #delete}.
|
||||||
|
*/
|
||||||
protected abstract PreparedStatement getDeleteStatement(int id) throws SQLException;
|
protected abstract PreparedStatement getDeleteStatement(int id) throws SQLException;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue