package e4s.tutorial;
import e4s.html.*;
import e4s.servlet.*;
import e4s.db.*;
import java.io.*;
// import java.awt.*;
import java.util.*;
import java.text.*;
import java.net.*;
import java.sql.*;
import tabledef.*;
/**
* Database access - Transactions.
*
* {@tutorial Example_DB_Transaction}
*/
public class Example_DB_Transaction extends E4ModuleImplementation
{
/*
public static E4Method start = null;
public static E4Method running = null;
public static E4Method select = null;
public static E4Method test = null;
private static char m_id = 'A';
*/
/*
public void start( HTML html, E4CgiParams params )
throws E4DBException
{
TEST_Mod TEST = new TEST_Mod( getApplObj() );
TEST.executeDelete();
menu(html);
m_id++;
}
public void menu( HTML html )
throws E4DBException
{
A hrefRunning = html.A(running);
hrefRunning.openInNewWindow("RUNNING");
hrefRunning.add("A",m_id);
hrefRunning.print("Klick here to open a new window with an incremental counter");
html.BR();
A hrefSelect = html.A(select);
hrefSelect.print("Klick here to select data");
html.BR();
A hrefTest = html.A(test);
hrefTest.print("Insert 100 records, delay whole process for 10 sec, commit after the 5th but rollback after 99");
}
public void running( HTML html, E4CgiParams params )
throws E4DBException
{
int n = params.getInt("N") + 1;
String a = params.get("A");
BODY body = html.BODY();
body.B().print(a + n);
html.setTitle(a + n);
E4EventHandlerBODY js = body.createEventHandler(E4EventHandlerBODY._EVENT_ONLOAD);
js.appendln("function " + js.getName() + "()");
js.appendln("{");
js.appendln(" url = '" + running.constructUrl(getServlet()) + "';" );
js.appendln(" url += '&N=" + n + "';");
js.appendln(" url += '&A=" + a + "';");
js.appendln(" document.location = url;");
js.appendln("}");
TEST_Mod TEST = new TEST_Mod( getApplObj() );
//TEST.set_N(n);
//TEST.set_D(new java.util.Date());
TEST.set_A(a);
TEST.executeInsert();
wait(1000);
}
public void select( HTML html, E4CgiParams params )
throws E4DBException
{
TEST_Sel TEST = new TEST_Sel( getApplObj() );
//TEST.sort_N();
TEST.executeQuery();
TABLE table = html.TABLE(TABLE.E4S_DEFAULT_TABLE());
while (TEST.next())
{
TR tr = table.TR();
//tr.TD().print(TEST.get_N());
//tr.TD().print(TEST.get_D());
tr.TD().print(TEST.get_A());
}
html.HR();
menu(html);
}
public void test( HTML html, E4CgiParams params )
throws E4DBException
{
E4DBConnectionTransactional con = E4DBConnectionTransactional.getTransactionalConnection();
for( int i = 1000; i < 1100; i++ )
{
TEST_Mod TEST = new TEST_Mod( con, getApplObj() );
//TEST.set_N(i);
//TEST.set_D(new java.util.Date());
TEST.set_A("TEST");
TEST.executeInsert();
if (i == 1005)
con.commit();
if (i == 1099)
con.rollback();
wait(5 * 1000 / 100);
}
con.close();
menu(html);
}
*/
}