use of java.sql.Clob in project sonarqube by SonarSource.
the class AbstractDbTester method getHashMap.
private static List<Map<String, Object>> getHashMap(ResultSet resultSet) throws Exception {
ResultSetMetaData metaData = resultSet.getMetaData();
int colCount = metaData.getColumnCount();
List<Map<String, Object>> rows = newArrayList();
while (resultSet.next()) {
Map<String, Object> columns = newHashMap();
for (int i = 1; i <= colCount; i++) {
Object value = resultSet.getObject(i);
if (value instanceof Clob) {
Clob clob = (Clob) value;
value = IOUtils.toString((clob.getAsciiStream()));
doClobFree(clob);
} else if (value instanceof BigDecimal) {
// In Oracle, INTEGER types are mapped as BigDecimal
BigDecimal bgValue = ((BigDecimal) value);
if (bgValue.scale() == 0) {
value = bgValue.longValue();
} else {
value = bgValue.doubleValue();
}
} else if (value instanceof Integer) {
// To be consistent, all INTEGER types are mapped as Long
value = ((Integer) value).longValue();
}
columns.put(metaData.getColumnLabel(i), value);
}
rows.add(columns);
}
return rows;
}
use of java.sql.Clob in project druid by alibaba.
the class StatFilter method buildSlowParameters.
private String buildSlowParameters(StatementProxy statement) {
JSONWriter out = new JSONWriter();
out.writeArrayStart();
for (int i = 0, parametersSize = statement.getParametersSize(); i < parametersSize; ++i) {
JdbcParameter parameter = statement.getParameter(i);
if (i != 0) {
out.writeComma();
}
if (parameter == null) {
continue;
}
Object value = parameter.getValue();
if (value == null) {
out.writeNull();
} else if (value instanceof String) {
String text = (String) value;
if (text.length() > 100) {
out.writeString(text.substring(0, 97) + "...");
} else {
out.writeString(text);
}
} else if (value instanceof Number) {
out.writeObject(value);
} else if (value instanceof java.util.Date) {
out.writeObject(value);
} else if (value instanceof Boolean) {
out.writeObject(value);
} else if (value instanceof InputStream) {
out.writeString("<InputStream>");
} else if (value instanceof NClob) {
out.writeString("<NClob>");
} else if (value instanceof Clob) {
out.writeString("<Clob>");
} else if (value instanceof Blob) {
out.writeString("<Blob>");
} else {
out.writeString('<' + value.getClass().getName() + '>');
}
}
out.writeArrayEnd();
return out.toString();
}
use of java.sql.Clob in project druid by alibaba.
the class ResultSetProxyImpl method getClob.
@Override
public Clob getClob(int columnIndex) throws SQLException {
FilterChainImpl chain = createChain();
Clob value = chain.resultSet_getClob(this, columnIndex);
recycleFilterChain(chain);
return value;
}
use of java.sql.Clob in project druid by alibaba.
the class DruidLobCreator method setClobAsAsciiStream.
@Override
public void setClobAsAsciiStream(PreparedStatement ps, int paramIndex, InputStream asciiStream, int contentLength) throws SQLException {
if (asciiStream != null) {
Clob clob = ps.getConnection().createClob();
OutputStream out = clob.setAsciiStream(1);
final int BUFFER_SIZE = 4096;
try {
byte[] buffer = new byte[BUFFER_SIZE];
int bytesRead = -1;
while ((bytesRead = asciiStream.read(buffer)) != -1) {
out.write(buffer, 0, bytesRead);
}
out.flush();
} catch (Exception e) {
throw new SQLException("setClob error", e);
} finally {
JdbcUtils.close(asciiStream);
JdbcUtils.close(out);
}
ps.setClob(paramIndex, clob);
} else {
ps.setClob(paramIndex, (Clob) null);
}
}
use of java.sql.Clob in project druid by alibaba.
the class FilterChainTest_Clob method test_resultSet_getClob_1.
public void test_resultSet_getClob_1() throws Exception {
FilterChainImpl chain = new FilterChainImpl(dataSource);
Clob clob = chain.resultSet_getClob(new ResultSetProxyImpl(statement, mockResultSet, 1, null), "1");
Assert.assertTrue(clob instanceof ClobProxy);
Assert.assertEquals(1, invokeCount);
}
Aggregations