1 25 26 package org.objectweb.jonas.jtests.tables; 27 28 import java.rmi.RemoteException ; 29 import java.sql.Connection ; 30 import java.sql.PreparedStatement ; 31 import java.sql.Statement ; 32 import java.sql.Timestamp ; 33 34 import javax.naming.NamingException ; 35 36 import org.objectweb.jonas.jtests.util.Env; 37 import org.objectweb.util.monolog.api.BasicLevel; 38 39 43 public class Tosqlts extends Tmanager { 44 45 48 public static void init() throws NamingException , RemoteException { 49 mgrInit(); 50 createTable("JT_EtypeOsqltsEC"); 51 } 52 53 56 private static void createTable(String name) throws RemoteException { 57 58 Connection conn = null; 60 try { 61 conn = dataSource.getConnection(); 62 } catch(Exception e) { 63 throw new RemoteException ("Cannot get Connection"); 64 } 65 66 Statement stmt; 67 PreparedStatement pStmt; 68 try { 69 stmt = conn.createStatement(); 70 stmt.execute("DROP TABLE "+name); 71 stmt.close(); 72 logger.log(BasicLevel.INFO, "Table "+name+" dropped"); 73 } catch(Exception e) { 74 logger.log(BasicLevel.DEBUG, "Exception in dropTable : \n"+e); 75 } 76 try { 77 int dbType = Env.getDatabaseType(conn); 78 String cTypeName; 79 switch (dbType) { 80 case Env.DB_ORACLE: cTypeName = "date"; break; 81 default: cTypeName = "timestamp"; } 83 stmt = conn.createStatement(); 84 stmt.execute("create table " + name + 85 "( c_pk varchar(30) not null primary key, c_f1 "+cTypeName+")"); 86 stmt.close(); 87 final long ONE_DAY = 24L*60L*60L*1000L; 88 pStmt = conn.prepareStatement("insert into "+name+" values('pk1', ?)"); 89 pStmt.setTimestamp(1, new Timestamp (ONE_DAY)); 90 pStmt.executeUpdate(); 91 pStmt.close(); 92 pStmt = conn.prepareStatement("insert into "+name+" values('pk2', ?)"); 93 pStmt.setTimestamp(1, new Timestamp (2*ONE_DAY)); 94 pStmt.executeUpdate(); 95 pStmt.close(); 96 pStmt = conn.prepareStatement("insert into "+name+" values('pk3', ?)"); 97 pStmt.setTimestamp(1, new Timestamp (3*ONE_DAY)); 98 pStmt.executeUpdate(); 99 pStmt.close(); 100 pStmt = conn.prepareStatement("insert into "+name+" values('pk4', ?)"); 101 pStmt.setTimestamp(1, new Timestamp (4*ONE_DAY)); 102 pStmt.executeUpdate(); 103 pStmt.close(); 104 pStmt = conn.prepareStatement("insert into "+name+" values('pk5', ?)"); 105 pStmt.setTimestamp(1, new Timestamp (5*ONE_DAY)); 106 pStmt.executeUpdate(); 107 pStmt.close(); 108 pStmt = conn.prepareStatement("insert into "+name+" values('pk5bis', ?)"); 109 pStmt.setTimestamp(1, new Timestamp (5*ONE_DAY)); 110 pStmt.executeUpdate(); 111 pStmt.close(); 112 pStmt = conn.prepareStatement("insert into "+name+" values('pktoremove', ?)"); 113 pStmt.setTimestamp(1, new Timestamp (12*ONE_DAY)); 114 pStmt.executeUpdate(); 115 pStmt.close(); 116 pStmt = conn.prepareStatement("insert into "+name+" values('pknull', NULL)"); 117 pStmt.executeUpdate(); 118 pStmt.close(); 119 pStmt = conn.prepareStatement("insert into "+name+" values('pkchangenull', ?)"); 120 pStmt.setTimestamp(1, new Timestamp (12*ONE_DAY)); 121 pStmt.executeUpdate(); 122 pStmt.close(); 123 conn.close(); } catch(Exception e) { 125 logger.log(BasicLevel.ERROR, "Exception in createTable : "+e); 126 throw new RemoteException ("Exception in createTable : "+e); 127 } 128 logger.log(BasicLevel.INFO, "Table "+name+" created"); 129 } 130 131 } 132 | Popular Tags |