This commit is contained in:
温少
2012-05-21 20:43:41 +08:00
parent 4036368eae
commit 8fdc2fd92e
4 changed files with 49 additions and 32 deletions
@@ -3,10 +3,12 @@ package com.alibaba.druid.hdriver;
import java.sql.Connection;
import java.sql.SQLException;
import com.alibaba.druid.hdriver.impl.HPreparedStatementImpl;
import com.alibaba.druid.hdriver.impl.mapping.HMapping;
public interface HConnection extends Connection {
HPreparedStatementImpl prepareStatement(String sql) throws SQLException;
HPreparedStatement prepareStatement(String sql) throws SQLException;
HPreparedStatement prepareStatement(String sql, HMapping mapping) throws SQLException;
HStatement createStatement() throws SQLException;;
}
@@ -21,7 +21,9 @@ import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.client.HTableInterface;
import com.alibaba.druid.hdriver.HConnection;
import com.alibaba.druid.hdriver.HPreparedStatement;
import com.alibaba.druid.hdriver.HStatement;
import com.alibaba.druid.hdriver.impl.mapping.HMapping;
import com.alibaba.druid.util.jdbc.ConnectionBase;
public class HBaseConnectionImpl extends ConnectionBase implements HConnection {
@@ -47,7 +49,7 @@ public class HBaseConnectionImpl extends ConnectionBase implements HConnection {
@Override
public void commit() throws SQLException {
throw new SQLFeatureNotSupportedException();
}
@Override
@@ -77,7 +79,7 @@ public class HBaseConnectionImpl extends ConnectionBase implements HConnection {
@Override
public HStatement createStatement() throws SQLException {
return new HStatementImpl(this);
throw new SQLFeatureNotSupportedException();
}
@Override
@@ -108,7 +110,7 @@ public class HBaseConnectionImpl extends ConnectionBase implements HConnection {
@Override
public DatabaseMetaData getMetaData() throws SQLException {
return null;
throw new SQLFeatureNotSupportedException();
}
@Override
@@ -196,7 +198,7 @@ public class HBaseConnectionImpl extends ConnectionBase implements HConnection {
@Override
public void rollback() throws SQLException {
throw new SQLFeatureNotSupportedException();
}
@Override
@@ -250,4 +252,9 @@ public class HBaseConnectionImpl extends ConnectionBase implements HConnection {
return engine.getHTable(tableName);
}
@Override
public HPreparedStatement prepareStatement(String sql, HMapping mapping) throws SQLException {
throw new SQLFeatureNotSupportedException();
}
}
@@ -0,0 +1,33 @@
package com.alibaba.druid.hdriver.impl.mapping;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.util.Bytes;
public abstract class HMappingAdapter implements HMapping {
@Override
public byte[] getQualifier(String columnName) {
return Bytes.toBytes(columnName);
}
@Override
public byte[] getRow(Result result, String columnName) {
return result.getRow();
}
@Override
public Object getObject(Result result, String columnName) {
byte[] family = this.getFamily(columnName);
byte[] bytes;
if (isRow(columnName)) {
bytes = getRow(result, columnName);
} else {
byte[] qualifier = Bytes.toBytes(columnName);
bytes = result.getValue(family, qualifier);
}
return bytes;
}
}
@@ -1,9 +1,8 @@
package com.alibaba.druid.hdriver.impl.mapping;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.util.Bytes;
public class HMappingDefaultImpl implements HMapping {
public class HMappingDefaultImpl extends HMappingAdapter implements HMapping {
private byte[] family = Bytes.toBytes("d");
private String rowColumn = "id";
@@ -24,34 +23,10 @@ public class HMappingDefaultImpl implements HMapping {
this.rowColumn = rowColumn;
}
@Override
public Object getObject(Result result, String columnName) {
byte[] family = this.getFamily(columnName);
byte[] bytes;
if (isRow(columnName)) {
bytes = getRow(result, columnName);
} else {
byte[] qualifier = Bytes.toBytes(columnName);
bytes = result.getValue(family, qualifier);
}
return bytes;
}
public byte[] getFamily(String columnName) {
return family;
}
public byte[] getRow(Result result, String columnName) {
return result.getRow();
}
@Override
public byte[] getQualifier(String columnName) {
return Bytes.toBytes(columnName);
}
@Override
public boolean isRow(String columnName) {
if (rowColumn.equals(columnName)) {