@Override public void setQueryTimeout( int milliseconds ) throws SQLException { throwIfClosed(); if ( milliseconds < 0 ) { throw new InvalidParameterSqlException( "Invalid (negative) \"milliseconds\" parameter to setQueryTimeout(...)" + " (" + milliseconds + ")" ); } else { if ( 0 != milliseconds ) { throw new SQLFeatureNotSupportedException( "Setting network timeout is not supported." ); } } }
@Test public void lessThanOrEqualTest() throws IOException, SqlParseException, SQLFeatureNotSupportedException { int someAge = 25; SearchHits response = query(String.format("SELECT * FROM %s WHERE age <= %s LIMIT 1000", TEST_INDEX, someAge)); SearchHit[] hits = response.getHits(); boolean isEqualFound = false; for(SearchHit hit : hits) { int age = (int) hit.getSource().get("age"); assertThat(age, lessThanOrEqualTo(someAge)); if(age == someAge) isEqualFound = true; } Assert.assertTrue(String.format("at least one of the documents need to contains age equal to %s", someAge), isEqualFound); }
/** Tests that "not supported" has priority over possible "type not supported" * check. */ @Test( expected = SQLFeatureNotSupportedException.class ) public void testParamSettingWhenUnsupportedTypeSaysUnsupported() throws SQLException { PreparedStatement prepStmt = connection.prepareStatement( "VALUES 1" ); try { prepStmt.setClob( 2, (Clob) null ); } catch ( final SQLFeatureNotSupportedException e ) { assertThat( "Check whether params.-unsupported wording changed or checks changed.", e.toString(), PARAMETERS_NOT_SUPPORTED_MSG_MATCHER ); throw e; } }
@Override public boolean othersUpdatesAreVisible(int type) throws SQLException { throwIfClosed(); try { return super.othersUpdatesAreVisible(type); } catch (RuntimeException e) { if ("todo: implement this method".equals(e.getMessage())) { throw new SQLFeatureNotSupportedException( "othersUpdatesAreVisible(int) is not supported", e); } else { throw new SQLException(e.getMessage(), e); } } }
@Override public void setNetworkTimeout( Executor executor, int milliseconds ) throws AlreadyClosedSqlException, JdbcApiSqlException, SQLFeatureNotSupportedException { checkNotClosed(); if ( null == executor ) { throw new InvalidParameterSqlException( "Invalid (null) \"executor\" parameter to setNetworkTimeout(...)" ); } else if ( milliseconds < 0 ) { throw new InvalidParameterSqlException( "Invalid (negative) \"milliseconds\" parameter to setNetworkTimeout(...)" + " (" + milliseconds + ")" ); } else { if ( 0 != milliseconds ) { throw new SQLFeatureNotSupportedException( "Setting network timeout is not supported." ); } } }
@Test public void topHitTest_WithInclude() throws IOException, SqlParseException, SQLFeatureNotSupportedException { Aggregations result = query(String.format("select topHits('size'=3,age='desc',include=age) from %s/account group by gender ", TEST_INDEX)); List<Terms.Bucket> buckets = ((Terms) (result.asList().get(0))).getBuckets(); for (Terms.Bucket bucket : buckets){ InternalSearchHits hits = (InternalSearchHits) ((InternalTopHits) bucket.getAggregations().asList().get(0)).getHits(); for(SearchHit hit: hits ){ Set<String> fields = hit.sourceAsMap().keySet(); Assert.assertEquals(1,fields.size()); Assert.assertEquals("age",fields.toArray()[0]); } } }
@Override public int getResultSetType() throws SQLException { throwIfClosed(); try { return super.getResultSetType(); } catch (UnsupportedOperationException e) { throw new SQLFeatureNotSupportedException(e.getMessage(), e); } }
@Override public void updateBlob( String columnLabel, Blob x ) throws SQLException { throwIfClosed(); try { super.updateBlob( columnLabel, x ); } catch (UnsupportedOperationException e) { throw new SQLFeatureNotSupportedException(e.getMessage(), e); } }
@Override public void updateNCharacterStream( int columnIndex, Reader x, long length ) throws SQLException { throwIfClosed(); try { super.updateNCharacterStream( columnIndex, x, length ); } catch (UnsupportedOperationException e) { throw new SQLFeatureNotSupportedException(e.getMessage(), e); } }
@Override protected DataAccessException doTranslate(String task, String sql, SQLException ex) { if (ex instanceof SQLTransientException) { if (ex instanceof SQLTransientConnectionException) { return new TransientDataAccessResourceException(buildMessage(task, sql, ex), ex); } else if (ex instanceof SQLTransactionRollbackException) { return new ConcurrencyFailureException(buildMessage(task, sql, ex), ex); } else if (ex instanceof SQLTimeoutException) { return new QueryTimeoutException(buildMessage(task, sql, ex), ex); } } else if (ex instanceof SQLNonTransientException) { if (ex instanceof SQLNonTransientConnectionException) { return new DataAccessResourceFailureException(buildMessage(task, sql, ex), ex); } else if (ex instanceof SQLDataException) { return new DataIntegrityViolationException(buildMessage(task, sql, ex), ex); } else if (ex instanceof SQLIntegrityConstraintViolationException) { return new DataIntegrityViolationException(buildMessage(task, sql, ex), ex); } else if (ex instanceof SQLInvalidAuthorizationSpecException) { return new PermissionDeniedDataAccessException(buildMessage(task, sql, ex), ex); } else if (ex instanceof SQLSyntaxErrorException) { return new BadSqlGrammarException(task, sql, ex); } else if (ex instanceof SQLFeatureNotSupportedException) { return new InvalidDataAccessApiUsageException(buildMessage(task, sql, ex), ex); } } else if (ex instanceof SQLRecoverableException) { return new RecoverableDataAccessException(buildMessage(task, sql, ex), ex); } // Fallback to Spring's own SQL state translation... return null; }
@Override public void updateClob( String columnLabel, Reader reader, long length ) throws SQLException { throwIfClosed(); try { super.updateClob( columnLabel, reader, length ); } catch (UnsupportedOperationException e) { throw new SQLFeatureNotSupportedException(e.getMessage(), e); } }
@Override public int executeUpdate( String sql, String[] columnNames ) throws SQLException { throwIfClosed(); try { return super.executeUpdate( sql, columnNames ); } catch (UnsupportedOperationException e) { throw new SQLFeatureNotSupportedException(e.getMessage(), e); } }
@Test public void statsTest() throws IOException, SqlParseException, SQLFeatureNotSupportedException { Aggregations result = query(String.format("SELECT STATS(age) FROM %s/account", TEST_INDEX)); Stats stats = result.get("STATS(age)"); Assert.assertEquals(1000, stats.getCount()); assertThat(stats.getSum(), equalTo(30171.0)); assertThat(stats.getMin(), equalTo(20.0)); assertThat(stats.getMax(), equalTo(40.0)); assertThat(stats.getAvg(), equalTo(30.171)); }
@Override public void updateNClob( String columnLabel, Reader reader ) throws SQLException { throwIfClosed(); try { super.updateNClob( columnLabel, reader ); } catch (UnsupportedOperationException e) { throw new SQLFeatureNotSupportedException(e.getMessage(), e); } }
/** Tests that setQueryTimeout(...) rejects setting a timeout. */ @Test( expected = SQLFeatureNotSupportedException.class ) public void testSetQueryTimeoutRejectsTimeoutRequest() throws SQLException { try { statement.setQueryTimeout( 1_000 ); } catch ( SQLFeatureNotSupportedException e ) { // Check exception for some mention of query timeout: assertThat( e.getMessage(), anyOf( containsString( "Timeout" ), containsString( "timeout" ) ) ); throw e; } }
@Override public void setPoolable(boolean poolable) throws SQLException { throwIfClosed(); try { super.setPoolable(poolable); } catch (UnsupportedOperationException e) { throw new SQLFeatureNotSupportedException(e.getMessage(), e); } }
private void joinNoConditionAndNoWhere(boolean useNestedLoops) throws SqlParseException, SQLFeatureNotSupportedException, IOException { String query = String.format("select c.name.firstname,c.parents.father , h.hname,h.words from %s/gotCharacters c " + "JOIN %s/gotHouses h ",TEST_INDEX,TEST_INDEX); if(useNestedLoops) query = query.replace("select","select /*! USE_NL*/ "); SearchHit[] hits = joinAndGetHits(query); Assert.assertEquals(12, hits.length); }
@Override public void updateDouble( int columnIndex, double x ) throws SQLException { throwIfClosed(); try { super.updateDouble( columnIndex, x ); } catch (UnsupportedOperationException e) { throw new SQLFeatureNotSupportedException(e.getMessage(), e); } }
@Test public void geoBounds() throws SQLFeatureNotSupportedException, SqlParseException { Aggregations result = query(String.format("SELECT * FROM %s/location GROUP BY geo_bounds(field='center',alias='bounds') ", TEST_INDEX)); InternalGeoBounds bounds = result.get("bounds"); Assert.assertEquals(0.5,bounds.bottomRight().getLat(),0.001); Assert.assertEquals(105.0,bounds.bottomRight().getLon(),0.001); Assert.assertEquals(5.0,bounds.topLeft().getLat(),0.001); Assert.assertEquals(100.5,bounds.topLeft().getLon(),0.001); }
/** * Tests fix for Bug#56122 - JDBC4 functionality failure when using replication connections. */ public void testBug56122() throws Exception { for (final Connection testConn : new Connection[] { this.conn, getFailoverConnection(), getLoadBalancedConnection(), getMasterSlaveReplicationConnection() }) { testConn.createClob(); testConn.createBlob(); testConn.createNClob(); testConn.createSQLXML(); testConn.isValid(12345); testConn.setClientInfo(new Properties()); testConn.setClientInfo("NAME", "VALUE"); testConn.getClientInfo(); testConn.getClientInfo("CLIENT"); assertThrows(SQLFeatureNotSupportedException.class, new Callable<Void>() { public Void call() throws Exception { testConn.createArrayOf("A_TYPE", null); return null; } }); assertThrows(SQLFeatureNotSupportedException.class, new Callable<Void>() { public Void call() throws Exception { testConn.createStruct("A_TYPE", null); return null; } }); } }
@Override public void updateObject( String columnLabel, Object x, int scaleOrLength ) throws SQLException { throwIfClosed(); try { super.updateObject( columnLabel, x, scaleOrLength ); } catch (UnsupportedOperationException e) { throw new SQLFeatureNotSupportedException(e.getMessage(), e); } }
@Override public void updateCharacterStream( String columnLabel, Reader reader, int length ) throws SQLException { throwIfClosed(); try { super.updateCharacterStream( columnLabel, reader, length ); } catch (UnsupportedOperationException e) { throw new SQLFeatureNotSupportedException(e.getMessage(), e); } }
@Override public void setCursorName(String name) throws SQLException { throwIfClosed(); try { super.setCursorName(name); } catch (UnsupportedOperationException e) { throw new SQLFeatureNotSupportedException(e.getMessage(), e); } }
@Test public void inTest() throws IOException, SqlParseException, SQLFeatureNotSupportedException{ SearchHits response = query(String.format("SELECT age FROM %s/phrase WHERE age IN (20, 22) LIMIT 1000", TEST_INDEX)); SearchHit[] hits = response.getHits(); for(SearchHit hit : hits) { int age = (int) hit.getSource().get("age"); assertThat(age, isOneOf(20, 22)); } }
@Override public void commit() throws SQLException { throwIfClosed(); if ( getAutoCommit() ) { throw new JdbcApiSqlException( "Can't call commit() in auto-commit mode." ); } else { // (Currently not reachable.) throw new SQLFeatureNotSupportedException( "Connection.commit() is not supported. (Dremio is not transactional.)" ); } }
@Override public int executeUpdate(String sql, String columnNames[]) throws SQLException { throwIfClosed(); try { return super.executeUpdate(sql, columnNames); } catch (UnsupportedOperationException e) { throw new SQLFeatureNotSupportedException(e.getMessage(), e); } }
@Override public void clearBatch() throws SQLException { throwIfClosed(); try { super.clearBatch(); } catch (UnsupportedOperationException e) { throw new SQLFeatureNotSupportedException(e.getMessage(), e); } }
@Override public void updateBinaryStream( int columnIndex, InputStream x ) throws SQLException { throwIfClosed(); try { super.updateBinaryStream( columnIndex, x ); } catch (UnsupportedOperationException e) { throw new SQLFeatureNotSupportedException(e.getMessage(), e); } }
@Override public int getMaxFieldSize() throws SQLException { throwIfClosed(); try { return super.getMaxFieldSize(); } catch (UnsupportedOperationException e) { throw new SQLFeatureNotSupportedException(e.getMessage(), e); } }
@Override public ResultSet getGeneratedKeys() throws SQLException { throwIfClosed(); try { return super.getGeneratedKeys(); } catch (UnsupportedOperationException e) { throw new SQLFeatureNotSupportedException(e.getMessage(), e); } }
@Override public Properties getClientInfo() throws SQLException { throwIfClosed(); try { return super.getClientInfo(); } catch (UnsupportedOperationException e) { throw new SQLFeatureNotSupportedException(e.getMessage(), e); } }
@Test public void lessThanTest() throws IOException, SqlParseException, SQLFeatureNotSupportedException { int someAge = 25; SearchHits response = query(String.format("SELECT * FROM %s WHERE age < %s LIMIT 1000", TEST_INDEX, someAge)); SearchHit[] hits = response.getHits(); for(SearchHit hit : hits) { int age = (int) hit.getSource().get("age"); assertThat(age, lessThan(someAge)); } }
@Test public void complexObjectReutrnField() throws IOException, SqlParseException, SQLFeatureNotSupportedException{ SearchHits response = query(String.format("SELECT parents.father FROM %s/gotCharacters where name.firstname = 'Brandon' LIMIT 1000", TEST_INDEX)); Assert.assertEquals(1, response.getTotalHits()); Map<String, Object> sourceAsMap = response.getHits()[0].sourceAsMap(); Assert.assertEquals("Eddard",((HashMap<String,Object>)sourceAsMap.get("parents")).get("father")); }
@Test public void testRollback() throws Exception { thrown.expect(SQLFeatureNotSupportedException.class); AbstractCloudSpannerConnection testSubject; Savepoint savepoint = null; // default test testSubject = createTestSubject(); testSubject.rollback(savepoint); }
private void hintLimits_firstNullSecondLimit(boolean useNestedLoops) throws SqlParseException, SQLFeatureNotSupportedException, IOException { String query = String.format("select /*! JOIN_TABLES_LIMIT(null,2) */ c.name.firstname,c.parents.father , h.hname,h.words from %s/gotCharacters c " + "JOIN %s/gotHouses h ",TEST_INDEX,TEST_INDEX); if(useNestedLoops) query = query.replace("select","select /*! USE_NL*/ "); SearchHit[] hits = joinAndGetHits(query); Assert.assertEquals(8, hits.length); }
@Override public void updateRowId( int columnIndex, RowId x ) throws SQLException { throwIfClosed(); try { super.updateRowId( columnIndex, x ); } catch (UnsupportedOperationException e) { throw new SQLFeatureNotSupportedException(e.getMessage(), e); } }
@Override public void updateClob( int columnIndex, Reader reader, long length ) throws SQLException { throwIfClosed(); try { super.updateClob( columnIndex, reader, length ); } catch (UnsupportedOperationException e) { throw new SQLFeatureNotSupportedException(e.getMessage(), e); } }
@Test public void limitTest() throws IOException, SqlParseException, SQLFeatureNotSupportedException { Aggregations result = query(String.format("SELECT COUNT(*) FROM %s/account GROUP BY age ORDER BY COUNT(*) LIMIT 5", TEST_INDEX)); Terms age = result.get("age"); assertThat(age.getBuckets().size(), equalTo(5)); }
@Test public void notLikeTest() throws IOException, SqlParseException, SQLFeatureNotSupportedException { SearchHits response = query(String.format("SELECT * FROM %s/account WHERE firstname NOT LIKE 'amb%%'", TEST_INDEX)); SearchHit[] hits = response.getHits(); // assert we got hits Assert.assertNotEquals(0, response.getTotalHits()); for (SearchHit hit : hits) { Assert.assertFalse(hit.getSource().get("firstname").toString().toLowerCase().startsWith("amb")); } }
@Test public void geoDistance() throws SQLFeatureNotSupportedException, SqlParseException, InterruptedException { SearchHits results = query(String.format("SELECT * FROM %s/location WHERE GEO_DISTANCE(center,'1km',100.5,0.500001)", TEST_INDEX)); org.junit.Assert.assertEquals(1,results.getTotalHits()); SearchHit result = results.getAt(0); Assert.assertEquals("square",result.getSource().get("description")); }