package org.apache.tomcat.jdbc.pool.jmx;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
public class MockCommonDao extends SqlMapClientDaoSupport {
ArrayList<ArrayList> listOlists = new ArrayList<ArrayList>();
public List selectByExample(List<Object> example)
{
List<Future<Object>> listOlists = null;
ExecutorService executor = Executors.newFixedThreadPool(example.size());
List<TransactionImpl> callingList = new ArrayList<MockCommonDao.TransactionImpl>();
for (int i = 0; i < example.size(); i++) {
TransactionImpl localImpl = new TransactionImpl(example.get(i));
callingList.add(localImpl);
}
try {
listOlists = executor.invokeAll(callingList);
} catch (InterruptedException e) {
}
return listOlists;
}
private String getClassNameFromExample(Object example)
{
String tableName = example.getClass().getName();
int cnt = tableName.indexOf("Example");
int last = tableName.lastIndexOf('.');
tableName = tableName.substring(last + 1, cnt);
return tableName.toUpperCase();
}
private class TransactionImpl implements Callable<Object>{
private Object example;
TransactionImpl(Object Criteria) {
this.example = Criteria;
}
@Override
public Object call() throws Exception {
List list = getSqlMapClientTemplate().queryForList((new StringBuilder(String.valueOf(getClassNameFromExample(example)))).append(".ibatorgenerated_selectByExample").toString(), example);
listOlists.add((ArrayList) list);
return listOlists;
}
}}
No comments:
Post a Comment