org.apache.calcite.avatica.AvaticaPreparedStatement Java Examples
The following examples show how to use
org.apache.calcite.avatica.AvaticaPreparedStatement.
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: CalciteJdbc41Factory.java From Quicksql with MIT License | 5 votes |
public AvaticaPreparedStatement newPreparedStatement( AvaticaConnection connection, Meta.StatementHandle h, Meta.Signature signature, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { return new CalciteJdbc41PreparedStatement( (CalciteConnectionImpl) connection, h, (CalcitePrepare.CalciteSignature) signature, resultSetType, resultSetConcurrency, resultSetHoldability); }
Example #2
Source File: QuicksqlJdbc41Factory.java From Quicksql with MIT License | 5 votes |
public AvaticaPreparedStatement newPreparedStatement( AvaticaConnection connection, Meta.StatementHandle h, Signature signature, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { return new QuickSqlJdbc41PreparedStatement( (QuicksqlConnectionImpl) connection, h, signature, resultSetType, resultSetConcurrency, resultSetHoldability); }
Example #3
Source File: JdbcMetaTest.java From calcite-avatica with Apache License 2.0 | 5 votes |
@Test public void testPrepareSetsMaxRows() throws Exception { final String id = UUID.randomUUID().toString(); final String sql = "SELECT * FROM FOO"; final int maxRows = 500; final ConnectionHandle ch = new ConnectionHandle(id); final AtomicInteger statementIdGenerator = new AtomicInteger(0); JdbcMeta meta = Mockito.mock(JdbcMeta.class); Connection connection = Mockito.mock(Connection.class); PreparedStatement statement = Mockito.mock(PreparedStatement.class); ResultSetMetaData resultSetMetaData = Mockito.mock(ResultSetMetaData.class); ParameterMetaData parameterMetaData = Mockito.mock(ParameterMetaData.class); @SuppressWarnings("unchecked") Cache<Integer, StatementInfo> statementCache = (Cache<Integer, StatementInfo>) Mockito.mock(Cache.class); Mockito.when(meta.getStatementIdGenerator()).thenReturn(statementIdGenerator); Mockito.when(meta.getStatementCache()).thenReturn(statementCache); Mockito.when(meta.getConnection(id)).thenReturn(connection); Mockito.when(connection.prepareStatement(sql)).thenReturn(statement); Mockito.when(statement.isWrapperFor(AvaticaPreparedStatement.class)).thenReturn(false); Mockito.when(statement.getMetaData()).thenReturn(resultSetMetaData); Mockito.when(statement.getParameterMetaData()).thenReturn(parameterMetaData); // Call the real methods Mockito.doCallRealMethod().when(meta).setMaxRows(statement, maxRows); Mockito.doCallRealMethod().when(meta).prepare(ch, sql, maxRows); meta.prepare(ch, sql, maxRows); Mockito.verify(statement).setMaxRows(maxRows); }
Example #4
Source File: QuarkJdbc41Factory.java From quark with Apache License 2.0 | 5 votes |
@Override public AvaticaPreparedStatement newPreparedStatement(AvaticaConnection connection, Meta.StatementHandle h, Meta.Signature signature, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { throw new SQLFeatureNotSupportedException(); }
Example #5
Source File: QuarkConnectionImpl.java From quark with Apache License 2.0 | 5 votes |
@Override public AvaticaPreparedStatement prepareStatement( String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { AvaticaPreparedStatement preparedStatement = (AvaticaPreparedStatement) super .prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability); server.addStatement(this, preparedStatement.handle); //server.getStatement(preparedStatement.handle).setSignature(signature); return preparedStatement; }
Example #6
Source File: CalciteJdbc41Factory.java From calcite with Apache License 2.0 | 5 votes |
public AvaticaPreparedStatement newPreparedStatement( AvaticaConnection connection, Meta.StatementHandle h, Meta.Signature signature, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { return new CalciteJdbc41PreparedStatement( (CalciteConnectionImpl) connection, h, (CalcitePrepare.CalciteSignature) signature, resultSetType, resultSetConcurrency, resultSetHoldability); }
Example #7
Source File: KylinJdbcFactory.java From kylin-on-parquet-v2 with Apache License 2.0 | 4 votes |
@Override public AvaticaPreparedStatement newPreparedStatement(AvaticaConnection connection, StatementHandle h, Signature signature, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { return new KylinPreparedStatement((KylinConnection) connection, h, signature, resultSetType, resultSetConcurrency, resultSetHoldability); }
Example #8
Source File: JdbcMeta.java From calcite-avatica with Apache License 2.0 | 4 votes |
@Override public ExecuteResult execute(StatementHandle h, List<TypedValue> parameterValues, int maxRowsInFirstFrame) throws NoSuchStatementException { try { if (MetaImpl.checkParameterValueHasNull(parameterValues)) { throw new SQLException("exception while executing query: unbound parameter"); } final StatementInfo statementInfo = statementCache.getIfPresent(h.id); if (null == statementInfo) { throw new NoSuchStatementException(h); } final List<MetaResultSet> resultSets; final PreparedStatement preparedStatement = (PreparedStatement) statementInfo.statement; if (parameterValues != null) { for (int i = 0; i < parameterValues.size(); i++) { TypedValue o = parameterValues.get(i); preparedStatement.setObject(i + 1, o.toJdbc(calendar)); } } if (preparedStatement.execute()) { final Signature signature2; if (preparedStatement.isWrapperFor(AvaticaPreparedStatement.class)) { signature2 = h.signature; } else { h.signature = signature(preparedStatement.getMetaData(), preparedStatement.getParameterMetaData(), h.signature.sql, Meta.StatementType.SELECT); signature2 = h.signature; } // Make sure we set this for subsequent fetch()'s to find the result set. statementInfo.setResultSet(preparedStatement.getResultSet()); if (statementInfo.getResultSet() == null) { resultSets = Collections.<MetaResultSet>singletonList( JdbcResultSet.empty(h.connectionId, h.id, signature2)); } else { resultSets = Collections.<MetaResultSet>singletonList( JdbcResultSet.create(h.connectionId, h.id, statementInfo.getResultSet(), maxRowsInFirstFrame, signature2)); } } else { resultSets = Collections.<MetaResultSet>singletonList( JdbcResultSet.count(h.connectionId, h.id, preparedStatement.getUpdateCount())); } return new ExecuteResult(resultSets); } catch (SQLException e) { throw propagate(e); } }
Example #9
Source File: QuarkMetaImpl.java From quark with Apache License 2.0 | 4 votes |
@Override public ExecuteResult execute(StatementHandle h, List<TypedValue> parameterValues, long maxRowCount) { try { if (MetaImpl.checkParameterValueHasNull(parameterValues)) { throw new SQLException("exception while executing query: unbound parameter"); } final StatementInfo statementInfo = Objects.requireNonNull( statementCache.getIfPresent(h.id), "Statement not found, potentially expired. " + h); final List<MetaResultSet> resultSets = new ArrayList<>(); final PreparedStatement preparedStatement = (PreparedStatement) statementInfo.statement; if (parameterValues != null) { for (int i = 0; i < parameterValues.size(); i++) { TypedValue o = parameterValues.get(i); preparedStatement.setObject(i + 1, o.toJdbc(calendar)); } } if (preparedStatement.execute()) { final Meta.Frame frame; final Signature signature2; if (preparedStatement.isWrapperFor(AvaticaPreparedStatement.class)) { signature2 = h.signature; } else { h.signature = signature(preparedStatement.getMetaData(), preparedStatement.getParameterMetaData(), h.signature.sql, Meta.StatementType.SELECT); signature2 = h.signature; } statementInfo.resultSet = preparedStatement.getResultSet(); if (statementInfo.resultSet == null) { frame = Frame.EMPTY; resultSets.add(QuarkMetaResultSet.empty(h.connectionId, h.id, signature2)); } else { resultSets.add( QuarkMetaResultSet.create(h.connectionId, h.id, statementInfo.resultSet, maxRowCount, signature2)); } } else { resultSets.add( QuarkMetaResultSet.count( h.connectionId, h.id, preparedStatement.getUpdateCount())); } return new ExecuteResult(resultSets); } catch (SQLException e) { throw propagate(e); } }
Example #10
Source File: KylinJdbcFactory.java From kylin with Apache License 2.0 | 4 votes |
@Override public AvaticaPreparedStatement newPreparedStatement(AvaticaConnection connection, StatementHandle h, Signature signature, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { return new KylinPreparedStatement((KylinConnection) connection, h, signature, resultSetType, resultSetConcurrency, resultSetHoldability); }