/* * 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; /** * Abstract base class for objects that like to implement the Record interface. * This class is meant as a convenience so that not all methods need to be implmented. Simply * implement those needed by overriding the necessary ones. * * @author Copyright (c) Ulrich Hilger, http://uhilger.de * @author Published under the terms and conditions of * the GNU General Public License */ public abstract class BaseRecord implements Record { /** * Get a statement suitable to delete a given object from the database * *

Override this method in subclasses as required

* * @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 { throw new Exception("not implemented"); } /** * Get a statement suitable to insert a given object to the database * *

Override this method in subclasses as required

* * @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 { throw new Exception("not implemented"); } /** * 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 { throw new Exception("not implemented"); } /** * Get the name of the database table this record references * *

Override this method in subclasses as required

* * @return the table name */ public String getTableName() { return null; } /** * Get a statement suitable to update a given object in the database * *

Override this method in subclasses as required

* * @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 { throw new Exception("not implemented"); } /** * Get contents of this record as an object * *

Override this method in subclasses as required

* * @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 { throw new Exception("not implemented"); } }