Skip to content

Commit

Permalink
clean up server platforms
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Jungmann <lukas.jungmann@oracle.com>
  • Loading branch information
lukasj committed Sep 14, 2021
1 parent f79629c commit f3fd372
Show file tree
Hide file tree
Showing 32 changed files with 169 additions and 74 deletions.
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 @@ -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
@@ -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 All @@ -15,7 +15,7 @@
package org.eclipse.persistence.platform.server;

import org.eclipse.persistence.sessions.DatabaseSession;
import org.eclipse.persistence.platform.server.ServerPlatformBase;
import org.eclipse.persistence.sessions.ExternalTransactionController;

/**
* INTERNAL:
Expand Down Expand Up @@ -58,7 +58,7 @@ public CustomServerPlatform(DatabaseSession newDatabaseSession) {
* @see #initializeExternalTransactionController()
*/
@Override
public Class getExternalTransactionControllerClass() {
public Class<? extends ExternalTransactionController> getExternalTransactionControllerClass() {
return externalTransactionControllerClass;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ public MBeanServer getMBeanServer() {
try {
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
try {
mBeanServerList = (List<MBeanServer>) AccessController.doPrivileged(
new PrivilegedExceptionAction() {
mBeanServerList = AccessController.doPrivileged(
new PrivilegedExceptionAction<List<MBeanServer>>() {
@Override
public List<MBeanServer> run() {
return MBeanServerFactory.findMBeanServer(null);
Expand Down Expand Up @@ -322,10 +322,11 @@ public void serverSpecificRegisterMBean() {
args[0] = developmentMBean;
args[1] = name;
try {
@SuppressWarnings({"rawtypes"})
Method getMethod = PrivilegedAccessHelper.getPublicMethod(MBeanServer.class,
"registerMBean", new Class[] {Object.class, ObjectName.class}, false);
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
info = (ObjectInstance) AccessController.doPrivileged(new PrivilegedMethodInvoker(getMethod, mBeanServerRuntime, args));
info = AccessController.doPrivileged(new PrivilegedMethodInvoker<ObjectInstance>(getMethod, mBeanServerRuntime, args));
} else {
info = mBeanServerRuntime.registerMBean(developmentMBean, name);
}
Expand Down Expand Up @@ -354,10 +355,11 @@ public void serverSpecificRegisterMBean() {
Object[] args = new Object[2];
args[0] = runtimeServicesMBean;
args[1] = name;
@SuppressWarnings({"rawtypes"})
Method getMethod = PrivilegedAccessHelper.getPublicMethod(MBeanServer.class,
"registerMBean", new Class[] {Object.class, ObjectName.class}, false);
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
runtimeInstance = (ObjectInstance) AccessController.doPrivileged(new PrivilegedMethodInvoker(getMethod, mBeanServerRuntime, args));
runtimeInstance = AccessController.doPrivileged(new PrivilegedMethodInvoker<ObjectInstance>(getMethod, mBeanServerRuntime, args));
} else {
runtimeInstance = mBeanServerRuntime.registerMBean(runtimeServicesMBean, name);
}
Expand Down Expand Up @@ -406,10 +408,11 @@ public void serverSpecificUnregisterMBean() {
Object[] args = new Object[1];
args[0] = name;
try {
@SuppressWarnings({"rawtypes"})
Method getMethod = PrivilegedAccessHelper.getPublicMethod(MBeanServer.class,
"unregisterMBean", new Class[] {ObjectName.class}, false);
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
AccessController.doPrivileged(new PrivilegedMethodInvoker(getMethod, mBeanServerRuntime, args));
AccessController.doPrivileged(new PrivilegedMethodInvoker<>(getMethod, mBeanServerRuntime, args));
} else {
mBeanServerRuntime.unregisterMBean(name);
}
Expand All @@ -434,10 +437,11 @@ public void serverSpecificUnregisterMBean() {
Object[] args = new Object[1];
args[0] = name;
try {
@SuppressWarnings({"rawtypes"})
Method getMethod = PrivilegedAccessHelper.getPublicMethod(MBeanServer.class,
"unregisterMBean", new Class[] {ObjectName.class}, false);
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
AccessController.doPrivileged(new PrivilegedMethodInvoker(getMethod, mBeanServerRuntime, args));
AccessController.doPrivileged(new PrivilegedMethodInvoker<>(getMethod, mBeanServerRuntime, args));
} else {
mBeanServerRuntime.unregisterMBean(name);
}
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 All @@ -16,6 +16,7 @@

import org.eclipse.persistence.sessions.DatabaseSession;
import org.eclipse.persistence.logging.DefaultSessionLog;
import org.eclipse.persistence.sessions.ExternalTransactionController;

/**
*
Expand Down Expand Up @@ -60,9 +61,10 @@ public String getServerNameAndVersion() {
* @see #isJTAEnabled()
* @see #disableJTA()
* @see #initializeExternalTransactionController()
* @return
*/
@Override
public Class getExternalTransactionControllerClass() {
public Class<? extends ExternalTransactionController> getExternalTransactionControllerClass() {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2018 IBM Corporation. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand All @@ -26,6 +26,12 @@
public class NoServerPlatformDetector implements ServerPlatformDetector {
private static final String SE_CLASSLOADER_STRING = "sun.misc.Launcher$AppClassLoader";

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

@Override
public String checkPlatform() {
String loaderStr;
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 @@ -29,6 +29,7 @@
import org.eclipse.persistence.internal.helper.JPAClassLoaderHolder;
import org.eclipse.persistence.internal.sessions.AbstractSession;
import org.eclipse.persistence.sessions.DatabaseSession;
import org.eclipse.persistence.sessions.ExternalTransactionController;

/**
* PUBLIC:
Expand Down Expand Up @@ -92,7 +93,7 @@ public interface ServerPlatform {
* @see #disableJTA()
* @see #initializeExternalTransactionController()
*/
Class getExternalTransactionControllerClass();
Class<? extends ExternalTransactionController> getExternalTransactionControllerClass();

/**
* INTERNAL: setExternalTransactionControllerClass(Class newClass): Set the class of external
Expand All @@ -103,8 +104,9 @@ public interface ServerPlatform {
* @see #isJTAEnabled()
* @see #disableJTA()
* @see #initializeExternalTransactionController()
* @param newClass
*/
void setExternalTransactionControllerClass(Class newClass);
void setExternalTransactionControllerClass(Class<? extends ExternalTransactionController> newClass);

/**
* INTERNAL: initializeExternalTransactionController(): Populate the DatabaseSession's
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public abstract class ServerPlatformBase implements ServerPlatform {
* externalTransactionControllerClass: This is a user-specifiable class defining the class
* of external transaction controller to be set into the DatabaseSession
*/
protected Class externalTransactionControllerClass;
protected Class<? extends ExternalTransactionController> externalTransactionControllerClass;


/**
Expand Down Expand Up @@ -253,7 +253,7 @@ public String getModuleName() {
* @see #disableJTA()
*/
@Override
public abstract Class getExternalTransactionControllerClass();
public abstract Class<? extends ExternalTransactionController> getExternalTransactionControllerClass();

/**
* INTERNAL: setExternalTransactionControllerClass(Class newClass): Set the class of external
Expand All @@ -264,9 +264,10 @@ public String getModuleName() {
* @see #isJTAEnabled()
* @see #disableJTA()
* @see #initializeExternalTransactionController()
* @param newClass
*/
@Override
public void setExternalTransactionControllerClass(Class newClass) {
public void setExternalTransactionControllerClass(Class<? extends ExternalTransactionController> newClass) {
this.externalTransactionControllerClass = newClass;
}

Expand Down Expand Up @@ -302,7 +303,7 @@ public void initializeExternalTransactionController() {
ExternalTransactionController controller = null;
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){
try {
controller = AccessController.<ExternalTransactionController>doPrivileged(new PrivilegedNewInstanceFromClass<>(this.getExternalTransactionControllerClass()));
controller = AccessController.doPrivileged(new PrivilegedNewInstanceFromClass<>(this.getExternalTransactionControllerClass()));
} catch (PrivilegedActionException exception) {
Exception throwableException = exception.getException();
if (throwableException instanceof InstantiationException) {
Expand All @@ -312,7 +313,7 @@ public void initializeExternalTransactionController() {
}
}
} else {
controller = PrivilegedAccessHelper.<ExternalTransactionController>newInstanceFromClass(this.getExternalTransactionControllerClass());
controller = PrivilegedAccessHelper.newInstanceFromClass(this.getExternalTransactionControllerClass());
}
getDatabaseSession().setExternalTransactionController(controller);
} catch (InstantiationException instantiationException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public static String detectServerPlatform(AbstractSession session) {
*
* @see ServerPlatformBase#ServerPlatformBase(DatabaseSession)
*/
@SuppressWarnings({"rawtypes"})
public static ServerPlatform createServerPlatform(DatabaseSession session, String platformClass, ClassLoader loader) {
if (platformClass == null) {
throw ServerPlatformException.invalidServerPlatformClass(null, null);
Expand All @@ -127,7 +128,7 @@ public static ServerPlatform createServerPlatform(DatabaseSession session, Strin
throw ServerPlatformException.serverPlatformClassNotFound(platformClass, ex);
}
}
final Class[] paramTypes = new Class[] { DatabaseSession.class };
final Class<?>[] paramTypes = (Class<?>[]) new Class[] { DatabaseSession.class };
final Object[] params = new Object[] { session };
ServerPlatform platform = null;
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.eclipse.persistence.platform.server.ServerPlatformBase;
import org.eclipse.persistence.services.glassfish.MBeanGlassfishRuntimeServices;
import org.eclipse.persistence.sessions.DatabaseSession;
import org.eclipse.persistence.sessions.ExternalTransactionController;
import org.eclipse.persistence.transaction.glassfish.GlassfishTransactionController;
import org.eclipse.persistence.transaction.glassfish.GlassfishTransactionController11;

Expand Down Expand Up @@ -92,7 +93,7 @@ public GlassfishPlatform(DatabaseSession newDatabaseSession) {
* @see ServerPlatformBase#initializeExternalTransactionController()
*/
@Override
public Class getExternalTransactionControllerClass() {
public Class<? extends ExternalTransactionController> getExternalTransactionControllerClass() {
if (externalTransactionControllerClass == null) {
// JTA 1.1 exixts since Glassfish 3. Check JTA 1.1 availability to set proper JTa transaction controller.
externalTransactionControllerClass = isJTA11()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 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 All @@ -26,6 +26,12 @@ public final class GlassfishPlatformDetector implements ServerPlatformDetector {

private static final String GF_ROOT_PROP = "com.sun.aas.installRoot";

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

@Override
public String checkPlatform() {
if (isGlassfish()) {
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 @@ -28,6 +28,7 @@
import org.eclipse.persistence.platform.server.JMXServerPlatformBase;
import org.eclipse.persistence.services.jboss.MBeanJBossRuntimeServices;
import org.eclipse.persistence.sessions.DatabaseSession;
import org.eclipse.persistence.sessions.ExternalTransactionController;
import org.eclipse.persistence.transaction.jboss.JBossTransactionController;
import org.eclipse.persistence.transaction.jboss.JBossTransactionController11;

Expand Down Expand Up @@ -89,7 +90,7 @@ public boolean isRuntimeServicesEnabledDefault() {
* @see org.eclipse.persistence.platform.server.ServerPlatformBase#initializeExternalTransactionController()
*/
@Override
public Class getExternalTransactionControllerClass() {
public Class<? extends ExternalTransactionController> getExternalTransactionControllerClass() {
if (externalTransactionControllerClass == null){
externalTransactionControllerClass = isJTA11()
? JBossTransactionController11.class : JBossTransactionController.class;
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 All @@ -15,6 +15,7 @@
package org.eclipse.persistence.platform.server.oc4j;

import org.eclipse.persistence.sessions.DatabaseSession;
import org.eclipse.persistence.sessions.ExternalTransactionController;
import org.eclipse.persistence.transaction.oc4j.Oc4jTransactionController;
import org.eclipse.persistence.platform.database.OraclePlatform;
import org.eclipse.persistence.platform.server.ServerPlatformBase;
Expand Down Expand Up @@ -54,7 +55,7 @@ public Oc4jPlatform(DatabaseSession newDatabaseSession) {
* @see ServerPlatformBase#initializeExternalTransactionController()
*/
@Override
public Class getExternalTransactionControllerClass() {
public Class<? extends ExternalTransactionController> getExternalTransactionControllerClass() {
if (externalTransactionControllerClass == null){
externalTransactionControllerClass = Oc4jTransactionController.class;
}
Expand Down

0 comments on commit f3fd372

Please sign in to comment.