Skip to content

Commit

Permalink
Merge pull request #3077 from SanojPunchihewa/dss
Browse files Browse the repository at this point in the history
Add support to use SQLXML type within the dataservice
  • Loading branch information
SanojPunchihewa authored Feb 6, 2024
2 parents 44e6c5c + 2a59ed4 commit c1edc8b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ private DataTypes() {
public static final String VARINT = "VARINT";
public static final String UUID = "UUID";
public static final String INETADDRESS = "INETADDRESS";
public static final String SQLXML = "SQLXML";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ public class DBUtils {
conversionTypes.put(DBConstants.DataTypes.TIMESTAMP, "java.sql.Timestamp");
conversionTypes.put(DBConstants.DataTypes.ANYURI, "java.net.URI");
conversionTypes.put(DBConstants.DataTypes.STRUCT, "java.sql.Struct");

conversionTypes.put(DBConstants.DataTypes.SQLXML, "java.sql.SQLXML");

conversionTypes.put(DBConstants.DataTypes.VARINT, "java.math.BigInteger");
conversionTypes.put(DBConstants.DataTypes.UUID, "java.lang.String");
conversionTypes.put(DBConstants.DataTypes.INETADDRESS, "java.lang.String");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.apache.axis2.databinding.utils.ConverterUtil;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Expand Down Expand Up @@ -68,6 +69,7 @@
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.sql.SQLXML;
import java.sql.Statement;
import java.sql.Struct;
import java.sql.Time;
Expand Down Expand Up @@ -1508,13 +1510,13 @@ private PreparedStatement createProcessedPreparedStatement(int queryType,
for (ParamValue arrayElement : value.getArrayValue()) {
this.setParamInPreparedStatement(
stmt, param, arrayElement == null ? null : arrayElement.toString(),
queryType, currentOrdinal);
queryType, currentOrdinal, conn);
currentOrdinal++;
}
} else { /* scalar value */
this.setParamInPreparedStatement(stmt, param,
value != null ? value.getScalarValue() : null, queryType,
currentOrdinal);
currentOrdinal, conn);
currentOrdinal++;
}
}
Expand Down Expand Up @@ -1618,7 +1620,7 @@ private String generateSQLupdateQuery(InternalParamCollection params, String que
}

private void setParamInPreparedStatement(PreparedStatement stmt, InternalParam param,
String value, int queryType, int index) throws SQLException, DataServiceFault {
String value, int queryType, int index, Connection connection) throws SQLException, DataServiceFault {
String paramName = param.getName();
String sqlType = param.getSqlType();
String paramType = param.getType();
Expand Down Expand Up @@ -1666,6 +1668,8 @@ private void setParamInPreparedStatement(PreparedStatement stmt, InternalParam p
setUserDefinedType(stmt, index, paramType, structType);
} else if (DBConstants.DataTypes.ARRAY.equals(sqlType)) {
setArrayValue(stmt, index, paramType, structType);
} else if (DBConstants.DataTypes.SQLXML.equals(sqlType)) {
setSQLXMLValue(queryType, value, paramType, stmt, index, connection);
} else {
throw new DataServiceFault("[" + this.getDataService().getName()
+ "] Found Unsupported data type : " + sqlType + " as input parameter.");
Expand Down Expand Up @@ -1781,6 +1785,40 @@ private void setBinaryValue(int queryType, String paramName, String value, Strin
}
}

private void setSQLXMLValue(int queryType, String value, String paramType,
PreparedStatement sqlQuery, int i, Connection connection) throws SQLException {
if (QueryTypes.IN.equals(paramType)) {
if (queryType == SQLQuery.DS_QUERY_TYPE_NORMAL) {
if (value == null) {
sqlQuery.setNull(i + 1, Types.SQLXML);
} else {
SQLXML xmlVal = connection.createSQLXML();
xmlVal.setString(StringEscapeUtils.unescapeXml(value));
sqlQuery.setSQLXML(i + 1, xmlVal);
}
} else {
if (value == null) {
((CallableStatement) sqlQuery).setNull(i + 1, Types.SQLXML);
} else {
SQLXML xmlVal = connection.createSQLXML();
xmlVal.setString(StringEscapeUtils.unescapeXml(value));
((CallableStatement) sqlQuery).setSQLXML(i + 1, xmlVal);
}
}
} else if (QueryTypes.INOUT.equals(paramType)) {
if (value == null) {
((CallableStatement) sqlQuery).setNull(i + 1, Types.SQLXML);
} else {
SQLXML xmlVal = connection.createSQLXML();
xmlVal.setString(StringEscapeUtils.unescapeXml(value));
((CallableStatement) sqlQuery).setSQLXML(i + 1, xmlVal);
}
((CallableStatement) sqlQuery).registerOutParameter(i + 1, Types.SQLXML);
} else {
((CallableStatement) sqlQuery).registerOutParameter(i + 1, Types.SQLXML);
}
}

private void setBlobValue(int queryType, String paramName, String value, String paramType,
PreparedStatement sqlQuery, int i) throws SQLException, DataServiceFault {
if ("IN".equals(paramType)) {
Expand Down Expand Up @@ -2260,6 +2298,10 @@ private ParamValue getOutparameterValue(CallableStatement cs, String type, int o
elementValue = cs.getClob(ordinal);
return new ParamValue(elementValue == null ? null :
deriveValueFromClob((Clob) elementValue));
} else if (type.equals(DBConstants.DataTypes.SQLXML)) {
elementValue = cs.getSQLXML(ordinal).getString();
return new ParamValue(elementValue == null ? null
: elementValue.toString());
} else if (type.equals(DBConstants.DataTypes.STRUCT)) {
elementValue = cs.getObject(ordinal);
return new ParamValue(elementValue == null ? null : (Struct) elementValue);
Expand Down

0 comments on commit c1edc8b

Please sign in to comment.