mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
hbase support
This commit is contained in:
@@ -25,7 +25,7 @@ import java.util.Map;
|
||||
public abstract class ResultSetBase implements ResultSet {
|
||||
|
||||
protected boolean closed = false;
|
||||
private boolean wasNull = false;
|
||||
protected boolean wasNull = false;
|
||||
private SQLWarning warning;
|
||||
private String cursorName;
|
||||
private int fetchSize = 0;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.alibaba.druid.hbase;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.ResultSetMetaData;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
@@ -76,11 +77,40 @@ public class HBaseResultSet extends ResultSetBase {
|
||||
if ("@ROW".equals(columnName)) {
|
||||
return result.getRow();
|
||||
}
|
||||
|
||||
if ("id".equals(columnName)) { // TODO
|
||||
return result.getRow();
|
||||
}
|
||||
|
||||
byte[] qualifier = Bytes.toBytes(columnName);
|
||||
byte[] value = result.getValue(family, qualifier);
|
||||
|
||||
this.wasNull = value == null;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInt(String columnName) throws SQLException {
|
||||
byte[] bytes = getBytes(columnName);
|
||||
|
||||
if (bytes == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return Bytes.toInt(bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getBigDecimal(String columnName) throws SQLException {
|
||||
byte[] bytes = getBytes(columnName);
|
||||
|
||||
if (bytes == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Bytes.toBigDecimal(bytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws SQLException {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.alibaba.druid.hbase.exec;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.SQLException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
@@ -22,7 +23,6 @@ public class InsertExecutePlan extends SingleTableExecutePlan {
|
||||
public boolean execute(HBasePreparedStatement statement) throws SQLException {
|
||||
try {
|
||||
HBaseConnection connection = statement.getConnection();
|
||||
HTableInterface htable = connection.getHTable(getTableName());
|
||||
String dbType = connection.getConnectProperties().getProperty("dbType");
|
||||
|
||||
Put put = null;
|
||||
@@ -50,6 +50,9 @@ public class InsertExecutePlan extends SingleTableExecutePlan {
|
||||
} else if (value instanceof Boolean) {
|
||||
boolean booleanValue = ((Boolean) value).booleanValue();
|
||||
bytes = Bytes.toBytes(booleanValue);
|
||||
} else if (value instanceof BigDecimal) {
|
||||
BigDecimal decimalValue = (BigDecimal) value;
|
||||
bytes = Bytes.toBytes(decimalValue);
|
||||
} else {
|
||||
throw new SQLException("TODO"); // TODO
|
||||
}
|
||||
@@ -62,6 +65,7 @@ public class InsertExecutePlan extends SingleTableExecutePlan {
|
||||
}
|
||||
}
|
||||
|
||||
HTableInterface htable = connection.getHTable(getTableName());
|
||||
htable.put(put);
|
||||
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user