/** * Send a function call to the PostgreSQL backend. * * @param fnId Function id * @param args FastpathArguments to pass to fastpath * @return null if no data, byte[] otherwise * @throws SQLException if a database-access error occurs. */ public byte[] fastpath(int fnId, FastpathArg[] args) throws SQLException { // Turn fastpath array into a parameter list. ParameterList params = executor.createFastpathParameters(args.length); for (int i = 0; i < args.length; ++i) { args[i].populateParameter(params, i + 1); } // Run it. return executor.fastpathCall(fnId, params, connection.getAutoCommit()); }
public static byte[][] run(QueryExecutor executor, String queryString, boolean wantResults) throws SQLException { Query query = executor.createSimpleQuery(queryString); SimpleResultHandler handler = new SimpleResultHandler(); int flags = QueryExecutor.QUERY_ONESHOT | QueryExecutor.QUERY_SUPPRESS_BEGIN | QueryExecutor.QUERY_EXECUTE_AS_SIMPLE; if (!wantResults) { flags |= QueryExecutor.QUERY_NO_RESULTS | QueryExecutor.QUERY_NO_METADATA; } try { executor.execute(query, null, handler, 0, 0, flags); } finally { query.close(); } if (!wantResults) { return null; } List<byte[][]> tuples = handler.getResults(); if (tuples == null || tuples.size() != 1) { throw new PSQLException(GT.tr("An unexpected result was returned by a query."), PSQLState.CONNECTION_UNABLE_TO_CONNECT); } return tuples.get(0); }
connection.getQueryExecutor().fetch(cursor, new CursorResultHandler(), fetchRows);
@Override public PGNotification[] getNotifications(int timeoutMillis) throws SQLException { checkClosed(); getQueryExecutor().processNotifies(timeoutMillis); // Backwards-compatibility hand-holding. PGNotification[] notifications = queryExecutor.getNotifications(); return (notifications.length == 0 ? null : notifications); }
private void executeTransactionCommand(Query query) throws SQLException { int flags = QueryExecutor.QUERY_NO_METADATA | QueryExecutor.QUERY_NO_RESULTS | QueryExecutor.QUERY_SUPPRESS_BEGIN; if (prepareThreshold == 0) { flags |= QueryExecutor.QUERY_ONESHOT; } try { getQueryExecutor().execute(query, null, new TransactionCommandHandler(), 0, 0, flags); } catch (SQLException e) { // Don't retry composite queries as it might get partially executed if (query.getSubqueries() != null || !queryExecutor.willHealOnRetry(e)) { throw e; } query.close(); // retry getQueryExecutor().execute(query, null, new TransactionCommandHandler(), 0, 0, flags); } }
private void executeTransactionCommand(Query query) throws SQLException { getQueryExecutor().execute(query, null, new TransactionCommandHandler(), 0, 0, QueryExecutor.QUERY_NO_METADATA | QueryExecutor.QUERY_NO_RESULTS | QueryExecutor.QUERY_SUPPRESS_BEGIN); }
public CopyOut copyOut(String sql) throws SQLException { CopyOperation op = queryExecutor.startCopy(sql, connection.getAutoCommit()); if (op == null || op instanceof CopyOut) { return (CopyOut) op; } else { op.cancelCopy(); throw new PSQLException(GT.tr("Requested CopyOut but got {0}", op.getClass().getName()), PSQLState.WRONG_OBJECT_TYPE); } }
public void addBatch(String p_sql) throws SQLException { checkClosed(); if (preparedQuery != null) throw new PSQLException(GT.tr("Can''t use query methods that take a query string on a PreparedStatement."), PSQLState.WRONG_OBJECT_TYPE); if (batchStatements == null) { batchStatements = new ArrayList(); batchParameters = new ArrayList(); } p_sql = replaceProcessing(p_sql); batchStatements.add(connection.getQueryExecutor().createSimpleQuery(p_sql)); batchParameters.add(null); }
public PGNotification[] getNotifications() throws SQLException { checkClosed(); getQueryExecutor().processNotifies(); // Backwards-compatibility hand-holding. PGNotification[] notifications = protoConnection.getNotifications(); return (notifications.length == 0 ? null : notifications); }
public AbstractJdbc2Statement(AbstractJdbc2Connection connection, String sql, boolean isCallable, int rsType, int rsConcurrency) throws SQLException { this.connection = connection; this.lastSimpleQuery = null; String parsed_sql = replaceProcessing(sql); if (isCallable) parsed_sql = modifyJdbcCall(parsed_sql); this.preparedQuery = connection.getQueryExecutor().createParameterizedQuery(parsed_sql); this.preparedParameters = preparedQuery.createParameterList(); int inParamCount = preparedParameters.getInParameterCount() + 1; this.testReturn = new int[inParamCount]; this.functionReturnType = new int[inParamCount]; resultsettype = rsType; concurrency = rsConcurrency; }
public ParameterMetaData getParameterMetaData() throws SQLException { int flags = QueryExecutor.QUERY_ONESHOT | QueryExecutor.QUERY_DESCRIBE_ONLY | QueryExecutor.QUERY_SUPPRESS_BEGIN; StatementResultHandler handler = new StatementResultHandler(); connection.getQueryExecutor().execute(preparedQuery.query, preparedParameters, handler, 0, 0, flags); int[] oids = preparedParameters.getTypeOIDs(); if (oids != null) { return createParameterMetaData(connection, oids); } return null; }
public CopyIn copyIn(String sql) throws SQLException { CopyOperation op = queryExecutor.startCopy(sql, connection.getAutoCommit()); if (op == null || op instanceof CopyIn) { return (CopyIn) op; } else { op.cancelCopy(); throw new PSQLException(GT.tr("Requested CopyIn but got {0}", op.getClass().getName()), PSQLState.WRONG_OBJECT_TYPE); } }
public boolean executeWithFlags(String p_sql, int flags) throws SQLException { checkClosed(); p_sql = replaceProcessing(p_sql); Query simpleQuery = connection.getQueryExecutor().createSimpleQuery(p_sql); execute(simpleQuery, null, QueryExecutor.QUERY_ONESHOT | flags); this.lastSimpleQuery = simpleQuery; return (result != null && result.getResultSet() != null); }
public PGNotification[] getNotifications() throws SQLException { getQueryExecutor().processNotifies(); // Backwards-compatibility hand-holding. PGNotification[] notifications = protoConnection.getNotifications(); return (notifications.length == 0 ? null : notifications); }
public AbstractJdbc2Statement(AbstractJdbc2Connection connection, String sql, boolean isCallable, int rsType, int rsConcurrency) throws SQLException { this.connection = connection; this.lastSimpleQuery = null; String parsed_sql = replaceProcessing(sql); if (isCallable) parsed_sql = modifyJdbcCall(parsed_sql); this.preparedQuery = connection.getQueryExecutor().createParameterizedQuery(parsed_sql); this.preparedParameters = preparedQuery.createParameterList(); int inParamCount = preparedParameters.getInParameterCount() + 1; this.testReturn = new int[inParamCount]; this.functionReturnType = new int[inParamCount]; resultsettype = rsType; concurrency = rsConcurrency; }
connection.getQueryExecutor().execute(queries, parameterLists, handler,
/** * Send a function call to the PostgreSQL backend * * @param fnId Function id * @param resultType True if the result is an integer, false for other results * @param args FastpathArguments to pass to fastpath * @return null if no data, Integer if an integer result, or byte[] otherwise * @exception SQLException if a database-access error occurs. */ public Object fastpath(int fnId, boolean resultType, FastpathArg[] args) throws SQLException { // Turn fastpath array into a parameter list. ParameterList params = executor.createFastpathParameters(args.length); for (int i = 0; i < args.length; ++i) { args[i].populateParameter(params, i + 1); } // Run it. byte[] returnValue = executor.fastpathCall(fnId, params, connection.getAutoCommit()); // Interpret results. if (!resultType || returnValue == null) return returnValue; if (returnValue.length != 4) throw new PSQLException(GT.tr("Fastpath call {0} - No result was returned and we expected an integer.", new Integer(fnId)), PSQLState.NO_DATA); return new Integer((returnValue[3] & 255) | ((returnValue[2] & 255) << 8) | ((returnValue[1] & 255) << 16) | ((returnValue[0] & 255) << 24)); }
public static byte[][] run(ProtocolConnection protoConnection, String queryString, boolean wantResults) throws SQLException { QueryExecutor executor = protoConnection.getQueryExecutor(); Query query = executor.createSimpleQuery(queryString); SimpleResultHandler handler = new SimpleResultHandler(protoConnection); int flags = QueryExecutor.QUERY_ONESHOT | QueryExecutor.QUERY_SUPPRESS_BEGIN; if (!wantResults) flags |= QueryExecutor.QUERY_NO_RESULTS | QueryExecutor.QUERY_NO_METADATA; try { executor.execute(query, null, handler, 0, 0, flags); } finally { query.close(); } if (!wantResults) return null; Vector tuples = handler.getResults(); if (tuples == null || tuples.size() != 1) throw new PSQLException(GT.tr("An unexpected result was returned by a query."), PSQLState.CONNECTION_UNABLE_TO_CONNECT); return (byte[][]) tuples.elementAt(0); }
public CopyDual copyDual(String sql) throws SQLException { CopyOperation op = queryExecutor.startCopy(sql, connection.getAutoCommit()); if (op == null || op instanceof CopyDual) { return (CopyDual) op; } else { op.cancelCopy(); throw new PSQLException(GT.tr("Requested CopyDual but got {0}", op.getClass().getName()), PSQLState.WRONG_OBJECT_TYPE); } }
commitQuery = getQueryExecutor().createSimpleQuery("COMMIT"); rollbackQuery = getQueryExecutor().createSimpleQuery("ROLLBACK");