Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2025 Contributors to the Eclipse Foundation.
* Copyright (c) 1998, 2024 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2024 IBM Corporation. All rights reserved.
*
Expand Down Expand Up @@ -1082,10 +1083,13 @@ public void translate(AbstractRecord translationRow, AbstractRecord modifyRow, A
if (!isPrepared()) {
throw ValidationException.cannotTranslateUnpreparedCall(toString());
}

boolean bindParameters = usesBinding(session) && parameters != null;
boolean bindPartial = session.getPlatform().shouldBindPartialParameters();

if(session.getPlatform().shouldBindPartialParameters() && (this.parameters != null)) {
if (bindParameters && bindPartial) {
translateQueryStringAndBindParameters(translationRow, modifyRow, session);
} else if (usesBinding(session) && (this.parameters != null)) {
} else if (bindParameters) {
boolean hasParameterizedIN = false;
List<Object> parameters = getParameters();
int size = parameters.size();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2025 Contributors to the Eclipse Foundation.
* Copyright (c) 1998, 2025 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2025 IBM Corporation. All rights reserved.
*
Expand Down Expand Up @@ -476,7 +477,7 @@ public boolean shouldPrintOutputTokenAtStart() {
*/
@Override
public boolean shouldBindPartialParameters() {
return this.shouldBindPartialParameters;
return true;
}

/**
Expand Down Expand Up @@ -1783,7 +1784,7 @@ public boolean isNullAllowedInSelectClause() {
*/
@Override
public boolean isDynamicSQLRequiredForFunctions() {
if(shouldForceBindAllParameters()) {
if(shouldForceBindAllParameters() || shouldBindPartialParameters()) {
return false;
}
return !isCastRequired();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2025 Contributors to the Eclipse Foundation.
* Copyright (c) 2005, 2025 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2024 IBM Corporation. All rights reserved.
*
Expand Down Expand Up @@ -173,6 +174,18 @@ public boolean isDB2() {
//This class inherits from DB2. But it is not DB2
return false;
}

/**
* Used to determine if the platform should perform partial parameter binding or not
* Enabled for DB2 and DB2 for zOS to add support for partial binding
*/
@Override
public boolean shouldBindPartialParameters() {
// This class inherits from DB2. But it is not DB2
return this.shouldBindPartialParameters;
}



@Override
public String getSelectForUpdateString() {
Expand Down Expand Up @@ -906,20 +919,6 @@ protected ExpressionOperator roundOperator() {
return operator;
}

/**
* INTERNAL
* Derby has some issues with using parameters on certain functions and relations.
* This allows statements to disable binding, for queries, only in these cases.
* If users set casting on, then casting is used instead of dynamic SQL.
*/
@Override
public boolean isDynamicSQLRequiredForFunctions() {
if(shouldForceBindAllParameters()) {
return false;
}
return !isCastRequired();
}

/**
* INTERNAL:
* Use the JDBC maxResults and firstResultIndex setting to compute a value to use when
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2025 Contributors to the Eclipse Foundation.
* Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022 IBM Corporation. All rights reserved.
*
Expand Down Expand Up @@ -175,7 +176,9 @@ public void testQueryOrderByLiterals3() {
assertNotNull(dto01);
assertEquals(3, dto01.size());
assertEquals(1, _sql.size());
if(platform.isDB2Z() || platform.isDB2() || platform.isDerby()) {
if (platform.isDB2()) {
assertEquals("SELECT ITEM_INTEGER1 FROM SIMPLE_TBL01 WHERE (ITEM_STRING2 = ?) ORDER BY 1", _sql.remove(0));
} else if (platform.isDB2Z() || platform.isDerby()) {
assertEquals("SELECT ITEM_INTEGER1 FROM SIMPLE_TBL01 WHERE (ITEM_STRING2 = 'B') ORDER BY 1", _sql.remove(0));
} else {
assertEquals("SELECT ITEM_INTEGER1 FROM SIMPLE_TBL01 WHERE (ITEM_STRING2 = ?) ORDER BY ?", _sql.remove(0));
Expand All @@ -187,13 +190,16 @@ public void testQueryOrderByLiterals3() {
assertNotNull(dto01);
assertEquals(3, dto01.size());
assertEquals(1, _sql.size());
if(platform.isDB2Z() || platform.isDB2() || platform.isDerby()) {

if (platform.isDB2()) {
assertEquals("SELECT ITEM_INTEGER1 FROM SIMPLE_TBL01 WHERE (ITEM_STRING2 = ?) ORDER BY 1 ASC", _sql.remove(0));
} else if (platform.isDB2Z() || platform.isDerby()) {
assertEquals("SELECT ITEM_INTEGER1 FROM SIMPLE_TBL01 WHERE (ITEM_STRING2 = 'B') ORDER BY 1 ASC", _sql.remove(0));
} else {
assertEquals("SELECT ITEM_INTEGER1 FROM SIMPLE_TBL01 WHERE (ITEM_STRING2 = ?) ORDER BY ? ASC", _sql.remove(0));
}

// equivalent CriteriaBuilder
// Equivalent CriteriaBuilder
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Integer> cquery = cb.createQuery(Integer.class);
Root<EntityTbl01> root = cquery.from(EntityTbl01.class);
Expand All @@ -206,7 +212,10 @@ public void testQueryOrderByLiterals3() {
assertNotNull(dto01);
assertEquals(3, dto01.size());
assertEquals(1, _sql.size());
if(platform.isDB2Z() || platform.isDB2() || platform.isDerby()) {

if (platform.isDB2()) {
assertEquals("SELECT ITEM_INTEGER1 FROM SIMPLE_TBL01 WHERE (ITEM_STRING2 = ?) ORDER BY 1 ASC", _sql.remove(0));
} else if (platform.isDB2Z() || platform.isDB2() || platform.isDerby()) {
assertEquals("SELECT ITEM_INTEGER1 FROM SIMPLE_TBL01 WHERE (ITEM_STRING2 = 'B') ORDER BY 1 ASC", _sql.remove(0));
} else {
assertEquals("SELECT ITEM_INTEGER1 FROM SIMPLE_TBL01 WHERE (ITEM_STRING2 = ?) ORDER BY ? ASC", _sql.remove(0));
Expand Down Expand Up @@ -442,8 +451,11 @@ public void testQueryOrderByMix1() {
assertNotNull(dto01);
assertEquals(3, dto01.size());
assertEquals(1, _sql.size());
if(platform.isDB2Z() || platform.isDB2() || platform.isDerby()) {

if (platform.isDB2Z() || platform.isDerby()) {
assertEquals("SELECT ITEM_INTEGER1 FROM SIMPLE_TBL01 WHERE (ITEM_STRING2 = 'B') ORDER BY 1", _sql.remove(0));
} else if (platform.isDB2()) {
assertEquals("SELECT ITEM_INTEGER1 FROM SIMPLE_TBL01 WHERE (ITEM_STRING2 = ?) ORDER BY 1", _sql.remove(0));
} else {
assertEquals("SELECT ITEM_INTEGER1 FROM SIMPLE_TBL01 WHERE (ITEM_STRING2 = ?) ORDER BY ?", _sql.remove(0));
}
Expand All @@ -455,8 +467,11 @@ public void testQueryOrderByMix1() {
assertNotNull(dto01);
assertEquals(3, dto01.size());
assertEquals(1, _sql.size());
if(platform.isDB2Z() || platform.isDB2() || platform.isDerby()) {

if (platform.isDB2Z() || platform.isDerby()) {
assertEquals("SELECT ITEM_INTEGER1 FROM SIMPLE_TBL01 WHERE (ITEM_STRING2 = 'B') ORDER BY 1 ASC", _sql.remove(0));
} else if (platform.isDB2()) {
assertEquals("SELECT ITEM_INTEGER1 FROM SIMPLE_TBL01 WHERE (ITEM_STRING2 = ?) ORDER BY 1 ASC", _sql.remove(0));
} else {
assertEquals("SELECT ITEM_INTEGER1 FROM SIMPLE_TBL01 WHERE (ITEM_STRING2 = ?) ORDER BY ? ASC", _sql.remove(0));
}
Expand All @@ -476,8 +491,11 @@ public void testQueryOrderByMix1() {
assertNotNull(dto01);
assertEquals(3, dto01.size());
assertEquals(1, _sql.size());
if(platform.isDB2Z() || platform.isDB2() || platform.isDerby()) {

if (platform.isDB2Z() || platform.isDerby()) {
assertEquals("SELECT ITEM_INTEGER1 FROM SIMPLE_TBL01 WHERE (ITEM_STRING2 = 'B') ORDER BY 1 ASC", _sql.remove(0));
} else if (platform.isDB2()) {
assertEquals("SELECT ITEM_INTEGER1 FROM SIMPLE_TBL01 WHERE (ITEM_STRING2 = ?) ORDER BY 1 ASC", _sql.remove(0));
} else {
assertEquals("SELECT ITEM_INTEGER1 FROM SIMPLE_TBL01 WHERE (ITEM_STRING2 = ?) ORDER BY ? ASC", _sql.remove(0));
}
Expand All @@ -504,7 +522,7 @@ public void testQueryOrderByMix2() {

// DB2 and Derby does not support untyped parameter binding in ORDER BY clause
// 'emf2' sets 'shouldBindLiterals=true', which makes literal values bind as untyped parameters
if(platform.isDB2Z() || platform.isDB2() || platform.isDerby()) {
if (platform.isDB2Z() || platform.isDB2() || platform.isDerby()) {
return;
}

Expand All @@ -516,7 +534,7 @@ public void testQueryOrderByMix2() {
assertNotNull(dto01);
assertEquals(3, dto01.size());
assertEquals(1, _sql2.size());
if(platform.isDB2Z() || platform.isDB2() || platform.isDerby()) {
if (platform.isDB2Z() || platform.isDB2() || platform.isDerby()) {
assertEquals("SELECT ITEM_INTEGER1 FROM SIMPLE_TBL01 WHERE (ITEM_STRING2 = 'B') ORDER BY 1", _sql2.remove(0));
} else {
assertEquals("SELECT ITEM_INTEGER1 FROM SIMPLE_TBL01 WHERE (ITEM_STRING2 = ?) ORDER BY ?", _sql2.remove(0));
Expand All @@ -529,7 +547,7 @@ public void testQueryOrderByMix2() {
assertNotNull(dto01);
assertEquals(3, dto01.size());
assertEquals(1, _sql2.size());
if(platform.isDB2Z() || platform.isDB2() || platform.isDerby()) {
if (platform.isDB2Z() || platform.isDB2() || platform.isDerby()) {
assertEquals("SELECT ITEM_INTEGER1 FROM SIMPLE_TBL01 WHERE (ITEM_STRING2 = 'B') ORDER BY 1 ASC", _sql2.remove(0));
} else {
assertEquals("SELECT ITEM_INTEGER1 FROM SIMPLE_TBL01 WHERE (ITEM_STRING2 = ?) ORDER BY ? ASC", _sql2.remove(0));
Expand All @@ -550,7 +568,7 @@ public void testQueryOrderByMix2() {
assertNotNull(dto01);
assertEquals(3, dto01.size());
assertEquals(1, _sql2.size());
if(platform.isDB2Z() || platform.isDB2() || platform.isDerby()) {
if (platform.isDB2Z() || platform.isDB2() || platform.isDerby()) {
assertEquals("SELECT ITEM_INTEGER1 FROM SIMPLE_TBL01 WHERE (ITEM_STRING2 = 'B') ORDER BY 1 ASC", _sql2.remove(0));
} else {
assertEquals("SELECT ITEM_INTEGER1 FROM SIMPLE_TBL01 WHERE (ITEM_STRING2 = ?) ORDER BY ? ASC", _sql2.remove(0));
Expand Down
Loading
Loading