KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > ce > auction > test > TransformerTest


1 package org.hibernate.ce.auction.test;
2
3 import junit.framework.Test;
4 import junit.framework.TestSuite;
5 import junit.textui.TestRunner;
6 import org.hibernate.Criteria;
7 import org.hibernate.ce.auction.model.Item;
8 import org.hibernate.ce.auction.persistence.HibernateUtil;
9 import org.hibernate.transform.ResultTransformer;
10
11 import javax.sql.RowSetReader JavaDoc;
12 import javax.sql.RowSet JavaDoc;
13 import javax.sql.RowSetInternal JavaDoc;
14 import javax.sql.rowset.JdbcRowSet JavaDoc;
15 import java.util.Collection JavaDoc;
16 import java.util.Iterator JavaDoc;
17 import java.util.List JavaDoc;
18 import java.sql.SQLException JavaDoc;
19
20 import com.sun.rowset.JdbcRowSetImpl;
21 import com.sun.rowset.CachedRowSetImpl;
22
23 public class TransformerTest extends TestCaseWithData {
24
25     // ********************************************************** //
26

27     public void testTransformer() throws Exception JavaDoc {
28         /*
29         initData();
30
31         // AliasToBeanResultTransformer, DistinctRootEntityResultTransformer <- also nice
32         class JDBCTransformer implements ResultTransformer, RowSetReader {
33
34             public void readData(RowSetInternal rowSetInternal) throws SQLException {
35
36             }
37
38             private Class jdbcRowSetType;
39             int i = 1;
40
41             public JDBCTransformer(Class jdbcRowSetType) {
42                 this.jdbcRowSetType = jdbcRowSetType;
43             }
44
45             public Object transformTuple(Object[] tuple, String[] aliases) {
46                 return tuple.length==1 ? tuple[0] : tuple;
47             }
48
49             public List transformList(List collection) {
50                 try {
51                     CachedRowSetImpl crs = new CachedRowSetImpl();
52                     crs.
53                     RowSetReader input = new RowSetReader();
54                     System.out.println("### TRANSFORM TUPLE: " + tuple);
55                     System.out.println("### TRANSFORM TUPLE ALIASES:" + aliases);
56                     return i++;
57
58                     System.out.println("### TRANFORM LIST: " + collection);
59                     for (Iterator it = collection.iterator(); it.hasNext();) {
60                         Object o = it.next();
61                         System.out.println("### TRANFORM LIST ITEM: " + o);
62                     }
63                 } catch (Exception e) {
64                     throw new RuntimeException(e);
65                 }
66                 return collection;
67             }
68
69         }
70
71         System.out.println("### QUERYING");
72         JDBCTransformer trf = new JDBCTransformer(javax.sql.rowset.JdbcRowSet.class);
73         Criteria items = HibernateUtil.getSession().createCriteria(Item.class);
74         Collection objects = items.setResultTransformer(trf).list();
75         for (Iterator it = objects.iterator(); it.hasNext();) {
76             Object o = it.next();
77             System.out.println("### FINAL RESULT ITEM: " + o);
78         }
79 */

80     }
81
82
83     // ********************************************************** //
84

85     public TransformerTest(String JavaDoc x) {
86         super(x);
87     }
88
89     public static Test suite() {
90         return new TestSuite(TransformerTest.class);
91     }
92
93     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
94         TestRunner.run( suite() );
95     }
96
97 }
98
Popular Tags