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 10*ef39d40dSAndrew Rist * 11*ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*ef39d40dSAndrew Rist * 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. 19*ef39d40dSAndrew Rist * 20*ef39d40dSAndrew Rist *************************************************************/ 21*ef39d40dSAndrew Rist 22*ef39d40dSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package mod._dbaccess; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import java.io.PrintWriter; 27cdf0e10cSrcweir import java.util.Vector; 28cdf0e10cSrcweir 29cdf0e10cSrcweir import lib.Status; 30cdf0e10cSrcweir import lib.StatusException; 31cdf0e10cSrcweir import lib.TestCase; 32cdf0e10cSrcweir import lib.TestEnvironment; 33cdf0e10cSrcweir import lib.TestParameters; 34cdf0e10cSrcweir import util.DBTools; 35cdf0e10cSrcweir import util.utils; 36cdf0e10cSrcweir 37cdf0e10cSrcweir import com.sun.star.beans.PropertyValue; 38cdf0e10cSrcweir import com.sun.star.beans.XPropertySet; 39cdf0e10cSrcweir import com.sun.star.lang.XComponent; 40cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 41cdf0e10cSrcweir import com.sun.star.sdb.CommandType; 42cdf0e10cSrcweir import com.sun.star.sdb.ParametersRequest; 43cdf0e10cSrcweir import com.sun.star.sdb.XInteractionSupplyParameters; 44cdf0e10cSrcweir import com.sun.star.sdbc.XConnection; 45cdf0e10cSrcweir import com.sun.star.sdbc.XResultSet; 46cdf0e10cSrcweir import com.sun.star.sdbc.XResultSetUpdate; 47cdf0e10cSrcweir import com.sun.star.sdbc.XRow; 48cdf0e10cSrcweir import com.sun.star.sdbc.XRowSet; 49cdf0e10cSrcweir import com.sun.star.sdbc.XRowUpdate; 50cdf0e10cSrcweir import com.sun.star.task.XInteractionAbort; 51cdf0e10cSrcweir import com.sun.star.task.XInteractionContinuation; 52cdf0e10cSrcweir import com.sun.star.task.XInteractionRequest; 53cdf0e10cSrcweir import com.sun.star.ucb.AuthenticationRequest; 54cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 55cdf0e10cSrcweir import com.sun.star.uno.XInterface; 56cdf0e10cSrcweir import com.sun.star.util.XCloseable; 57cdf0e10cSrcweir import com.sun.star.frame.XModel; 58cdf0e10cSrcweir import com.sun.star.sdb.RowChangeEvent; 59cdf0e10cSrcweir import com.sun.star.sdbc.SQLException; 60cdf0e10cSrcweir import com.sun.star.sdbc.XParameters; 61cdf0e10cSrcweir import ifc.sdb._XCompletedExecution; 62cdf0e10cSrcweir import util.db.DataSource; 63cdf0e10cSrcweir import util.db.DataSourceDescriptor; 64cdf0e10cSrcweir 65cdf0e10cSrcweir /** 66cdf0e10cSrcweir * Test for object which is represented by service 67cdf0e10cSrcweir * <code>com.sun.star.sdb.RowSet</code>. <p> 68cdf0e10cSrcweir * 69cdf0e10cSrcweir * The following files used by this test : 70cdf0e10cSrcweir * <ul> 71cdf0e10cSrcweir * <li><b> TestDB/TestDB.dbf </b> : the database file with some 72cdf0e10cSrcweir * predefined fields described in <code>util.DBTools</code>. 73cdf0e10cSrcweir * The copy of this file is always made in temp directory for 74cdf0e10cSrcweir * testing purposes.</li> 75cdf0e10cSrcweir * </ul> 76cdf0e10cSrcweir * The following parameters in ini-file used by this test: 77cdf0e10cSrcweir * <ul> 78cdf0e10cSrcweir * <li><code>test.db.url</code> - URL to MySQL database. 79cdf0e10cSrcweir * For example: <code>mysql://mercury:3306/api_current</code></li> 80cdf0e10cSrcweir * <li><code>test.db.user</code> - user for MySQL database</li> 81cdf0e10cSrcweir * <li><code>test.db.password</code> - password for MySQL database</li> 82cdf0e10cSrcweir * </ul> 83cdf0e10cSrcweir * 84cdf0e10cSrcweir * @see com.sun.star.sdbc.RowSet 85cdf0e10cSrcweir * @see com.sun.star.sdbcx.XRowLocate 86cdf0e10cSrcweir * @see com.sun.star.sdbc.XResultSetUpdate 87cdf0e10cSrcweir * @see com.sun.star.util.XCancellable 88cdf0e10cSrcweir * @see com.sun.star.sdbc.XParameters 89cdf0e10cSrcweir * @see com.sun.star.sdbc.XResultSetMetaDataSupplier 90cdf0e10cSrcweir * @see com.sun.star.sdbcx.XDeleteRows 91cdf0e10cSrcweir * @see com.sun.star.sdbc.XCloseable 92cdf0e10cSrcweir * @see com.sun.star.sdbcx.XColumnsSupplier 93cdf0e10cSrcweir * @see com.sun.star.sdb.XResultSetAccess 94cdf0e10cSrcweir * @see com.sun.star.sdbc.XResultSet 95cdf0e10cSrcweir * @see com.sun.star.sdbc.XColumnLocate 96cdf0e10cSrcweir * @see com.sun.star.sdbc.XRowSet 97cdf0e10cSrcweir * @see com.sun.star.sdb.RowSet 98cdf0e10cSrcweir * @see com.sun.star.sdbc.XRowUpdate 99cdf0e10cSrcweir * @see com.sun.star.sdb.XRowSetApproveBroadcaster 100cdf0e10cSrcweir * @see com.sun.star.beans.XPropertySet 101cdf0e10cSrcweir * @see com.sun.star.sdbc.XRow 102cdf0e10cSrcweir * @see com.sun.star.sdbc.XWarningsSupplier 103cdf0e10cSrcweir * @see com.sun.star.lang.XComponent 104cdf0e10cSrcweir * @see com.sun.star.sdbcx.ResultSet 105cdf0e10cSrcweir * @see com.sun.star.sdbc.ResultSet 106cdf0e10cSrcweir * @see ifc.sdbc._RowSet 107cdf0e10cSrcweir * @see ifc.sdbcx._XRowLocate 108cdf0e10cSrcweir * @see ifc.sdbc._XResultSetUpdate 109cdf0e10cSrcweir * @see ifc.util._XCancellable 110cdf0e10cSrcweir * @see ifc.sdbc._XParameters 111cdf0e10cSrcweir * @see ifc.sdbc._XResultSetMetaDataSupplier 112cdf0e10cSrcweir * @see ifc.sdbcx._XDeleteRows 113cdf0e10cSrcweir * @see ifc.sdbc._XCloseable 114cdf0e10cSrcweir * @see ifc.sdbcx._XColumnsSupplier 115cdf0e10cSrcweir * @see ifc.sdb._XResultSetAccess 116cdf0e10cSrcweir * @see ifc.sdbc._XResultSet 117cdf0e10cSrcweir * @see ifc.sdbc._XColumnLocate 118cdf0e10cSrcweir * @see ifc.sdbc._XRowSet 119cdf0e10cSrcweir * @see ifc.sdb._RowSet 120cdf0e10cSrcweir * @see ifc.sdbc._XRowUpdate 121cdf0e10cSrcweir * @see ifc.sdb._XRowSetApproveBroadcaster 122cdf0e10cSrcweir * @see ifc.beans._XPropertySet 123cdf0e10cSrcweir * @see ifc.sdbc._XRow 124cdf0e10cSrcweir * @see ifc.sdbc._XWarningsSupplier 125cdf0e10cSrcweir * @see ifc.lang._XComponent 126cdf0e10cSrcweir * @see ifc.sdbcx._ResultSet 127cdf0e10cSrcweir * @see ifc.sdbc._ResultSet 128cdf0e10cSrcweir */ 129cdf0e10cSrcweir public class ORowSet extends TestCase { 130cdf0e10cSrcweir 131cdf0e10cSrcweir private static int uniqueSuffix = 0 ; 132cdf0e10cSrcweir private DBTools dbTools = null ; 133cdf0e10cSrcweir private static String origDB = null ; 134cdf0e10cSrcweir String tableName = null; 135cdf0e10cSrcweir DataSourceDescriptor srcInf = null; 136cdf0e10cSrcweir boolean isMySQLDB = false; 137cdf0e10cSrcweir protected final static String dbSourceName = "ORowSetDataSource"; 138cdf0e10cSrcweir public XConnection m_connection = null; 139cdf0e10cSrcweir private Object m_rowSet = null; 140cdf0e10cSrcweir private DataSource m_dataSource; 141cdf0e10cSrcweir private String m_tableFile; 142cdf0e10cSrcweir private XMultiServiceFactory m_orb = null; 143cdf0e10cSrcweir 144cdf0e10cSrcweir /** 145cdf0e10cSrcweir * Initializes some class fields. Then creates DataSource, which serves 146cdf0e10cSrcweir * as a single source for all tables created in the test. 147cdf0e10cSrcweir * This DataSource then registered in the global 148cdf0e10cSrcweir * <code>DatabaseContext</code> service. This data source's URL 149cdf0e10cSrcweir * points to SOffice temp directory where tables are copied from 150cdf0e10cSrcweir * <code>TestDocuments</code> directory on every environment 151cdf0e10cSrcweir * creation. 152cdf0e10cSrcweir * To create DataSource for MySQL database next parameters required 153cdf0e10cSrcweir * in ini-file: 154cdf0e10cSrcweir * <ul> 155cdf0e10cSrcweir * <li><code>test.db.url</code> - URL to MySQL database. 156cdf0e10cSrcweir * For example: <code>mysql://mercury:3306/api_current</code></li> 157cdf0e10cSrcweir * <li><code>test.db.user</code> - user for MySQL database</li> 158cdf0e10cSrcweir * <li><code>test.db.password</code> - password for MySQL database</li> 159cdf0e10cSrcweir * </ul> 160cdf0e10cSrcweir * 161cdf0e10cSrcweir * @throws StatusException if DataSource can not be created or 162cdf0e10cSrcweir * registered. 163cdf0e10cSrcweir */ initialize( TestParameters Param, PrintWriter _log)164cdf0e10cSrcweir protected void initialize ( TestParameters Param, PrintWriter _log) 165cdf0e10cSrcweir throws StatusException 166cdf0e10cSrcweir { 167cdf0e10cSrcweir m_orb = (XMultiServiceFactory)Param.getMSF(); 168cdf0e10cSrcweir 169cdf0e10cSrcweir String tmpDir = utils.getOfficeTemp( m_orb ); 170cdf0e10cSrcweir 171cdf0e10cSrcweir origDB = util.utils.getFullTestDocName("TestDB/testDB.dbf"); 172cdf0e10cSrcweir 173cdf0e10cSrcweir dbTools = new DBTools( m_orb, _log ); 174cdf0e10cSrcweir 175cdf0e10cSrcweir // creating DataSource and registering it in DatabaseContext 176cdf0e10cSrcweir String dbURL = (String) Param.get("test.db.url"); 177cdf0e10cSrcweir String dbUser = (String) Param.get("test.db.user"); 178cdf0e10cSrcweir String dbPassword = (String) Param.get("test.db.password"); 179cdf0e10cSrcweir 180cdf0e10cSrcweir log.println("Creating and registering DataSource ..."); 181cdf0e10cSrcweir srcInf = new DataSourceDescriptor( m_orb ); 182cdf0e10cSrcweir if (dbURL != null && dbUser != null && dbPassword != null) 183cdf0e10cSrcweir { 184cdf0e10cSrcweir isMySQLDB = true; 185cdf0e10cSrcweir log.println("dbURL = " + dbURL); 186cdf0e10cSrcweir log.println("dbUSER = " + dbUser); 187cdf0e10cSrcweir log.println("dbPASSWORD = " + dbPassword); 188cdf0e10cSrcweir //DataSource for mysql db 189cdf0e10cSrcweir tableName = "soffice_test_table"; 190cdf0e10cSrcweir srcInf.URL = "jdbc:" + dbURL; 191cdf0e10cSrcweir srcInf.IsPasswordRequired = new Boolean(true); 192cdf0e10cSrcweir srcInf.Password = dbPassword; 193cdf0e10cSrcweir srcInf.User = dbUser; 194cdf0e10cSrcweir PropertyValue[] propInfo = new PropertyValue[1]; 195cdf0e10cSrcweir propInfo[0] = new PropertyValue(); 196cdf0e10cSrcweir propInfo[0].Name = "JavaDriverClass"; 197cdf0e10cSrcweir propInfo[0].Value = "org.gjt.mm.mysql.Driver"; 198cdf0e10cSrcweir srcInf.Info = propInfo; 199cdf0e10cSrcweir } 200cdf0e10cSrcweir else 201cdf0e10cSrcweir { 202cdf0e10cSrcweir srcInf.URL = "sdbc:dbase:" + DBTools.dirToUrl(tmpDir); 203cdf0e10cSrcweir } 204cdf0e10cSrcweir m_dataSource = srcInf.createDataSource(); 205cdf0e10cSrcweir m_dataSource.registerAs( dbSourceName, true ); 206cdf0e10cSrcweir } 207cdf0e10cSrcweir 208cdf0e10cSrcweir /** 209cdf0e10cSrcweir * Creating a Testenvironment for the interfaces to be tested. 210cdf0e10cSrcweir * The database (DBF) file is copied from test document directory 211cdf0e10cSrcweir * into SOffice temp dir with unique name for each enviroment 212cdf0e10cSrcweir * creation. If the file cann't be copied (is not released) 213cdf0e10cSrcweir * then another unique name is used (file name suffix incremented 214cdf0e10cSrcweir * by 1).<p> 215cdf0e10cSrcweir * 216cdf0e10cSrcweir * <code>com.sun.star.sdb.RowSet</code> service created and its 217cdf0e10cSrcweir * source is all rows from the current copy of the table. Then 218cdf0e10cSrcweir * row set command ("select all rows from a table") is executed 219cdf0e10cSrcweir * and cursor is positioned to the first row. <p> 220cdf0e10cSrcweir * 221cdf0e10cSrcweir * Object relations created : 222cdf0e10cSrcweir * <ul> 223cdf0e10cSrcweir * <li> <code>'ORowSet.Connection'</code> for 224cdf0e10cSrcweir * internal component test usage. Is used for 225cdf0e10cSrcweir * closing connection when cleaning up environment. </li> 226cdf0e10cSrcweir * <li> <code>'XRowSetApproveBroadcaster.ApproveChecker'</code> for 227cdf0e10cSrcweir * {@link ifc.sdb._XRowSetApproveBroadcaster} interface 228cdf0e10cSrcweir * implementation which made actions required </li> 229cdf0e10cSrcweir * <li> <code>'CurrentRowData'</code> for 230cdf0e10cSrcweir * {@link ifc.sdbc._XRow}, {@link ifc.sdbc._XRowUpdate} : 231cdf0e10cSrcweir * exports types and values of the current row data.</li> 232cdf0e10cSrcweir * <li> <code>'XColumnLocate.ColumnName'</code> for 233cdf0e10cSrcweir * {@link ifc.sdbc._XColumnLocate} : 234cdf0e10cSrcweir * the name of the first column of the table.</li> 235cdf0e10cSrcweir * <li> <code>'XParameters.ParamValues'</code> for 236cdf0e10cSrcweir * {@link ifc.sdbc._XParameters} : 237cdf0e10cSrcweir * Collection of parameter types presented in the query. </li> 238cdf0e10cSrcweir * <li> <code>'XRowUpdate.XRow'</code> for 239cdf0e10cSrcweir * {@link ifc.sdbc._XRowUpdate} : 240cdf0e10cSrcweir * <code>XRow</code> interface of the current component.</li> 241cdf0e10cSrcweir * <li> <code>'XResultSetUpdate.UpdateTester'</code> for 242cdf0e10cSrcweir * {@link ifc.sdbc._XResultSetUpdate} </li> 243cdf0e10cSrcweir * </ul> 244cdf0e10cSrcweir * 245cdf0e10cSrcweir * @see com.sun.star.sdb.DatabaseContext 246cdf0e10cSrcweir * @see com.sun.star.sdb.DataSource 247cdf0e10cSrcweir */ createTestEnvironment(TestParameters Param, PrintWriter log)248cdf0e10cSrcweir protected TestEnvironment createTestEnvironment(TestParameters Param, 249cdf0e10cSrcweir PrintWriter log) 250cdf0e10cSrcweir { 251cdf0e10cSrcweir XMultiServiceFactory orb = (XMultiServiceFactory)Param.getMSF(); 252cdf0e10cSrcweir uniqueSuffix++; 253cdf0e10cSrcweir boolean envCreatedOK = false ; 254cdf0e10cSrcweir 255cdf0e10cSrcweir //initialize test table 256cdf0e10cSrcweir if (isMySQLDB) 257cdf0e10cSrcweir { 258cdf0e10cSrcweir try 259cdf0e10cSrcweir { 260cdf0e10cSrcweir DBTools.DataSourceInfo legacyDescriptor = dbTools.newDataSourceInfo(); 261cdf0e10cSrcweir legacyDescriptor.Name = srcInf.Name; 262cdf0e10cSrcweir legacyDescriptor.User = srcInf.User; 263cdf0e10cSrcweir legacyDescriptor.Password = srcInf.Password; 264cdf0e10cSrcweir legacyDescriptor.Info = srcInf.Info; 265cdf0e10cSrcweir legacyDescriptor.URL = srcInf.URL; 266cdf0e10cSrcweir legacyDescriptor.IsPasswordRequired = srcInf.IsPasswordRequired; 267cdf0e10cSrcweir dbTools.initTestTableUsingJDBC(tableName, legacyDescriptor); 268cdf0e10cSrcweir } 269cdf0e10cSrcweir catch(java.sql.SQLException e) 270cdf0e10cSrcweir { 271cdf0e10cSrcweir e.printStackTrace(log); 272cdf0e10cSrcweir throw new StatusException(Status.failed("Couldn't " + 273cdf0e10cSrcweir " init test table. SQLException...")); 274cdf0e10cSrcweir } 275cdf0e10cSrcweir catch(java.lang.ClassNotFoundException e) 276cdf0e10cSrcweir { 277cdf0e10cSrcweir throw new StatusException(Status.failed("Couldn't " + 278cdf0e10cSrcweir "register mysql driver")); 279cdf0e10cSrcweir } 280cdf0e10cSrcweir } 281cdf0e10cSrcweir else 282cdf0e10cSrcweir { 283cdf0e10cSrcweir String oldF = null ; 284cdf0e10cSrcweir String newF = null ; 285cdf0e10cSrcweir String tempFolder = utils.getOfficeTemp( orb ); 286cdf0e10cSrcweir do 287cdf0e10cSrcweir { 288cdf0e10cSrcweir tableName = "ORowSet_tmp" + uniqueSuffix ; 289cdf0e10cSrcweir oldF = utils.getFullURL(origDB); 290cdf0e10cSrcweir newF = tempFolder + tableName + ".dbf"; 291cdf0e10cSrcweir } 292cdf0e10cSrcweir while ( !utils.tryOverwriteFile( orb, oldF, newF ) ); 293cdf0e10cSrcweir m_tableFile = newF; 294cdf0e10cSrcweir } 295cdf0e10cSrcweir 296cdf0e10cSrcweir try 297cdf0e10cSrcweir { 298cdf0e10cSrcweir m_rowSet = orb.createInstance("com.sun.star.sdb.RowSet"); 299cdf0e10cSrcweir 300cdf0e10cSrcweir XPropertySet rowSetProps = UnoRuntime.queryInterface( XPropertySet.class, m_rowSet ); 301cdf0e10cSrcweir 302cdf0e10cSrcweir log.println("Trying to open: " + tableName); 303cdf0e10cSrcweir 304cdf0e10cSrcweir rowSetProps.setPropertyValue("DataSourceName", dbSourceName); 305cdf0e10cSrcweir rowSetProps.setPropertyValue("Command", tableName); 306cdf0e10cSrcweir rowSetProps.setPropertyValue("CommandType", 307cdf0e10cSrcweir new Integer(CommandType.TABLE)); 308cdf0e10cSrcweir 309cdf0e10cSrcweir final XRowSet rowSet = UnoRuntime.queryInterface( XRowSet.class, m_rowSet); 310cdf0e10cSrcweir rowSet.execute(); 311cdf0e10cSrcweir m_connection = UnoRuntime.queryInterface( XConnection.class, rowSetProps.getPropertyValue("ActiveConnection") ); 312cdf0e10cSrcweir 313cdf0e10cSrcweir XResultSet xRes = UnoRuntime.queryInterface( XResultSet.class, m_rowSet ); 314cdf0e10cSrcweir xRes.first(); 315cdf0e10cSrcweir 316cdf0e10cSrcweir log.println( "creating a new environment for object" ); 317cdf0e10cSrcweir TestEnvironment tEnv = new TestEnvironment( (XInterface)m_rowSet ); 318cdf0e10cSrcweir 319cdf0e10cSrcweir // Adding obj relation for XRowSetApproveBroadcaster test 320cdf0e10cSrcweir { 321cdf0e10cSrcweir final XResultSet resultSet = UnoRuntime.queryInterface( XResultSet.class, m_rowSet ); 322cdf0e10cSrcweir final XResultSetUpdate resultSetUpdate = UnoRuntime.queryInterface( XResultSetUpdate.class, m_rowSet ); 323cdf0e10cSrcweir final XRowUpdate rowUpdate = UnoRuntime.queryInterface(XRowUpdate.class, m_rowSet ); 324cdf0e10cSrcweir final PrintWriter logF = log ; 325cdf0e10cSrcweir tEnv.addObjRelation( "XRowSetApproveBroadcaster.ApproveChecker", 326cdf0e10cSrcweir new ifc.sdb._XRowSetApproveBroadcaster.RowSetApproveChecker() 327cdf0e10cSrcweir { 328cdf0e10cSrcweir public void moveCursor() 329cdf0e10cSrcweir { 330cdf0e10cSrcweir try 331cdf0e10cSrcweir { 332cdf0e10cSrcweir resultSet.beforeFirst(); 333cdf0e10cSrcweir resultSet.afterLast(); 334cdf0e10cSrcweir resultSet.first(); 335cdf0e10cSrcweir } 336cdf0e10cSrcweir catch (com.sun.star.sdbc.SQLException e) 337cdf0e10cSrcweir { 338cdf0e10cSrcweir logF.println("### _XRowSetApproveBroadcaster.RowSetApproveChecker.moveCursor() :"); 339cdf0e10cSrcweir e.printStackTrace(logF); 340cdf0e10cSrcweir throw new StatusException( "RowSetApproveChecker.moveCursor failed", e ); 341cdf0e10cSrcweir } 342cdf0e10cSrcweir } 343cdf0e10cSrcweir public RowChangeEvent changeRow() 344cdf0e10cSrcweir { 345cdf0e10cSrcweir try 346cdf0e10cSrcweir { 347cdf0e10cSrcweir resultSet.first(); 348cdf0e10cSrcweir rowUpdate.updateString(1, "ORowSetTest2"); 349cdf0e10cSrcweir resultSetUpdate.updateRow(); 350cdf0e10cSrcweir } 351cdf0e10cSrcweir catch (com.sun.star.sdbc.SQLException e) 352cdf0e10cSrcweir { 353cdf0e10cSrcweir logF.println("### _XRowSetApproveBroadcaster.RowSetApproveChecker.changeRow() :"); 354cdf0e10cSrcweir e.printStackTrace(logF); 355cdf0e10cSrcweir throw new StatusException( "RowSetApproveChecker.changeRow failed", e ); 356cdf0e10cSrcweir } 357cdf0e10cSrcweir RowChangeEvent ev = new RowChangeEvent(); 358cdf0e10cSrcweir ev.Action = com.sun.star.sdb.RowChangeAction.UPDATE ; 359cdf0e10cSrcweir ev.Rows = 1 ; 360cdf0e10cSrcweir 361cdf0e10cSrcweir return ev ; 362cdf0e10cSrcweir } 363cdf0e10cSrcweir public void changeRowSet() 364cdf0e10cSrcweir { 365cdf0e10cSrcweir try 366cdf0e10cSrcweir { 367cdf0e10cSrcweir // since we gave the row set a parametrized statement, we need to ensure the 368cdf0e10cSrcweir // parameter is actually filled, otherwise we would get an empty result set, 369cdf0e10cSrcweir // which would imply some further tests failing 370cdf0e10cSrcweir XParameters rowSetParams = UnoRuntime.queryInterface( XParameters.class, resultSet ); 371cdf0e10cSrcweir rowSetParams.setString( 1, "String2" ); 372cdf0e10cSrcweir rowSet.execute(); 373cdf0e10cSrcweir resultSet.first(); 374cdf0e10cSrcweir } 375cdf0e10cSrcweir catch (com.sun.star.sdbc.SQLException e) 376cdf0e10cSrcweir { 377cdf0e10cSrcweir logF.println("### _XRowSetApproveBroadcaster.RowSetApproveChecker.changeRowSet() :"); 378cdf0e10cSrcweir e.printStackTrace(logF); 379cdf0e10cSrcweir throw new StatusException( "RowSetApproveChecker.changeRowSet failed", e ); 380cdf0e10cSrcweir } 381cdf0e10cSrcweir } 382cdf0e10cSrcweir } 383cdf0e10cSrcweir ); 384cdf0e10cSrcweir } 385cdf0e10cSrcweir // Adding relations for XRow as a Vector with all data 386cdf0e10cSrcweir // of current row of RowSet. 387cdf0e10cSrcweir 388cdf0e10cSrcweir Vector rowData = new Vector(); 389cdf0e10cSrcweir 390cdf0e10cSrcweir for (int i = 0; i < DBTools.TST_TABLE_VALUES[0].length; i++) { 391cdf0e10cSrcweir rowData.add(DBTools.TST_TABLE_VALUES[0][i]); 392cdf0e10cSrcweir } 393cdf0e10cSrcweir 394cdf0e10cSrcweir // here XRef must be added 395cdf0e10cSrcweir // here XBlob must be added 396cdf0e10cSrcweir // here XClob must be added 397cdf0e10cSrcweir // here XArray must be added 398cdf0e10cSrcweir 399cdf0e10cSrcweir tEnv.addObjRelation("CurrentRowData", rowData); 400cdf0e10cSrcweir 401cdf0e10cSrcweir // Adding relation for XColumnLocate ifc test 402cdf0e10cSrcweir tEnv.addObjRelation( "XColumnLocate.ColumnName", DBTools.TST_STRING_F ); 403cdf0e10cSrcweir 404cdf0e10cSrcweir // Adding relation for XCompletedExecution 405cdf0e10cSrcweir tEnv.addObjRelation( "InteractionHandlerChecker", new InteractionHandlerImpl() ); 406cdf0e10cSrcweir try 407cdf0e10cSrcweir { 408cdf0e10cSrcweir String sqlCommand = isMySQLDB 409cdf0e10cSrcweir ? "SELECT Column0 FROM soffice_test_table WHERE ( ( Column0 = :param1 ) )" 410cdf0e10cSrcweir : "SELECT \"_TEXT\" FROM \"" + tableName + "\" WHERE ( ( \"_TEXT\" = :param1 ) )"; 411cdf0e10cSrcweir rowSetProps.setPropertyValue( "DataSourceName", dbSourceName ); 412cdf0e10cSrcweir rowSetProps.setPropertyValue( "Command", sqlCommand ); 413cdf0e10cSrcweir rowSetProps.setPropertyValue( "CommandType", new Integer(CommandType.COMMAND) ); 414cdf0e10cSrcweir } 415cdf0e10cSrcweir catch(Exception e) 416cdf0e10cSrcweir { 417cdf0e10cSrcweir throw new StatusException( "setting up the RowSet with a parametrized command failed", e ); 418cdf0e10cSrcweir } 419cdf0e10cSrcweir 420cdf0e10cSrcweir // Adding relation for XParameters ifc test 421cdf0e10cSrcweir tEnv.addObjRelation( "XParameters.ParamValues", new Vector() ); 422cdf0e10cSrcweir 423cdf0e10cSrcweir // Adding relation for XRowUpdate 424cdf0e10cSrcweir final XRow row = UnoRuntime.queryInterface( XRow.class, m_rowSet ); 425cdf0e10cSrcweir tEnv.addObjRelation("XRowUpdate.XRow", row); 426cdf0e10cSrcweir 427cdf0e10cSrcweir // Adding relation for XResultSetUpdate 428cdf0e10cSrcweir { 429cdf0e10cSrcweir final XResultSet resultSet = UnoRuntime.queryInterface( XResultSet.class, m_rowSet ); 430cdf0e10cSrcweir final XRowUpdate rowUpdate = UnoRuntime.queryInterface( XRowUpdate.class, m_rowSet ); 431cdf0e10cSrcweir 432cdf0e10cSrcweir tEnv.addObjRelation("XResultSetUpdate.UpdateTester", 433cdf0e10cSrcweir new ifc.sdbc._XResultSetUpdate.UpdateTester() 434cdf0e10cSrcweir { 435cdf0e10cSrcweir String lastUpdate = null ; 436cdf0e10cSrcweir 437cdf0e10cSrcweir public int rowCount() throws SQLException 438cdf0e10cSrcweir { 439cdf0e10cSrcweir int prevPos = resultSet.getRow(); 440cdf0e10cSrcweir resultSet.last(); 441cdf0e10cSrcweir int count = resultSet.getRow(); 442cdf0e10cSrcweir resultSet.absolute(prevPos); 443cdf0e10cSrcweir 444cdf0e10cSrcweir return count ; 445cdf0e10cSrcweir } 446cdf0e10cSrcweir 447cdf0e10cSrcweir public void update() throws SQLException 448cdf0e10cSrcweir { 449cdf0e10cSrcweir lastUpdate = row.getString(1); 450cdf0e10cSrcweir lastUpdate += "_" ; 451cdf0e10cSrcweir rowUpdate.updateString(1, lastUpdate); 452cdf0e10cSrcweir } 453cdf0e10cSrcweir 454cdf0e10cSrcweir public boolean wasUpdated() throws SQLException 455cdf0e10cSrcweir { 456cdf0e10cSrcweir String getStr = row.getString(1); 457cdf0e10cSrcweir return lastUpdate.equals(getStr); 458cdf0e10cSrcweir } 459cdf0e10cSrcweir 460cdf0e10cSrcweir public int currentRow() throws SQLException 461cdf0e10cSrcweir { 462cdf0e10cSrcweir return resultSet.getRow(); 463cdf0e10cSrcweir } 464cdf0e10cSrcweir } 465cdf0e10cSrcweir ); 466cdf0e10cSrcweir } 467cdf0e10cSrcweir 468cdf0e10cSrcweir envCreatedOK = true ; 469cdf0e10cSrcweir return tEnv; 470cdf0e10cSrcweir 471cdf0e10cSrcweir } 472cdf0e10cSrcweir catch(com.sun.star.uno.Exception e) 473cdf0e10cSrcweir { 474cdf0e10cSrcweir log.println( "couldn't set up tes tenvironment:" ); 475cdf0e10cSrcweir e.printStackTrace(log); 476cdf0e10cSrcweir try 477cdf0e10cSrcweir { 478cdf0e10cSrcweir if ( m_connection != null ) 479cdf0e10cSrcweir m_connection.close(); 480cdf0e10cSrcweir } 481cdf0e10cSrcweir catch(Exception ex) 482cdf0e10cSrcweir { 483cdf0e10cSrcweir } 484cdf0e10cSrcweir throw new StatusException( "couldn't set up tes tenvironment", e ); 485cdf0e10cSrcweir } 486cdf0e10cSrcweir finally 487cdf0e10cSrcweir { 488cdf0e10cSrcweir if (!envCreatedOK) 489cdf0e10cSrcweir { 490cdf0e10cSrcweir try 491cdf0e10cSrcweir { 492cdf0e10cSrcweir m_connection.close(); 493cdf0e10cSrcweir } 494cdf0e10cSrcweir catch(Exception ex) 495cdf0e10cSrcweir { 496cdf0e10cSrcweir } 497cdf0e10cSrcweir } 498cdf0e10cSrcweir } 499cdf0e10cSrcweir 500cdf0e10cSrcweir } // finish method getTestEnvironment 501cdf0e10cSrcweir 502cdf0e10cSrcweir /** 503cdf0e10cSrcweir * Closes connection of <code>RowSet</code> instance created. 504cdf0e10cSrcweir */ cleanup( TestParameters Param, PrintWriter log)505cdf0e10cSrcweir protected void cleanup( TestParameters Param, PrintWriter log) 506cdf0e10cSrcweir { 507cdf0e10cSrcweir String doing = null; 508cdf0e10cSrcweir try 509cdf0e10cSrcweir { 510cdf0e10cSrcweir doing = "revoking data source registration"; 511cdf0e10cSrcweir log.println( doing ); 512cdf0e10cSrcweir m_dataSource.revokeRegistration(); 513cdf0e10cSrcweir 514cdf0e10cSrcweir doing = "closing database document"; 515cdf0e10cSrcweir log.println( doing ); 516cdf0e10cSrcweir XModel databaseDocModel = UnoRuntime.queryInterface( XModel.class, 517cdf0e10cSrcweir m_dataSource.getDatabaseDocument().getDatabaseDocument() ); 518cdf0e10cSrcweir String documentFile = databaseDocModel.getURL(); 519cdf0e10cSrcweir 520cdf0e10cSrcweir XCloseable closeModel = UnoRuntime.queryInterface( XCloseable.class, 521cdf0e10cSrcweir m_dataSource.getDatabaseDocument().getDatabaseDocument() ); 522cdf0e10cSrcweir closeModel.close( true ); 523cdf0e10cSrcweir 524cdf0e10cSrcweir if ( m_rowSet != null ) 525cdf0e10cSrcweir { 526cdf0e10cSrcweir doing = "disposing row set"; 527cdf0e10cSrcweir log.println( doing ); 528cdf0e10cSrcweir XComponent rowSetComponent = UnoRuntime.queryInterface( XComponent.class, m_rowSet ); 529cdf0e10cSrcweir rowSetComponent.dispose(); 530cdf0e10cSrcweir } 531cdf0e10cSrcweir 532cdf0e10cSrcweir try 533cdf0e10cSrcweir { 534cdf0e10cSrcweir doing = "closing connection"; 535cdf0e10cSrcweir log.println( doing ); 536cdf0e10cSrcweir m_connection.close(); 537cdf0e10cSrcweir } 538cdf0e10cSrcweir catch (com.sun.star.lang.DisposedException e) 539cdf0e10cSrcweir { 540cdf0e10cSrcweir log.println( "already closed - okay." ); 541cdf0e10cSrcweir } 542cdf0e10cSrcweir 543cdf0e10cSrcweir doing = "deleting database file (" + documentFile + ")"; 544cdf0e10cSrcweir log.println( doing ); 545cdf0e10cSrcweir impl_deleteFile( documentFile ); 546cdf0e10cSrcweir 547cdf0e10cSrcweir if ( m_tableFile != null ) 548cdf0e10cSrcweir { 549cdf0e10cSrcweir doing = "deleting dBase table file (" + m_tableFile + ")"; 550cdf0e10cSrcweir log.println( doing ); 551cdf0e10cSrcweir impl_deleteFile( m_tableFile ); 552cdf0e10cSrcweir } 553cdf0e10cSrcweir } 554cdf0e10cSrcweir catch (com.sun.star.uno.Exception e) 555cdf0e10cSrcweir { 556cdf0e10cSrcweir log.println( "error: "); 557cdf0e10cSrcweir e.printStackTrace(log); 558cdf0e10cSrcweir } 559cdf0e10cSrcweir } 560cdf0e10cSrcweir impl_deleteFile( final String _file )561cdf0e10cSrcweir private final void impl_deleteFile( final String _file ) 562cdf0e10cSrcweir { 563cdf0e10cSrcweir java.io.File file = new java.io.File( _file ); 564cdf0e10cSrcweir file.delete(); 565cdf0e10cSrcweir if ( file.exists() ) 566cdf0e10cSrcweir file.deleteOnExit(); 567cdf0e10cSrcweir } 568cdf0e10cSrcweir 569cdf0e10cSrcweir /** 570cdf0e10cSrcweir * Implementation of interface _XCompletedExecution.CheckInteractionHandler 571cdf0e10cSrcweir * for the XCompletedExecution test 572cdf0e10cSrcweir * @see ifc.sdb._XCompletedExecution 573cdf0e10cSrcweir */ 574cdf0e10cSrcweir public class InteractionHandlerImpl implements _XCompletedExecution.CheckInteractionHandler { 575cdf0e10cSrcweir private boolean handlerWasUsed = false; 576cdf0e10cSrcweir private PrintWriter log = new PrintWriter(System.out); 577cdf0e10cSrcweir checkInteractionHandler()578cdf0e10cSrcweir public boolean checkInteractionHandler() { 579cdf0e10cSrcweir return handlerWasUsed; 580cdf0e10cSrcweir } 581cdf0e10cSrcweir handle(XInteractionRequest xInteractionRequest)582cdf0e10cSrcweir public void handle(XInteractionRequest xInteractionRequest) { 583cdf0e10cSrcweir log.println("### _XCompletedExecution.InteractionHandlerImpl: handle called."); 584cdf0e10cSrcweir ParametersRequest req = null; 585cdf0e10cSrcweir boolean abort = false; 586cdf0e10cSrcweir 587cdf0e10cSrcweir Object o = xInteractionRequest.getRequest(); 588cdf0e10cSrcweir if (o instanceof ParametersRequest) { 589cdf0e10cSrcweir req = (ParametersRequest)o; 590cdf0e10cSrcweir } 591cdf0e10cSrcweir else if (o instanceof AuthenticationRequest) { 592cdf0e10cSrcweir log.println("### The request in XCompletedExecution is of type 'AuthenticationRequest'"); 593cdf0e10cSrcweir log.println("### This is not implemented in ORowSet.InteractionHandlerImpl test -> abort."); 594cdf0e10cSrcweir abort = true; 595cdf0e10cSrcweir } 596cdf0e10cSrcweir else { 597cdf0e10cSrcweir log.println("### Unknown request:" + o.toString()); 598cdf0e10cSrcweir log.println("### This is not implemented in ORowSet.InteractionHandlerImpl test -> abort."); 599cdf0e10cSrcweir abort = true; 600cdf0e10cSrcweir } 601cdf0e10cSrcweir 602cdf0e10cSrcweir XInteractionContinuation[]xCont = xInteractionRequest.getContinuations(); 603cdf0e10cSrcweir XInteractionSupplyParameters xParamCallback = null; 604cdf0e10cSrcweir for(int i=0; i<xCont.length; i++) { 605cdf0e10cSrcweir if (abort) { 606cdf0e10cSrcweir XInteractionAbort xAbort = null; 607cdf0e10cSrcweir xAbort = UnoRuntime.queryInterface(XInteractionAbort.class, xCont[i]); 608cdf0e10cSrcweir if (xAbort != null) 609cdf0e10cSrcweir xAbort.select(); 610cdf0e10cSrcweir return; 611cdf0e10cSrcweir } 612cdf0e10cSrcweir else { 613cdf0e10cSrcweir xParamCallback = UnoRuntime.queryInterface(XInteractionSupplyParameters.class, xCont[i]); 614cdf0e10cSrcweir if (xParamCallback != null) 615cdf0e10cSrcweir break; 616cdf0e10cSrcweir } 617cdf0e10cSrcweir } 618cdf0e10cSrcweir if (xParamCallback != null) { 619cdf0e10cSrcweir log.println("### _XCompletedExecution.InteractionHandlerImpl: supplying parameters."); 620cdf0e10cSrcweir handlerWasUsed = true; 621cdf0e10cSrcweir PropertyValue[] prop = new PropertyValue[1]; 622cdf0e10cSrcweir prop[0] = new PropertyValue(); 623cdf0e10cSrcweir prop[0].Name = "param1"; 624cdf0e10cSrcweir prop[0].Value = "Hi."; 625cdf0e10cSrcweir 626cdf0e10cSrcweir xParamCallback.setParameters(prop); 627cdf0e10cSrcweir xParamCallback.select(); 628cdf0e10cSrcweir } 629cdf0e10cSrcweir else { // we should never reach this: abort has to be true first. 630cdf0e10cSrcweir log.println("### _XCompletedExecution.InteractionHandlerImpl: Got no " + 631cdf0e10cSrcweir "'XInteractionSupplyParameters' and no 'XInteractionAbort'."); 632cdf0e10cSrcweir } 633cdf0e10cSrcweir } 634cdf0e10cSrcweir setLog(PrintWriter log)635cdf0e10cSrcweir public void setLog(PrintWriter log) { 636cdf0e10cSrcweir this.log = log; 637cdf0e10cSrcweir } 638cdf0e10cSrcweir 639cdf0e10cSrcweir } 640cdf0e10cSrcweir } 641