use of java.sql.Array in project databus by linkedin.
the class OracleAvroGenericEventFactory method getJdbcArray.
private static Array getJdbcArray(ResultSet rs, Schema schema) throws EventCreationException {
// fails if schema isn't for array type
Schema elementSchema = schema.getElementType();
String dbFieldName = SchemaHelper.getMetaField(elementSchema, "dbFieldName");
if (dbFieldName == null) {
throw new EventCreationException("array field is missing required metadata dbFieldName. " + schema.getName());
}
Array array;
try {
array = rs.getArray(dbFieldName);
} catch (SQLException e) {
throw new EventCreationException("unable to read array field: " + dbFieldName + ": " + e.getMessage(), e);
}
return array;
}
use of java.sql.Array in project mybatis-3 by mybatis.
the class SPTest method testGetNamesWithArray_a1.
/*
* This test shows how to use the ARRAY JDBC type with MyBatis.
*
* This test shows using annotations for stored procedures
*
* @throws SQLException
*/
@Test
public void testGetNamesWithArray_a1() throws SQLException {
SqlSession sqlSession = sqlSessionFactory.openSession();
try {
SPMapper spMapper = sqlSession.getMapper(SPMapper.class);
Array array = sqlSession.getConnection().createArrayOf("int", new Integer[] { 1, 2, 5 });
Map<String, Object> parms = new HashMap<String, Object>();
parms.put("ids", array);
List<Name> names = spMapper.getNamesWithArrayAnnotated(parms);
Object[] returnedIds = (Object[]) parms.get("returnedIds");
assertEquals(4, returnedIds.length);
assertEquals(3, parms.get("requestedRows"));
assertEquals(2, names.size());
} finally {
sqlSession.close();
}
}
use of java.sql.Array in project mybatis-3 by mybatis.
the class SPTest method testGetNamesWithArray_a2.
/*
* This test shows how to use the ARRAY JDBC type with MyBatis.
*
* This test shows using annotations for stored procedures and using a
* resultMap in XML
*
* @throws SQLException
*/
@Test
public void testGetNamesWithArray_a2() throws SQLException {
SqlSession sqlSession = sqlSessionFactory.openSession();
try {
SPMapper spMapper = sqlSession.getMapper(SPMapper.class);
Array array = sqlSession.getConnection().createArrayOf("int", new Integer[] { 1, 2, 5 });
Map<String, Object> parms = new HashMap<String, Object>();
parms.put("ids", array);
List<Name> names = spMapper.getNamesWithArrayAnnotatedWithXMLResultMap(parms);
Object[] returnedIds = (Object[]) parms.get("returnedIds");
assertEquals(4, returnedIds.length);
assertEquals(3, parms.get("requestedRows"));
assertEquals(2, names.size());
} finally {
sqlSession.close();
}
}
use of java.sql.Array in project mybatis-3 by mybatis.
the class SPTest method testGetNamesWithArray.
/*
* This test shows how to use the ARRAY JDBC type with MyBatis.
*
* @throws SQLException
*/
@Test
public void testGetNamesWithArray() throws SQLException {
SqlSession sqlSession = sqlSessionFactory.openSession();
try {
SPMapper spMapper = sqlSession.getMapper(SPMapper.class);
Array array = sqlSession.getConnection().createArrayOf("int", new Integer[] { 1, 2, 5 });
Map<String, Object> parms = new HashMap<String, Object>();
parms.put("ids", array);
List<Name> names = spMapper.getNamesWithArray(parms);
Object[] returnedIds = (Object[]) parms.get("returnedIds");
assertEquals(4, returnedIds.length);
assertEquals(3, parms.get("requestedRows"));
assertEquals(2, names.size());
} finally {
sqlSession.close();
}
}
use of java.sql.Array in project presto by prestodb.
the class Validator method convertJdbcResultSet.
private List<List<Object>> convertJdbcResultSet(ResultSet resultSet) throws SQLException, VerifierException {
int rowCount = 0;
int columnCount = resultSet.getMetaData().getColumnCount();
ImmutableList.Builder<List<Object>> rows = ImmutableList.builder();
while (resultSet.next()) {
List<Object> row = new ArrayList<>();
for (int i = 1; i <= columnCount; i++) {
Object object = resultSet.getObject(i);
if (object instanceof BigDecimal) {
if (((BigDecimal) object).scale() <= 0) {
object = ((BigDecimal) object).longValueExact();
} else {
object = ((BigDecimal) object).doubleValue();
}
}
if (object instanceof Array) {
object = ((Array) object).getArray();
}
if (object instanceof byte[]) {
object = new SqlVarbinary((byte[]) object);
}
row.add(object);
}
rows.add(unmodifiableList(row));
rowCount++;
if (rowCount > maxRowCount) {
throw new VerifierException("More than '" + maxRowCount + "' rows, failing query");
}
}
return rows.build();
}
Aggregations