Skip to content

Commit

Permalink
move away from Vector in core/core API
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Jungmann <lukas.jungmann@oracle.com>
  • Loading branch information
lukasj committed Jan 24, 2024
1 parent ad16233 commit ff5658d
Show file tree
Hide file tree
Showing 24 changed files with 268 additions and 261 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2022 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 @@ -260,7 +260,7 @@ static protected String getQualifiedFieldNameFromKey(Object key, Class<?> refere
String name = (String)key;
DatabaseMapping mapping = descriptor.getObjectBuilder().getMappingForAttributeName(name);
if(mapping != null) {
field = mapping.getFields().firstElement();
field = mapping.getFields().get(0);
}
} else if(key instanceof DataExpression) {
DataExpression fieldExpression = (DataExpression)key;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2023 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 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 @@ -188,15 +188,15 @@ public Map<String, ATTRIBUTE_GROUP> getAttributeGroups(){

/**
* PUBLIC:
* User can specify a vector of all the primary key field names if primary key is composite.
* User can specify a list of all the primary key field names if primary key is composite.
*
* @see org.eclipse.persistence.descriptors.ClassDescriptor#addPrimaryKeyFieldName(String)
*/
public abstract void setPrimaryKeyFieldNames(LIST primaryKeyFieldNames);

/**
* PUBLIC:
* User can specify a vector of all the primary key field names if primary key is composite.
* User can specify a list of all the primary key field names if primary key is composite.
*
* @see org.eclipse.persistence.descriptors.ClassDescriptor#addPrimaryKeyFieldName(String)
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2023 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 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,7 +19,7 @@
import org.eclipse.persistence.internal.core.queries.CoreContainerPolicy;
import org.eclipse.persistence.internal.core.sessions.CoreAbstractSession;

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

/**
* INTERNAL
Expand Down Expand Up @@ -89,7 +89,7 @@ protected CoreMapping() {
* INTERNAL:
* Return the field associated with this mapping if there is exactly one.
* This is required for object relational mapping to print them, but because
* they are defined in in an Enterprise context they cannot be cast to.
* they are defined in an Enterprise context they cannot be cast to.
* Mappings that have a field include direct mappings and object relational mappings.
*
* @return TODO
Expand All @@ -98,11 +98,11 @@ protected CoreMapping() {

/**
* INTERNAL:
* Returns a vector of all the fields this mapping represents.
* Returns a list of all the fields this mapping represents.
*
* @return TODO
*/
public abstract Vector<FIELD> getFields();
public abstract List<FIELD> getFields();

/**
* PUBLIC:
Expand Down Expand Up @@ -236,7 +236,7 @@ protected CoreMapping() {
*
* @param fields TODO
*/
protected abstract void setFields(Vector<FIELD> fields);
protected abstract void setFields(List<FIELD> fields);

/**
* INTERNAL:
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 @@ -376,8 +376,7 @@ public Object valueFromRow(AbstractRecord row, JoinedAttributeManager joinManage
// If any field in the foreign key is null then it means there are no referenced objects
// Skip for partial objects as fk may not be present.
if (!query.hasPartialAttributeExpressions()) {
for (Enumeration<DatabaseField> enumeration = getFields().elements(); enumeration.hasMoreElements();) {
DatabaseField field = enumeration.nextElement();
for (DatabaseField field: getFields()) {
if (row.get(field) == null) {
return getIndirectionPolicy().nullValueFromRow();
}
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 All @@ -20,7 +20,6 @@
import org.eclipse.persistence.internal.helper.DatabaseField;
import org.eclipse.persistence.internal.helper.DatabaseTable;
import org.eclipse.persistence.internal.helper.Helper;
import org.eclipse.persistence.internal.helper.NonSynchronizedVector;
import org.eclipse.persistence.internal.sessions.AbstractSession;
import org.eclipse.persistence.mappings.DatabaseMapping;
import org.eclipse.persistence.mappings.querykeys.ForeignReferenceQueryKey;
Expand Down Expand Up @@ -483,13 +482,13 @@ public ClassDescriptor getDescriptor() {
* only applies to query keys representing an object or to expression builders.
*/
@Override
public Vector getFields() {
public List<DatabaseField> getFields() {
if (getDescriptor() == null) {
DatabaseMapping mapping = getMapping();
if (mapping != null) {
return mapping.getSelectFields();
}
return new NonSynchronizedVector(0);
return new ArrayList<>(0);
}
if (descriptor.hasInheritance() && descriptor.getInheritancePolicy().shouldReadSubclasses()
&& (!descriptor.getInheritancePolicy().hasMultipleTableChild()) || shouldUseOuterJoinForMultitableInheritance()) {
Expand Down Expand Up @@ -534,10 +533,10 @@ public List<DatabaseField> getSelectionFields(ReadQuery query) {
* Returns the first field from each of the owned tables, used for
* fine-grained pessimistic locking.
*/
protected Vector getForUpdateOfFields() {
Vector allFields = getFields();
protected List<DatabaseField> getForUpdateOfFields() {
List<DatabaseField> allFields = getFields();
int expected = getTableAliases().size();
Vector firstFields = new Vector(expected);
List<DatabaseField> firstFields = new ArrayList<>(expected);
DatabaseTable lastTable = null;
DatabaseField field = null;
int i = 0;
Expand All @@ -548,18 +547,18 @@ protected Vector getForUpdateOfFields() {
// take O(n) time.
// An even faster way may be to go getDescriptor().getAdditionalPrimaryKeyFields.
while ((i < allFields.size()) && (firstFields.size() < expected)) {
field = (DatabaseField)allFields.elementAt(i++);
field = allFields.get(i++);
if ((lastTable == null) || !field.getTable().equals(lastTable)) {
lastTable = field.getTable();
int j = 0;
while (j < firstFields.size()) {
if (lastTable.equals(((DatabaseField)firstFields.elementAt(j)).getTable())) {
if (lastTable.equals(firstFields.get(j).getTable())) {
break;
}
j++;
}
if (j == firstFields.size()) {
firstFields.addElement(field);
firstFields.add(field);
}
}
}
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 @@ -368,16 +368,16 @@ public DatabaseField getField() {
* Return all the fields
*/
@Override
public Vector getFields() {
public List<DatabaseField> getFields() {
if (isAttribute()) {
Vector result = new Vector(1);
List<DatabaseField> result = new ArrayList<>(1);
DatabaseField field = getField();
if (field != null) {
result.addElement(field);
result.add(field);
}
return result;
} else {
Vector result = new Vector();
List<DatabaseField> result = new ArrayList<>();
result.addAll(super.getFields());
if ((this.mapping != null) && this.mapping.isCollectionMapping()){
List<DatabaseField> fields = this.mapping.getContainerPolicy().getAdditionalFieldsForJoin((CollectionMapping)this.mapping);
Expand Down Expand Up @@ -1441,7 +1441,7 @@ public DatabaseTable getSourceTable() {
// from the descriptor. In an joined inheritance hierarchy, the
// fk used in the outer join may be from a subclasses's table.
if (getMapping().isObjectReferenceMapping() && ((ObjectReferenceMapping) getMapping()).isForeignKeyRelationship()) {
return getMapping().getFields().firstElement().getTable();
return getMapping().getFields().get(0).getTable();
} else {
return ((ObjectExpression)this.baseExpression).getDescriptor().getTables().firstElement();
}
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.
* Copyright (c) 2022 IBM Corporation. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -26,7 +26,9 @@
import java.io.CharArrayWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Vector;

/**
Expand All @@ -48,8 +50,8 @@ public class SQLDeleteAllStatement extends SQLDeleteStatement {
protected String tableAliasInSelectCallForNotExist;

// A pair of Vectors for join expression
protected Vector aliasedFields;
protected Vector originalFields;
protected List<DatabaseField> aliasedFields;
protected List<DatabaseField> originalFields;

protected boolean shouldExtractWhereClauseFromSelectCallForExist;

Expand Down Expand Up @@ -77,29 +79,30 @@ public void setTableAliasInSelectCallForNotExist(String tableAliasInSelectCallFo
public String getTableAliasInSelectCallForNotExist() {
return tableAliasInSelectCallForNotExist;
}
@SuppressWarnings({"unchecked"})
public void setPrimaryKeyFieldsForAutoJoin(Collection primaryKeyFields) {
if(primaryKeyFields != null) {
if(primaryKeyFields instanceof Vector) {
setOriginalFieldsForJoin((Vector)primaryKeyFields);
if(primaryKeyFields instanceof ArrayList<?>) {
setOriginalFieldsForJoin((ArrayList<DatabaseField>)primaryKeyFields);
} else {
setOriginalFieldsForJoin(new Vector(primaryKeyFields));
setOriginalFieldsForJoin(new ArrayList<>(primaryKeyFields));
}
setAliasedFieldsForJoin((Vector)getOriginalFieldsForJoin().clone());
setAliasedFieldsForJoin((List<DatabaseField>) ((ArrayList<DatabaseField>) getOriginalFieldsForJoin()).clone());
} else {
setOriginalFieldsForJoin(null);
setAliasedFieldsForJoin(null);
}
}
public void setOriginalFieldsForJoin(Vector originalFields) {
public void setOriginalFieldsForJoin(List<DatabaseField> originalFields) {
this.originalFields = originalFields;
}
public Vector getOriginalFieldsForJoin() {
public List<DatabaseField> getOriginalFieldsForJoin() {
return originalFields;
}
public void setAliasedFieldsForJoin(Vector aliasedFields) {
public void setAliasedFieldsForJoin(List<DatabaseField> aliasedFields) {
this.aliasedFields = aliasedFields;
}
public Vector getAliasedFieldsForExpression() {
public List<DatabaseField> getAliasedFieldsForExpression() {
return aliasedFields;
}
public void setInheritanceExpression(Expression inheritanceExpression) {
Expand Down Expand Up @@ -214,11 +217,11 @@ protected void writeSelect(Writer writer, SQLCall selectCall, String tableAliasI
writer.write(tableAliasInSelectCall);
writer.write('.');
}
writer.write(((DatabaseField)aliasedFields.elementAt(i)).getNameDelimited(platform));
writer.write(((DatabaseField)aliasedFields.get(i)).getNameDelimited(platform));
writer.write(" = ");
writer.write(table.getQualifiedNameDelimited(platform));
writer.write('.');
writer.write(((DatabaseField)originalFields.elementAt(i)).getNameDelimited(platform));
writer.write(((DatabaseField)originalFields.get(i)).getNameDelimited(platform));
}

// add parameters
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.
* Copyright (c) 2022 IBM Corporation. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -27,16 +27,16 @@
import java.io.IOException;
import java.io.Writer;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
* @author Guy Pelletier
* @since TOPLink/Java 1.0
*/
public class SQLUpdateAllStatement extends SQLModifyStatement {
protected HashMap m_updateClauses;
protected HashMap databaseFieldsToTableAliases;
protected Map m_updateClauses;
protected Map<DatabaseField, String> databaseFieldsToTableAliases;

protected SQLCall selectCallForExist;
protected String tableAliasInSelectCallForExist;
Expand All @@ -61,16 +61,16 @@ public void setPrimaryKeyFieldsForAutoJoin(Collection primaryKeyFields) {
public Collection getPrimaryKeyFieldsForAutoJoin() {
return primaryKeyFields;
}
public void setUpdateClauses(HashMap updateClauses) {
public void setUpdateClauses(Map updateClauses) {
m_updateClauses = updateClauses;
}
public HashMap getUpdateClauses() {
public Map getUpdateClauses() {
return m_updateClauses;
}
public void setDatabaseFieldsToTableAliases(HashMap databaseFieldsToTableAliases) {
public void setDatabaseFieldsToTableAliases(Map<DatabaseField, String> databaseFieldsToTableAliases) {
this.databaseFieldsToTableAliases = databaseFieldsToTableAliases;
}
public HashMap getDatabaseFieldsToTableAliases() {
public Map<DatabaseField, String> getDatabaseFieldsToTableAliases() {
return databaseFieldsToTableAliases;
}
public void setShouldExtractWhereClauseFromSelectCallForExist(boolean shouldExtractWhereClauseFromSelectCallForExist) {
Expand Down Expand Up @@ -169,7 +169,7 @@ protected SQLCall buildSimple(AbstractSession session) {
} else {
// must be SQLCall
SQLCall selCall = (SQLCall)value;
String tableAlias = (String)getDatabaseFieldsToTableAliases().get(field);
String tableAlias = getDatabaseFieldsToTableAliases().get(field);
// should be SQLCall select
writer.write("(");
writeSelect(writer, selCall, tableAlias, call, session.getPlatform());
Expand Down

0 comments on commit ff5658d

Please sign in to comment.