public SqlWindow(ResultSet rs, ValueToJooqConverterProvider valueToJooqConverterProvider, ValueToJooqDataTypeProvider valueToJooqDataTypeProvider, ScalarTypeToSqlType scalarTypeToSqlType) throws SQLException { ResultSetMetaData metaData = rs.getMetaData(); final int columnLenght = metaData.getColumnCount(); String[] columns = new String[columnLenght]; SubdocValueConverter<?, ?>[] converters = new SubdocValueConverter[columnLenght]; for (int i = 0; i < columnLenght; i++) { int jdbcIndex = i + 1; //result sets are 1-based instead of 0-based! columns[i] = metaData.getColumnName(jdbcIndex); ScalarType scalarType = getScalarType(metaData, jdbcIndex, scalarTypeToSqlType); converters[i] = valueToJooqDataTypeProvider.getDataType(scalarType).getSubdocValueConverter(); } ImmutableList.Builder<ValueRow<ScalarValue<?>>> builder = ImmutableList.builder(); while (rs.next()) { ScalarValue[] values = new ScalarValue[columns.length]; for (int i = 0; i < columns.length; i++) { int jdbcIndex = i+1; ScalarValue<?> value = readAndTransform(rs, jdbcIndex, converters[i]); Preconditions.checkNotNull(value); values[i] = value; } builder.add(new WindowValueRow(columns, values)); } rows = builder.build().iterator(); }
@SuppressFBWarnings( value = "SQL_NONCONSTANT_STRING_PASSED_TO_EXECUTE", justification = "It is known that this command is unsafe. We need" + "to improve it as soon as we can") @Override public Iterator<ValueRow<ScalarValue<?>>> select(String query) throws UserToroException { Connection connection = getJooqConf().connectionProvider().acquire(); try { try (Statement st = connection.createStatement()) { //This is executed to force read only executions st.executeUpdate("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE"); st.executeUpdate("SET TRANSACTION READ ONLY"); st.executeUpdate("SET TRANSACTION DEFERRABLE"); //Once the first query is executed, transacion level is immutable ResultSet fakeRS = st.executeQuery("SELECT 1"); fakeRS.close(); try (ResultSet rs = st.executeQuery(query)) { return new SqlWindow(rs, getDatabaseInterface().getValueToJooqConverterProvider(), getDatabaseInterface().getValueToJooqDataTypeProvider(), getDatabaseInterface().getScalarTypeToSqlType()); } } catch (SQLException ex) { //TODO: Change exception throw new UserToroException(ex); } } finally { getJooqConf().connectionProvider().release(connection); } }
@SuppressFBWarnings( value = "SQL_NONCONSTANT_STRING_PASSED_TO_EXECUTE", justification = "It is known that this command is unsafe. We need" + "to improve it as soon as we can") @Override public Iterator<ValueRow<ScalarValue<?>>> select(String query) throws UserToroException { Connection connection = getJooqConf().connectionProvider().acquire(); try { try (Statement st = connection.createStatement()) { //This is executed to force read only executions st.executeUpdate("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE"); st.executeUpdate("SET TRANSACTION READ ONLY"); st.executeUpdate("SET TRANSACTION DEFERRABLE"); //Once the first query is executed, transacion level is immutable ResultSet fakeRS = st.executeQuery("SELECT 1"); fakeRS.close(); try (ResultSet rs = st.executeQuery(query)) { return new SqlWindow(rs, getDatabaseInterface().getValueToJooqConverterProvider(), getDatabaseInterface().getValueToJooqDataTypeProvider(), getDatabaseInterface().getScalarTypeToSqlType()); } } catch (SQLException ex) { //TODO: Change exception throw new UserToroException(ex); } } finally { getJooqConf().connectionProvider().release(connection); } }
@SuppressFBWarnings( value = "SQL_NONCONSTANT_STRING_PASSED_TO_EXECUTE", justification = "It is known that this command is unsafe. We need" + "to improve it as soon as we can") @Override public Iterator<ValueRow<ScalarValue<?>>> select(String query) throws UserToroException { Connection connection = getJooqConf().connectionProvider().acquire(); try { try (Statement st = connection.createStatement()) { //TODO: MySQL wine about a java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed. // This is due to a check in mysql driver that check first statement character is 'S' but we are also using CALL // This should be fixed in the driver. Please fill a bug at http://bugs.mysql.com. //st.executeUpdate("SET TRANSACTION READ ONLY"); ResultSet fakeRS = st.executeQuery("SELECT 1"); fakeRS.close(); try (ResultSet rs = st.executeQuery(query)) { return new SqlWindow(rs, getDatabaseInterface().getValueToJooqConverterProvider(), getDatabaseInterface().getValueToJooqDataTypeProvider(), getDatabaseInterface().getScalarTypeToSqlType()); } } catch (SQLException ex) { //TODO: Change exception throw new UserToroException(ex); } } finally { getJooqConf().connectionProvider().release(connection); } }