/*
|
* BaseLink - Generic object relational mapping
|
* Copyright (C) 2011 Ulrich Hilger, http://uhilger.de
|
*
|
* This program is free software: you can redistribute it and/or modify
|
* it under the terms of the GNU General Public License as published by
|
* the Free Software Foundation, either version 3 of the License, or
|
* (at your option) any later version.
|
*
|
* This program is distributed in the hope that it will be useful,
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* GNU General Public License for more details.
|
*
|
* You should have received a copy of the GNU General Public License
|
* along with this program. If not, see http://www.gnu.org/licenses/
|
*/
|
|
package de.uhilger.baselink;
|
|
import java.sql.Connection;
|
import java.sql.PreparedStatement;
|
import java.sql.ResultSet;
|
|
/**
|
* Classes that map objects to and from database records need to implement this interface.
|
*
|
* @author Copyright (c) Ulrich Hilger, http://uhilger.de
|
* @author Published under the terms and conditions of
|
* the <a href="http://www.gnu.org/licenses/" target="_blank">GNU General Public License</a>
|
*/
|
public interface Record {
|
|
/** indicator to include BLOBS in read / write operations */
|
public static final boolean WITH_BLOBS = true;
|
/** indicator to exclude BLOBS from read / write operations */
|
public static final boolean WITHOUT_BLOBS = false;
|
|
/**
|
* Get the name of the database table this record references
|
* @return the table name
|
*/
|
public String getTableName();
|
|
/**
|
* Get contents of this record as an object
|
* @param resultSet a resultSet that points to the record to get as an object
|
* @param includeBlobs indicator whether or not to include BLOBs
|
* @return an object having the data of this record
|
* @throws Exception
|
*/
|
public Object toObject(ResultSet resultSet, boolean includeBlobs) throws Exception;
|
|
/**
|
* Get a statement suitable to insert a given object to the database
|
* @param c the database connection to use for the insert
|
* @param record the object to insert
|
* @param autoGeneratedKeys a flag indicating whether auto-generated keys should be returned;
|
* one of Statement.RETURN_GENERATED_KEYS or Statement.NO_GENERATED_KEYS
|
* @return the insert statement
|
* @throws Exception
|
*/
|
public PreparedStatement getInsertStmt(Connection c, Object record, int autoGeneratedKeys)
|
throws Exception;
|
|
/**
|
* Get a statement suitable to insert a given object to the database
|
* @param c the database connection to use for the insert
|
* @param record the object to insert
|
* @return the insert statement
|
* @throws Exception
|
*/
|
public PreparedStatement getInsertStatment(Connection c, Object record)
|
throws Exception;
|
|
/**
|
* Get a statement suitable to update a given object in the database
|
* @param c the database connection to use for the update
|
* @param record the object to update
|
* @return the update statement
|
* @throws Exception
|
*/
|
public PreparedStatement getUpdateStatment(Connection c, Object record)
|
throws Exception;
|
|
/**
|
* Get a statement suitable to delete a given object from the database
|
* @param c the database connection to use for the delete
|
* @param record the object to delete
|
* @return the delete statement
|
* @throws Exception
|
*/
|
public PreparedStatement getDeleteStatment(Connection c, Object record)
|
throws Exception;
|
}
|