xref: /AOO41X/main/qadevOOo/tests/java/ifc/sdbc/_XRowUpdate.java (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir package ifc.sdbc;
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir import java.util.Vector;
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir import lib.MultiMethodTest;
33*cdf0e10cSrcweir import lib.Status;
34*cdf0e10cSrcweir import util.ValueComparer;
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir import com.sun.star.io.XDataInputStream;
37*cdf0e10cSrcweir import com.sun.star.io.XInputStream;
38*cdf0e10cSrcweir import com.sun.star.io.XTextInputStream;
39*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
40*cdf0e10cSrcweir import com.sun.star.sdbc.SQLException;
41*cdf0e10cSrcweir import com.sun.star.sdbc.XRow;
42*cdf0e10cSrcweir import com.sun.star.sdbc.XRowUpdate;
43*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
44*cdf0e10cSrcweir import com.sun.star.util.Date;
45*cdf0e10cSrcweir import com.sun.star.util.DateTime;
46*cdf0e10cSrcweir import com.sun.star.util.Time;
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir /**
49*cdf0e10cSrcweir * Testing <code>com.sun.star.sdbc.XRowUpdate</code>
50*cdf0e10cSrcweir * interface methods :
51*cdf0e10cSrcweir * <ul>
52*cdf0e10cSrcweir *  <li><code> updateNull()</code></li>
53*cdf0e10cSrcweir *  <li><code> updateBoolean()</code></li>
54*cdf0e10cSrcweir *  <li><code> updateByte()</code></li>
55*cdf0e10cSrcweir *  <li><code> updateShort()</code></li>
56*cdf0e10cSrcweir *  <li><code> updateInt()</code></li>
57*cdf0e10cSrcweir *  <li><code> updateLong()</code></li>
58*cdf0e10cSrcweir *  <li><code> updateFloat()</code></li>
59*cdf0e10cSrcweir *  <li><code> updateDouble()</code></li>
60*cdf0e10cSrcweir *  <li><code> updateString()</code></li>
61*cdf0e10cSrcweir *  <li><code> updateBytes()</code></li>
62*cdf0e10cSrcweir *  <li><code> updateDate()</code></li>
63*cdf0e10cSrcweir *  <li><code> updateTime()</code></li>
64*cdf0e10cSrcweir *  <li><code> updateTimestamp()</code></li>
65*cdf0e10cSrcweir *  <li><code> updateBinaryStream()</code></li>
66*cdf0e10cSrcweir *  <li><code> updateCharacterStream()</code></li>
67*cdf0e10cSrcweir *  <li><code> updateObject()</code></li>
68*cdf0e10cSrcweir *  <li><code> updateNumericObject()</code></li>
69*cdf0e10cSrcweir * </ul> <p>
70*cdf0e10cSrcweir * Object relations required :
71*cdf0e10cSrcweir * <ul>
72*cdf0e10cSrcweir * <li> <code>'CurrentRowData'</code> : (may be used in other
73*cdf0e10cSrcweir *   interface tests) is a <code>java.util.Vector</code> object
74*cdf0e10cSrcweir *   that contains column types and values in current row. Each
75*cdf0e10cSrcweir *   element of vector corresponds to appropriate column (element
76*cdf0e10cSrcweir *   with index 0 to column 1, 1 -> 2, etc.). <p>
77*cdf0e10cSrcweir *   The following <code>XRowUpdate</code> methods correspond to classes
78*cdf0e10cSrcweir *   in Vector :
79*cdf0e10cSrcweir *   <ul>
80*cdf0e10cSrcweir *   <li> <code>setBinaryStream</code> -
81*cdf0e10cSrcweir *        <code>com.sun.star.io.XDataInputStream</code> class. </li>
82*cdf0e10cSrcweir *   <li> <code>setCharacterStream</code> -
83*cdf0e10cSrcweir *        <code>com.sun.star.io.XTextInputStream</code> class. </li>
84*cdf0e10cSrcweir *   <li> <code>setObject</code> -
85*cdf0e10cSrcweir *        <code>java.lang.Object[]</code> class, the element with
86*cdf0e10cSrcweir *         index 0 must be used. </li>
87*cdf0e10cSrcweir *   </ul>
88*cdf0e10cSrcweir *   Other methods uses types they return (i.e. <code>java.lang.String</code>
89*cdf0e10cSrcweir *   for <code>setString</code> method, <code>com.sun.star.sdbc.XRef</code>
90*cdf0e10cSrcweir *   for <code>setRef</code> method).
91*cdf0e10cSrcweir * </li>
92*cdf0e10cSrcweir * <li> <code>'XRowUpdate.XRow'</code> : implementation of <code>
93*cdf0e10cSrcweir *   com.sun.star.sdbc.XRow</code> interface for checking updated data.
94*cdf0e10cSrcweir * </li>
95*cdf0e10cSrcweir * </ul> <p>
96*cdf0e10cSrcweir * The test <b>damages</b> the object, so it is recreated finally.
97*cdf0e10cSrcweir * @see com.sun.star.sdbc.XRowUpdate
98*cdf0e10cSrcweir * @see com.sun.star.sdbc.XRow
99*cdf0e10cSrcweir */
100*cdf0e10cSrcweir public class _XRowUpdate extends MultiMethodTest {
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir     // oObj filled by MultiMethodTest
103*cdf0e10cSrcweir     public XRowUpdate oObj = null ;
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir     private Vector rowData = null ;
106*cdf0e10cSrcweir     private XRow row = null ;
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir     /**
109*cdf0e10cSrcweir     * Gets relations.
110*cdf0e10cSrcweir     */
111*cdf0e10cSrcweir     public void before() {
112*cdf0e10cSrcweir         rowData = (Vector) tEnv.getObjRelation("CurrentRowData") ;
113*cdf0e10cSrcweir         if (rowData == null) {
114*cdf0e10cSrcweir             log.println("!!! 'CurrentRowData' relation not found !!!") ;
115*cdf0e10cSrcweir         }
116*cdf0e10cSrcweir         row = (XRow) tEnv.getObjRelation("XRowUpdate.XRow") ;
117*cdf0e10cSrcweir         if (rowData == null) {
118*cdf0e10cSrcweir             log.println("!!! 'XRowUpdate.XRow' relation not found !!!") ;
119*cdf0e10cSrcweir         }
120*cdf0e10cSrcweir     }
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir     /**
123*cdf0e10cSrcweir     * Try to set NULL value for each column. Then using <code>XRow</code>
124*cdf0e10cSrcweir     * relation check if NULL was really set. <p>
125*cdf0e10cSrcweir     * Has OK status if for every column NULL value was successfully set.
126*cdf0e10cSrcweir     * @see com.sun.star.sdbc.XRow
127*cdf0e10cSrcweir     */
128*cdf0e10cSrcweir     public void _updateNull() {
129*cdf0e10cSrcweir         boolean result = true ;
130*cdf0e10cSrcweir         for (int i = 0; i < rowData.size(); i++) {
131*cdf0e10cSrcweir             if (rowData.get(i) == null) continue ;
132*cdf0e10cSrcweir             log.print("  Setting NULL at column #" + (i+1) + " ...") ;
133*cdf0e10cSrcweir             try {
134*cdf0e10cSrcweir                 oObj.updateNull(i + 1) ;
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir                 if (rowData.get(i) instanceof String) row.getString(i + 1) ;
137*cdf0e10cSrcweir                 if (rowData.get(i) instanceof Boolean) row.getBoolean(i + 1) ;
138*cdf0e10cSrcweir                 if (rowData.get(i) instanceof Byte) row.getByte(i + 1) ;
139*cdf0e10cSrcweir                 if (rowData.get(i) instanceof Short) row.getShort(i + 1) ;
140*cdf0e10cSrcweir                 if (rowData.get(i) instanceof Integer) row.getInt(i + 1) ;
141*cdf0e10cSrcweir                 if (rowData.get(i) instanceof Long) row.getLong(i + 1) ;
142*cdf0e10cSrcweir                 if (rowData.get(i) instanceof Float) row.getFloat(i + 1) ;
143*cdf0e10cSrcweir                 if (rowData.get(i) instanceof Double) row.getDouble(i + 1) ;
144*cdf0e10cSrcweir                 if (rowData.get(i) instanceof byte[]) row.getBytes(i + 1) ;
145*cdf0e10cSrcweir                 if (rowData.get(i) instanceof Date) row.getDate(i + 1) ;
146*cdf0e10cSrcweir                 if (rowData.get(i) instanceof Time) row.getTime(i + 1) ;
147*cdf0e10cSrcweir                 if (rowData.get(i) instanceof DateTime)
148*cdf0e10cSrcweir                     row.getTimestamp(i + 1) ;
149*cdf0e10cSrcweir                 if (rowData.get(i) instanceof XDataInputStream)
150*cdf0e10cSrcweir                     row.getBinaryStream(i + 1) ;
151*cdf0e10cSrcweir                 if (rowData.get(i) instanceof XTextInputStream)
152*cdf0e10cSrcweir                     row.getCharacterStream(i + 1) ;
153*cdf0e10cSrcweir                 //if (rowData.get(i) instanceof Object[]) row.getObject(i) ;
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir                 if (!row.wasNull()) {
156*cdf0e10cSrcweir                     log.println("FAILED") ;
157*cdf0e10cSrcweir                     log.println("Not NULL was returned !!!") ;
158*cdf0e10cSrcweir                     result = false ;
159*cdf0e10cSrcweir                 } else {
160*cdf0e10cSrcweir                     log.println("OK") ;
161*cdf0e10cSrcweir                 }
162*cdf0e10cSrcweir             } catch (SQLException e) {
163*cdf0e10cSrcweir                 log.println("FAILED") ;
164*cdf0e10cSrcweir                 e.printStackTrace(log) ;
165*cdf0e10cSrcweir                 result = false ;
166*cdf0e10cSrcweir             }
167*cdf0e10cSrcweir         }
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir         tRes.tested("updateNull()", result) ;
170*cdf0e10cSrcweir     }
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir     /**
173*cdf0e10cSrcweir     * Updates column with the appropriate type (if exists) and then
174*cdf0e10cSrcweir     * checks result with interface <code>XRow</code>.<p>
175*cdf0e10cSrcweir     * Has OK status if column successfully updated, ahd the same
176*cdf0e10cSrcweir     * result returned.
177*cdf0e10cSrcweir     */
178*cdf0e10cSrcweir     public void _updateBoolean() {
179*cdf0e10cSrcweir         boolean result = true ;
180*cdf0e10cSrcweir         int idx = findColumnOfType(Boolean.class) ;
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir         if (idx < 0) {
183*cdf0e10cSrcweir             log.println("Required type not found") ;
184*cdf0e10cSrcweir             tRes.tested("updateBoolean()", Status.skipped(true)) ;
185*cdf0e10cSrcweir             return ;
186*cdf0e10cSrcweir         }
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir         try {
189*cdf0e10cSrcweir             boolean newVal = !row.getBoolean(idx) ;
190*cdf0e10cSrcweir             oObj.updateBoolean(idx, newVal) ;
191*cdf0e10cSrcweir             boolean getVal = row.getBoolean(idx) ;
192*cdf0e10cSrcweir             result = newVal == getVal ;
193*cdf0e10cSrcweir         } catch (SQLException e) {
194*cdf0e10cSrcweir             e.printStackTrace(log) ;
195*cdf0e10cSrcweir             result = false ;
196*cdf0e10cSrcweir         }
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir         tRes.tested("updateBoolean()", result) ;
199*cdf0e10cSrcweir     }
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir     /**
202*cdf0e10cSrcweir     * Updates column with the appropriate type (if exists) and then
203*cdf0e10cSrcweir     * checks result with interface <code>XRow</code>.<p>
204*cdf0e10cSrcweir     * Has OK status if column successfully updated, ahd the same
205*cdf0e10cSrcweir     * result returned.
206*cdf0e10cSrcweir     */
207*cdf0e10cSrcweir     public void _updateByte() {
208*cdf0e10cSrcweir         boolean result = true ;
209*cdf0e10cSrcweir         int idx = findColumnOfType(Byte.class) ;
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir         if (idx < 0) {
212*cdf0e10cSrcweir             log.println("Required type not found") ;
213*cdf0e10cSrcweir             tRes.tested("updateByte()", Status.skipped(true)) ;
214*cdf0e10cSrcweir             return ;
215*cdf0e10cSrcweir         }
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir         try {
218*cdf0e10cSrcweir             byte newVal = (byte) (row.getByte(idx) + 1) ;
219*cdf0e10cSrcweir             oObj.updateByte(idx, newVal) ;
220*cdf0e10cSrcweir             byte getVal = row.getByte(idx) ;
221*cdf0e10cSrcweir             result = newVal == getVal ;
222*cdf0e10cSrcweir         } catch (SQLException e) {
223*cdf0e10cSrcweir             e.printStackTrace(log) ;
224*cdf0e10cSrcweir             result = false ;
225*cdf0e10cSrcweir         }
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir         tRes.tested("updateByte()", result) ;
228*cdf0e10cSrcweir     }
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir     /**
231*cdf0e10cSrcweir     * Updates column with the appropriate type (if exists) and then
232*cdf0e10cSrcweir     * checks result with interface <code>XRow</code>.<p>
233*cdf0e10cSrcweir     * Has OK status if column successfully updated, ahd the same
234*cdf0e10cSrcweir     * result returned.
235*cdf0e10cSrcweir     */
236*cdf0e10cSrcweir     public void _updateShort() {
237*cdf0e10cSrcweir         boolean result = true ;
238*cdf0e10cSrcweir         int idx = findColumnOfType(Short.class) ;
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir         if (idx < 0) {
241*cdf0e10cSrcweir             log.println("Required type not found") ;
242*cdf0e10cSrcweir             tRes.tested("updateShort()", Status.skipped(true)) ;
243*cdf0e10cSrcweir             return ;
244*cdf0e10cSrcweir         }
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir         try {
247*cdf0e10cSrcweir             short newVal = (short) (row.getShort(idx) + 1) ;
248*cdf0e10cSrcweir             oObj.updateShort(idx, newVal) ;
249*cdf0e10cSrcweir             short getVal = row.getShort(idx) ;
250*cdf0e10cSrcweir             result = newVal == getVal ;
251*cdf0e10cSrcweir         } catch (SQLException e) {
252*cdf0e10cSrcweir             e.printStackTrace(log) ;
253*cdf0e10cSrcweir             result = false ;
254*cdf0e10cSrcweir         }
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir         tRes.tested("updateShort()", result) ;
257*cdf0e10cSrcweir     }
258*cdf0e10cSrcweir 
259*cdf0e10cSrcweir     /**
260*cdf0e10cSrcweir     * Updates column with the appropriate type (if exists) and then
261*cdf0e10cSrcweir     * checks result with interface <code>XRow</code>.<p>
262*cdf0e10cSrcweir     * Has OK status if column successfully updated, ahd the same
263*cdf0e10cSrcweir     * result returned.
264*cdf0e10cSrcweir     */
265*cdf0e10cSrcweir     public void _updateInt() {
266*cdf0e10cSrcweir         boolean result = true ;
267*cdf0e10cSrcweir         int idx = findColumnOfType(Integer.class) ;
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir         if (idx < 0) {
270*cdf0e10cSrcweir             log.println("Required type not found") ;
271*cdf0e10cSrcweir             tRes.tested("updateInt()", Status.skipped(true)) ;
272*cdf0e10cSrcweir             return ;
273*cdf0e10cSrcweir         }
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir         try {
276*cdf0e10cSrcweir             int newVal = 1 + row.getInt(idx)  ;
277*cdf0e10cSrcweir             oObj.updateInt(idx, newVal) ;
278*cdf0e10cSrcweir             int getVal = row.getInt(idx) ;
279*cdf0e10cSrcweir             result = newVal == getVal ;
280*cdf0e10cSrcweir         } catch (SQLException e) {
281*cdf0e10cSrcweir             e.printStackTrace(log) ;
282*cdf0e10cSrcweir             result = false ;
283*cdf0e10cSrcweir         }
284*cdf0e10cSrcweir 
285*cdf0e10cSrcweir         tRes.tested("updateInt()", result) ;
286*cdf0e10cSrcweir     }
287*cdf0e10cSrcweir 
288*cdf0e10cSrcweir     /**
289*cdf0e10cSrcweir     * Updates column with the appropriate type (if exists) and then
290*cdf0e10cSrcweir     * checks result with interface <code>XRow</code>.<p>
291*cdf0e10cSrcweir     * Has OK status if column successfully updated, ahd the same
292*cdf0e10cSrcweir     * result returned.
293*cdf0e10cSrcweir     */
294*cdf0e10cSrcweir     public void _updateLong() {
295*cdf0e10cSrcweir         boolean result = true ;
296*cdf0e10cSrcweir         int idx = findColumnOfType(Long.class) ;
297*cdf0e10cSrcweir 
298*cdf0e10cSrcweir         if (idx < 0) {
299*cdf0e10cSrcweir             log.println("Required type not found") ;
300*cdf0e10cSrcweir             tRes.tested("updateLong()", Status.skipped(true)) ;
301*cdf0e10cSrcweir             return ;
302*cdf0e10cSrcweir         }
303*cdf0e10cSrcweir 
304*cdf0e10cSrcweir         try {
305*cdf0e10cSrcweir             long newVal = 1 + row.getLong(idx) ;
306*cdf0e10cSrcweir             oObj.updateLong(idx, newVal) ;
307*cdf0e10cSrcweir             long getVal = row.getLong(idx) ;
308*cdf0e10cSrcweir             result = newVal == getVal ;
309*cdf0e10cSrcweir         } catch (SQLException e) {
310*cdf0e10cSrcweir             e.printStackTrace(log) ;
311*cdf0e10cSrcweir             result = false ;
312*cdf0e10cSrcweir         }
313*cdf0e10cSrcweir 
314*cdf0e10cSrcweir         tRes.tested("updateLong()", result) ;
315*cdf0e10cSrcweir     }
316*cdf0e10cSrcweir 
317*cdf0e10cSrcweir     /**
318*cdf0e10cSrcweir     * Updates column with the appropriate type (if exists) and then
319*cdf0e10cSrcweir     * checks result with interface <code>XRow</code>.<p>
320*cdf0e10cSrcweir     * Has OK status if column successfully updated, ahd the same
321*cdf0e10cSrcweir     * result returned.
322*cdf0e10cSrcweir     */
323*cdf0e10cSrcweir     public void _updateFloat() {
324*cdf0e10cSrcweir         boolean result = true ;
325*cdf0e10cSrcweir         int idx = findColumnOfType(Float.class) ;
326*cdf0e10cSrcweir 
327*cdf0e10cSrcweir         if (idx < 0) {
328*cdf0e10cSrcweir             log.println("Required type not found") ;
329*cdf0e10cSrcweir             tRes.tested("updateFloat()", Status.skipped(true)) ;
330*cdf0e10cSrcweir             return ;
331*cdf0e10cSrcweir         }
332*cdf0e10cSrcweir 
333*cdf0e10cSrcweir         try {
334*cdf0e10cSrcweir             float newVal = (float) (1.1 + row.getFloat(idx));
335*cdf0e10cSrcweir             oObj.updateFloat(idx, newVal) ;
336*cdf0e10cSrcweir             float getVal = row.getFloat(idx) ;
337*cdf0e10cSrcweir             result = newVal == getVal ;
338*cdf0e10cSrcweir         } catch (SQLException e) {
339*cdf0e10cSrcweir             e.printStackTrace(log) ;
340*cdf0e10cSrcweir             result = false ;
341*cdf0e10cSrcweir         }
342*cdf0e10cSrcweir 
343*cdf0e10cSrcweir         tRes.tested("updateFloat()", result) ;
344*cdf0e10cSrcweir     }
345*cdf0e10cSrcweir 
346*cdf0e10cSrcweir     /**
347*cdf0e10cSrcweir     * Updates column with the appropriate type (if exists) and then
348*cdf0e10cSrcweir     * checks result with interface <code>XRow</code>.<p>
349*cdf0e10cSrcweir     * Has OK status if column successfully updated, ahd the same
350*cdf0e10cSrcweir     * result returned.
351*cdf0e10cSrcweir     */
352*cdf0e10cSrcweir     public void _updateDouble() {
353*cdf0e10cSrcweir         boolean result = true ;
354*cdf0e10cSrcweir         int idx = findColumnOfType(Double.class) ;
355*cdf0e10cSrcweir 
356*cdf0e10cSrcweir         if (idx < 0) {
357*cdf0e10cSrcweir             log.println("Required type not found") ;
358*cdf0e10cSrcweir             tRes.tested("updateDouble()", Status.skipped(true)) ;
359*cdf0e10cSrcweir             return ;
360*cdf0e10cSrcweir         }
361*cdf0e10cSrcweir 
362*cdf0e10cSrcweir         try {
363*cdf0e10cSrcweir             double newVal = 1.1 + row.getDouble(idx) ;
364*cdf0e10cSrcweir             oObj.updateDouble(idx, newVal) ;
365*cdf0e10cSrcweir             double getVal = row.getDouble(idx) ;
366*cdf0e10cSrcweir             result = newVal == getVal ;
367*cdf0e10cSrcweir         } catch (SQLException e) {
368*cdf0e10cSrcweir             e.printStackTrace(log) ;
369*cdf0e10cSrcweir             result = false ;
370*cdf0e10cSrcweir         }
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir         tRes.tested("updateDouble()", result) ;
373*cdf0e10cSrcweir     }
374*cdf0e10cSrcweir 
375*cdf0e10cSrcweir     /**
376*cdf0e10cSrcweir     * Updates column with the appropriate type (if exists) and then
377*cdf0e10cSrcweir     * checks result with interface <code>XRow</code>.<p>
378*cdf0e10cSrcweir     * Has OK status if column successfully updated, ahd the same
379*cdf0e10cSrcweir     * result returned.
380*cdf0e10cSrcweir     */
381*cdf0e10cSrcweir     public void _updateString() {
382*cdf0e10cSrcweir         boolean result = true ;
383*cdf0e10cSrcweir         int idx = findColumnOfType(String.class) ;
384*cdf0e10cSrcweir 
385*cdf0e10cSrcweir         if (idx < 0) {
386*cdf0e10cSrcweir             log.println("Required type not found") ;
387*cdf0e10cSrcweir             tRes.tested("updateString()", Status.skipped(true)) ;
388*cdf0e10cSrcweir             return ;
389*cdf0e10cSrcweir         }
390*cdf0e10cSrcweir 
391*cdf0e10cSrcweir         try {
392*cdf0e10cSrcweir             String newVal = "_" + row.getString(idx) ;
393*cdf0e10cSrcweir             oObj.updateString(idx, newVal) ;
394*cdf0e10cSrcweir             String getVal = row.getString(idx) ;
395*cdf0e10cSrcweir             result = newVal.equals(getVal) ;
396*cdf0e10cSrcweir             log.println("New value = '" + newVal + "', get value = '"
397*cdf0e10cSrcweir                 + getVal + "'") ;
398*cdf0e10cSrcweir         } catch (SQLException e) {
399*cdf0e10cSrcweir             e.printStackTrace(log) ;
400*cdf0e10cSrcweir             result = false ;
401*cdf0e10cSrcweir         }
402*cdf0e10cSrcweir 
403*cdf0e10cSrcweir         tRes.tested("updateString()", result) ;
404*cdf0e10cSrcweir     }
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir     /**
407*cdf0e10cSrcweir     * Updates column with the appropriate type (if exists) and then
408*cdf0e10cSrcweir     * checks result with interface <code>XRow</code>.<p>
409*cdf0e10cSrcweir     * Has OK status if column successfully updated, ahd the same
410*cdf0e10cSrcweir     * result returned.
411*cdf0e10cSrcweir     */
412*cdf0e10cSrcweir     public void _updateBytes() {
413*cdf0e10cSrcweir         boolean result = true ;
414*cdf0e10cSrcweir         int idx = findColumnOfType(byte[].class) ;
415*cdf0e10cSrcweir 
416*cdf0e10cSrcweir         if (idx < 0) {
417*cdf0e10cSrcweir             log.println("Required type not found") ;
418*cdf0e10cSrcweir             tRes.tested("updateBytes()", Status.skipped(true)) ;
419*cdf0e10cSrcweir             return ;
420*cdf0e10cSrcweir         }
421*cdf0e10cSrcweir 
422*cdf0e10cSrcweir         try {
423*cdf0e10cSrcweir             byte[] newVal = row.getBytes(idx) ;
424*cdf0e10cSrcweir             if (newVal == null || newVal.length == 0) {
425*cdf0e10cSrcweir                 newVal = new byte[] {34, 111, 98} ;
426*cdf0e10cSrcweir             } else {
427*cdf0e10cSrcweir                 newVal = new byte[] {(byte) (newVal[0] + 1), 111, 98} ;
428*cdf0e10cSrcweir             }
429*cdf0e10cSrcweir             oObj.updateBytes(idx, newVal) ;
430*cdf0e10cSrcweir             byte[] getVal = row.getBytes(idx) ;
431*cdf0e10cSrcweir             result = ValueComparer.equalValue(newVal, getVal) ;
432*cdf0e10cSrcweir         } catch (SQLException e) {
433*cdf0e10cSrcweir             e.printStackTrace(log) ;
434*cdf0e10cSrcweir             result = false ;
435*cdf0e10cSrcweir         }
436*cdf0e10cSrcweir 
437*cdf0e10cSrcweir         tRes.tested("updateBytes()", result) ;
438*cdf0e10cSrcweir     }
439*cdf0e10cSrcweir 
440*cdf0e10cSrcweir     /**
441*cdf0e10cSrcweir     * Updates column with the appropriate type (if exists) and then
442*cdf0e10cSrcweir     * checks result with interface <code>XRow</code>.<p>
443*cdf0e10cSrcweir     * Has OK status if column successfully updated, ahd the same
444*cdf0e10cSrcweir     * result returned.
445*cdf0e10cSrcweir     */
446*cdf0e10cSrcweir     public void _updateDate() {
447*cdf0e10cSrcweir         boolean result = true ;
448*cdf0e10cSrcweir         int idx = findColumnOfType(Date.class) ;
449*cdf0e10cSrcweir 
450*cdf0e10cSrcweir         if (idx < 0) {
451*cdf0e10cSrcweir             log.println("Required type not found") ;
452*cdf0e10cSrcweir             tRes.tested("updateDate()", Status.skipped(true)) ;
453*cdf0e10cSrcweir             return ;
454*cdf0e10cSrcweir         }
455*cdf0e10cSrcweir 
456*cdf0e10cSrcweir         try {
457*cdf0e10cSrcweir             Date newVal = row.getDate(idx) ;
458*cdf0e10cSrcweir             newVal.Year ++ ;
459*cdf0e10cSrcweir             oObj.updateDate(idx, newVal) ;
460*cdf0e10cSrcweir             Date getVal = row.getDate(idx) ;
461*cdf0e10cSrcweir             result = ValueComparer.equalValue(newVal, getVal) ;
462*cdf0e10cSrcweir         } catch (SQLException e) {
463*cdf0e10cSrcweir             e.printStackTrace(log) ;
464*cdf0e10cSrcweir             result = false ;
465*cdf0e10cSrcweir         }
466*cdf0e10cSrcweir 
467*cdf0e10cSrcweir         tRes.tested("updateDate()", result) ;
468*cdf0e10cSrcweir     }
469*cdf0e10cSrcweir 
470*cdf0e10cSrcweir     /**
471*cdf0e10cSrcweir     * Updates column with the appropriate type (if exists) and then
472*cdf0e10cSrcweir     * checks result with interface <code>XRow</code>.<p>
473*cdf0e10cSrcweir     * Has OK status if column successfully updated, ahd the same
474*cdf0e10cSrcweir     * result returned.
475*cdf0e10cSrcweir     */
476*cdf0e10cSrcweir     public void _updateTime() {
477*cdf0e10cSrcweir         boolean result = true ;
478*cdf0e10cSrcweir         int idx = findColumnOfType(Time.class) ;
479*cdf0e10cSrcweir 
480*cdf0e10cSrcweir         if (idx < 0) {
481*cdf0e10cSrcweir             log.println("Required type not found") ;
482*cdf0e10cSrcweir             tRes.tested("updateTime()", Status.skipped(true)) ;
483*cdf0e10cSrcweir             return ;
484*cdf0e10cSrcweir         }
485*cdf0e10cSrcweir 
486*cdf0e10cSrcweir         try {
487*cdf0e10cSrcweir             Time newVal = row.getTime(idx) ;
488*cdf0e10cSrcweir             newVal.Seconds ++ ;
489*cdf0e10cSrcweir             oObj.updateTime(idx, newVal) ;
490*cdf0e10cSrcweir             Time getVal = row.getTime(idx) ;
491*cdf0e10cSrcweir             result = ValueComparer.equalValue(newVal, getVal) ;
492*cdf0e10cSrcweir         } catch (SQLException e) {
493*cdf0e10cSrcweir             e.printStackTrace(log) ;
494*cdf0e10cSrcweir             result = false ;
495*cdf0e10cSrcweir         }
496*cdf0e10cSrcweir 
497*cdf0e10cSrcweir         tRes.tested("updateTime()", result) ;
498*cdf0e10cSrcweir     }
499*cdf0e10cSrcweir 
500*cdf0e10cSrcweir     /**
501*cdf0e10cSrcweir     * Updates column with the appropriate type (if exists) and then
502*cdf0e10cSrcweir     * checks result with interface <code>XRow</code>.<p>
503*cdf0e10cSrcweir     * Has OK status if column successfully updated, ahd the same
504*cdf0e10cSrcweir     * result returned.
505*cdf0e10cSrcweir     */
506*cdf0e10cSrcweir     public void _updateTimestamp() {
507*cdf0e10cSrcweir         boolean result = true ;
508*cdf0e10cSrcweir         int idx = findColumnOfType(DateTime.class) ;
509*cdf0e10cSrcweir 
510*cdf0e10cSrcweir         if (idx < 0) {
511*cdf0e10cSrcweir             log.println("Required type not found") ;
512*cdf0e10cSrcweir             tRes.tested("updateTimestamp()", Status.skipped(true)) ;
513*cdf0e10cSrcweir             return ;
514*cdf0e10cSrcweir         }
515*cdf0e10cSrcweir 
516*cdf0e10cSrcweir         try {
517*cdf0e10cSrcweir             DateTime newVal = row.getTimestamp(idx) ;
518*cdf0e10cSrcweir             newVal.Year ++ ;
519*cdf0e10cSrcweir             oObj.updateTimestamp(idx, newVal) ;
520*cdf0e10cSrcweir             DateTime getVal = row.getTimestamp(idx) ;
521*cdf0e10cSrcweir             result = ValueComparer.equalValue(newVal, getVal) ;
522*cdf0e10cSrcweir         } catch (SQLException e) {
523*cdf0e10cSrcweir             e.printStackTrace(log) ;
524*cdf0e10cSrcweir             result = false ;
525*cdf0e10cSrcweir         }
526*cdf0e10cSrcweir 
527*cdf0e10cSrcweir         tRes.tested("updateTimestamp()", result) ;
528*cdf0e10cSrcweir     }
529*cdf0e10cSrcweir 
530*cdf0e10cSrcweir 
531*cdf0e10cSrcweir     /**
532*cdf0e10cSrcweir     * Updates column with the appropriate type (if exists) and then
533*cdf0e10cSrcweir     * checks result with interface <code>XRow</code>.<p>
534*cdf0e10cSrcweir     * Has OK status if column successfully updated, ahd the same
535*cdf0e10cSrcweir     * result returned.
536*cdf0e10cSrcweir     */
537*cdf0e10cSrcweir     public void _updateBinaryStream() {
538*cdf0e10cSrcweir         boolean result = true ;
539*cdf0e10cSrcweir         int idx = findColumnOfType(XDataInputStream.class) ;
540*cdf0e10cSrcweir 
541*cdf0e10cSrcweir         if (idx < 0) {
542*cdf0e10cSrcweir             log.println("Required type not found") ;
543*cdf0e10cSrcweir             tRes.tested("updateBinaryStream()", Status.skipped(true)) ;
544*cdf0e10cSrcweir             return ;
545*cdf0e10cSrcweir         }
546*cdf0e10cSrcweir 
547*cdf0e10cSrcweir         try {
548*cdf0e10cSrcweir             Object oStream = ((XMultiServiceFactory)tParam.getMSF()).
549*cdf0e10cSrcweir                 createInstance("com.sun.star.io.DataInputStream") ;
550*cdf0e10cSrcweir             XInputStream newVal = (XInputStream) UnoRuntime.queryInterface
551*cdf0e10cSrcweir                 (XInputStream.class, oStream);
552*cdf0e10cSrcweir 
553*cdf0e10cSrcweir             oObj.updateBinaryStream(idx, newVal, 0) ;
554*cdf0e10cSrcweir             XInputStream getVal = row.getBinaryStream(idx) ;
555*cdf0e10cSrcweir             result = UnoRuntime.areSame(newVal, getVal) ;
556*cdf0e10cSrcweir         } catch (SQLException e) {
557*cdf0e10cSrcweir             e.printStackTrace(log) ;
558*cdf0e10cSrcweir             result = false ;
559*cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
560*cdf0e10cSrcweir             log.println("Unexpected exception:") ;
561*cdf0e10cSrcweir             e.printStackTrace(log) ;
562*cdf0e10cSrcweir             result = false ;
563*cdf0e10cSrcweir         }
564*cdf0e10cSrcweir 
565*cdf0e10cSrcweir         tRes.tested("updateBinaryStream()", result) ;
566*cdf0e10cSrcweir     }
567*cdf0e10cSrcweir 
568*cdf0e10cSrcweir     /**
569*cdf0e10cSrcweir     * Updates column with the appropriate type (if exists) and then
570*cdf0e10cSrcweir     * checks result with interface <code>XRow</code>.<p>
571*cdf0e10cSrcweir     * Has OK status if column successfully updated, ahd the same
572*cdf0e10cSrcweir     * result returned.
573*cdf0e10cSrcweir     */
574*cdf0e10cSrcweir     public void _updateCharacterStream() {
575*cdf0e10cSrcweir         boolean result = true ;
576*cdf0e10cSrcweir         int idx = findColumnOfType(XTextInputStream.class) ;
577*cdf0e10cSrcweir 
578*cdf0e10cSrcweir         if (idx < 0) {
579*cdf0e10cSrcweir             log.println("Required type not found") ;
580*cdf0e10cSrcweir             tRes.tested("updateCharacterStream()", Status.skipped(true)) ;
581*cdf0e10cSrcweir             return ;
582*cdf0e10cSrcweir         }
583*cdf0e10cSrcweir 
584*cdf0e10cSrcweir         try {
585*cdf0e10cSrcweir             Object oStream = ((XMultiServiceFactory)tParam.getMSF()).
586*cdf0e10cSrcweir                 createInstance("com.sun.star.io.TextInputStream") ;
587*cdf0e10cSrcweir             XInputStream newVal = (XInputStream) UnoRuntime.queryInterface
588*cdf0e10cSrcweir                 (XInputStream.class, oStream);
589*cdf0e10cSrcweir 
590*cdf0e10cSrcweir             oObj.updateCharacterStream(idx, newVal, 0) ;
591*cdf0e10cSrcweir             XInputStream getVal = row.getCharacterStream(idx) ;
592*cdf0e10cSrcweir             result = UnoRuntime.areSame(newVal, getVal) ;
593*cdf0e10cSrcweir         } catch (SQLException e) {
594*cdf0e10cSrcweir             e.printStackTrace(log) ;
595*cdf0e10cSrcweir             result = false ;
596*cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
597*cdf0e10cSrcweir             log.println("Unexpected exception:") ;
598*cdf0e10cSrcweir             e.printStackTrace(log) ;
599*cdf0e10cSrcweir             result = false ;
600*cdf0e10cSrcweir         }
601*cdf0e10cSrcweir 
602*cdf0e10cSrcweir         tRes.tested("updateCharacterStream()", result) ;
603*cdf0e10cSrcweir     }
604*cdf0e10cSrcweir 
605*cdf0e10cSrcweir     /**
606*cdf0e10cSrcweir     * Updates column with the appropriate type (if exists) and then
607*cdf0e10cSrcweir     * checks result with interface <code>XRow</code>.<p>
608*cdf0e10cSrcweir     * Has OK status if column successfully updated, ahd the same
609*cdf0e10cSrcweir     * result returned.
610*cdf0e10cSrcweir     */
611*cdf0e10cSrcweir     public void _updateObject() {
612*cdf0e10cSrcweir         boolean result = true ;
613*cdf0e10cSrcweir         int idx = findColumnOfType(Object[].class) ;
614*cdf0e10cSrcweir 
615*cdf0e10cSrcweir         if (idx < 0) {
616*cdf0e10cSrcweir             log.println("Required type not found") ;
617*cdf0e10cSrcweir             tRes.tested("updateObject()", Status.skipped(true)) ;
618*cdf0e10cSrcweir             return ;
619*cdf0e10cSrcweir         }
620*cdf0e10cSrcweir 
621*cdf0e10cSrcweir         try {
622*cdf0e10cSrcweir             Object newVal = ((XMultiServiceFactory)tParam.getMSF()).
623*cdf0e10cSrcweir                 createInstance("com.sun.star.io.Pipe") ;
624*cdf0e10cSrcweir 
625*cdf0e10cSrcweir             oObj.updateObject(idx, newVal) ;
626*cdf0e10cSrcweir             //Object getVal = row.getObject(idx) ;
627*cdf0e10cSrcweir             //result = UnoRuntime.areSame(newVal, getVal) ;
628*cdf0e10cSrcweir         } catch (SQLException e) {
629*cdf0e10cSrcweir             e.printStackTrace(log) ;
630*cdf0e10cSrcweir             result = false ;
631*cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
632*cdf0e10cSrcweir             log.println("Unexpected exception:") ;
633*cdf0e10cSrcweir             e.printStackTrace(log) ;
634*cdf0e10cSrcweir             result = false ;
635*cdf0e10cSrcweir         }
636*cdf0e10cSrcweir 
637*cdf0e10cSrcweir         tRes.tested("updateObject()", result) ;
638*cdf0e10cSrcweir     }
639*cdf0e10cSrcweir 
640*cdf0e10cSrcweir     /**
641*cdf0e10cSrcweir     * Updates column with the appropriate type (if exists) and then
642*cdf0e10cSrcweir     * checks result with interface <code>XRow</code>.<p>
643*cdf0e10cSrcweir     * Has OK status if column successfully updated, ahd the same
644*cdf0e10cSrcweir     * result returned.
645*cdf0e10cSrcweir     */
646*cdf0e10cSrcweir     public void _updateNumericObject() {
647*cdf0e10cSrcweir         boolean result = true ;
648*cdf0e10cSrcweir         int idx = findColumnOfType(Object[].class) ;
649*cdf0e10cSrcweir 
650*cdf0e10cSrcweir         if (idx < 0) {
651*cdf0e10cSrcweir             log.println("Required type not found") ;
652*cdf0e10cSrcweir             tRes.tested("updateNumericObject()", Status.skipped(true)) ;
653*cdf0e10cSrcweir             return ;
654*cdf0e10cSrcweir         }
655*cdf0e10cSrcweir 
656*cdf0e10cSrcweir         try {
657*cdf0e10cSrcweir             Object newVal = ((XMultiServiceFactory)tParam.getMSF()).
658*cdf0e10cSrcweir                                 createInstance("com.sun.star.io.Pipe") ;
659*cdf0e10cSrcweir 
660*cdf0e10cSrcweir             oObj.updateNumericObject(idx, newVal, 0) ;
661*cdf0e10cSrcweir             //Object getVal = row.getObject(idx) ;
662*cdf0e10cSrcweir             //result = UnoRuntime.areSame(newVal, getVal) ;
663*cdf0e10cSrcweir         } catch (SQLException e) {
664*cdf0e10cSrcweir             e.printStackTrace(log) ;
665*cdf0e10cSrcweir             result = false ;
666*cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
667*cdf0e10cSrcweir             log.println("Unexpected exception:") ;
668*cdf0e10cSrcweir             e.printStackTrace(log) ;
669*cdf0e10cSrcweir             result = false ;
670*cdf0e10cSrcweir         }
671*cdf0e10cSrcweir 
672*cdf0e10cSrcweir         tRes.tested("updateNumericObject()", result) ;
673*cdf0e10cSrcweir     }
674*cdf0e10cSrcweir 
675*cdf0e10cSrcweir     /**
676*cdf0e10cSrcweir     * Finds in relation vector index of column of the appropriate
677*cdf0e10cSrcweir     * type.
678*cdf0e10cSrcweir     */
679*cdf0e10cSrcweir     protected int findColumnOfType(Class clz) {
680*cdf0e10cSrcweir 
681*cdf0e10cSrcweir         for (int i = 0; i < rowData.size(); i++)
682*cdf0e10cSrcweir             if (clz.isInstance(rowData.get(i))) return i + 1 ;
683*cdf0e10cSrcweir         return -1 ;
684*cdf0e10cSrcweir     }
685*cdf0e10cSrcweir 
686*cdf0e10cSrcweir     /**
687*cdf0e10cSrcweir     * Disposes environment.
688*cdf0e10cSrcweir     */
689*cdf0e10cSrcweir     public void after() {
690*cdf0e10cSrcweir         disposeEnvironment() ;
691*cdf0e10cSrcweir     }
692*cdf0e10cSrcweir 
693*cdf0e10cSrcweir }  // finish class _XRow
694*cdf0e10cSrcweir 
695*cdf0e10cSrcweir 
696