From c5aed35b2e3c64f0b929c7d5a70bb119efb7dd95 Mon Sep 17 00:00:00 2001 From: Lukas Jungmann Date: Tue, 12 Mar 2024 10:38:26 +0100 Subject: [PATCH] remove unused internal classes, minor cleanup Signed-off-by: Lukas Jungmann --- .../internal/codegen/HierarchyNode.java | 68 ------------ .../codegen/InheritanceHierarchyBuilder.java | 62 ----------- .../databaseaccess/DatabasePlatform.java | 21 ++-- .../internal/descriptors/ObjectBuilder.java | 4 +- .../identitymaps/AbstractIdentityMap.java | 13 +-- .../identitymaps/FullIdentityMap.java | 26 ++--- .../internal/identitymaps/IdentityMap.java | 12 +-- .../identitymaps/IdentityMapManager.java | 102 ++++++++---------- .../internal/identitymaps/NoIdentityMap.java | 19 ++-- .../identitymaps/UnitOfWorkIdentityMap.java | 4 +- .../WeakUnitOfWorkIdentityMap.java | 9 +- .../internal/oxm/XMLObjectBuilder.java | 2 +- .../sessions/IdentityMapAccessor.java | 10 +- ...latedClientSessionIdentityMapAccessor.java | 6 +- .../internal/sessions/UnitOfWorkImpl.java | 2 +- .../persistence/services/RuntimeServices.java | 78 +++++++------- .../mbean/MBeanRuntimeServicesMBean.java | 13 ++- .../interceptors/CacheInterceptor.java | 12 +-- .../tests/jpa/config/CacheAuditor.java | 4 +- .../advanced/member_1/CacheAuditor.java | 6 +- .../models/jpa/xml/advanced/CacheAuditor.java | 6 +- 21 files changed, 168 insertions(+), 311 deletions(-) delete mode 100644 foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/codegen/HierarchyNode.java delete mode 100644 foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/codegen/InheritanceHierarchyBuilder.java diff --git a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/codegen/HierarchyNode.java b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/codegen/HierarchyNode.java deleted file mode 100644 index 3a836b71f14..00000000000 --- a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/codegen/HierarchyNode.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 1998, 2023 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 - * http://www.eclipse.org/legal/epl-2.0, - * or the Eclipse Distribution License v. 1.0 which is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause - */ - -// Contributors: -// Oracle - initial API and implementation from Oracle TopLink -package org.eclipse.persistence.internal.codegen; - -import java.util.ArrayList; -import java.util.List; - -/** - * INTERNAL: - */ -public class HierarchyNode { - // the class that this node represents - public String className; - public HierarchyNode parent; - public List children; - - /** - * This member will hold the different definition types that should be implemented by the code generated children - * Used mostly in CMP code generation - */ - public List definitions; - - public HierarchyNode(String className) { - this.className = className; - this.children = new ArrayList<>(); - this.definitions = new ArrayList<>(); - } - - public void setParent(HierarchyNode parent) { - this.parent = parent; - this.parent.addChild(this); - } - - public void addChild(HierarchyNode child) { - if (!this.children.contains(child)) { - this.children.add(child); - } - } - - public List getChildren() { - return this.children; - } - - public HierarchyNode getParent() { - return this.parent; - } - - public String getClassName() { - return this.className; - } - - @Override - public String toString() { - return "HierarchyNode:\n\t" + className + "\n" + children + "\n end HierarchyNode\n"; - } -} diff --git a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/codegen/InheritanceHierarchyBuilder.java b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/codegen/InheritanceHierarchyBuilder.java deleted file mode 100644 index 39bce039d7c..00000000000 --- a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/codegen/InheritanceHierarchyBuilder.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 1998, 2023 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 - * http://www.eclipse.org/legal/epl-2.0, - * or the Eclipse Distribution License v. 1.0 which is available at - * http://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause - */ - -// Contributors: -// Oracle - initial API and implementation from Oracle TopLink -package org.eclipse.persistence.internal.codegen; - -import org.eclipse.persistence.descriptors.ClassDescriptor; -import org.eclipse.persistence.sessions.Project; - -import java.util.HashMap; -import java.util.Map; - -/** - * INTERNAL: - */ -public class InheritanceHierarchyBuilder { - - private InheritanceHierarchyBuilder() { - //no instance please - } - - /** - * INTERNAL: - * Based on a class name either return a pre-existing node from the hierarchyTree or build one and - * add it to the tree. - */ - public static HierarchyNode getNodeForClass(String className, Map hierarchyTree) { - HierarchyNode node = hierarchyTree.get(className); - if (node == null) { - node = new HierarchyNode(className); - hierarchyTree.put(className, node); - } - return node; - } - - public static Map buildInheritanceHierarchyTree(Project project) { - Map, ClassDescriptor> descriptors = project.getDescriptors(); - Map hierarchyTree = new HashMap<>(descriptors.size()); - for (ClassDescriptor descriptor : descriptors.values()) { - String className = descriptor.getJavaClassName(); - if (className == null) { - className = descriptor.getJavaClass().getName(); - } - HierarchyNode node = getNodeForClass(className, hierarchyTree); - if (descriptor.hasInheritance() && (descriptor.getInheritancePolicy().getParentClassName() != null)) { - HierarchyNode parentNode = getNodeForClass(descriptor.getInheritancePolicy().getParentClassName(), hierarchyTree); - node.setParent(parentNode); - } - } - return hierarchyTree; - } -} diff --git a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/databaseaccess/DatabasePlatform.java b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/databaseaccess/DatabasePlatform.java index 2e9d90f73aa..e688652ecb0 100644 --- a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/databaseaccess/DatabasePlatform.java +++ b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/databaseaccess/DatabasePlatform.java @@ -950,7 +950,7 @@ public String getProcedureAsString() { /** * Some platforms have an option list * Only to be used for stored procedure creation. - * + * * @see org.eclipse.persistence.tools.schemaframework.StoredProcedureDefinition */ public String getProcedureOptionList() { @@ -1359,7 +1359,7 @@ public String getSelectForUpdateString() { /** * Platforms that support the WAIT option should override this method. * By default the wait timeout is ignored. - * + * * @see DatabasePlatform#supportsWaitForUpdate() */ public String getSelectForUpdateWaitString(Integer waitTimeout) { @@ -1482,14 +1482,14 @@ public boolean isLobCompatibleWithDistinct() { } /** - * Returns the attribute containing the results from the batch execution + * Returns the attribute containing the results from the batch execution */ public int[] getExecuteBatchRowCounts() { return executeBatchRowCounts; } /** - * Sets the attribute containing the results from the batch execution + * Sets the attribute containing the results from the batch execution */ public void setExecuteBatchRowCounts(int[] rowCounts) { executeBatchRowCounts = rowCounts; @@ -1602,7 +1602,7 @@ public int printValuelist(Collection theObjects, DatabaseCall call, Writer wr /** * This method is used to register output parameter on CallableStatements for Stored Procedures * as each database seems to have a different method. - * + * * @see java.sql.CallableStatement#registerOutParameter(int parameterIndex, int sqlType) */ public void registerOutputParameter(CallableStatement statement, int parameterIndex, int sqlType) throws SQLException { @@ -1612,7 +1612,7 @@ public void registerOutputParameter(CallableStatement statement, int parameterIn /** * This method is used to register output parameter on CallableStatements for Stored Procedures * as each database seems to have a different method. - * + * * @see java.sql.CallableStatement#registerOutParameter(int parameterIndex, int sqlType, String typeName) */ public void registerOutputParameter(CallableStatement statement, int parameterIndex, int sqlType, String typeName) throws SQLException { @@ -1622,7 +1622,7 @@ public void registerOutputParameter(CallableStatement statement, int parameterIn /** * This method is used to register output parameter on CallableStatements for Stored Procedures * as each database seems to have a different method. - * + * * @see java.sql.CallableStatement#registerOutParameter(String parameterName, int sqlType) */ public void registerOutputParameter(CallableStatement statement, String parameterName, int sqlType) throws SQLException { @@ -1632,7 +1632,7 @@ public void registerOutputParameter(CallableStatement statement, String paramete /** * This method is used to register output parameter on CallableStatements for Stored Procedures * as each database seems to have a different method. - * + * * @see java.sql.CallableStatement#registerOutParameter(String parameterName, int sqlType, String typeName) */ public void registerOutputParameter(CallableStatement statement, String parameterName, int sqlType, String typeName) throws SQLException { @@ -2247,7 +2247,7 @@ public boolean supportsVPD() { /** * INTERNAL: * Indicates whether the platform supports timeouts on For Update - * + * * @see DatabasePlatform#getSelectForUpdateWaitString(Integer waitTimeout) */ public boolean supportsWaitForUpdate() { @@ -2383,6 +2383,7 @@ public void setPingSQL(String pingSQL) { public void setParameterValueInDatabaseCall(Object parameter, PreparedStatement statement, int index, AbstractSession session) throws SQLException { + // Process common types first. if (parameter instanceof String) { // Check for stream binding of large strings. @@ -3539,7 +3540,7 @@ public void setShouldBindLiterals(boolean shouldBindLiterals) { * Some databases have issues with using parameters on certain functions and relations. * This allows statements to disable binding only in these cases. *

- * Alternatively, DatabasePlatforms can override specific ExpressionOperators and add them + * Alternatively, DatabasePlatforms can override specific ExpressionOperators and add them * to the platform specific operators. See {@link DatasourcePlatform#initializePlatformOperators()} */ public boolean isDynamicSQLRequiredForFunctions() { diff --git a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/descriptors/ObjectBuilder.java b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/descriptors/ObjectBuilder.java index 5038ac1d7d8..3af7e8c9acf 100644 --- a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/descriptors/ObjectBuilder.java +++ b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/descriptors/ObjectBuilder.java @@ -4353,7 +4353,7 @@ protected void loadBatchReadAttributes(ClassDescriptor concreteDescriptor, Objec } AbstractSession session = query.getExecutionSession(); mapping.readFromRowIntoObject(databaseRow, joinManager, sourceObject, cacheKey, query, query.getExecutionSession(),isTargetProtected); - session.getIdentityMapAccessorInstance().getIdentityMap(concreteDescriptor).lazyRelationshipLoaded(sourceObject, (ValueHolderInterface) ((ForeignReferenceMapping)mapping).getIndirectionPolicy().getOriginalValueHolder(attributeValue, session), (ForeignReferenceMapping)mapping); + session.getIdentityMapAccessorInstance().getIdentityMap(concreteDescriptor).lazyRelationshipLoaded(sourceObject, (ValueHolderInterface) ((ForeignReferenceMapping)mapping).getIndirectionPolicy().getOriginalValueHolder(attributeValue, session), (ForeignReferenceMapping)mapping); } } } @@ -4399,7 +4399,7 @@ protected void loadJoinedAttributes(ClassDescriptor concreteDescriptor, Object s } AbstractSession session = query.getExecutionSession(); mapping.readFromRowIntoObject(databaseRow, joinManager, intermediateValue, cacheKey, query, query.getExecutionSession(), isTargetProtected); - session.getIdentityMapAccessorInstance().getIdentityMap(concreteDescriptor).lazyRelationshipLoaded(intermediateValue, (ValueHolderInterface) ((ForeignReferenceMapping)mapping).getIndirectionPolicy().getOriginalValueHolder(attributeValue, session), (ForeignReferenceMapping)mapping); + session.getIdentityMapAccessorInstance().getIdentityMap(concreteDescriptor).lazyRelationshipLoaded(intermediateValue, (ValueHolderInterface) ((ForeignReferenceMapping)mapping).getIndirectionPolicy().getOriginalValueHolder(attributeValue, session), (ForeignReferenceMapping)mapping); } } } diff --git a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/identitymaps/AbstractIdentityMap.java b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/identitymaps/AbstractIdentityMap.java index d4544c864a6..c68a3649391 100644 --- a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/identitymaps/AbstractIdentityMap.java +++ b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/identitymaps/AbstractIdentityMap.java @@ -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 @@ -22,6 +22,7 @@ import java.util.Enumeration; import java.util.HashMap; import java.util.Map; +import java.util.Set; /** *

Purpose: Caches objects, and allows their retrieval by their primary key. @@ -222,16 +223,16 @@ public CacheKey acquireReadLockOnCacheKeyNoWait(Object primaryKey) { * Used to print all the locks in the identity map. */ @Override - public abstract void collectLocks(HashMap threadList); + public abstract void collectLocks(Map> threadList); /** * Clone the map and all of the CacheKeys. * This is used by UnitOfWork commitAndResumeOnFailure to avoid corrupting the cache during a failed commit. */ @Override - public Object clone() { + public IdentityMap clone() { try { - return super.clone(); + return (IdentityMap) super.clone(); } catch (CloneNotSupportedException exception) { throw new InternalError(exception.toString()); } @@ -258,7 +259,7 @@ public CacheKey createCacheKey(Object primaryKey, Object object, Object writeLoc * Allow for the cache to be iterated on. */ @Override - public abstract Enumeration elements(); + public abstract Enumeration elements(); /** * Return the object cached in the identity map or null if it could not be found. @@ -413,7 +414,7 @@ public Object getWriteLockValue(Object primaryKey) { * Allow for the CacheKeys to be iterated on. */ @Override - public abstract Enumeration keys(); + public abstract Enumeration keys(); /** * Store the object in the cache at its primary key. diff --git a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/identitymaps/FullIdentityMap.java b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/identitymaps/FullIdentityMap.java index 09e2af29b61..65940c8dba6 100644 --- a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/identitymaps/FullIdentityMap.java +++ b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/identitymaps/FullIdentityMap.java @@ -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 @@ -24,13 +24,11 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Enumeration; -import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; /** *

Purpose: A FullIdentityMap holds all objects stored within it for the life of the application. @@ -53,7 +51,7 @@ public FullIdentityMap() { public FullIdentityMap(int size, ClassDescriptor descriptor, AbstractSession session, boolean isolated) { super(size, descriptor, session, isolated); - this.cacheKeys = new ConcurrentHashMap(size); + this.cacheKeys = new ConcurrentHashMap<>(size); } /** @@ -61,9 +59,9 @@ public FullIdentityMap(int size, ClassDescriptor descriptor, AbstractSession ses * Clones itself. */ @Override - public Object clone() { + public IdentityMap clone() { FullIdentityMap clone = (FullIdentityMap)super.clone(); - clone.setCacheKeys(new ConcurrentHashMap(this.cacheKeys.size())); + clone.setCacheKeys(new ConcurrentHashMap<>(this.cacheKeys.size())); for (Iterator cacheKeysIterator = this.cacheKeys.values().iterator(); cacheKeysIterator.hasNext();) { CacheKey key = (CacheKey) cacheKeysIterator.next().clone(); @@ -78,17 +76,13 @@ public Object clone() { * Used to print all the Locks in every identity map in this session. */ @Override - public void collectLocks(HashMap threadList) { + public void collectLocks(Map> threadList) { Iterator cacheKeyIterator = this.cacheKeys.values().iterator(); while (cacheKeyIterator.hasNext()) { CacheKey cacheKey = cacheKeyIterator.next(); if (cacheKey.isAcquired()) { Thread activeThread = cacheKey.getActiveThread(); - Set set = (Set)threadList.get(activeThread); - if (set == null) { - set = new HashSet(); - threadList.put(activeThread, set); - } + Set set = threadList.computeIfAbsent(activeThread, k -> new HashSet<>()); set.add(cacheKey); } } @@ -100,7 +94,7 @@ public void collectLocks(HashMap threadList) { * @return {@link Enumeration} of {@link CacheKey#getObject()} instances. */ @Override - public Enumeration elements() { + public Enumeration elements() { return new IdentityMapEnumeration(this.getCacheKeys().values()); } @@ -121,7 +115,7 @@ public CacheKey getCacheKey(Object searchKey, boolean forMerge) { @Override protected CacheKey putCacheKeyIfAbsent(CacheKey searchKey) { searchKey.setOwningMap(this); - return (CacheKey)((ConcurrentMap)this.cacheKeys).putIfAbsent(searchKey.getKey(), searchKey); + return this.cacheKeys.putIfAbsent(searchKey.getKey(), searchKey); } /** @@ -196,7 +190,7 @@ public Enumeration keys(boolean checkReadLocks) { */ @Override public Enumeration cloneKeys() { - return new IdentityMapKeyEnumeration(new ArrayList(this.getCacheKeys().values()), true); + return new IdentityMapKeyEnumeration(new ArrayList<>(this.getCacheKeys().values()), true); } /** @@ -204,7 +198,7 @@ public Enumeration cloneKeys() { * and the cache may need to be updated */ @Override - public void lazyRelationshipLoaded(Object object, ValueHolderInterface valueHolder, ForeignReferenceMapping mapping){ + public void lazyRelationshipLoaded(Object object, ValueHolderInterface valueHolder, ForeignReferenceMapping mapping){ //NO-OP } diff --git a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/identitymaps/IdentityMap.java b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/identitymaps/IdentityMap.java index 5a0fc501b70..1b99e8ed79f 100644 --- a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/identitymaps/IdentityMap.java +++ b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/identitymaps/IdentityMap.java @@ -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 @@ -22,8 +22,8 @@ import org.eclipse.persistence.mappings.ForeignReferenceMapping; import java.util.Enumeration; -import java.util.HashMap; import java.util.Map; +import java.util.Set; /** *

Purpose: Provides the interface for IdentityMap interaction. @@ -82,13 +82,13 @@ public interface IdentityMap extends Cloneable{ * Clone the map and all of the CacheKeys. * This is used by UnitOfWork commitAndResumeOnFailure to avoid corrupting the cache during a failed commit. */ - Object clone(); + IdentityMap clone(); /** * Add all locked CacheKeys to the map grouped by thread. * Used to print all the locks in the identity map. */ - void collectLocks(HashMap threadList); + void collectLocks(Map> threadList); /** @@ -101,7 +101,7 @@ public interface IdentityMap extends Cloneable{ /** * Allow for the cache to be iterated on. */ - Enumeration elements(); + Enumeration elements(); /** * Return the object cached in the identity map or null if it could not be found. @@ -202,7 +202,7 @@ public interface IdentityMap extends Cloneable{ * Notify the cache that a lazy relationship has been triggered in the object * and the cache may need to be updated */ - void lazyRelationshipLoaded(Object rootEntity, ValueHolderInterface valueHolder, ForeignReferenceMapping mapping); + void lazyRelationshipLoaded(Object rootEntity, ValueHolderInterface valueHolder, ForeignReferenceMapping mapping); /** * Store the object in the cache at its primary key. diff --git a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/identitymaps/IdentityMapManager.java b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/identitymaps/IdentityMapManager.java index 124440a97e6..5722578b63b 100644 --- a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/identitymaps/IdentityMapManager.java +++ b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/identitymaps/IdentityMapManager.java @@ -54,6 +54,7 @@ import java.io.Serializable; import java.io.StringWriter; import java.lang.reflect.Constructor; +import java.util.ArrayList; import java.util.Enumeration; import java.util.HashMap; import java.util.HashSet; @@ -85,7 +86,7 @@ public class IdentityMapManager implements Serializable, Cloneable { protected Map queryResults; /** A map of class to list of queries that need to be invalidated when that class changes. */ - protected Map, Set> queryResultsInvalidationsByClass; + protected Map, Set> queryResultsInvalidationsByClass; /** A map of indexes on the cache. */ protected Map cacheIndexes; @@ -113,17 +114,17 @@ public IdentityMapManager(AbstractSession session) { this.cacheMutex = new ConcurrencyManager(); // PERF: Avoid query cache for uow as never used. if (session.isUnitOfWork()) { - this.identityMaps = new HashMap(); + this.identityMaps = new HashMap<>(); } else if (session.isIsolatedClientSession()) { - this.identityMaps = new HashMap(); - this.queryResults = new HashMap(); - this.queryResultsInvalidationsByClass = new HashMap(); - this.cacheIndexes = new HashMap(); + this.identityMaps = new HashMap<>(); + this.queryResults = new HashMap<>(); + this.queryResultsInvalidationsByClass = new HashMap<>(); + this.cacheIndexes = new HashMap<>(); } else { - this.identityMaps = new ConcurrentHashMap(); - this.queryResults = new ConcurrentHashMap(); - this.queryResultsInvalidationsByClass = new ConcurrentHashMap(); - this.cacheIndexes = new ConcurrentHashMap(); + this.identityMaps = new ConcurrentHashMap<>(); + this.queryResults = new ConcurrentHashMap<>(); + this.queryResultsInvalidationsByClass = new ConcurrentHashMap<>(); + this.cacheIndexes = new ConcurrentHashMap<>(); } checkIsCacheAccessPreCheckRequired(); } @@ -251,12 +252,8 @@ public CacheKey acquireLockWithWait(Object primaryKey, Class domainClass, boo * Avoid the readLock and profile checks if not required. */ public void checkIsCacheAccessPreCheckRequired() { - if ((this.session.getProfiler() != null) - || ((this.session.getDatasourceLogin() != null) && this.session.getDatasourceLogin().shouldSynchronizedReadOnWrite())) { - this.isCacheAccessPreCheckRequired = true; - } else { - this.isCacheAccessPreCheckRequired = false; - } + this.isCacheAccessPreCheckRequired = (this.session.getProfiler() != null) + || ((this.session.getDatasourceLogin() != null) && this.session.getDatasourceLogin().shouldSynchronizedReadOnWrite()); } /** @@ -394,8 +391,8 @@ protected IdentityMap buildNewIdentityMap( final Object[] values = new Object[]{size, descriptor, this.session, isIsolated}; IdentityMap map = PrivilegedAccessHelper.callDoPrivilegedWithException( () -> { - final Constructor constructor = PrivilegedAccessHelper.getConstructorFor(identityMapClass, parameters, false); - return PrivilegedAccessHelper.invokeConstructor(constructor, values); + final Constructor constructor = PrivilegedAccessHelper.getConstructorFor(identityMapClass, parameters, false); + return PrivilegedAccessHelper.invokeConstructor(constructor, values); }, (ex) -> DescriptorException.invalidIdentityMap(descriptor, ex) ); @@ -426,34 +423,33 @@ public void clearLastAccessedIdentityMap() { * Clones itself, used for uow commit and resume on failure. */ @Override - public Object clone() { - IdentityMapManager manager = null; + public IdentityMapManager clone() { try { - manager = (IdentityMapManager)super.clone(); - manager.setIdentityMaps(new ConcurrentHashMap()); + IdentityMapManager manager = (IdentityMapManager) super.clone(); + manager.setIdentityMaps(new ConcurrentHashMap<>()); for (Iterator, IdentityMap>> iterator = this.identityMaps.entrySet().iterator(); iterator.hasNext();) { Map.Entry, IdentityMap> entry = iterator.next(); - manager.identityMaps.put(entry.getKey(), (IdentityMap) entry.getValue().clone()); + manager.identityMaps.put(entry.getKey(), entry.getValue().clone()); } + return manager; } catch (CloneNotSupportedException exception) { throw new InternalError(exception.toString()); } - return manager; } /** * Clear all the query caches. */ public void clearQueryCache() { - this.queryResults = new ConcurrentHashMap(); - this.queryResultsInvalidationsByClass = new ConcurrentHashMap(); + this.queryResults = new ConcurrentHashMap<>(); + this.queryResultsInvalidationsByClass = new ConcurrentHashMap<>(); } /** * Clear all index caches. */ public void clearCacheIndexes() { - this.cacheIndexes = new ConcurrentHashMap(); + this.cacheIndexes = new ConcurrentHashMap<>(); } /** @@ -480,7 +476,7 @@ public void invalidateQueryCache(Class classThatChanged) { if (this.queryResultsInvalidationsByClass == null) { return; } - Set invalidations = this.queryResultsInvalidationsByClass.get(classThatChanged); + Set invalidations = this.queryResultsInvalidationsByClass.get(classThatChanged); if (invalidations != null) { for (Object queryKey : invalidations) { this.queryResults.remove(queryKey); @@ -525,7 +521,7 @@ public boolean containsKey(Object key, Class theClass, ClassDescriptor descri public Vector getAllFromIdentityMap(Expression selectionCriteria, Class theClass, DataRecord translationRow, int valueHolderPolicy, boolean shouldReturnInvalidatedObjects) { ClassDescriptor descriptor = this.session.getDescriptor(theClass); this.session.startOperationProfile(SessionProfiler.Caching); - Vector objects = null; + Vector objects = null; try { if (selectionCriteria != null) { // PERF: Avoid clone of expression. @@ -535,7 +531,7 @@ public Vector getAllFromIdentityMap(Expression selectionCriteria, Class theCl builder.setQueryClass(theClass); } } - objects = new Vector(); + objects = new Vector<>(); IdentityMap map = getIdentityMap(descriptor, false); // Bug #522635 - if policy is set to trigger indirection, then iterate over a copy of the cache keys collection @@ -769,9 +765,9 @@ public ConcurrencyManager getCacheMutex() { /** * This method is used to get a list of those classes with IdentityMaps in the Session. */ - public Vector getClassesRegistered() { + public List getClassesRegistered() { Iterator> classes = getIdentityMaps().keySet().iterator(); - Vector results = new Vector(getIdentityMaps().size()); + List results = new ArrayList<>(getIdentityMaps().size()); while (classes.hasNext()) { results.add(classes.next().getName()); } @@ -996,7 +992,7 @@ public IdentityMap getIdentityMap(ClassDescriptor descriptor, boolean returnNull identityMap = this.identityMaps.put(descriptorClass, newIdentityMap); } else { newIdentityMap = buildNewIdentityMap(descriptor); - identityMap = (IdentityMap)((ConcurrentMap)this.identityMaps).putIfAbsent(descriptorClass, newIdentityMap); + identityMap = this.identityMaps.putIfAbsent(descriptorClass, newIdentityMap); } if (identityMap == null) { identityMap = newIdentityMap; @@ -1014,7 +1010,7 @@ protected Map, IdentityMap> getIdentityMaps() { /** * Return an iterator of the classes in the identity map. */ - public Iterator getIdentityMapClasses() { + public Iterator> getIdentityMapClasses() { return getIdentityMaps().keySet().iterator(); } @@ -1189,7 +1185,7 @@ public void initializeIdentityMap(Class theClass) throws EclipseLinkException public void initializeIdentityMaps() { clearLastAccessedIdentityMap(); - setIdentityMaps(new ConcurrentHashMap()); + setIdentityMaps(new ConcurrentHashMap<>()); clearQueryCache(); clearCacheIndexes(); } @@ -1277,7 +1273,7 @@ public void printIdentityMaps() { */ public void printLocks() { StringWriter writer = new StringWriter(); - HashMap threadCollection = new HashMap(); + Map> threadCollection = new HashMap<>(); writer.write(TraceLocalization.buildMessage("lock_writer_header", null) + System.lineSeparator()); Iterator idenityMapsIterator = this.session.getIdentityMapAccessorInstance().getIdentityMapManager().getIdentityMaps().values().iterator(); while (idenityMapsIterator.hasNext()) { @@ -1285,13 +1281,13 @@ public void printLocks() { idenityMap.collectLocks(threadCollection); } Object[] parameters = new Object[1]; - for (Iterator threads = threadCollection.keySet().iterator(); threads.hasNext();) { - Thread activeThread = (Thread)threads.next(); + for (Iterator threads = threadCollection.keySet().iterator(); threads.hasNext();) { + Thread activeThread = threads.next(); parameters[0] = activeThread.getName(); writer.write(TraceLocalization.buildMessage("active_thread", parameters) + System.lineSeparator()); - for (Iterator cacheKeys = ((HashSet)threadCollection.get(activeThread)).iterator(); + for (Iterator cacheKeys = threadCollection.get(activeThread).iterator(); cacheKeys.hasNext();) { - CacheKey cacheKey = (CacheKey)cacheKeys.next(); + CacheKey cacheKey = cacheKeys.next(); if (cacheKey.isAcquired() && cacheKey.getActiveThread() == activeThread){ parameters[0] = cacheKey.getObject(); writer.write(TraceLocalization.buildMessage("locked_object", parameters) + System.lineSeparator()); @@ -1309,9 +1305,9 @@ public void printLocks() { } DeferredLockManager deferredLockManager = ConcurrencyManager.getDeferredLockManager(activeThread); if (deferredLockManager != null) { - for (Iterator deferredLocks = deferredLockManager.getDeferredLocks().iterator(); + for (Iterator deferredLocks = deferredLockManager.getDeferredLocks().iterator(); deferredLocks.hasNext();) { - ConcurrencyManager lock = (ConcurrencyManager)deferredLocks.next(); + ConcurrencyManager lock = deferredLocks.next(); if (lock instanceof CacheKey){ parameters[0] = ((CacheKey)lock).getObject(); writer.write(TraceLocalization.buildMessage("deferred_locks", parameters) + System.lineSeparator()); @@ -1330,19 +1326,19 @@ public void printLocks() { public void printLocks(Class theClass) { ClassDescriptor descriptor = this.session.getDescriptor(theClass); StringWriter writer = new StringWriter(); - HashMap threadCollection = new HashMap(); + Map> threadCollection = new HashMap<>(); writer.write(TraceLocalization.buildMessage("lock_writer_header", null) + System.lineSeparator()); IdentityMap identityMap = getIdentityMap(descriptor, false); identityMap.collectLocks(threadCollection); Object[] parameters = new Object[1]; - for (Iterator threads = threadCollection.keySet().iterator(); threads.hasNext();) { - Thread activeThread = (Thread)threads.next(); + for (Iterator threads = threadCollection.keySet().iterator(); threads.hasNext();) { + Thread activeThread = threads.next(); parameters[0] = activeThread.getName(); writer.write(TraceLocalization.buildMessage("active_thread", parameters) + System.lineSeparator()); - for (Iterator cacheKeys = ((HashSet)threadCollection.get(activeThread)).iterator(); + for (Iterator cacheKeys = threadCollection.get(activeThread).iterator(); cacheKeys.hasNext();) { - CacheKey cacheKey = (CacheKey)cacheKeys.next(); + CacheKey cacheKey = cacheKeys.next(); parameters[0] = cacheKey.getObject(); writer.write(TraceLocalization.buildMessage("locked_object", parameters) + System.lineSeparator()); parameters[0] = cacheKey.getDepth(); @@ -1350,9 +1346,9 @@ public void printLocks(Class theClass) { } DeferredLockManager deferredLockManager = ConcurrencyManager.getDeferredLockManager(activeThread); if (deferredLockManager != null) { - for (Iterator deferredLocks = deferredLockManager.getDeferredLocks().iterator(); + for (Iterator deferredLocks = deferredLockManager.getDeferredLocks().iterator(); deferredLocks.hasNext();) { - ConcurrencyManager lock = (ConcurrencyManager)deferredLocks.next(); + ConcurrencyManager lock = deferredLocks.next(); if (lock instanceof CacheKey){ parameters[0] = ((CacheKey)lock).getObject(); writer.write(TraceLocalization.buildMessage("deferred_locks", parameters) + System.lineSeparator()); @@ -1426,11 +1422,7 @@ public void putQueryResult(ReadQuery query, List parameters, Object results) { // Mark the query to be invalidated for the query classes. if (query.getQueryResultsCachePolicy().getInvalidateOnChange()) { for (Class queryClass : query.getQueryResultsCachePolicy().getInvalidationClasses()) { - Set invalidations = this.queryResultsInvalidationsByClass.get(queryClass); - if (invalidations == null) { - invalidations = new HashSet(); - this.queryResultsInvalidationsByClass.put(queryClass, invalidations); - } + Set invalidations = this.queryResultsInvalidationsByClass.computeIfAbsent(queryClass, k -> new HashSet<>()); invalidations.add(queryKey); } } @@ -1515,7 +1507,7 @@ protected void setCacheMutex(ConcurrencyManager cacheMutex) { this.cacheMutex = cacheMutex; } - public void setIdentityMaps(ConcurrentMap identityMaps) { + public void setIdentityMaps(ConcurrentMap, IdentityMap> identityMaps) { clearLastAccessedIdentityMap(); this.identityMaps = identityMaps; } diff --git a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/identitymaps/NoIdentityMap.java b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/identitymaps/NoIdentityMap.java index b2ed4d8c566..5095ba0e4ea 100644 --- a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/identitymaps/NoIdentityMap.java +++ b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/identitymaps/NoIdentityMap.java @@ -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 @@ -23,7 +23,8 @@ import java.util.Collections; import java.util.Enumeration; -import java.util.HashMap; +import java.util.Map; +import java.util.Set; /** @@ -43,7 +44,7 @@ public NoIdentityMap(int size, ClassDescriptor descriptor, AbstractSession sessi * NoIdentityMap has no locks. */ @Override - public void collectLocks(HashMap threadList) { + public void collectLocks(Map> threadList) { return; } @@ -51,8 +52,8 @@ public void collectLocks(HashMap threadList) { * Return an empty enumerator. */ @Override - public Enumeration elements() { - return Collections.emptyEnumeration(); + public Enumeration elements() { + return Collections.emptyEnumeration(); } /** @@ -108,7 +109,7 @@ public Object getWriteLockValue(Object primaryKey) { */ @Override public Enumeration keys() { - return Collections.emptyEnumeration(); + return Collections.emptyEnumeration(); } /** @@ -116,7 +117,7 @@ public Enumeration keys() { */ @Override public Enumeration cloneKeys() { - return Collections.emptyEnumeration(); + return Collections.emptyEnumeration(); } /** @@ -124,7 +125,7 @@ public Enumeration cloneKeys() { */ @Override public Enumeration keys(boolean checkReadLocks) { - return Collections.emptyEnumeration(); + return Collections.emptyEnumeration(); } /** @@ -132,7 +133,7 @@ public Enumeration keys(boolean checkReadLocks) { * and the cache may need to be updated */ @Override - public void lazyRelationshipLoaded(Object object, ValueHolderInterface valueHolder, ForeignReferenceMapping mapping){ + public void lazyRelationshipLoaded(Object object, ValueHolderInterface valueHolder, ForeignReferenceMapping mapping){ //NO-OP } diff --git a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/identitymaps/UnitOfWorkIdentityMap.java b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/identitymaps/UnitOfWorkIdentityMap.java index 2deb0f866bb..e07d821e60a 100644 --- a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/identitymaps/UnitOfWorkIdentityMap.java +++ b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/identitymaps/UnitOfWorkIdentityMap.java @@ -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 @@ -34,7 +34,7 @@ public UnitOfWorkIdentityMap(int size, ClassDescriptor descriptor, AbstractSessi super(); this.maxSize = size; // PERF: Use a HashMap as more efficient than a ConcurrentMap and single threaded. - this.cacheKeys = new HashMap(size); + this.cacheKeys = new HashMap<>(size); this.descriptor = descriptor; this.session = session; this.isIsolated = isolated; diff --git a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/identitymaps/WeakUnitOfWorkIdentityMap.java b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/identitymaps/WeakUnitOfWorkIdentityMap.java index aab0f7e4976..92da5d765e8 100644 --- a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/identitymaps/WeakUnitOfWorkIdentityMap.java +++ b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/identitymaps/WeakUnitOfWorkIdentityMap.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2023 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 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 @@ -15,6 +15,7 @@ import org.eclipse.persistence.descriptors.ClassDescriptor; import org.eclipse.persistence.internal.sessions.AbstractSession; +import java.lang.ref.Reference; import java.lang.ref.ReferenceQueue; public class WeakUnitOfWorkIdentityMap extends UnitOfWorkIdentityMap { @@ -41,11 +42,11 @@ public WeakUnitOfWorkIdentityMap(int size, ClassDescriptor descriptor, AbstractS * the total time still constant. */ protected void cleanupDeadCacheKeys() { - QueueableWeakCacheKey.CacheKeyReference reference = (QueueableWeakCacheKey.CacheKeyReference)referenceQueue.poll(); + Reference reference = referenceQueue.poll(); while ( reference != null) { - CacheKey key = reference.getOwner(); + CacheKey key = ((QueueableWeakCacheKey.CacheKeyReference) reference.get()).getOwner(); remove(key); - reference = (QueueableWeakCacheKey.CacheKeyReference)referenceQueue.poll(); + reference = referenceQueue.poll(); } } diff --git a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/oxm/XMLObjectBuilder.java b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/oxm/XMLObjectBuilder.java index 24c6e7b974c..c757fe5ea84 100644 --- a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/oxm/XMLObjectBuilder.java +++ b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/oxm/XMLObjectBuilder.java @@ -483,7 +483,7 @@ public NamespaceResolver getNamespaceResolver() { NamespaceResolver namespaceResolver = null; if (isXmlDescriptor()) { namespaceResolver = ((XMLDescriptor)getDescriptor()).getNamespaceResolver(); - } else if (getDescriptor() instanceof org.eclipse.persistence.eis.EISDescriptor) { + } else if (getDescriptor().isEISDescriptor()) { namespaceResolver = ((org.eclipse.persistence.eis.EISDescriptor)getDescriptor()).getNamespaceResolver(); } return namespaceResolver; diff --git a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/sessions/IdentityMapAccessor.java b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/sessions/IdentityMapAccessor.java index 539669b4160..7caba4d9233 100644 --- a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/sessions/IdentityMapAccessor.java +++ b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/sessions/IdentityMapAccessor.java @@ -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 @@ -253,7 +253,7 @@ public CacheKey getCacheKeyForObject(Object object, ClassDescriptor descriptor) * INTERNAL: * This method is used to get a list of those classes with IdentityMaps in the Session. */ - public Vector getClassesRegistered() { + public List getClassesRegistered() { return getIdentityMapManager().getClassesRegistered(); } @@ -885,10 +885,10 @@ public void invalidateQueryCache(Class classThatChanged) { */ @Override public void invalidateAll() { - Iterator identiyMapClasses = getIdentityMapManager().getIdentityMapClasses(); + Iterator> identiyMapClasses = getIdentityMapManager().getIdentityMapClasses(); while (identiyMapClasses.hasNext()) { - invalidateClass((Class) identiyMapClasses.next()); + invalidateClass(identiyMapClasses.next()); } } @@ -1158,7 +1158,7 @@ public void iterate(Object object) { ClassDescriptor descriptor = descriptors.next(); IdentityMap cache = getIdentityMap(descriptor, true); if (cache != null) { - for (Enumeration mapEnum = cache.elements(); mapEnum.hasMoreElements();) { + for (Enumeration mapEnum = cache.elements(); mapEnum.hasMoreElements();) { iterator.startIterationOn(mapEnum.nextElement()); } } diff --git a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/sessions/IsolatedClientSessionIdentityMapAccessor.java b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/sessions/IsolatedClientSessionIdentityMapAccessor.java index 2880dfb7d26..07939ff02bb 100644 --- a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/sessions/IsolatedClientSessionIdentityMapAccessor.java +++ b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/sessions/IsolatedClientSessionIdentityMapAccessor.java @@ -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 @@ -177,8 +177,8 @@ public boolean containsObjectInIdentityMap(Object primaryKey, Class theClass, * This method is used to get a list of those classes with IdentityMaps in the Session. */ @Override - public Vector getClassesRegistered() { - Vector results = getIdentityMapManager().getClassesRegistered(); + public List getClassesRegistered() { + List results = getIdentityMapManager().getClassesRegistered(); results.addAll(((IsolatedClientSession)session).getParent().getIdentityMapAccessorInstance().getClassesRegistered()); return results; } diff --git a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/sessions/UnitOfWorkImpl.java b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/sessions/UnitOfWorkImpl.java index 8f5d110ffed..8fed6ff5efe 100644 --- a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/sessions/UnitOfWorkImpl.java +++ b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/sessions/UnitOfWorkImpl.java @@ -1312,7 +1312,7 @@ public void commitAndResumeWithPreBuiltChangeSet(UnitOfWorkChangeSet uowChangeSe @Override public void commitAndResumeOnFailure() throws DatabaseException, OptimisticLockException { // First clone the identity map, on failure replace the clone back as the cache. - IdentityMapManager failureManager = (IdentityMapManager)getIdentityMapAccessorInstance().getIdentityMapManager().clone(); + IdentityMapManager failureManager = getIdentityMapAccessorInstance().getIdentityMapManager().clone(); try { // Call commitAndResume. // Oct 13, 2000 - JED PRS #13551 diff --git a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/services/RuntimeServices.java b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/services/RuntimeServices.java index 659e79765dd..d56972213cc 100644 --- a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/services/RuntimeServices.java +++ b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/services/RuntimeServices.java @@ -62,7 +62,6 @@ import java.util.List; import java.util.Map; import java.util.StringTokenizer; -import java.util.Vector; import java.util.regex.PatternSyntaxException; @@ -232,20 +231,17 @@ public void updatePoolSize(String poolName, int maxSize, int minSize) { } /** - * This method will return the available Connection pools within this Server Session + * This method will return the available Connection pools within this Server Session * @return java.util.List the available pools. */ - public List getAvailableConnectionPools() { - Vector list = null; + public List getAvailableConnectionPools() { + List list = null; if (ClassConstants.ServerSession_Class.isAssignableFrom(getSession().getClass())) { Map pools = ((ServerSession)getSession()).getConnectionPools(); - list = new Vector(pools.size()); - Iterator poolNames = pools.keySet().iterator(); - while (poolNames.hasNext()) { - list.add(poolNames.next()); - } + list = new ArrayList<>(pools.size()); + list.addAll(pools.keySet()); } else { - list = new Vector(); + list = new ArrayList<>(); } return list; } @@ -256,8 +252,8 @@ public List getAvailableConnectionPools() { * @return java.util.List a list containing two values. The first value is the Maximun size of the pool. * The second value is the Minimum size of the pool. */ - public List getSizeForPool(String poolName) { - Vector results = new Vector(2); + public List getSizeForPool(String poolName) { + List results = new ArrayList<>(2); if (ClassConstants.ServerSession_Class.isAssignableFrom(getSession().getClass())) { ConnectionPool connectionPool = ((ServerSession)getSession()).getConnectionPool(poolName); if (connectionPool != null) { @@ -311,26 +307,28 @@ public void resetAllConnections() { } /** - * This method is used to return those Class Names that have identity Maps in the Session. + * This method is used to return those Class Names that have identity Maps in the Session. * Please note that SubClasses and aggregates will be missing form this list as they do not have * separate identity maps. + * * @return java.util.List contains all of the classes which have identity maps in the current session. */ - public List getClassesInSession() { + public List getClassesInSession() { return getSession().getIdentityMapAccessorInstance().getIdentityMapManager().getClassesRegistered(); } /** * This method will return a collection of the objects in the Identity Map. * There is no particular order to these objects. + * * @param className the fully qualified classname of the class to the instances of - * @exception ClassNotFoundException thrown then the IdentityMap for that class name could not be found + * @throws ClassNotFoundException thrown then the IdentityMap for that class name could not be found */ - public List getObjectsInIdentityMap(String className) throws ClassNotFoundException { + public List getObjectsInIdentityMap(String className) throws ClassNotFoundException { Class classToChange = getSession().getDatasourcePlatform().getConversionManager().convertObject(className, ClassConstants.CLASS); IdentityMap map = getSession().getIdentityMapAccessorInstance().getIdentityMap(classToChange); - Vector results = new Vector(map.getSize()); + List results = new ArrayList<>(map.getSize()); Enumeration objects = map.keys(); while (objects.hasMoreElements()) { results.add(objects.nextElement().getObject()); @@ -380,7 +378,7 @@ public Integer getNumberOfObjectsInIdentityMapSubCache(String className) throws Class classToChange = getSession().getDatasourcePlatform().getConversionManager().convertObject(className, ClassConstants.CLASS); IdentityMap map = getSession().getIdentityMapAccessorInstance().getIdentityMap(classToChange); if (map.getClass().isAssignableFrom(ClassConstants.HardCacheWeakIdentityMap_Class)) { - List subCache = ((HardCacheWeakIdentityMap)map).getReferenceCache(); + List subCache = ((HardCacheWeakIdentityMap)map).getReferenceCache(); result = subCache.size(); } return result; @@ -491,7 +489,7 @@ private String trimProfileString(String originalProfileString) { String trimmedString; if (originalProfileString.length() > 1) { - trimmedString = originalProfileString.substring(0, originalProfileString.length()); + trimmedString = originalProfileString; if ((trimmedString.charAt(0) == '{') && (trimmedString.charAt(trimmedString.length() - 1) == '}')) { trimmedString = trimmedString.substring(1, trimmedString.length() - 1); } @@ -746,9 +744,9 @@ public Object[][] getClassSummaryDetails() { * * @return java.util.Vector */ - private Vector getMappedClassNames() { + private List getMappedClassNames() { Map alreadyAdded = new HashMap<>(); - Vector mappedClassNames = new Vector<>(); + List mappedClassNames = new ArrayList<>(); String mappedClassName = null; Iterator descriptorsIterator = getSession().getProject().getDescriptors() @@ -777,19 +775,19 @@ private Vector getMappedClassNames() { /** * INTERNAL: - * This method traverses the EclipseLink descriptors and returns a Vector of the descriptor's + * This method traverses the EclipseLink descriptors and returns a List of the descriptor's * reference class names that match the provided filter. The filter is a comma separated * list of strings to match against. * * @param filter A comma separated list of strings to match against. * @return A Vector of class names that match the filter. */ - public Vector getMappedClassNamesUsingFilter(String filter) { + public List getMappedClassNamesUsingFilter(String filter) { //Output Vector - Vector outputVector = new Vector<>(); + List outputVector = new ArrayList<>(); //Input mapped class names - Vector mappedClassNames = getMappedClassNames(); + List mappedClassNames = getMappedClassNames(); //Input filter values List filters = new ArrayList<>(); @@ -988,7 +986,7 @@ public void printAvailableConnectionPools() { Map pools = ((ServerSession)getSession()).getConnectionPools(); Iterator poolNames = pools.keySet().iterator(); while (poolNames.hasNext()) { - String poolName = poolNames.next().toString(); + String poolName = poolNames.next(); ((AbstractSession)session).log(SessionLog.INFO, SessionLog.SERVER, "jmx_mbean_runtime_services_pool_name", poolName); } } else { @@ -1033,7 +1031,7 @@ public Integer getMinSizeForPool(String poolName) { * separate identity maps. */ public void printClassesInSession() { - Vector classes = getSession().getIdentityMapAccessorInstance().getIdentityMapManager().getClassesRegistered(); + List classes = getSession().getIdentityMapAccessorInstance().getIdentityMapManager().getClassesRegistered(); int index; if (classes.isEmpty()) { ((AbstractSession)session).log(SessionLog.INFO, SessionLog.SERVER, "jmx_mbean_runtime_services_no_classes_in_session"); @@ -1041,7 +1039,7 @@ public void printClassesInSession() { } for (index = 0; index < classes.size(); index++) { - getSession().getSessionLog().log(SessionLog.FINEST, (String)classes.get(index)); + getSession().getSessionLog().log(SessionLog.FINEST, classes.get(index)); } } @@ -1081,7 +1079,7 @@ public void printObjectsInIdentityMap(String className) throws ClassNotFoundExce * This method will log the types of Identity Maps in the session. */ public void printAllIdentityMapTypes() { - Vector classesRegistered = getSession().getIdentityMapAccessorInstance().getIdentityMapManager().getClassesRegistered(); + List classesRegistered = getSession().getIdentityMapAccessorInstance().getIdentityMapManager().getClassesRegistered(); String registeredClassName; Class registeredClass; @@ -1093,7 +1091,7 @@ public void printAllIdentityMapTypes() { //get each identity map, and log the type for (int index = 0; index < classesRegistered.size(); index++) { - registeredClassName = (String)classesRegistered.get(index); + registeredClassName = classesRegistered.get(index); registeredClass = getSession().getDatasourcePlatform().getConversionManager().convertObject(registeredClassName, ClassConstants.CLASS); IdentityMap map = getSession().getIdentityMapAccessorInstance().getIdentityMap(registeredClass); ((AbstractSession)session).log(SessionLog.INFO, SessionLog.SERVER, "jmx_mbean_runtime_services_identity_map_class", @@ -1105,7 +1103,7 @@ public void printAllIdentityMapTypes() { * This method will log all objects in all Identity Maps in the session. */ public void printObjectsInIdentityMaps() { - Vector classesRegistered = getSession().getIdentityMapAccessorInstance().getIdentityMapManager().getClassesRegistered(); + List classesRegistered = getSession().getIdentityMapAccessorInstance().getIdentityMapManager().getClassesRegistered(); String registeredClassName; //Check if there aren't any classes registered @@ -1116,7 +1114,7 @@ public void printObjectsInIdentityMaps() { //get each identity map, and log the type for (int index = 0; index < classesRegistered.size(); index++) { - registeredClassName = (String)classesRegistered.get(index); + registeredClassName = classesRegistered.get(index); try { this.printObjectsInIdentityMap(registeredClassName); } catch (ClassNotFoundException classNotFound) { @@ -1131,7 +1129,7 @@ public void printObjectsInIdentityMaps() { * This method will SUM and return the number of objects in all Identity Maps in the session. */ public Integer getNumberOfObjectsInAllIdentityMaps() { - Vector classesRegistered = getSession().getIdentityMapAccessorInstance().getIdentityMapManager().getClassesRegistered(); + List classesRegistered = getSession().getIdentityMapAccessorInstance().getIdentityMapManager().getClassesRegistered(); String registeredClassName; int sum = 0; @@ -1143,7 +1141,7 @@ public Integer getNumberOfObjectsInAllIdentityMaps() { //get each identity map, and log the size for (int index = 0; index < classesRegistered.size(); index++) { - registeredClassName = (String)classesRegistered.get(index); + registeredClassName = classesRegistered.get(index); try { sum += this.getNumberOfObjectsInIdentityMap(registeredClassName); } catch (ClassNotFoundException classNotFound) { @@ -1161,7 +1159,7 @@ public Integer getNumberOfObjectsInAllIdentityMaps() { * This does not include aggregates. */ public Integer getNumberOfPersistentClasses() { - Map classesTable = new HashMap(); + Map classesTable = new HashMap<>(); ClassDescriptor currentDescriptor; //use a table to eliminate duplicate classes. Ignore Aggregates @@ -1265,7 +1263,7 @@ public synchronized void initializeIdentityMaps(String[] classNames) throws Clas * This method is used to invalidate the identity maps in the session. */ public synchronized void invalidateAllIdentityMaps() { - Vector classesRegistered = getSession().getIdentityMapAccessorInstance().getIdentityMapManager().getClassesRegistered(); + List classesRegistered = getSession().getIdentityMapAccessorInstance().getIdentityMapManager().getClassesRegistered(); String registeredClassName; Class registeredClass; @@ -1275,7 +1273,7 @@ public synchronized void invalidateAllIdentityMaps() { //get each identity map, and invalidate for (int index = 0; index < classesRegistered.size(); index++) { - registeredClassName = (String)classesRegistered.get(index); + registeredClassName = classesRegistered.get(index); registeredClass = getSession().getDatasourcePlatform().getConversionManager() .convertObject(registeredClassName, ClassConstants.CLASS); getSession().getIdentityMapAccessor().invalidateClass(registeredClass); @@ -1392,7 +1390,7 @@ private CompositeType buildCompositeTypeForClassSummaryDetails() throws OpenData public List getClassSummaryDetailsUsingFilterArray(String filter) { try { // if the filter is null, return all the details - Vector mappedClassNames = getMappedClassNamesUsingFilter(filter); + List mappedClassNames = getMappedClassNamesUsingFilter(filter); String mappedClassName; List classSummaryDetails = new ArrayList<>(); // Check if there aren't any classes mapped @@ -1531,7 +1529,7 @@ private TabularData buildClassSummaryDetailsUsingFilter(String filter) { } try { - Vector mappedClassNames = getMappedClassNamesUsingFilter(filter); + List mappedClassNames = getMappedClassNamesUsingFilter(filter); String mappedClassName; TabularDataSupport rowData = new TabularDataSupport(buildTabularTypeForClassSummaryDetails()); // Check if there aren't any classes mapped @@ -1569,7 +1567,7 @@ private TabularData buildClassSummaryDetailsUsingFilter(String filter) { */ private TabularData buildClassSummaryDetails() { try { - Vector mappedClassNames = getMappedClassNames(); + List mappedClassNames = getMappedClassNames(); String mappedClassName; TabularDataSupport rowData = new TabularDataSupport(buildTabularTypeForClassSummaryDetails()); // Check if there aren't any classes mapped diff --git a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/services/mbean/MBeanRuntimeServicesMBean.java b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/services/mbean/MBeanRuntimeServicesMBean.java index 2f4a71f9c9a..eef988e3b92 100644 --- a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/services/mbean/MBeanRuntimeServicesMBean.java +++ b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/services/mbean/MBeanRuntimeServicesMBean.java @@ -19,7 +19,6 @@ import org.eclipse.persistence.services.ClassSummaryDetailBase; import java.util.List; -import java.util.Vector; /** *

@@ -95,12 +94,12 @@ public interface MBeanRuntimeServicesMBean { /** * This method will return the available Connection pools within this Server Session */ - List getAvailableConnectionPools(); + List getAvailableConnectionPools(); /** * This method will retrieve the size of a particular connection pool */ - List getSizeForPool(String poolName); + List getSizeForPool(String poolName); /** @@ -120,13 +119,13 @@ public interface MBeanRuntimeServicesMBean { * Please note that SubClasses and aggregates will be missing from this list as they do not have * separate identity maps. */ - List getClassesInSession(); + List getClassesInSession(); /** - * This method will return a collection of the objects in the Identity Map. + * This method will return a collection of the objects in the Identity Map. * There is no particular order to these objects. */ - List getObjectsInIdentityMap(String className) throws ClassNotFoundException; + List getObjectsInIdentityMap(String className) throws ClassNotFoundException; /** * This method is used to return the number of objects in a particular Identity Map @@ -261,7 +260,7 @@ public interface MBeanRuntimeServicesMBean { * @param filter A comma separated list of strings to match against. * @return A Vector of class names that match the filter. */ - Vector getMappedClassNamesUsingFilter(String filter); + List getMappedClassNamesUsingFilter(String filter); /** * getModuleName(): Answer the name of the context-root of the application that this session is associated with. diff --git a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/sessions/interceptors/CacheInterceptor.java b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/sessions/interceptors/CacheInterceptor.java index 2c60f45e3aa..7e5f416214c 100644 --- a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/sessions/interceptors/CacheInterceptor.java +++ b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/sessions/interceptors/CacheInterceptor.java @@ -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 @@ -26,8 +26,8 @@ import java.util.Collection; import java.util.Enumeration; -import java.util.HashMap; import java.util.Map; +import java.util.Set; /** @@ -137,7 +137,7 @@ public CacheKey acquireReadLockOnCacheKeyNoWait(Object primaryKey) { * Used to print all the locks in the identity map. */ @Override - public void collectLocks(HashMap threadList) { + public void collectLocks(Map> threadList) { this.targetIdentityMap.collectLocks(threadList); } @@ -146,7 +146,7 @@ public void collectLocks(HashMap threadList) { * This is used by UnitOfWork commitAndResumeOnFailure to avoid corrupting the cache during a failed commit. */ @Override - public abstract Object clone(); + public abstract IdentityMap clone(); /** * Return true if an CacheKey with the primary key is in the map. @@ -166,7 +166,7 @@ public boolean containsKey(Object primaryKey) { * validateCache() has been called to print out the contents of the cache. */ @Override - public Enumeration elements() { + public Enumeration elements() { return this.targetIdentityMap.elements(); } @@ -326,7 +326,7 @@ public Enumeration keys(boolean checkReadLocks) { * and the cache may need to be updated */ @Override - public void lazyRelationshipLoaded(Object rootEntity, ValueHolderInterface valueHolder, ForeignReferenceMapping mapping){ + public void lazyRelationshipLoaded(Object rootEntity, ValueHolderInterface valueHolder, ForeignReferenceMapping mapping){ this.targetIdentityMap.lazyRelationshipLoaded(rootEntity, valueHolder, mapping); } diff --git a/jpa/eclipselink.jpa.test/src/it/java/org/eclipse/persistence/testing/tests/jpa/config/CacheAuditor.java b/jpa/eclipselink.jpa.test/src/it/java/org/eclipse/persistence/testing/tests/jpa/config/CacheAuditor.java index 20c30382864..5839db92612 100644 --- a/jpa/eclipselink.jpa.test/src/it/java/org/eclipse/persistence/testing/tests/jpa/config/CacheAuditor.java +++ b/jpa/eclipselink.jpa.test/src/it/java/org/eclipse/persistence/testing/tests/jpa/config/CacheAuditor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2022 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 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 @@ -52,7 +52,7 @@ public CacheAuditor(IdentityMap targetIdentityMap, AbstractSession interceptedSe } @Override - public Object clone() { + public IdentityMap clone() { return new CacheAuditor(targetIdentityMap, interceptedSession); } diff --git a/jpa/eclipselink.jpa.testapps/jpa.test.xml.composite.advanced/common/src/main/java/org/eclipse/persistence/testing/models/jpa/xml/composite/advanced/member_1/CacheAuditor.java b/jpa/eclipselink.jpa.testapps/jpa.test.xml.composite.advanced/common/src/main/java/org/eclipse/persistence/testing/models/jpa/xml/composite/advanced/member_1/CacheAuditor.java index 57f3a736863..c8f6d29a15e 100644 --- a/jpa/eclipselink.jpa.testapps/jpa.test.xml.composite.advanced/common/src/main/java/org/eclipse/persistence/testing/models/jpa/xml/composite/advanced/member_1/CacheAuditor.java +++ b/jpa/eclipselink.jpa.testapps/jpa.test.xml.composite.advanced/common/src/main/java/org/eclipse/persistence/testing/models/jpa/xml/composite/advanced/member_1/CacheAuditor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2022 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 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 @@ -49,7 +49,7 @@ public CacheAuditor(IdentityMap targetIdentityMap, AbstractSession interceptedSe } @Override - public Object clone() { + public IdentityMap clone() { return new CacheAuditor(targetIdentityMap, interceptedSession); } @@ -72,7 +72,7 @@ public void release() { } @Override - public void lazyRelationshipLoaded(Object rootEntity, ValueHolderInterface valueHolder, ForeignReferenceMapping mapping) { + public void lazyRelationshipLoaded(Object rootEntity, ValueHolderInterface valueHolder, ForeignReferenceMapping mapping) { // TODO Auto-generated method stub } diff --git a/jpa/eclipselink.jpa.testapps/jpa.test.xml.only/jpa.test.xml.advanced/src/main/java/org/eclipse/persistence/testing/models/jpa/xml/advanced/CacheAuditor.java b/jpa/eclipselink.jpa.testapps/jpa.test.xml.only/jpa.test.xml.advanced/src/main/java/org/eclipse/persistence/testing/models/jpa/xml/advanced/CacheAuditor.java index a3e523a4815..2d86f14e167 100644 --- a/jpa/eclipselink.jpa.testapps/jpa.test.xml.only/jpa.test.xml.advanced/src/main/java/org/eclipse/persistence/testing/models/jpa/xml/advanced/CacheAuditor.java +++ b/jpa/eclipselink.jpa.testapps/jpa.test.xml.only/jpa.test.xml.advanced/src/main/java/org/eclipse/persistence/testing/models/jpa/xml/advanced/CacheAuditor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2022 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 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 @@ -40,7 +40,7 @@ public CacheAuditor(IdentityMap targetIdentityMap, AbstractSession interceptedSe } @Override - public Object clone() { + public IdentityMap clone() { return new CacheAuditor(targetIdentityMap, interceptedSession); } @@ -113,7 +113,7 @@ public void setShouldThrow(boolean shouldThrow) { } @Override - public void lazyRelationshipLoaded(Object rootEntity, @SuppressWarnings({"rawtypes"}) ValueHolderInterface valueHolder, ForeignReferenceMapping mapping) { + public void lazyRelationshipLoaded(Object rootEntity, ValueHolderInterface valueHolder, ForeignReferenceMapping mapping) { // TODO Auto-generated method stub }