1 4 package org.ofbiz.minerva.pool.jdbc; 5 6 import java.sql.*; 7 import java.util.Properties ; 8 9 import javax.sql.DataSource ; 10 11 29 public class PoolDriver implements Driver { 30 31 private final static String URL_START = "jdbc:minerva:"; 32 private final static PoolDriver instance; 33 34 static { 35 instance = new PoolDriver(); 36 try { 37 DriverManager.registerDriver(PoolDriver.instance()); 38 } catch (SQLException e) { 39 System.out.println("Unable to register Minerva DB pool driver!"); 40 e.printStackTrace(); 41 } 42 } 43 44 47 public static PoolDriver instance() { 48 return instance; 49 } 50 51 private PoolDriver() { 52 } 53 54 57 public boolean acceptsURL(String url) throws java.sql.SQLException { 58 return url.startsWith(URL_START); 59 } 60 61 64 public Connection connect(String url, Properties props) throws java.sql.SQLException { 65 if (url.startsWith(URL_START)) { 66 return getJDBCConnection(url.substring(URL_START.length())); 67 } 68 return null; } 70 71 private Connection getJDBCConnection(String name) { 72 Connection con = null; 73 try { 74 DataSource source = JDBCPoolDataSource.getDataSource(name); 75 if (source != null) 76 con = source.getConnection(); 77 } catch (Exception e) { 78 e.printStackTrace(); 79 } 80 return con; 81 } 82 83 86 public int getMajorVersion() { 87 return 2; 88 } 89 90 93 public int getMinorVersion() { 94 return 0; 95 } 96 97 101 public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException { 102 return new DriverPropertyInfo[0]; 103 } 104 105 109 public boolean jdbcCompliant() { 110 return false; 111 } 112 } 113 | Popular Tags |