All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.alterioncorp.perfjdbc.io.PerfWriter Maven / Gradle / Ivy

Go to download

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.io;

import java.io.IOException;
import java.io.Writer;

import com.alterioncorp.perfjdbc.PerfProxy;
import com.alterioncorp.perfjdbc.StopWatch;

public class PerfWriter extends Writer implements PerfProxy {

	private final Writer target;
	
	public PerfWriter(Writer target) {
		super();
		this.target = target;
	}

	@Override
	public void flush() throws IOException {
		StopWatch.start();
		try {
			target.flush();
		}
		finally {
			StopWatch.stop();
		}
	}

	@Override
	public void close() throws IOException {
		StopWatch.start();
		try {
			target.close();
		}
		finally {
			StopWatch.stop();
		}
	}

	@Override
	public void write(char[] cbuf, int off, int len) throws IOException {
		StopWatch.start();
		try {
			target.write(cbuf, off, len);
		}
		finally {
			StopWatch.stop();
		}
	}

	@Override
	public void write(int c) throws IOException {
		StopWatch.start();
		try {
			target.write(c);
		}
		finally {
			StopWatch.stop();
		}
	}

	@Override
	public void write(char[] cbuf) throws IOException {
		StopWatch.start();
		try {
			target.write(cbuf);
		}
		finally {
			StopWatch.stop();
		}
	}

	@Override
	public void write(String str) throws IOException {
		StopWatch.start();
		try {
			target.write(str);
		}
		finally {
			StopWatch.stop();
		}
	}

	@Override
	public void write(String str, int off, int len) throws IOException {
		StopWatch.start();
		try {
			target.write(str, off, len);
		}
		finally {
			StopWatch.stop();
		}
	}

	@Override
	public Writer append(CharSequence csq) throws IOException {
		StopWatch.start();
		try {
			Writer out = target.append(csq);
			if (out == target) {
				out = this;
			}
			else if (! (out instanceof PerfProxy)) {
				out = new PerfWriter(target);
			}
			return out;
		}
		finally {
			StopWatch.stop();
		}
	}

	@Override
	public Writer append(CharSequence csq, int start, int end)
			throws IOException {
		StopWatch.start();
		try {
			Writer out = target.append(csq, start, end);
			if (out == target) {
				out = this;
			}
			else if (! (out instanceof PerfProxy)) {
				out = new PerfWriter(target);
			}
			return out;
		}
		finally {
			StopWatch.stop();
		}
	}

	@Override
	public Writer append(char c) throws IOException {
		StopWatch.start();
		try {
			Writer out = target.append(c);
			if (out == target) {
				out = this;
			}
			else if (! (out instanceof PerfProxy)) {
				out = new PerfWriter(target);
			}
			return out;
		}
		finally {
			StopWatch.stop();
		}
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy