java.sql.Struct Java Examples
The following examples show how to use
java.sql.Struct.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JDBC4ResultSet.java From Komondor with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("unchecked") public <T> T getObject(int columnIndex, Class<T> type) throws SQLException { if (type == null) { throw SQLError.createSQLException("Type parameter can not be null", SQLError.SQL_STATE_ILLEGAL_ARGUMENT, getExceptionInterceptor()); } if (type.equals(Struct.class)) { throw new SQLFeatureNotSupportedException(); } else if (type.equals(RowId.class)) { return (T) getRowId(columnIndex); } else if (type.equals(NClob.class)) { return (T) getNClob(columnIndex); } else if (type.equals(SQLXML.class)) { return (T) getSQLXML(columnIndex); } return super.getObject(columnIndex, type); }
Example #2
Source File: StructImplTest.java From calcite-avatica with Apache License 2.0 | 6 votes |
@Test public void testStructAccessor() throws Exception { // Create rows based on the inputValues data List<List<Object>> rows = new ArrayList<>(); for (Object o : columnInputBundle.inputValues) { rows.add(Collections.singletonList(o)); } try (Cursor cursor = new ListIteratorCursor(rows.iterator())) { List<Accessor> accessors = cursor.createAccessors( Collections.singletonList(columnInputBundle.metaData), Unsafe.localCalendar(), null); Accessor accessor = accessors.get(0); int i = 0; while (cursor.next()) { Struct s = accessor.getObject(Struct.class); Object[] expectedStructAttributes = columnInputBundle.expectedValues.get(i).getAttributes(); Object[] actualStructAttributes = s.getAttributes(); assertArrayEquals(expectedStructAttributes, actualStructAttributes); i++; } } }
Example #3
Source File: SQLQuery.java From micro-integrator with Apache License 2.0 | 6 votes |
/** * Processes a SQL Array instance and transform it into a ParamValue * instance * * @param dataArray * SQLArray instance * @param paramValue * Container into which the SQLArray elements should be populated * @return ParamValue instance containing all the elements of the * corresponding SQLArray instance * @throws SQLException * When it fails to processes the result set produced by the * SQLArray instance */ private ParamValue processSQLArray(Array dataArray, ParamValue paramValue) throws SQLException { ResultSet rs = null; try { rs = dataArray.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))); } } return paramValue; } finally { this.releaseResources(rs, null); } }
Example #4
Source File: JDBC4ResultSet.java From r-course with MIT License | 6 votes |
@SuppressWarnings("unchecked") public <T> T getObject(int columnIndex, Class<T> type) throws SQLException { if (type == null) { throw SQLError.createSQLException("Type parameter can not be null", SQLError.SQL_STATE_ILLEGAL_ARGUMENT, getExceptionInterceptor()); } if (type.equals(Struct.class)) { throw new SQLFeatureNotSupportedException(); } else if (type.equals(RowId.class)) { return (T) getRowId(columnIndex); } else if (type.equals(NClob.class)) { return (T) getNClob(columnIndex); } else if (type.equals(SQLXML.class)) { return (T) getSQLXML(columnIndex); } return super.getObject(columnIndex, type); }
Example #5
Source File: QueryComplexTypeITest.java From ClickHouse-Native-JDBC with Apache License 2.0 | 6 votes |
@Test public void successfullyTuple() throws Exception { withNewConnection(connection -> { Statement statement = connection.createStatement(); ResultSet rs = statement.executeQuery("SELECT (toUInt32(1),'2')"); Assert.assertTrue(rs.next()); Struct struct = (Struct) rs.getObject(1); Assert.assertEquals(struct.getAttributes(), new Object[]{(long) 1, "2"}); Map<String, Class<?>> attrNameWithClass = new LinkedHashMap<String, Class<?>>(); attrNameWithClass.put("_2", String.class); attrNameWithClass.put("_1", Long.class); Assert.assertEquals(struct.getAttributes(attrNameWithClass), new Object[]{"2", (long) 1}); }); }
Example #6
Source File: AbstractPreparedStatement.java From ClickHouse-Native-JDBC with Apache License 2.0 | 6 votes |
private boolean assembleComplexQuotedParameter(StringBuilder queryBuilder, Object parameter) throws SQLException { if (parameter instanceof Array) { queryBuilder.append("["); Object[] arrayData = (Object[]) ((Array) parameter).getArray(); for (int arrayIndex = 0; arrayIndex < arrayData.length; arrayIndex++) { assembleParameter(arrayData[arrayIndex], queryBuilder); queryBuilder.append(arrayIndex == arrayData.length - 1 ? "]" : ","); } return true; } else if (parameter instanceof Struct) { queryBuilder.append("("); Object[] structData = ((Struct) parameter).getAttributes(); for (int structIndex = 0; structIndex < structData.length; structIndex++) { assembleParameter(structData[structIndex], queryBuilder); queryBuilder.append(structIndex == structData.length - 1 ? ")" : ","); } return true; } return false; }
Example #7
Source File: LogicalConnection.java From snowflake-jdbc with Apache License 2.0 | 6 votes |
@Override public Struct createStruct(String typeName, Object[] attributes) throws SQLException { throwExceptionIfClosed(); try { return physicalConnection.createStruct(typeName, attributes); } catch (SQLException e) { pooledConnection.fireConnectionErrorEvent(e); throw e; } }
Example #8
Source File: LogicalConnection40.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
public Struct createStruct(String typeName, Object[] attributes) throws SQLException { try { checkForNullPhysicalConnection(); return physicalConnection_.createStruct( typeName, attributes ); } catch (SQLException sqle) { notifyException(sqle); throw sqle; } }
Example #9
Source File: LogicalConnection40.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
public Struct createStruct(String typeName, Object[] attributes) throws SQLException { try { checkForNullPhysicalConnection(); return physicalConnection_.createStruct( typeName, attributes ); } catch (SQLException sqle) { notifyException(sqle); throw sqle; } }
Example #10
Source File: PooledConnection.java From FHIR with Apache License 2.0 | 5 votes |
@Override public Struct createStruct(String typeName, Object[] attributes) throws SQLException { try { return wrapped.createStruct(typeName, attributes); } catch (SQLException x) { this.reusable = !pool.checkConnectionFailure(x); throw x; } }
Example #11
Source File: SQLOutputImplTests.java From hottub with GNU General Public License v2.0 | 5 votes |
@Test(enabled = true) public void test08() throws Exception { Object[] attributes = new Object[]{"Bruce", "Wayne", 1939, "Batman"}; Struct s = new StubStruct(sqlType, attributes); outImpl.writeStruct(s); SerialStruct ss = (SerialStruct) results.get(0); assertTrue(Arrays.equals(attributes, (Object[]) ss.getAttributes())); assertTrue(sqlType.equals(ss.getSQLTypeName())); }
Example #12
Source File: SQLOutputImplTests.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@Test(enabled = true) public void test08() throws Exception { Object[] attributes = new Object[]{"Bruce", "Wayne", 1939, "Batman"}; Struct s = new StubStruct(sqlType, attributes); outImpl.writeStruct(s); SerialStruct ss = (SerialStruct) results.get(0); assertTrue(Arrays.equals(attributes, (Object[]) ss.getAttributes())); assertTrue(sqlType.equals(ss.getSQLTypeName())); }
Example #13
Source File: PoolConnectionImpl.java From clearpool with GNU General Public License v3.0 | 5 votes |
@Override public Struct createStruct(String typeName, Object[] attributes) throws SQLException { this.checkState(); Struct struct = null; try { struct = this.connection.createStruct(typeName, attributes); } catch (SQLException ex) { this.handleException(ex); } return struct; }
Example #14
Source File: JdbcConnectionHandler.java From orcas with Apache License 2.0 | 5 votes |
public static Struct createStruct(String pTypeName, Object[] pAttributes, CallableStatementProvider pCallableStatementProvider) { try { CallableStatementProviderImpl lCallableStatementProviderImpl = (CallableStatementProviderImpl) pCallableStatementProvider; return lCallableStatementProviderImpl._connection.createStruct(lCallableStatementProviderImpl._parameters .getOrcasDbUser() .toUpperCase() + "." + pTypeName.toUpperCase(), pAttributes); } catch (SQLException e) { throw new RuntimeException(e); } }
Example #15
Source File: DataTypeTuple.java From ClickHouse-Native-JDBC with Apache License 2.0 | 5 votes |
@Override public void serializeBinaryBulk(Object[] data, BinarySerializer serializer) throws SQLException, IOException { for (int i = 0; i < nestedTypes.length; i++) { Object[] elemsData = new Object[data.length]; for (int row = 0; row < data.length; row++) { elemsData[row] = ((Struct) data[row]).getAttributes()[i]; } nestedTypes[i].serializeBinaryBulk(elemsData, serializer); } }
Example #16
Source File: UtilAdapter.java From importer-exporter with Apache License 2.0 | 5 votes |
@Override protected BoundingBox transformBoundingBox(BoundingBox bbox, DatabaseSrs sourceSrs, DatabaseSrs targetSrs, Connection connection) throws SQLException { BoundingBox result = new BoundingBox(bbox); int sourceSrid = get2DSrid(sourceSrs, connection); int targetSrid = get2DSrid(targetSrs, connection); try (PreparedStatement psQuery = connection.prepareStatement("select SDO_CS.TRANSFORM(MDSYS.SDO_GEOMETRY(2003, " + sourceSrid + ", NULL, MDSYS.SDO_ELEM_INFO_ARRAY(1, 1003, 1), " + "MDSYS.SDO_ORDINATE_ARRAY(?,?,?,?)), " + targetSrid + ") from dual")) { psQuery.setDouble(1, bbox.getLowerCorner().getX()); psQuery.setDouble(2, bbox.getLowerCorner().getY()); psQuery.setDouble(3, bbox.getUpperCorner().getX()); psQuery.setDouble(4, bbox.getUpperCorner().getY()); try (ResultSet rs = psQuery.executeQuery()) { if (rs.next()) { Struct struct = (Struct) rs.getObject(1); if (!rs.wasNull() && struct != null) { JGeometry geom = JGeometry.loadJS(struct); double[] ordinatesArray = geom.getOrdinatesArray(); result.getLowerCorner().setX(ordinatesArray[0]); result.getLowerCorner().setY(ordinatesArray[1]); result.getUpperCorner().setX(ordinatesArray[2]); result.getUpperCorner().setY(ordinatesArray[3]); result.setSrs(targetSrs); } } } return result; } }
Example #17
Source File: CalciteRemoteDriverTest.java From calcite with Apache License 2.0 | 5 votes |
/** Check that the "set" conversion table looks like Table B-5 in JDBC 4.1 * specification */ @Test void testTableB5() { SqlType[] columns = { SqlType.TINYINT, SqlType.SMALLINT, SqlType.INTEGER, SqlType.BIGINT, SqlType.REAL, SqlType.FLOAT, SqlType.DOUBLE, SqlType.DECIMAL, SqlType.NUMERIC, SqlType.BIT, SqlType.BOOLEAN, SqlType.CHAR, SqlType.VARCHAR, SqlType.LONGVARCHAR, SqlType.BINARY, SqlType.VARBINARY, SqlType.LONGVARBINARY, SqlType.DATE, SqlType.TIME, SqlType.TIMESTAMP, SqlType.ARRAY, SqlType.BLOB, SqlType.CLOB, SqlType.STRUCT, SqlType.REF, SqlType.DATALINK, SqlType.JAVA_OBJECT, SqlType.ROWID, SqlType.NCHAR, SqlType.NVARCHAR, SqlType.LONGNVARCHAR, SqlType.NCLOB, SqlType.SQLXML }; Class[] rows = { String.class, BigDecimal.class, Boolean.class, Byte.class, Short.class, Integer.class, Long.class, Float.class, Double.class, byte[].class, BigInteger.class, java.sql.Date.class, Time.class, Timestamp.class, Array.class, Blob.class, Clob.class, Struct.class, Ref.class, URL.class, Class.class, RowId.class, NClob.class, SQLXML.class, Calendar.class, java.util.Date.class }; for (Class row : rows) { final String s = row == Date.class ? row.getName() : row.getSimpleName(); out.print(pad(s)); for (SqlType column : columns) { out.print(SqlType.canSet(row, column) ? "x " : ". "); } out.println(); } }
Example #18
Source File: GeometryConverterAdapter.java From importer-exporter with Apache License 2.0 | 5 votes |
@Override public GeometryObject getEnvelope(Object geomObj) throws SQLException { GeometryObject envelope = null; if (geomObj instanceof Struct) { JGeometry geometry = JGeometry.loadJS((Struct)geomObj); double[] ordinates = geometry.getMBR(); double[] coordinates; if (geometry.getDimensions() == 3) coordinates = new double[]{ordinates[0], ordinates[1], ordinates[2], ordinates[3], ordinates[4], ordinates[5]}; else coordinates = new double[]{ordinates[0], ordinates[1], 0, ordinates[2], ordinates[3], 0}; envelope = GeometryObject.createEnvelope(coordinates, 3, geometry.getSRID()); } return envelope; }
Example #19
Source File: SQLOutputImplTests.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@Test(enabled = true) public void test08() throws Exception { Object[] attributes = new Object[]{"Bruce", "Wayne", 1939, "Batman"}; Struct s = new StubStruct(sqlType, attributes); outImpl.writeStruct(s); SerialStruct ss = (SerialStruct) results.get(0); assertTrue(Arrays.equals(attributes, (Object[]) ss.getAttributes())); assertTrue(sqlType.equals(ss.getSQLTypeName())); }
Example #20
Source File: SQLInputImplTests.java From hottub with GNU General Public License v2.0 | 5 votes |
@Test() public void test11() throws Exception { Object[] attributes = new Object[]{"Bruce", "Wayne", 1939, "Batman"}; map.put(sqlType, Class.forName("util.SuperHero")); Struct struct = new StubStruct(sqlType, attributes); Object[] values = {struct}; SQLInputImpl sqli = new SQLInputImpl(values, map); Object o = sqli.readObject(); assertTrue(hero.equals(o)); }
Example #21
Source File: BrokeredConnection40.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
public Struct createStruct(String typeName, Object[] attributes) throws SQLException { try { return getRealConnection().createStruct (typeName, attributes); } catch (SQLException sqle) { notifyException(sqle); throw sqle; } }
Example #22
Source File: JdbcTypeJavaClassMappings.java From lams with GNU General Public License v2.0 | 5 votes |
private static ConcurrentHashMap<Class, Integer> buildJavaClassToJdbcTypeCodeMappings() { final ConcurrentHashMap<Class, Integer> workMap = new ConcurrentHashMap<>(); // these mappings are the ones outlined specifically in the spec workMap.put( String.class, Types.VARCHAR ); workMap.put( BigDecimal.class, Types.NUMERIC ); workMap.put( BigInteger.class, Types.NUMERIC ); workMap.put( Boolean.class, Types.BIT ); workMap.put( Short.class, Types.SMALLINT ); workMap.put( Integer.class, Types.INTEGER ); workMap.put( Long.class, Types.BIGINT ); workMap.put( Float.class, Types.REAL ); workMap.put( Double.class, Types.DOUBLE ); workMap.put( byte[].class, Types.LONGVARBINARY ); workMap.put( java.sql.Date.class, Types.DATE ); workMap.put( Time.class, Types.TIME ); workMap.put( Timestamp.class, Types.TIMESTAMP ); workMap.put( Blob.class, Types.BLOB ); workMap.put( Clob.class, Types.CLOB ); workMap.put( Array.class, Types.ARRAY ); workMap.put( Struct.class, Types.STRUCT ); workMap.put( Ref.class, Types.REF ); workMap.put( Class.class, Types.JAVA_OBJECT ); workMap.put( RowId.class, Types.ROWID ); workMap.put( SQLXML.class, Types.SQLXML ); // additional "common sense" registrations workMap.put( Character.class, Types.CHAR ); workMap.put( char[].class, Types.VARCHAR ); workMap.put( Character[].class, Types.VARCHAR ); workMap.put( Byte[].class, Types.LONGVARBINARY ); workMap.put( java.util.Date.class, Types.TIMESTAMP ); workMap.put( Calendar.class, Types.TIMESTAMP ); return workMap; }
Example #23
Source File: BrokeredConnection40.java From spliceengine with GNU Affero General Public License v3.0 | 5 votes |
public Struct createStruct(String typeName, Object[] attributes) throws SQLException { try { return getRealConnection().createStruct (typeName, attributes); } catch (SQLException sqle) { notifyException(sqle); throw sqle; } }
Example #24
Source File: DataTypeTuple.java From ClickHouse-Native-JDBC with Apache License 2.0 | 5 votes |
@Override public Object[] deserializeBinaryBulk(int rows, BinaryDeserializer deserializer) throws SQLException, IOException { Object[][] rowsWithElems = getRowsWithElems(rows, deserializer); Struct[] rowsData = new Struct[rows]; for (int row = 0; row < rows; row++) { Object[] elemsData = new Object[nestedTypes.length]; for (int elemIndex = 0; elemIndex < nestedTypes.length; elemIndex++) { elemsData[elemIndex] = rowsWithElems[elemIndex][row]; } rowsData[row] = new ClickHouseStruct("Tuple", elemsData); } return rowsData; }
Example #25
Source File: NetConnection40.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
public Struct createStruct(String typeName, Object[] attributes) throws SQLException { throw SQLExceptionFactory.notImplemented ("createStruct(String,Object[])"); }
Example #26
Source File: EmbedConnection40.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
public Struct createStruct(String typeName, Object[] attributes) throws SQLException { throw Util.notImplemented(); }
Example #27
Source File: JdbcTypeHelper.java From SimpleFlatMapper with MIT License | 4 votes |
public static Class<?> toJavaType(int sqlType, Type propertyType) { switch (sqlType) { case Types.ARRAY: return Array.class; case Types.CHAR: case Types.VARCHAR: case Types.LONGNVARCHAR: return String.class; case Types.NUMERIC: case Types.DECIMAL: return BigDecimal.class; case Types.BIT: return boolean.class; case Types.TINYINT: return byte.class; case Types.SMALLINT: return short.class; case Types.INTEGER: return int.class; case Types.BIGINT: return long.class; case Types.REAL: return float.class; case Types.FLOAT: case Types.DOUBLE: return double.class; case Types.BINARY: case Types.VARBINARY: case Types.LONGVARBINARY: return byte[].class; case Types.DATE: return Date.class; case Types.TIME: return Time.class; case Types.TIMESTAMP: return Timestamp.class; case Types.CLOB: return Clob.class; case Types.BLOB: return Blob.class; case Types.STRUCT: return Struct.class; case Types.REF: return Ref.class; //IFJAVA8_START case Types.TIME_WITH_TIMEZONE: return OffsetTime.class; case Types.TIMESTAMP_WITH_TIMEZONE: return OffsetDateTime.class; //IFJAVA8_END } Class<?> defaultSqlType = javaTypeToSqlType.get(TypeHelper.toClass(propertyType).getName()); if (defaultSqlType != null) { return defaultSqlType; } return Object.class; }
Example #28
Source File: SimulateConnection.java From Agent-Benchmarks with Apache License 2.0 | 4 votes |
@Override public Struct createStruct(String typeName, Object[] attributes) throws SQLException { return null; }
Example #29
Source File: JdbcPoolConnection.java From XPagesExtensionLibrary with Apache License 2.0 | 4 votes |
@Override public Struct createStruct(String typeName, Object[] attributes) throws SQLException { return connection.createStruct(typeName, attributes); }
Example #30
Source File: Connection.java From Tomcat7.0.67 with Apache License 2.0 | 4 votes |
@Override public Struct createStruct(String typeName, Object[] attributes) throws SQLException { return null; }