public PreparedStatement getNativePreparedStatement(PreparedStatement ps) throws SQLException { return (PreparedStatement) ps.unwrap(PreparedStatement.class); }
@Override public <T> T unwrap(Class<T> iface) throws SQLException { return rawStatement.unwrap(iface); }
/** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override public <T> T unwrap(Class<T> iface) throws SQLException { if (iface == PreparedStatementExImpl.class || iface == PreparedStatementEx.class) return (T)this; return delegate.unwrap(iface); }
@Override public <T> T unwrap(Class<T> iface) throws SQLException { return rawStatement.unwrap(iface); }
public static void setRowPrefetch(PreparedStatement stmt, int value) throws SQLException { OracleStatement oracleStmt = stmt.unwrap(OracleStatement.class); if (oracleStmt != null) { oracleStmt.setRowPrefetch(value); } }
public static OraclePreparedStatement unwrapInternal(PreparedStatement stmt) throws SQLException { if (stmt instanceof OraclePreparedStatement) { return (OraclePreparedStatement) stmt; } OraclePreparedStatement unwrapped = stmt.unwrap(OraclePreparedStatement.class); if (unwrapped == null) { LOG.error("can not unwrap statement : " + stmt.getClass()); } return unwrapped; }
public static int getRowPrefetch(PreparedStatement stmt) throws SQLException { OracleStatement oracleStmt = stmt.unwrap(OracleStatement.class); if (oracleStmt == null) { return -1; } return oracleStmt.getRowPrefetch(); }
@Override public PreparedStatement getPreparedStatement(Connection connection, String sql) throws SQLException { PreparedStatement statement = connection.prepareStatement(sql); if (statement.isWrapperFor(Statement.class)) { statement.unwrap(Statement.class).enableStreamingResults(); } return statement; }
/** */ private static Command extractCommand(PreparedStatement stmt) { try { return COMMAND.get(stmt.unwrap(JdbcPreparedStatement.class)); } catch (SQLException e) { throw new IgniteSQLException(e); } }
/** * Get cached prepared statement (if any). * * @param c Connection. * @param sql SQL. * @return Prepared statement or {@code null}. * @throws SQLException On error. */ @Nullable public PreparedStatement cachedPreparedStatement(Connection c, String sql) throws SQLException { H2StatementCache cache = statementCacheForThread(); H2CachedStatementKey key = new H2CachedStatementKey(c.getSchema(), sql); PreparedStatement stmt = cache.get(key); if (stmt != null && !stmt.isClosed() && !stmt.unwrap(JdbcStatement.class).isCancelled() && !GridSqlQueryParser.prepared(stmt).needRecompile()) { assert stmt.getConnection() == c; return stmt; } return null; }
/** * @throws Exception If failed. */ @Test public void testStoringMeta() throws Exception { PreparedStatement stmt = stmt(); PreparedStatementEx wrapped = stmt.unwrap(PreparedStatementEx.class); wrapped.putMeta(0, "0"); assertEquals("0", wrapped.meta(0)); }
/** * Initialises MVCC filter and returns MVCC query tracker if needed. * @param stmt Prepared statement. * @param startTx Start transaction flag. * @return MVCC query tracker or {@code null} if MVCC is disabled for involved caches. */ private MvccQueryTracker mvccTracker(PreparedStatement stmt, boolean startTx) throws IgniteCheckedException { boolean mvccEnabled; GridCacheContext mvccCacheCtx = null; try { if (stmt.isWrapperFor(PreparedStatementEx.class)) { PreparedStatementEx stmtEx = stmt.unwrap(PreparedStatementEx.class); Boolean mvccState = stmtEx.meta(MVCC_STATE); mvccEnabled = mvccState != null ? mvccState : checkMvcc(stmt); if (mvccEnabled) { Integer cacheId = stmtEx.meta(MVCC_CACHE_ID); assert cacheId != null; mvccCacheCtx = ctx.cache().context().cacheContext(cacheId); assert mvccCacheCtx != null; } } else mvccEnabled = checkMvcc(stmt); } catch (SQLException e) { throw new IgniteSQLException(e); } assert !mvccEnabled || mvccCacheCtx != null; return mvccEnabled ? MvccUtils.mvccTracker(mvccCacheCtx, startTx) : null; }
/** * @throws Exception If failed. */ @Test public void testStoringMoreMetaKeepsExisting() throws Exception { PreparedStatement stmt = stmt(); PreparedStatementEx wrapped = stmt.unwrap(PreparedStatementEx.class); wrapped.putMeta(0, "0"); wrapped.putMeta(1, "1"); assertEquals("0", wrapped.meta(0)); assertEquals("1", wrapped.meta(1)); }
PreparedStatementEx stmtEx = stmt.unwrap(PreparedStatementEx.class);
public static OraclePreparedStatement unwrapInternal(PreparedStatement stmt) throws SQLException { if (stmt instanceof OraclePreparedStatement) { return (OraclePreparedStatement) stmt; } OraclePreparedStatement unwrapped = stmt.unwrap(OraclePreparedStatement.class); if (unwrapped == null) { LOG.error("can not unwrap statement : " + stmt.getClass()); } return unwrapped; }
/** * Returns the opitmized query plan used by phoenix for executing the sql. * @param stmt to return the plan for * @throws SQLException */ public static QueryPlan getOptimizedQueryPlan(PreparedStatement stmt) throws SQLException { checkNotNull(stmt); QueryPlan plan = stmt.unwrap(PhoenixPreparedStatement.class).optimizeQuery(); return plan; }
final CallableStatement cs = st.unwrap( CallableStatement.class );
private static QueryPlan getQueryPlan(Connection conn,String sql) throws SQLException { PhoenixPreparedStatement statement = conn.prepareStatement(sql).unwrap(PhoenixPreparedStatement.class); QueryPlan queryPlan = statement.optimizeQuery(sql); queryPlan.iterator(); return queryPlan; }
private PreparedStatement loadDataAndPrepareQuery(int timeoutMs, int timeoutSecs) throws Exception, SQLException { Properties props = new Properties(); props.setProperty(QueryServices.THREAD_TIMEOUT_MS_ATTRIB, String.valueOf(timeoutMs)); Connection conn = DriverManager.getConnection(getUrl(), props); PreparedStatement ps = conn.prepareStatement("SELECT * FROM " + tableName); PhoenixStatement phoenixStmt = ps.unwrap(PhoenixStatement.class); assertEquals(timeoutMs, phoenixStmt.getQueryTimeoutInMillis()); assertEquals(timeoutSecs, phoenixStmt.getQueryTimeout()); return ps; } }
@Test public void testZeroCustomQueryTimeout() throws Exception { // Arrange Properties connectionProperties = new Properties(); connectionProperties.setProperty("phoenix.query.timeoutMs", "0"); Connection connection = DriverManager.getConnection(getUrl(), connectionProperties); PreparedStatement stmt = connection.prepareStatement("SELECT * FROM " + ATABLE); PhoenixStatement phoenixStmt = stmt.unwrap(PhoenixStatement.class); // Assert assertEquals(0, stmt.getQueryTimeout()); assertEquals(0, phoenixStmt.getQueryTimeoutInMillis()); }