Refine search
Object o = rs.getObject(columnIndex); if (o instanceof byte[]) { v = ValueBytes.getNoCopy((byte[]) o); Object o = rs.getObject(columnIndex); if (o instanceof UUID) { v = ValueUuid.get((UUID) o); boolean value = rs.getBoolean(columnIndex); v = rs.wasNull() ? (Value) ValueNull.INSTANCE : ValueBoolean.get(value); return ValueNull.INSTANCE; Object[] list = (Object[]) array.getArray(); if (list == null) { return ValueNull.INSTANCE;
private Object buildFromResultSet(java.sql.Array array, StatementContext ctx) throws SQLException { List<Object> list = new ArrayList<>(); try (ResultSet rs = array.getResultSet()) { while (rs.next()) { list.add(elementMapper.map(rs, 2, ctx)); } } Object ary = Array.newInstance(componentType, list.size()); if (componentType.isPrimitive()) { for (int i = 0; i < list.size(); i++) { Array.set(ary, i, list.get(i)); } return ary; } return list.toArray((Object[]) ary); } }
private Object buildArray(java.sql.Array array, StatementContext ctx) throws SQLException { if (!UNSUPPORTED_TYPES.contains(array.getBaseType())) { try { Object ary = array.getArray(); if (componentType.equals(ary.getClass().getComponentType())) { return ary; } } catch (SQLFeatureNotSupportedException ignore) {} } UNSUPPORTED_TYPES.add(array.getBaseType()); return buildFromResultSet(array, ctx); }
public void rowLessThanOffsetNoGroupBy() throws Exception { Connection conn = DriverManager.getConnection(getUrl()); String tableName = generateUniqueName(); String ddl = "CREATE TABLE IF NOT EXISTS " + tableName + " " + "(id INTEGER NOT NULL PRIMARY KEY, page_id UNSIGNED_LONG," + " dates INTEGER, val INTEGER)"; conn.createStatement().execute(ddl); conn.createStatement().execute( "UPSERT INTO " + tableName + " (id, page_id, dates, val) VALUES (2, 8, 1, 7)"); conn.createStatement().execute( "UPSERT INTO " + tableName + " (id, page_id, dates, val) VALUES (3, 8, 2, 9)"); conn.commit(); ResultSet rs = conn.createStatement().executeQuery( "SELECT FIRST_VALUES(val, 3) WITHIN GROUP (ORDER BY dates DESC) FROM " + tableName); assertTrue(rs.next()); Assert.assertArrayEquals(new int[]{9, 7}, (int[]) rs.getArray(1).getArray()); assertFalse(rs.next()); }
@Test public void testSplit_DynamicPattern() throws SQLException { Connection conn = DriverManager.getConnection(getUrl()); initTable(conn, "ONE,TWO,THREE"); ResultSet rs = conn.createStatement().executeQuery( "SELECT REGEXP_SPLIT(VAL, SEP) FROM " + tableName); assertTrue(rs.next()); Array array = rs.getArray(1); String[] values = (String[]) array.getArray(); assertArrayEquals(new String[] { "ONE", "TWO", "THREE" }, values); }
ResultSet rs = stmt.executeQuery(sql); while (rs.next()) { byte[] schema = rs.getBytes("nspname"); byte[] procedureName = rs.getBytes("proname"); byte[] specificName = connection.encodeString(rs.getString("proname") + "_" + rs.getString("oid")); Array argNamesArray = rs.getArray("proargnames"); if (argNamesArray != null) { argNames = (String[]) argNamesArray.getArray(); Array argModesArray = rs.getArray("proargmodes"); if (argModesArray != null) { argModes = (String[]) argModesArray.getArray(); Array allArgTypesArray = rs.getArray("proallargtypes"); if (allArgTypesArray != null) { allArgTypes = (Long[]) allArgTypesArray.getArray(); numArgs = allArgTypes.length; + " AND NOT a.attisdropped AND a.attnum > 0 ORDER BY a.attnum "; Statement columnstmt = connection.createStatement(); ResultSet columnrs = columnstmt.executeQuery(columnsql); while (columnrs.next()) { int columnTypeOid = (int) columnrs.getLong("atttypid"); columnrs.close(); columnstmt.close();
throws SQLException int count = resultSet.getMetaData().getColumnCount(); checkArgument(types.size() == count, "type does not match result"); List<Object> row = new ArrayList<>(count); Type type = types.get(i - 1); if (BOOLEAN.equals(type)) { boolean booleanValue = resultSet.getBoolean(i); if (resultSet.wasNull()) { row.add(null); row.add(newArrayList((Object[]) array.getArray()));
switch (fieldType) { case STRING: String string = resultSet.getString(i); if (resultSet.wasNull()) return NullNode.getInstance(); node = JsonHelper.textNode(string); break; case INTEGER: int anInt = resultSet.getInt(i); if (resultSet.wasNull()) return NullNode.getInstance(); node = JsonHelper.numberNode(anInt); if (resultSet.wasNull()) return NullNode.getInstance(); ResultSet rs = array.getResultSet(); int arrIdx = 1; if (rs.next()) {
@Test public void testSplit_Upsert() throws SQLException { Connection conn = DriverManager.getConnection(getUrl()); initTable(conn, "ONE,TWO,THREE"); conn.createStatement().executeUpdate( "UPSERT INTO " + tableName + " (ID, ARR) SELECT ID, " + "REGEXP_SPLIT(VAL, ',') FROM " + tableName); conn.commit(); ResultSet rs = conn.createStatement().executeQuery("SELECT ARR FROM " + tableName); assertTrue(rs.next()); Array array = rs.getArray(1); String[] values = (String[]) array.getArray(); assertArrayEquals(new String[]{ "ONE", "TWO", "THREE" }, values); }
/** Returns whether two arrays have the same contents. * * <p>Arrays must have the same size, and elements in the same order. * Elements are compared using {@link Object#equals(Object)}, and null * values are equal to each other. */ public static boolean equalContents(Array left, Array right) throws SQLException { ResultSet leftResultSet = left.getResultSet(); ResultSet rightResultSet = right.getResultSet(); while (leftResultSet.next() && rightResultSet.next()) { if (!Objects.equals(leftResultSet.getObject(1), rightResultSet.getObject(1))) { return false; } } return !leftResultSet.next() && !rightResultSet.next(); }
int columnCount = resultSet.getMetaData().getColumnCount(); 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 = ((Array) object).getArray();
public EntityList map(int index, ResultSet resultSet, StatementContext ctx) throws SQLException { EntityList list = new EntityList(); list.setId((UUID) resultSet.getObject("id")); list.setParentId((UUID) resultSet.getObject("parent_id")); list.setSlug(resultSet.getString("slug")); list.setHint(resultSet.getString("hint")); list.setType(resultSet.getString("entity_type")); if (resultSet.getArray("entities") != null) { // There's no support for getting the pg uuid array as a Java UUID array (or even String array) at the time // this is written, we have to iterate over the array own result set and construct the Java array ourselves List<UUID> ids = new ArrayList<>(); Array array = resultSet.getArray("entities"); if (array != null) { ResultSet entitiesResultSet = array.getResultSet(); while (entitiesResultSet.next()) { ids.add((UUID) entitiesResultSet.getObject("value")); } list.setEntities(ids); } } return list; } }
@Override public Annotation mapRow(ResultSet rs, int rowNum) throws SQLException { Integer pre = rs.getInt("pre"); String corpusName = rs.getString("corpus_name"); String type = rs.getString("type"); String namespace = rs.getString("namespace"); String name = rs.getString("name"); String value = rs.getString("value"); Array annotationPathArray = rs.getArray("path_name"); List<String> annotationPath = new LinkedList<>(); if(annotationPathArray.getBaseType() == Types.VARCHAR) { annotationPath = Arrays.asList((String[]) annotationPathArray.getArray()); } return new Annotation(namespace, name, value, type, corpusName, pre, annotationPath); } }
/** * Converts an Array into a List using {@link Array#getResultSet()}. This implementation is * recursive and can parse multi-dimensional arrays. */ static List<?> extractUsingResultSet(Array array, Calendar calendar) throws SQLException { ResultSet arrayValues = array.getResultSet(); TreeMap<Integer, Object> map = new TreeMap<>(); while (arrayValues.next()) { // column 1 is the index in the array, column 2 is the value. // Recurse on `getValue` to unwrap nested types correctly. // `j` is zero-indexed and incremented for us, thus we have `1` being used twice. map.put(arrayValues.getInt(1), getValue(arrayValues, array.getBaseType(), 1, calendar)); } // If the result set is not in the same order as the actual Array, TreeMap fixes that. // Need to make a concrete list to ensure Jackson serialization. return new ArrayList<>(map.values()); }
@Override public List<T> convert(Array in, Context context) throws Exception { if (in == null) return null; List<T> list = new ArrayList<T>(); ResultSet rs = in.getResultSet(); try { while(rs.next()) { list.add(getter.get(rs)); } } finally { rs.close(); } return list; } }
/** * Processes a particular SQL Array object and interprets its value as a ParamValue object. * * @param sqlArray SQL Array element. * @param paramValue Parameter value object initialized to contain an array of ParamValues. * @return ParamValue object representing the SQL Array. * @throws SQLException Throws an SQL Exception if the result set is not accessible. */ public static ParamValue processSQLArray(Array sqlArray, ParamValue paramValue) throws SQLException { ResultSet rs = sqlArray.getResultSet(); while (rs.next()) { Object arrayEl = rs.getObject(2); if (arrayEl instanceof Struct) { paramValue.getArrayValue().add(new ParamValue((Struct) arrayEl)); } else if (arrayEl instanceof Array) { paramValue.getArrayValue().add(processSQLArray( (Array) arrayEl, new ParamValue(ParamValue.PARAM_VALUE_ARRAY))); } else { paramValue.getArrayValue().add(new ParamValue(String.valueOf(arrayEl))); } } rs.close(); return paramValue; }
conn = ds.getConnection(); String storedProc = "{call enquiry_activity_report(?)}"; CallableStatement cs = conn.prepareCall(storedProc); // register output parameter cs.registerOutParameter(1, OracleTypes.ARRAY, "ACTIVITY_REPORT_ITEMS_TYPE"); cs.execute(); Array array = cs.getArray(1); ResultSet rs = array.getResultSet(); while (rs.next()) { // why getObject(2) instead of getObject(1)? Object elements[] = ((STRUCT) rs.getObject(2)).getAttributes(); System.out.println(elements[0]); System.out.println(elements[1]); System.out.println(elements[2]); } cs.close();
.appendIdentifier(schema, tableName).append(" WHERE ") .append(ID_COLUMN).append("=?").toString(); result = new CachedStatement(type, connection().prepareStatement(query), listeners); if (isArray) { final java.sql.Array array = (java.sql.Array) value; value = array.getArray(); array.free();