Skip to content

Commit

Permalink
Apply new language features
Browse files Browse the repository at this point in the history
* enhanced switch
* Objects.equals, String.isEmpty, String.contains etc

Signed-off-by: Lukas Jungmann <lukas.jungmann@oracle.com>
  • Loading branch information
lukasj committed Jan 30, 2024
1 parent 5cb364c commit 6c49784
Show file tree
Hide file tree
Showing 484 changed files with 3,419 additions and 4,113 deletions.
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 @@ -43,6 +43,7 @@
requires static jakarta.messaging;
requires static jakarta.resource;

requires static org.objectweb.asm;
requires static com.sun.xml.bind.core;

exports org.eclipse.persistence.jpa.jpql;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ public SOAPMessage invoke(SOAPMessage request) {
try {
XMLContext xmlContext = dbwsAdapter.getXMLContext();
XMLUnmarshaller unmarshaller = xmlContext.createUnmarshaller();
if (attachments != null && attachments.size() > 0) {
if (attachments != null && !attachments.isEmpty()) {
unmarshaller.setAttachmentUnmarshaller(new XMLAttachmentUnmarshaller() {
Map<String,DataHandler> attachments;
public XMLAttachmentUnmarshaller setAttachments(Map<String, DataHandler> attachments) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2024 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -40,7 +40,7 @@ public class SOAPAttachmentHandler implements XMLAttachmentMarshaller {
private HashMap<String, DataHandler> attachments = new HashMap<>();

public boolean hasAttachments() {
return attachments.size() > 0;
return !attachments.isEmpty();
}

public Map<String, DataHandler> getAttachments() {
Expand All @@ -67,15 +67,15 @@ public String addSwaRefAttachment(byte[] data, int start, int length) {

@Override
public String addMtomAttachment(DataHandler data, String elementName, String namespace) {
String name = "cid:" + randomUUID().toString();
String name = "cid:" + randomUUID();
attachments.put(name, data);
return name;
}

@Override
public String addMtomAttachment(byte[] data, int start, int len, String mimeType,
String elementName, String namespace) {
String name = "cid:" + randomUUID().toString();
String name = "cid:" + randomUUID();
DataHandler dataHandler = new DataHandler(new ByteArrayDataSource(data,
"application/octet-stream"));
attachments.put(name, dataHandler);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2024 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -114,7 +114,7 @@ public Object invoke(XRServiceAdapter xrService, Invocation invocation) {
Object toBeDeleted;

// a query created via ORM metadata processing does not have parameters set, however, the operation should
if (query.getArguments().size() == 0) {
if (query.getArguments().isEmpty()) {
int idx = 0;
for (Parameter param : getParameters()) {
// for custom SQL query (as configured via ORM metadata processing) we add args by position
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2024 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -62,8 +62,6 @@
import static org.eclipse.persistence.internal.oxm.Constants.UNSIGNED_SHORT;
import static org.eclipse.persistence.internal.oxm.Constants.UNSIGNED_SHORT_QNAME;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

//java eXtension imports
Expand All @@ -83,32 +81,29 @@ public class QNameTransformer implements AttributeTransformer, FieldTransformer

public static final Map<String, QName> SCHEMA_QNAMES;
static {
SCHEMA_QNAMES = Collections.unmodifiableMap(new HashMap<>() {
{
put(ANY, ANY_QNAME);
put(ANY_SIMPLE_TYPE, ANY_SIMPLE_TYPE_QNAME);
put(BASE_64_BINARY, BASE_64_BINARY_QNAME);
put(BOOLEAN, BOOLEAN_QNAME);
put(BYTE, BYTE_QNAME);
put(DATE, DATE_QNAME);
put(DATE_TIME, DATE_TIME_QNAME);
put(DECIMAL, DECIMAL_QNAME);
put(DOUBLE, DOUBLE_QNAME);
put(FLOAT, FLOAT_QNAME);
put(HEX_BINARY, HEX_BINARY_QNAME);
put(INT, INT_QNAME);
put(INTEGER, INTEGER_QNAME);
put(LONG, LONG_QNAME);
put(QNAME, QNAME_QNAME);
put(SHORT, SHORT_QNAME);
put(STRING, STRING_QNAME);
put(TIME, TIME_QNAME);
put(UNSIGNED_BYTE, UNSIGNED_BYTE_QNAME);
put(UNSIGNED_INT, UNSIGNED_INT_QNAME);
put(UNSIGNED_SHORT, UNSIGNED_SHORT_QNAME);
put(SWA_REF, SWA_REF_QNAME);
}
});
SCHEMA_QNAMES = Map.ofEntries(
Map.entry(ANY, ANY_QNAME),
Map.entry(ANY_SIMPLE_TYPE, ANY_SIMPLE_TYPE_QNAME),
Map.entry(BASE_64_BINARY, BASE_64_BINARY_QNAME),
Map.entry(BOOLEAN, BOOLEAN_QNAME),
Map.entry(BYTE, BYTE_QNAME),
Map.entry(DATE, DATE_QNAME),
Map.entry(DATE_TIME, DATE_TIME_QNAME),
Map.entry(DECIMAL, DECIMAL_QNAME),
Map.entry(DOUBLE, DOUBLE_QNAME),
Map.entry(FLOAT, FLOAT_QNAME),
Map.entry(HEX_BINARY, HEX_BINARY_QNAME),
Map.entry(INT, INT_QNAME),
Map.entry(INTEGER, INTEGER_QNAME),
Map.entry(LONG, LONG_QNAME),
Map.entry(QNAME, QNAME_QNAME),
Map.entry(SHORT, SHORT_QNAME),
Map.entry(STRING, STRING_QNAME),
Map.entry(TIME, TIME_QNAME),
Map.entry(UNSIGNED_BYTE, UNSIGNED_BYTE_QNAME),
Map.entry(UNSIGNED_INT, UNSIGNED_INT_QNAME),
Map.entry(UNSIGNED_SHORT, UNSIGNED_SHORT_QNAME),
Map.entry(SWA_REF, SWA_REF_QNAME));
}
private static final char COLON = ':';
private static final String DEFAULT_NAMESPACE_PREFIX = "";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2024 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -147,7 +147,7 @@ public void initializeArguments(XRServiceAdapter xrService, QueryOperation query
if (o instanceof Parameter) {
Parameter p = o;
String name = p.getName();
if (name != null && name.length() > 0 ) {
if (name != null && !name.isEmpty()) {
databaseQuery.addArgument(name);
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ public Object invoke(XRServiceAdapter xrService, Invocation invocation) {
// a named query created via ORM metadata processing does not have
// parameters set, however, the operation should
List<Object> argVals = new ArrayList<>();
if (query.getArguments().size() == 0) {
if (query.getArguments().isEmpty()) {
int idx = 0;
for (Parameter param : getParameters()) {
// for custom SQL query (as configured via ORM metadata
Expand Down Expand Up @@ -414,7 +414,7 @@ public Object invoke(XRServiceAdapter xrService, Invocation invocation) {
// JPA spec returns an ArrayList<Object[]> for stored procedure queries - will need to unwrap.
// Note that for legacy deployment XML projects this is not the case.
if (value instanceof ArrayList<?> returnedList) {
if (returnedList.size() > 0 && returnedList.get(0) instanceof Object[] objs) {
if (!returnedList.isEmpty() && returnedList.get(0) instanceof Object[] objs) {
if (isCollection()) {
value = new ArrayList<>();
for (Object obj : objs) {
Expand Down Expand Up @@ -480,7 +480,7 @@ public Object invoke(XRServiceAdapter xrService, Invocation invocation) {
}
} else if (isCollection() && value instanceof Vector) {
// could be a collection of populated objects, in which case we just return it
if (((Vector<?>) value).size() > 0 && !(((Vector<?>) value).get(0) instanceof AbstractRecord)) {
if (!((Vector<?>) value).isEmpty() && !(((Vector<?>) value).get(0) instanceof AbstractRecord)) {
return value;
}
XRDynamicEntity_CollectionWrapper xrCollWrapper = new XRDynamicEntity_CollectionWrapper();
Expand Down Expand Up @@ -562,7 +562,7 @@ public Object createSimpleXMLFormat(XRServiceAdapter xrService, Object value) {
}
// now create a record using DatabaseField/value pairs
DatabaseRecord dr = new DatabaseRecord();
if (paramFlds.size() > 0) {
if (!paramFlds.isEmpty()) {
for (int i=0; i < ((ArrayList<?>) value).size(); i++) {
dr.add(paramFlds.get(i), ((ArrayList<?>) value).get(i));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void initializeDatabaseQuery(XRServiceAdapter xrService, QueryOperation q
}
}
else {
if (getOutArguments().size() == 0 && getInOutArguments().size() == 0) {
if (getOutArguments().isEmpty() && getInOutArguments().isEmpty()) {
if (isStoredFunctionQueryHandler()) {
if (!xrService.descriptorsByQName.containsKey(type)) {
databaseQueryToInitialize = new ValueReadQuery();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2024 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -254,44 +254,26 @@ public static String xmlToSqlName(String name) {
public static String hexEscape(char c) {
String outPutString;
outPutString = Integer.toHexString(c);
switch (outPutString.length()) {
case 1:
outPutString = "_x000" + outPutString.toUpperCase(Locale.US) + "_";
break;
case 2:
outPutString = "_x00" + outPutString.toUpperCase(Locale.US) + "_";
break;
case 3:
outPutString = "_x0" + outPutString.toUpperCase(Locale.US) + "_";
break;
case 4:
outPutString = "_x" + outPutString.toUpperCase(Locale.US) + "_";
break;
}
outPutString = switch (outPutString.length()) {
case 1 -> "_x000" + outPutString.toUpperCase(Locale.US) + "_";
case 2 -> "_x00" + outPutString.toUpperCase(Locale.US) + "_";
case 3 -> "_x0" + outPutString.toUpperCase(Locale.US) + "_";
case 4 -> "_x" + outPutString.toUpperCase(Locale.US) + "_";
default -> outPutString;
};
return outPutString;
}

public static String hexEscape(int c) {
String outPutString;
outPutString = Integer.toHexString(c);
switch (outPutString.length()) {
case 1:
case 5:
outPutString = "_x000" + outPutString.toUpperCase(Locale.US) + "_";
break;
case 2:
case 6:
outPutString = "_x00" + outPutString.toUpperCase(Locale.US) + "_";
break;
case 3:
case 7:
outPutString = "_x0" + outPutString.toUpperCase(Locale.US) + "_";
break;
case 4:
case 8:
outPutString = "_x" + outPutString.toUpperCase(Locale.US) + "_";
break;
}
outPutString = switch (outPutString.length()) {
case 1, 5 -> "_x000" + outPutString.toUpperCase(Locale.US) + "_";
case 2, 6 -> "_x00" + outPutString.toUpperCase(Locale.US) + "_";
case 3, 7 -> "_x0" + outPutString.toUpperCase(Locale.US) + "_";
case 4, 8 -> "_x" + outPutString.toUpperCase(Locale.US) + "_";
default -> outPutString;
};
return outPutString;
}

Expand Down Expand Up @@ -436,7 +418,7 @@ public static Class<?> getClassFromJDBCType(String typeName, DatabasePlatform da

public static final Map<QName, Class<?>> SCHEMA_2_CLASS;
static {
SCHEMA_2_CLASS = Collections.unmodifiableMap(new HashMap<QName, Class<?>>() {{
SCHEMA_2_CLASS = Collections.unmodifiableMap(new HashMap<>() {{
put(ANY_SIMPLE_TYPE_QNAME, CoreClassConstants.OBJECT);
put(BASE_64_BINARY_QNAME, APBYTE);
put(BOOLEAN_QNAME, BOOLEAN);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2024 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -46,12 +46,9 @@ protected Class<?> findClass(String className) throws ClassNotFoundException {
byte[] data = defaultWriter.writeClass(this, className);
return defineClass(className, data, 0, data.length);
}
catch (ClassFormatError cfe) {
catch (ClassFormatError | ClassCircularityError cfe) {
throw new ClassNotFoundException(className, cfe);
}
catch (ClassCircularityError cce) {
throw new ClassNotFoundException(className, cce);
}
}

public void dontGenerateSubclasses() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2024 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -51,7 +51,7 @@ public boolean add(Object e) {

@Override
@SuppressWarnings("unchecked")
public boolean addAll(Collection<? extends Object> c) {
public boolean addAll(Collection<?> c) {
return ((Collection<Object>)propertiesMap.get(ITEMS_PROPERTY).getValue()).addAll(c);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2024 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -463,7 +463,7 @@ public void buildSessions() {
// at this point we may have a legacy deployment XML project, or none set
oxProject = xrService.oxSession.getProject();
// check to see if it's a default Project
if (oxProject.getName().length() == 0) {
if (oxProject.getName().isEmpty()) {
// default to SimpleXMLFormat
oxProject = new SimpleXMLFormatProject();
}
Expand Down

0 comments on commit 6c49784

Please sign in to comment.