1 23 24 package org.objectweb.jorm.runtime; 25 26 import org.objectweb.jorm.naming.api.PBinder; 27 import org.objectweb.jorm.api.PException; 28 import org.objectweb.util.monolog.api.BasicLevel; 29 30 import java.sql.Connection ; 31 import java.sql.ResultSet ; 32 import java.sql.SQLException ; 33 import java.util.ArrayList ; 34 35 38 public class TestJdbcConnection extends TestRuntimeHelper { 39 40 protected String getLoggerName() { 41 return null; 42 } 43 44 protected PBinder getBinder(String className) throws Exception { 45 return null; 46 } 47 48 public TestJdbcConnection(String s) throws Exception { 49 super(s); 50 } 51 public void testGetConnection() throws Exception { 52 mapper.closeConnection(mapper.getConnection()); 53 } 54 55 public void testExistingTable() throws Exception { 56 Connection connection = (Connection ) mapper.getConnection(); 57 String name = "JT_EXISTING_TABLE"; 58 try { 59 connection.createStatement().execute("DROP TABLE " + name); 60 } catch (SQLException e) { 61 } 62 logger.log(BasicLevel.DEBUG, "create the table: " + name); 63 connection.createStatement().execute( 64 "CREATE TABLE " + name + " (f1 INTEGER)"); 65 ResultSet rs = null; 66 boolean existtable = false; 67 logger.log(BasicLevel.DEBUG, "Search the table: " + name); 68 ArrayList tables = new ArrayList (1); 69 try { 70 rs = connection.getMetaData() 71 .getTables(null, null, null, null); 72 String current = null; 73 while (rs.next() && !existtable) { 74 current = rs.getString(3); 75 logger.log(BasicLevel.DEBUG, "found: " + current); 76 logger.log(BasicLevel.DEBUG, "1: " + current); 77 tables.add(current); 78 existtable = name.equalsIgnoreCase(current); 79 } 80 } catch (SQLException e) { 81 throw new PException(e, "Pb while testing the existence of table " + name); 82 } finally { 83 if (rs != null) { 84 try { 85 rs.close(); 86 } catch (SQLException e) { 87 } 88 } 89 } 90 connection.createStatement().execute("DROP TABLE " + name); 91 assertTrue("The table "+ name + " was not found in " + tables, existtable); 92 } 93 94 95 } 96 | Popular Tags |