mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-23 12:19:09 +00:00
Use slf4j for logging and tidy up dependencies.
This commit is contained in:
@@ -37,10 +37,9 @@
|
||||
</scm>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>jcl-over-slf4j</artifactId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>[1.7,)</version>
|
||||
</dependency>
|
||||
|
||||
@@ -74,25 +73,6 @@
|
||||
<artifactId>spring-context</artifactId>
|
||||
<version>${spring.framework.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-core</artifactId>
|
||||
<version>${spring.framework.version}</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-aspects</artifactId>
|
||||
<version>${spring.framework.version}</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>commons-logging</groupId>
|
||||
@@ -135,6 +115,12 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>jcl-over-slf4j</artifactId>
|
||||
<version>[1.7,)</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
@@ -170,7 +156,7 @@
|
||||
</plugins>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<!--This plugin's configuration is used to store Eclipse m2e settings
|
||||
<!--This plugin's configuration is used to store Eclipse m2e settings
|
||||
only. It has no influence on the Maven build itself. -->
|
||||
<plugin>
|
||||
<groupId>org.eclipse.m2e</groupId>
|
||||
@@ -230,7 +216,7 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
|
||||
@@ -7,7 +7,7 @@ import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
/**
|
||||
* To Setup Enhancement in Spring
|
||||
* <bean class="org.ebean.AgentLoaderSupport">
|
||||
* <bean class="com.avaje.ebean.springsupport.AgentLoaderSupport">
|
||||
* <property name="debug" value="1" />
|
||||
* <property name="packages" value="org.ebean.**" />
|
||||
* </bean>
|
||||
|
||||
+11
-22
@@ -20,22 +20,21 @@
|
||||
package com.avaje.ebean.springsupport.txn;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.persistence.PersistenceException;
|
||||
import javax.sql.DataSource;
|
||||
import com.avaje.ebean.config.ExternalTransactionManager;
|
||||
import com.avaje.ebeaninternal.api.SpiTransaction;
|
||||
import com.avaje.ebeaninternal.server.transaction.DefaultTransactionThreadLocal;
|
||||
import com.avaje.ebeaninternal.server.transaction.TransactionManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.jdbc.datasource.ConnectionHolder;
|
||||
import org.springframework.transaction.support.TransactionSynchronization;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationAdapter;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
|
||||
/**
|
||||
* A Spring aware TransactionScopeManager.
|
||||
*
|
||||
* A Spring-aware {@link ExternalTransactionManager}.
|
||||
* <p>
|
||||
* Will look for Spring transactions and use them if they exist.
|
||||
* </p>
|
||||
@@ -45,7 +44,7 @@ import org.springframework.transaction.support.TransactionSynchronizationManager
|
||||
*/
|
||||
public class SpringAwareJdbcTransactionManager implements ExternalTransactionManager {
|
||||
|
||||
private final static Logger logger = Logger.getLogger(SpringAwareJdbcTransactionManager.class.getName());
|
||||
private static final Logger log = LoggerFactory.getLogger(SpringAwareJdbcTransactionManager.class);
|
||||
|
||||
/**
|
||||
* The data source.
|
||||
@@ -97,23 +96,18 @@ public class SpringAwareJdbcTransactionManager implements ExternalTransactionMan
|
||||
if (holder == null || !holder.isSynchronizedWithTransaction()) {
|
||||
// no current Spring transaction
|
||||
SpiTransaction currentEbeanTransaction = DefaultTransactionThreadLocal.get(serverName);
|
||||
if (currentEbeanTransaction != null) {
|
||||
// NOT expecting this so log WARNING
|
||||
String msg = "SpringTransaction - no current spring txn BUT using current Ebean one " + currentEbeanTransaction.getId();
|
||||
logger.log(Level.WARNING, msg);
|
||||
|
||||
} else if (logger.isLoggable(Level.FINEST)) {
|
||||
logger.log(Level.FINEST, "Spring Txn - no current transaction ");
|
||||
if (currentEbeanTransaction != null) { // this is unexpected
|
||||
log.warn("No current Spring transaction BUT using current Ebean one {}", currentEbeanTransaction.getId());
|
||||
} else {
|
||||
log.trace("No current Spring transaction");
|
||||
}
|
||||
return currentEbeanTransaction;
|
||||
}
|
||||
|
||||
SpringTxnListener springTxnLister = getSpringTxnListener();
|
||||
|
||||
if (springTxnLister != null) {
|
||||
// we have already seen this transaction
|
||||
return springTxnLister.getTransaction();
|
||||
|
||||
} else {
|
||||
// This is a new spring transaction that we have not seen before.
|
||||
// "wrap" it in a SpringJdbcTransaction for use with Ebean
|
||||
@@ -210,23 +204,18 @@ public class SpringAwareJdbcTransactionManager implements ExternalTransactionMan
|
||||
|
||||
switch (status) {
|
||||
case STATUS_COMMITTED:
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine("Spring Txn [" + transaction.getId() + "] committed");
|
||||
}
|
||||
log.debug("Spring Txn [{}] committed", transaction.getId());
|
||||
transactionManager.notifyOfCommit(transaction);
|
||||
break;
|
||||
|
||||
case STATUS_ROLLED_BACK:
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine("Spring Txn [" + transaction.getId() + "] rollback");
|
||||
}
|
||||
log.debug("Spring Txn [{}] rollback", transaction.getId());
|
||||
transactionManager.notifyOfRollback(transaction, null);
|
||||
break;
|
||||
|
||||
default:
|
||||
// this should never happen
|
||||
String msg = "Invalid status " + status;
|
||||
throw new PersistenceException(msg);
|
||||
throw new PersistenceException("Invalid status " + status);
|
||||
}
|
||||
|
||||
// Remove this transaction object as it is completed
|
||||
|
||||
@@ -19,17 +19,14 @@
|
||||
*/
|
||||
package com.avaje.test.springsupport;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Unit test for Ebean Spring Module.
|
||||
|
||||
@@ -20,9 +20,7 @@
|
||||
|
||||
package com.avaje.test.springsupport;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.ManyToMany;
|
||||
@@ -56,6 +54,4 @@ public class Role {
|
||||
public void setUsers(Set<User> users) {
|
||||
this.users = users;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -8,6 +8,11 @@
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
|
||||
|
||||
<bean class="com.avaje.ebean.springsupport.AgentLoaderSupport">
|
||||
<property name="debug" value="1" />
|
||||
<property name="packages" value="com.avaje.test.springsupport.**" />
|
||||
</bean>
|
||||
|
||||
<import resource="classpath:default-ebean-server.xml"/>
|
||||
|
||||
<!-- Transaktionen via Annotation use Springs @Transactional -->
|
||||
|
||||
Reference in New Issue
Block a user