import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
<c:setVariable var="boClassName" select="camelCase(/table/@formatname)" />
<c:setVariable var="boClassNameVar" select="lowercaseFirst(camelCase(/table/@formatname))" />
/**
* This DAO class provides access to the
* Oracle table <c:get select="/table/@name" /> by
* several defined methods thus abstracting the
* database access.<br>
* The transaction is set to prevent dirty reads, non-repeatable
* reads and phantom reads. The autocommit-flag is set, meaning
* that a commit is executed after every update, insert or
* delete statement.
*/
public class <c:get select="$boClassName" />DAO {
/**
* Connection to the database
*/
private Connection con=null;
/**
* Statement on which the statements are executed
*/
private Statement stmt=null;
/**
* Default constructor initialized the connection
* @param db_url URL of the database e.g. localhost
* @param username name of the user to log into the database
* @param password password for <code>username</code> to log into the database
* @throws ClassNotFoundException the JDBC driver could not be loaded.
* Make sure the correct library is on your classpath
* @param SQLException The connection could not be established or the statement created.
*/
public <c:get select="$boClassName" />DAO(String db_url, String username, String password)
throws ClassNotFoundException, SQLException{
Class.forName("com.oracle.jdbc.OracleDriver");
con = DriverManager.getConnection(db_url, username, password);
con.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
con.setAutoCommit(true);
stmt = con.createStatement();
}
public int update(){
<c:setVariable var="numFields" select="0" />
<c:setVariable var="numFieldsSet" select="-1" />
<c:iterate select="/table/tabledef/field" var="f">
<c:setVariable var="numFields" select="$numFields+1" />
<c:setVariable var="numFieldsSet" select="$numFieldsSet+1" />
</c:iterate>
<c:setVariable var="curField" select="0" />
String statement = <c:include template="templates/updateSQL.jet" />
}
public int insert(){
}
public int delete(){
}
<c:iterate select="/table/indexdef/index" var="i">
<c:if test="$i/@constraint='UNIQUE'">
<c:setVariable var="numFieldsSet" select="-1" />
<c:iterate select="/table/tabledef/field" var="f">
<c:setVariable var="numFieldsSet" select="$numFieldsSet+1" />
</c:iterate>
public <c:get select="$boClassName" /> loadUnique<c:get select="$i/@name"
/>(<c:iterate select="$i/field" var="f"><c:get select="$f/@shorttype"
/> <c:get select="lowercaseFirst(camelCase($f/@formatname))"
/><c:if test="$curField<$numFieldsSet">, </c:if></c:iterate>){
}
</c:if>
</c:iterate>