ArrayImpl.Factory factory = new ArrayFactoryImpl(Unsafe.localCalendar().getTimeZone()); Array array1 = factory.createArray(structType, Arrays.<Object>asList(struct1, struct2)); Array array2 = factory.createArray(structType, Arrays.<Object>asList(struct3, struct4)); List<List<Object>> rows = Arrays.asList(Collections.<Object>singletonList(array1), Collections.<Object>singletonList(array2));
ArrayImpl.Factory factory = new ArrayFactoryImpl(Unsafe.localCalendar().getTimeZone()); Array array1 = factory.createArray(intType, Arrays.<Object>asList(1, 2)); Array array2 = factory.createArray(intType, Arrays.<Object>asList(3)); Array array3 = factory.createArray(intType, Arrays.<Object>asList(4, 5, 6)); List<List<Object>> rows = Arrays.asList(Collections.<Object>singletonList(array1), Collections.<Object>singletonList(array2), Collections.<Object>singletonList(array3));
ArrayImpl.Factory factory = new ArrayFactoryImpl(Unsafe.localCalendar().getTimeZone()); Array array1 = factory.createArray(structType, Arrays.<Object>asList(struct1, struct2)); Array array2 = factory.createArray(structType, Arrays.<Object>asList(struct3, struct4)); List<List<Object>> rows = Arrays.asList(Collections.<Object>singletonList(array1), Collections.<Object>singletonList(array2));
ArrayImpl.Factory factory = new ArrayFactoryImpl(Unsafe.localCalendar().getTimeZone()); Array array1 = factory.createArray(intType, Arrays.<Object>asList(1, 2)); Array array2 = factory.createArray(intType, Arrays.<Object>asList(3)); Array array3 = factory.createArray(intType, Arrays.<Object>asList(4, 5, 6)); List<List<Object>> rows = Arrays.asList(Collections.<Object>singletonList(array1), Collections.<Object>singletonList(array2), Collections.<Object>singletonList(array3));
@Test public void testArrayWithOffsets() throws Exception { // Define the struct type we're creating ScalarType intType = ColumnMetaData.scalar(Types.INTEGER, "INTEGER", Rep.INTEGER); ArrayImpl.Factory factory = new ArrayFactoryImpl(Unsafe.localCalendar().getTimeZone()); // Create some arrays from the structs Array array1 = factory.createArray(intType, Arrays.<Object>asList(1, 2)); Array array3 = factory.createArray(intType, Arrays.<Object>asList(4, 5, 6)); Object[] data = (Object[]) array1.getArray(2, 1); assertEquals(1, data.length); assertEquals(2, data[0]); data = (Object[]) array3.getArray(1, 1); assertEquals(1, data.length); assertEquals(4, data[0]); data = (Object[]) array3.getArray(2, 2); assertEquals(2, data.length); assertEquals(5, data[0]); assertEquals(6, data[1]); data = (Object[]) array3.getArray(1, 3); assertEquals(3, data.length); assertEquals(4, data[0]); assertEquals(5, data[1]); assertEquals(6, data[2]); } }
@Test public void testArrayWithOffsets() throws Exception { // Define the struct type we're creating ScalarType intType = ColumnMetaData.scalar(Types.INTEGER, "INTEGER", Rep.INTEGER); ArrayImpl.Factory factory = new ArrayFactoryImpl(Unsafe.localCalendar().getTimeZone()); // Create some arrays from the structs Array array1 = factory.createArray(intType, Arrays.<Object>asList(1, 2)); Array array3 = factory.createArray(intType, Arrays.<Object>asList(4, 5, 6)); Object[] data = (Object[]) array1.getArray(2, 1); assertEquals(1, data.length); assertEquals(2, data[0]); data = (Object[]) array3.getArray(1, 1); assertEquals(1, data.length); assertEquals(4, data[0]); data = (Object[]) array3.getArray(2, 2); assertEquals(2, data.length); assertEquals(5, data[0]); assertEquals(6, data[1]); data = (Object[]) array3.getArray(1, 3); assertEquals(3, data.length); assertEquals(4, data[0]); assertEquals(5, data[1]); assertEquals(6, data[2]); } }
@Test public void testArrays() { List<Object> serialObj = Arrays.<Object>asList(1, 2, 3, 4); ArrayImpl.Factory factory = new ArrayFactoryImpl(Unsafe.localCalendar().getTimeZone()); ScalarType scalarType = ColumnMetaData.scalar(Types.INTEGER, "INTEGER", Rep.INTEGER); Array a1 = factory.createArray(scalarType, serialObj); TypedValue tv1 = TypedValue.ofJdbc(Rep.ARRAY, a1, Unsafe.localCalendar()); Object jdbcObj = tv1.toJdbc(Unsafe.localCalendar()); assertTrue("The JDBC object is an " + jdbcObj.getClass(), jdbcObj instanceof Array); Object localObj = tv1.toLocal(); assertTrue("The local object is an " + localObj.getClass(), localObj instanceof List); Common.TypedValue protoTv1 = tv1.toProto(); assertEquals(serialObj.size(), protoTv1.getArrayValueCount()); TypedValue tv1Copy = TypedValue.fromProto(protoTv1); Object jdbcObjCopy = tv1Copy.toJdbc(Unsafe.localCalendar()); assertTrue("The JDBC object is an " + jdbcObjCopy.getClass(), jdbcObjCopy instanceof Array); Object localObjCopy = tv1Copy.toLocal(); assertTrue("The local object is an " + localObjCopy.getClass(), localObjCopy instanceof List); } }
@Test public void testArrays() { List<Object> serialObj = Arrays.<Object>asList(1, 2, 3, 4); ArrayImpl.Factory factory = new ArrayFactoryImpl(Unsafe.localCalendar().getTimeZone()); ScalarType scalarType = ColumnMetaData.scalar(Types.INTEGER, "INTEGER", Rep.INTEGER); Array a1 = factory.createArray(scalarType, serialObj); TypedValue tv1 = TypedValue.ofJdbc(Rep.ARRAY, a1, Unsafe.localCalendar()); Object jdbcObj = tv1.toJdbc(Unsafe.localCalendar()); assertTrue("The JDBC object is an " + jdbcObj.getClass(), jdbcObj instanceof Array); Object localObj = tv1.toLocal(); assertTrue("The local object is an " + localObj.getClass(), localObj instanceof List); Common.TypedValue protoTv1 = tv1.toProto(); assertEquals(serialObj.size(), protoTv1.getArrayValueCount()); TypedValue tv1Copy = TypedValue.fromProto(protoTv1); Object jdbcObjCopy = tv1Copy.toJdbc(Unsafe.localCalendar()); assertTrue("The JDBC object is an " + jdbcObjCopy.getClass(), jdbcObjCopy instanceof Array); Object localObjCopy = tv1Copy.toLocal(); assertTrue("The local object is an " + localObjCopy.getClass(), localObjCopy instanceof List); } }
@Override public ResultSet getResultSet() throws SQLException { return accessor.factory.create(accessor.componentType, list); }
@Override public ResultSet getResultSet() throws SQLException { return accessor.factory.create(accessor.componentType, list); }
public ResultSet getResultSet() throws SQLException { return accessor.factory.create(accessor.componentType, list); }