postgresql-jdbc.git / summary / log / commit / refs

commit    99eb4753870d5e07f581ee5f546db275331ba2bb
Author:   Alexis Meneses <alexismeneses@users.noreply.github.com>
Date:     Thu Dec 04 21:24:38 2014 +0000

    Restore but deprecate fastpath public api with original signature


org/postgresql/fastpath/Fastpath.java | 80 ++++++++++++++++++++++++++--------- 1 file changed, 61 insertions(+), 19 deletions(-) diff --git a/org/postgresql/fastpath/Fastpath.java b/org/postgresql/fastpath/Fastpath.java index d7cd2c9b..316c572d 100644 --- a/org/postgresql/fastpath/Fastpath.java +++ b/org/postgresql/fastpath/Fastpath.java @@ -15,6 +15,7 @@ import java.util.Map; import org.postgresql.core.BaseConnection; import org.postgresql.core.QueryExecutor; import org.postgresql.core.ParameterList; +import org.postgresql.util.ByteConverter; import org.postgresql.util.PSQLException; import org.postgresql.util.PSQLState; import org.postgresql.util.GT; @@ -52,13 +53,47 @@ public class Fastpath this.executor = conn.getQueryExecutor(); } + /** + * Send a function call to the PostgreSQL backend + * + * @deprecated please use {@link #fastpath(int, FastpathArg[])} + * @param fnId Function id + * @param resultType True if the result is a numeric (Integer or Long) + * @param args FastpathArguments to pass to fastpath + * @return null if no data, Integer if an integer result, Long if a long result, or byte[] otherwise + * @exception SQLException if a database-access error occurs. + */ + @Deprecated + public Object fastpath(int fnId, boolean resultType, FastpathArg[] args) throws SQLException + { + // Run it. + byte[] returnValue = fastpath(fnId, args); + + // Interpret results. + if (!resultType || returnValue == null) + return returnValue; + + if (returnValue.length == 4) + { + return new Integer(ByteConverter.int4(returnValue, 0)); + } + else if (returnValue.length == 8) + { + return new Long(ByteConverter.int8(returnValue, 0)); + } + else + { + throw new PSQLException(GT.tr("Fastpath call {0} - No result was returned and we expected a numeric.", new Integer(fnId)), + PSQLState.NO_DATA); + } + } + /** * Send a function call to the PostgreSQL backend * * @param fnId Function id - * @param resultType True if the result is a numeric (integer or long) * @param args FastpathArguments to pass to fastpath - * @return null if no data, Integer if an integer result, or byte[] otherwise + * @return null if no data, byte[] otherwise * @exception SQLException if a database-access error occurs. */ public byte[] fastpath(int fnId, FastpathArg[] args) throws SQLException @@ -73,26 +108,43 @@ public class Fastpath // Run it. byte[] returnValue = executor.fastpathCall(fnId, params, connection.getAutoCommit()); - // Interpret results. return returnValue; } + /** + * @param name Function name + * @param resultType True if the result is a numeric (Integer or Long) + * @param args FastpathArguments to pass to fastpath + * @return null if no data, Integer if an integer result, Long if a long result, or byte[] otherwise + * + * @deprecated Use {@link #getData(String, FastpathArg[])} if you expect a binary result, + * or one of {@link #getInteger(String, FastpathArg[])} or {@link #getLong(String, FastpathArg[])} if you + * expect a numeric one + * @see #fastpath(int, FastpathArg[]) + * @see #fastpath(String, FastpathArg[]) + */ + @Deprecated + public Object fastpath(String name, boolean resulttype, FastpathArg[] args) throws SQLException + { + if (connection.getLogger().logDebug()) + connection.getLogger().debug("Fastpath: calling " + name); + return fastpath(getID(name), resulttype, args); + } + /** * Send a function call to the PostgreSQL backend by name. * * Note: the mapping for the procedure name to function id needs to exist, * usually to an earlier call to addfunction(). * - * This is the prefered method to call, as function id's can/may change + * This is the preferred method to call, as function id's can/may change * between versions of the backend. * * For an example of how this works, refer to org.postgresql.largeobject.LargeObject * * @param name Function name - * @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 + * @return null if no data, byte[] otherwise * @exception SQLException if name is unknown or if a database-access error * occurs. * @see org.postgresql.largeobject.LargeObject @@ -122,10 +174,7 @@ public class Fastpath if (returnValue.length == 4) { - int i = ((returnValue[3] & 255) | - ((returnValue[2] & 255) << 8) | - ((returnValue[1] & 255) << 16) | - ((returnValue[0] & 255) << 24)); + int i = ByteConverter.int4(returnValue, 0); return i; } else @@ -152,14 +201,7 @@ public class Fastpath } if (returnValue.length == 8) { - long l = ((long)(returnValue[7] & 255) | - ((long)(returnValue[6] & 255) << 8) | - ((long)(returnValue[5] & 255) << 16) | - ((long)(returnValue[4] & 255) << 24) | - ((long)(returnValue[3] & 255) << 32) | - ((long)(returnValue[2] & 255) << 40) | - ((long)(returnValue[1] & 255) << 48) | - ((long)(returnValue[0] & 255) << 56)); + long l = ByteConverter.int8(returnValue, 0); return l; } [parent: 227bddd5c5a8]