general formatting work

This commit is contained in:
eugenp 2016-01-30 12:01:41 +02:00
parent fc59834adb
commit 95e2d063f4
36 changed files with 71 additions and 97 deletions

View File

@ -67,8 +67,4 @@ public class CollectionJavaPartitionUnitTest {
assertThat(lastPartition, equalTo(expectedLastPartition));
}
}

View File

@ -19,15 +19,13 @@ public class DataAccessAnnotationProcessor implements BeanPostProcessor {
}
@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;
}

View File

@ -12,18 +12,14 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
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;
@ -34,8 +30,7 @@ public final class DataAccessFieldCallback implements FieldCallback {
}
@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;
}
@ -54,7 +49,6 @@ public final class DataAccessFieldCallback implements FieldCallback {
}
}
/**
* For example, if user write:
* <pre>
@ -75,8 +69,6 @@ public final class DataAccessFieldCallback implements FieldCallback {
}
}
public final Object getBeanInstance(final String beanName, final Class<?> genericClass, final Class<?> paramClass) {
Object daoInstance = null;
if (!configurableListableBeanFactory.containsBean(beanName)) {

View File

@ -8,7 +8,8 @@ public class BeanWithGenericDAO {
@DataAccess(entity = Person.class)
private GenericDAO<Person> personGenericDAO;
public BeanWithGenericDAO() {}
public BeanWithGenericDAO() {
}
public GenericDAO<Person> getPersonGenericDAO() {
return personGenericDAO;

View File

@ -15,7 +15,6 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { CustomAnnotationConfiguration.class })
public class DataAccessFieldCallbackTest {
@ -36,8 +35,7 @@ public class DataAccessFieldCallbackTest {
}
@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);

View File

@ -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" };
@ -61,8 +60,7 @@ public class SpringBatchConfig {
}
@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");
@ -78,11 +76,8 @@ public class SpringBatchConfig {
}
@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")

View File

@ -38,8 +38,7 @@ public class SpringConfig {
}
@Bean
public DataSourceInitializer dataSourceInitializer(DataSource dataSource)
throws MalformedURLException {
public DataSourceInitializer dataSourceInitializer(DataSource dataSource) throws MalformedURLException {
ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
databasePopulator.addScript(dropReopsitoryTables);

View File

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

View File

@ -3,8 +3,7 @@ package org.baeldung.spring_batch_intro.service;
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);

View File

@ -41,7 +41,6 @@ public class JPABarAuditTest {
logger.info("tearDownAfterClass()");
}
@Autowired
@Qualifier("barJpaService")
private IBarService barService;
@ -51,7 +50,6 @@ public class JPABarAuditTest {
private EntityManager em;
@Before
public void setUp() throws Exception {
logger.info("setUp()");
@ -64,7 +62,6 @@ public class JPABarAuditTest {
em.close();
}
@Test
public final void whenBarsModified_thenBarsAudited() {
@ -84,7 +81,6 @@ public class JPABarAuditTest {
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);

View File

@ -24,13 +24,16 @@ public class LoggingAspect {
};
@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) {

View File

@ -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 {

View File

@ -21,13 +21,16 @@ public class PublishingAspect {
}
@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 {

View File

@ -14,9 +14,6 @@ public class Foo {
@Override
public String toString() {
return "Foo{" +
"id=" + id +
", name='" + name + '\'' +
'}';
return "Foo{" + "id=" + id + ", name='" + name + '\'' + '}';
}
}

View File

@ -22,8 +22,7 @@ public class UserController {
}
@RequestMapping(value = "/processForm", method = RequestMethod.POST)
public String processForm(@ModelAttribute(value = "user") final User user,
final Model model) {
public String processForm(@ModelAttribute(value = "user") final User user, final Model model) {
// Insert User into DB
model.addAttribute("name", user.getFirstname() + " " + user.getLastname());
return "hello";

View File

@ -60,8 +60,7 @@ public class AopPublishingTest {
dao.create(1L, "Bar");
String logMessage = messages.get(0);
Pattern pattern = Pattern.compile("Created foo instance: " +
Pattern.quote(new Foo(1L, "Bar").toString()));
Pattern pattern = Pattern.compile("Created foo instance: " + Pattern.quote(new Foo(1L, "Bar").toString()));
assertTrue(pattern.matcher(logMessage).matches());
}
}