1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package ifc.sdbcx;
25 
26 import lib.MultiMethodTest;
27 import lib.Status;
28 import lib.StatusException;
29 
30 import com.sun.star.sdbc.XResultSet;
31 import com.sun.star.sdbcx.XDeleteRows;
32 import com.sun.star.sdbcx.XRowLocate;
33 import com.sun.star.uno.UnoRuntime;
34 
35 /**
36 * Testing <code>com.sun.star.sdbcx.XDeleteRows</code>
37 * interface methods :
38 * <ul>
39 *  <li><code> deleteRows()</code></li>
40 * </ul> <p>
41 * @see com.sun.star.sdbcx.XDeleteRows
42 */
43 public class _XDeleteRows extends MultiMethodTest {
44     // oObj filled by MultiMethodTest
45     public XDeleteRows oObj = null ;
46 
47     /**
48     * Retrieves bookmark using XRowLocate and deletes
49     * row pointed by this bookmark. <p>
50     * Has OK status if number of rows after deleting is less than before
51     * and no exception rizes while method call, FAILED otherwise. <p>
52     */
_deleteRows()53     public void _deleteRows() {
54         XRowLocate xRowLocate = (XRowLocate)
55             UnoRuntime.queryInterface(XRowLocate.class, oObj);
56         XResultSet xResultSet = (XResultSet)
57             UnoRuntime.queryInterface(XResultSet.class, oObj);
58         if (xRowLocate == null || xResultSet == null) {
59             log.println("The test must be modified according to "+
60                 "component testcase");
61             throw new StatusException(Status.failed(
62                 "The component doesn't support one of the "+
63                     "required interfaces"));
64         }
65 
66         int rowsBefore = 0, rowsAfter = 0;
67         Object bkmrk = null;
68         try {
69             xResultSet.last();
70             rowsBefore = xResultSet.getRow();
71             xResultSet.first();
72             bkmrk = xRowLocate.getBookmark();
73             oObj.deleteRows(new Object[] {bkmrk});
74             xResultSet.last();
75             rowsAfter = xResultSet.getRow();
76         } catch(com.sun.star.sdbc.SQLException e) {
77             log.println("SQLException:" + e);
78             tRes.tested("deleteRows()", false);
79             return;
80         }
81 
82         log.println("Rows before: " + rowsBefore + ", after: " + rowsAfter);
83         tRes.tested("deleteRows()", rowsBefore - 1 == rowsAfter);
84     }
85 
after()86     protected void after() {
87         disposeEnvironment();
88     }
89 }  // finish class _XDeleteRows
90 
91