-
Notifications
You must be signed in to change notification settings - Fork 43
UDP Implementation #86
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,4 +36,5 @@ | |
requires transitive r2dbc.spi; | ||
|
||
exports oracle.r2dbc; | ||
exports oracle.r2dbc.impl; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -212,7 +212,8 @@ else if (Object.class.equals(type)) { | |
// Use the default type mapping if Object.class has been specified. | ||
// This method is invoked recursively with the default mapping, so long | ||
// as Object.class is not also the default mapping. | ||
Class<?> defaultType = readablesMetadata.get(index).getJavaType(); | ||
Class<?> defaultType = readablesMetadata.get(index).getType().getJavaType(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you explain why we need this change? I feel like I'm missing something :) |
||
|
||
value = Object.class.equals(defaultType) | ||
? jdbcReadable.getObject(index, Object.class) | ||
: convert(index, defaultType); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -694,7 +694,7 @@ private void bindObject(int index, Object object) { | |
if (object == null){ | ||
bindValues[index] = NULL_BIND; | ||
} | ||
else if (object instanceof Parameter) { | ||
else if (object instanceof Parameter || object instanceof UserDefinedType) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The R2DBC SPI uses instances of Parameter.Out to represent out binds. It should be possible to do so with UserDefinedType, as in: statement.bind(Parameters.out(new UserDefinedType(...))) There should be no need to support mapping UserDefinedType objects directly. |
||
bindParameter(index, (Parameter)object); | ||
} | ||
else if (object instanceof Parameter.In | ||
|
@@ -716,7 +716,7 @@ else if (object instanceof Parameter.In | |
* @throws IllegalArgumentException If the Java or SQL type of the | ||
* {@code parameter} is not supported. | ||
*/ | ||
private void bindParameter(int index, Parameter parameter) { | ||
private void bindParameter(int index, Object parameter) { | ||
|
||
if (parameter instanceof Parameter.Out) { | ||
if (! batch.isEmpty()) | ||
|
@@ -725,21 +725,35 @@ private void bindParameter(int index, Parameter parameter) { | |
throw outParameterWithGeneratedValues(); | ||
} | ||
|
||
Type parameterType; | ||
Object parameterValue; | ||
if(parameter instanceof Parameter){ | ||
parameterType= ((Parameter) parameter).getType(); | ||
parameterValue= ((Parameter) parameter).getValue(); | ||
} else { | ||
throw new IllegalArgumentException("Invalid parameter type: "+parameter); | ||
} | ||
|
||
// TODO: This method should check if Java type can be converted to the | ||
// specified SQL type. If the conversion is unsupported, then JDBC | ||
// setObject(...) will throw when this statement is executed. The correct | ||
// behavior is to throw IllegalArgumentException here, and not from | ||
// execute() | ||
Type r2dbcType = | ||
requireNonNull(parameter.getType(), "Parameter type is null"); | ||
SQLType jdbcType = toJdbcType(r2dbcType); | ||
Type r2dbcType= requireNonNull(parameterType, "Parameter type is null"); | ||
|
||
SQLType jdbcType; | ||
if(r2dbcType instanceof UserDefinedType){ | ||
jdbcType = toJdbcType(r2dbcType.getJavaType()); | ||
} else { | ||
jdbcType = toJdbcType(r2dbcType); | ||
} | ||
|
||
if (jdbcType == null) { | ||
throw new IllegalArgumentException( | ||
"Unsupported SQL type: " + r2dbcType); | ||
} | ||
|
||
requireSupportedJavaType(parameter.getValue()); | ||
requireSupportedJavaType(parameterValue); | ||
bindValues[index] = parameter; | ||
} | ||
|
||
|
@@ -983,7 +997,7 @@ protected final Publisher<Void> bind(Object[] binds) { | |
List<Publisher<Void>> bindPublishers = null; | ||
for (int i = 0; i < binds.length; i++) { | ||
|
||
if (binds[i] instanceof Parameter.Out | ||
if ((((binds[i] instanceof Parameter.Out) || (binds[i] instanceof UserDefinedType))) | ||
&& !(binds[i] instanceof Parameter.In)) | ||
continue; | ||
|
||
|
@@ -1339,7 +1353,7 @@ private JdbcCall( | |
super(callableStatement, bindValues); | ||
|
||
outBindIndexes = IntStream.range(0, bindValues.length) | ||
.filter(i -> bindValues[i] instanceof Parameter.Out) | ||
.filter(i -> bindValues[i] instanceof Parameter.Out || bindValues[i] instanceof UserDefinedType) | ||
.toArray(); | ||
|
||
OutParameterMetadata[] metadataArray = | ||
|
@@ -1351,8 +1365,10 @@ private JdbcCall( | |
// Use the parameter name, or the index if the parameter is unnamed | ||
String name = requireNonNullElse( | ||
parameterNames.get(bindIndex), String.valueOf(i)); | ||
metadataArray[i] = createParameterMetadata( | ||
name, ((Parameter)bindValues[bindIndex]).getType()); | ||
if(bindValues[bindIndex] instanceof Parameter){ | ||
metadataArray[i] = createParameterMetadata( | ||
name, ((Parameter)bindValues[bindIndex]).getType()); | ||
} | ||
} | ||
|
||
this.metadata = createOutParametersMetadata(metadataArray); | ||
|
@@ -1377,8 +1393,15 @@ private Publisher<Void> registerOutParameters() { | |
|
||
for (int i : outBindIndexes) { | ||
Type type = ((Parameter) binds[i]).getType(); | ||
SQLType jdbcType = toJdbcType(type); | ||
callableStatement.registerOutParameter(i + 1, jdbcType); | ||
SQLType jdbcType; | ||
|
||
if(type instanceof UserDefinedType){ | ||
jdbcType = toJdbcType(type.getJavaType()); | ||
callableStatement.registerOutParameter(i+1,jdbcType,type.getName()); | ||
} else { | ||
jdbcType = toJdbcType(type); | ||
callableStatement.registerOutParameter(i+1, jdbcType); | ||
} | ||
} | ||
}); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package oracle.r2dbc.impl; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the need for exporting the impl package came from here. |
||
|
||
import io.r2dbc.spi.Type; | ||
|
||
public final class UserDefinedType implements Type { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We must write a JavaDoc before merging any code. The doc should capture the rationale which was present in the mind of the programmer who wrote the code: What problem was the code intended to solve, and how did the programmer intend for their code to be used? |
||
private final Class sqlClassType; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had been thinking to add new Type constants in OracleR2dbcTypes: And these SQL types can map to Java classes of the java.sql package: Struct, Array, and Ref All this is to say that UserDefinedType can retain an io.r2dbc.spi.Type field, rather than a Class field. The Type field would be one of STRUCT, ARRAY, REF. We can then implement getJavaType to return the java type mapping for this Type field. Does this make sense? |
||
private final String typeName; | ||
|
||
public UserDefinedType(Class sqlClassType, String typeName) { | ||
this.sqlClassType = sqlClassType; | ||
this.typeName = typeName; | ||
} | ||
|
||
@Override | ||
public Class<?> getJavaType() { | ||
return sqlClassType; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return typeName; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The impl package is not part of the public API. We can not export it.