Skip to content

Instantly share code, notes, and snippets.

@maeste
Created October 14, 2009 08:07
Show Gist options
  • Save maeste/209887 to your computer and use it in GitHub Desktop.
Save maeste/209887 to your computer and use it in GitHub Desktop.
package it.lince.rivendell.connectionManagement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import oracle.jdbc.driver.OracleConnection;
import oracle.jdbc.driver.OracleDriver;
import org.jboss.resource.adapter.jdbc.WrappedConnection;
public abstract class AbstractConnectionSet
{
protected AbstractConnectionParametersSet connParams =null;
protected Connection DL =null;
protected Connection DU =null;
protected Connection DC =null;
protected Connection LYNX =null;
public AbstractConnectionSet() {}
public AbstractConnectionSet(AbstractConnectionParametersSet set) throws SQLException
{
this.connParams=set;
DriverManager.registerDriver(new OracleDriver());
}
public void setConenctionParameters(AbstractConnectionParametersSet set) throws SQLException
{
this.connParams=set;
DriverManager.registerDriver(new OracleDriver());
}
protected abstract void openDC()/* throws Exception*/;
protected abstract void openDL()/* throws Exception*/;
protected abstract void openDU()/* throws Exception*/;
protected abstract void openLYNX()/* throws Exception*/;
public Connection getDC()// throws Exception
{
if(this.DC==null) openDC();
return this.DC;
}
public Connection getDL()// throws Exception
{
if(this.DL==null) openDL();
return this.DL;
}
public Connection getDU()// throws Exception
{
if(this.DU==null) openDU();
return this.DU;
}
public Connection getLYNX()// throws Exception
{
if(this.LYNX==null) openLYNX();
return this.LYNX;
}
public boolean isDCOpen() throws SQLException
{
return this.DC!=null && !this.DC.isClosed();
}
public boolean isDLOpen() throws SQLException
{
return this.DL!=null && !this.DL.isClosed();
}
public boolean isDUOpen() throws SQLException
{
return this.DU!=null && !this.DU.isClosed();
}
public boolean isLYNXOpen() throws SQLException
{
return this.LYNX!=null && !this.LYNX.isClosed();
}
public boolean isAnyConnectionOpen() throws SQLException
{
if(this.DU !=null && !this.DU.isClosed()) return true;
if(this.DL !=null && !this.DL.isClosed()) return true;
if(this.DC !=null && !this.DC.isClosed()) return true;
if(this.LYNX!=null && !this.LYNX.isClosed()) return true;
return false;
}
/*
public void closeConnections() throws SQLException
{
if(this.DU!=null && !this.DU.isClosed())
{
this.DU.close();
this.DU=null;
}
if(this.DL!=null && !this.DL.isClosed())
{
this.DL.close();
this.DL=null;
}
if(this.DC!=null && !this.DC.isClosed())
{
this.DC.close();
this.DC=null;
}
if(this.LYNX!=null && !this.LYNX.isClosed())
{
this.LYNX.close();
this.LYNX=null;
}
}
*/
public OracleConnection getDCOracle() throws Exception
{
return extractOracleConnection(getDC());
}
public OracleConnection getDLOracle() throws Exception
{
return extractOracleConnection(getDL());
}
public OracleConnection getDUOracle() throws Exception
{
return extractOracleConnection(getDU());
}
public OracleConnection getLYNXOracle() throws Exception
{
return extractOracleConnection(getLYNX());
}
private static OracleConnection extractOracleConnection(Connection cnn) throws SQLException
{
if(cnn instanceof WrappedConnection) cnn = ((WrappedConnection)cnn).getUnderlyingConnection();
return (OracleConnection)cnn;
}
}
public ManagementScoreObj loadManagementScore(Long idLince) throws CustomException
{
DefaultConnectionSet dcs=null;
try
{
dcs=DefaultConnectionSet.getInstance();
ProduttoreManagementScore produttoreManagementScore = new ProduttoreManagementScore(dcs);
return produttoreManagementScore.leggiManagementScore(idLince);
}
catch(Exception e)
{
Logger.getLogger(getClass()).error(this,e);
throw new CustomException(e.getMessage());
}
finally
{
try {DefaultConnectionSet.releaseInstance(dcs);}
catch(Exception e) {}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment