Skip to content

Commit

Permalink
Avoid creation of SQLWarning objects when ignoring warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jeber-ibm authored Aug 15, 2023
1 parent 5605b90 commit 431b8a7
Show file tree
Hide file tree
Showing 16 changed files with 283 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3238,7 +3238,7 @@ private void testDataTruncation(int parameterIndex, SQLData data, boolean except
{
if(wasDataMappingError_)
{
postWarning(new DataTruncation(parameterIndex, true, true, -1, -1));
postDataTruncationWarning(parameterIndex, true, true, -1, -1);
}

if(data != null)
Expand All @@ -3253,7 +3253,7 @@ private void testDataTruncation(int parameterIndex, SQLData data, boolean except
}
} //@trunc
int actualSize = data.getActualSize();
postWarning(new DataTruncation(parameterIndex, true, true, actualSize, actualSize - truncated));
postDataTruncationWarning(parameterIndex, true, true, actualSize, actualSize - truncated);
}
}
}
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/com/ibm/as400/access/AS400JDBCConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -807,11 +807,20 @@ abstract void notifyClose (AS400JDBCStatement statement, int id)
/**
Posts a warning for the connection.
@param sqlWarning The warning.
@param id The id used to create the warning
@param errorClass The error class used to create the warning
@param returnCode The return code used to create the warning
**/
abstract void postWarning (SQLWarning sqlWarning)
abstract void postWarning (int id, int errorClass, int returnCode)
throws SQLException;

/**
Posts a warning for the connection.
@param sqlState The SQL state for the warning.
**/
abstract void postWarningSQLState (String sqlState)
throws SQLException;


/**
Expand Down Expand Up @@ -1440,7 +1449,6 @@ abstract void setProperties(JDDataSourceURL dataSourceUrl, JDProperties properti

/* Should the warning be ignored @Q1A*/
abstract boolean ignoreWarning(String sqlState);
abstract boolean ignoreWarning(SQLWarning warning);
//@A3A - This logic formerly resided in the ctor.
abstract void setProperties (JDDataSourceURL dataSourceUrl, JDProperties properties, AS400Impl as400, boolean newServer, boolean skipSignonServer)
throws SQLException;
Expand Down
20 changes: 17 additions & 3 deletions src/main/java/com/ibm/as400/access/AS400JDBCConnectionHandle.java
Original file line number Diff line number Diff line change
Expand Up @@ -790,13 +790,27 @@ void notifyClose (AS400JDBCStatement statement, int id)
/**
* Posts a warning for the connection.
*
* @param sqlWarning The warning.
@param id The id used to create the warning
@param errorClass The error class used to create the warning
@param returnCode The return code used to create the warning
**/
void postWarning (SQLWarning sqlWarning)
void postWarning (int id, int errorCode, int returnCode)
throws SQLException // @A3A
{
validateConnection();
connection_.postWarning(sqlWarning);
connection_.postWarning(id, errorCode, returnCode);
}

/**
* Posts a warning for the connection.
*
* @param sqlState The sqlstate for the warning.
**/
void postWarningSQLState (String sqlState)
throws SQLException // @A3A
{
validateConnection();
connection_.postWarningSQLState(sqlState);
}

/**
Expand Down
96 changes: 66 additions & 30 deletions src/main/java/com/ibm/as400/access/AS400JDBCConnectionImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ private class HeldRequestsLock extends Object {} //@C7A
private String clientProgramID_ = ""; //@pdc

private String ignoreWarnings_ = ""; /*@Q1A*/
private boolean ignoreAllWarnings_ = false;

private int concurrentAccessResolution_ = AS400JDBCDataSource.CONCURRENTACCESS_NOT_SET; //@cc1

Expand Down Expand Up @@ -724,7 +725,7 @@ public int correctResultSetType (int resultSetType,
{
int newResultSetType = (resultSetConcurrency == ResultSet.CONCUR_UPDATABLE)
? ResultSet.TYPE_SCROLL_SENSITIVE : ResultSet.TYPE_SCROLL_INSENSITIVE;
postWarning (JDError.getSQLWarning (JDError.WARN_OPTION_VALUE_CHANGED));
postWarningSQLState (JDError.WARN_OPTION_VALUE_CHANGED);
return newResultSetType;
}

Expand Down Expand Up @@ -879,7 +880,7 @@ public Statement createStatement (AS400JDBCConnection con,
{ //@K1A
thousandStatements_ = true; //@K1A
//post warning //@K1A
postWarning(JDError.getSQLWarning(JDError.WARN_1000_OPEN_STATEMENTS)); //@K1A
postWarningSQLState(JDError.WARN_1000_OPEN_STATEMENTS); //@K1A
} //@K1A

if (JDTrace.isTraceOn()) //@F4A
Expand Down Expand Up @@ -1869,25 +1870,46 @@ public void notifyClose (AS400JDBCStatement statement, int id)




/**
Posts a warning for the connection.
@param sqlWarning The warning.
@param sqlState the SQL state for the warning.
**/
public void postWarning (SQLWarning sqlWarning)
public void postWarningSQLState (String sqlState)
throws SQLException // @EGA
{
String sqlState = sqlWarning.getSQLState();
if( !ignoreWarning(sqlState )) { /*@Q1A*/

SQLWarning sqlWarning = JDError.getSQLWarning(sqlState);
if (sqlWarning_ == null)
sqlWarning_ = sqlWarning;
else
sqlWarning_.setNextWarning (sqlWarning);
} /*@Q1A*/
}

/**
Posts a warning for the connection, constructing the SQLWarning object only if necessary.
@param id The id used to create the warning
@param errorClass The error class used to create the warning
@param returnCode The return code used to create the warning
**/
public void postWarning (int id, int errorClass, int returnCode)
throws SQLException // @EGA
{
String sqlState = JDError.getSQLState(this, id);
if( !ignoreWarning(sqlState )) {
SQLWarning sqlWarning = JDError.getSQLWarning (this, id, errorClass, returnCode);
if (sqlWarning_ == null)
sqlWarning_ = sqlWarning;
else
sqlWarning_.setNextWarning (sqlWarning);
}
}




/**
Precompiles an SQL stored procedure call with optional input
Expand Down Expand Up @@ -2038,7 +2060,7 @@ public CallableStatement prepareCall(AS400JDBCConnection con, String sql,
{ //@K1A
thousandStatements_ = true; //@K1A
//post warning //@K1A
postWarning(JDError.getSQLWarning(JDError.WARN_1000_OPEN_STATEMENTS)); //@K1A
postWarningSQLState(JDError.WARN_1000_OPEN_STATEMENTS); //@K1A
} //@K1A

if (JDTrace.isTraceOn()) //@F4A
Expand Down Expand Up @@ -2176,7 +2198,7 @@ public PreparedStatement prepareStatement (AS400JDBCConnection con, String sql,
{ //@K1A
thousandStatements_ = true; //@K1A
//post warning //@K1A
postWarning(JDError.getSQLWarning(JDError.WARN_1000_OPEN_STATEMENTS)); //@K1A
postWarningSQLState(JDError.WARN_1000_OPEN_STATEMENTS); //@K1A
} //@K1A

if (JDTrace.isTraceOn()) //@F4A
Expand Down Expand Up @@ -2319,7 +2341,7 @@ public PreparedStatement prepareStatement (AS400JDBCConnection con, String sql,
{ //@K1A
thousandStatements_ = true; //@K1A
//post warning //@K1A
postWarning(JDError.getSQLWarning(JDError.WARN_1000_OPEN_STATEMENTS)); //@K1A
postWarningSQLState(JDError.WARN_1000_OPEN_STATEMENTS); //@K1A
} //@K1A

if (JDTrace.isTraceOn()) //@F4A
Expand Down Expand Up @@ -3570,6 +3592,9 @@ public void setProperties(JDDataSourceURL dataSourceUrl, JDProperties properties

/* Should the warning be ignored @Q1A*/
public boolean ignoreWarning(String sqlState) {
if (ignoreAllWarnings_) {
return true;
}
if (ignoreWarnings_.indexOf(sqlState ) >= 0) {
return true;
} else {
Expand All @@ -3591,8 +3616,10 @@ public void setProperties (JDDataSourceURL dataSourceUrl, JDProperties propertie
properties_ = properties;


ignoreWarnings_ = properties_.getString(JDProperties.IGNORE_WARNINGS).toUpperCase(); /*@Q1A*/

ignoreWarnings_ = properties_.getString(JDProperties.IGNORE_WARNINGS).toUpperCase().trim(); /*@Q1A*/
if (ignoreWarnings_.equals("ALL")) {
ignoreAllWarnings_ = true;
}
//Set the real default for METADATA SOURCE property since we now know the hostsrvr version
if(properties_.getString(JDProperties.METADATA_SOURCE).equals(JDProperties.METADATA_SOURCE_HOST_VERSION_DEFAULT)) //@mdsp
{ //@mdsp
Expand Down Expand Up @@ -3621,12 +3648,12 @@ else if(!properties_.getBoolean(JDProperties.TRUE_AUTO_COMMIT)) //@

// Issue any warnings.
if (dataSourceUrl_.isExtraPathSpecified ())
postWarning (JDError.getSQLWarning (JDError.WARN_URL_EXTRA_IGNORED));
postWarningSQLState (JDError.WARN_URL_EXTRA_IGNORED);
if (properties.isExtraPropertySpecified ())
postWarning (JDError.getSQLWarning (JDError.WARN_PROPERTY_EXTRA_IGNORED));
postWarningSQLState (JDError.WARN_PROPERTY_EXTRA_IGNORED);
if (dataSourceUrl_.isPortSpecified ()) {
if (dataSourceUrl_.getPortNumber() == 0) {
postWarning (JDError.getSQLWarning (JDError.WARN_URL_EXTRA_IGNORED));
postWarningSQLState (JDError.WARN_URL_EXTRA_IGNORED);
}
}

Expand Down Expand Up @@ -4606,13 +4633,13 @@ else if ( roundingModeStr.equals(JDProperties.DECFLOAT_ROUNDING_MODE_HALF_DOWN))
// Sort sequence attribute cannot be set.
if ((errorClass == 7)
&& ((returnCode == 301) || (returnCode == 303)))
postWarning (JDError.getSQLWarning (this, id_, errorClass, returnCode));
postWarning ( id_, errorClass, returnCode);

// Language feature code id was not changed. This is caused
// when the secondary language can not be added to the library
// list, and shows up as a PWS0003.
else if ((errorClass == 7) && (returnCode == 304))
postWarning (JDError.getSQLWarning (this, id_, errorClass, returnCode));
postWarning ( id_, errorClass, returnCode);

// -704 is RDB (IASP) does not exist. We do not go back to the system to get
// error info since they are sending an invalid attribute exception when the
Expand Down Expand Up @@ -5232,7 +5259,7 @@ public void setClientInfo(String name, String value)
{
oldValue = null;
// post generic syntax error for invalid clientInfo name
postWarning(JDError.getSQLWarning(JDError.EXC_SYNTAX_ERROR));
postWarningSQLState(JDError.EXC_SYNTAX_ERROR);
}

if ((getVRM() >= JDUtilities.vrm610) && (oldValue != null))
Expand Down Expand Up @@ -5464,7 +5491,7 @@ else if (name.equals(clientProgramIDPropertyName_)) //@pda
{
//post generic syntax error for invalid clientInfo name
//since javadoc for setClientInfo(String,String) says to generate warning, we will do same here and return null
postWarning(JDError.getSQLWarning(JDError.EXC_SYNTAX_ERROR));
postWarningSQLState(JDError.EXC_SYNTAX_ERROR);
return null;
}
}
Expand Down Expand Up @@ -6157,9 +6184,9 @@ public boolean testDataTruncation(AS400JDBCStatement statementWarningObject,
break;
case NUMERIC_RANGE_ERROR_WARNING:
if (statementWarningObject != null) {
statementWarningObject.postWarning( JDError.getSQLWarning(JDError.EXC_DATA_TYPE_MISMATCH));
statementWarningObject.postWarningSQLState(JDError.EXC_DATA_TYPE_MISMATCH);
} else if (resultSetWarningObject != null ) {
resultSetWarningObject.postWarning( JDError.getSQLWarning(JDError.EXC_DATA_TYPE_MISMATCH));
resultSetWarningObject.postWarningSQLState( JDError.EXC_DATA_TYPE_MISMATCH);
}
break;
case NUMERIC_RANGE_ERROR_NONE:
Expand All @@ -6177,8 +6204,9 @@ public boolean testDataTruncation(AS400JDBCStatement statementWarningObject,
int actualSize = data.getActualSize();
// boolean isRead = sqlStatement_.isSelect(); //@pda jdbc40 //@pdc same
// as native (only select is read) //@trunc //@pdc match native
DataTruncation dt = new DataTruncation(parameterIndex, isParameter, false,
actualSize + truncated, actualSize); // @pdc jdbc40 //@trunc //@pdc
// Delay construction until needed.
// DataTruncation dt = new DataTruncation(parameterIndex, isParameter, false,
// actualSize + truncated, actualSize); // @pdc jdbc40 //@trunc //@pdc
// match native

// if 610 and number data type, then throw DataTruncation
Expand All @@ -6188,22 +6216,27 @@ public boolean testDataTruncation(AS400JDBCStatement statementWarningObject,
{ // @trunc2
if (characterTruncation_ == CHARACTER_TRUNCATION_WARNING) {
if (statementWarningObject != null) {
statementWarningObject.postWarning( dt);
statementWarningObject.postDataTruncationWarning( parameterIndex, isParameter, false,
actualSize + truncated, actualSize);
} else if (resultSetWarningObject != null ) {
resultSetWarningObject.postWarning( dt);
resultSetWarningObject.postDataTruncationWarning( parameterIndex, isParameter, false,
actualSize + truncated, actualSize);
}
} else {
throw dt; // @trunc2
throw new DataTruncation(parameterIndex, isParameter, false,
actualSize + truncated, actualSize); // @trunc2
}
} // @trunc2
else if ((sqlStatement != null) && (sqlStatement.isSelect())
&& (!sqlStatement.isSelectFromInsert())) // @trunc2 //@selins1
{

if (statementWarningObject != null) {
statementWarningObject.postWarning( dt);
statementWarningObject.postDataTruncationWarning( parameterIndex, isParameter, false,
actualSize + truncated, actualSize);
} else if (resultSetWarningObject != null ) {
resultSetWarningObject.postWarning( dt);
resultSetWarningObject.postDataTruncationWarning( parameterIndex, isParameter, false,
actualSize + truncated, actualSize);
}
// If we want the data replace on a warning. Go ahead and
// do the replacement.
Expand All @@ -6213,14 +6246,17 @@ else if ((sqlStatement != null) && (sqlStatement.isSelect())
} else {
if (characterTruncation_ == CHARACTER_TRUNCATION_WARNING) {
if (statementWarningObject != null ) {
statementWarningObject.postWarning( dt);
statementWarningObject.postDataTruncationWarning( parameterIndex, isParameter, false,
actualSize + truncated, actualSize);
checkRawBytes = true;
} else if (resultSetWarningObject != null ) {
resultSetWarningObject.postWarning( dt);
resultSetWarningObject.postDataTruncationWarning( parameterIndex, isParameter, false,
actualSize + truncated, actualSize);
}

} else {
throw dt;
throw new DataTruncation(parameterIndex, isParameter, false,
actualSize + truncated, actualSize);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1320,18 +1320,30 @@ public synchronized void notifyClose(AS400JDBCStatement statement, int id)

}

public synchronized void postWarning(SQLWarning sqlWarning) throws SQLException {
public synchronized void postWarningSQLState(String sqlState) throws SQLException {
boolean retryOperation = true;
while (retryOperation) {
try {
currentConnection_.postWarning(sqlWarning);
currentConnection_.postWarningSQLState(sqlState);
retryOperation = false;
} catch (SQLException e) {
retryOperation = handleException(e);
}
}

}
public synchronized void postWarning(int id, int errorCode, int returnCode) throws SQLException {
boolean retryOperation = true;
while (retryOperation) {
try {
currentConnection_.postWarning(id, errorCode, returnCode);
retryOperation = false;
} catch (SQLException e) {
retryOperation = handleException(e);
}
}

}

public synchronized CallableStatement prepareCall(String sql) throws SQLException {
boolean retryOperation = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ void notifyClose () throws SQLException {
stmt_.notifyClose();
}

void postWarning(SQLWarning sqlWarning) {
stmt_.postWarning(sqlWarning);
void postWarningSQLState(String sqlState) {
stmt_.postWarningSQLState(sqlState);
}

public void setCursorName(String name) throws SQLException {
Expand Down
Loading

0 comments on commit 431b8a7

Please sign in to comment.