1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package ifc.sdbcx;
29 
30 import lib.MultiMethodTest;
31 import lib.Status;
32 import lib.StatusException;
33 
34 import com.sun.star.sdbc.XResultSet;
35 import com.sun.star.sdbcx.XDeleteRows;
36 import com.sun.star.sdbcx.XRowLocate;
37 import com.sun.star.uno.UnoRuntime;
38 
39 /**
40 * Testing <code>com.sun.star.sdbcx.XDeleteRows</code>
41 * interface methods :
42 * <ul>
43 *  <li><code> deleteRows()</code></li>
44 * </ul> <p>
45 * @see com.sun.star.sdbcx.XDeleteRows
46 */
47 public class _XDeleteRows extends MultiMethodTest {
48     // oObj filled by MultiMethodTest
49     public XDeleteRows oObj = null ;
50 
51     /**
52     * Retrieves bookmark using XRowLocate and deletes
53     * row pointed by this bookmark. <p>
54     * Has OK status if number of rows after deleting is less than before
55     * and no exception rizes while method call, FAILED otherwise. <p>
56     */
57     public void _deleteRows() {
58         XRowLocate xRowLocate = (XRowLocate)
59             UnoRuntime.queryInterface(XRowLocate.class, oObj);
60         XResultSet xResultSet = (XResultSet)
61             UnoRuntime.queryInterface(XResultSet.class, oObj);
62         if (xRowLocate == null || xResultSet == null) {
63             log.println("The test must be modified according to "+
64                 "component testcase");
65             throw new StatusException(Status.failed(
66                 "The component doesn't support one of the "+
67                     "required interfaces"));
68         }
69 
70         int rowsBefore = 0, rowsAfter = 0;
71         Object bkmrk = null;
72         try {
73             xResultSet.last();
74             rowsBefore = xResultSet.getRow();
75             xResultSet.first();
76             bkmrk = xRowLocate.getBookmark();
77             oObj.deleteRows(new Object[] {bkmrk});
78             xResultSet.last();
79             rowsAfter = xResultSet.getRow();
80         } catch(com.sun.star.sdbc.SQLException e) {
81             log.println("SQLException:" + e);
82             tRes.tested("deleteRows()", false);
83             return;
84         }
85 
86         log.println("Rows before: " + rowsBefore + ", after: " + rowsAfter);
87         tRes.tested("deleteRows()", rowsBefore - 1 == rowsAfter);
88     }
89 
90     protected void after() {
91         disposeEnvironment();
92     }
93 }  // finish class _XDeleteRows
94 
95