Skip to content

Commit

Permalink
Replace Vector/NonSynchronizedVector with List/ArrayList in mappings
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 Feb 22, 2024
1 parent c5827e7 commit d8375ee
Show file tree
Hide file tree
Showing 46 changed files with 794 additions and 766 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ public org.eclipse.persistence.sessions.Project getInitialProject(String user) {
}
mapping.setRelationTableName(user + "." + oldRelationTableName);

Vector<DatabaseField> targetRelationKeyFields = mapping.getTargetKeyFields();
List<DatabaseField> targetRelationKeyFields = mapping.getTargetKeyFields();
for (DatabaseField targetRelationKeyField : targetRelationKeyFields) {
String oldName = targetRelationKeyField.getTable().getName();
targetRelationKeyField.setTableName(user + "." + oldName);
}

Vector<DatabaseField> sourceRelationKeyFields = mapping.getSourceRelationKeyFields();
List<DatabaseField> sourceRelationKeyFields = mapping.getSourceRelationKeyFields();
for (DatabaseField sourceRelationKeyField : sourceRelationKeyFields) {
String oldName = sourceRelationKeyField.getTable().getName();
sourceRelationKeyField.setTableName(user + "." + oldName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,23 @@
// Oracle - initial API and implementation from Oracle TopLink
package org.eclipse.persistence.testing.tests.interfaces;

import java.util.Vector;
import java.util.Enumeration;

import org.eclipse.persistence.testing.framework.*;
import org.eclipse.persistence.sessions.Session;
import org.eclipse.persistence.internal.helper.Helper;
import org.eclipse.persistence.internal.helper.DatabaseField;
import org.eclipse.persistence.internal.helper.Helper;
import org.eclipse.persistence.internal.sessions.AbstractSession;
import org.eclipse.persistence.mappings.Association;
import org.eclipse.persistence.mappings.TypedAssociation;
import org.eclipse.persistence.mappings.VariableOneToOneMapping;
import org.eclipse.persistence.testing.models.interfaces.*;
import org.eclipse.persistence.sessions.Session;
import org.eclipse.persistence.testing.framework.TestCase;
import org.eclipse.persistence.testing.framework.TestErrorException;
import org.eclipse.persistence.testing.models.interfaces.Actor;
import org.eclipse.persistence.testing.models.interfaces.Broadcastor;
import org.eclipse.persistence.testing.models.interfaces.Employee;
import org.eclipse.persistence.testing.models.interfaces.Secretary;

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

public class VariableOneToOneCodeCoverageTest extends TestCase {
VariableOneToOneMapping mapping;
Expand Down Expand Up @@ -56,10 +61,10 @@ public void runTests() {
if (mapping.getClassIndicatorAssociations().isEmpty()) {
testFailures += "addClassIndicator = null did not add a null wrapper type indicator";
} else {
Enumeration e = mapping.getClassIndicatorAssociations().elements();
Iterator e = mapping.getClassIndicatorAssociations().iterator();

while (e.hasMoreElements()) {
TypedAssociation association = (TypedAssociation)e.nextElement();
while (e.hasNext()) {
TypedAssociation association = (TypedAssociation)e.next();

if (association.getKey() == Employee.class) {
if (!(association.getValue() instanceof Helper)) {
Expand All @@ -77,15 +82,15 @@ public void runTests() {

mapping.setClassIndicatorAssociations(vectorIn);

Vector vectorOut = mapping.getClassIndicatorAssociations();
List vectorOut = mapping.getClassIndicatorAssociations();

if (vectorOut.size() != 3) {
testFailures += "setClassIndicatorAssociations - the set failed";
} else {
int foundCount = 0;

for (int i = 0; i < vectorOut.size(); i++) {
Association ass = (Association)vectorOut.elementAt(i);
Association ass = (Association)vectorOut.get(i);

if (ass.getKey() == Actor.class.getName() && ass.getValue().equals("ASHLEY JUDD")) {
foundCount++;
Expand All @@ -108,12 +113,12 @@ public void runTests() {
Vector in = new Vector();
in.add(assoc);
mapping.setSourceToTargetQueryKeyFieldAssociations(in);
Vector out = mapping.getSourceToTargetQueryKeyFieldAssociations();
List out = mapping.getSourceToTargetQueryKeyFieldAssociations();

if (out.size() != 1) {
testFailures += "setSourceToTargetQueryFieldAssociations - the set failed";
} else {
Association a = (Association)out.elementAt(0);
Association a = (Association)out.get(0);

if (!(a.getKey().equals("key") && a.getValue().equals("value"))) {
testFailures += "setSourceToTargetQueryFieldAssociations - value in the set failed";
Expand All @@ -127,7 +132,7 @@ public void runTests() {
foreignKeyNames.add("fkey3");
mapping.setForeignKeyFieldNames(foreignKeyNames);

Vector fieldNames = mapping.getForeignKeyFieldNames();
List fieldNames = mapping.getForeignKeyFieldNames();

if (!(mapping.getForeignKeyFieldNames().contains("fkey1"))) {
testFailures += "addForeignQueryKeyName - fkey1";
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 Down Expand Up @@ -43,7 +43,7 @@ public void test() {
org.eclipse.persistence.testing.tests.validation.EmployeeWithProblems person = new org.eclipse.persistence.testing.tests.validation.EmployeeWithProblems();

OneToOneMapping dMapping = (OneToOneMapping)descriptor.getMappingForAttributeName("manager");
DatabaseField dField = dMapping.getForeignKeyFields().firstElement();
DatabaseField dField = dMapping.getForeignKeyFields().get(0);
//the following causes the correct error to occure.
descriptor.getObjectBuilder().getMappingsByField().remove(dField);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ protected void setup() {
mapping = (VariableOneToOneMapping)descriptor.getMappingForAttributeName("program");

sourceField = new DatabaseField("ACTOR.PROGRAM_ID");
targetQueryKeyName = (String)mapping.getSourceToTargetQueryKeyNames().get(sourceField);
targetQueryKeyName = mapping.getSourceToTargetQueryKeyNames().get(sourceField);
mapping.addForeignQueryKeyName("ACTOR.PROGRAM_ID", "name2");
mapping.getForeignKeyFields().removeElement(sourceField);
mapping.getForeignKeyFields().remove(sourceField);

actor = Actor.example4();
databaseRow = new DatabaseRecord();
Expand All @@ -90,7 +90,7 @@ protected void setup() {
@Override
public void reset() {
mapping.addForeignQueryKeyName("ACTOR.PROGRAM_ID", targetQueryKeyName);
mapping.getForeignKeyFields().removeElement(sourceField);
mapping.getForeignKeyFields().remove(sourceField);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// Oracle - initial API and implementation
package org.eclipse.persistence.asm;

import org.eclipse.persistence.asm.internal.Util;
import org.eclipse.persistence.config.SystemProperties;
import org.eclipse.persistence.exceptions.ValidationException;
import org.eclipse.persistence.internal.security.PrivilegedAccessHelper;
Expand All @@ -27,7 +26,6 @@
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// Oracle - initial API and implementation
package org.eclipse.persistence.asm.internal.platform.eclipselink;

import org.eclipse.persistence.asm.ASMFactory;
import org.eclipse.persistence.asm.AnnotationVisitor;
import org.eclipse.persistence.asm.FieldVisitor;
import org.eclipse.persistence.asm.MethodVisitor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// Oracle - initial API and implementation
package org.eclipse.persistence.asm.internal.platform.eclipselink;

import org.eclipse.persistence.asm.ASMFactory;
import org.eclipse.persistence.asm.Opcodes;
import org.eclipse.persistence.internal.libraries.asm.ClassVisitor;
import org.eclipse.persistence.internal.libraries.asm.commons.SerialVersionUIDAdder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// Oracle - initial API and implementation
package org.eclipse.persistence.asm.internal.platform.ow2;

import org.eclipse.persistence.asm.ASMFactory;
import org.eclipse.persistence.asm.AnnotationVisitor;
import org.eclipse.persistence.asm.FieldVisitor;
import org.eclipse.persistence.asm.MethodVisitor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// Oracle - initial API and implementation
package org.eclipse.persistence.asm.internal.platform.ow2;

import org.eclipse.persistence.asm.ASMFactory;
import org.eclipse.persistence.asm.Opcodes;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.commons.SerialVersionUIDAdder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -772,11 +772,11 @@ public Object clone() {
* Return all the fields mapped by the mapping.
*/
@Override
protected Vector<DatabaseField> collectFields() {
protected List<DatabaseField> collectFields() {
if (isForeignKeyRelationship()) {
if (this.getForeignKeyGroupingElement() != null) {
Vector<DatabaseField> fields = new Vector<>(1);
fields.addElement(this.getForeignKeyGroupingElement());
List<DatabaseField> fields = new ArrayList<>(1);
fields.add(this.getForeignKeyGroupingElement());
return fields;
} else {
return NO_FIELDS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.eclipse.persistence.queries.ReadObjectQuery;
import org.eclipse.persistence.queries.ReadQuery;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -90,7 +91,7 @@ public class EISOneToOneMapping extends ObjectReferenceMapping implements EISMap
public EISOneToOneMapping() {
this.selectionQuery = new ReadObjectQuery();

this.foreignKeyFields = org.eclipse.persistence.internal.helper.NonSynchronizedVector.newInstance(1);
this.foreignKeyFields = new ArrayList<>(1);

this.sourceToTargetKeyFields = new HashMap<>(2);
this.targetToSourceKeyFields = new HashMap<>(2);
Expand Down Expand Up @@ -147,7 +148,7 @@ public void addForeignKeyFieldName(String sourceForeignKeyFieldName, String targ
@Override
public Object clone() {
EISOneToOneMapping clone = (EISOneToOneMapping)super.clone();
clone.setForeignKeyFields(org.eclipse.persistence.internal.helper.NonSynchronizedVector.newInstance(getForeignKeyFields().size()));
clone.setForeignKeyFields(new ArrayList<>(getForeignKeyFields().size()));
clone.setSourceToTargetKeyFields(new HashMap<>(getSourceToTargetKeyFields().size()));
clone.setTargetToSourceKeyFields(new HashMap<>(getTargetToSourceKeyFields().size()));
Map<DatabaseField, DatabaseField> setOfFields = new HashMap<>(getTargetToSourceKeyFields().size());
Expand All @@ -157,7 +158,7 @@ public Object clone() {

DatabaseField fieldClone = field.clone();
setOfFields.put(field, fieldClone);
clone.getForeignKeyFields().addElement(fieldClone);
clone.getForeignKeyFields().add(fieldClone);
}

//get clones from set for source hashtable. If they do not exist, create a new one.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public ClassDescriptor getDescriptor() {
*/
public final List<DatabaseTable> getHistoricalTables() {
if (historicalTables == null) {
historicalTables = org.eclipse.persistence.internal.helper.NonSynchronizedVector.newInstance(1);
historicalTables = new ArrayList<>(1);
}
return historicalTables;
}
Expand Down Expand Up @@ -523,7 +523,7 @@ public void addStartFieldName(String startFieldName) {
startField.setLength(6);

if (startFields == null) {
startFields = org.eclipse.persistence.internal.helper.NonSynchronizedVector.newInstance();
startFields = new ArrayList<>();
startFields.add(startField);
return;
}
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 @@ -17,7 +17,6 @@
// javase imports

import org.eclipse.persistence.descriptors.ClassDescriptor;
import org.eclipse.persistence.internal.helper.NonSynchronizedVector;
import org.eclipse.persistence.mappings.converters.Converter;
import org.eclipse.persistence.mappings.converters.EnumTypeConverter;
import org.eclipse.persistence.mappings.transformers.ConstantTransformer;
Expand All @@ -34,6 +33,8 @@
import org.eclipse.persistence.queries.DatabaseQuery;
import org.eclipse.persistence.sessions.DatasourceLogin;

import java.util.ArrayList;

import static javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI;
import static javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI;
import static org.eclipse.persistence.internal.helper.DatabaseField.NULL_SQL_TYPE;
Expand Down Expand Up @@ -96,7 +97,7 @@ protected ClassDescriptor buildProjectDescriptor() {
descriptor.setSchemaReference(new XMLSchemaClassPathReference(SCHEMA_DIR + ECLIPSELINK_SCHEMA));

XMLCompositeCollectionMapping projectQueriesMapping = new XMLCompositeCollectionMapping();
projectQueriesMapping.useCollectionClass(NonSynchronizedVector.class);
projectQueriesMapping.useCollectionClass(ArrayList.class);
projectQueriesMapping.setAttributeName("queries");
projectQueriesMapping.setSetMethodName("setQueries");
projectQueriesMapping.setGetMethodName("getQueries");
Expand Down

0 comments on commit d8375ee

Please sign in to comment.