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.jonas.jtests.util.Env; 35 import org.objectweb.util.monolog.api.BasicLevel; 36 37 41 public class Toboolean extends Tmanager { 42 43 46 public static void init() throws NamingException , RemoteException { 47 mgrInit(); 48 createTable("JT_EtypeObooleanEC"); 49 } 50 51 54 private static void createTable(String name) throws RemoteException { 55 56 Connection conn = null; 58 try { 59 conn = dataSource.getConnection(); 60 } catch(Exception e) { 61 throw new RemoteException ("Cannot get Connection"); 62 } 63 64 Statement stmt; 65 try { 66 stmt = conn.createStatement(); 67 stmt.execute("DROP TABLE "+name); 68 stmt.close(); 69 logger.log(BasicLevel.INFO, "Table "+name+" dropped"); 70 } catch(Exception e) { 71 logger.log(BasicLevel.DEBUG, "Exception in dropTable : \n"+e); 72 } 73 try { 74 int dbType = Env.getDatabaseType(conn); 75 String cTypeName; 76 switch (dbType) { 77 case Env.DB_ORACLE: cTypeName = "number"; break; 78 case Env.DB_POSGRESQL: cTypeName = "boolean"; break; 79 default: cTypeName = "bit"; } 81 stmt = conn.createStatement(); 82 stmt.execute("create table " + name + 83 "( c_pk varchar(30) not null primary key, c_f1 "+cTypeName+")"); 84 if ((dbType == Env.DB_ORACLE) || (dbType == Env.DB_MYSQL)) { 85 stmt.execute("insert into "+name+" values('pk1', 0)"); 86 stmt.execute("insert into "+name+" values('pk2', 1)"); 87 stmt.execute("insert into "+name+" values('pk3', 0)"); 88 stmt.execute("insert into "+name+" values('pk4', 1)"); 89 stmt.execute("insert into "+name+" values('pk5', 0)"); 90 stmt.execute("insert into "+name+" values('pktoremove', 1)"); 91 stmt.execute("insert into "+name+" values('pknull', NULL)"); 92 stmt.execute("insert into "+name+" values('pkchangenull', 1)"); 93 } else { 94 stmt.execute("insert into "+name+" values('pk1', 'false')"); 95 stmt.execute("insert into "+name+" values('pk2', 'true')"); 96 stmt.execute("insert into "+name+" values('pk3', 'false')"); 97 stmt.execute("insert into "+name+" values('pk4', 'true')"); 98 stmt.execute("insert into "+name+" values('pk5', 'false')"); 99 stmt.execute("insert into "+name+" values('pktoremove', 'true')"); 100 stmt.execute("insert into "+name+" values('pknull', NULL)"); 101 stmt.execute("insert into "+name+" values('pkchangenull', 'true')"); 102 } 103 stmt.close(); 104 conn.close(); } catch(Exception e) { 106 logger.log(BasicLevel.ERROR, "Exception in createTable : "+e); 107 throw new RemoteException ("Exception in createTable : "+e); 108 } 109 logger.log(BasicLevel.INFO, "Table "+name+" created"); 110 } 111 112 } 113 | Popular Tags |