Skip to content

Commit

Permalink
Improve EclipseLink query parameter binding behavior
Browse files Browse the repository at this point in the history
Signed-off-by: Will Dazey <dazeydev.3@gmail.com>
  • Loading branch information
dazey3 authored and rfelcman committed Jun 23, 2022
1 parent fc5106d commit 096aa3e
Show file tree
Hide file tree
Showing 61 changed files with 4,537 additions and 1,201 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1016,19 +1016,40 @@ public class PersistenceUnitProperties {
public static final String PARTITIONING_CALLBACK = "eclipselink.partitioning.callback";

/**
* Property "<code>eclipselink.jdbc.bind-parameters</code>" configures whether parameter binding will be used in the
* creation of JDBC prepared statements. Usage of parameter binding is
* generally a performance optimization allowing for SQL and prepared
* statement caching as well as usage of batch writing.
* Property "<code>eclipselink.jdbc.bind-parameters</code>" configures whether parameter binding
* should be used in the creation of JDBC prepared statements.
* <p>
* Usage of parameter binding is generally a performance optimization;
* allowing for SQL and prepared statement caching, as well as usage of batch writing.
* <p>
* <b>Allowed Values:</b>
* <ul>
* <li>"<code>false</code>" - values will be written literally into the generated SQL
* <li>"<code>true</code>" (DEFAULT) - binding will be used
* <li>"<code>false</code>" - all values will be written literally into the generated SQL
* <li>"<code>true</code>" (DEFAULT) - all values will be bound as parameters in the generated SQL
* </ul>
*/
public static final String JDBC_BIND_PARAMETERS = "eclipselink.jdbc.bind-parameters";

/**
* Property "<code>eclipselink.jdbc.allow-partial-bind-parameters</code>" configures whether
* partial parameter binding should be allowed in the creation of JDBC prepared statements.
* <p>
* EclipseLink determines binding behavior based on the database platform's support for binding.
* If the database platform doesn't support binding for a specific expression, EclipseLink disables
* all binding for the whole query. Setting this property to 'true' will allow EclipseLink to bind
* per expression, instead of per query.
* <p>
* Usage of parameter binding is generally a performance optimization;
* allowing for SQL and prepared statement caching, as well as usage of batch writing.
* <p>
* <b>Allowed Values:</b>
* <ul>
* <li>"<code>false</code>" (DEFAULT) - EclipseLink either binds all parameters or no parameters; depending on database support
* <li>"<code>true</code>" - EclipseLink binds parameters per SQL function/expression
* </ul>
*/
public static final String JDBC_ALLOW_PARTIAL_PARAMETERS = "eclipselink.jdbc.allow-partial-bind-parameters";

/**
* Property "<code>eclipselink.jdbc.force-bind-parameters</code>" enables parameter binding
* in the creation of JDBC prepared statements. Some database platforms disable parameter binding
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 1998, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021 IBM Corporation. All rights reserved.
* Copyright (c) 1998, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2022 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 Down Expand Up @@ -750,10 +750,8 @@ public Expression caseStatement(Map caseItems, Object defaultItem) {
* @see ArgumentListFunctionExpression
*/
public ArgumentListFunctionExpression caseStatement() {

ListExpressionOperator caseOperator = (ListExpressionOperator)getOperator(ExpressionOperator.Case);
ListExpressionOperator clonedCaseOperator = new ListExpressionOperator();
caseOperator.copyTo(clonedCaseOperator);
ExpressionOperator caseOperator = getOperator(ExpressionOperator.Case);
ExpressionOperator clonedCaseOperator = caseOperator.clone();

ArgumentListFunctionExpression expression = new ArgumentListFunctionExpression();
expression.setBaseExpression(this);
Expand Down Expand Up @@ -822,9 +820,8 @@ public Expression caseConditionStatement(Map<Expression, Object> caseConditions,
* @see ArgumentListFunctionExpression
*/
public ArgumentListFunctionExpression caseConditionStatement() {
ListExpressionOperator caseOperator = (ListExpressionOperator)getOperator(ExpressionOperator.CaseCondition);
ListExpressionOperator clonedCaseOperator = new ListExpressionOperator();
caseOperator.copyTo(clonedCaseOperator);
ExpressionOperator caseOperator = getOperator(ExpressionOperator.CaseCondition);
ExpressionOperator clonedCaseOperator = caseOperator.clone();

ArgumentListFunctionExpression expression = new ArgumentListFunctionExpression();
expression.setBaseExpression(this);
Expand Down Expand Up @@ -885,9 +882,8 @@ public ArgumentListFunctionExpression coalesce(Collection expressions) {
}

public ArgumentListFunctionExpression coalesce() {
ListExpressionOperator coalesceOperator = (ListExpressionOperator)getOperator(ExpressionOperator.Coalesce);
ListExpressionOperator clonedCoalesceOperator = new ListExpressionOperator();
coalesceOperator.copyTo(clonedCoalesceOperator);
ExpressionOperator coalesceOperator = getOperator(ExpressionOperator.Coalesce);
ExpressionOperator clonedCoalesceOperator = coalesceOperator.clone();

ArgumentListFunctionExpression expression = new ArgumentListFunctionExpression();
expression.setBaseExpression(this);
Expand Down Expand Up @@ -2003,14 +1999,27 @@ public ExpressionOperator getOperator() {
* INTERNAL:
* Create a new expression tree with the named operator. Part of the implementation of user-level "get"
*/
public ExpressionOperator getOperator(int selector) {
public static ExpressionOperator getOperator(int selector) {
/*
* Get an operator based on a user defined function, if it exists.
*/
ExpressionOperator result = ExpressionOperator.getOperator(Integer.valueOf(selector));
if (result != null) {
return result;
}

// Make a temporary operator which we expect the platform
// to supply later.
/*
* Create an operator based on known selectors.
* This is actually a temporary object which we expect Platforms to supply later.
* @see org.eclipse.persistence.internal.expressions.CompoundExpression#initializePlatformOperator(DatabasePlatform platform)
* @see org.eclipse.persistence.internal.expressions.FunctionExpression#initializePlatformOperator(DatabasePlatform platform)
*/
result = ExpressionOperator.getInternalOperator(Integer.valueOf(selector));
if (result != null) {
return result;
}

// Create a default Function ExpressionOperator
result = new ExpressionOperator();
result.setSelector(selector);
result.setNodeClass(ClassConstants.FunctionExpression_Class);
Expand Down
Loading

0 comments on commit 096aa3e

Please sign in to comment.