1 4 package org.ofbiz.minerva.pool.jdbc.xa; 5 6 import java.sql.Connection ; 7 import java.sql.Driver ; 8 import java.sql.DriverManager ; 9 import java.sql.DriverPropertyInfo ; 10 import java.sql.SQLException ; 11 import java.util.Properties ; 12 13 import javax.sql.DataSource ; 14 15 import org.apache.log4j.Logger; 16 17 33 34 public class XAPoolDriver implements Driver { 35 36 private final static Logger log = Logger.getLogger(XAPoolDriver.class); 37 private final static String URL_START = "jdbc:minerva:xa:"; 38 private final static XAPoolDriver instance; 39 40 static { 41 instance = new XAPoolDriver(); 42 try { 43 DriverManager.registerDriver(XAPoolDriver.instance()); 44 } catch (SQLException e) { 45 log.error("Unable to register Minerva XA DB pool driver!", e); 46 } 47 } 48 49 52 public static XAPoolDriver instance() { 53 return instance; 54 } 55 56 private XAPoolDriver() { 57 } 58 59 62 public boolean acceptsURL(String url) throws java.sql.SQLException { 63 return url.startsWith(URL_START); 64 } 65 66 69 public Connection connect(String url, Properties props) throws java.sql.SQLException { 70 if (url.startsWith(URL_START)) { 71 return getXAConnection(url.substring(URL_START.length())); 72 } 73 return null; } 75 76 private Connection getXAConnection(String name) { 77 Connection con = null; 78 try { 79 DataSource source = XAPoolDataSource.getDataSource(name); 80 if (source != null) 81 con = source.getConnection(); 82 } catch (Exception e) { 83 log.error("Can't get DataSource from XAPool", e); 84 } 85 return con; 86 } 87 88 91 public int getMajorVersion() { 92 return 2; 93 } 94 95 98 public int getMinorVersion() { 99 return 0; 100 } 101 102 106 public DriverPropertyInfo [] getPropertyInfo(String url, Properties info) throws SQLException { 107 return new DriverPropertyInfo [0]; 108 } 109 110 114 public boolean jdbcCompliant() { 115 return false; 116 } 117 } 118 119 122 | Popular Tags |