1 25 26 package org.objectweb.jonas.jtests.tables; 27 28 import java.rmi.RemoteException ; 29 import java.sql.Connection ; 30 import java.sql.Statement ; 31 import javax.naming.NamingException ; 32 import org.objectweb.util.monolog.api.BasicLevel; 33 34 38 39 public class Trcycle extends Tmanager { 40 41 46 public static void init() throws NamingException , RemoteException { 47 mgrInit(); 48 createTables(); 49 } 50 51 55 private static void createTables() throws RemoteException { 56 57 Connection conn = null; 59 try { 60 conn = dataSource.getConnection(); 61 } catch (Exception e) { 62 throw new RemoteException ("Cannot get Connection"); 63 } 64 65 Statement stmt; 66 String personTname = "JT2_RCYCLE_PERSON"; 68 String jointTname = "JT2_RCYCLE_J_PAR_CHILD"; 70 try { 71 stmt = conn.createStatement(); 72 stmt.execute("DROP TABLE " + personTname); 73 logger.log(BasicLevel.INFO, "Table " + personTname + " dropped"); 74 stmt.execute("DROP TABLE " + jointTname); 75 logger.log(BasicLevel.INFO, "Table " + jointTname + " dropped"); 76 stmt.close(); 77 } catch (Exception e) { 78 logger.log(BasicLevel.DEBUG, "Exception in drop Tables : " + e); 79 } 80 try { 81 stmt = conn.createStatement(); 83 stmt.execute("create table " + personTname 84 + "(c_id integer not null primary key," 85 + " c_name varchar(40)," 86 + " c_sex integer," 87 + " cfk_spouse integer," 88 + " cfk_guardian integer)"); 89 stmt.execute("insert into " + personTname + " values(1, 'Laurent Eric', 1, 2, null)"); 90 stmt.execute("insert into " + personTname + " values(2, 'Joanin-Laurent Helene', 2, 1, null)"); 91 stmt.execute("insert into " + personTname + " values(3, 'Laurent Guilhem', 1, null, 1)"); 92 stmt.execute("insert into " + personTname + " values(4, 'Laurent Malva', 2, null, 1)"); 93 logger.log(BasicLevel.INFO, "Table " + personTname + " created"); 94 stmt.execute("create table " + jointTname 96 + "(cfk_parents integer," 97 + " cfk_children integer)"); 98 stmt.execute("insert into " + jointTname + " values(1, 3)"); 99 stmt.execute("insert into " + jointTname + " values(1, 4)"); 100 stmt.execute("insert into " + jointTname + " values(2, 3)"); 101 stmt.execute("insert into " + jointTname + " values(2, 4)"); 102 logger.log(BasicLevel.INFO, "Table " + jointTname + " created"); 103 stmt.close(); 104 conn.close(); } catch (Exception e) { 106 logger.log(BasicLevel.ERROR, "Exception in create Table : " + e); 107 throw new RemoteException ("Exception in create Table : " + e); 108 } 109 } 110 111 } 112 113 114 | Popular Tags |