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 jdk8u_jdk by JetBrains.
the class BaseRowSetTests method testAdvancedParameters.
/*
* DataProvider used to set advanced parameters for types that are supported
*/
@DataProvider(name = "testAdvancedParameters")
private Object[][] testAdvancedParameters() throws SQLException {
byte[] bytes = new byte[10];
Ref aRef = new SerialRef(new StubRef("INTEGER", query));
Array aArray = new SerialArray(new StubArray("INTEGER", new Object[1]));
Blob aBlob = new SerialBlob(new StubBlob());
Clob aClob = new SerialClob(new StubClob());
Reader rdr = new StringReader(query);
InputStream is = new StringBufferInputStream(query);
;
brs = new StubBaseRowSet();
brs.setBytes(1, bytes);
brs.setAsciiStream(2, is, query.length());
brs.setRef(3, aRef);
brs.setArray(4, aArray);
brs.setBlob(5, aBlob);
brs.setClob(6, aClob);
brs.setBinaryStream(7, is, query.length());
brs.setUnicodeStream(8, is, query.length());
brs.setCharacterStream(9, rdr, query.length());
return new Object[][] { { 1, bytes }, { 2, is }, { 3, aRef }, { 4, aArray }, { 5, aBlob }, { 6, aClob }, { 7, is }, { 8, is }, { 9, rdr } };
}
use of java.sql.Array in project jdk8u_jdk by JetBrains.
the class CommonCachedRowSetTests method createDataTypesRows.
/*
* Add rows to DATAYPES table
*/
protected void createDataTypesRows(RowSet crs) throws SQLException {
Integer aInteger = 100;
String aChar = "Oswald Cobblepot";
Long aLong = Long.MAX_VALUE;
Short aShort = Short.MAX_VALUE;
Double aDouble = Double.MAX_VALUE;
BigDecimal aBigDecimal = BigDecimal.ONE;
Boolean aBoolean = false;
Float aFloat = Float.MAX_VALUE;
Byte aByte = Byte.MAX_VALUE;
Date aDate = Date.valueOf(LocalDate.now());
Time aTime = Time.valueOf(LocalTime.now());
Timestamp aTimeStamp = Timestamp.valueOf(LocalDateTime.now());
Array aArray = new StubArray("INTEGER", new Object[1]);
Ref aRef = new SerialRef(new StubRef("INTEGER", query));
byte[] bytes = new byte[10];
crs.moveToInsertRow();
crs.updateInt(1, aInteger);
crs.updateString(2, aChar);
crs.updateString(3, aChar);
crs.updateLong(4, aLong);
crs.updateBoolean(5, aBoolean);
crs.updateShort(6, aShort);
crs.updateDouble(7, aDouble);
crs.updateBigDecimal(8, aBigDecimal);
crs.updateFloat(9, aFloat);
crs.updateByte(10, aByte);
crs.updateDate(11, aDate);
crs.updateTime(12, aTime);
crs.updateTimestamp(13, aTimeStamp);
crs.updateBytes(14, bytes);
crs.updateArray(15, aArray);
crs.updateRef(16, aRef);
crs.updateDouble(17, aDouble);
crs.insertRow();
crs.moveToCurrentRow();
}
use of java.sql.Array in project calcite-avatica by apache.
the class ArrayTypeTest method testCreateArrayOf.
@Test
public void testCreateArrayOf() throws Exception {
try (Connection conn = DriverManager.getConnection(url)) {
final String componentName = SqlType.INTEGER.name();
Array a1 = conn.createArrayOf(componentName, new Object[] { 1, 2, 3, 4, 5 });
Array a2 = conn.createArrayOf(componentName, new Object[] { 2, 3, 4, 5, 6 });
Array a3 = conn.createArrayOf(componentName, new Object[] { 3, 4, 5, 6, 7 });
AvaticaType arrayType = ColumnMetaData.array(ColumnMetaData.scalar(Types.INTEGER, componentName, Rep.INTEGER), "NUMBERS", Rep.ARRAY);
writeAndReadArrays(conn, "CREATE_ARRAY_OF_INTEGERS", componentName, arrayType, Arrays.asList(a1, a2, a3), PRIMITIVE_LIST_VALIDATOR);
}
}
Aggregations