Skip to content

Commit

Permalink
HHH-12763 - Log which JtaPlatform implementation is used at startup o…
Browse files Browse the repository at this point in the history
…n info level
  • Loading branch information
aepedraza authored and gsmet committed Jul 23, 2018
1 parent 5164d8b commit b94b126
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public JtaPlatform initiateService(Map configurationValues, ServiceRegistryImple
platform = getFallbackProvider( configurationValues, registry );
}

LOG.usingJtaPlatform( platform != null ? platform.getClass().getName() : "null" );
return platform;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ public interface JtaPlatform extends Service {
*
* @return The {@link TransactionManager}
*/
public TransactionManager retrieveTransactionManager();
TransactionManager retrieveTransactionManager();

/**
* Locate the {@link UserTransaction}
*
* @return The {@link UserTransaction}
*/
public UserTransaction retrieveUserTransaction();
UserTransaction retrieveUserTransaction();

/**
* Determine an identifier for the given transaction appropriate for use in caching/lookup usages.
Expand All @@ -44,21 +44,21 @@ public interface JtaPlatform extends Service {
* @param transaction The transaction to be identified.
* @return An appropriate identifier
*/
public Object getTransactionIdentifier(Transaction transaction);
Object getTransactionIdentifier(Transaction transaction);

/**
* Can we currently register a {@link Synchronization}?
*
* @return True if registering a {@link Synchronization} is currently allowed; false otherwise.
*/
public boolean canRegisterSynchronization();
boolean canRegisterSynchronization();

/**
* Register a JTA {@link Synchronization} in the means defined by the platform.
*
* @param synchronization The synchronization to register
*/
public void registerSynchronization(Synchronization synchronization);
void registerSynchronization(Synchronization synchronization);

/**
* Obtain the current transaction status using whatever means is preferred for this platform
Expand All @@ -67,5 +67,5 @@ public interface JtaPlatform extends Service {
*
* @throws SystemException Indicates a problem access the underlying status
*/
public int getCurrentStatus() throws SystemException;
int getCurrentStatus() throws SystemException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -1814,4 +1814,8 @@ void attemptToAssociateProxyWithTwoOpenSessions(
@LogMessage(level = WARN)
@Message(value = "Setting " + AvailableSettings.NATIVE_EXCEPTION_HANDLING_51_COMPLIANCE + "=true is not valid with JPA bootstrapping; setting will be ignored.", id = 489 )
void nativeExceptionHandling51ComplianceJpaBootstrapping();

@LogMessage(level = INFO)
@Message(value = "Using JtaPlatform implementation: [%s]", id = 490)
void usingJtaPlatform(String jtaPlatformClassName);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.tool.schema;

import java.util.HashMap;
import java.util.Map;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

import org.hibernate.SessionFactory;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.model.process.internal.ScanningCoordinator;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Environment;
import org.hibernate.engine.transaction.jta.platform.internal.JtaPlatformInitiator;
import org.hibernate.internal.CoreMessageLogger;

import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.jta.TestingJtaBootstrap;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.hibernate.testing.logger.LoggerInspectionRule;
import org.hibernate.testing.logger.Triggerable;
import org.hibernate.test.resource.transaction.jta.JtaPlatformStandardTestingImpl;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

import org.jboss.logging.Logger;

import static org.junit.Assert.assertEquals;

/**
* @author Vlad Mihalcea
*/
@TestForIssue( jiraKey = "HHH-12763" )
public class JtaPlatformLoggingTest extends BaseNonConfigCoreFunctionalTestCase {

@Rule
public LoggerInspectionRule logInspection = new LoggerInspectionRule(
Logger.getMessageLogger( CoreMessageLogger.class, JtaPlatformInitiator.class.getName() ) );

private Triggerable triggerable = logInspection.watchForLogMessages( "HHH000490" );

@Override
protected void addSettings(Map settings) {
TestingJtaBootstrap.prepare( settings );
settings.put( AvailableSettings.TRANSACTION_COORDINATOR_STRATEGY, "jta" );
}

@Test
public void test() {
assertEquals(
"HHH000490: Using JtaPlatform implementation: [org.hibernate.testing.jta.TestingJtaPlatformImpl]",
triggerable.triggerMessage()
);
}

@Override
protected Class[] getAnnotatedClasses() {
return new Class[] {
TestEntity.class
};
}

@Entity( name = "TestEntity" )
@Table( name = "TestEntity" )
public static class TestEntity {
@Id
public Integer id;
String name;
}
}

0 comments on commit b94b126

Please sign in to comment.