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 Tlcp 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 try { 67 stmt = conn.createStatement(); 68 stmt.execute("DROP TABLE JT2_SIMPLEPARENT"); 69 logger.log(BasicLevel.INFO, "Table JT2_SIMPLEPARENT dropped"); 70 stmt.execute("DROP TABLE JT2_SIMPLECHILD"); 71 logger.log(BasicLevel.INFO, "Table JT2_SIMPLECHILD dropped"); 72 stmt.close(); 73 } catch (Exception e) { 74 logger.log(BasicLevel.DEBUG, "Exception in drop Tables : " + e); 75 } 76 try { 77 stmt = conn.createStatement(); 79 String tname = "JT2_SIMPLEPARENT"; 80 stmt.execute("create table " + tname 81 + "(SP_PK_ID VARCHAR(32) NOT NULL," 82 + " SP_DESC VARCHAR(32)," 83 + " PRIMARY KEY (SP_PK_ID))"); 84 stmt.execute("insert into " + tname + " values('p0', 'p0')"); 85 stmt.execute("insert into " + tname + " values('p1', 'p1')"); 86 stmt.execute("insert into " + tname + " values('p2', 'p2')"); 87 logger.log(BasicLevel.INFO, "Table " + tname + " created"); 88 tname = "JT2_SIMPLECHILD"; 90 stmt.execute("create table " + tname 91 + "(SC_PK_ID VARCHAR(32) NOT NULL," 92 + "SP_FK_ID VARCHAR(32)," 93 + "SC_DESC VARCHAR(32)," 94 + "PRIMARY KEY (SC_PK_ID))"); 95 stmt.execute("insert into " + tname + " values('c0', NULL, 'c0')"); 96 stmt.execute("insert into " + tname + " values('c1_1', 'p1', 'c1_1')"); 97 stmt.execute("insert into " + tname + " values('c1_2', 'p1', 'c1_2')"); 98 stmt.execute("insert into " + tname + " values('c2_1', 'p2', 'c2_1')"); 99 stmt.execute("insert into " + tname + " values('c2_2', 'p2', 'c2_2')"); 100 logger.log(BasicLevel.INFO, "Table " + tname + " created"); 101 stmt.close(); 102 conn.close(); } catch (Exception e) { 104 logger.log(BasicLevel.ERROR, "Exception in create Table : " + e); 105 throw new RemoteException ("Exception in create Table : " + e); 106 } 107 } 108 109 } 110 111 112 | Popular Tags |