Skip to content

Commit

Permalink
add generics to ValueHolders,
Browse files Browse the repository at this point in the history
related cleanup
cleanup in remote sessions related code

Signed-off-by: Lukas Jungmann <lukas.jungmann@oracle.com>
  • Loading branch information
lukasj committed Sep 23, 2021
1 parent 48f84fe commit 61bbf0c
Show file tree
Hide file tree
Showing 79 changed files with 586 additions and 536 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1014,13 +1014,13 @@ protected void checkDatabase(AbstractSession session) {
if (session.getIntegrityChecker().checkTable(table, session)) {
// To load the fields of database into a vector
List databaseFields = new ArrayList();
List result = session.getAccessor().getColumnInfo(null, null, table.getName(), null, session);
List<AbstractRecord> result = session.getAccessor().getColumnInfo(null, null, table.getName(), null, session);
// Table name may need to be lowercase.
if (result.isEmpty() && session.getPlatform().shouldForceFieldNamesToUpperCase()) {
result = session.getAccessor().getColumnInfo(null, null, table.getName().toLowerCase(), null, session);
}
for (Iterator resultIterator = result.iterator(); resultIterator.hasNext();) {
AbstractRecord row = (AbstractRecord)resultIterator.next();
for (Iterator<AbstractRecord> resultIterator = result.iterator(); resultIterator.hasNext();) {
AbstractRecord row = resultIterator.next();
if (session.getPlatform().shouldForceFieldNamesToUpperCase()) {
databaseFields.add(((String)row.get("COLUMN_NAME")).toUpperCase());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@ public void addTypes(boolean createMissingTables, boolean generateFKConstraints,
*/
public static class SessionCustomizer implements org.eclipse.persistence.config.SessionCustomizer {

/**
* Default constructor.
*/
public SessionCustomizer() {
}

@Override
public void customize(Session session) throws Exception {
DynamicClassLoader dcl = DynamicClassLoader.lookup(session);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public Vector<DatabaseField> getFields() {
*/
@Override
public Vector getValues() {
return new Vector(getRecord().values());
return new Vector<>(getRecord().values());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
public class IntegrityChecker implements Serializable {

/** To add all the Descriptor exceptions */
protected Vector caughtExceptions = null;
protected Vector<Exception> caughtExceptions = null;

/** To load the tables from database */
protected Vector tables = null;
Expand Down Expand Up @@ -124,9 +124,9 @@ public void dontCheckInstantiationPolicy() {
* PUBLIC:
* This method returns the vector which adds all the Descriptors Exceptions.
*/
public Vector getCaughtExceptions() {
public Vector<Exception> getCaughtExceptions() {
if (caughtExceptions == null) {
caughtExceptions = new Vector();
caughtExceptions = new Vector<>();
}
return caughtExceptions;
}
Expand Down Expand Up @@ -171,7 +171,7 @@ public boolean hasErrors() {
*/
public boolean hasRuntimeExceptions() {
if (hasErrors()) {
for (Enumeration exceptionsEnum = getCaughtExceptions().elements();
for (Enumeration<Exception> exceptionsEnum = getCaughtExceptions().elements();
exceptionsEnum.hasMoreElements();) {
if (exceptionsEnum.nextElement() instanceof RuntimeException) {
return true;
Expand All @@ -186,9 +186,9 @@ public boolean hasRuntimeExceptions() {
* This method is used to get all the database tables and add them into a vector.
*/
public void initializeTables(AbstractSession session) {
List result = session.getAccessor().getTableInfo(null, null, null, null, session);
for (Iterator iterator = result.iterator(); iterator.hasNext();) {
AbstractRecord row = (AbstractRecord)iterator.next();
List<AbstractRecord> result = session.getAccessor().getTableInfo(null, null, null, null, session);
for (Iterator<AbstractRecord> iterator = result.iterator(); iterator.hasNext();) {
AbstractRecord row = iterator.next();
if (session.getPlatform().shouldForceFieldNamesToUpperCase()) {
this.tables.add(((String)row.get("TABLE_NAME")).toUpperCase());
} else {
Expand All @@ -200,7 +200,7 @@ public void initializeTables(AbstractSession session) {
/**
* INTERNAL:
*/
public void setCaughtExceptions(Vector exceptions) {
public void setCaughtExceptions(Vector<Exception> exceptions) {
this.caughtExceptions = exceptions;
}

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 @@ -61,9 +61,9 @@ public String getMessage() {
java.io.PrintWriter writer = new java.io.PrintWriter(swriter);
writer.println(cr + ExceptionMessageGenerator.getHeader("DescriptorExceptionsHeader"));
writer.println("---------------------------------------------------------");
for (Enumeration enumtr = getIntegrityChecker().getCaughtExceptions().elements();
for (Enumeration<Exception> enumtr = getIntegrityChecker().getCaughtExceptions().elements();
enumtr.hasMoreElements();) {
Exception e = (Exception)enumtr.nextElement();
Exception e = enumtr.nextElement();
if (e instanceof DescriptorException) {
writer.println(cr + e);
}
Expand All @@ -72,9 +72,9 @@ public String getMessage() {
if (getIntegrityChecker().hasRuntimeExceptions()) {
writer.println(cr + ExceptionMessageGenerator.getHeader("RuntimeExceptionsHeader"));
writer.println("---------------------------------------------------------");
for (Enumeration enumtr = getIntegrityChecker().getCaughtExceptions().elements();
for (Enumeration<Exception> enumtr = getIntegrityChecker().getCaughtExceptions().elements();
enumtr.hasMoreElements();) {
Exception e = (Exception)enumtr.nextElement();
Exception e = enumtr.nextElement();
if (!(e instanceof DescriptorException)) {
writer.println(cr + e);
}
Expand Down Expand Up @@ -114,9 +114,9 @@ public void printStackTrace(PrintWriter writer) {
String cr = org.eclipse.persistence.internal.helper.Helper.cr();
writer.println(cr + ExceptionMessageGenerator.getHeader("DescriptorExceptionsHeader"));
writer.println("---------------------------------------------------------");
for (Enumeration enumtr = getIntegrityChecker().getCaughtExceptions().elements();
for (Enumeration<Exception> enumtr = getIntegrityChecker().getCaughtExceptions().elements();
enumtr.hasMoreElements();) {
Exception e = (Exception)enumtr.nextElement();
Exception e = enumtr.nextElement();
if (e instanceof DescriptorException) {
writer.println(cr);
e.printStackTrace(writer);
Expand All @@ -126,9 +126,9 @@ public void printStackTrace(PrintWriter writer) {
if (getIntegrityChecker().hasRuntimeExceptions()) {
writer.println(cr + ExceptionMessageGenerator.getHeader("RuntimeExceptionsHeader"));
writer.println("---------------------------------------------------------");
for (Enumeration enumtr = getIntegrityChecker().getCaughtExceptions().elements();
for (Enumeration<Exception> enumtr = getIntegrityChecker().getCaughtExceptions().elements();
enumtr.hasMoreElements();) {
Exception e = (Exception)enumtr.nextElement();
Exception e = enumtr.nextElement();
if (!(e instanceof DescriptorException)) {
writer.println(cr);
e.printStackTrace(writer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ protected Set<E> cloneDelegate() {
try {
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){
try {
return (Set<E>)AccessController.doPrivileged(new PrivilegedMethodInvoker(cloneMethod, this.getDelegate(), null));
return AccessController.doPrivileged(new PrivilegedMethodInvoker<>(cloneMethod, this.getDelegate(), null));
} catch (PrivilegedActionException exception) {
Exception throwableException = exception.getException();
if (throwableException instanceof IllegalAccessException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public interface CoreField {
*/
String getName();

<T> Class<T> getType();
Class<?> getType();

/**
* Set the unqualified name of the field.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2019 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 @@ -125,7 +125,7 @@ public interface Accessor extends Cloneable {
* Return the column metadata for the specified
* selection criteria.
*/
Vector getColumnInfo(String catalog, String schema, String tableName, String columnName, AbstractSession session) throws DatabaseException;
Vector<AbstractRecord> getColumnInfo(String catalog, String schema, String tableName, String columnName, AbstractSession session) throws DatabaseException;

/**
* Return the JDBC connection for relational accessors.
Expand All @@ -148,7 +148,7 @@ public interface Accessor extends Cloneable {
* Return the table metadata for the specified
* selection criteria.
*/
Vector getTableInfo(String catalog, String schema, String tableName, String[] types, AbstractSession session) throws DatabaseException;
Vector<AbstractRecord> getTableInfo(String catalog, String schema, String tableName, String[] types, AbstractSession session) throws DatabaseException;

/**
* Increment the number of calls in progress.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ public Object convert(Object parameter, DatabaseField dbField, AbstractSession s
return parameter;
}

Collection container = (Collection)parameter;
Collection<?> container = (Collection<?>)parameter;

DatabaseField nestedType = ordField.getNestedTypeField();

Object[] fields = new Object[container.size()];
int i = 0;
for (Iterator iter = container.iterator(); iter.hasNext();) {
for (Iterator<?> iter = container.iterator(); iter.hasNext();) {
Object element = iter.next();
if (element != null) {
element = convert(element, nestedType, session, connection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ public Object processResultSet(ResultSet resultSet, DatabaseCall call, Statement
}
} else {
boolean hasMultipleResultsSets = call.hasMultipleResultSets();
Vector results = null;
Vector<AbstractRecord> results = null;
boolean hasMoreResultsSets = true;
while (hasMoreResultsSets) {
boolean hasNext = resultSet.next();
Expand All @@ -770,14 +770,14 @@ public Object processResultSet(ResultSet resultSet, DatabaseCall call, Statement
// do not close the result or statement as the rows are being fetched by the thread.
return buildThreadCursoredResult(call, resultSet, statement, metaData, session);
} else {
results = new Vector(16);
results = new Vector<>(16);
while (hasNext) {
results.add(fetchRow(call.getFields(), call.getFieldsArray(), resultSet, metaData, session));
hasNext = resultSet.next();
}
}
} else {
results = new Vector(0);
results = new Vector<>(0);
}
if (result == null) {
if (call.returnMultipleResultSetCollections()) {
Expand Down Expand Up @@ -817,7 +817,7 @@ public Object processResultSet(ResultSet resultSet, DatabaseCall call, Statement
* This allows for the rows to be fetched concurrently to the objects being built.
* This code is not currently publicly supported.
*/
protected Vector buildThreadCursoredResult(final DatabaseCall dbCall, final ResultSet resultSet, final Statement statement, final ResultSetMetaData metaData, final AbstractSession session) {
protected Vector<AbstractRecord> buildThreadCursoredResult(final DatabaseCall dbCall, final ResultSet resultSet, final Statement statement, final ResultSetMetaData metaData, final AbstractSession session) {
final ThreadCursoredList<AbstractRecord> results = new ThreadCursoredList<>(20);
Runnable runnable = new Runnable() {
@Override
Expand Down Expand Up @@ -1042,7 +1042,7 @@ public ResultSet executeSelect(DatabaseCall call, Statement statement, AbstractS
*/
protected AbstractRecord fetchRow(Vector<DatabaseField> fields, ResultSet resultSet, ResultSetMetaData metaData, AbstractSession session) throws DatabaseException {
int size = fields.size();
Vector values = NonSynchronizedVector.newInstance(size);
Vector<Object> values = NonSynchronizedVector.newInstance(size);
// PERF: Pass platform and optimize data flag.
DatabasePlatform platform = getPlatform();
boolean optimizeData = platform.shouldOptimizeDataConversion();
Expand Down Expand Up @@ -1070,7 +1070,7 @@ protected AbstractRecord fetchRow(Vector<DatabaseField> fields, ResultSet result
* match the number of column names available on the database.
* PERF: This method must be highly optimized.
*/
public AbstractRecord fetchRow(Vector fields, DatabaseField[] fieldsArray, ResultSet resultSet, ResultSetMetaData metaData, AbstractSession session) throws DatabaseException {
public AbstractRecord fetchRow(Vector<DatabaseField> fields, DatabaseField[] fieldsArray, ResultSet resultSet, ResultSetMetaData metaData, AbstractSession session) throws DatabaseException {
int size = fieldsArray.length;
Object[] values = new Object[size];
// PERF: Pass platform and optimize data flag.
Expand Down Expand Up @@ -1168,17 +1168,17 @@ public BatchWritingMechanism getActiveBatchWritingMechanism(AbstractSession sess
* @return a Vector of DatabaseRows.
*/
@Override
public Vector getColumnInfo(String catalog, String schema, String tableName, String columnName, AbstractSession session) throws DatabaseException {
public Vector<AbstractRecord> getColumnInfo(String catalog, String schema, String tableName, String columnName, AbstractSession session) throws DatabaseException {
if (session.shouldLog(SessionLog.FINEST, SessionLog.QUERY)) {// Avoid printing if no logging required.
Object[] args = { catalog, schema, tableName, columnName };
session.log(SessionLog.FINEST, SessionLog.QUERY, "query_column_meta_data_with_column", args, this);
}
Vector result = new Vector();
Vector<AbstractRecord> result = new Vector<>();
ResultSet resultSet = null;
try {
incrementCallCount(session);
resultSet = getConnectionMetaData().getColumns(catalog, schema, tableName, columnName);
Vector fields = buildSortedFields(null, resultSet, session);
Vector<DatabaseField> fields = buildSortedFields(null, resultSet, session);
ResultSetMetaData metaData = resultSet.getMetaData();

while (resultSet.next()) {
Expand Down Expand Up @@ -1346,7 +1346,7 @@ public Object getObject(ResultSet resultSet, DatabaseField field, ResultSetMetaD
*/
protected Object getObjectThroughOptimizedDataConversion(ResultSet resultSet, DatabaseField field, int type, int columnNumber, DatabasePlatform platform, AbstractSession session) throws SQLException {
Object value = this;// Means no optimization, need to distinguish from null.
Class fieldType = field.type;
Class<?> fieldType = field.type;

if (platform.shouldUseGetSetNString() && (type == Types.NVARCHAR || type == Types.NCHAR)) {
value = resultSet.getNString(columnNumber);
Expand Down Expand Up @@ -1485,12 +1485,12 @@ protected synchronized Map<String, Statement> getStatementCache() {
* @return a Vector of DatabaseRows.
*/
@Override
public Vector getTableInfo(String catalog, String schema, String tableName, String[] types, AbstractSession session) throws DatabaseException {
public Vector<AbstractRecord> getTableInfo(String catalog, String schema, String tableName, String[] types, AbstractSession session) throws DatabaseException {
if (session.shouldLog(SessionLog.FINEST, SessionLog.QUERY)) {// Avoid printing if no logging required.
Object[] args = { catalog, schema, tableName };
session.log(SessionLog.FINEST, SessionLog.QUERY, "query_column_meta_data", args, this);
}
Vector result = new Vector();
Vector<AbstractRecord> result = new Vector<>();
ResultSet resultSet = null;
try {
incrementCallCount(session);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public abstract class DatabaseCall extends DatasourceCall {
protected Boolean shouldCacheStatement;

// The returned fields.
transient protected Vector fields;
transient protected Vector<DatabaseField> fields;
// PERF: fields array
transient protected DatabaseField[] fieldsArray;

Expand Down Expand Up @@ -384,7 +384,7 @@ public String getCallString() {
* The fields expected by the calls result set.
* null means that the fields are unknown and should be built from the result set.
*/
public Vector getFields() {
public Vector<DatabaseField> getFields() {
return fields;
}

Expand Down Expand Up @@ -856,13 +856,13 @@ public boolean returnMultipleResultSetCollections() {
/**
* The fields expected by the calls result set.
*/
public void setFields(Vector fields) {
public void setFields(Vector<DatabaseField> fields) {
this.fields = fields;
if (fields != null) {
int size = fields.size();
this.fieldsArray = new DatabaseField[size];
for (int index = 0; index < size; index++) {
this.fieldsArray[index] = (DatabaseField)fields.get(index);
this.fieldsArray[index] = fields.get(index);
}
} else {
this.fieldsArray = null;
Expand Down

0 comments on commit 61bbf0c

Please sign in to comment.