Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: deprecate Fastpath API #903

Merged
merged 4 commits into from May 4, 2018
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+36 −35
Diff settings

Always

Just for now

Prev

refactor: deprecate Fastpath API

revert adding varargs to Fastpath
  • Loading branch information...
AlexElin committed Aug 7, 2017
commit 503e089cb2e9b1b37946829a48c224ece8a4e856
@@ -65,7 +65,7 @@ public Fastpath(BaseConnection conn) {
* @return null if no data, Integer if an integer result, Long if a long result, or byte[]
* otherwise
* @throws SQLException if a database-access error occurs.
* @deprecated please use {@link #fastpath(String, FastpathArg[])}
* @deprecated please use {@link #fastpath(int, FastpathArg[])}
*/
@Deprecated
public Object fastpath(int fnId, boolean resultType, FastpathArg[] args) throws SQLException {
@@ -89,16 +89,14 @@ public Object fastpath(int fnId, boolean resultType, FastpathArg[] args) throws
}

/**
* Sends a function call to the PostgreSQL backend
* 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.
* @deprecated please use {@link #fastpath(String, FastpathArg[])}
*/
@Deprecated
public byte[] fastpath(int fnId, FastpathArg... args) throws SQLException {
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) {
@@ -116,6 +114,7 @@ public Object fastpath(int fnId, boolean resultType, FastpathArg[] args) throws
* @return null if no data, Integer if an integer result, Long if a long result, or byte[]
* otherwise
* @throws SQLException if something goes wrong
* @see #fastpath(int, FastpathArg[])
* @see #fastpath(String, FastpathArg[])
* @deprecated Use {@link #getData(String, FastpathArg[])} if you expect a binary result, or one
* of {@link #getInteger(String, FastpathArg[])} or
@@ -128,7 +127,7 @@ public Object fastpath(String name, boolean resulttype, FastpathArg[] args) thro
}

/**
* Sends a function call to the PostgreSQL backend by name.
* 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().
@@ -144,16 +143,9 @@ public Object fastpath(String name, boolean resulttype, FastpathArg[] args) thro
* @throws SQLException if name is unknown or if a database-access error occurs.
* @see org.postgresql.largeobject.LargeObject
*/
public byte[] fastpath(String name, FastpathArg... args) throws SQLException {
public byte[] fastpath(String name, FastpathArg[] args) throws SQLException {
connection.getLogger().log(Level.FINEST, "Fastpath: calling {0}", name);
// 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(getID(name), params, connection.getAutoCommit());
return fastpath(getID(name), args);
}

/**
@@ -164,7 +156,7 @@ public Object fastpath(String name, boolean resulttype, FastpathArg[] args) thro
* @return integer result
* @throws SQLException if a database-access error occurs or no result
*/
public int getInteger(String name, FastpathArg... args) throws SQLException {
public int getInteger(String name, FastpathArg[] args) throws SQLException {
byte[] returnValue = fastpath(name, args);
if (returnValue == null) {
throw new PSQLException(
@@ -189,7 +181,7 @@ public int getInteger(String name, FastpathArg... args) throws SQLException {
* @return long result
* @throws SQLException if a database-access error occurs or no result
*/
public long getLong(String name, FastpathArg... args) throws SQLException {
public long getLong(String name, FastpathArg[] args) throws SQLException {
byte[] returnValue = fastpath(name, args);
if (returnValue == null) {
throw new PSQLException(
@@ -215,7 +207,7 @@ public long getLong(String name, FastpathArg... args) throws SQLException {
* @return oid of the given call
* @throws SQLException if a database-access error occurs or no result
*/
public long getOID(String name, FastpathArg... args) throws SQLException {
public long getOID(String name, FastpathArg[] args) throws SQLException {
long oid = getInteger(name, args);
if (oid < 0) {
oid += NUM_OIDS;
@@ -231,12 +223,12 @@ public long getOID(String name, FastpathArg... args) throws SQLException {
* @return byte[] array containing result
* @throws SQLException if a database-access error occurs or no result
*/
public byte[] getData(String name, FastpathArg... args) throws SQLException {
public byte[] getData(String name, FastpathArg[] args) throws SQLException {
return fastpath(name, args);
}

/**
* Adds a function to our lookup table.
* This adds a function to our lookup table.
*
* <p>
* User code should use the addFunctions method, which is based upon a query, rather than hard
@@ -292,7 +284,7 @@ public void addFunctions(ResultSet rs) throws SQLException {
}

/**
* Returns the function id associated by its name.
* This returns the function id associated by its name.
*
* <p>
* If addFunction() or addFunctions() have not been called for this name, then an SQLException is
@@ -137,7 +137,6 @@ public LargeObject copy() throws SQLException {
* @return the OID of this LargeObject
* @deprecated As of 8.3, replaced by {@link #getLongOID()}
*/
@Deprecated
public int getOID() {
return (int) oid;
}
@@ -169,7 +168,9 @@ public void close() throws SQLException {
}

// finally close
fp.fastpath("lo_close", new FastpathArg(fd)); // true here as we dont care!!
FastpathArg[] args = new FastpathArg[1];
args[0] = new FastpathArg(fd);
fp.fastpath("lo_close", args); // true here as we dont care!!
closed = true;
if (this.commitOnClose) {
this.conn.commit();
@@ -292,15 +293,19 @@ public void seek(int pos) throws SQLException {
* @throws SQLException if a database-access error occurs.
*/
public int tell() throws SQLException {
return fp.getInteger("lo_tell", new FastpathArg(fd));
FastpathArg[] args = new FastpathArg[1];
args[0] = new FastpathArg(fd);
return fp.getInteger("lo_tell", args);
}

/**
* @return the current position within the object
* @throws SQLException if a database-access error occurs.
*/
public long tell64() throws SQLException {
return fp.getLong("lo_tell64", new FastpathArg(fd));
FastpathArg[] args = new FastpathArg[1];
args[0] = new FastpathArg(fd);
return fp.getLong("lo_tell64", args);
}

/**
@@ -266,7 +266,7 @@ public LargeObject open(long oid, int mode, boolean commitOnClose) throws SQLExc
}

/**
* Creates a large object, returning its OID.
* This creates a large object, returning its OID.
*
* <p>
* It defaults to READWRITE for the new object's attributes.
@@ -281,7 +281,7 @@ public int create() throws SQLException {
}

/**
* Creates a large object, returning its OID.
* This creates a large object, returning its OID.
*
* <p>
* It defaults to READWRITE for the new object's attributes.
@@ -294,7 +294,7 @@ public long createLO() throws SQLException {
}

/**
* Creates a large object, returning its OID
* This creates a large object, returning its OID
*
* @param mode a bitmask describing different attributes of the new object
* @return oid of new object
@@ -305,11 +305,13 @@ public long createLO(int mode) throws SQLException {
throw new PSQLException(GT.tr("Large Objects may not be used in auto-commit mode."),
PSQLState.NO_ACTIVE_SQL_TRANSACTION);
}
return fp.getOID("lo_creat", new FastpathArg(mode));
FastpathArg[] args = new FastpathArg[1];
args[0] = new FastpathArg(mode);
return fp.getOID("lo_creat", args);
}

/**
* Creates a large object, returning its OID
* This creates a large object, returning its OID
*
* @param mode a bitmask describing different attributes of the new object
* @return oid of new object
@@ -323,17 +325,19 @@ public int create(int mode) throws SQLException {
}

/**
* Deletes a large object.
* This deletes a large object.
*
* @param oid describing object to delete
* @throws SQLException on error
*/
public void delete(long oid) throws SQLException {
fp.fastpath("lo_unlink", Fastpath.createOIDArg(oid));
FastpathArg[] args = new FastpathArg[1];
args[0] = Fastpath.createOIDArg(oid);
fp.fastpath("lo_unlink", args);
}

/**
* Deletes a large object.
* This deletes a large object.
*
* <p>
* It is identical to the delete method, and is supplied as the C API uses unlink.
@@ -348,7 +352,7 @@ public void unlink(int oid) throws SQLException {
}

/**
* Deletes a large object.
* This deletes a large object.
*
* <p>
* It is identical to the delete method, and is supplied as the C API uses unlink.
@@ -361,7 +365,7 @@ public void unlink(long oid) throws SQLException {
}

/**
* Deletes a large object.
* This deletes a large object.
*
* @param oid describing object to delete
* @throws SQLException on error
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.