Skip to content

Commit

Permalink
Test Fix: testCoalesceJPQLQueryWithNullParameterValue, StoredProcedur…
Browse files Browse the repository at this point in the history
…eTest_Inout_Out_In bind, testEmpRecordInOut (#581)

Signed-off-by: Will Dazey <[email protected]>
  • Loading branch information
dazey3 authored and rfelcman committed Oct 10, 2019
1 parent f2584ae commit 8a232d4
Show file tree
Hide file tree
Showing 11 changed files with 202 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -839,12 +839,9 @@ public String buildProcedureCallString(StoredProcedureCall call, AbstractSession
Integer parameterType = call.getParameterTypes().get(index);
// If the argument is optional and null, ignore it.
if (!call.hasOptionalArguments() || !call.getOptionalArguments().contains(parameter) || (row.get(parameter) != null)) {
if (name != null && shouldPrintStoredProcedureArgumentNameInCall()) {
writer.write(getProcedureArgumentString());
writer.write(name);
writer.write(getProcedureArgumentSetter());
}
writer.write("?");

writer.write(getProcedureArgument(name, parameter, parameterType, call, session));

if (DatasourceCall.isOutputParameterType(parameterType)) {
if (requiresProcedureCallOuputToken()) {
writer.write(" ");
Expand Down Expand Up @@ -1502,17 +1499,20 @@ public String getPingSQL(){
}

/**
* Used for sp calls.
* Used for sp defs.
*/
public String getProcedureArgumentSetter() {
return " = ";
public String getProcedureArgumentString() {
return "";
}

/**
* Used for sp defs.
* Obtain the platform specific argument string
*/
public String getProcedureArgumentString() {
return "";
public String getProcedureArgument(String name, Object parameter, Integer parameterType, StoredProcedureCall call, AbstractSession session) {
if (name != null && shouldPrintStoredProcedureArgumentNameInCall()) {
return getProcedureArgumentString() + name + " = " + "?";
}
return "?";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -669,20 +669,28 @@ public void visit(CoalesceExpression expression) {
List<Expression> expressions = new ArrayList<Expression>();
List<Class<?>> types = new LinkedList<Class<?>>();

//cache the type of the expression so untyped children have a default type
Class<?> coalesceType = type[0];

// Create the Expression for each scalar expression
for (org.eclipse.persistence.jpa.jpql.parser.Expression child : expression.getExpression().children()) {
child.accept(this);
expressions.add(queryExpression);
types.add(type[0]);

// Set the type on an untyped ParameterExpression, so that
// valid types can be passed for null parameter values in JDBC
//get the expression type parsed from the child expression
Class<?> childType = type[0];

// Default the type on an untyped ParameterExpression to the cached expression type.
// This is to help provide a valid type for null parameter when binding JDBC parameter types
if (queryExpression.isParameterExpression()) {
ParameterExpression paramExpression = (ParameterExpression) queryExpression;
if (paramExpression.getType() == null || paramExpression.getType().equals(Object.class)) {
paramExpression.setType(type[0]);
paramExpression.setType(coalesceType);
childType = coalesceType;
}
}

types.add(childType);
}

// Create the COALESCE expression
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ public String getTableCreationSuffix() {
}

@Override
public String getProcedureArgumentSetter() {
public String getProcedureArgument(String name, Object parameter, Integer parameterType,
StoredProcedureCall call, AbstractSession session) {
if (name != null && shouldPrintStoredProcedureArgumentNameInCall()) {
return ":" + name;
}
return "";
}

Expand Down Expand Up @@ -127,11 +131,9 @@ public String buildProcedureCallString(StoredProcedureCall call, AbstractSession
Integer parameterType = call.getParameterTypes().get(index);
// If the argument is optional and null, ignore it.
if (!call.hasOptionalArguments() || !call.getOptionalArguments().contains(parameter) || (row.get(parameter) != null)) {
if (name != null && shouldPrintStoredProcedureArgumentNameInCall()) {
writer.write(":");
writer.write(name);
writer.write(getProcedureArgumentSetter());
}

writer.write(getProcedureArgument(name, parameter, parameterType, call, session));

if (DatasourceCall.isOutputParameterType(parameterType)) {
if (requiresProcedureCallOuputToken()) {
writer.write(" ");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 1998, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2019 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019 IBM Corporation. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -15,6 +16,7 @@
package org.eclipse.persistence.platform.database;

import java.io.*;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.*;
Expand Down Expand Up @@ -89,6 +91,20 @@ public void setParameterValueInDatabaseCall(Object parameter,
super.setParameterValueInDatabaseCall(databaseValue, statement, index, session);
}

/**
* INTERNAL:
* DBase does not support Time/Timestamp so we must map to strings.
*/
@Override
public void setParameterValueInDatabaseCall(Object parameter,
CallableStatement statement, String name, AbstractSession session) throws SQLException {
Object databaseValue = super.convertToDatabaseType(parameter);
if ((databaseValue instanceof java.sql.Time) || (databaseValue instanceof java.sql.Timestamp)) {
databaseValue = databaseValue.toString();
}
super.setParameterValueInDatabaseCall(databaseValue, statement, name, session);
}

/**
* INTERNAL:
* returns the maximum number of characters that can be used in a field
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2018 SAP. All rights reserved.
* Copyright (c) 2012, 2019 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019 IBM Corporation. All rights reserved.
* Copyright (c) 2012, 2019 SAP. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -496,11 +497,6 @@ public boolean shouldPrintStoredProcedureArgumentNameInCall() {
return false;
}

@Override
public boolean requiresProcedureCallOuputToken() {
return false;
}

@Override
public boolean supportsStoredFunctions() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.eclipse.persistence.expressions.Expression;
import org.eclipse.persistence.expressions.ExpressionOperator;
import org.eclipse.persistence.internal.databaseaccess.DatabaseCall;
import org.eclipse.persistence.internal.databaseaccess.DatasourceCall;
import org.eclipse.persistence.internal.databaseaccess.FieldTypeDefinition;
import org.eclipse.persistence.internal.expressions.ExpressionSQLPrinter;
import org.eclipse.persistence.internal.expressions.FunctionExpression;
Expand All @@ -68,6 +69,7 @@
import org.eclipse.persistence.queries.ObjectBuildingQuery;
import org.eclipse.persistence.queries.ReadQuery;
import org.eclipse.persistence.queries.SQLCall;
import org.eclipse.persistence.queries.StoredProcedureCall;
import org.eclipse.persistence.queries.ValueReadQuery;
import org.eclipse.persistence.tools.schemaframework.TableDefinition;

Expand Down Expand Up @@ -434,14 +436,6 @@ public Vector getNativeTableInfo(String table, String creator, AbstractSession s
return session.executeSelectingCall(new SQLCall(query));
}

/**
* Used for sp calls.
*/
@Override
public String getProcedureArgumentSetter() {
return "=>";
}

/**
* Used for sp calls.
*/
Expand Down Expand Up @@ -816,6 +810,15 @@ public boolean shouldPrintStoredProcedureArgumentNameInCall() {
return false;
}

@Override
public String getProcedureArgument(String name, Object parameter, Integer parameterType,
StoredProcedureCall call, AbstractSession session) {
if(name != null && DatasourceCall.IN.equals(parameterType) && !call.usesBinding(session)) {
return name + "=>" + "?";
}
return "?";
}

/**
* JDBC defines and outer join syntax, many drivers do not support this. So we normally avoid it.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 1998, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2018 IBM Corporation. All rights reserved.
* Copyright (c) 1998, 2019 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2019 IBM Corporation. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -22,6 +22,7 @@
package org.eclipse.persistence.platform.database;

import java.io.*;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
Expand Down Expand Up @@ -821,7 +822,19 @@ public void setParameterValueInDatabaseCall(Object parameter, PreparedStatement
statement.setObject(index, parameter);
return;
}

super.setParameterValueInDatabaseCall(parameter, statement, index, session);
}

@Override
public void setParameterValueInDatabaseCall(Object parameter, CallableStatement statement, String name,
AbstractSession session) throws SQLException {
if (driverSupportsOffsetDateTime && parameter instanceof OffsetDateTime) {
// avoid default logic, which loses offset when converting to java.sql.Timestamp
statement.setObject(name, parameter);
return;
}

super.setParameterValueInDatabaseCall(parameter, statement, name, session);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,11 @@ public void registerOutputParameter(CallableStatement statement, int index, int
statement.registerOutParameter(index, jdbcType, getTypeStrings().get(jdbcType));
}

@Override
public void registerOutputParameter(CallableStatement statement, int index, int jdbcType, String typeName) throws SQLException {
statement.registerOutParameter(index, jdbcType, getTypeStrings().get(jdbcType));
}

/**
* USed for sp calls.
*/
Expand Down
Loading

0 comments on commit 8a232d4

Please sign in to comment.