Skip to content

Instantly share code, notes, and snippets.

@langmi
langmi / set_http_proxy__var_windows.bat
Created August 17, 2011 08:24
simple set command for http_proxy variable in windows
SET HTTP_PROXY=http://%USER%:%PASSWORD%@%SERVER%:%PORT%
@langmi
langmi / gist:1226119
Created September 19, 2011 07:46
AsyncTaskExecutorFactory example
public class AsyncTaskExecutorFactory {
...
public static SimpleAsyncTaskExecutor createInstance() {
SimpleAsyncTaskExecutor instance = new SimpleAsyncTaskExecutor();
// set concurrencyLimit according to available processors
// real simple 1:1 relation
Runtime runtime = Runtime.getRuntime();
int nrCpu = runtime.availableProcessors();
instance.setConcurrencyLimit(nrCpu);
@langmi
langmi / SetupHsqldbDatasource.java
Created September 24, 2011 09:24
Setup HSQLDB Datasource
public class JdbcPagingItemReaderTests {
private BasicDataSource dataSource;
public void setUp() throws Exception {
// DataSource Setup, apache commons
dataSource = new BasicDataSource();
dataSource.setDriverClassName("org.hsqldb.jdbcDriver");
dataSource.setUrl("jdbc:hsqldb:mem:testdb");
dataSource.setUsername("sa");
@langmi
langmi / CustomSqlParameterSourceProvider.java
Created September 30, 2011 09:14
simple example CustomSqlParameterSourceProvider which constructs a MapSqlParameterSource with given item
/**
* CustomSqlParameterSourceProvider, constructs {@link MapSqlParameterSource} with
* given item.
*
* @author Michael R. Lange <michael.r.lange@langmi.de>
*/
public class CustomSqlParameterSourceProvider implements ItemSqlParameterSourceProvider<YourItemObject> {
@Override
public SqlParameterSource createSqlParameterSource(final YourItemObject item) {
@langmi
langmi / FieldSetSqlParameterSourceProvider.java
Created September 30, 2011 09:19
Implementation for ItemSqlParameterSourceProvider which creates a MapSqlParameterSource directly from the FieldSet
/**
* Implementation for {@link ItemSqlParameterSourceProvider},
* creates {@link MapSqlParameterSource} from {@link FieldSet}.
*
* @author Michael R. Lange <michael.r.lange@langmi.de>
*/
public class FieldSetSqlParameterSourceProvider implements ItemSqlParameterSourceProvider<FieldSet> {
/** {@inheritDoc} */
@Override
@langmi
langmi / WrappedMrirToGetCurrentResource.java
Created January 9, 2012 07:57
(Spring-Batch) Example implementation wraps a MultiResourceItemReader to get the current resource.
public class WrappedMrirToGetCurrentResource<T> implements ItemStreamReader<T> {
private MultiResourceItemReader<T> mrir;
@Override
public void open(ExecutionContext executionContext) throws ItemStreamException {
mrir.open(executionContext);
// current.resource is only available here if it's a restart
if (mrir.getCurrentResource() != null && mrir.getCurrentResource().getFilename() != null) {
System.out.println("open:" + mrir.getCurrentResource().getFilename());
@langmi
langmi / gist:1582202
Created January 9, 2012 09:39
access target behind spring proxy
// from http://www.techper.net/2009/06/05/how-to-acess-target-object-behind-a-spring-proxy/
@SuppressWarnings({"unchecked"})
protected <T> T getTargetObject(Object proxy, Class<T> targetClass) throws Exception {
if (AopUtils.isJdkDynamicProxy(proxy)) {
return (T) ((Advised)proxy).getTargetSource().getTarget();
} else {
return (T) proxy; // expected to be cglib proxy then, which is simply a specialized class
}
}
@langmi
langmi / ReaderExhaustedWrapper.java
Created January 24, 2012 22:18
Spring Batch Reader wrapping another reader, for each read it peeks ahead to look for end of data.
/**
* Copyright 2012 Michael R. Lange <michael.r.lange@langmi.de>.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@langmi
langmi / AggregatingSimpleItemsWriter.java
Created January 24, 2012 22:20
Itemwriter which aggregates items before delegating to another wrapped itemwriter. See https://gist.github.com/1673074 for example of Reader which checks if resource is exhausted.
/**
* Copyright 2012 Michael R. Lange <michael.r.lange@langmi.de>.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@langmi
langmi / CompositeItemStreamReader.java
Created February 3, 2012 07:23
CompositeItemStreamReader wraps multiple ItemStreamReaders and reads them simultaneously.
import java.util.ArrayList;
import java.util.List;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.ItemStreamException;
import org.springframework.batch.item.ItemStreamReader;
import org.springframework.batch.item.NonTransientResourceException;
import org.springframework.batch.item.ParseException;
import org.springframework.batch.item.UnexpectedInputException;