1 16 package org.apache.cocoon.components.language.markup.xsp; 17 18 import org.apache.avalon.excalibur.datasource.DataSourceComponent; 19 20 import java.sql.Connection ; 21 import java.sql.SQLException ; 22 import java.sql.DriverManager ; 23 24 30 31 final public class Cocoon2EsqlConnection extends AbstractEsqlConnection { 32 final private DataSourceComponent datasource; 33 private Connection connection = null; 34 35 public Cocoon2EsqlConnection() { 36 this.datasource = null; 37 this.connection = null; 38 } 39 40 44 public Cocoon2EsqlConnection( Connection connection ) { 45 this.datasource = null; 46 this.connection = connection; 47 } 48 49 53 public Cocoon2EsqlConnection( DataSourceComponent datasource ) { 54 this.datasource = datasource; 55 } 56 57 public Connection getConnection() throws SQLException { 58 if (connection != null) { 59 return(connection); 60 } 61 else { 62 if (datasource != null) { 63 connection = datasource.getConnection(); 65 } 66 else { 67 connection = DriverManager.getConnection(getURL(), getProperties()); 69 } 70 if (connection != null) { 71 return(connection); 72 } 73 else { 74 throw new SQLException ("Could not obtain connection"); 75 } 76 } 77 } 78 } 79 | Popular Tags |