Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup in server/db platforms #1296

Merged
merged 3 commits into from
Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions bundles/eclipselink/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
exports org.eclipse.persistence.sessions.coordination.jms;
exports org.eclipse.persistence.sessions.coordination.rmi;
exports org.eclipse.persistence.sessions.factories;
exports org.eclipse.persistence.sessions.interceptors;
exports org.eclipse.persistence.sessions.remote;
exports org.eclipse.persistence.sessions.remote.rmi;
exports org.eclipse.persistence.sessions.serializers;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2021 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 @@ -34,6 +34,7 @@
import org.eclipse.persistence.platform.server.ServerPlatformDetector;
import org.eclipse.persistence.platform.server.ServerPlatformUtils;
import org.eclipse.persistence.sessions.DatabaseSession;
import org.eclipse.persistence.sessions.ExternalTransactionController;
import org.eclipse.persistence.sessions.factories.SessionManager;
import org.junit.After;
import org.junit.Assert;
Expand Down Expand Up @@ -327,7 +328,7 @@ public Platform(DatabaseSession newDatabaseSession) {
}

@Override
public Class getExternalTransactionControllerClass() {
public Class<? extends ExternalTransactionController> getExternalTransactionControllerClass() {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
exports org.eclipse.persistence.sessions.coordination.jms;
exports org.eclipse.persistence.sessions.coordination.rmi;
exports org.eclipse.persistence.sessions.factories;
exports org.eclipse.persistence.sessions.interceptors;
exports org.eclipse.persistence.sessions.remote;
exports org.eclipse.persistence.sessions.remote.rmi;
exports org.eclipse.persistence.sessions.serializers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
public class DatabasePlatform extends DatasourcePlatform {

/** Holds a map of values used to map JAVA types to database types for table creation */
protected transient Map<Class, FieldTypeDefinition> fieldTypes;
protected transient Map<Class<?>, FieldTypeDefinition> fieldTypes;

/** Indicates that native SQL should be used for literal values instead of ODBC escape format
Only used with Oracle, Sybase &amp; DB2 */
Expand Down Expand Up @@ -199,7 +199,7 @@ public class DatabasePlatform extends DatasourcePlatform {
protected boolean shouldOptimizeDataConversion;

/** Stores mapping of class types to database types for schema creation. */
protected transient Map<String, Class> classTypes;
protected transient Map<String, Class<?>> classTypes;

/** Allow for case in field names to be ignored as some databases are not case sensitive and when using custom this can be an issue. */
public static boolean shouldIgnoreCaseOnFieldComparisons = false;
Expand Down Expand Up @@ -678,8 +678,8 @@ public DatabaseCall buildCallWithReturning(SQLCall sqlCall, Vector returnFields)
/**
* Return the mapping of class types to database types for the schema framework.
*/
protected Map<String, Class> buildClassTypes() {
Map<String, Class> classTypeMapping = new HashMap<>();
protected Map<String, Class<?>> buildClassTypes() {
Map<String, Class<?>> classTypeMapping = new HashMap<>();
// Key the Map the other way for table creation.
classTypeMapping.put("NUMBER", java.math.BigInteger.class);
classTypeMapping.put("DECIMAL", java.math.BigDecimal.class);
Expand Down Expand Up @@ -730,10 +730,8 @@ protected Map<String, Class> buildClassTypes() {
/**
* Return the mapping of class types to database types for the schema framework.
*/
protected Hashtable buildFieldTypes() {
Hashtable fieldTypeMapping;

fieldTypeMapping = new Hashtable();
protected Hashtable<Class<?>, FieldTypeDefinition> buildFieldTypes() {
Hashtable<Class<?>, FieldTypeDefinition> fieldTypeMapping = new Hashtable<>();
fieldTypeMapping.put(Boolean.class, new FieldTypeDefinition("NUMBER", 1));

fieldTypeMapping.put(Integer.class, new FieldTypeDefinition("NUMBER", 10));
Expand Down Expand Up @@ -1154,7 +1152,7 @@ public String getProcedureOptionList() {
/**
* Return the class type to database type mapping for the schema framework.
*/
public Map<String, Class> getClassTypes() {
public Map<String, Class<?>> getClassTypes() {
if (classTypes == null) {
classTypes = buildClassTypes();
}
Expand Down Expand Up @@ -1229,14 +1227,14 @@ public String getDropDatabaseSchemaString(String schema) {
* Return the field type object describing this databases platform specific representation
* of the Java primitive class name.
*/
public FieldTypeDefinition getFieldTypeDefinition(Class javaClass) {
public FieldTypeDefinition getFieldTypeDefinition(Class<?> javaClass) {
return getFieldTypes().get(javaClass);
}

/**
* Return the class type to database type mappings for the schema framework.
*/
public Map<Class, FieldTypeDefinition> getFieldTypes() {
public Map<Class<?>, FieldTypeDefinition> getFieldTypes() {
if (this.fieldTypes == null) {
this.fieldTypes = buildFieldTypes();
}
Expand Down Expand Up @@ -1677,8 +1675,8 @@ public boolean isLobCompatibleWithDistinct() {
* might also be useful to end users attempting to sanitize values.
* <p><b>NOTE</b>: BigInteger &amp; BigDecimal maximums are dependent upon their precision &amp; Scale
*/
public Hashtable maximumNumericValues() {
Hashtable values = new Hashtable();
public Hashtable<Class<? extends Number>, ? super Number> maximumNumericValues() {
Hashtable<Class<? extends Number>, ? super Number> values = new Hashtable<>();

values.put(Integer.class, Integer.MAX_VALUE);
values.put(Long.class, Long.MAX_VALUE);
Expand All @@ -1696,8 +1694,8 @@ public Hashtable maximumNumericValues() {
* might also be useful to end users attempting to sanitize values.
* <p><b>NOTE</b>: BigInteger &amp; BigDecimal minimums are dependent upon their precision &amp; Scale
*/
public Hashtable minimumNumericValues() {
Hashtable values = new Hashtable();
public Hashtable<Class<? extends Number>, ? super Number> minimumNumericValues() {
Hashtable<Class<? extends Number>, ? super Number> values = new Hashtable<>();

values.put(Integer.class, Integer.MIN_VALUE);
values.put(Long.class, Long.MIN_VALUE);
Expand Down Expand Up @@ -1904,7 +1902,7 @@ public void setCastSizeForVarcharParameter(int maxLength){
castSizeForVarcharParameter = maxLength;
}

protected void setClassTypes(Hashtable classTypes) {
protected void setClassTypes(Map<String, Class<?>> classTypes) {
this.classTypes = classTypes;
}

Expand All @@ -1924,7 +1922,7 @@ public void setDriverName(String driverName) {
this.driverName = driverName;
}

protected void setFieldTypes(Hashtable theFieldTypes) {
protected void setFieldTypes(Map<Class<?>, FieldTypeDefinition> theFieldTypes) {
fieldTypes = theFieldTypes;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Vector;

import org.eclipse.persistence.descriptors.DescriptorQueryManager;
import org.eclipse.persistence.exceptions.ConversionException;
Expand Down Expand Up @@ -72,13 +71,13 @@ public class DatasourcePlatform implements Platform {
protected ValueReadQuery timestampQuery;

/** Operators specific to this platform */
protected transient Map platformOperators;
protected transient Map<Integer, ExpressionOperator> platformOperators;

/** Store the list of Classes that can be converted to from the key. */
protected Hashtable dataTypesConvertedFromAClass;
protected Hashtable<Class<?>, List<Class<?>>> dataTypesConvertedFromAClass;

/** Store the list of Classes that can be converted from to the key. */
protected Hashtable dataTypesConvertedToAClass;
protected Hashtable<Class<?>, List<Class<?>>> dataTypesConvertedToAClass;

/** Store default sequence */
protected Sequence defaultSequence;
Expand Down Expand Up @@ -195,11 +194,11 @@ protected void sequencesAfterCloneCleanup() {
setDefaultSequence(defaultSequenceClone);
}
if (getSequences() != null) {
HashMap sequencesCopy = new HashMap(getSequences());
HashMap sequencesDeepClone = new HashMap(getSequences().size());
Iterator it = sequencesCopy.values().iterator();
Map<String, Sequence> sequencesCopy = new HashMap<>(getSequences());
Map<String, Sequence> sequencesDeepClone = new HashMap<>(getSequences().size());
Iterator<Sequence> it = sequencesCopy.values().iterator();
while (it.hasNext()) {
Sequence sequence = (Sequence)it.next();
Sequence sequence = it.next();
if ((defaultSequenceClone != null) && (sequence == getDefaultSequence())) {
sequencesDeepClone.put(defaultSequenceClone.getName(), defaultSequenceClone);
} else {
Expand Down Expand Up @@ -402,7 +401,7 @@ public DataModifyQuery getUpdateSequenceQuery() {
* Initialize any platform-specific operators
*/
protected void initializePlatformOperators() {
this.platformOperators = new HashMap();
this.platformOperators = new HashMap<>();

// Outer join
addOperator(ExpressionOperator.equalOuterJoin());
Expand Down Expand Up @@ -717,7 +716,7 @@ public String toString() {
* @param javaClass - the class that is converted from
* @return - a vector of classes
*/
public List getDataTypesConvertedFrom(Class javaClass) {
public List<Class<?>> getDataTypesConvertedFrom(Class<?> javaClass) {
return getConversionManager().getDataTypesConvertedFrom(javaClass);
}

Expand All @@ -727,7 +726,7 @@ public List getDataTypesConvertedFrom(Class javaClass) {
* @param javaClass - the class that is converted to
* @return - a vector of classes
*/
public List getDataTypesConvertedTo(Class javaClass) {
public List<Class<?>> getDataTypesConvertedTo(Class<?> javaClass) {
return getConversionManager().getDataTypesConvertedTo(javaClass);
}

Expand Down Expand Up @@ -789,18 +788,19 @@ public void addSequence(Sequence sequence, boolean isSessionConnected) {
synchronized(sequencesLock) {
if (isSessionConnected) {
if (this.sequences == null) {
this.sequences = new HashMap();
this.sequences = new HashMap<>();
this.sequences.put(sequence.getName(), sequence);
} else {
if (!this.sequences.containsKey(sequence.getName())) {
Map newSequences = (Map)((HashMap)this.sequences).clone();
@SuppressWarnings({"unchecked"})
Map<String, Sequence> newSequences = (Map<String, Sequence>)((HashMap<String, Sequence>)this.sequences).clone();
newSequences.put(sequence.getName(), sequence);
this.sequences = newSequences;
}
}
} else {
if (this.sequences == null) {
this.sequences = new HashMap();
this.sequences = new HashMap<>();
}
this.sequences.put(sequence.getName(), sequence);
}
Expand Down Expand Up @@ -872,11 +872,11 @@ public Map<String, Sequence> getSequencesToWrite() {
if ((getSequences() == null) || getSequences().isEmpty()) {
return null;
}
Map sequencesCopy = new HashMap(getSequences());
Map sequencesToWrite = new HashMap();
Iterator it = sequencesCopy.values().iterator();
Map<String, Sequence> sequencesCopy = new HashMap<>(getSequences());
Map<String, Sequence> sequencesToWrite = new HashMap<>();
Iterator<Sequence> it = sequencesCopy.values().iterator();
while (it.hasNext()) {
Sequence sequence = (Sequence)it.next();
Sequence sequence = it.next();
if (!(sequence instanceof DefaultSequence) || ((DefaultSequence)sequence).hasPreallocationSize()) {
sequencesToWrite.put(sequence.getName(), sequence);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
import org.eclipse.persistence.sequencing.UnaryTableSequence;
import org.eclipse.persistence.sessions.DatabaseLogin;
import org.eclipse.persistence.sessions.DatasourceLogin;
import org.eclipse.persistence.sessions.ExternalTransactionController;
import org.eclipse.persistence.sessions.JNDIConnector;
import org.eclipse.persistence.sessions.Login;
import org.eclipse.persistence.sessions.Project;
Expand Down Expand Up @@ -735,13 +736,13 @@ protected ConnectionPool buildConnectionPoolConfig(ConnectionPoolConfig poolConf
/**
* INTERNAL:
*/
@SuppressWarnings({"unchecked"})
protected ServerPlatform buildCustomServerPlatformConfig(CustomServerPlatformConfig platformConfig, DatabaseSessionImpl session) {
ServerPlatform platform;

// Server class - XML schema default is org.eclipse.persistence.platform.server.CustomServerPlatform
String serverClassName = platformConfig.getServerClassName();
try {
@SuppressWarnings({"unchecked"})
Class<ServerPlatform> serverClass = (Class<ServerPlatform>) m_classLoader.loadClass(serverClassName);
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){
Constructor<ServerPlatform> constructor = AccessController.doPrivileged(new PrivilegedGetConstructorFor<>(serverClass, new Class[] { org.eclipse.persistence.sessions.DatabaseSession.class }, false));
Expand All @@ -758,7 +759,7 @@ protected ServerPlatform buildCustomServerPlatformConfig(CustomServerPlatformCon
String externalTransactionControllerClass = platformConfig.getExternalTransactionControllerClass();
if (externalTransactionControllerClass != null) {
try {
platform.setExternalTransactionControllerClass(m_classLoader.loadClass(externalTransactionControllerClass));
platform.setExternalTransactionControllerClass((Class<ExternalTransactionController>) m_classLoader.loadClass(externalTransactionControllerClass));
} catch (Exception exception) {
throw SessionLoaderException.failedToLoadTag("external-transaction-controller-class", externalTransactionControllerClass, exception);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -850,9 +850,9 @@ protected void initializeFieldToTransformers(AbstractSession session) throws Des
} else if (field.getColumnDefinition() != null) {
// Search for the type for this field definition.
if (session.getDatasourcePlatform() instanceof DatabasePlatform) {
Iterator<Map.Entry<Class, FieldTypeDefinition>> iterator = session.getPlatform().getFieldTypes().entrySet().iterator();
Iterator<Map.Entry<Class<?>, FieldTypeDefinition>> iterator = session.getPlatform().getFieldTypes().entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<Class, FieldTypeDefinition> entry = iterator.next();
Map.Entry<Class<?>, FieldTypeDefinition> entry = iterator.next();
if (entry.getValue().getName().equals(field.getColumnDefinition())) {
field.setType(entry.getKey());
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,17 @@
* @since TOPLink/Java 1.0
*/
public class AccessPlatform extends org.eclipse.persistence.platform.database.DatabasePlatform {

/**
* Default constructor.
*/
public AccessPlatform() {
super();
}

@Override
protected Map<String, Class> buildClassTypes() {
Map<String, Class> classTypeMapping = super.buildClassTypes();
protected Map<String, Class<?>> buildClassTypes() {
Map<String, Class<?>> classTypeMapping = super.buildClassTypes();

// In access LONG means numeric not CLOB like in Oracle
classTypeMapping.put("LONG", Long.class);
Expand All @@ -42,10 +50,8 @@ protected Map<String, Class> buildClassTypes() {
}

@Override
protected Hashtable buildFieldTypes() {
Hashtable fieldTypeMapping;

fieldTypeMapping = new Hashtable();
protected Hashtable<Class<?>, FieldTypeDefinition> buildFieldTypes() {
Hashtable<Class<?>, FieldTypeDefinition> fieldTypeMapping = new Hashtable<>();
fieldTypeMapping.put(Boolean.class, new FieldTypeDefinition("BIT", false));

fieldTypeMapping.put(Integer.class, new FieldTypeDefinition("LONG", false));
Expand Down Expand Up @@ -121,8 +127,8 @@ public boolean isAccess() {
* <p><b>NOTE</b>: BigInteger {@literal &} BigDecimal maximums are dependent upon their precision {@literal &} Scale
*/
@Override
public Hashtable maximumNumericValues() {
Hashtable values = new Hashtable();
public Hashtable<Class<? extends Number>, ? super Number> maximumNumericValues() {
Hashtable<Class<? extends Number>, ? super Number> values = new Hashtable<>();

values.put(Integer.class, Integer.MAX_VALUE);
values.put(Long.class, Long.MAX_VALUE);
Expand All @@ -141,8 +147,8 @@ public Hashtable maximumNumericValues() {
* <p><b>NOTE</b>: BigInteger {@literal &} BigDecimal minimums are dependent upon their precision {@literal &} Scale
*/
@Override
public Hashtable minimumNumericValues() {
Hashtable values = new Hashtable();
public Hashtable<Class<? extends Number>, ? super Number> minimumNumericValues() {
Hashtable<Class<? extends Number>, ? super Number> values = new Hashtable<>();

values.put(Integer.class, Integer.MIN_VALUE);
values.put(Long.class, Long.MIN_VALUE);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2021 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 @@ -35,10 +35,8 @@ public AttunityPlatform() {
* @return java.util.Hashtable
*/
@Override
protected Hashtable buildFieldTypes() {
Hashtable fieldTypeMapping;

fieldTypeMapping = new Hashtable();
protected Hashtable<Class<?>, FieldTypeDefinition> buildFieldTypes() {
Hashtable<Class<?>, FieldTypeDefinition> fieldTypeMapping = new Hashtable<>();
fieldTypeMapping.put(Boolean.class, new FieldTypeDefinition("TINYINT", false));

fieldTypeMapping.put(Integer.class, new FieldTypeDefinition("NUMERIC", 10));
Expand Down