Skip to content

Commit

Permalink
CallParameterMetaData detects function return parameter specifically
Browse files Browse the repository at this point in the history
Closes gh-25588
  • Loading branch information
jhoeller committed Sep 7, 2020
1 parent 613b05d commit e797398
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 16 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,25 +30,39 @@
*/
public class CallParameterMetaData {

private final boolean function;

@Nullable
private String parameterName;
private final String parameterName;

private int parameterType;
private final int parameterType;

private int sqlType;
private final int sqlType;

@Nullable
private String typeName;
private final String typeName;

private boolean nullable;
private final boolean nullable;


/**
* Constructor taking all the properties.
* Constructor taking all the properties except the function marker.
*/
@Deprecated
public CallParameterMetaData(
@Nullable String columnName, int columnType, int sqlType, @Nullable String typeName, boolean nullable) {

this(false, columnName, columnType, sqlType, typeName, nullable);
}

/**
* Constructor taking all the properties including the function marker.
* @since 5.2.9
*/
public CallParameterMetaData(boolean function, @Nullable String columnName, int columnType,
int sqlType, @Nullable String typeName, boolean nullable) {

this.function = function;
this.parameterName = columnName;
this.parameterType = columnType;
this.sqlType = sqlType;
Expand All @@ -58,15 +72,23 @@ public CallParameterMetaData(


/**
* Get the parameter name.
* Return whether this parameter is declared in a function.
* @since 5.2.9
*/
public boolean isFunction() {
return this.function;
}

/**
* Return the parameter name.
*/
@Nullable
public String getParameterName() {
return this.parameterName;
}

/**
* Get the parameter type.
* Return the parameter type.
*/
public int getParameterType() {
return this.parameterType;
Expand All @@ -75,31 +97,33 @@ public int getParameterType() {
/**
* Determine whether the declared parameter qualifies as a 'return' parameter
* for our purposes: type {@link DatabaseMetaData#procedureColumnReturn} or
* {@link DatabaseMetaData#procedureColumnResult}.
* {@link DatabaseMetaData#procedureColumnResult}, or in case of a function,
* {@link DatabaseMetaData#functionReturn}.
* @since 4.3.15
*/
public boolean isReturnParameter() {
return (this.parameterType == DatabaseMetaData.procedureColumnReturn ||
this.parameterType == DatabaseMetaData.procedureColumnResult);
return (this.function ? this.parameterType == DatabaseMetaData.functionReturn :
(this.parameterType == DatabaseMetaData.procedureColumnReturn ||
this.parameterType == DatabaseMetaData.procedureColumnResult));
}

/**
* Get the parameter SQL type.
* Return the parameter SQL type.
*/
public int getSqlType() {
return this.sqlType;
}

/**
* Get the parameter type name.
* Return the parameter type name.
*/
@Nullable
public String getTypeName() {
return this.typeName;
}

/**
* Get whether the parameter is nullable.
* Return whether the parameter is nullable.
*/
public boolean isNullable() {
return this.nullable;
Expand Down
Expand Up @@ -399,7 +399,7 @@ else if ("Oracle".equals(databaseMetaData.getDatabaseProductName())) {
}
else {
int nullable = (function ? DatabaseMetaData.functionNullable : DatabaseMetaData.procedureNullable);
CallParameterMetaData meta = new CallParameterMetaData(columnName, columnType,
CallParameterMetaData meta = new CallParameterMetaData(function, columnName, columnType,
columns.getInt("DATA_TYPE"), columns.getString("TYPE_NAME"),
columns.getInt("NULLABLE") == nullable);
this.callParameterMetaData.add(meta);
Expand Down

0 comments on commit e797398

Please sign in to comment.