package eu.dnetlib.sesame.xapool;

import java.sql.Array;
import java.sql.Blob;
import java.sql.CallableStatement;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.NClob;
import java.sql.PreparedStatement;
import java.sql.SQLClientInfoException;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.SQLXML;
import java.sql.Savepoint;
import java.sql.Statement;
import java.sql.Struct;
import java.util.Map;
import java.util.Properties;

import org.openrdf.repository.RepositoryConnection;
import org.openrdf.repository.RepositoryException;

/**
 * Connection implementation.
 * 
 * @author lexis
 */
public class ConnectionSesame implements Connection {

	/** Connection to a Sesame tripelstore. */
	private RepositoryConnection repositoryConnection;

	public RepositoryConnection getRepositoryConnection() {
		return this.repositoryConnection;
	}

	public void setRepositoryConnection(final RepositoryConnection repositoryConnection) {
		this.repositoryConnection = repositoryConnection;
	}

	/** No args constructor. */
	public ConnectionSesame() {
		//do nothing
	}

	/**
	 * Constructor.
	 * 
	 * @param con
	 *            RepositoryConnection instance to wrap in this ConnectionSesame object.
	 */
	public ConnectionSesame(final RepositoryConnection con) {
		this.repositoryConnection = con;
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#clearWarnings()
	 */
	public void clearWarnings() throws SQLException {
		//do nothing
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#close()
	 */
	public void close() throws SQLException {
		if (this.repositoryConnection != null) {
			try {
				this.repositoryConnection.close();
			} catch (RepositoryException e) {
				throw new SQLException(e);
			}
		}
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#commit()
	 */
	public void commit() throws SQLException {
		try {
			this.repositoryConnection.commit();
		} catch (RepositoryException e) {
			throw new SQLException(e);
		}
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#createArrayOf(java.lang.String, java.lang.Object[])
	 */
	public Array createArrayOf(final String typeName, final Object[] elements) throws SQLException {
		throw new SQLException();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#createBlob()
	 */
	public Blob createBlob() throws SQLException {
		throw new SQLException();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#createClob()
	 */
	public Clob createClob() throws SQLException {
		throw new SQLException();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#createNClob()
	 */
	public NClob createNClob() throws SQLException {
		throw new SQLException();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#createSQLXML()
	 */
	public SQLXML createSQLXML() throws SQLException {
		throw new SQLException();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#createStatement()
	 */
	public Statement createStatement() throws SQLException {
		throw new SQLException();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#createStatement(int, int)
	 */
	public Statement createStatement(final int resultSetType, final int resultSetConcurrency) throws SQLException {
		throw new SQLException();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#createStatement(int, int, int)
	 */
	public Statement createStatement(final int resultSetType, final int resultSetConcurrency, final int resultSetHoldability) throws SQLException {
		throw new SQLException();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#createStruct(java.lang.String, java.lang.Object[])
	 */
	public Struct createStruct(final String typeName, final Object[] attributes) throws SQLException {
		throw new SQLException();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#getAutoCommit()
	 */
	public boolean getAutoCommit() throws SQLException {
		try {
			return this.repositoryConnection.isAutoCommit();
		} catch (RepositoryException e) {
			throw new SQLException(e);
		}
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#getCatalog()
	 */
	public String getCatalog() throws SQLException {
		throw new SQLException();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#getClientInfo()
	 */
	public Properties getClientInfo() throws SQLException {
		throw new SQLException();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#getClientInfo(java.lang.String)
	 */
	public String getClientInfo(final String name) throws SQLException {
		throw new SQLException();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#getHoldability()
	 */
	public int getHoldability() throws SQLException {
		throw new SQLException();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#getMetaData()
	 */
	public DatabaseMetaData getMetaData() throws SQLException {
		throw new SQLException();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#getTransactionIsolation()
	 */
	public int getTransactionIsolation() throws SQLException {
		throw new SQLException();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#getTypeMap()
	 */
	public Map<String, Class<?>> getTypeMap() throws SQLException {
		throw new SQLException();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#getWarnings()
	 */
	public SQLWarning getWarnings() throws SQLException {
		throw new SQLException();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#isClosed()
	 */
	public boolean isClosed() throws SQLException {
		try {
			return !this.repositoryConnection.isOpen();
		} catch (RepositoryException e) {
			throw new SQLException(e);
		}
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#isReadOnly()
	 */
	public boolean isReadOnly() throws SQLException {
		try {
			return !this.repositoryConnection.getRepository().isWritable();
		} catch (RepositoryException e) {
			throw new SQLException(e);
		}
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#isValid(int)
	 */
	public boolean isValid(final int timeout) throws SQLException {
		throw new SQLException();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#nativeSQL(java.lang.String)
	 */
	public String nativeSQL(final String sql) throws SQLException {
		throw new SQLException();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#prepareCall(java.lang.String)
	 */
	public CallableStatement prepareCall(final String sql) throws SQLException {
		throw new SQLException();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#prepareCall(java.lang.String, int, int)
	 */
	public CallableStatement prepareCall(final String sql, final int resultSetType, final int resultSetConcurrency) throws SQLException {
		throw new SQLException();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#prepareCall(java.lang.String, int, int, int)
	 */
	public CallableStatement prepareCall(final String sql, final int resultSetType, final int resultSetConcurrency, final int resultSetHoldability)
			throws SQLException {
		throw new SQLException();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#prepareStatement(java.lang.String)
	 */
	public PreparedStatement prepareStatement(final String sql) throws SQLException {
		throw new SQLException();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#prepareStatement(java.lang.String, int)
	 */
	public PreparedStatement prepareStatement(final String sql, final int autoGeneratedKeys) throws SQLException {
		throw new SQLException();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#prepareStatement(java.lang.String, int[])
	 */
	public PreparedStatement prepareStatement(final String sql, final int[] columnIndexes) throws SQLException {
		throw new SQLException();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#prepareStatement(java.lang.String, java.lang.String[])
	 */
	public PreparedStatement prepareStatement(final String sql, final String[] columnNames) throws SQLException {
		throw new SQLException();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#prepareStatement(java.lang.String, int, int)
	 */
	public PreparedStatement prepareStatement(final String sql, final int resultSetType, final int resultSetConcurrency) throws SQLException {
		throw new SQLException();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#prepareStatement(java.lang.String, int, int, int)
	 */
	public PreparedStatement prepareStatement(final String sql, final int resultSetType, final int resultSetConcurrency, final int resultSetHoldability)
			throws SQLException {
		throw new SQLException();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#releaseSavepoint(java.sql.Savepoint)
	 */
	public void releaseSavepoint(final Savepoint savepoint) throws SQLException {
		throw new SQLException();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#rollback()
	 */
	public void rollback() throws SQLException {
		try {
			this.repositoryConnection.rollback();
		} catch (RepositoryException e) {
			throw new SQLException(e);
		}
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#rollback(java.sql.Savepoint)
	 */
	public void rollback(final Savepoint savepoint) throws SQLException {
		throw new SQLException();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#setAutoCommit(boolean)
	 */
	public void setAutoCommit(final boolean autoCommit) throws SQLException {
		try {
			this.repositoryConnection.setAutoCommit(autoCommit);
		} catch (RepositoryException e) {
			throw new SQLException(e);
		}
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#setCatalog(java.lang.String)
	 */
	public void setCatalog(final String catalog) throws SQLException {
		throw new SQLException();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#setClientInfo(java.util.Properties)
	 */
	public void setClientInfo(final Properties properties) throws SQLClientInfoException {
		throw new SQLClientInfoException();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#setClientInfo(java.lang.String, java.lang.String)
	 */
	public void setClientInfo(final String name, final String value) throws SQLClientInfoException {
		throw new SQLClientInfoException();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#setHoldability(int)
	 */
	public void setHoldability(final int holdability) throws SQLException {
		throw new SQLException();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#setReadOnly(boolean)
	 */
	public void setReadOnly(final boolean readOnly) throws SQLException {
		throw new SQLException();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#setSavepoint()
	 */
	public Savepoint setSavepoint() throws SQLException {
		throw new SQLException();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#setSavepoint(java.lang.String)
	 */
	public Savepoint setSavepoint(final String name) throws SQLException {
		throw new SQLException();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#setTransactionIsolation(int)
	 */
	public void setTransactionIsolation(final int level) throws SQLException {
		throw new SQLException();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Connection#setTypeMap(java.util.Map)
	 */
	public void setTypeMap(final Map<String, Class<?>> map) throws SQLException {
		throw new SQLException();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Wrapper#isWrapperFor(java.lang.Class)
	 */
	public boolean isWrapperFor(final Class<?> arg0) throws SQLException {
		throw new SQLException();
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see java.sql.Wrapper#unwrap(java.lang.Class)
	 */
	public <T> T unwrap(final Class<T> arg0) throws SQLException {
		throw new SQLException();
	}

}
