hbase support

This commit is contained in:
温少
2012-05-18 20:08:07 +08:00
parent a8ab7b14d6
commit 41d4720eda
6 changed files with 1002 additions and 3 deletions
@@ -0,0 +1,315 @@
package com.alibaba.druid.hbase;
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.SQLFeatureNotSupportedException;
import java.sql.SQLWarning;
import java.sql.SQLXML;
import java.sql.Savepoint;
import java.sql.Statement;
import java.sql.Struct;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.apache.hadoop.conf.Configuration;
public class HBaseConnection implements Connection {
private Configuration config;
private boolean autoCommit = true;
private String catalog;
private int transactionIsolation;
private int holdability;
private Map<String, Class<?>> typeMap = new HashMap<String, Class<?>>();
private SQLWarning warings;
public HBaseConnection(Properties info){
config = new Configuration();
this.setClientInfo(info);
}
@SuppressWarnings("unchecked")
@Override
public <T> T unwrap(Class<T> iface) throws SQLException {
if (iface == Configuration.class) {
return (T) config;
}
if (iface == Connection.class || iface == HBaseConnection.class) {
return (T) this;
}
return null;
}
@Override
public boolean isWrapperFor(Class<?> iface) throws SQLException {
if (iface == Configuration.class) {
return true;
}
if (iface == Connection.class || iface == HBaseConnection.class) {
return true;
}
return false;
}
@Override
public Statement createStatement() throws SQLException {
return new HBaseStatement(this);
}
@Override
public PreparedStatement prepareStatement(String sql) throws SQLException {
throw new SQLFeatureNotSupportedException();
}
@Override
public CallableStatement prepareCall(String sql) throws SQLException {
throw new SQLFeatureNotSupportedException();
}
@Override
public String nativeSQL(String sql) throws SQLException {
throw new SQLFeatureNotSupportedException();
}
@Override
public void setAutoCommit(boolean autoCommit) throws SQLException {
this.autoCommit = autoCommit;
}
@Override
public boolean getAutoCommit() throws SQLException {
return autoCommit;
}
@Override
public void commit() throws SQLException {
}
@Override
public void rollback() throws SQLException {
}
@Override
public void close() throws SQLException {
}
@Override
public boolean isClosed() throws SQLException {
return false;
}
@Override
public DatabaseMetaData getMetaData() throws SQLException {
return null;
}
@Override
public void setReadOnly(boolean readOnly) throws SQLException {
}
@Override
public boolean isReadOnly() throws SQLException {
return false;
}
@Override
public void setCatalog(String catalog) throws SQLException {
this.catalog = catalog;
}
@Override
public String getCatalog() throws SQLException {
return catalog;
}
@Override
public void setTransactionIsolation(int level) throws SQLException {
this.transactionIsolation = level;
}
@Override
public int getTransactionIsolation() throws SQLException {
return transactionIsolation;
}
@Override
public SQLWarning getWarnings() throws SQLException {
return warings;
}
@Override
public void clearWarnings() throws SQLException {
this.warings = null;
}
public void setWarings(SQLWarning warings) {
this.warings = warings;
}
@Override
public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
throw new SQLFeatureNotSupportedException();
}
@Override
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
throws SQLException {
throw new SQLFeatureNotSupportedException();
}
@Override
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
throw new SQLFeatureNotSupportedException();
}
@Override
public Map<String, Class<?>> getTypeMap() throws SQLException {
return typeMap;
}
@Override
public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
this.typeMap = map;
}
@Override
public void setHoldability(int holdability) throws SQLException {
this.holdability = holdability;
}
@Override
public int getHoldability() {
return holdability;
}
@Override
public Savepoint setSavepoint() throws SQLException {
throw new SQLFeatureNotSupportedException();
}
@Override
public Savepoint setSavepoint(String name) throws SQLException {
throw new SQLFeatureNotSupportedException();
}
@Override
public void rollback(Savepoint savepoint) throws SQLException {
throw new SQLFeatureNotSupportedException();
}
@Override
public void releaseSavepoint(Savepoint savepoint) throws SQLException {
throw new SQLFeatureNotSupportedException();
}
@Override
public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)
throws SQLException {
throw new SQLFeatureNotSupportedException();
}
@Override
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency,
int resultSetHoldability) throws SQLException {
throw new SQLFeatureNotSupportedException();
}
@Override
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency,
int resultSetHoldability) throws SQLException {
throw new SQLFeatureNotSupportedException();
}
@Override
public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
throw new SQLFeatureNotSupportedException();
}
@Override
public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
throw new SQLFeatureNotSupportedException();
}
@Override
public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
throw new SQLFeatureNotSupportedException();
}
@Override
public Clob createClob() throws SQLException {
throw new SQLFeatureNotSupportedException();
}
@Override
public Blob createBlob() throws SQLException {
throw new SQLFeatureNotSupportedException();
}
@Override
public NClob createNClob() throws SQLException {
throw new SQLFeatureNotSupportedException();
}
@Override
public SQLXML createSQLXML() throws SQLException {
throw new SQLFeatureNotSupportedException();
}
@Override
public boolean isValid(int timeout) throws SQLException {
throw new SQLFeatureNotSupportedException();
}
@Override
public void setClientInfo(String name, String value) throws SQLClientInfoException {
this.config.set(name, value);
}
@Override
public void setClientInfo(Properties properties) {
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
if (entry.getKey() != null && entry.getValue() != null) {
config.set(entry.getKey().toString(), entry.getValue().toString());
}
}
}
@Override
public String getClientInfo(String name) throws SQLException {
return config.get(name);
}
@Override
public Properties getClientInfo() throws SQLException {
throw new SQLFeatureNotSupportedException();
}
@Override
public Array createArrayOf(String typeName, Object[] elements) throws SQLException {
throw new SQLFeatureNotSupportedException();
}
@Override
public Struct createStruct(String typeName, Object[] attributes) throws SQLException {
throw new SQLFeatureNotSupportedException();
}
}