Skip to content

Commit

Permalink
general formatting work
Browse files Browse the repository at this point in the history
  • Loading branch information
eugenp committed Jan 30, 2016
1 parent fc59834 commit 95e2d06
Show file tree
Hide file tree
Showing 36 changed files with 71 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,4 @@ public final void givenList_whenSplittingBySeparator_thenCorrect() {
assertThat(lastPartition, equalTo(expectedLastPartition));
}





}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
@Target({ ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Documented
public @interface DataAccess {
Class<?>entity();
Class<?> entity();
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ public DataAccessAnnotationProcessor(ConfigurableListableBeanFactory bf) {
}

@Override
public Object postProcessBeforeInitialization(Object bean, String beanName)
throws BeansException {
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
scanDataAccessAnnotation(bean, beanName);
return bean;
}

@Override
public Object postProcessAfterInitialization(Object bean, String beanName)
throws BeansException {
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
return bean;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,14 @@
import org.springframework.util.ReflectionUtils;
import org.springframework.util.ReflectionUtils.FieldCallback;


public final class DataAccessFieldCallback implements FieldCallback {

private static Logger logger = LoggerFactory.getLogger(DataAccessFieldCallback.class);
private static int AUTOWIRE_MODE = AutowireCapableBeanFactory.AUTOWIRE_BY_NAME;

private static String ERROR_ENTITY_VALUE_NOT_SAME = "@DataAccess(entity) "
+ "value should have same type with injected generic type.";
private static String WARN_NON_GENERIC_VALUE = "@DataAccess annotation assigned "
+ "to raw (non-generic) declaration. This will make your code less type-safe.";
private static String ERROR_CREATE_INSTANCE = "Cannot create instance of "
+ "type '{}' or instance creation is failed because: {}";
private static String ERROR_ENTITY_VALUE_NOT_SAME = "@DataAccess(entity) " + "value should have same type with injected generic type.";
private static String WARN_NON_GENERIC_VALUE = "@DataAccess annotation assigned " + "to raw (non-generic) declaration. This will make your code less type-safe.";
private static String ERROR_CREATE_INSTANCE = "Cannot create instance of " + "type '{}' or instance creation is failed because: {}";

private ConfigurableListableBeanFactory configurableListableBeanFactory;
private Object bean;
Expand All @@ -34,15 +30,14 @@ public DataAccessFieldCallback(final ConfigurableListableBeanFactory bf, final O
}

@Override
public void doWith(final Field field)
throws IllegalArgumentException, IllegalAccessException {
public void doWith(final Field field) throws IllegalArgumentException, IllegalAccessException {
if (!field.isAnnotationPresent(DataAccess.class)) {
return;
}
ReflectionUtils.makeAccessible(field);
final Type fieldGenericType = field.getGenericType();
// In this example, get actual "GenericDAO' type.
final Class<?> generic = field.getType();
// In this example, get actual "GenericDAO' type.
final Class<?> generic = field.getType();
final Class<?> classValue = field.getDeclaredAnnotation(DataAccess.class).entity();

if (genericTypeIsValid(classValue, fieldGenericType)) {
Expand All @@ -54,7 +49,6 @@ public void doWith(final Field field)
}
}


/**
* For example, if user write:
* <pre>
Expand All @@ -75,8 +69,6 @@ public boolean genericTypeIsValid(final Class<?> clazz, final Type field) {
}
}



public final Object getBeanInstance(final String beanName, final Class<?> genericClass, final Class<?> paramClass) {
Object daoInstance = null;
if (!configurableListableBeanFactory.containsBean(beanName)) {
Expand All @@ -90,7 +82,7 @@ public final Object getBeanInstance(final String beanName, final Class<?> generi
logger.error(ERROR_CREATE_INSTANCE, genericClass.getTypeName(), e);
throw new RuntimeException(e);
}

daoInstance = configurableListableBeanFactory.initializeBean(toRegister, beanName);
configurableListableBeanFactory.autowireBeanProperties(daoInstance, AUTOWIRE_MODE, true);
configurableListableBeanFactory.registerSingleton(beanName, daoInstance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
@Repository
public class BeanWithGenericDAO {

@DataAccess(entity=Person.class)
@DataAccess(entity = Person.class)
private GenericDAO<Person> personGenericDAO;

public BeanWithGenericDAO() {}
public BeanWithGenericDAO() {
}

public GenericDAO<Person> getPersonGenericDAO() {
return personGenericDAO;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;


@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { CustomAnnotationConfiguration.class })
public class DataAccessFieldCallbackTest {
Expand All @@ -36,8 +35,7 @@ public void whenObjectCreated_thenObjectCreationIsSuccessful() {
}

@Test
public void whenMethodGenericTypeIsValidCalled_thenReturnCorrectValue()
throws NoSuchFieldException, SecurityException {
public void whenMethodGenericTypeIsValidCalled_thenReturnCorrectValue() throws NoSuchFieldException, SecurityException {
final DataAccessFieldCallback callback = new DataAccessFieldCallback(configurableListableBeanFactory, beanWithGenericDAO);
final Type fieldType = BeanWithGenericDAO.class.getDeclaredField("personGenericDAO").getGenericType();
final boolean result = callback.genericTypeIsValid(Person.class, fieldType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public class SpringBatchConfig {
private Resource outputXml;

@Bean
public ItemReader<Transaction> itemReader()
throws UnexpectedInputException, ParseException {
public ItemReader<Transaction> itemReader() throws UnexpectedInputException, ParseException {
FlatFileItemReader<Transaction> reader = new FlatFileItemReader<Transaction>();
DelimitedLineTokenizer tokenizer = new DelimitedLineTokenizer();
String[] tokens = { "username", "userid", "transactiondate", "amount" };
Expand All @@ -61,8 +60,7 @@ public ItemProcessor<Transaction, Transaction> itemProcessor() {
}

@Bean
public ItemWriter<Transaction> itemWriter(Marshaller marshaller)
throws MalformedURLException {
public ItemWriter<Transaction> itemWriter(Marshaller marshaller) throws MalformedURLException {
StaxEventItemWriter<Transaction> itemWriter = new StaxEventItemWriter<Transaction>();
itemWriter.setMarshaller(marshaller);
itemWriter.setRootTagName("transactionRecord");
Expand All @@ -78,11 +76,8 @@ public Marshaller marshaller() {
}

@Bean
protected Step step1(ItemReader<Transaction> reader,
ItemProcessor<Transaction, Transaction> processor,
ItemWriter<Transaction> writer) {
return steps.get("step1").<Transaction, Transaction> chunk(10)
.reader(reader).processor(processor).writer(writer).build();
protected Step step1(ItemReader<Transaction> reader, ItemProcessor<Transaction, Transaction> processor, ItemWriter<Transaction> writer) {
return steps.get("step1").<Transaction, Transaction> chunk(10).reader(reader).processor(processor).writer(writer).build();
}

@Bean(name = "firstBatchJob")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ public DataSource dataSource() {
}

@Bean
public DataSourceInitializer dataSourceInitializer(DataSource dataSource)
throws MalformedURLException {
public DataSourceInitializer dataSourceInitializer(DataSource dataSource) throws MalformedURLException {
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();

databasePopulator.addScript(dropReopsitoryTables);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ public void setAmount(double amount) {

@Override
public String toString() {
return "Transaction [username=" + username + ", userId=" + userId
+ ", transactionDate=" + transactionDate + ", amount=" + amount
+ "]";
return "Transaction [username=" + username + ", userId=" + userId + ", transactionDate=" + transactionDate + ", amount=" + amount + "]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import org.baeldung.spring_batch_intro.model.Transaction;
import org.springframework.batch.item.ItemProcessor;

public class CustomItemProcessor implements
ItemProcessor<Transaction, Transaction> {
public class CustomItemProcessor implements ItemProcessor<Transaction, Transaction> {

public Transaction process(Transaction item) {
System.out.println("Processing..." + item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.springframework.stereotype.Repository;

@Repository
public class ChildDao extends AbstractHibernateDao<Child>implements IChildDao {
public class ChildDao extends AbstractHibernateDao<Child> implements IChildDao {

@Autowired
private SessionFactory sessionFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.springframework.stereotype.Repository;

@Repository
public class FooDao extends AbstractHibernateDao<Foo>implements IFooDao {
public class FooDao extends AbstractHibernateDao<Foo> implements IFooDao {

@Autowired
private SessionFactory sessionFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.springframework.stereotype.Repository;

@Repository
public class ParentDao extends AbstractHibernateDao<Parent>implements IParentDao {
public class ParentDao extends AbstractHibernateDao<Parent> implements IParentDao {

@Autowired
private SessionFactory sessionFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.springframework.stereotype.Service;

@Service
public class ChildService extends AbstractService<Child>implements IChildService {
public class ChildService extends AbstractService<Child> implements IChildService {

@Autowired
private IChildDao dao;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.springframework.stereotype.Service;

@Service
public class FooService extends AbstractService<Foo>implements IFooService {
public class FooService extends AbstractService<Foo> implements IFooService {

@Autowired
private IFooDao dao;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.springframework.stereotype.Service;

@Service
public class ParentService extends AbstractService<Parent>implements IParentService {
public class ParentService extends AbstractService<Parent> implements IParentService {

@Autowired
private IParentDao dao;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.springframework.stereotype.Repository;

@Repository
public class FooDao extends AbstractHibernateDao<Foo>implements IFooDao {
public class FooDao extends AbstractHibernateDao<Foo> implements IFooDao {

public FooDao() {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@

@Repository
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class GenericHibernateDao<T extends Serializable> extends AbstractHibernateDao<T>implements IGenericDao<T> {
public class GenericHibernateDao<T extends Serializable> extends AbstractHibernateDao<T> implements IGenericDao<T> {
//
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.springframework.stereotype.Service;

@Service
public class ChildService extends AbstractHibernateService<Child>implements IChildService {
public class ChildService extends AbstractHibernateService<Child> implements IChildService {

@Autowired
private IChildDao dao;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.springframework.stereotype.Service;

@Service
public class FooService extends AbstractHibernateService<Foo>implements IFooService {
public class FooService extends AbstractHibernateService<Foo> implements IFooService {

@Autowired
@Qualifier("fooHibernateDao")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.springframework.stereotype.Service;

@Service
public class ParentService extends AbstractHibernateService<Parent>implements IParentService {
public class ParentService extends AbstractHibernateService<Parent> implements IParentService {

@Autowired
private IParentDao dao;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public static void tearDownAfterClass() throws Exception {
logger.info("tearDownAfterClass()");
}


@Autowired
@Qualifier("barJpaService")
private IBarService barService;
Expand All @@ -51,7 +50,6 @@ public static void tearDownAfterClass() throws Exception {

private EntityManager em;


@Before
public void setUp() throws Exception {
logger.info("setUp()");
Expand All @@ -64,7 +62,6 @@ public void tearDown() throws Exception {
em.close();
}


@Test
public final void whenBarsModified_thenBarsAudited() {

Expand All @@ -84,7 +81,6 @@ public final void whenBarsModified_thenBarsAudited() {
bar1.setName("BAR1b");
barService.update(bar1);


// get BAR1 and BAR2 from the DB and check the audit values
// detach instances from persistence context to make sure we fire db
em.detach(bar1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.springframework.stereotype.Repository;

@Repository
public class FooDao extends AbstractJpaDAO<Foo>implements IFooDao {
public class FooDao extends AbstractJpaDAO<Foo> implements IFooDao {

public FooDao() {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class User {
private String email;

@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "users_roles", joinColumns = @JoinColumn(name = "user_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "role_id", referencedColumnName = "id"))
@JoinTable(name = "users_roles", joinColumns = @JoinColumn(name = "user_id", referencedColumnName = "id") , inverseJoinColumns = @JoinColumn(name = "role_id", referencedColumnName = "id") )
@JsonApiToMany
@JsonApiIncludeByDefault
private Set<Role> roles;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ protected SimpleDateFormat initialValue() {
};

@Pointcut("@target(org.springframework.stereotype.Repository)")
public void repositoryMethods() {}
public void repositoryMethods() {
}

@Pointcut("@annotation(org.baeldung.aop.annotations.Loggable)")
public void loggableMethods() {}
public void loggableMethods() {
}

@Pointcut("@args(org.baeldung.aop.annotations.Entity)")
public void methodsAcceptingEntities() {}
public void methodsAcceptingEntities() {
}

@Before("repositoryMethods()")
public void logMethodCall(JoinPoint jp) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public class PerformanceAspect {
private static Logger logger = Logger.getLogger(PerformanceAspect.class.getName());

@Pointcut("within(@org.springframework.stereotype.Repository *)")
public void repositoryClassMethods() {}
public void repositoryClassMethods() {
}

@Around("repositoryClassMethods()")
public Object measureMethodExecutionTime(ProceedingJoinPoint pjp) throws Throwable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ public void setEventPublisher(ApplicationEventPublisher eventPublisher) {
}

@Pointcut("@target(org.springframework.stereotype.Repository)")
public void repositoryMethods() {}
public void repositoryMethods() {
}

@Pointcut("execution(* *..create*(Long,..))")
public void firstLongParamMethods() {}
public void firstLongParamMethods() {
}

@Pointcut("repositoryMethods() && firstLongParamMethods()")
public void entityCreationMethods() {}
public void entityCreationMethods() {
}

@AfterReturning(value = "entityCreationMethods()", returning = "entity")
public void logMethodCall(JoinPoint jp, Object entity) throws Throwable {
Expand Down
Loading

0 comments on commit 95e2d06

Please sign in to comment.