Skip to content

Commit

Permalink
Update expressions to use Lists instead of Vectors
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Jungmann <[email protected]>
  • Loading branch information
lukasj committed Feb 28, 2024
1 parent 33339de commit 0acf479
Show file tree
Hide file tree
Showing 48 changed files with 448 additions and 513 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3405,7 +3405,7 @@ public void initializeMultipleTablePrimaryKeyFields() {
getQueryManager().setInternalMultipleTableJoinExpression(joinExpression);
}
if (getQueryManager().hasCustomMultipleTableJoinExpression()) {
Map tablesJoinExpressions = SQLSelectStatement.mapTableToExpression(joinExpression, getTables());
Map<DatabaseTable, Expression> tablesJoinExpressions = SQLSelectStatement.mapTableToExpression(joinExpression, getTables());
getQueryManager().getTablesJoinExpressions().putAll(tablesJoinExpressions);
}
if (isChild && (additionalTablesSize > 0)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ public SQLSelectStatement buildClassIndicatorSelectStatement(ObjectLevelReadQuer
selectStatement.addTable(classIndicatorField.getTable());
selectStatement.addField(getClassIndicatorField());
// 2612538 - the default size of Map (32) is appropriate
Map clonedExpressions = new IdentityHashMap();
Map<Expression, Expression> clonedExpressions = new IdentityHashMap<>();
selectStatement.setWhereClause(((ExpressionQueryMechanism)query.getQueryMechanism()).buildBaseSelectionCriteria(false, clonedExpressions));
appendWithAllSubclassesExpression(selectStatement);
selectStatement.setTranslationRow(query.getTranslationRow());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,7 @@ public void iterate(Expression each) {
/**
* INTERNAL:
*/
public Expression copiedVersionFrom(Map alreadyDone) {
public Expression copiedVersionFrom(Map<Expression, Expression> alreadyDone) {
if (alreadyDone == null) {
// For sub-selects no cloning is done.
return this;
Expand Down Expand Up @@ -3899,7 +3899,7 @@ public Expression performOperator(ExpressionOperator anOperator, List args) {
return anOperator.expressionForArguments(this, args);
}

protected void postCopyIn(Map alreadyDone) {
protected void postCopyIn(Map<Expression, Expression> alreadyDone) {
}

/**
Expand Down Expand Up @@ -3981,7 +3981,7 @@ public Expression ref() {
return getFunction(ExpressionOperator.Ref);
}

protected Expression registerIn(Map alreadyDone) {
protected Expression registerIn(Map<Expression, Expression> alreadyDone) {
Expression copy = shallowClone();
alreadyDone.put(this, copy);
copy.postCopyIn(alreadyDone);
Expand All @@ -3995,7 +3995,7 @@ protected Expression registerIn(Map alreadyDone) {
*/
public Expression replace(Object stringToReplace, Object stringToReplaceWith) {
ExpressionOperator anOperator = getOperator(ExpressionOperator.Replace);
List args = new ArrayList(2);
List<Object> args = new ArrayList<>(2);
args.add(stringToReplace);
args.add(stringToReplaceWith);
return anOperator.expressionForArguments(this, args);
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// tware - initial API and implementation from for JPA 2.0 criteria API
package org.eclipse.persistence.expressions;

import org.eclipse.persistence.internal.helper.Helper;
import java.util.Arrays;

/**
* INTERNAL:
Expand Down Expand Up @@ -57,10 +57,10 @@ public void copyTo(ExpressionOperator operator){
if(operator == null)
return;

if (operator instanceof ListExpressionOperator){
((ListExpressionOperator)operator).startStrings = Helper.copyStringArray(startStrings);
((ListExpressionOperator)operator).separators = Helper.copyStringArray(separators);
((ListExpressionOperator)operator).terminationStrings = Helper.copyStringArray(terminationStrings);
if (operator instanceof ListExpressionOperator listExpressionOperator){
listExpressionOperator.startStrings = startStrings == null ? null : Arrays.copyOf(startStrings, startStrings.length);
listExpressionOperator.separators = separators == null ? null : Arrays.copyOf(separators, separators.length);
listExpressionOperator.terminationStrings = terminationStrings == null ? null : Arrays.copyOf(terminationStrings, terminationStrings.length);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import org.eclipse.persistence.expressions.ExpressionOperator;
import org.eclipse.persistence.internal.expressions.FunctionExpression;

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import static org.eclipse.persistence.expressions.ExpressionOperator.SDO_FILTER;
import static org.eclipse.persistence.expressions.ExpressionOperator.SDO_NN;
Expand Down Expand Up @@ -134,7 +134,7 @@ public static Expression nearestNeighbor(Expression geom1, Object geom2, Spatial
* @param operator the ordinal of the operator
*/
public static Expression getSpatialExpression(int operator, Expression geom1, Object geom2, String params) {
List<Object> vParameters = new Vector<>(2);
List<Object> vParameters = new ArrayList<>(2);
vParameters.add(geom2);
//Bug 5885276, the empty string either like " " or "" needs to be substituted
//by null prior to passing to Geometry call.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2024 Oracle and/or its affiliates. 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 @@ -19,18 +19,18 @@
/**
* PUBLIC:
* A utility class used to set parameters on spatial operators within TopLink's
* expression framework. This class allows the aptial operator parameters to be
* passed in directly as a string or to be programatically configured using the
* expression framework. This class allows the spatial operator parameters to be
* passed in directly as a string or to be programmatically configured using the
* attributes defined and the enum types. Each spatial operator offers different
* parameter arguments and values. This class does not enforce these rules but
* instead leaves it to the caller to decide what values they want included.
* <p>
* When providing the parameter string through setParams or the constructor none
* of the other values will be used. Instead the string as provided will be used.
* of the other values will be used. Instead, the string as provided will be used.
* <p>
* Creating an instance of SpatialParameters without configuring it and passing
* it into the SpatialExpressionFactory call is equivalent to passing in null.
* The resulting SQL will have NULL writen out for the parameters argument to the
* The resulting SQL will have NULL written out for the parameters argument to the
* spatial operator.
*
* @since Oracle TopLink 11.1.1.0.0
Expand All @@ -44,12 +44,12 @@ public class SpatialParameters {
private QueryType queryType = null;
private Mask[] masks = null;

private static String UNIT_PARAM = "UNIT=";
private static String MAX_RES_PARAM = "MAX_RESOLUTION=";
private static String MIN_RES_PARAM = "MIN_RESOLUTION=";
private static String DISTANCE_PARAM = "DISTANCE=";
private static String QUERYTYPE_PARAM = "QUERYTYPE=";
private static String MASK_PARAM = "MASK=";
private static final String UNIT_PARAM = "UNIT=";
private static final String MAX_RES_PARAM = "MAX_RESOLUTION=";
private static final String MIN_RES_PARAM = "MIN_RESOLUTION=";
private static final String DISTANCE_PARAM = "DISTANCE=";
private static final String QUERYTYPE_PARAM = "QUERYTYPE=";
private static final String MASK_PARAM = "MASK=";

public SpatialParameters() {
}
Expand Down Expand Up @@ -148,7 +148,7 @@ public SpatialParameters.QueryType getQueryType() {
/**
* PUBLIC:
* Set the MASK parameter
* @param masks an array of values from the SpatialParmeters.Mask enum
* @param masks an array of values from the SpatialParameters.Mask enum
* @return this instance of SpatialParameters
*/
public SpatialParameters setMasks(Mask[] masks) {
Expand All @@ -159,7 +159,7 @@ public SpatialParameters setMasks(Mask[] masks) {
/**
* PUBLIC:
* Set the MASK parameter
* @param mask a value from the SpatialParmeters.Mask enum
* @param mask a value from the SpatialParameters.Mask enum
* @return this instance of SpatialParameters
*/
public SpatialParameters setMask(Mask mask) {
Expand Down Expand Up @@ -236,15 +236,13 @@ public enum Units {
MILE, // Mile
NAUT_MILE, // Nautical Mile
FOOT, // Foot
INCH,
; // Inch
INCH // Inch
}

public enum QueryType {
WINDOW,
JOIN,
FILTER,
;
FILTER
}

public enum Mask {
Expand All @@ -257,7 +255,6 @@ public enum Mask {
CONTAINS,
COVERS,
ANYINTERACT,
ON,
;
ON
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void printSQL(ExpressionSQLPrinter printer) {


@Override
protected void postCopyIn(Map alreadyDone) {
protected void postCopyIn(Map<Expression, Expression> alreadyDone) {
Boolean hasLastChildCopy = hasLastChild;
hasLastChild = null;
super.postCopyIn(alreadyDone);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2023 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2024 Oracle and/or its affiliates. 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 @@ -63,7 +63,7 @@ public ExpressionBuilder getBuilder() {
* Used for cloning.
*/
@Override
protected void postCopyIn(Map alreadyDone) {
protected void postCopyIn(Map<Expression, Expression> alreadyDone) {
super.postCopyIn(alreadyDone);
if (this.baseExpression != null) {
setBaseExpression(this.baseExpression.copiedVersionFrom(alreadyDone));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@

import java.io.BufferedWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.Vector;
import java.util.List;

/**
* @author cdelahun
Expand Down Expand Up @@ -125,22 +126,17 @@ public Object valueFromObject(Object object, AbstractSession session, AbstractRe

// If from an anyof the object will be a collection of values,
// A new vector must union the object values and the values extracted from it.
if (object instanceof Vector) {
Vector comparisonVector = new Vector(((Vector)object).size() + 2);
for (Iterator iterator1 = ((Vector) object).iterator();
iterator1.hasNext();) {
Object vectorObject = iterator1.next();
if (object instanceof @SuppressWarnings({"rawtypes"}) List v) {
List<Object> comparisonVector = new ArrayList<>(v.size() + 2);
for (Object vectorObject : v) {
if (vectorObject == null) {
comparisonVector.add(null);
} else {
Object valueOrValues = typeValueFromObject(vectorObject, session);

// If a collection of values were extracted union them.
if (valueOrValues instanceof Vector) {
for (Iterator iterator = ((Vector) valueOrValues).iterator();
iterator.hasNext();) {
comparisonVector.add(iterator.next());
}
if (valueOrValues instanceof @SuppressWarnings({"rawtypes"}) List vv) {
comparisonVector.addAll(vv);
} else {
comparisonVector.add(valueOrValues);
}
Expand Down Expand Up @@ -190,31 +186,31 @@ public Object getFieldValue(Object objectValue, AbstractSession session) {
return null;
}

if (objectValue instanceof Collection values) {
// This can actually be a collection for IN within expressions... however it would be better for expressions to handle this.
Vector fieldValues = new Vector(values.size());
for (Iterator iterator = values.iterator(); iterator.hasNext();) {
Object value = iterator.next();
if (!(value instanceof Expression)){
value = getFieldValue(value, session);
}
fieldValues.add(value);
if (objectValue instanceof @SuppressWarnings({"rawtypes"}) Collection values) {
// This can actually be a collection for IN within expressions... however it would be better for expressions to handle this.
List<Object> fieldValues = new ArrayList<>(values.size());
for (Iterator<?> iterator = values.iterator(); iterator.hasNext();) {
Object value = iterator.next();
if (!(value instanceof Expression)){
value = getFieldValue(value, session);
}
return fieldValues;
fieldValues.add(value);
}
return fieldValues;
} else {
if (! (objectValue instanceof Class) ){
if (! (objectValue instanceof @SuppressWarnings({"rawtypes"}) Class cls) ){
throw QueryException.invalidTypeExpression(objectValue.getClass().toString());
}

ClassDescriptor descriptor = session.getDescriptor((Class)objectValue);
ClassDescriptor descriptor = session.getDescriptor(cls);
if (descriptor == null){
throw QueryException.invalidTypeExpression(objectValue.getClass().toString());
}

if (descriptor.hasInheritance() && !descriptor.getInheritancePolicy().shouldUseClassNameAsIndicator()){
return descriptor.getInheritancePolicy().getClassIndicatorMapping().get(objectValue);
return descriptor.getInheritancePolicy().getClassIndicatorMapping().get(cls);
} else {
return ((Class)objectValue).getName();
return cls.getName();
}
}
}
Expand Down Expand Up @@ -265,7 +261,7 @@ public boolean isAttribute() {
* additional expressions to normalizer both times, and the foreign key join
* replaces the equal expression.
*/
public Expression normalize(ExpressionNormalizer normalizer, Vector foreignKeyJoinPointer) {
public Expression normalize(ExpressionNormalizer normalizer, List<?> foreignKeyJoinPointer) {
if (hasBeenNormalized()) {
return this;
}
Expand Down Expand Up @@ -316,8 +312,8 @@ protected DatabaseTable getAliasedTable() {
* Return all the fields
*/
@Override
public Vector getFields() {
Vector result = new Vector(1);
public List<DatabaseField> getFields() {
List<DatabaseField> result = new ArrayList<>(1);
DatabaseField field = getField();
if (field != null) {
result.add(field);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
import org.eclipse.persistence.internal.sessions.AbstractRecord;
import org.eclipse.persistence.internal.sessions.AbstractSession;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Vector;

/**
* Used for wrapping collection of values or expressions.
Expand All @@ -41,7 +42,7 @@ public void printSQL(ExpressionSQLPrinter printer) {
if(this.localBase != null) {
value = this.localBase.getFieldValue(value, getSession());
}
printer.printList((Collection)value, this.canBind);
printer.printList((Collection<?>) value, this.canBind);
}

/**
Expand All @@ -51,12 +52,12 @@ public void printSQL(ExpressionSQLPrinter printer) {
*/
@Override
public Object valueFromObject(Object object, AbstractSession session, AbstractRecord translationRow, int valueHolderPolicy, boolean isObjectUnregistered) {
if (this.value instanceof Collection values) {
Vector fieldValues = new Vector(values.size());
for (Iterator iterator = values.iterator(); iterator.hasNext();) {
if (this.value instanceof @SuppressWarnings({"rawtypes"}) Collection values) {
List<Object> fieldValues = new ArrayList<>(values.size());
for (Iterator<?> iterator = values.iterator(); iterator.hasNext();) {
Object value = iterator.next();
if (value instanceof Expression){
value = ((Expression)value).valueFromObject(object, session, translationRow, valueHolderPolicy, isObjectUnregistered);
if (value instanceof Expression expression){
value = expression.valueFromObject(object, session, translationRow, valueHolderPolicy, isObjectUnregistered);
} else if(this.localBase != null) {
value = this.localBase.getFieldValue(value, session);
}
Expand All @@ -74,11 +75,11 @@ public Object valueFromObject(Object object, AbstractSession session, AbstractRe
@Override
public void setLocalBase(Expression e) {
super.setLocalBase(e);
if (this.value instanceof Collection values) {
for (Iterator iterator = values.iterator(); iterator.hasNext();) {
if (this.value instanceof @SuppressWarnings({"rawtypes"}) Collection values) {
for (Iterator<?> iterator = values.iterator(); iterator.hasNext();) {
Object val = iterator.next();
if (val instanceof Expression){
((Expression)val).setLocalBase(e);
if (val instanceof Expression expression){
expression.setLocalBase(e);
}
}
}
Expand All @@ -89,14 +90,14 @@ public void setLocalBase(Expression e) {
* Used for cloning.
*/
@Override
protected void postCopyIn(Map alreadyDone) {
protected void postCopyIn(Map<Expression, Expression> alreadyDone) {
super.postCopyIn(alreadyDone);
if (this.value instanceof Collection values) {
Vector newValues = org.eclipse.persistence.internal.helper.NonSynchronizedVector.newInstance(values.size());
for (Iterator iterator = values.iterator(); iterator.hasNext();) {
if (this.value instanceof @SuppressWarnings({"rawtypes"}) Collection values) {
List<Object> newValues = new ArrayList<>(values.size());
for (Iterator<?> iterator = values.iterator(); iterator.hasNext();) {
Object val = iterator.next();
if (val instanceof Expression){
newValues.add(((Expression)val).copiedVersionFrom(alreadyDone));
if (val instanceof Expression expression){
newValues.add((expression).copiedVersionFrom(alreadyDone));
} else {
newValues.add(val);
}
Expand Down
Loading

0 comments on commit 0acf479

Please sign in to comment.