Skip to content

Commit

Permalink
basic code cleanup in jpa
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Jungmann <[email protected]>
  • Loading branch information
lukasj committed Jan 16, 2024
1 parent e70ba5c commit 12d8dd8
Show file tree
Hide file tree
Showing 280 changed files with 1,302 additions and 1,506 deletions.
3 changes: 2 additions & 1 deletion bundles/eclipselink/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 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 @@ -291,6 +291,7 @@
exports org.eclipse.persistence.internal.xr.sxf;

uses org.eclipse.persistence.jpa.rs.PersistenceContextFactoryProvider;
uses org.eclipse.persistence.mappings.converters.spi.ConverterProvider;
uses org.eclipse.persistence.internal.databaseaccess.spi.JsonPlatformProvider;

provides jakarta.persistence.spi.PersistenceProvider with org.eclipse.persistence.jpa.PersistenceProvider;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2023 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 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 @@ -66,4 +66,6 @@

opens org.eclipse.persistence.internal.jpa.deployment to org.eclipse.persistence.core;
provides jakarta.persistence.spi.PersistenceProvider with org.eclipse.persistence.jpa.PersistenceProvider;

uses org.eclipse.persistence.mappings.converters.spi.ConverterProvider;
}
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 @@ -51,29 +51,29 @@ public String getAttributeName() {
@Override
public Map<Class, Subgraph> getSubgraphs() {
if (this.subgraphs == null){
this.subgraphs = new HashMap<Class, Subgraph>();
this.subgraphs = new HashMap<>();
}
return this.subgraphs;
}

@Override
public Map<Class, Subgraph> getKeySubgraphs() {
if (this.keySubgraphs == null){
this.keySubgraphs = new HashMap<Class, Subgraph>();
this.keySubgraphs = new HashMap<>();
}
return this.keySubgraphs;
}

public void addSubgraph(EntityGraphImpl entityGraphImpl) {
if (this.subgraphs == null){
this.subgraphs = new HashMap<Class, Subgraph>();
this.subgraphs = new HashMap<>();
}
this.subgraphs.put(entityGraphImpl.getClassType(), entityGraphImpl);
}

public void addKeySubgraph(EntityGraphImpl entityGraphImpl) {
if (this.keySubgraphs == null){
this.keySubgraphs = new HashMap<Class, Subgraph>();
this.keySubgraphs = new HashMap<>();
}
this.keySubgraphs.put(entityGraphImpl.getClassType(), entityGraphImpl);
}
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 @@ -342,7 +342,7 @@ public Object createBeanUsingKey(Object key, AbstractSession session) {
* INTERNAL:
* Cache the bean's primary key fields so speed up creating of primary key
* objects and initialization of beans.
*
* <p>
* Note, we have to re-look up the fields for the bean class since
* these fields may have been loaded with the wrong loader (thank you Kirk).
* If the key is compound, we also have to look up the fields for the key.
Expand All @@ -351,7 +351,7 @@ protected KeyElementAccessor[] initializePrimaryKeyFields(Class<?> keyClass, Abs
KeyElementAccessor[] pkAttributes = null;
ClassDescriptor aDescriptor = this.getDescriptor();

fieldToAccessorMap = new HashMap<DatabaseField,KeyElementAccessor>();
fieldToAccessorMap = new HashMap<>();
int numberOfIDFields = aDescriptor.getPrimaryKeyFields().size();
pkAttributes = new KeyElementAccessor[numberOfIDFields];
Iterator<DatabaseField> attributesIter = aDescriptor.getPrimaryKeyFields().iterator();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 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 @@ -64,7 +64,7 @@ public boolean contains(Class cls, Object id) {
return false;
}
ClassDescriptor descriptor = getSession().getClassDescriptor(cls); // getDescriptor() is the same call
/**
/*
* Check for no descriptor associated with the class parameter.
* This will occur if the class represents a MappedSuperclass (concrete or abstract class),
* an interface or Embeddable class.
Expand Down Expand Up @@ -152,7 +152,7 @@ public void evict(Class classToEvict, Object id) {
@Override
public void evict(Class<?> classToEvict, Object id, boolean invalidateInCluster) {
getEntityManagerFactory().verifyOpen();
/**
/*
* The following descriptor lookup will return the Entity representing the classToEvict parameter,
* or it will return the first Entity superclass of a MappedSuperclass in the hierarchy
* - in this case all subclasses of the parent Entity will be evicted.
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 @@ -227,7 +227,7 @@ public static DatabaseQuery buildSQLDatabaseQuery(Class<?> resultClass, String s
* Build a DataReadQuery from a sql string.
*/
public static DatabaseQuery buildSQLDatabaseQuery(String sqlString, ClassLoader classLoader, AbstractSession session) {
return buildSQLDatabaseQuery(sqlString, new HashMap<String, Object>(), classLoader, session);
return buildSQLDatabaseQuery(sqlString, new HashMap<>(), classLoader, session);
}

/**
Expand Down Expand Up @@ -371,10 +371,7 @@ public Collection getResultCollection() {
return (Collection) executeReadQuery();
} catch (LockTimeoutException exception) {
throw exception;
} catch (PersistenceException exception) {
setRollbackOnly();
throw exception;
} catch (IllegalStateException exception) {
} catch (PersistenceException | IllegalStateException exception) {
setRollbackOnly();
throw exception;
} catch (RuntimeException exception) {
Expand Down Expand Up @@ -413,10 +410,7 @@ public Cursor getResultCursor() {
return (Cursor) result;
} catch (LockTimeoutException e) {
throw e;
} catch (PersistenceException exception) {
setRollbackOnly();
throw exception;
} catch (IllegalStateException exception) {
} catch (PersistenceException | IllegalStateException exception) {
setRollbackOnly();
throw exception;
} catch (RuntimeException exception) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 1998, 2023 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2021 IBM Corporation. All rights reserved.
* Copyright (c) 1998, 2024 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2024 IBM Corporation. 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 @@ -467,7 +467,7 @@ protected void processProperties(Map properties) {
* Re-bootstrap this factory. This method will rebuild the EntityManagerFactory. It should be used
* in conjunction with a MetadataSource to allow mappings to be changed in a running system. All existing
* EntityMangers will continue to function with the old metadata, but new factories will use the new metadata.
*
* <p>
* This call will throw an exception when called on EntityManagerFactoryImplDelegate
*/
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2023 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 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 @@ -46,7 +46,6 @@
import jakarta.persistence.metamodel.Metamodel;
import org.eclipse.persistence.config.ReferenceMode;
import org.eclipse.persistence.descriptors.ClassDescriptor;
import org.eclipse.persistence.descriptors.TimestampLockingPolicy;
import org.eclipse.persistence.descriptors.VersionLockingPolicy;
import org.eclipse.persistence.exceptions.PersistenceUnitLoadingException;
import org.eclipse.persistence.internal.descriptors.OptimisticLockingPolicy;
Expand Down Expand Up @@ -370,8 +369,7 @@ public void refreshMetadata(Map<String, Object> properties){
}
String sessionName = setupImpl.getSessionName();
Map<String, Object> existingProperties = delegate.getProperties();
Map<String, Object> deployProperties = new HashMap<>();
deployProperties.putAll(existingProperties);
Map<String, Object> deployProperties = new HashMap<>(existingProperties);
if (properties != null){
deployProperties.putAll(properties);
}
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.
* Copyright (c) 2021 IBM Corporation. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -60,7 +60,7 @@ public class EntityManagerFactoryProvider {
// TEMPORARY - WILL BE REMOVED.
// Used to warn users about deprecated property name and suggest the valid name.
// TEMPORARY the old property names will be translated to the new ones and processed.
protected static final String oldPropertyNames[][] = {
protected static final String[][] oldPropertyNames = {
{PersistenceUnitProperties.CONNECTION_POOL_MAX, "eclipselink.max-write-connections"},
{PersistenceUnitProperties.CONNECTION_POOL_MIN, "eclipselink.min-write-connections"},
{PersistenceUnitProperties.CONNECTION_POOL_MAX, "eclipselink.max-read-connections"},
Expand Down Expand Up @@ -194,7 +194,7 @@ protected static Object getConfigPropertyLogDebug(String propertyKey, Map overri
}
if ((value != null) && (session != null)) {
if (session.shouldLog(SessionLog.FINEST, SessionLog.PROPERTIES)) {
String overrideValue = PersistenceUnitProperties.getOverriddenLogStringForProperty(propertyKey);;
String overrideValue = PersistenceUnitProperties.getOverriddenLogStringForProperty(propertyKey);
Object logValue = (overrideValue == null) ? value : overrideValue;
session.log(SessionLog.FINEST, SessionLog.PROPERTIES, "property_value_specified", new Object[]{propertyKey, logValue});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 1998, 2023 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2021 IBM Corporation and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2024 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2024 IBM Corporation 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 @@ -164,7 +164,7 @@
* @since TopLink Essentials - JPA 1.0
*/
public class EntityManagerImpl implements org.eclipse.persistence.jpa.JpaEntityManager {
protected enum OperationType {FIND, REFRESH, LOCK};
protected enum OperationType {FIND, REFRESH, LOCK}

/** Allows transparent transactions across JTA and local transactions. */
private TransactionWrapperImpl transaction;
Expand Down Expand Up @@ -423,7 +423,7 @@ public EntityManagerImpl(String sessionName) {
*/
protected Map<QueryImpl, QueryImpl> getOpenQueriesMap() {
if (openQueriesMap == null) {
openQueriesMap = new WeakHashMap<QueryImpl, QueryImpl>();
openQueriesMap = new WeakHashMap<>();
}

return openQueriesMap;
Expand Down Expand Up @@ -1741,7 +1741,7 @@ public jakarta.persistence.Query createQuery(DatabaseQuery databaseQuery) {
public <T> TypedQuery<T> createQuery(CriteriaQuery<T> criteriaQuery) {
try {
verifyOpen();
return new EJBQueryImpl<T>(((CriteriaQueryImpl<T>)criteriaQuery).translate(), this);
return new EJBQueryImpl<>(((CriteriaQueryImpl<T>) criteriaQuery).translate(), this);
} catch (RuntimeException e) {
setRollbackOnly();
throw e;
Expand All @@ -1752,7 +1752,7 @@ public <T> TypedQuery<T> createQuery(CriteriaQuery<T> criteriaQuery) {
public <T> TypedQuery<T> createQuery(CriteriaSelect<T> selectQuery) {
try {
verifyOpen();
return new EJBQueryImpl<T>(((CriteriaSelectInternal<T>)selectQuery).translate(), this);
return new EJBQueryImpl<>(((CriteriaSelectInternal<T>) selectQuery).translate(), this);
} catch (RuntimeException e) {
setRollbackOnly();
throw e;
Expand Down Expand Up @@ -1875,7 +1875,7 @@ public StoredProcedureQuery createStoredProcedureQuery(String procedureName) {
verifyOpen();
StoredProcedureCall call = new StoredProcedureCall();
call.setProcedureName(procedureName);
return new StoredProcedureQueryImpl(StoredProcedureQueryImpl.buildResultSetMappingQuery(new ArrayList<SQLResultSetMapping>(), call), this);
return new StoredProcedureQueryImpl(StoredProcedureQueryImpl.buildResultSetMappingQuery(new ArrayList<>(), call), this);
} catch (RuntimeException e) {
setRollbackOnly();
throw e;
Expand Down Expand Up @@ -1908,7 +1908,7 @@ public StoredProcedureQuery createStoredProcedureQuery(String procedureName, Cla
call.setProcedureName(procedureName);
call.setHasMultipleResultSets(resultClasses.length > 1);

List<SQLResultSetMapping> sqlResultSetMappings = new ArrayList<SQLResultSetMapping>();
List<SQLResultSetMapping> sqlResultSetMappings = new ArrayList<>();
for (Class<?> resultClass : resultClasses) {
sqlResultSetMappings.add(new SQLResultSetMapping(resultClass));
}
Expand Down Expand Up @@ -1947,10 +1947,8 @@ public StoredProcedureQuery createStoredProcedureQuery(String procedureName, Str
call.setProcedureName(procedureName);
call.setHasMultipleResultSets(resultSetMappings.length > 1);

List<String> sqlResultSetMappingNames = new ArrayList<String>();
for (String resultSetMapping : resultSetMappings) {
sqlResultSetMappingNames.add(resultSetMapping);
}
List<String> sqlResultSetMappingNames = new ArrayList<>();
Collections.addAll(sqlResultSetMappingNames, resultSetMappings);

return new StoredProcedureQueryImpl(StoredProcedureQueryImpl.buildResultSetMappingNameQuery(sqlResultSetMappingNames, call), this);
} catch (RuntimeException e) {
Expand Down Expand Up @@ -2563,7 +2561,7 @@ protected static ConnectionPolicy createConnectionPolicy(ServerSession serverSes
if(password != null) {
// can't compare the passed (un-encrypted) password with the existing encrypted one, therefore
// use the new password if it's not an empty string.
isNewPasswordRequired = password.length() > 0;
isNewPasswordRequired = !password.isEmpty();
}
} else {
// user should be removed -> remove password as well
Expand Down Expand Up @@ -2699,19 +2697,19 @@ public boolean isBroker() {
* Property value is to be added if it's non null and not an empty string.
*/
protected static boolean isPropertyToBeAdded(String value) {
return value != null && value.length() > 0;
return value != null && !value.isEmpty();
}

protected static boolean isPropertyToBeAdded(DataSource ds, String dsName) {
return ds != null || (dsName != null && dsName.length() > 0);
return ds != null || (dsName != null && !dsName.isEmpty());
}

/**
* Property value of an empty string indicates that the existing property
* should be removed.
*/
protected static boolean isPropertyToBeRemoved(String value) {
return value != null && value.length() == 0;
return value != null && value.isEmpty();
}

/**
Expand All @@ -2724,7 +2722,7 @@ protected static Boolean isPropertyValueToBeUpdated(String oldValue, String newV
return null;
} else {
// new value is a non empty string
if (newValue.length() > 0) {
if (!newValue.isEmpty()) {
if (oldValue != null) {
if (newValue.equals(oldValue)) {
// new and old values are equal - no change.
Expand Down Expand Up @@ -2809,7 +2807,7 @@ protected HashMap<String, Object> getQueryHints(Object entity, OperationType ope
// Individual methods will handle the entity = null case, although we
// could likely do it here as well.
if (entity != null && properties != null) {
queryHints = new HashMap<String, Object>();
queryHints = new HashMap<>();

if (properties.containsKey(QueryHints.PESSIMISTIC_LOCK_TIMEOUT)) {
queryHints.put(QueryHints.PESSIMISTIC_LOCK_TIMEOUT, properties.get(QueryHints.PESSIMISTIC_LOCK_TIMEOUT));
Expand Down Expand Up @@ -3165,7 +3163,7 @@ public <T> EntityGraph<T> createEntityGraph(Class<T> rootType) {
if (descriptor == null || descriptor.isAggregateDescriptor()){
throw new IllegalArgumentException(ExceptionLocalization.buildMessage("unknown_bean_class", new Object[]{rootType.getName()}));
}
return new EntityGraphImpl<T>(new AttributeGroup(null, rootType, true), descriptor);
return new EntityGraphImpl<>(new AttributeGroup(null, rootType, true), descriptor);
}

@Override
Expand Down Expand Up @@ -3193,7 +3191,7 @@ public <T> List<EntityGraph<? super T>> getEntityGraphs(Class<T> entityClass) {
if (descriptor == null || descriptor.isAggregateDescriptor()){
throw new IllegalArgumentException(ExceptionLocalization.buildMessage("unknown_bean_class", new Object[]{entityClass.getName()}));
}
List<EntityGraph<? super T>> result = new ArrayList<EntityGraph<? super T>>();
List<EntityGraph<? super T>> result = new ArrayList<>();
for (AttributeGroup group : descriptor.getAttributeGroups().values()){
result.add(new EntityGraphImpl<>(group));
}
Expand Down
Loading

0 comments on commit 12d8dd8

Please sign in to comment.