/*************************************************************************
*
* $RCSfile: ORowSet.java,v $
*
* $Revision: 1.6 $
*
* last change:$Date: 2004-08-02 17:57:14 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc., October, 2000
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2000 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 (the "License"); You may not use this file
* except in compliance with the License. You may obtain a copy of the
* License at http://www.openoffice.org/license.html.
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): _______________________________________
*
*
************************************************************************/
package mod._dbaccess;
import com.sun.star.beans.Property;
import java.io.PrintWriter;
import java.util.Vector;
import lib.Status;
import lib.StatusException;
import lib.TestCase;
import lib.TestEnvironment;
import lib.TestParameters;
import util.DBTools;
import util.utils;
import com.sun.star.beans.PropertyValue;
import com.sun.star.beans.XPropertySet;
import com.sun.star.container.XIndexAccess;
import com.sun.star.frame.XStorable;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.sdb.CommandType;
import com.sun.star.sdb.ParametersRequest;
import com.sun.star.sdb.RowChangeEvent;
import com.sun.star.sdb.XInteractionSupplyParameters;
import com.sun.star.sdbc.SQLException;
import com.sun.star.sdbc.XConnection;
import com.sun.star.sdbc.XResultSet;
import com.sun.star.sdbc.XResultSetUpdate;
import com.sun.star.sdbc.XRow;
import com.sun.star.sdbc.XRowSet;
import com.sun.star.sdbc.XRowUpdate;
import com.sun.star.task.XInteractionAbort;
import com.sun.star.task.XInteractionContinuation;
import com.sun.star.task.XInteractionRequest;
import com.sun.star.ucb.AuthenticationRequest;
import com.sun.star.ucb.XSimpleFileAccess;
import com.sun.star.uno.Any;
import com.sun.star.uno.AnyConverter;
import com.sun.star.uno.Type;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XInterface;
import ifc.sdb._XCompletedExecution;
/**
* Test for object which is represented by service
* com.sun.star.sdb.DataSource.
* * Object implements the following interfaces : *
com::sun::star::sdbc::RowSetcom::sun::star::sdbcx::XRowLocatecom::sun::star::sdbc::XResultSetUpdatecom::sun::star::util::XCancellablecom::sun::star::sdbc::XParameterscom::sun::star::sdbc::XResultSetMetaDataSuppliercom::sun::star::sdbcx::XDeleteRowscom::sun::star::sdbc::XCloseablecom::sun::star::sdbcx::XColumnsSuppliercom::sun::star::sdb::XResultSetAccesscom::sun::star::sdbc::XResultSetcom::sun::star::sdbc::XColumnLocatecom::sun::star::sdbc::XRowSetcom::sun::star::sdb::RowSetcom::sun::star::sdbc::XRowUpdatecom::sun::star::sdb::XRowSetApproveBroadcastercom::sun::star::beans::XPropertySetcom::sun::star::sdbc::XRowcom::sun::star::sdbc::XWarningsSuppliercom::sun::star::lang::XComponentcom::sun::star::sdbcx::ResultSetcom::sun::star::sdbc::ResultSet* The following files used by this test : *
util.DBTools.
* The copy of this file is always made in temp directory for
* testing purposes.* The following parameters in ini-file used by this test: *
test.db.url - URL to MySQL database.
* For example: mysql://mercury:3306/api_currenttest.db.user - user for MySQL databasetest.db.password - password for MySQL database
*
* @see com.sun.star.sdbc.RowSet
* @see com.sun.star.sdbcx.XRowLocate
* @see com.sun.star.sdbc.XResultSetUpdate
* @see com.sun.star.util.XCancellable
* @see com.sun.star.sdbc.XParameters
* @see com.sun.star.sdbc.XResultSetMetaDataSupplier
* @see com.sun.star.sdbcx.XDeleteRows
* @see com.sun.star.sdbc.XCloseable
* @see com.sun.star.sdbcx.XColumnsSupplier
* @see com.sun.star.sdb.XResultSetAccess
* @see com.sun.star.sdbc.XResultSet
* @see com.sun.star.sdbc.XColumnLocate
* @see com.sun.star.sdbc.XRowSet
* @see com.sun.star.sdb.RowSet
* @see com.sun.star.sdbc.XRowUpdate
* @see com.sun.star.sdb.XRowSetApproveBroadcaster
* @see com.sun.star.beans.XPropertySet
* @see com.sun.star.sdbc.XRow
* @see com.sun.star.sdbc.XWarningsSupplier
* @see com.sun.star.lang.XComponent
* @see com.sun.star.sdbcx.ResultSet
* @see com.sun.star.sdbc.ResultSet
* @see ifc.sdbc._RowSet
* @see ifc.sdbcx._XRowLocate
* @see ifc.sdbc._XResultSetUpdate
* @see ifc.util._XCancellable
* @see ifc.sdbc._XParameters
* @see ifc.sdbc._XResultSetMetaDataSupplier
* @see ifc.sdbcx._XDeleteRows
* @see ifc.sdbc._XCloseable
* @see ifc.sdbcx._XColumnsSupplier
* @see ifc.sdb._XResultSetAccess
* @see ifc.sdbc._XResultSet
* @see ifc.sdbc._XColumnLocate
* @see ifc.sdbc._XRowSet
* @see ifc.sdb._RowSet
* @see ifc.sdbc._XRowUpdate
* @see ifc.sdb._XRowSetApproveBroadcaster
* @see ifc.beans._XPropertySet
* @see ifc.sdbc._XRow
* @see ifc.sdbc._XWarningsSupplier
* @see ifc.lang._XComponent
* @see ifc.sdbcx._ResultSet
* @see ifc.sdbc._ResultSet
*/
public class ORowSet extends TestCase {
private static int uniqueSuffix = 0 ;
private DBTools dbTools = null ;
private static String origDB = null ;
private PrintWriter log = null ;
private static String tmpDir = null ;
String tableName = null;
DBTools.DataSourceInfo srcInf = null;
boolean isMySQLDB = false;
protected final static String dbSourceName = "ORowSetDataSource";
public XConnection conn = null;
Object dbSrc = null;
String aFile = "";
/**
* Initializes some class fields. Then creates DataSource, which serves
* as a single source for all tables created in the test.
* This DataSource then registered in the global
* DatabaseContext service. This data source's URL
* points to SOffice temp directory where tables are copied from
* TestDocuments directory on every environment
* creation.
* To create DataSource for MySQL database next parameters required
* in ini-file:
*
test.db.url - URL to MySQL database.
* For example: mysql://mercury:3306/api_currenttest.db.user - user for MySQL databasetest.db.password - password for MySQL database
*
* com.sun.star.sdb.RowSet service created and its
* source is all rows from the current copy of the table. Then
* row set command ("select all rows from a table") is executed
* and cursor is positioned to the first row.
* * Object relations created : *
'ORowSet.Connection' for
* internal component test usage. Is used for
* closing connection when cleaning up environment. 'XRowSetApproveBroadcaster.ApproveChecker' for
* {@link ifc.sdb._XRowSetApproveBroadcaster} interface
* implementation which made actions required 'CurrentRowData' for
* {@link ifc.sdbc._XRow}, {@link ifc.sdbc._XRowUpdate} :
* exports types and values of the current row data.'XColumnLocate.ColumnName' for
* {@link ifc.sdbc._XColumnLocate} :
* the name of the first column of the table.'XParameters.ParamValues' for
* {@link ifc.sdbc._XParameters} :
* Collection of parameter types presented in the query. 'XRowUpdate.XRow' for
* {@link ifc.sdbc._XRowUpdate} :
* XRow interface of the current component.'XResultSetUpdate.UpdateTester' for
* {@link ifc.sdbc._XResultSetUpdate} RowSet instance created.
*/
protected void cleanup( TestParameters Param, PrintWriter log) {
try {
conn.close() ;
XMultiServiceFactory xMSF = (XMultiServiceFactory)Param.getMSF ();
Object sfa = xMSF.createInstance ("com.sun.star.comp.ucb.SimpleFileAccess");
XSimpleFileAccess xSFA = (XSimpleFileAccess) UnoRuntime.queryInterface (XSimpleFileAccess.class, sfa);
log.println ("deleting database file");
xSFA.kill (aFile);
log.println ("Could delete file "+aFile+": "+!xSFA.exists (aFile));
} catch (com.sun.star.uno.Exception e) {
log.println("Can't close the connection") ;
e.printStackTrace(log) ;
} catch (com.sun.star.lang.DisposedException e) {
log.println("Connection was already closed. It's OK.") ;
}
// try {
// dbTools.revokeDB(dbSourceName) ;
// XComponent db = (XComponent) UnoRuntime.queryInterface(XComponent.class,dbSrc);
// db.dispose();
// } catch (com.sun.star.uno.Exception e) {
// log.println("Error while object test cleaning up :") ;
// e.printStackTrace(log) ;
// throw new StatusException("Error while object test cleaning up",e) ;
// }
}
/**
* Implementation of interface _XCompletedExecution.CheckInteractionHandler
* for the XCompletedExecution test
* @see ifc.sdb._XCompletedExecution
*/
public class InteractionHandlerImpl implements _XCompletedExecution.CheckInteractionHandler {
private boolean handlerWasUsed = false;
private PrintWriter log = new PrintWriter(System.out);
public boolean checkInteractionHandler() {
return handlerWasUsed;
}
public void handle(XInteractionRequest xInteractionRequest) {
log.println("### _XCompletedExecution.InteractionHandlerImpl: handle called.");
ParametersRequest req = null;
boolean abort = false;
Object o = xInteractionRequest.getRequest();
if (o instanceof ParametersRequest) {
req = (ParametersRequest)o;
}
else if (o instanceof AuthenticationRequest) {
log.println("### The request in XCompletedExecution is of type 'AuthenticationRequest'");
log.println("### This is not implemented in ORowSet.InteractionHandlerImpl test -> abort.");
abort = true;
}
else {
log.println("### Unknown request:" + o.toString());
log.println("### This is not implemented in ORowSet.InteractionHandlerImpl test -> abort.");
abort = true;
}
XInteractionContinuation[]xCont = xInteractionRequest.getContinuations();
XInteractionSupplyParameters xParamCallback = null;
for(int i=0; i