Skip to content

Commit

Permalink
JDBC-617 Remove of UDF support for JDBC escapes
Browse files Browse the repository at this point in the history
Refactor FBEscapedParser to use a static entrypoint to make clear it is stateless
  • Loading branch information
mrotteveel committed Mar 15, 2020
1 parent f512aab commit 302f28b
Show file tree
Hide file tree
Showing 19 changed files with 120 additions and 588 deletions.
31 changes: 22 additions & 9 deletions src/documentation/release_notes.md
Expand Up @@ -338,6 +338,28 @@ The following constants have been removed in Jaybird 5:
There is no official replacement as this should be considered an
implementation detail. It is possible that `DatabaseParameterBufferExtension`
will be removed entirely.

Removal of UDF support for JDBC escapes
---------------------------------------

Given recent Firebird versions have significantly improved support for built-in
functions, and UDFs are now deprecated, the support to map JDBC function escapes
to UDFs from `ib_udf` instead of built-in functions using the boolean connection
property `useStandarUdf`\[sic\] has been removed.

As a result, the following methods, constants, properties and others are no
longer available:

- Connection property `useStandarUdf`\[sic\] and its alias `use_standard_udf`
- `isUseStandardUdf()` and `setUseStandardUdf(boolean useStandardUdf)` in
`FirebirdConnectionProperties` and in implementations of `DataSource` and
other classes
- Constants `FBConnectionProperties.USE_STANDARD_UDF_PROPERTY`,
`DatabaseParameterBufferExtension.USE_STANDARD_UDF`,
`ISCConstants.isc_dpb_use_standard_udf`
- Enum `EscapeParserMode` and its usages in `FBEscapedCallParser` and
`FBEscapedParser`
- Public classes in package are now marked as internal-api

Breaking changes for Jaybird 5
------------------------------
Expand Down Expand Up @@ -365,15 +387,6 @@ If you are currently using Jaybird as a JCA driver, please let us know on the
Firebird-Java mailing list. We may reconsider this decision and instead
restructure Jaybird so the dependency on JCA is only needed when Jaybird is used
as a JCA driver.

### Removal of UDF support for JDBC escapes ###

Jaybird 4 and earlier have support to map JDBC function escapes to UDFs from
`ib_udf` instead of built-in function using the boolean connection property
`useStandarUdf`\[sic\].

Given recent Firebird versions have significantly improved support for built-in
functions, and UDFs are now deprecated, this option will be removed in Jaybird 5.

Compatibility notes
===================
Expand Down
15 changes: 0 additions & 15 deletions src/main/org/firebirdsql/ds/FBAbstractCommonDataSource.java
Expand Up @@ -320,21 +320,6 @@ public void setUseStreamBlobs(boolean useStreamBlobs) {
}
}

@Override
public boolean isUseStandardUdf() {
synchronized (lock) {
return connectionProperties.isUseStandardUdf();
}
}

@Override
public void setUseStandardUdf(boolean useStandardUdf) {
synchronized (lock) {
checkNotStarted();
connectionProperties.setUseStandardUdf(useStandardUdf);
}
}

@Override
public int getSocketBufferSize() {
synchronized (lock) {
Expand Down
8 changes: 0 additions & 8 deletions src/main/org/firebirdsql/ds/FBSimpleDataSource.java
Expand Up @@ -279,10 +279,6 @@ public boolean isTimestampUsesLocalTimezone() {
return mcf.isTimestampUsesLocalTimezone();
}

public boolean isUseStandardUdf() {
return mcf.isUseStandardUdf();
}

public boolean isUseStreamBlobs() {
return mcf.isUseStreamBlobs();
}
Expand Down Expand Up @@ -339,10 +335,6 @@ public void setType(String type) {
mcf.setType(type);
}

public void setUseStandardUdf(boolean useStandardUdf) {
mcf.setUseStandardUdf(useStandardUdf);
}

public void setUseStreamBlobs(boolean useStreamBlobs) {
mcf.setUseStreamBlobs(useStreamBlobs);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/org/firebirdsql/gds/ISCConstants.java
Expand Up @@ -180,7 +180,7 @@ public interface ISCConstants {
@Deprecated
int isc_dpb_paranoia_mode = 132;
int isc_dpb_timestamp_uses_local_timezone = 133;
int isc_dpb_use_standard_udf = 134;
// unused 134 (was isc_dpb_use_standard_udf)
int isc_dpb_local_encoding = 135;
@Deprecated
int isc_dpb_mapping_path = 136;
Expand Down
Expand Up @@ -45,7 +45,6 @@ public interface DatabaseParameterBufferExtension extends DatabaseParameterBuffe
@Deprecated
int PARANOIA_MODE = ISCConstants.isc_dpb_paranoia_mode;
int TIMESTAMP_USES_LOCAL_TIMEZONE = ISCConstants.isc_dpb_timestamp_uses_local_timezone;
int USE_STANDARD_UDF = ISCConstants.isc_dpb_use_standard_udf;
int LOCAL_ENCODING = ISCConstants.isc_dpb_local_encoding;
@Deprecated
int MAPPING_PATH = ISCConstants.isc_dpb_mapping_path;
Expand Down
8 changes: 0 additions & 8 deletions src/main/org/firebirdsql/jca/FBManagedConnectionFactory.java
Expand Up @@ -276,10 +276,6 @@ public boolean isTimestampUsesLocalTimezone() {
return connectionProperties.isTimestampUsesLocalTimezone();
}

public boolean isUseStandardUdf() {
return connectionProperties.isUseStandardUdf();
}

public boolean isUseStreamBlobs() {
return connectionProperties.isUseStreamBlobs();
}
Expand Down Expand Up @@ -360,10 +356,6 @@ public void setUserName(String userName) {
connectionProperties.setUserName(userName);
}

public void setUseStandardUdf(boolean useStandardUdf) {
connectionProperties.setUseStandardUdf(useStandardUdf);
}

public void setUseStreamBlobs(boolean useStreamBlobs) {
connectionProperties.setUseStreamBlobs(useStreamBlobs);
}
Expand Down
24 changes: 7 additions & 17 deletions src/main/org/firebirdsql/jdbc/AbstractCallableStatement.java
Expand Up @@ -18,22 +18,19 @@
*/
package org.firebirdsql.jdbc;

import org.firebirdsql.gds.impl.GDSHelper;
import org.firebirdsql.jdbc.escape.FBEscapedCallParser;
import org.firebirdsql.jdbc.field.FBField;
import org.firebirdsql.jdbc.field.TypeConversionException;

import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
import java.net.URL;
import java.sql.*;
import java.sql.Date;
import java.sql.*;
import java.util.*;

import org.firebirdsql.gds.DatabaseParameterBuffer;
import org.firebirdsql.gds.impl.DatabaseParameterBufferExtension;
import org.firebirdsql.gds.impl.GDSHelper;
import org.firebirdsql.jdbc.escape.FBEscapedCallParser;
import org.firebirdsql.jdbc.escape.FBEscapedParser.EscapeParserMode;
import org.firebirdsql.jdbc.field.FBField;
import org.firebirdsql.jdbc.field.TypeConversionException;

/**
* Abstract implementation of {@link java.sql.CallableStatement}.
*
Expand Down Expand Up @@ -63,14 +60,7 @@ protected AbstractCallableStatement(GDSHelper c, String sql, int rsType,
throws SQLException {
super(c, rsType, rsConcurrency, rsHoldability, statementListener, blobListener);

DatabaseParameterBuffer dpb = c.getDatabaseParameterBuffer();

EscapeParserMode mode = EscapeParserMode.USE_BUILT_IN;

if (dpb.hasArgument(DatabaseParameterBufferExtension.USE_STANDARD_UDF))
mode = EscapeParserMode.USE_STANDARD_UDF;

FBEscapedCallParser parser = new FBEscapedCallParser(mode);
FBEscapedCallParser parser = new FBEscapedCallParser();

// here statement is parsed twice, once in c.nativeSQL(...)
// and second time in parser.parseCall(...)... not nice, maybe
Expand Down
20 changes: 1 addition & 19 deletions src/main/org/firebirdsql/jdbc/FBConnection.java
Expand Up @@ -31,7 +31,6 @@
import org.firebirdsql.jca.FBManagedConnection;
import org.firebirdsql.jca.FirebirdLocalTransaction;
import org.firebirdsql.jdbc.escape.FBEscapedParser;
import org.firebirdsql.jdbc.escape.FBEscapedParser.EscapeParserMode;
import org.firebirdsql.logging.Logger;
import org.firebirdsql.logging.LoggerFactory;
import org.firebirdsql.util.SQLExceptionChainBuilder;
Expand Down Expand Up @@ -86,7 +85,6 @@ public class FBConnection implements FirebirdConnection, Synchronizable {
private int resultSetHoldability = ResultSet.CLOSE_CURSORS_AT_COMMIT;

private StoredProcedureMetaData storedProcedureMetaData;
private FBEscapedParser escapedParser;
private GeneratedKeysSupport generatedKeysSupport;

/**
Expand Down Expand Up @@ -327,25 +325,9 @@ public Array createArrayOf(String typeName, Object[] elements) throws SQLExcepti
public String nativeSQL(String sql) throws SQLException {
synchronized (getSynchronizationObject()) {
checkValidity();
return getEscapedParser().parse(sql);
return FBEscapedParser.toNativeSql(sql);
}
}

/**
* Returns the FBEscapedParser instance for this connection.
*
* @return Instance of FBEscapedParser
*/
protected FBEscapedParser getEscapedParser() {
if (escapedParser == null) {
DatabaseParameterBuffer dpb = getDatabaseParameterBuffer();
EscapeParserMode mode = dpb.hasArgument(DatabaseParameterBufferExtension.USE_STANDARD_UDF)
? EscapeParserMode.USE_STANDARD_UDF
: EscapeParserMode.USE_BUILT_IN;
escapedParser = new FBEscapedParser(mode);
}
return escapedParser;
}

@Override
public void setAutoCommit(boolean autoCommit) throws SQLException {
Expand Down
9 changes: 0 additions & 9 deletions src/main/org/firebirdsql/jdbc/FBConnectionProperties.java
Expand Up @@ -50,7 +50,6 @@ public class FBConnectionProperties implements FirebirdConnectionProperties, Ser
public static final String ROLE_NAME_PROPERTY = "roleName";
public static final String SQL_DIALECT_PROPERTY = "sqlDialect";
public static final String USE_STREAM_BLOBS_PROPERTY = "useStreamBlobs";
public static final String USE_STANDARD_UDF_PROPERTY = "useStandardUdf";
public static final String SOCKET_BUFFER_SIZE_PROPERTY = "socketBufferSize";
public static final String TIMESTAMP_USES_LOCAL_TIMEZONE_PROPERTY = "timestampUsesLocalTimezone";
public static final String USER_NAME_PROPERTY = "userName";
Expand Down Expand Up @@ -260,14 +259,6 @@ public void setUseStreamBlobs(boolean useStreamBlobs) {
setBooleanProperty(USE_STREAM_BLOBS_PROPERTY, useStreamBlobs);
}

public boolean isUseStandardUdf() {
return getBooleanProperty(USE_STANDARD_UDF_PROPERTY);
}

public void setUseStandardUdf(boolean useStandardUdf) {
setBooleanProperty(USE_STANDARD_UDF_PROPERTY, useStandardUdf);
}

public int getSocketBufferSize() {
return getIntProperty(SOCKET_BUFFER_SIZE_PROPERTY);
}
Expand Down
9 changes: 1 addition & 8 deletions src/main/org/firebirdsql/jdbc/FBStatement.java
Expand Up @@ -18,15 +18,12 @@
*/
package org.firebirdsql.jdbc;

import org.firebirdsql.gds.DatabaseParameterBuffer;
import org.firebirdsql.gds.JaybirdErrorCodes;
import org.firebirdsql.gds.impl.DatabaseParameterBufferExtension;
import org.firebirdsql.gds.impl.GDSHelper;
import org.firebirdsql.gds.ng.*;
import org.firebirdsql.gds.ng.fields.RowValue;
import org.firebirdsql.gds.ng.listeners.StatementListener;
import org.firebirdsql.jdbc.escape.FBEscapedParser;
import org.firebirdsql.jdbc.escape.FBEscapedParser.EscapeParserMode;
import org.firebirdsql.logging.LoggerFactory;

import java.sql.*;
Expand Down Expand Up @@ -908,11 +905,7 @@ protected String nativeSQL(String sql) throws SQLException {
if (connection != null) {
return connection.nativeSQL(sql);
} else {
DatabaseParameterBuffer dpb = gdsHelper.getDatabaseParameterBuffer();
EscapeParserMode mode = dpb.hasArgument(DatabaseParameterBufferExtension.USE_STANDARD_UDF)
? EscapeParserMode.USE_STANDARD_UDF
: EscapeParserMode.USE_BUILT_IN;
return new FBEscapedParser(mode).parse(sql);
return FBEscapedParser.toNativeSql(sql);
}
}

Expand Down
13 changes: 0 additions & 13 deletions src/main/org/firebirdsql/jdbc/FirebirdConnectionProperties.java
Expand Up @@ -130,19 +130,6 @@ public interface FirebirdConnectionProperties {
*/
void setUseStreamBlobs(boolean useStreamBlobs);

/**
* @return <code>true</code> if driver should assume that standard UDF are
* installed.
*/
boolean isUseStandardUdf();

/**
* @param useStandardUdf
* <code>true</code> if driver should assume that standard UDF
* are installed.
*/
void setUseStandardUdf(boolean useStandardUdf);

/**
* @return socket buffer size in bytes, or -1 is not specified.
*/
Expand Down
10 changes: 3 additions & 7 deletions src/main/org/firebirdsql/jdbc/escape/FBEscapedCallParser.java
Expand Up @@ -20,13 +20,14 @@

import org.firebirdsql.jdbc.FBProcedureCall;
import org.firebirdsql.jdbc.FBProcedureParam;
import org.firebirdsql.jdbc.escape.FBEscapedParser.EscapeParserMode;
import org.firebirdsql.util.InternalApi;

import java.sql.SQLException;

/**
* Parser for escaped procedure call.
*/
@InternalApi
public class FBEscapedCallParser {

private static final int NORMAL_STATE = 1;
Expand All @@ -48,11 +49,6 @@ public class FBEscapedCallParser {
private int openBraceCount;

private FBProcedureCall procedureCall;
private FBEscapedParser escapedParser;

public FBEscapedCallParser(EscapeParserMode mode) {
this.escapedParser = new FBEscapedParser(mode);
}

/**
* Returns the current state.
Expand Down Expand Up @@ -398,6 +394,6 @@ protected boolean processToken(String token) {
* @throws FBSQLParseException if parameter cannot be correctly parsed.
*/
protected String processParam(String param) throws SQLException {
return escapedParser.parse(param);
return FBEscapedParser.toNativeSql(param);
}
}

0 comments on commit 302f28b

Please sign in to comment.