1
2 package net.sf.voruta;
3
4 import java.util.*;
5 import java.lang.reflect.*;
6 /*** Transforms result set to collection of beans
7 * @author baliuka
8 */
9 public class BeanCollectionHandler implements ResultSetHandler{
10 private Class type;
11 /*** Creates a new instance of BeanCollectionHandler
12 * @param type Bean type
13 */
14 public BeanCollectionHandler(Class type) {
15 this.type = type;
16 }
17
18 public Object handle(DbResultSet rs,Class returnType, Object[] params) throws Exception {
19
20 Collection result ;
21 boolean isInterface = Modifier.isInterface(returnType.getModifiers());
22
23 if( isInterface && Set.class.isAssignableFrom(returnType) ){
24
25 result = Collections.synchronizedSet(new HashSet());
26
27 }else if( isInterface && List.class.isAssignableFrom(returnType) ){
28
29 result = new Vector();
30
31 }else if (isInterface && Collection.class.isAssignableFrom(returnType) ){
32
33 result = new Vector();
34
35 }else if ( returnType.isArray() ){
36
37 result = new ArrayList();
38
39 }else {
40
41 result = (Collection)returnType.newInstance();
42
43 }
44
45 DbUtils.resultSetToBeanCollection(rs,type, result);
46
47 return !returnType.isArray() ? result : (Object)result.toArray(
48
49 (Object [])Array.newInstance(
50 returnType.getComponentType(),
51 result.size()
52 )
53 );
54 }
55
56
57 }
This page was automatically generated by Maven