Code Generator for Eclipse Code
Brought to you by:
hotzst
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 = "UPDATE <c:get select="/table/@name" /> SET <c:iterate select="/table/tabledef/field" var="f" ><c:get select="$f/@name" />=<c:setVariable var="type" select="$f/@shorttype" /><c:include template="templates/dbTypeQuote.jet" passVariables="type" />"+<c:get select="$boClassNameVar" />.get<c:get select="camelCase($f/@formatname)" />()+"<c:include template="templates/dbTypeQuote.jet" passVariables="type" /><c:if test="$curField<$numFieldsSet">, </c:if ><c:setVariable var="curField" select="$curField+1"/></c:iterate>"; } public int insert(){ } public int delete(){ } <c:iterate select="/table/indexdef/index" var="i"> <c:if test="$i/@constraint='UNIQUE'"> public <c:get select="camelCase(/table/@formatname)" /> loadUniqueBy<c:get select="$i/@name" />( <c:iterate select="$i/field" var="f"> </c:iterate> </c:if> </c:iterate> }