
com.alterioncorp.perfjdbc.sql.PerfCommonDataSource Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of perf-jdbc Show documentation
Show all versions of perf-jdbc Show documentation
Wrapper JDBC driver that monitors time spent inside JDBC code by thread.
JDBC driver URL:
jdbc:alterion:perf://class=<TARGET_DRIVER_CLASS>|url=<TARGET_JDBC_URL>
To get the time in millis spent inside JDBC for thread:
StopWatch.getTime()
The newest version!
package com.alterioncorp.perfjdbc.sql;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.logging.Logger;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.CommonDataSource;
import com.alterioncorp.perfjdbc.PerfProxy;
import com.alterioncorp.perfjdbc.StopWatch;
public abstract class PerfCommonDataSource implements CommonDataSource, PerfProxy {
private CommonDataSource targetDataSource;
private String targetJndi;
public PerfCommonDataSource() {
super();
}
public PerfCommonDataSource(CommonDataSource targetDataSource) {
super();
this.targetDataSource = targetDataSource;
}
public PerfCommonDataSource(String targetJndi) {
super();
this.targetJndi = targetJndi;
}
@Override
public PrintWriter getLogWriter() throws SQLException {
StopWatch.start();
try {
return this.getTargetCommonDataSource().getLogWriter();
}
finally {
StopWatch.stop();
}
}
@Override
public void setLogWriter(PrintWriter out) throws SQLException {
StopWatch.start();
try {
this.getTargetCommonDataSource().setLogWriter(out);
}
finally {
StopWatch.stop();
}
}
@Override
public int getLoginTimeout() throws SQLException {
StopWatch.start();
try {
return this.getTargetCommonDataSource().getLoginTimeout();
}
finally {
StopWatch.stop();
}
}
@Override
public void setLoginTimeout(int seconds) throws SQLException {
StopWatch.start();
try {
this.getTargetCommonDataSource().setLoginTimeout(seconds);
}
finally {
StopWatch.stop();
}
}
@Override
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
StopWatch.start();
try {
return this.getTargetCommonDataSource().getParentLogger();
}
finally {
StopWatch.stop();
}
}
public String getTargetJndi() {
return targetJndi;
}
public void setTargetJndi(String targetJndi) {
this.targetJndi = targetJndi;
}
protected final CommonDataSource getTargetCommonDataSource() {
if (targetDataSource == null) {
try {
InitialContext initialContext = new InitialContext();
targetDataSource = (CommonDataSource)initialContext.lookup(targetJndi);
}
catch (NamingException e) {
throw new RuntimeException(e);
}
}
return targetDataSource;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy