Skip to content

Commit

Permalink
JPA fixes (apereo#1710)
Browse files Browse the repository at this point in the history
* use the ticket registry jpa properties for the jpa-ticket-registry

* fix an NPE in the JPA Locking Strategy

* add pointcuts for ticketRegistrySupport object

* remove duplicate property
  • Loading branch information
frett authored and SavvasMisaghMoayyed committed Apr 24, 2016
1 parent 9699946 commit d522901
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,104 +36,104 @@ public class JpaTicketRegistryConfiguration {
/**
* The Hibernate dialect.
*/
@Value("${svcreg.database.dialect:org.hibernate.dialect.HSQLDialect}")
@Value("${ticketreg.database.dialect:org.hibernate.dialect.HSQLDialect}")
private String hibernateDialect;

/**
* The Hibernate hbm 2 ddl auto.
*/
@Value("${svcreg.database.ddl.auto:create-drop}")
@Value("${ticketreg.database.ddl.auto:create-drop}")
private String hibernateHbm2DdlAuto;

/**
* The Hibernate batch size.
*/
@Value("${svcreg.database.batchSize:1}")
@Value("${ticketreg.database.batchSize:1}")
private String hibernateBatchSize;


/**
* The Driver class.
*/
@Value("${svcreg.database.driverClass:org.hsqldb.jdbcDriver}")
@Value("${ticketreg.database.driverClass:org.hsqldb.jdbcDriver}")
private String driverClass;

/**
* The Jdbc url.
*/
@Value("${svcreg.database.url:jdbc:hsqldb:mem:cas-service-registry}")
@Value("${ticketreg.database.url:jdbc:hsqldb:mem:cas-service-registry}")
private String jdbcUrl;

/**
* The User.
*/
@Value("${svcreg.database.user:sa}")
@Value("${ticketreg.database.user:sa}")
private String user;

/**
* The Password.
*/
@Value("${svcreg.database.password:}")
@Value("${ticketreg.database.password:}")
private String password;

/**
* The Initial pool size.
*/
@Value("${svcreg.database.pool.minSize:6}")
@Value("${ticketreg.database.pool.minSize:6}")
private int initialPoolSize;

/**
* The Min pool size.
*/
@Value("${svcreg.database.pool.minSize:6}")
@Value("${ticketreg.database.pool.minSize:6}")
private int minPoolSize;

/**
* The Max pool size.
*/
@Value("${svcreg.database.pool.maxSize:18}")
@Value("${ticketreg.database.pool.maxSize:18}")
private int maxPoolSize;

/**
* The Max idle time excess connections.
*/
@Value("${svcreg.database.pool.maxIdleTime:1000}")
@Value("${ticketreg.database.pool.maxIdleTime:1000}")
private int maxIdleTimeExcessConnections;

/**
* The Checkout timeout.
*/
@Value("${svcreg.database.pool.maxWait:2000}")
@Value("${ticketreg.database.pool.maxWait:2000}")
private int checkoutTimeout;

/**
* The Acquire increment.
*/
@Value("${svcreg.database.pool.acquireIncrement:16}")
@Value("${ticketreg.database.pool.acquireIncrement:16}")
private int acquireIncrement;

/**
* The Acquire retry attempts.
*/
@Value("${svcreg.database.pool.acquireRetryAttempts:5}")
@Value("${ticketreg.database.pool.acquireRetryAttempts:5}")
private int acquireRetryAttempts;

/**
* The Acquire retry delay.
*/
@Value("${svcreg.database.pool.acquireRetryDelay:2000}")
@Value("${ticketreg.database.pool.acquireRetryDelay:2000}")
private int acquireRetryDelay;

/**
* The Idle connection test period.
*/
@Value("${svcreg.database.pool.idleConnectionTestPeriod:30}")
@Value("${ticketreg.database.pool.idleConnectionTestPeriod:30}")
private int idleConnectionTestPeriod;

/**
* The Preferred test query.
*/
@Value("${svcreg.database.pool.connectionHealthQuery:select 1}")
@Value("${ticketreg.database.pool.connectionHealthQuery:select 1}")
private String preferredTestQuery;

/**
Expand Down Expand Up @@ -172,7 +172,7 @@ public LocalContainerEntityManagerFactoryBean ticketEntityManagerFactory() {
final LocalContainerEntityManagerFactoryBean bean = new LocalContainerEntityManagerFactoryBean();

bean.setJpaVendorAdapter(ticketJpaVendorAdapter());
bean.setPersistenceUnitName("jpaServiceRegistryContext");
bean.setPersistenceUnitName("jpaTicketRegistryContext");
bean.setPackagesToScan(ticketPackagesToScan());
bean.setDataSource(dataSourceTicket());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ public boolean acquire() {

boolean result = false;
if (lock != null) {
final ZonedDateTime expDate = ZonedDateTime.from(lock.getExpirationDate());
final ZonedDateTime expDate = lock.getExpirationDate();
if (lock.getUniqueId() == null) {
// No one currently possesses lock
logger.debug("{} trying to acquire {} lock.", uniqueId, applicationId);
result = acquire(entityManager, lock);
} else if (ZonedDateTime.now(ZoneOffset.UTC).isAfter(expDate)) {
} else if (expDate == null || ZonedDateTime.now(ZoneOffset.UTC).isAfter(expDate)) {
// Acquire expired lock regardless of who formerly owned it
logger.debug("{} trying to acquire expired {} lock.", uniqueId, applicationId);
result = acquire(entityManager, lock);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@
</tx:attributes>
</tx:advice>

<tx:advice id="txRegistrySupportAdvice" transaction-manager="ticketTransactionManager">
<tx:attributes>
<tx:method name="getAuthenticationFrom" read-only="false" />
<tx:method name="getAuthenticatedPrincipalFrom" read-only="false" />
<tx:method name="getPrincipalAttributesFrom" read-only="false" />
</tx:attributes>
</tx:advice>

<tx:advice id="txRegistryServiceTicketDelegatorAdvice" transaction-manager="ticketTransactionManager">
<tx:attributes>
<tx:method name="grantProxyGrantingTicket" read-only="false" />
Expand Down Expand Up @@ -73,6 +81,8 @@
<aop:config>
<aop:pointcut id="ticketRegistryOperations"
expression="execution(* org.jasig.cas.ticket.registry.JpaTicketRegistry.*(..))"/>
<aop:pointcut id="ticketRegistrySupportOperations"
expression="execution(* org.jasig.cas.ticket.registry.TicketRegistrySupport.*(..))"/>
<aop:pointcut id="ticketRegistryLockingOperations"
expression="execution(* org.jasig.cas.ticket.registry.support.JpaLockingStrategy.*(..))"/>
<aop:pointcut id="ticketRegistryServiceTicketDelegatorOperations"
Expand All @@ -83,10 +93,12 @@
expression="execution(* org.jasig.cas.ticket.registry.ProxyGrantingTicketDelegator.*(..))"/>

<aop:pointcut id="casOperations"
expression="execution(* org.jasig.cas.CentralAuthenticationServiceImpl.*(..))"/>
expression="execution(* org.jasig.cas.CentralAuthenticationService.*(..))"/>

<aop:advisor advice-ref="txRegistryAdvice"
pointcut-ref="ticketRegistryOperations"/>
<aop:advisor advice-ref="txRegistrySupportAdvice"
pointcut-ref="ticketRegistrySupportOperations"/>
<aop:advisor advice-ref="txRegistryLockingAdvice"
pointcut-ref="ticketRegistryLockingOperations"/>
<aop:advisor advice-ref="txRegistryTicketGrantingTicketDelegatorAdvice"
Expand Down
1 change: 0 additions & 1 deletion cas-server-webapp/src/main/webapp/WEB-INF/cas.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ server.prefix=${server.name}/cas
# ticketreg.database.pool.maxIdleTime=120
# ticketreg.database.pool.acquireIncrement=6
# ticketreg.database.pool.idleConnectionTestPeriod=30
# ticketreg.database.pool.connectionHealthQuery=select 1
# ticketreg.database.pool.acquireRetryAttempts=5
# ticketreg.database.pool.acquireRetryDelay=2000
# ticketreg.database.pool.connectionHealthQuery=select 1
Expand Down

0 comments on commit d522901

Please sign in to comment.