summaryrefslogtreecommitdiff
path: root/connectivity/qa/connectivity/tools
diff options
context:
space:
mode:
Diffstat (limited to 'connectivity/qa/connectivity/tools')
-rwxr-xr-xconnectivity/qa/connectivity/tools/AbstractDatabase.java36
-rw-r--r--connectivity/qa/connectivity/tools/CRMDatabase.java292
-rw-r--r--connectivity/qa/connectivity/tools/DataSource.java45
-rwxr-xr-xconnectivity/qa/connectivity/tools/DatabaseAccess.java9
-rwxr-xr-x[-rw-r--r--]connectivity/qa/connectivity/tools/DbaseDatabase.java5
-rw-r--r--connectivity/qa/connectivity/tools/HsqlColumnDescriptor.java5
-rw-r--r--connectivity/qa/connectivity/tools/HsqlDatabase.java18
-rw-r--r--connectivity/qa/connectivity/tools/HsqlTableDescriptor.java21
-rw-r--r--connectivity/qa/connectivity/tools/QueryDefinition.java5
-rw-r--r--connectivity/qa/connectivity/tools/RowSet.java5
-rw-r--r--connectivity/qa/connectivity/tools/makefile.mk20
-rw-r--r--connectivity/qa/connectivity/tools/sdb/Connection.java93
12 files changed, 435 insertions, 119 deletions
diff --git a/connectivity/qa/connectivity/tools/AbstractDatabase.java b/connectivity/qa/connectivity/tools/AbstractDatabase.java
index d3150cd8aa07..b47c7c7961da 100755
--- a/connectivity/qa/connectivity/tools/AbstractDatabase.java
+++ b/connectivity/qa/connectivity/tools/AbstractDatabase.java
@@ -2,13 +2,10 @@
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
- * Copyright 2008 by Sun Microsystems, Inc.
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
- * $RCSfile: RowSetEventListener.java,v $
- * $Revision: 1.4 $
- *
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
@@ -38,10 +35,10 @@ import com.sun.star.sdb.XDocumentDataSource;
import com.sun.star.sdb.XOfficeDatabaseDocument;
import com.sun.star.sdbc.SQLException;
import com.sun.star.sdbc.XCloseable;
-import com.sun.star.sdbc.XConnection;
import com.sun.star.sdbc.XStatement;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.util.CloseVetoException;
+import connectivity.tools.sdb.Connection;
import java.io.File;
/**
@@ -60,7 +57,7 @@ public abstract class AbstractDatabase implements DatabaseAccess
// the data source belonging to the database document
protected DataSource m_dataSource;
// the default connection
- protected XConnection m_connection;
+ protected Connection m_connection;
public AbstractDatabase(final XMultiServiceFactory orb) throws Exception
{
@@ -80,12 +77,10 @@ public abstract class AbstractDatabase implements DatabaseAccess
* the ownership of the connection, so you don't need to (and should not) dispose/close it.
*
*/
- public XConnection defaultConnection() throws SQLException
+ public Connection defaultConnection() throws SQLException
{
- if (m_connection == null)
- {
- m_connection = m_databaseDocument.getDataSource().getConnection("", "");
- }
+ if ( m_connection == null )
+ m_connection = new Connection( m_databaseDocument.getDataSource().getConnection("", "") );
return m_connection;
}
@@ -104,8 +99,7 @@ public abstract class AbstractDatabase implements DatabaseAccess
{
if (m_databaseDocument != null)
{
- final XStorable storeDoc = (XStorable) UnoRuntime.queryInterface(XStorable.class,
- m_databaseDocument);
+ final XStorable storeDoc = UnoRuntime.queryInterface(XStorable.class, m_databaseDocument);
storeDoc.store();
}
}
@@ -118,8 +112,8 @@ public abstract class AbstractDatabase implements DatabaseAccess
public void close()
{
// close connection
- final XCloseable closeConn = (XCloseable) UnoRuntime.queryInterface(XCloseable.class,
- m_connection);
+ final XCloseable closeConn = UnoRuntime.queryInterface( XCloseable.class,
+ m_connection != null ? m_connection.getXConnection() : null );
if (closeConn != null)
{
try
@@ -133,8 +127,7 @@ public abstract class AbstractDatabase implements DatabaseAccess
m_connection = null;
// close document
- final com.sun.star.util.XCloseable closeDoc = (com.sun.star.util.XCloseable) UnoRuntime.queryInterface(
- com.sun.star.util.XCloseable.class, m_databaseDocument);
+ final com.sun.star.util.XCloseable closeDoc = UnoRuntime.queryInterface( com.sun.star.util.XCloseable.class, m_databaseDocument );
if (closeDoc != null)
{
try
@@ -178,7 +171,7 @@ public abstract class AbstractDatabase implements DatabaseAccess
*/
public XModel getModel()
{
- return (XModel) UnoRuntime.queryInterface(XModel.class, m_databaseDocument);
+ return UnoRuntime.queryInterface( XModel.class, m_databaseDocument );
}
public XMultiServiceFactory getORB()
@@ -191,10 +184,9 @@ public abstract class AbstractDatabase implements DatabaseAccess
{
m_databaseDocumentFile = _docURL;
- final XNameAccess dbContext = (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class,
- m_orb.createInstance("com.sun.star.sdb.DatabaseContext"));
- final XDocumentDataSource dataSource = (XDocumentDataSource) UnoRuntime.queryInterface(XDocumentDataSource.class,
- dbContext.getByName(_docURL));
+ final XNameAccess dbContext = UnoRuntime.queryInterface( XNameAccess.class,
+ m_orb.createInstance( "com.sun.star.sdb.DatabaseContext" ) );
+ final XDocumentDataSource dataSource = UnoRuntime.queryInterface( XDocumentDataSource.class, dbContext.getByName( _docURL ) );
m_databaseDocument = dataSource.getDatabaseDocument();
m_dataSource = new DataSource(m_orb, m_databaseDocument.getDataSource());
diff --git a/connectivity/qa/connectivity/tools/CRMDatabase.java b/connectivity/qa/connectivity/tools/CRMDatabase.java
new file mode 100644
index 000000000000..c35faac75ff7
--- /dev/null
+++ b/connectivity/qa/connectivity/tools/CRMDatabase.java
@@ -0,0 +1,292 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org 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 version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+package connectivity.tools;
+
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.beans.PropertyState;
+import com.sun.star.container.ElementExistException;
+import com.sun.star.container.NoSuchElementException;
+import com.sun.star.frame.XComponentLoader;
+import com.sun.star.frame.XController;
+import com.sun.star.frame.XModel;
+import com.sun.star.io.IOException;
+import com.sun.star.lang.IllegalArgumentException;
+import com.sun.star.lang.WrappedTargetException;
+import com.sun.star.lang.XComponent;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.sdb.XSingleSelectQueryComposer;
+import com.sun.star.sdb.application.XDatabaseDocumentUI;
+import com.sun.star.sdbc.SQLException;
+import com.sun.star.sdbcx.XTablesSupplier;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.util.XRefreshable;
+import connectivity.tools.sdb.Connection;
+
+/** implements a small Customer Relationship Management database
+ *
+ * Not finished, by far. Feel free to add features as you need them.
+ */
+public class CRMDatabase
+{
+ private static final String INTEGER = "INTEGER";
+ private static final String VARCHAR50 = "VARCHAR(50)";
+ private final XMultiServiceFactory m_orb;
+ private final HsqlDatabase m_database;
+ private final DataSource m_dataSource;
+ private final Connection m_connection;
+
+ /** constructs the CRM database
+ */
+ public CRMDatabase( XMultiServiceFactory _orb, boolean _withUI ) throws Exception
+ {
+ m_orb = _orb;
+
+ m_database = new HsqlDatabase( m_orb );
+ m_dataSource = m_database.getDataSource();
+
+ if ( _withUI )
+ {
+ final XComponentLoader loader = UnoRuntime.queryInterface( XComponentLoader.class,
+ m_orb.createInstance( "com.sun.star.frame.Desktop" ) );
+ PropertyValue[] loadArgs = new PropertyValue[] {
+ new PropertyValue( "PickListEntry", 0, false, PropertyState.DIRECT_VALUE )
+ };
+ loader.loadComponentFromURL( m_database.getDocumentURL(), "_blank", 0, loadArgs );
+ getDocumentUI().connect();
+ m_connection = new Connection( getDocumentUI().getActiveConnection() );
+ }
+ else
+ {
+ m_connection = m_database.defaultConnection();
+ }
+
+ createTables();
+ createQueries();
+ }
+
+ /**
+ * creates a CRMDatabase from an existing document, given by URL
+ * @param _orb
+ * @param _existingDocumentURL
+ * @throws Exceptio
+ */
+ public CRMDatabase( XMultiServiceFactory _orb, final String _existingDocumentURL ) throws Exception
+ {
+ m_orb = _orb;
+
+ m_database = new HsqlDatabase( m_orb, _existingDocumentURL );
+ m_dataSource = m_database.getDataSource();
+ m_connection = m_database.defaultConnection();
+ }
+
+ // --------------------------------------------------------------------------------------------------------
+ /** returns the database document underlying the CRM database
+ */
+ public final HsqlDatabase getDatabase()
+ {
+ return m_database;
+ }
+
+ // --------------------------------------------------------------------------------------------------------
+ /** returns the default connection to the database
+ */
+ public final Connection getConnection()
+ {
+ return m_connection;
+ }
+
+ // --------------------------------------------------------------------------------------------------------
+ public void saveAndClose() throws SQLException, IOException
+ {
+ XDatabaseDocumentUI ui = getDocumentUI();
+ if ( ui != null )
+ ui.closeSubComponents();
+ m_database.store();
+ m_database.closeAndDelete();
+ }
+
+ // --------------------------------------------------------------------------------------------------------
+ public XDatabaseDocumentUI getDocumentUI()
+ {
+ XModel docModel = UnoRuntime.queryInterface( XModel.class, m_database.getDatabaseDocument() );
+ return UnoRuntime.queryInterface( XDatabaseDocumentUI.class, docModel.getCurrentController() );
+ }
+
+ // --------------------------------------------------------------------------------------------------------
+ public XController loadSubComponent( final int _objectType, final String _name ) throws IllegalArgumentException, SQLException, NoSuchElementException
+ {
+ XDatabaseDocumentUI docUI = getDocumentUI();
+ if ( !docUI.isConnected() )
+ docUI.connect();
+
+ XComponent subComponent = docUI.loadComponent( _objectType, _name, false );
+ XController controller = UnoRuntime.queryInterface( XController.class, subComponent );
+ if ( controller != null )
+ return controller;
+ XModel document = UnoRuntime.queryInterface( XModel.class, subComponent );
+ return document.getCurrentController();
+ }
+
+ // --------------------------------------------------------------------------------------------------------
+ private void createTables() throws SQLException
+ {
+ HsqlTableDescriptor table = new HsqlTableDescriptor( "categories",
+ new HsqlColumnDescriptor[] {
+ new HsqlColumnDescriptor( "ID",INTEGER, HsqlColumnDescriptor.PRIMARY ),
+ new HsqlColumnDescriptor( "Name",VARCHAR50),
+ new HsqlColumnDescriptor( "Description", "VARCHAR(1024)" ),
+ new HsqlColumnDescriptor( "Image", "LONGVARBINARY" ) } );
+ m_database.createTable( table, true );
+
+ m_database.executeSQL( "INSERT INTO \"categories\" ( \"ID\", \"Name\" ) VALUES ( 1, 'Food' )" );
+ m_database.executeSQL( "INSERT INTO \"categories\" ( \"ID\", \"Name\" ) VALUES ( 2, 'Furniture' )" );
+
+ table = new HsqlTableDescriptor( "products",
+ new HsqlColumnDescriptor[] {
+ new HsqlColumnDescriptor( "ID",INTEGER, HsqlColumnDescriptor.PRIMARY ),
+ new HsqlColumnDescriptor( "Name",VARCHAR50),
+ new HsqlColumnDescriptor( "CategoryID",INTEGER, HsqlColumnDescriptor.REQUIRED, "categories", "ID" ) } );
+ m_database.createTable( table, true );
+
+ m_database.executeSQL( "INSERT INTO \"products\" VALUES ( 1, 'Oranges', 1 )" );
+ m_database.executeSQL( "INSERT INTO \"products\" VALUES ( 2, 'Apples', 1 )" );
+ m_database.executeSQL( "INSERT INTO \"products\" VALUES ( 3, 'Pears', 1 )" );
+ m_database.executeSQL( "INSERT INTO \"products\" VALUES ( 4, 'Strawberries', 1 )" );
+
+ table = new HsqlTableDescriptor( "customers",
+ new HsqlColumnDescriptor[] {
+ new HsqlColumnDescriptor( "ID",INTEGER, HsqlColumnDescriptor.PRIMARY ),
+ new HsqlColumnDescriptor( "Name",VARCHAR50),
+ new HsqlColumnDescriptor( "Address",VARCHAR50),
+ new HsqlColumnDescriptor( "City",VARCHAR50),
+ new HsqlColumnDescriptor( "Postal",VARCHAR50),
+ new HsqlColumnDescriptor( "Comment","LONGVARCHAR")} );
+ m_database.createTable( table, true );
+
+ m_database.executeSQL( "INSERT INTO \"customers\" VALUES(1,'Food, Inc.','Down Under','Melbourne','509','Prefered') " );
+ m_database.executeSQL( "INSERT INTO \"customers\" VALUES(2,'Simply Delicious','Down Under','Melbourne','518',null) " );
+ m_database.executeSQL( "INSERT INTO \"customers\" VALUES(3,'Pure Health','10 Fish St.','San Francisco','94107',null) " );
+ m_database.executeSQL( "INSERT INTO \"customers\" VALUES(4,'Milk And More','Arlington Road 21','Dublin','31021','Good one.') " );
+
+ table = new HsqlTableDescriptor( "orders",
+ new HsqlColumnDescriptor[] {
+ new HsqlColumnDescriptor( "ID",INTEGER, HsqlColumnDescriptor.PRIMARY ),
+ new HsqlColumnDescriptor( "CustomerID",INTEGER, HsqlColumnDescriptor.REQUIRED, "customers", "ID" ),
+ new HsqlColumnDescriptor( "OrderDate", "DATE" ),
+ new HsqlColumnDescriptor( "ShipDate", "DATE" ) } );
+ m_database.createTable( table, true );
+
+ m_database.executeSQL( "INSERT INTO \"orders\" (\"ID\", \"CustomerID\", \"OrderDate\") VALUES(1, 1, {D '2009-01-01'})" );
+ m_database.executeSQL( "INSERT INTO \"orders\" VALUES(2, 2, {D '2009-01-01'}, {D '2009-01-23'})" );
+
+ table = new HsqlTableDescriptor( "orders_details",
+ new HsqlColumnDescriptor[] {
+ new HsqlColumnDescriptor( "OrderID",INTEGER, HsqlColumnDescriptor.PRIMARY, "orders", "ID" ),
+ new HsqlColumnDescriptor( "ProductID",INTEGER, HsqlColumnDescriptor.PRIMARY, "products", "ID" ),
+ new HsqlColumnDescriptor( "Quantity",INTEGER) } );
+ m_database.createTable( table, true );
+
+ m_database.executeSQL( "INSERT INTO \"orders_details\" VALUES(1, 1, 100)" );
+ m_database.executeSQL( "INSERT INTO \"orders_details\" VALUES(1, 2, 100)" );
+ m_database.executeSQL( "INSERT INTO \"orders_details\" VALUES(2, 2, 2000)" );
+ m_database.executeSQL( "INSERT INTO \"orders_details\" VALUES(2, 3, 2000)" );
+ m_database.executeSQL( "INSERT INTO \"orders_details\" VALUES(2, 4, 2000)" );
+
+ // since we created the tables by directly executing the SQL statements, we need to refresh
+ // the tables container
+ m_connection.refreshTables();
+ }
+
+ // --------------------------------------------------------------------------------------------------------
+ private void validateUnparseable()
+ {
+ // The "unparseable" query should be indeed be unparseable by OOo (though a valid HSQL query)
+ XSingleSelectQueryComposer composer;
+ QueryDefinition unparseableQuery;
+ try
+ {
+ final XMultiServiceFactory factory = UnoRuntime.queryInterface(
+ XMultiServiceFactory.class, m_database.defaultConnection().getXConnection() );
+ composer = UnoRuntime.queryInterface(
+ XSingleSelectQueryComposer.class, factory.createInstance( "com.sun.star.sdb.SingleSelectQueryComposer" ) );
+ unparseableQuery = m_dataSource.getQueryDefinition( "unparseable" );
+ }
+ catch( Exception e )
+ {
+ throw new RuntimeException( "caught an unexpected exception: " + e.getMessage() );
+ }
+
+ boolean caughtExpected = false;
+ try
+ {
+ composer.setQuery( unparseableQuery.getCommand() );
+ }
+ catch (WrappedTargetException e) { }
+ catch( SQLException e )
+ {
+ caughtExpected = true;
+ }
+
+ if ( !caughtExpected )
+ throw new RuntimeException( "Somebody improved the parser! This is bad :), since we need an unparsable query here!" );
+ }
+
+ // --------------------------------------------------------------------------------------------------------
+ private void createQueries() throws ElementExistException, WrappedTargetException, com.sun.star.lang.IllegalArgumentException
+ {
+ m_database.getDataSource().createQuery(
+ "all orders",
+ "SELECT \"orders\".\"ID\" AS \"Order No.\", " +
+ "\"customers\".\"Name\" AS \"Customer Name\", " +
+ "\"orders\".\"OrderDate\" AS \"Order Date\", " +
+ "\"orders\".\"ShipDate\" AS \"Ship Date\", " +
+ "\"orders_details\".\"Quantity\", " +
+ "\"products\".\"Name\" AS \"Product Name\" " +
+ "FROM \"orders_details\" AS \"orders_details\", " +
+ "\"orders\" AS \"orders\", " +
+ "\"products\" AS \"products\", " +
+ "\"customers\" AS \"customers\" " +
+ "WHERE ( \"orders_details\".\"OrderID\" = \"orders\".\"ID\" " +
+ "AND \"orders_details\".\"ProductID\" = \"products\".\"ID\" " +
+ "AND \"orders\".\"CustomerID\" = \"customers\".\"ID\" )"
+ );
+
+ m_database.getDataSource().createQuery(
+ "unshipped orders",
+ "SELECT * " +
+ "FROM \"all orders\"" +
+ "WHERE ( \"ShipDate\" IS NULL )"
+ );
+
+ m_database.getDataSource().createQuery( "parseable", "SELECT * FROM \"customers\"" );
+ m_database.getDataSource().createQuery( "parseable native", "SELECT * FROM INFORMATION_SCHEMA.SYSTEM_VIEWS", false );
+ m_database.getDataSource().createQuery( "unparseable",
+ "SELECT CAST( \"ID\" AS VARCHAR(3) ) AS \"ID_VARCHAR\" FROM \"products\"", false );
+
+ validateUnparseable();
+ }
+}
diff --git a/connectivity/qa/connectivity/tools/DataSource.java b/connectivity/qa/connectivity/tools/DataSource.java
index 1ed8f7f98af7..221ada3cb487 100644
--- a/connectivity/qa/connectivity/tools/DataSource.java
+++ b/connectivity/qa/connectivity/tools/DataSource.java
@@ -2,13 +2,10 @@
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
- * Copyright 2008 by Sun Microsystems, Inc.
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
- * $RCSfile: DataSource.java,v $
- * $Revision: 1.4 $
- *
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
@@ -39,10 +36,8 @@ import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.beans.XPropertySet;
import com.sun.star.sdb.XQueryDefinitionsSupplier;
import com.sun.star.sdbc.XDataSource;
-import com.sun.star.sdbcx.XTablesSupplier;
import com.sun.star.uno.Exception;
import com.sun.star.uno.UnoRuntime;
-import com.sun.star.util.XRefreshable;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -57,11 +52,10 @@ public class DataSource
{
m_orb = _orb;
- final XNameAccess dbContext = (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class,
- _orb.createInstance("com.sun.star.sdb.DatabaseContext"));
+ final XNameAccess dbContext = UnoRuntime.queryInterface(
+ XNameAccess.class, _orb.createInstance( "com.sun.star.sdb.DatabaseContext" ) );
- m_dataSource = (XDataSource) UnoRuntime.queryInterface(XDataSource.class,
- dbContext.getByName(_registeredName));
+ m_dataSource = UnoRuntime.queryInterface( XDataSource.class, dbContext.getByName( _registeredName ) );
}
public DataSource(final XMultiServiceFactory _orb,final XDataSource _dataSource)
@@ -86,13 +80,11 @@ public class DataSource
*/
public void createQuery(final String _name, final String _sqlCommand, final boolean _escapeProcessing) throws ElementExistException, WrappedTargetException, com.sun.star.lang.IllegalArgumentException
{
- final XSingleServiceFactory queryDefsFac = (XSingleServiceFactory) UnoRuntime.queryInterface(
- XSingleServiceFactory.class, getQueryDefinitions());
+ final XSingleServiceFactory queryDefsFac = UnoRuntime.queryInterface( XSingleServiceFactory.class, getQueryDefinitions() );
XPropertySet queryDef = null;
try
{
- queryDef = (XPropertySet) UnoRuntime.queryInterface(
- XPropertySet.class, queryDefsFac.createInstance());
+ queryDef = UnoRuntime.queryInterface( XPropertySet.class, queryDefsFac.createInstance() );
queryDef.setPropertyValue("Command", _sqlCommand);
queryDef.setPropertyValue("EscapeProcessing", Boolean.valueOf(_escapeProcessing));
}
@@ -101,8 +93,7 @@ public class DataSource
e.printStackTrace(System.err);
}
- final XNameContainer queryDefsContainer = (XNameContainer) UnoRuntime.queryInterface(
- XNameContainer.class, getQueryDefinitions());
+ final XNameContainer queryDefsContainer = UnoRuntime.queryInterface( XNameContainer.class, getQueryDefinitions() );
queryDefsContainer.insertByName(_name, queryDef);
}
@@ -113,8 +104,7 @@ public class DataSource
final XNameAccess allDefs = getQueryDefinitions();
try
{
- return new QueryDefinition(
- (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, allDefs.getByName(_name)));
+ return new QueryDefinition( UnoRuntime.queryInterface( XPropertySet.class, allDefs.getByName( _name) ) );
}
catch (WrappedTargetException e)
{
@@ -126,25 +116,11 @@ public class DataSource
*/
public XNameAccess getQueryDefinitions()
{
- final XQueryDefinitionsSupplier suppQueries = (XQueryDefinitionsSupplier) UnoRuntime.queryInterface(
+ final XQueryDefinitionsSupplier suppQueries = UnoRuntime.queryInterface(
XQueryDefinitionsSupplier.class, m_dataSource);
return suppQueries.getQueryDefinitions();
}
- /** refreshs the table container of a given connection
- *
- * This is usually necessary if you created tables by directly executing SQL statements,
- * bypassing the SDBCX layer.
- */
- public void refreshTables(final com.sun.star.sdbc.XConnection _connection)
- {
- final XTablesSupplier suppTables = (XTablesSupplier) UnoRuntime.queryInterface(
- XTablesSupplier.class, _connection);
- final XRefreshable refreshTables = (XRefreshable) UnoRuntime.queryInterface(
- XRefreshable.class, suppTables.getTables());
- refreshTables.refresh();
- }
-
/** returns the name of the data source
*
* If a data source is registered at the database context, the name is the registration
@@ -157,8 +133,7 @@ public class DataSource
String name = null;
try
{
- final XPropertySet dataSourceProps = (XPropertySet) UnoRuntime.queryInterface(
- XPropertySet.class, m_dataSource);
+ final XPropertySet dataSourceProps = UnoRuntime.queryInterface( XPropertySet.class, m_dataSource );
name = (String) dataSourceProps.getPropertyValue("Name");
}
catch (Exception ex)
diff --git a/connectivity/qa/connectivity/tools/DatabaseAccess.java b/connectivity/qa/connectivity/tools/DatabaseAccess.java
index bc39bb099087..c099a44d1fb9 100755
--- a/connectivity/qa/connectivity/tools/DatabaseAccess.java
+++ b/connectivity/qa/connectivity/tools/DatabaseAccess.java
@@ -2,13 +2,10 @@
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
- * Copyright 2008 by Sun Microsystems, Inc.
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
- * $RCSfile: RowSetEventListener.java,v $
- * $Revision: 1.4 $
- *
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
@@ -34,7 +31,7 @@ import com.sun.star.io.IOException;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.sdb.XOfficeDatabaseDocument;
import com.sun.star.sdbc.SQLException;
-import com.sun.star.sdbc.XConnection;
+import connectivity.tools.sdb.Connection;
/**
*
@@ -42,7 +39,7 @@ import com.sun.star.sdbc.XConnection;
*/
public interface DatabaseAccess
{
- XConnection defaultConnection() throws SQLException;
+ Connection defaultConnection() throws SQLException;
void executeSQL(final String statementString) throws SQLException;
diff --git a/connectivity/qa/connectivity/tools/DbaseDatabase.java b/connectivity/qa/connectivity/tools/DbaseDatabase.java
index 8846c3995f56..ae40be4222aa 100644..100755
--- a/connectivity/qa/connectivity/tools/DbaseDatabase.java
+++ b/connectivity/qa/connectivity/tools/DbaseDatabase.java
@@ -2,13 +2,10 @@
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
- * Copyright 2008 by Sun Microsystems, Inc.
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
- * $RCSfile: DbaseDatabase.java,v $
- * $Revision: 1.4.50.2 $
- *
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
diff --git a/connectivity/qa/connectivity/tools/HsqlColumnDescriptor.java b/connectivity/qa/connectivity/tools/HsqlColumnDescriptor.java
index 1552236c3614..c0c46d07149f 100644
--- a/connectivity/qa/connectivity/tools/HsqlColumnDescriptor.java
+++ b/connectivity/qa/connectivity/tools/HsqlColumnDescriptor.java
@@ -2,13 +2,10 @@
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
- * Copyright 2008 by Sun Microsystems, Inc.
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
- * $RCSfile: HsqlColumnDescriptor.java,v $
- * $Revision: 1.4 $
- *
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
diff --git a/connectivity/qa/connectivity/tools/HsqlDatabase.java b/connectivity/qa/connectivity/tools/HsqlDatabase.java
index 593a5ad95981..058c61e1afaa 100644
--- a/connectivity/qa/connectivity/tools/HsqlDatabase.java
+++ b/connectivity/qa/connectivity/tools/HsqlDatabase.java
@@ -2,13 +2,10 @@
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
- * Copyright 2008 by Sun Microsystems, Inc.
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
- * $RCSfile: HsqlDatabase.java,v $
- * $Revision: 1.4.50.2 $
- *
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
@@ -30,6 +27,7 @@
package connectivity.tools;
import com.sun.star.beans.PropertyValue;
+import com.sun.star.beans.PropertyState;
import com.sun.star.beans.XPropertySet;
import com.sun.star.container.ElementExistException;
import com.sun.star.frame.XStorable;
@@ -83,9 +81,9 @@ public class HsqlDatabase extends AbstractDatabase
dsProperties.setPropertyValue("URL", "sdbc:embedded:hsqldb");
final XStorable storable = (XStorable) UnoRuntime.queryInterface(XStorable.class, m_databaseDocument);
- storable.storeAsURL(m_databaseDocumentFile, new PropertyValue[]
- {
- });
+ storable.storeAsURL( m_databaseDocumentFile, new PropertyValue[]
+ { new PropertyValue( "PickListEntry", 0, false, PropertyState.DIRECT_VALUE )
+ } );
}
/** drops the table with a given name
@@ -208,10 +206,8 @@ public class HsqlDatabase extends AbstractDatabase
public void createTableInSDBCX(final HsqlTableDescriptor _tableDesc) throws SQLException, ElementExistException
{
final XPropertySet sdbcxDescriptor = _tableDesc.createSdbcxDescriptor(defaultConnection());
- final XTablesSupplier suppTables = (XTablesSupplier) UnoRuntime.queryInterface(
- XTablesSupplier.class, defaultConnection());
- final XAppend appendTable = (XAppend) UnoRuntime.queryInterface(
- XAppend.class, suppTables.getTables());
+ final XTablesSupplier suppTables = UnoRuntime.queryInterface( XTablesSupplier.class, defaultConnection().getXConnection() );
+ final XAppend appendTable = UnoRuntime.queryInterface( XAppend.class, suppTables.getTables() );
appendTable.appendByDescriptor(sdbcxDescriptor);
}
}
diff --git a/connectivity/qa/connectivity/tools/HsqlTableDescriptor.java b/connectivity/qa/connectivity/tools/HsqlTableDescriptor.java
index ec6c472309d5..dcda754f8b8c 100644
--- a/connectivity/qa/connectivity/tools/HsqlTableDescriptor.java
+++ b/connectivity/qa/connectivity/tools/HsqlTableDescriptor.java
@@ -2,13 +2,10 @@
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
- * Copyright 2008 by Sun Microsystems, Inc.
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
- * $RCSfile: HsqlTableDescriptor.java,v $
- * $Revision: 1.4 $
- *
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
@@ -33,11 +30,11 @@ package connectivity.tools;
import com.sun.star.beans.XPropertySet;
import com.sun.star.container.XNameAccess;
import com.sun.star.sdbc.ColumnValue;
-import com.sun.star.sdbc.XConnection;
import com.sun.star.sdbcx.XColumnsSupplier;
import com.sun.star.sdbcx.XDataDescriptorFactory;
import com.sun.star.sdbcx.XTablesSupplier;
import com.sun.star.uno.UnoRuntime;
+import connectivity.tools.sdb.Connection;
/** is a very simply descriptor of a HSQL table, to be used with a HsqlDatabase.createTable method
*/
@@ -67,12 +64,10 @@ public class HsqlTableDescriptor
return m_columns;
}
- public XPropertySet createSdbcxDescriptor( XConnection _forConnection )
+ public XPropertySet createSdbcxDescriptor( Connection _forConnection )
{
- XTablesSupplier suppTables = (XTablesSupplier)UnoRuntime.queryInterface(
- XTablesSupplier.class, _forConnection );
- XDataDescriptorFactory tableDescFac = (XDataDescriptorFactory)UnoRuntime.queryInterface(
- XDataDescriptorFactory.class, suppTables.getTables() );
+ XTablesSupplier suppTables = UnoRuntime.queryInterface( XTablesSupplier.class, _forConnection.getXConnection() );
+ XDataDescriptorFactory tableDescFac = UnoRuntime.queryInterface( XDataDescriptorFactory.class, suppTables.getTables() );
XPropertySet tableDesc = tableDescFac.createDataDescriptor();
try
@@ -81,12 +76,10 @@ public class HsqlTableDescriptor
}
catch ( Exception e ) { e.printStackTrace( System.err ); }
- XColumnsSupplier suppDescCols = (XColumnsSupplier)UnoRuntime.queryInterface(
- XColumnsSupplier.class, tableDesc );
+ XColumnsSupplier suppDescCols = UnoRuntime.queryInterface( XColumnsSupplier.class, tableDesc );
XNameAccess descColumns = suppDescCols.getColumns();
- XDataDescriptorFactory columnDescFac = (XDataDescriptorFactory)UnoRuntime.queryInterface(
- XDataDescriptorFactory.class, descColumns );
+ XDataDescriptorFactory columnDescFac = UnoRuntime.queryInterface( XDataDescriptorFactory.class, descColumns );
HsqlColumnDescriptor[] myColumns = getColumns();
for ( int i = 0; i < myColumns.length; ++i )
diff --git a/connectivity/qa/connectivity/tools/QueryDefinition.java b/connectivity/qa/connectivity/tools/QueryDefinition.java
index 040d250ef254..ebc9d1a25cfe 100644
--- a/connectivity/qa/connectivity/tools/QueryDefinition.java
+++ b/connectivity/qa/connectivity/tools/QueryDefinition.java
@@ -2,13 +2,10 @@
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
- * Copyright 2008 by Sun Microsystems, Inc.
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
- * $RCSfile: QueryDefinition.java,v $
- * $Revision: 1.3 $
- *
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
diff --git a/connectivity/qa/connectivity/tools/RowSet.java b/connectivity/qa/connectivity/tools/RowSet.java
index d09e79efb79a..a26456dcc746 100644
--- a/connectivity/qa/connectivity/tools/RowSet.java
+++ b/connectivity/qa/connectivity/tools/RowSet.java
@@ -2,13 +2,10 @@
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
- * Copyright 2008 by Sun Microsystems, Inc.
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
- * $RCSfile: RowSet.java,v $
- * $Revision: 1.3 $
- *
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
diff --git a/connectivity/qa/connectivity/tools/makefile.mk b/connectivity/qa/connectivity/tools/makefile.mk
index 589a85ea385f..0f3c9c84b92e 100644
--- a/connectivity/qa/connectivity/tools/makefile.mk
+++ b/connectivity/qa/connectivity/tools/makefile.mk
@@ -2,14 +2,10 @@
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
-# Copyright 2008 by Sun Microsystems, Inc.
+# Copyright 2000, 2010 Oracle and/or its affiliates.
#
# OpenOffice.org - a multi-platform office productivity suite
#
-# $RCSfile: makefile.mk,v $
-#
-# $Revision: 1.8.60.1 $
-#
# This file is part of OpenOffice.org.
#
# OpenOffice.org is free software: you can redistribute it and/or modify
@@ -29,10 +25,10 @@
#
#*************************************************************************
-PRJ = ..$/..$/..
+PRJ = ../../..
TARGET = ConnectivityTools
PRJNAME = connectivity
-PACKAGE = connectivity$/tools
+PACKAGE = connectivity/tools
# --- Settings -----------------------------------------------------
.INCLUDE: settings.mk
@@ -46,14 +42,8 @@ all:
#----- compile .java files -----------------------------------------
JARFILES = ridl.jar unoil.jar jurt.jar juh.jar java_uno.jar OOoRunnerLight.jar
-# Do not use $/ with the $(FIND) command as for W32-4nt this leads to a backslash
-# in a posix command. In this special case use / instead of $/
-.IF "$(GUI)"=="OS2"
-JAVAFILES := $(shell @ls ./*.java)
-.ELSE
-JAVAFILES := $(shell @$(FIND) ./*.java)
-.ENDIF
-JAVACLASSFILES = $(foreach,i,$(JAVAFILES) $(CLASSDIR)$/$(PACKAGE)$/$(i:b).class)
+JAVAFILES := $(shell @$(FIND) . -name "*.java")
+JAVACLASSFILES := $(foreach,i,$(JAVAFILES) $(CLASSDIR)/$(PACKAGE)/$(i:d)$(i:b).class)
#----- make a jar from compiled files ------------------------------
diff --git a/connectivity/qa/connectivity/tools/sdb/Connection.java b/connectivity/qa/connectivity/tools/sdb/Connection.java
new file mode 100644
index 000000000000..aac120fb1e73
--- /dev/null
+++ b/connectivity/qa/connectivity/tools/sdb/Connection.java
@@ -0,0 +1,93 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package connectivity.tools.sdb;
+
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.sdb.XSingleSelectQueryComposer;
+import com.sun.star.sdbc.SQLException;
+import com.sun.star.sdbc.XConnection;
+import com.sun.star.sdbc.XDatabaseMetaData;
+import com.sun.star.sdbc.XPreparedStatement;
+import com.sun.star.sdbc.XResultSet;
+import com.sun.star.sdbc.XStatement;
+import com.sun.star.sdbcx.XTablesSupplier;
+import com.sun.star.uno.Exception;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.util.XRefreshable;
+
+/**
+ * is a convenience wrapper around a SDB-level connection object
+ */
+public class Connection
+{
+ private final XConnection m_connection;
+
+ public Connection( final XConnection _connection )
+ {
+ m_connection = _connection;
+ }
+
+ public XConnection getXConnection()
+ {
+ return m_connection;
+ }
+
+ public boolean execute( final String _sql ) throws SQLException
+ {
+ XStatement statement = createStatement();
+ return statement.execute( _sql );
+ }
+
+ public XResultSet executeQuery( final String _sql ) throws SQLException
+ {
+ XStatement statement = createStatement();
+ return statement.executeQuery( _sql );
+ }
+
+ public int executeUpdate( final String _sql ) throws SQLException
+ {
+ XStatement statement = createStatement();
+ return statement.executeUpdate( _sql );
+ }
+
+ public void refreshTables()
+ {
+ final XTablesSupplier suppTables = UnoRuntime.queryInterface(XTablesSupplier.class, m_connection);
+ final XRefreshable refresh = UnoRuntime.queryInterface( XRefreshable.class, suppTables.getTables() );
+ refresh.refresh();
+ }
+
+ public XSingleSelectQueryComposer createSingleSelectQueryComposer() throws Exception
+ {
+ final XMultiServiceFactory connectionFactory = UnoRuntime.queryInterface( XMultiServiceFactory.class, m_connection );
+ return UnoRuntime.queryInterface(
+ XSingleSelectQueryComposer.class, connectionFactory.createInstance( "com.sun.star.sdb.SingleSelectQueryComposer" ) );
+ }
+
+ public
+ XStatement createStatement() throws SQLException
+ {
+ return m_connection.createStatement();
+ }
+
+ public
+ XPreparedStatement prepareStatement( String _sql ) throws SQLException
+ {
+ return m_connection.prepareStatement( _sql );
+ }
+
+ public
+ XDatabaseMetaData getMetaData() throws SQLException
+ {
+ return m_connection.getMetaData();
+ }
+
+ public
+ void close() throws SQLException
+ {
+ m_connection.close();
+ }
+}