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