Skip to content

Commit

Permalink
Polish
Browse files Browse the repository at this point in the history
  • Loading branch information
making committed Jul 26, 2017
1 parent a913903 commit dbdd045
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package org.seasar.doma.boot.autoconfigure;

import java.util.function.Supplier;

import javax.sql.DataSource;

import org.seasar.doma.boot.event.AnnotatedDomaEventHandlerInvoker;
Expand All @@ -26,8 +24,6 @@
import org.seasar.doma.jdbc.Naming;
import org.seasar.doma.jdbc.SqlFileRepository;
import org.seasar.doma.jdbc.dialect.Dialect;
import org.seasar.doma.jdbc.entity.EntityListener;
import org.seasar.doma.jdbc.entity.NullEntityListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
Expand All @@ -37,7 +33,6 @@
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.dao.support.PersistenceExceptionTranslator;
import org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator;

Expand Down Expand Up @@ -92,29 +87,9 @@ public DomaEventEntityListener domaEventEntityListener() {
}

@Bean
public TryLookupEntityListenerProvider tryLookupEntityListenerProvider() {
return new TryLookupEntityListenerProvider();
}

@Bean
@Primary
@ConditionalOnMissingBean
public <ENTITY> EntityListenerProvider entityListenerProvider(
DomaEventEntityListener<ENTITY> domaEventEntityListener,
TryLookupEntityListenerProvider tryLookupEntityListenerProvider) {
return new EntityListenerProvider() {

@SuppressWarnings("unchecked")
@Override
public <ENTITY, LISTENER extends EntityListener<ENTITY>> LISTENER get(
Class<LISTENER> listenerClass, Supplier<LISTENER> listenerSupplier) {
if (NullEntityListener.class.equals(listenerClass)) {
return tryLookupEntityListenerProvider.get(listenerClass,
listenerSupplier);
}
return (LISTENER) domaEventEntityListener;
}
};
public EntityListenerProvider tryLookupEntityListenerProvider() {
return new TryLookupEntityListenerProvider();
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,19 @@
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;

public class DomaEventEntityListener<T> extends /* ugly hack */NullEntityListener<T>
implements ApplicationEventPublisherAware {
/**
* {@link EntityListener} implementation that publishes {@link DomaEvent} and delegates
* actual processing on the event lister class which is annoteted with
* {@link org.seasar.doma.boot.event.annotation.DomaEventHandler}. <br>
* <br>
* This class extends {@link NullEntityListener} so that {@link org.seasar.doma.Entity} is
* available with default parameters.
*
* @param <T> Entity class
* @author Toshiaki Maki
*/
public class DomaEventEntityListener<T> extends NullEntityListener<T> implements
ApplicationEventPublisherAware {

private ApplicationEventPublisher eventPublisher;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.seasar.doma.boot;

import java.time.LocalDate;

import org.seasar.doma.jdbc.entity.EntityListener;
import org.seasar.doma.jdbc.entity.PreInsertContext;
import org.springframework.stereotype.Component;

import java.time.LocalDate;

@Component
public class MessageListener implements EntityListener<Message> {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
*/
package org.seasar.doma.boot;

import org.seasar.doma.*;

import java.time.LocalDate;

import org.seasar.doma.*;

@Entity
@Table(name = "messages")
public class Message {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.seasar.doma.boot;

import java.time.LocalDate;

import org.seasar.doma.boot.event.annotation.DomaEventHandler;
import org.seasar.doma.boot.event.annotation.HandlePreInsert;

import java.time.LocalDate;

@DomaEventHandler
public class MessageHandler {
@HandlePreInsert
Expand Down

0 comments on commit dbdd045

Please sign in to comment.