de.akquinet.jbosscc.guttenbase.export.ExportDumpConnection Maven / Gradle / Ivy
The newest version!
package de.akquinet.jbosscc.guttenbase.export;
import de.akquinet.jbosscc.guttenbase.exceptions.ExportException;
import de.akquinet.jbosscc.guttenbase.meta.TableMetaData;
import java.sql.*;
import java.util.HashSet;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.Executor;
/**
* Special "{@link Connection}" that supports writing data to a different storage then a data base. I.e., a file dump. Only few
* inherited methods have a meaningful implementation, most methods will throw a {@link UnsupportedOperationException}.
*
* © 2012-2034 akquinet tech@spree
*
*
* @author M. Dahm
*/
public class ExportDumpConnection implements Connection {
private final Exporter _exporter;
private boolean _closed;
private final Set _exportedTables = new HashSet<>();
private TableMetaData _currentTableMetaData;
public ExportDumpConnection(final Exporter exporter) {
assert exporter != null : "exporter != null";
_exporter = exporter;
}
/**
* Returns PreparedStatement object for export. {@inheritDoc}
*/
@Override
public PreparedStatement prepareStatement(final String sql) {
// Write header only once
if (_exportedTables.add(_currentTableMetaData)) {
writeTableHeader(_currentTableMetaData);
}
return new ExportDumpPreparedStatement(_exporter);
}
/**
* Simply forwards call to {@link Exporter}.
*/
public void initializeWriteTableData(final TableMetaData table) throws ExportException {
assert table != null : "table != null";
_currentTableMetaData = table;
try {
_exporter.initializeWriteTableData(table);
} catch (final Exception e) {
throw new ExportException("initializeWriteTableData", e);
}
}
/**
* Simply forwards call to {@link Exporter}.
*/
public void finalizeWriteTableData(final TableMetaData table) throws ExportException {
_currentTableMetaData = null;
try {
_exporter.finalizeWriteTableData(table);
} catch (final Exception e) {
throw new ExportException("finalizeWriteTableData", e);
}
}
public void initializeWriteRowData(final TableMetaData table) throws ExportException {
try {
_exporter.initializeWriteRowData(table);
} catch (final Exception e) {
throw new ExportException("initializeWriteRowData", e);
}
}
public void finalizeWriteRowData(final TableMetaData table) throws ExportException {
try {
_exporter.finalizeWriteRowData(table);
} catch (final Exception e) {
throw new ExportException("finalizeWriteRowData", e);
}
}
/**
* Simply forwards call to {@link Exporter} which will close any open resources.
*/
@Override
public void close() {
try {
_exporter.finishExport();
} catch (final Exception e) {
throw new ExportException("close", e);
} finally {
_closed = true;
_exportedTables.clear();
}
}
/**
* Simply forwards call to {@link Exporter} which may then flush its buffers.
*/
@Override
public void commit() {
try {
_exporter.flush();
} catch (final Exception e) {
throw new ExportException("commit", e);
}
}
/**
* {@inheritDoc}
*/
@Override
public boolean isClosed() {
return _closed;
}
@Override
public void setAutoCommit(final boolean autoCommit) {
}
@Override
public boolean getAutoCommit() {
return false;
}
@Override
public void setReadOnly(final boolean readOnly) {
}
@Override
public boolean isReadOnly() {
return false;
}
@Override
public void rollback() {
}
@Override
public PreparedStatement prepareStatement(final String sql, final int autoGeneratedKeys) {
return prepareStatement(sql);
}
@Override
public PreparedStatement prepareStatement(final String sql, final int[] columnIndexes) {
return prepareStatement(sql);
}
@Override
public PreparedStatement prepareStatement(final String sql, final String[] columnNames) {
return prepareStatement(sql);
}
@Override
public Statement createStatement() {
return prepareStatement("");
}
@Override
public T unwrap(final Class iface) {
throw new UnsupportedOperationException();
}
@Override
public boolean isWrapperFor(final Class> iface) {
throw new UnsupportedOperationException();
}
@Override
public CallableStatement prepareCall(final String sql) {
throw new UnsupportedOperationException();
}
@Override
public String nativeSQL(final String sql) {
throw new UnsupportedOperationException();
}
@Override
public DatabaseMetaData getMetaData() {
throw new UnsupportedOperationException();
}
@Override
public void setCatalog(final String catalog) {
throw new UnsupportedOperationException();
}
@Override
public String getCatalog() {
throw new UnsupportedOperationException();
}
@Override
public void setTransactionIsolation(final int level) {
throw new UnsupportedOperationException();
}
@Override
public int getTransactionIsolation() {
throw new UnsupportedOperationException();
}
@Override
public SQLWarning getWarnings() {
throw new UnsupportedOperationException();
}
@Override
public void clearWarnings() {
}
@Override
public Statement createStatement(final int resultSetType, final int resultSetConcurrency) {
throw new UnsupportedOperationException();
}
@Override
public PreparedStatement prepareStatement(final String sql, final int resultSetType, final int resultSetConcurrency)
{
throw new UnsupportedOperationException();
}
@Override
public CallableStatement prepareCall(final String sql, final int resultSetType, final int resultSetConcurrency)
{
throw new UnsupportedOperationException();
}
@Override
public Map> getTypeMap() {
throw new UnsupportedOperationException();
}
@Override
public void setTypeMap(final Map> map) {
throw new UnsupportedOperationException();
}
@Override
public void setHoldability(final int holdability) {
throw new UnsupportedOperationException();
}
@Override
public int getHoldability() {
throw new UnsupportedOperationException();
}
@Override
public Savepoint setSavepoint() {
throw new UnsupportedOperationException();
}
@Override
public Savepoint setSavepoint(final String name) {
throw new UnsupportedOperationException();
}
@Override
public void rollback(final Savepoint savepoint) {
throw new UnsupportedOperationException();
}
@Override
public void releaseSavepoint(final Savepoint savepoint) {
throw new UnsupportedOperationException();
}
@Override
public Statement createStatement(final int resultSetType, final int resultSetConcurrency, final int resultSetHoldability)
{
throw new UnsupportedOperationException();
}
@Override
public PreparedStatement prepareStatement(final String sql, final int resultSetType, final int resultSetConcurrency,
final int resultSetHoldability) {
throw new UnsupportedOperationException();
}
@Override
public CallableStatement prepareCall(final String sql, final int resultSetType, final int resultSetConcurrency,
final int resultSetHoldability) {
throw new UnsupportedOperationException();
}
@Override
public Clob createClob() {
throw new UnsupportedOperationException();
}
@Override
public Blob createBlob() {
throw new UnsupportedOperationException();
}
@Override
public NClob createNClob() {
throw new UnsupportedOperationException();
}
@Override
public SQLXML createSQLXML() {
throw new UnsupportedOperationException();
}
@Override
public boolean isValid(final int timeout) {
throw new UnsupportedOperationException();
}
@Override
public void setClientInfo(final String name, final String value) throws SQLClientInfoException {
throw new UnsupportedOperationException();
}
@Override
public void setClientInfo(final Properties properties) throws SQLClientInfoException {
throw new UnsupportedOperationException();
}
@Override
public String getClientInfo(final String name) {
throw new UnsupportedOperationException();
}
@Override
public Properties getClientInfo() {
throw new UnsupportedOperationException();
}
@Override
public Array createArrayOf(final String typeName, final Object[] elements) {
throw new UnsupportedOperationException();
}
@Override
public Struct createStruct(final String typeName, final Object[] attributes) {
throw new UnsupportedOperationException();
}
private void writeTableHeader(final TableMetaData tableMetaData) {
try {
_exporter.writeTableHeader(new ExportTableHeaderImpl(tableMetaData));
} catch (final Exception e) {
throw new ExportException("writeTableHeader", e);
}
}
// JRE 1.7
public void setSchema(final String schema) {
throw new UnsupportedOperationException();
}
public String getSchema() {
throw new UnsupportedOperationException();
}
public void abort(final Executor executor) {
throw new UnsupportedOperationException();
}
public void setNetworkTimeout(final Executor executor, final int milliseconds) {
throw new UnsupportedOperationException();
}
public int getNetworkTimeout() {
throw new UnsupportedOperationException();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy