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 32 import javax.naming.NamingException ; 33 34 import org.objectweb.util.monolog.api.BasicLevel; 35 36 public class Tebasic extends Tmanager { 37 38 41 public static void init() throws NamingException , RemoteException { 42 mgrInit(); 43 createTableSimple("ebasicSimpleEB"); 44 createTableSimple("ebasicSimpleEC"); 45 createTableAccount("ebasicAccountEC"); 46 createTablePerson("ebasicPersonEC"); 47 createTablePkAuto("jt2_pkautoobjectec"); 48 } 49 50 53 private static void createTableSimple(String name) throws RemoteException { 54 55 Connection conn = null; 57 try { 58 conn = dataSource.getConnection(); 59 } catch(Exception e) { 60 throw new RemoteException ("Cannot get Connection"); 61 } 62 63 Statement stmt; 64 try { 65 stmt = conn.createStatement(); 66 stmt.execute("DROP TABLE "+name); 67 stmt.close(); 68 logger.log(BasicLevel.INFO, "Table "+name+" dropped"); 69 } catch(Exception e) { 70 logger.log(BasicLevel.DEBUG, "Exception in dropTable : \n"+e); 71 } 72 try { 73 stmt = conn.createStatement(); 74 stmt.execute("create table " + name + 75 "(c_testname varchar(30) not null primary key,"+ 76 "c_info integer, c_numtest integer )"); 77 stmt.execute("insert into "+name+" values('pk1', 10, 4)"); 78 stmt.execute("insert into "+name+" values('pk2', 10, 4)"); 79 stmt.execute("insert into "+name+" values('pk3', 10, 4)"); 80 stmt.execute("insert into "+name+" values('pk4', 40, 8)"); 81 stmt.execute("insert into "+name+" values('pk5', 50, 8)"); 82 stmt.execute("insert into "+name+" values('pk6', 60, 8)"); 83 stmt.execute("insert into "+name+" values('pk7', 70, 8)"); 84 stmt.execute("insert into "+name+" values('pk8', 45, 20)"); 85 stmt.execute("insert into "+name+" values('pk9', 55, 30)"); 86 stmt.execute("insert into "+name+" values('pk10',80, 80)"); 87 stmt.execute("insert into "+name+" values('pk11',80, 80)"); 88 stmt.execute("insert into "+name+" values('pk12',90, 90)"); 89 stmt.execute("insert into "+name+" values('pk13',100, 90)"); 90 stmt.execute("insert into "+name+" values('pk14',110, 90)"); 91 92 stmt.close(); 93 conn.close(); } catch(Exception e) { 95 logger.log(BasicLevel.ERROR, "Exception in createTable : "+e); 96 throw new RemoteException ("Exception in createTable : "+e); 97 } 98 logger.log(BasicLevel.INFO, "Table "+name+" created"); 99 } 100 101 104 private static void createTableAccount(String name) throws RemoteException { 105 106 Connection conn = null; 108 try { 109 conn = dataSource.getConnection(); 110 } catch(Exception e) { 111 throw new RemoteException ("Cannot get Connection"); 112 } 113 114 Statement stmt; 115 try { 116 stmt = conn.createStatement(); 117 stmt.execute("DROP TABLE "+name); 118 stmt.close(); 119 logger.log(BasicLevel.INFO, "Table "+name+" dropped"); 120 } catch(Exception e) { 121 logger.log(BasicLevel.DEBUG, "Exception in dropTable : \n"+e); 122 } 123 try { 124 stmt = conn.createStatement(); 125 stmt.execute("create table " + name + 126 "(c_number integer not null primary key,"+ 127 " c_customer varchar(30) )"); 128 stmt.execute("insert into "+name+" values(0, 'to be removed')"); 129 stmt.execute("insert into "+name+" values(10, 'Eric')"); 130 stmt.execute("insert into "+name+" values(20, 'Helene')"); 131 stmt.execute("insert into "+name+" values(30, 'Guilhem')"); 132 stmt.execute("insert into "+name+" values(40, 'Malva')"); 133 134 stmt.close(); 135 conn.close(); } catch(Exception e) { 137 logger.log(BasicLevel.ERROR, "Exception in createTable : "+e); 138 throw new RemoteException ("Exception in createTable : "+e); 139 } 140 logger.log(BasicLevel.INFO, "Table "+name+" created"); 141 } 142 143 146 private static void createTablePerson(String name) throws RemoteException { 147 148 Connection conn = null; 150 try { 151 conn = dataSource.getConnection(); 152 } catch(Exception e) { 153 throw new RemoteException ("Cannot get Connection"); 154 } 155 156 Statement stmt; 157 try { 158 stmt = conn.createStatement(); 159 stmt.execute("DROP TABLE "+name); 160 stmt.close(); 161 logger.log(BasicLevel.INFO, "Table "+name+" dropped"); 162 } catch(Exception e) { 163 logger.log(BasicLevel.DEBUG, "Exception in dropTable : \n"+e); 164 } 165 try { 166 stmt = conn.createStatement(); 167 stmt.execute("create table " + name + 168 "(c_number integer not null primary key,"+ 169 " c_name varchar(30) )"); 170 stmt.execute("insert into "+name+" values(0, 'to be removed')"); 171 stmt.execute("insert into "+name+" values(10, 'Eric')"); 172 stmt.execute("insert into "+name+" values(20, 'Helene')"); 173 stmt.execute("insert into "+name+" values(30, 'Guilhem')"); 174 stmt.execute("insert into "+name+" values(40, 'Malva')"); 175 176 stmt.close(); 177 conn.close(); } catch(Exception e) { 179 logger.log(BasicLevel.ERROR, "Exception in createTable : "+e); 180 throw new RemoteException ("Exception in createTable : "+e); 181 } 182 logger.log(BasicLevel.INFO, "Table "+name+" created"); 183 } 184 185 188 private static void createTablePkAuto(String name) throws RemoteException { 189 190 Connection conn = null; 192 try { 193 conn = dataSource.getConnection(); 194 } catch(Exception e) { 195 throw new RemoteException ("Cannot get Connection"); 196 } 197 198 Statement stmt; 199 try { 200 stmt = conn.createStatement(); 201 stmt.execute("DROP TABLE "+name); 202 stmt.close(); 203 logger.log(BasicLevel.INFO, "Table "+name+" dropped"); 204 } catch(Exception e) { 205 logger.log(BasicLevel.DEBUG, "Exception in dropTable : \n"+e); 206 } 207 try { 208 stmt = conn.createStatement(); 209 stmt.execute("create table " + name + 210 "(c_field1 integer, c_field2 integer, pkautoincrementee integer not null primary key )"); 211 212 stmt.close(); 213 conn.close(); } catch(Exception e) { 215 logger.log(BasicLevel.ERROR, "Exception in createTable : "+e); 216 throw new RemoteException ("Exception in createTable : "+e); 217 } 218 logger.log(BasicLevel.INFO, "Table "+name+" created"); 219 } 220 221 222 } 223 | Popular Tags |