1 /*******************************************************************************
2 * Copyright (c) 2005, 2006 Imola Informatica.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the LGPL License v2.1
5 * which accompanies this distribution, and is available at
6 * http://www.gnu.org/licenses/lgpl.html
7 *******************************************************************************/
8 /**
9 *
10 */
11 package it.imolinfo.jbi4cics.test.mapping.jdbc;
12
13 import it.imolinfo.jbi4cics.test.connection.jdbc.util.BaseJdbcTestCase;
14
15 /**
16 * @author raffaele
17 *
18 */
19 public class SimpleJdbcMappingTest extends BaseJdbcTestCase {
20
21 /*private static Log log=LogFactory.getLog(SimpleJdbcMappingTest.class);
22
23 *//**
24 * @param arg0
25 *//*
26 public SimpleJdbcMappingTest(String arg0) {
27 super(arg0);
28 // TODO Auto-generated constructor stub
29 }
30
31 public void testQueryPreparedStatement(){
32 try {
33 //costruisco il parameter descriptor
34 JdbcParameterDescriptor tableTypeParameter=new JdbcParameterDescriptor(JdbcParameterDescriptor.IN_PARAMETER);
35
36 //costruisco lo statement decriptor
37 JdbcStatementDescriptor jdbcStatementDescriptor=new JdbcStatementDescriptor();
38 jdbcStatementDescriptor.addFieldMapping("tableType",new Integer(1),tableTypeParameter);
39 jdbcStatementDescriptor.setStatementType(JdbcStatementDescriptor.PREPARED_STATEMENT);
40 jdbcStatementDescriptor.setSqlType(JdbcStatementDescriptor.SELECT_SQL);
41 jdbcStatementDescriptor.setSql("select TABLEID, TABLENAME, TABLETYPE, SCHEMAID, LOCKGRANULARITY from SYS.SYSTABLES where TABLETYPE=?");
42 jdbcStatementDescriptor.setBeanClass(SysTableParameterBean.class);
43
44 // costrisco il result set mapping descriptor
45 ResultSetMappingDescriptor resultSetMappingDescriptor=new ResultSetMappingDescriptor();
46 resultSetMappingDescriptor.addFieldMapping("tableId","TABLEID",null);
47 resultSetMappingDescriptor.addFieldMapping("tableName","TABLENAME",null);
48 resultSetMappingDescriptor.addFieldMapping("tableType","TABLETYPE",null);
49 resultSetMappingDescriptor.addFieldMapping("schemaId","SCHEMAID",null);
50 resultSetMappingDescriptor.addFieldMapping("lockGranularity","LOCKGRANULARITY",null);
51 resultSetMappingDescriptor.setBeanClass(SysTableRowBean.class);
52
53 // costruisco il mapping descriptor
54 JdbcBeanMappingDescriptor jdbcBeanMappingDescriptor=new JdbcBeanMappingDescriptor();
55 jdbcBeanMappingDescriptor.setJdbcStatementDescriptor(jdbcStatementDescriptor);
56 jdbcBeanMappingDescriptor.setResultSetMappingDescriptor(resultSetMappingDescriptor);
57 jdbcBeanMappingDescriptor.setResultSetPropertyName("rowBeans");
58
59 // costruisco l'input bean
60 SysTableParameterBean inputBean=new SysTableParameterBean();
61 inputBean.setTableType("S");
62
63 //costruisco il service context
64 //inizializzazione del service context
65 ServiceContext serviceContext=new ServiceContext();
66 serviceContext.setInputMappingDescriptor(jdbcBeanMappingDescriptor);
67 serviceContext.setOutputMappingDescriptor(jdbcBeanMappingDescriptor);
68 serviceContext.setInputBean(inputBean);
69
70
71 // costruisco il jdbc formatter
72 JdbcFormatter jdbcFormatter=new JdbcFormatter();
73
74 // eseguo la formattazione in andata
75 long millis1=System.currentTimeMillis();
76 jdbcFormatter.mapInputBeanToInputMessage(serviceContext);
77 DisconnectedPreparedStatement inputMessage=(DisconnectedPreparedStatement)serviceContext.getInputMessage();
78 long millis2=System.currentTimeMillis();
79 log.debug("input message: "+inputMessage);
80 log.debug("conversion time1="+(millis2-millis1)+" millis");
81
82 // connetto lo statement ed eseguo la query
83 inputMessage.setConnection(conn);
84 inputMessage.setConnected(true);
85 ResultSet rs=inputMessage.executeQuery();
86 log.debug("resultset: "+rs);
87
88 //mi disconnetto
89 inputMessage.setConnected(false);
90 conn.close();
91
92 // costruisco il messaggio di output
93 JdbcOutputMessage jdbcOutputMessage=new JdbcOutputMessage(inputMessage,rs);
94 serviceContext.setOutputMessage(jdbcOutputMessage);
95
96 millis1=System.currentTimeMillis();
97 jdbcFormatter.mapOutputMessageToOutputBean(serviceContext);
98 SysTableParameterBean outputBean=(SysTableParameterBean)serviceContext.getOutputBean();
99 millis2=System.currentTimeMillis();
100
101 log.debug("output bean: "+outputBean);
102 log.debug("conversion time1="+(millis2-millis1)+" millis");
103 }
104 catch(FormatException e){
105 e.printStackTrace();
106 fail(e.getMessage());
107 }
108 catch(SQLException e){
109 e.printStackTrace();
110 fail(e.getMessage());
111 }
112
113 }
114
115 public static class SysTableParameterBean {
116 private String tableType;
117 private Collection rowBeans;
118 *//**
119 * @return Returns the rowBeans.
120 *//*
121 public Collection getRowBeans() {
122 return rowBeans;
123 }
124 *//**
125 * @param rowBeans The rowBeans to set.
126 *//*
127 public void setRowBeans(Collection rowBeans) {
128 this.rowBeans = rowBeans;
129 }
130 *//**
131 * @return Returns the tableType.
132 *//*
133 public String getTableType() {
134 return tableType;
135 }
136 *//**
137 * @param tableType The tableType to set.
138 *//*
139 public void setTableType(String tableType) {
140 this.tableType = tableType;
141 }
142
143 public String toString() {
144 return ReflectionToStringBuilder.toString(this);
145 }
146
147 public boolean equals(Object obj) {
148 return EqualsBuilder.reflectionEquals(this, obj);
149 }
150
151 }
152
153 public static class SysTableRowBean {
154 private String tableId;
155 private String tableName;
156 private String tableType;
157 private String schemaId;
158 private String lockGranularity;
159 *//**
160 * @return Returns the lockGranularity.
161 *//*
162 public String getLockGranularity() {
163 return lockGranularity;
164 }
165 *//**
166 * @param lockGranularity The lockGranularity to set.
167 *//*
168 public void setLockGranularity(String lockGranularity) {
169 this.lockGranularity = lockGranularity;
170 }
171 *//**
172 * @return Returns the schemaId.
173 *//*
174 public String getSchemaId() {
175 return schemaId;
176 }
177 *//**
178 * @param schemaId The schemaId to set.
179 *//*
180 public void setSchemaId(String schemaId) {
181 this.schemaId = schemaId;
182 }
183 *//**
184 * @return Returns the tableId.
185 *//*
186 public String getTableId() {
187 return tableId;
188 }
189 *//**
190 * @param tableId The tableId to set.
191 *//*
192 public void setTableId(String tableId) {
193 this.tableId = tableId;
194 }
195 *//**
196 * @return Returns the tableName.
197 *//*
198 public String getTableName() {
199 return tableName;
200 }
201 *//**
202 * @param tableName The tableName to set.
203 *//*
204 public void setTableName(String tableName) {
205 this.tableName = tableName;
206 }
207 *//**
208 * @return Returns the tableType.
209 *//*
210 public String getTableType() {
211 return tableType;
212 }
213 *//**
214 * @param tableType The tableType to set.
215 *//*
216 public void setTableType(String tableType) {
217 this.tableType = tableType;
218 }
219
220 public String toString() {
221 return ReflectionToStringBuilder.toString(this);
222 }
223
224 public boolean equals(Object obj) {
225 return EqualsBuilder.reflectionEquals(this, obj);
226 }
227
228 }
229 */
230 }