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 package mod._forms; 28 29 import java.io.PrintWriter; 30 import java.util.Vector; 31 32 import lib.Status; 33 import lib.StatusException; 34 import lib.TestCase; 35 import lib.TestEnvironment; 36 import lib.TestParameters; 37 import util.DBTools; 38 import util.DrawTools; 39 import util.FormTools; 40 import util.WriterTools; 41 import util.utils; 42 43 import com.sun.star.awt.XControl; 44 import com.sun.star.awt.XControlModel; 45 import com.sun.star.beans.PropertyValue; 46 import com.sun.star.beans.XPropertySet; 47 import com.sun.star.container.XIndexAccess; 48 import com.sun.star.container.XNameContainer; 49 import com.sun.star.container.XNamed; 50 import com.sun.star.drawing.XControlShape; 51 import com.sun.star.drawing.XShape; 52 import com.sun.star.drawing.XShapes; 53 import com.sun.star.form.DatabaseParameterEvent; 54 import com.sun.star.form.XForm; 55 import com.sun.star.form.XLoadable; 56 import com.sun.star.lang.EventObject; 57 import com.sun.star.lang.XMultiServiceFactory; 58 import com.sun.star.sdb.CommandType; 59 import com.sun.star.sdb.ParametersRequest; 60 import com.sun.star.sdb.RowChangeEvent; 61 import com.sun.star.sdbc.SQLException; 62 import com.sun.star.sdbc.XConnection; 63 import com.sun.star.sdbc.XResultSet; 64 import com.sun.star.sdbc.XResultSetUpdate; 65 import com.sun.star.sdbc.XRow; 66 import com.sun.star.sdbc.XRowSet; 67 import com.sun.star.sdbc.XRowUpdate; 68 import com.sun.star.task.XInteractionRequest; 69 import com.sun.star.text.XTextDocument; 70 import com.sun.star.uno.Any; 71 import com.sun.star.uno.AnyConverter; 72 import com.sun.star.uno.Type; 73 import com.sun.star.uno.UnoRuntime; 74 import com.sun.star.uno.XInterface; 75 import com.sun.star.util.Date; 76 import com.sun.star.util.DateTime; 77 import com.sun.star.util.Time; 78 import com.sun.star.util.XCloseable; 79 import com.sun.star.view.XControlAccess; 80 import ifc.form._XDatabaseParameterBroadcaster; 81 import ifc.sdb._XCompletedExecution; 82 83 84 /** 85 * Test for object which is represented by service 86 * <code>com.sun.star.form.component.DatabaseForm</code>. <p> 87 * 88 * Object implements the following interfaces : 89 * <ul> 90 * <li> <code>com::sun::star::script::XEventAttacherManager</code></li> 91 * <li> <code>com::sun::star::container::XElementAccess</code></li> 92 * <li> <code>com::sun::star::sdbcx::ResultSet</code></li> 93 * <li> <code>com::sun::star::container::XChild</code></li> 94 * <li> <code>com::sun::star::sdbc::XResultSetUpdate</code></li> 95 * <li> <code>com::sun::star::sdb::XResultSetAccess</code></li> 96 * <li> <code>com::sun::star::form::FormComponent</code></li> 97 * <li> <code>com::sun::star::form::component::DataForm</code></li> 98 * <li> <code>com::sun::star::sdbc::XResultSetMetaDataSupplier</code></li> 99 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li> 100 * <li> <code>com::sun::star::sdbcx::XDeleteRows</code></li> 101 * <li> <code>com::sun::star::sdb::RowSet</code></li> 102 * <li> <code>com::sun::star::lang::XComponent</code></li> 103 * <li> <code>com::sun::star::sdbc::XRowSet</code></li> 104 * <li> <code>com::sun::star::sdbc::XRowUpdate</code></li> 105 * <li> <code>com::sun::star::form::XLoadable</code></li> 106 * <li> <code>com::sun::star::container::XNamed</code></li> 107 * <li> <code>com::sun::star::container::XIndexReplace</code></li> 108 * <li> <code>com::sun::star::io::XPersistObject</code></li> 109 * <li> <code>com::sun::star::container::XNameReplace</code></li> 110 * <li> <code>com::sun::star::container::XIndexContainer</code></li> 111 * <li> <code>com::sun::star::container::XNameAccess</code></li> 112 * <li> <code>com::sun::star::sdbc::XParameters</code></li> 113 * <li> <code>com::sun::star::util::XCancellable</code></li> 114 * <li> <code>com::sun::star::form::XReset</code></li> 115 * <li> <code>com::sun::star::sdbc::XCloseable</code></li> 116 * <li> <code>com::sun::star::sdbcx::XColumnsSupplier</code></li> 117 * <li> <code>com::sun::star::sdb::XRowSetApproveBroadcaster</code></li> 118 * <li> <code>com::sun::star::sdbc::ResultSet</code></li> 119 * <li> <code>com::sun::star::sdbc::XResultSet</code></li> 120 * <li> <code>com::sun::star::sdbc::XRow</code></li> 121 * <li> <code>com::sun::star::sdbc::XColumnLocate</code></li> 122 * <li> <code>com::sun::star::awt::XTabControllerModel</code></li> 123 * <li> <code>com::sun::star::container::XIndexAccess</code></li> 124 * <li> <code>com::sun::star::form::XSubmit</code></li> 125 * <li> <code>com::sun::star::form::component::HTMLForm</code></li> 126 * <li> <code>com::sun::star::sdbcx::XRowLocate</code></li> 127 * <li> <code>com::sun::star::sdbc::XWarningsSupplier</code></li> 128 * <li> <code>com::sun::star::container::XNameContainer</code></li> 129 * <li> <code>com::sun::star::beans::XPropertyAccess</code></li> 130 * <li> <code>com::sun::star::beans::XPropertyContainer</code></li> 131 * <li> <code>com::sun::star::beans::XPropertySet</code></li> 132 * <li> <code>com::sun::star::sdbc::RowSet</code></li> 133 * </ul> <p> 134 * 135 * This object test <b> is NOT </b> designed to be run in several 136 * threads concurently. 137 * The following parameters in ini-file used by this test: 138 * <ul> 139 * <li><code>test.db.url</code> - URL to MySQL database. 140 * For example: <code>mysql://mercury:3306/api_current</code></li> 141 * <li><code>test.db.user</code> - user for MySQL database</li> 142 * <li><code>test.db.password</code> - password for MySQL database</li> 143 * </ul><p> 144 * 145 * @see com.sun.star.script.XEventAttacherManager 146 * @see com.sun.star.container.XElementAccess 147 * @see com.sun.star.sdbcx.ResultSet 148 * @see com.sun.star.container.XChild 149 * @see com.sun.star.sdbc.XResultSetUpdate 150 * @see com.sun.star.sdb.XResultSetAccess 151 * @see com.sun.star.form.FormComponent 152 * @see com.sun.star.form.component.DataForm 153 * @see com.sun.star.sdbc.XResultSetMetaDataSupplier 154 * @see com.sun.star.container.XEnumerationAccess 155 * @see com.sun.star.sdbcx.XDeleteRows 156 * @see com.sun.star.sdb.RowSet 157 * @see com.sun.star.lang.XComponent 158 * @see com.sun.star.sdbc.XRowSet 159 * @see com.sun.star.sdbc.XRowUpdate 160 * @see com.sun.star.form.XLoadable 161 * @see com.sun.star.container.XNamed 162 * @see com.sun.star.container.XIndexReplace 163 * @see com.sun.star.io.XPersistObject 164 * @see com.sun.star.container.XNameReplace 165 * @see com.sun.star.container.XIndexContainer 166 * @see com.sun.star.container.XNameAccess 167 * @see com.sun.star.sdbc.XParameters 168 * @see com.sun.star.util.XCancellable 169 * @see com.sun.star.form.XReset 170 * @see com.sun.star.sdbc.XCloseable 171 * @see com.sun.star.sdbcx.XColumnsSupplier 172 * @see com.sun.star.sdb.XRowSetApproveBroadcaster 173 * @see com.sun.star.sdbc.ResultSet 174 * @see com.sun.star.sdbc.XResultSet 175 * @see com.sun.star.sdbc.XRow 176 * @see com.sun.star.sdbc.XColumnLocate 177 * @see com.sun.star.awt.XTabControllerModel 178 * @see com.sun.star.container.XIndexAccess 179 * @see com.sun.star.form.XSubmit 180 * @see com.sun.star.form.component.HTMLForm 181 * @see com.sun.star.sdbcx.XRowLocate 182 * @see com.sun.star.sdbc.XWarningsSupplier 183 * @see com.sun.star.container.XNameContainer 184 * @see com.sun.star.beans.XPropertySet 185 * @see com.sun.star.sdbc.RowSet 186 * @see ifc.script._XEventAttacherManager 187 * @see ifc.container._XElementAccess 188 * @see ifc.sdbcx._ResultSet 189 * @see ifc.container._XChild 190 * @see ifc.sdbc._XResultSetUpdate 191 * @see ifc.sdb._XResultSetAccess 192 * @see ifc.form._FormComponent 193 * @see ifc.form.component._DataForm 194 * @see ifc.sdbc._XResultSetMetaDataSupplier 195 * @see ifc.container._XEnumerationAccess 196 * @see ifc.sdbcx._XDeleteRows 197 * @see ifc.sdb._RowSet 198 * @see ifc.lang._XComponent 199 * @see ifc.sdbc._XRowSet 200 * @see ifc.sdbc._XRowUpdate 201 * @see ifc.form._XLoadable 202 * @see ifc.container._XNamed 203 * @see ifc.container._XIndexReplace 204 * @see ifc.io._XPersistObject 205 * @see ifc.container._XNameReplace 206 * @see ifc.container._XIndexContainer 207 * @see ifc.container._XNameAccess 208 * @see ifc.sdbc._XParameters 209 * @see ifc.util._XCancellable 210 * @see ifc.form._XReset 211 * @see ifc.sdbc._XCloseable 212 * @see ifc.sdbcx._XColumnsSupplier 213 * @see ifc.sdb._XRowSetApproveBroadcaster 214 * @see ifc.sdbc._ResultSet 215 * @see ifc.sdbc._XResultSet 216 * @see ifc.sdbc._XRow 217 * @see ifc.sdbc._XColumnLocate 218 * @see ifc.awt._XTabControllerModel 219 * @see ifc.container._XIndexAccess 220 * @see ifc.form._XSubmit 221 * @see ifc.form.component._HTMLForm 222 * @see ifc.sdbcx._XRowLocate 223 * @see ifc.sdbc._XWarningsSupplier 224 * @see ifc.container._XNameContainer 225 * @see ifc.beans._XPropertyAccess 226 * @see ifc.beans._XPropertyContainer 227 * @see ifc.beans._XPropertySet 228 * @see ifc.sdbc._RowSet 229 */ 230 public class ODatabaseForm extends TestCase { 231 protected final static String dbSourceName = "ODatabaseFormDataSource"; 232 private static int uniqueSuffix = 0; 233 private static String origDB = null; 234 private static String tmpDir = null; 235 protected XTextDocument xTextDoc = null; 236 private DBTools dbTools = null; 237 String tableName = null; 238 DBTools.DataSourceInfo srcInf = null; 239 boolean isMySQLDB = false; 240 protected XConnection conn = null; 241 private Object dbSrc = null; 242 243 protected void initialize(TestParameters tParam, PrintWriter log) { 244 //log.println( "creating a draw document" ); 245 //xTextDoc = WriterTools.createTextDoc(t((XMultiServiceFactory) Param.getMSF)); 246 tmpDir = utils.getOfficeTemp(((XMultiServiceFactory) tParam.getMSF())); 247 248 origDB = util.utils.getFullTestDocName("TestDB/testDB.dbf"); 249 250 dbTools = new DBTools( (XMultiServiceFactory)tParam.getMSF(), log ); 251 252 // creating DataSource and registering it in DatabaseContext 253 String dbURL = (String) tParam.get("test.db.url"); 254 String dbUser = (String) tParam.get("test.db.user"); 255 String dbPassword = (String) tParam.get("test.db.password"); 256 257 log.println("Creating and registering DataSource ..."); 258 srcInf = dbTools.newDataSourceInfo(); 259 260 if ((dbURL != null) && (dbUser != null) && (dbPassword != null)) { 261 isMySQLDB = true; 262 log.println("dbURL = " + dbURL); 263 log.println("dbUSER = " + dbUser); 264 log.println("dbPASSWORD = " + dbPassword); 265 266 //DataSource for mysql db 267 try { 268 tableName = "soffice_test_table"; 269 srcInf.URL = "jdbc:" + dbURL; 270 srcInf.IsPasswordRequired = new Boolean(true); 271 srcInf.Password = dbPassword; 272 srcInf.User = dbUser; 273 274 PropertyValue[] propInfo = new PropertyValue[1]; 275 propInfo[0] = new PropertyValue(); 276 propInfo[0].Name = "JavaDriverClass"; 277 // propInfo[0].Value = "org.gjt.mm.mysql.Driver"; 278 propInfo[0].Value = "util.dddriver.Driver"; 279 srcInf.Info = propInfo; 280 281 dbSrc = srcInf.getDataSourceService(); 282 dbTools.reRegisterDB(dbSourceName, dbSrc); 283 } catch (com.sun.star.uno.Exception e) { 284 log.println("Error while object test initialization :"); 285 e.printStackTrace(log); 286 throw new StatusException("Error while object test" + 287 " initialization", e); 288 } 289 } else { 290 //DataSource for sdbc db 291 try { 292 String myDbUrl = "sdbc:dbase:" + DBTools.dirToUrl(tmpDir); 293 srcInf.URL = myDbUrl; 294 295 log.println("try to register '"+myDbUrl+"' as '"+dbSourceName+"'"); 296 297 dbSrc = srcInf.getDataSourceService(); 298 dbTools.reRegisterDB(dbSourceName, dbSrc); 299 } catch (com.sun.star.uno.Exception e) { 300 log.println("Error while object test initialization :"); 301 e.printStackTrace(log); 302 throw new StatusException( 303 "Error while object test initialization", e); 304 } 305 306 String oldF = null; 307 String newF = null; 308 309 do { 310 tableName = "ODatabaseForm_tmp" + uniqueSuffix; 311 oldF = utils.getFullURL(origDB); 312 newF = utils.getOfficeTemp((XMultiServiceFactory) tParam.getMSF()) + tableName + 313 ".dbf"; 314 } while (!utils.tryOverwriteFile(((XMultiServiceFactory) tParam.getMSF()), oldF, newF) && 315 (uniqueSuffix++ < 50)); 316 } 317 } 318 319 /** 320 * * creating a Testenvironment for the interfaces to be tested 321 */ 322 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, 323 PrintWriter log) { 324 if (xTextDoc != null) { 325 try { 326 XCloseable closer = (XCloseable) UnoRuntime.queryInterface( 327 XCloseable.class, xTextDoc); 328 closer.close(true); 329 } catch (com.sun.star.util.CloseVetoException e) { 330 log.println("couldn't close document"); 331 } catch (com.sun.star.lang.DisposedException e) { 332 log.println("couldn't close document"); 333 } 334 335 log.println("Existing document disposed"); 336 } 337 338 log.println("creating a text document"); 339 xTextDoc = WriterTools.createTextDoc(((XMultiServiceFactory) Param.getMSF())); 340 341 //initialize test table 342 if (isMySQLDB) { 343 try { 344 dbTools.initTestTableUsingJDBC(tableName, srcInf); 345 } catch (java.sql.SQLException e) { 346 e.printStackTrace(log); 347 throw new StatusException(Status.failed("Couldn't " + " init test table. SQLException...")); 348 } catch (java.lang.ClassNotFoundException e) { 349 throw new StatusException(Status.failed("Couldn't " + "register mysql driver")); 350 } 351 } 352 353 XInterface oObj = null; 354 XShapes oShapes = null; 355 XInterface oInstance = null; 356 XConnection connection = null; 357 358 359 // creation of testobject here 360 // first we write what we are intend to do to log file 361 log.println("creating a test environment"); 362 363 XNameContainer forms = FormTools.getForms(WriterTools.getDrawPage( 364 xTextDoc)); 365 366 try { 367 String[] formNames = forms.getElementNames(); 368 369 for (int i = 0; i < formNames.length; i++) { 370 log.println("Removing form '" + formNames[i] + "' ..."); 371 forms.removeByName(formNames[i]); 372 } 373 } catch (com.sun.star.lang.WrappedTargetException e) { 374 e.printStackTrace(log); 375 } catch (com.sun.star.container.NoSuchElementException e) { 376 e.printStackTrace(log); 377 } 378 379 String[] formNames = forms.getElementNames(); 380 FormTools.insertForm(xTextDoc, forms, "MyForm"); 381 formNames = forms.getElementNames(); 382 383 XLoadable formLoader = null; 384 385 try { 386 formLoader = FormTools.bindForm(xTextDoc, "MyForm", dbSourceName, 387 tableName); 388 } catch (com.sun.star.uno.Exception e) { 389 log.println("Cann't bind the form to source '" + dbSourceName + 390 "', table '" + tableName + "' :"); 391 e.printStackTrace(log); 392 throw new StatusException("Cann't bind a form", e); 393 } 394 395 396 // DEBUG 397 log.println("Forms before adding controls : "); 398 formNames = forms.getElementNames(); 399 400 for (int i = 0; i < formNames.length; i++) { 401 log.println(" '" + formNames[i] + "'"); 402 } 403 404 XControlShape shape1 = null; 405 XControlShape shape2 = null; 406 407 try { 408 409 log.println("Elements in the 'MyForm' :"); 410 411 XIndexAccess formElements1 = (XIndexAccess) UnoRuntime.queryInterface( 412 XIndexAccess.class, 413 forms.getByName("MyForm")); 414 415 for (int i = 0; i < formElements1.getCount(); i++) { 416 XNamed elemName = (XNamed) UnoRuntime.queryInterface( 417 XNamed.class, 418 formElements1.getByIndex(i)); 419 log.println(" '" + elemName.getName() + "'"); 420 } 421 422 423 // END DEBUG 424 //put something on the drawpage 425 log.println("inserting some ControlShapes"); 426 oShapes = DrawTools.getShapes(WriterTools.getDrawPage(xTextDoc)); 427 shape1 = FormTools.createControlShape(xTextDoc, 3000, 4500, 15000, 428 1000, "CommandButton"); 429 shape2 = FormTools.createControlShape(xTextDoc, 5000, 3500, 7500, 430 5000, "TextField"); 431 432 XControlShape shape3 = FormTools.createControlShape(xTextDoc, 2000, 433 1500, 1000, 434 1000, 435 "CheckBox"); 436 oShapes.add((XShape) shape1); 437 oShapes.add((XShape) shape2); 438 oShapes.add(shape3); 439 } catch (Exception e) { 440 e.printStackTrace(log); 441 } 442 443 log.println("Forms after adding controls : "); 444 formNames = forms.getElementNames(); 445 446 for (int i = 0; i < formNames.length; i++) { 447 log.println(" '" + formNames[i] + "'"); 448 } 449 450 try { 451 log.println("Elements in the 'MyForm' :"); 452 453 XIndexAccess formElements1 = (XIndexAccess) UnoRuntime.queryInterface( 454 XIndexAccess.class, 455 forms.getByName("MyForm")); 456 457 for (int i = 0; i < formElements1.getCount(); i++) { 458 XNamed elemName = (XNamed) UnoRuntime.queryInterface( 459 XNamed.class, 460 formElements1.getByIndex(i)); 461 log.println(" '" + elemName.getName() + "'"); 462 } 463 } catch (Exception e) { 464 e.printStackTrace(log); 465 } 466 467 formLoader.load(); 468 469 try { 470 oObj = (XForm) AnyConverter.toObject(new Type(XForm.class), 471 (FormTools.getForms( 472 WriterTools.getDrawPage( 473 xTextDoc))) 474 .getByName("MyForm")); 475 476 XPropertySet xSetProp = (XPropertySet) UnoRuntime.queryInterface( 477 XPropertySet.class, oObj); 478 connection = (XConnection) AnyConverter.toObject( 479 new Type(XConnection.class), 480 xSetProp.getPropertyValue("ActiveConnection")); 481 } catch (com.sun.star.uno.Exception e) { 482 log.println("Couldn't get Form"); 483 e.printStackTrace(log); 484 } 485 486 487 // get a control 488 oInstance = FormTools.createControl(xTextDoc, "TextField"); 489 490 log.println("creating a new environment for drawpage object"); 491 492 TestEnvironment tEnv = new TestEnvironment(oObj); 493 494 495 // adding relation for closing connection while environment disposing. 496 this.conn = connection; 497 498 // adding relation for XSubmit 499 XControlModel the_Model = shape2.getControl(); 500 XControlAccess the_access = (XControlAccess) UnoRuntime.queryInterface( 501 XControlAccess.class, 502 xTextDoc.getCurrentController()); 503 XControl cntrl = null; 504 505 //now get the OEditControl 506 try { 507 cntrl = the_access.getControl(the_Model); 508 log.println(cntrl.getClass().getName()); 509 } catch (com.sun.star.container.NoSuchElementException e) { 510 log.println("Couldn't get OEditControl"); 511 e.printStackTrace(log); 512 throw new StatusException("Couldn't get OEditControl", e); 513 } 514 515 XResultSet the_set = (XResultSet) UnoRuntime.queryInterface( 516 XResultSet.class, oObj); 517 518 try { 519 the_set.first(); 520 } catch (SQLException e) { 521 log.println("Cann't move cursor to the first row."); 522 e.printStackTrace(); 523 throw new StatusException("Can't move cursor to the first row.", e); 524 } 525 526 tEnv.addObjRelation("Model1", shape1.getControl()); 527 tEnv.addObjRelation("Model2", shape2.getControl()); 528 529 530 // adding an object for XNameReplace testing 531 log.println("adding oInstace as obj relation to environment"); 532 tEnv.addObjRelation("INSTANCE", oInstance); 533 534 535 // INDEX : _XNameContainer 536 log.println("adding INDEX as obj relation to environment"); 537 tEnv.addObjRelation("INDEX", "0"); 538 539 540 // INDEX : _XNameReplace 541 log.println("adding NameReplaceIndex as obj relation to environment"); 542 tEnv.addObjRelation("XNameReplaceINDEX", "2"); 543 544 545 // INSTANCEn : _XNameContainer; _XNameReplace 546 log.println("adding INSTANCEn as obj relation to environment"); 547 548 //XComponent xComp = (XComponent) 549 // UnoRuntime.queryInterface(XComponent.class, xDrawDoc); 550 String tc = (String) Param.get("THRCNT"); 551 int THRCNT = 1; 552 553 if (tc != null) { 554 THRCNT = Integer.parseInt(tc); 555 } 556 557 for (int n = 1; n < (2 * (THRCNT + 1)); n++) { 558 log.println("adding INSTANCE" + n + 559 " as obj relation to environment"); 560 tEnv.addObjRelation("INSTANCE" + n, 561 FormTools.createControl(xTextDoc, "CheckBox")); 562 } 563 564 565 // adding relation for XNameContainer 566 tEnv.addObjRelation("XNameContainer.AllowDuplicateNames", new Object()); 567 568 569 // adding relation for XPersistObject 570 tEnv.addObjRelation("OBJNAME", "stardiv.one.form.component.Form"); 571 572 if (the_set != null) { 573 log.println("The Form has a not empty ResultSet"); 574 } 575 576 // Adding obj relation for XRowSetApproveBroadcaster test 577 final XResultSet xResSet = (XResultSet) UnoRuntime.queryInterface( 578 XResultSet.class, oObj); 579 final XResultSetUpdate xResSetUpdate = (XResultSetUpdate) UnoRuntime.queryInterface( 580 XResultSetUpdate.class, 581 oObj); 582 final XRowSet xRowSet = (XRowSet) UnoRuntime.queryInterface( 583 XRowSet.class, oObj); 584 final PrintWriter logF = log; 585 tEnv.addObjRelation("XRowSetApproveBroadcaster.ApproveChecker", 586 new ifc.sdb._XRowSetApproveBroadcaster.RowSetApproveChecker() { 587 public void moveCursor() { 588 try { 589 xResSet.beforeFirst(); 590 xResSet.afterLast(); 591 } catch (com.sun.star.sdbc.SQLException e) { 592 logF.println("### _XRowSetApproveBroadcaster." + "RowSetApproveChecker.moveCursor() :"); 593 e.printStackTrace(logF); 594 } 595 } 596 597 public RowChangeEvent changeRow() { 598 try { 599 xResSet.first(); 600 601 XRowUpdate row = (XRowUpdate) UnoRuntime.queryInterface( 602 XRowUpdate.class, xResSet); 603 row.updateString(1, "1"); 604 xResSetUpdate.updateRow(); 605 } catch (com.sun.star.sdbc.SQLException e) { 606 logF.println("### _XRowSetApproveBroadcaster." + "RowSetApproveChecker.changeRow() :"); 607 e.printStackTrace(logF); 608 } 609 610 RowChangeEvent ev = new RowChangeEvent(); 611 ev.Action = com.sun.star.sdb.RowChangeAction.UPDATE; 612 ev.Rows = 1; 613 614 return ev; 615 } 616 617 public void changeRowSet() { 618 try { 619 xRowSet.execute(); 620 } catch (com.sun.star.sdbc.SQLException e) { 621 logF.println("### _XRowSetApproveBroadcaster." + "RowSetApproveChecker.changeRowSet() :"); 622 e.printStackTrace(logF); 623 } 624 } 625 }); 626 627 628 // Adding relation for XColumnLocate test 629 tEnv.addObjRelation("XColumnLocate.ColumnName", DBTools.TST_STRING_F); 630 631 // Adding relation for XParameters ifc test 632 Vector params = new Vector(); 633 634 635 /***** statement parameter types and their initial 636 values must be added here as relation. */ 637 params.add(new String("SAU99")) ; 638 params.add(new Boolean(false)) ; 639 params.add(new Byte((byte) 123)) ; 640 params.add(new Short((short) 234)) ; 641 params.add(new Integer(12345)) ; 642 params.add(new Long(23456)) ; 643 params.add(new Float(1.234)) ; 644 params.add(new Double(2.345)) ; 645 params.add(new byte[] {1, 2, 3}) ; 646 Date d = new Date(); 647 d.Day = 26; d.Month = 1; d.Year = 2001; 648 params.add(d) ; 649 Time t = new Time(); 650 t.Hours = 1; t.HundredthSeconds = 12; t.Minutes = 25; t.Seconds = 14; 651 params.add(t) ; 652 DateTime dt = new DateTime(); 653 dt.Day = 26; dt.Month = 1; dt.Year = 2001; dt.Hours = 1; 654 dt.HundredthSeconds = 12; dt.Minutes = 25; dt.Seconds = 14; 655 params.add(dt) ; 656 tEnv.addObjRelation("XParameters.ParamValues", params); 657 658 // Adding relation for XCompletedExecution 659 tEnv.addObjRelation("InteractionHandlerChecker", new InteractionHandlerImpl()); 660 661 // Adding for XWarningSupplier 662 tEnv.addObjRelation("CheckWarningsSupplier", new Boolean(isMySQLDB)); 663 664 // Adding relation for XDatabaseParameterBroadcaster 665 tEnv.addObjRelation("ParameterListenerChecker", new ODatabaseForm.ParameterListenerImpl()); 666 XPropertySet xSetProp = (XPropertySet) UnoRuntime.queryInterface 667 (XPropertySet.class, oObj) ; 668 try { 669 xSetProp.setPropertyValue("DataSourceName", dbSourceName) ; 670 if(isMySQLDB) { 671 xSetProp.setPropertyValue("Command", "SELECT Column0 FROM soffice_test_table WHERE ( ( Column0 = :param1 ) )"); 672 } 673 else { 674 xSetProp.setPropertyValue("Command", "SELECT \"_TEXT\" FROM \"ODatabaseForm_tmp0\" WHERE ( ( \"_TEXT\" = :param1 ) )"); 675 } 676 677 xSetProp.setPropertyValue("CommandType", 678 new Integer(CommandType.COMMAND)) ; 679 } 680 catch(Exception e) { 681 } 682 683 // Adding relation for XResultSetUpdate 684 final XRowUpdate xRowUpdate = (XRowUpdate) UnoRuntime.queryInterface( 685 XRowUpdate.class, oObj); 686 final XRow xRow = (XRow) UnoRuntime.queryInterface(XRow.class, oObj); 687 688 tEnv.addObjRelation("XResultSetUpdate.UpdateTester", 689 new ifc.sdbc._XResultSetUpdate.UpdateTester() { 690 String lastUpdate = null; 691 692 public int rowCount() throws SQLException { 693 int prevPos = xResSet.getRow(); 694 xResSet.last(); 695 696 int count = xResSet.getRow(); 697 xResSet.absolute(prevPos); 698 699 return count; 700 } 701 702 public void update() throws SQLException { 703 lastUpdate = xRow.getString(1); 704 lastUpdate += "_"; 705 xRowUpdate.updateString(1, lastUpdate); 706 } 707 708 public boolean wasUpdated() throws SQLException { 709 String getStr = xRow.getString(1); 710 711 return lastUpdate.equals(getStr); 712 } 713 714 public int currentRow() throws SQLException { 715 return xResSet.getRow(); 716 } 717 }); 718 719 // Adding relations for XRow as a Vector with all data 720 // of current row of RowSet. 721 722 Vector rowData = new Vector(); 723 724 for (int i = 0; i < DBTools.TST_TABLE_VALUES[0].length; i++) { 725 rowData.add(DBTools.TST_TABLE_VALUES[0][i]); 726 } 727 728 tEnv.addObjRelation("CurrentRowData", rowData); 729 730 // Adding relation for XRowUpdate 731 XRow row = (XRow) UnoRuntime.queryInterface(XRow.class, oObj); 732 tEnv.addObjRelation("XRowUpdate.XRow", row); 733 734 735 tEnv.addObjRelation("XPropertyContainer.propertyNotRemovable", "Cycle"); 736 737 PropertyValue propVal = new PropertyValue(); 738 propVal.Name = "Name"; 739 propVal.Value = "Text since XPropertyAccess"; 740 741 tEnv.addObjRelation("XPropertyAccess.propertyToChange", propVal); 742 743 return tEnv; 744 } // finish method getTestEnvironment 745 746 /** 747 * Closes connection of <code>RowSet</code> instance created. 748 */ 749 protected void cleanup(TestParameters Param, PrintWriter log) { 750 log.println("closing connection..."); 751 try { 752 conn.close(); 753 } catch (com.sun.star.uno.Exception e) { 754 log.println("Can't close the connection"); 755 e.printStackTrace(log); 756 } catch (com.sun.star.lang.DisposedException e) { 757 log.println("Connection was already closed. It's OK."); 758 } 759 760 761 log.println("closing data source..."); 762 try { 763 XCloseable closer = (XCloseable) UnoRuntime.queryInterface( 764 XCloseable.class, dbSrc); 765 closer.close(true); 766 } catch (com.sun.star.util.CloseVetoException e) { 767 log.println("couldn't close data source"); 768 } catch (com.sun.star.lang.DisposedException e) { 769 log.println("couldn't close data source"); 770 } 771 772 773 log.println("closing document..."); 774 775 try { 776 XCloseable closer = (XCloseable) UnoRuntime.queryInterface( 777 XCloseable.class, xTextDoc); 778 closer.close(true); 779 } catch (com.sun.star.util.CloseVetoException e) { 780 log.println("couldn't close document"); 781 } catch (com.sun.star.lang.DisposedException e) { 782 log.println("couldn't close document"); 783 } 784 785 log.println("revoking data source..."); 786 try { 787 dbTools.revokeDB(dbSourceName); 788 } catch (com.sun.star.container.NoSuchElementException e){ 789 } catch (com.sun.star.uno.Exception e) { 790 log.println("Error while object test cleaning up :"); 791 e.printStackTrace(log); 792 throw new StatusException("Error while object test cleaning up", e); 793 } 794 } 795 796 /** 797 * Implementation of interface _XDatabaseParameterBroadcaster.CheckParameterListener 798 * for the XDatabaseParameterBroadcaster test 799 * @see ifc.form._XDatabaseParameterBroadcaster 800 */ 801 public class ParameterListenerImpl implements _XDatabaseParameterBroadcaster.CheckParameterListener { 802 boolean listenerWasCalled = false; 803 PrintWriter log = new PrintWriter(System.out); 804 805 /** 806 * Return true, if the listener was called, false otherwise. 807 * @return True, if any other method of the listener was called. 808 */ 809 public boolean checkListener() { 810 return listenerWasCalled; 811 } 812 813 /** 814 * Take the DataBaseParameterEvent and fill it with a meaningful value. 815 * @param e The database parameter that will be filled with a value. 816 * @return True, if the value could be filled. 817 */ 818 public boolean approveParameter(DatabaseParameterEvent e) { 819 log.println("### ParameterListenerImpl: approve called."); 820 XIndexAccess params = e.Parameters; 821 int count = params.getCount(); 822 try { 823 for(int i=0; i<count; i++) { 824 log.println("### _XDatabaseParameterBroadcaster.ParameterListenerImpl: Parameter "+i+": "+params.getByIndex(i)); 825 XPropertySet xProp = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, params.getByIndex(i)); 826 log.println("### _XDatabaseParameterBroadcaster.ParameterListenerImpl: Parameter Name: '"+xProp.getPropertyValue("Name") + "' is set to Value '1'"); 827 xProp.setPropertyValue("Value", new Integer(1)); 828 listenerWasCalled = true; 829 } 830 } 831 catch(Exception eI) { 832 log.println("### _XDatabaseParameterBroadcaster.ParameterListenerImpl: Exception!"); 833 eI.printStackTrace(log); 834 return false; 835 } 836 return true; 837 } 838 839 /** 840 * Dummy implemetnation. Do nothing, just log 841 * @param o Ignore. 842 */ 843 public void disposing(EventObject o) { 844 log.println("### _XDatabaseParameterBroadcaster.ParameterListenerImpl: disposing"); 845 } 846 847 /** 848 * Set a log writer, so messages go to log instead of Standard.out 849 * @param log The log messages get printed to. 850 */ 851 public void setLog(PrintWriter log) { 852 this.log = log; 853 } 854 855 } 856 857 858 /** 859 * Implementation of interface _XCompletedExecution.CheckInteractionHandler 860 * for the XCompletedExecution test 861 * @see ifc.sdb._XCompletedExecution 862 */ 863 public class InteractionHandlerImpl implements _XCompletedExecution.CheckInteractionHandler { 864 private boolean handlerWasUsed = false; 865 private PrintWriter log = new PrintWriter(System.out); 866 867 public boolean checkInteractionHandler() { 868 return handlerWasUsed; 869 } 870 871 public void handle(XInteractionRequest xInteractionRequest) { 872 log.println("### _XCompletedExecution.InteractionHandlerImpl: handle called."); 873 handlerWasUsed = true; 874 875 Object o = xInteractionRequest.getRequest(); 876 ParametersRequest req = (ParametersRequest)o; 877 XIndexAccess params = req.Parameters; 878 int count = params.getCount(); 879 try { 880 for(int i=0; i<count; i++) { 881 Object aObject = params.getByIndex(i); 882 Any any = (Any)aObject; 883 log.println("### _XCompletedExecution.InteractionHandlerImpl: Parameter "+i+": "+params.getByIndex(i)); 884 XPropertySet xProp = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, params.getByIndex(i)); 885 log.println("### _XCompletedExecution.InteractionHandlerImpl: Parameter Name: '"+xProp.getPropertyValue("Name") + "' is set to Value '1'"); 886 xProp.setPropertyValue("Value", new Integer(1)); 887 handlerWasUsed = true; 888 } 889 } 890 catch(Exception eI) { 891 log.println("### _XCompletedExecution.InteractionHandlerImpl: Exception!"); 892 eI.printStackTrace(log); 893 } 894 } 895 896 public void setLog(PrintWriter log) { 897 this.log = log; 898 } 899 900 } 901 } // finish class ODatabaseForm 902