From bde91154eeba3b07a63abed039f44af77cfcd767 Mon Sep 17 00:00:00 2001 From: "Frank Schönheit [fs]" Date: Tue, 3 Nov 2009 23:47:11 +0100 Subject: css.form.XFormController superseded by css.form.runtime.XFormController --- dbaccess/qa/complex/dbaccess/UISettings.java | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'dbaccess/qa') diff --git a/dbaccess/qa/complex/dbaccess/UISettings.java b/dbaccess/qa/complex/dbaccess/UISettings.java index 23fe10618810..56f5e2a2a3d7 100644 --- a/dbaccess/qa/complex/dbaccess/UISettings.java +++ b/dbaccess/qa/complex/dbaccess/UISettings.java @@ -32,7 +32,7 @@ package complex.dbaccess; import com.sun.star.awt.FontSlant; import com.sun.star.beans.PropertyValue; import com.sun.star.beans.XPropertySet; -import com.sun.star.form.XFormController; +import com.sun.star.form.runtime.XFormController; import com.sun.star.frame.XComponentLoader; import com.sun.star.frame.XModel; import com.sun.star.lang.XComponent; @@ -65,21 +65,21 @@ public class UISettings extends TestCase // load the document String docURL = database.getDatabase().getDocumentURL(); - final XComponentLoader loader = (XComponentLoader)UnoRuntime.queryInterface( XComponentLoader.class, + final XComponentLoader loader = UnoRuntime.queryInterface( XComponentLoader.class, getORB().createInstance( "com.sun.star.frame.Desktop" ) ); - XModel doc = (XModel)UnoRuntime.queryInterface( XModel.class, + XModel doc = UnoRuntime.queryInterface( XModel.class, loader.loadComponentFromURL( docURL, "_blank", 0, new PropertyValue[] {} ) ); // establish the connection - XDatabaseDocumentUI docUI = (XDatabaseDocumentUI)UnoRuntime.queryInterface( XDatabaseDocumentUI.class, + XDatabaseDocumentUI docUI = UnoRuntime.queryInterface( XDatabaseDocumentUI.class, doc.getCurrentController() ); docUI.connect(); // display the table XComponent tableViewComp = docUI.loadComponent( com.sun.star.sdb.application.DatabaseObject.TABLE, "customers", false ); - XFormController tableViewController = (XFormController)UnoRuntime.queryInterface( XFormController.class, + XFormController tableViewController = UnoRuntime.queryInterface( XFormController.class, tableViewComp ); - XPropertySet tableControlModel = (XPropertySet)UnoRuntime.queryInterface( XPropertySet.class, + XPropertySet tableControlModel = UnoRuntime.queryInterface( XPropertySet.class, tableViewController.getCurrentControl().getModel() ); // change the table's formatting @@ -102,18 +102,18 @@ public class UISettings extends TestCase // not cleaned up, the "database model impl" - the structure holding all document data - will // stay alive, and subsequent requests to load the doc will just reuse it, without really loading it. docURL = copyToTempFile( docURL ); - doc = (XModel)UnoRuntime.queryInterface( XModel.class, + doc = UnoRuntime.queryInterface( XModel.class, loader.loadComponentFromURL( docURL, "_blank", 0, new PropertyValue[] {} ) ); - docUI = (XDatabaseDocumentUI)UnoRuntime.queryInterface( XDatabaseDocumentUI.class, + docUI = UnoRuntime.queryInterface( XDatabaseDocumentUI.class, doc.getCurrentController() ); docUI.connect(); // display the table, again tableViewComp = docUI.loadComponent( com.sun.star.sdb.application.DatabaseObject.TABLE, "customers", false ); - tableViewController = (XFormController)UnoRuntime.queryInterface( XFormController.class, + tableViewController = UnoRuntime.queryInterface( XFormController.class, tableViewComp ); - tableControlModel = (XPropertySet)UnoRuntime.queryInterface( XPropertySet.class, + tableControlModel = UnoRuntime.queryInterface( XPropertySet.class, tableViewController.getCurrentControl().getModel() ); // verify the properties @@ -123,7 +123,7 @@ public class UISettings extends TestCase // close the doc docUI.closeSubComponents(); - final XCloseable closeDoc = (XCloseable)UnoRuntime.queryInterface( XCloseable.class, + final XCloseable closeDoc = UnoRuntime.queryInterface( XCloseable.class, doc ); closeDoc.close( true ); } -- cgit From df3a4b31dc7311fbac90747809d301aa392ac327 Mon Sep 17 00:00:00 2001 From: "Frank Schönheit [fs]" Date: Wed, 4 Nov 2009 09:52:11 +0100 Subject: added test case (UISettings.checkTransparentQueryColumnSettings) for #i67020# --- dbaccess/qa/complex/dbaccess/CRMBasedTestCase.java | 2 +- dbaccess/qa/complex/dbaccess/CRMDatabase.java | 58 ++++++++++-- dbaccess/qa/complex/dbaccess/TestCase.java | 19 +++- dbaccess/qa/complex/dbaccess/UISettings.java | 105 +++++++++++++++------ 4 files changed, 140 insertions(+), 44 deletions(-) (limited to 'dbaccess/qa') diff --git a/dbaccess/qa/complex/dbaccess/CRMBasedTestCase.java b/dbaccess/qa/complex/dbaccess/CRMBasedTestCase.java index eccb48647bae..2b23defe7eec 100644 --- a/dbaccess/qa/complex/dbaccess/CRMBasedTestCase.java +++ b/dbaccess/qa/complex/dbaccess/CRMBasedTestCase.java @@ -67,7 +67,7 @@ public abstract class CRMBasedTestCase extends TestCase try { if ( m_database != null ) - m_database.close(); + m_database.saveAndClose(); } catch ( Exception ex ) { diff --git a/dbaccess/qa/complex/dbaccess/CRMDatabase.java b/dbaccess/qa/complex/dbaccess/CRMDatabase.java index 77e2dcf6b2e2..fbffa0fbea33 100644 --- a/dbaccess/qa/complex/dbaccess/CRMDatabase.java +++ b/dbaccess/qa/complex/dbaccess/CRMDatabase.java @@ -30,10 +30,16 @@ package complex.dbaccess; import com.sun.star.container.ElementExistException; +import com.sun.star.container.NoSuchElementException; +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.sdbc.XConnection; import com.sun.star.sdbcx.XTablesSupplier; @@ -71,6 +77,21 @@ public class CRMDatabase 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 */ @@ -88,10 +109,33 @@ public class CRMDatabase } // -------------------------------------------------------------------------------------------------------- - public void close() throws SQLException, IOException + public void saveAndClose() throws SQLException, IOException { + getDocumentUI().closeSubComponents(); m_database.store(); - m_database.close(); + 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(); } // -------------------------------------------------------------------------------------------------------- @@ -161,10 +205,8 @@ public class CRMDatabase // since we created the tables by directly executing the SQL statements, we need to refresh // the tables container - final XTablesSupplier suppTables = (XTablesSupplier)UnoRuntime.queryInterface( - XTablesSupplier.class, m_connection ); - final XRefreshable refreshTables = (XRefreshable)UnoRuntime.queryInterface( - XRefreshable.class, suppTables.getTables() ); + final XTablesSupplier suppTables = UnoRuntime.queryInterface( XTablesSupplier.class, m_connection ); + final XRefreshable refreshTables = UnoRuntime.queryInterface( XRefreshable.class, suppTables.getTables() ); refreshTables.refresh(); } @@ -176,9 +218,9 @@ public class CRMDatabase QueryDefinition unparseableQuery; try { - final XMultiServiceFactory factory = (XMultiServiceFactory)UnoRuntime.queryInterface( + final XMultiServiceFactory factory = UnoRuntime.queryInterface( XMultiServiceFactory.class, m_database.defaultConnection() ); - composer = (XSingleSelectQueryComposer)UnoRuntime.queryInterface( + composer = UnoRuntime.queryInterface( XSingleSelectQueryComposer.class, factory.createInstance( "com.sun.star.sdb.SingleSelectQueryComposer" ) ); unparseableQuery = m_dataSource.getQueryDefinition( "unparseable" ); } diff --git a/dbaccess/qa/complex/dbaccess/TestCase.java b/dbaccess/qa/complex/dbaccess/TestCase.java index 1051b549c8f0..8a9594a34305 100644 --- a/dbaccess/qa/complex/dbaccess/TestCase.java +++ b/dbaccess/qa/complex/dbaccess/TestCase.java @@ -29,8 +29,12 @@ ************************************************************************/ package complex.dbaccess; +import com.sun.star.beans.PropertyValue; import com.sun.star.beans.XPropertySet; +import com.sun.star.frame.XComponentLoader; +import com.sun.star.frame.XModel; import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.Exception; import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.XComponentContext; import helper.FileTools; @@ -38,8 +42,6 @@ import java.io.File; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; -import java.net.URI; -import java.net.URISyntaxException; public abstract class TestCase extends complexlib.ComplexTestCase { @@ -55,8 +57,8 @@ public abstract class TestCase extends complexlib.ComplexTestCase XComponentContext context = null; try { - final XPropertySet orbProps = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, getORB() ); - context = (XComponentContext)UnoRuntime.queryInterface( XComponentContext.class, + final XPropertySet orbProps = UnoRuntime.queryInterface( XPropertySet.class, getORB() ); + context = UnoRuntime.queryInterface( XComponentContext.class, orbProps.getPropertyValue( "DefaultContext" ) ); } catch ( Exception ex ) @@ -108,6 +110,15 @@ public abstract class TestCase extends complexlib.ComplexTestCase return FileHelper.getOOoCompatibleFileURL( targetURL ); } + // -------------------------------------------------------------------------------------------------------- + protected final XModel loadDocument( final String _docURL ) throws Exception + { + final XComponentLoader loader = UnoRuntime.queryInterface( XComponentLoader.class, + getORB().createInstance( "com.sun.star.frame.Desktop" ) ); + return UnoRuntime.queryInterface( XModel.class, + loader.loadComponentFromURL( _docURL, "_blank", 0, new PropertyValue[] {} ) ); + } + // -------------------------------------------------------------------------------------------------------- protected void assureException( Object _object, Class _unoInterfaceClass, String _methodName, Object[] _methodArgs, Class _expectedExceptionClass ) diff --git a/dbaccess/qa/complex/dbaccess/UISettings.java b/dbaccess/qa/complex/dbaccess/UISettings.java index 56f5e2a2a3d7..7d9042d3e1dc 100644 --- a/dbaccess/qa/complex/dbaccess/UISettings.java +++ b/dbaccess/qa/complex/dbaccess/UISettings.java @@ -30,23 +30,27 @@ package complex.dbaccess; import com.sun.star.awt.FontSlant; -import com.sun.star.beans.PropertyValue; +import com.sun.star.awt.TextAlign; import com.sun.star.beans.XPropertySet; +import com.sun.star.container.XNameAccess; import com.sun.star.form.runtime.XFormController; -import com.sun.star.frame.XComponentLoader; +import com.sun.star.frame.XController; import com.sun.star.frame.XModel; -import com.sun.star.lang.XComponent; +import com.sun.star.sdb.application.DatabaseObject; import com.sun.star.sdb.application.XDatabaseDocumentUI; import com.sun.star.uno.UnoRuntime; import com.sun.star.util.XCloseable; public class UISettings extends TestCase { + private CRMDatabase m_database; + // -------------------------------------------------------------------------------------------------------- public String[] getTestMethodNames() { return new String[] { - "checkTableFormattingPersistence" + //"checkTableFormattingPersistence", + "checkTransparentQueryColumnSettings" }; } @@ -57,28 +61,33 @@ public class UISettings extends TestCase } // -------------------------------------------------------------------------------------------------------- - /** verifies that aliases for inner queries work as expected - */ - public void checkTableFormattingPersistence() throws java.lang.Exception + private CRMDatabase impl_createConnectedDatabaseDocument() throws Exception { final CRMDatabase database = new CRMDatabase( getORB() ); // load the document String docURL = database.getDatabase().getDocumentURL(); - final XComponentLoader loader = UnoRuntime.queryInterface( XComponentLoader.class, - getORB().createInstance( "com.sun.star.frame.Desktop" ) ); - XModel doc = UnoRuntime.queryInterface( XModel.class, - loader.loadComponentFromURL( docURL, "_blank", 0, new PropertyValue[] {} ) ); + XModel doc = loadDocument( docURL ); // establish the connection XDatabaseDocumentUI docUI = UnoRuntime.queryInterface( XDatabaseDocumentUI.class, doc.getCurrentController() ); docUI.connect(); - // display the table - XComponent tableViewComp = docUI.loadComponent( com.sun.star.sdb.application.DatabaseObject.TABLE, "customers", false ); + return database; + } + + // -------------------------------------------------------------------------------------------------------- + /** verifies that aliases for inner queries work as expected + */ + public void checkTableFormattingPersistence() throws java.lang.Exception + { + // create, load, and connect a DB doc + CRMDatabase database = impl_createConnectedDatabaseDocument(); + + // display a table XFormController tableViewController = UnoRuntime.queryInterface( XFormController.class, - tableViewComp ); + database.loadSubComponent( DatabaseObject.TABLE, "customers" ) ); XPropertySet tableControlModel = UnoRuntime.queryInterface( XPropertySet.class, tableViewController.getCurrentControl().getModel() ); @@ -87,12 +96,10 @@ public class UISettings extends TestCase tableControlModel.setPropertyValue( "FontHeight", Float.valueOf( 20 ) ); tableControlModel.setPropertyValue( "FontSlant", FontSlant.ITALIC ); - // close the table - docUI.closeSubComponents(); + String docURL = database.getDatabase().getModel().getURL(); - // save and close the database document - database.getDatabase().store(); - database.close(); + // save close the database document + database.saveAndClose(); // load a copy of the document // normally, it should be sufficient to load the same doc. However, there might be objects in the Java VM @@ -102,17 +109,12 @@ public class UISettings extends TestCase // not cleaned up, the "database model impl" - the structure holding all document data - will // stay alive, and subsequent requests to load the doc will just reuse it, without really loading it. docURL = copyToTempFile( docURL ); - doc = UnoRuntime.queryInterface( XModel.class, - loader.loadComponentFromURL( docURL, "_blank", 0, new PropertyValue[] {} ) ); - - docUI = UnoRuntime.queryInterface( XDatabaseDocumentUI.class, - doc.getCurrentController() ); - docUI.connect(); + loadDocument( docURL ); + database = new CRMDatabase( getORB(), docURL ); // display the table, again - tableViewComp = docUI.loadComponent( com.sun.star.sdb.application.DatabaseObject.TABLE, "customers", false ); tableViewController = UnoRuntime.queryInterface( XFormController.class, - tableViewComp ); + database.loadSubComponent( DatabaseObject.TABLE, "customers" ) ); tableControlModel = UnoRuntime.queryInterface( XPropertySet.class, tableViewController.getCurrentControl().getModel() ); @@ -122,9 +124,50 @@ public class UISettings extends TestCase assureEquals( "wrong font slant", FontSlant.ITALIC, (FontSlant)tableControlModel.getPropertyValue( "FontSlant" ) ); // close the doc - docUI.closeSubComponents(); - final XCloseable closeDoc = UnoRuntime.queryInterface( XCloseable.class, - doc ); - closeDoc.close( true ); + database.saveAndClose(); + } + + /** + * checks whether query columns use the settings of the underlying table column, if they do not (yet) have own + * settings + * @throws java.lang.Exception + */ + public void checkTransparentQueryColumnSettings() throws java.lang.Exception + { + // create, load, and connect a DB doc + CRMDatabase database = impl_createConnectedDatabaseDocument(); + + // display a table + XController tableView = database.loadSubComponent( DatabaseObject.TABLE, "customers" ); + XFormController tableViewController = UnoRuntime.queryInterface( XFormController.class, + tableView ); + XNameAccess tableControlModel = UnoRuntime.queryInterface( XNameAccess.class, + tableViewController.getCurrentControl().getModel() ); + + // change the formatting of a table column + XPropertySet idColumn = UnoRuntime.queryInterface( XPropertySet.class, tableControlModel.getByName( "ID" ) ); + assure( "precondition not met: column already centered", + ((Short)idColumn.getPropertyValue( "Align" )).shortValue() != TextAlign.CENTER ); + idColumn.setPropertyValue( "Align", TextAlign.CENTER ); + + // close the table data view + XCloseable closeSubComponent = UnoRuntime.queryInterface( XCloseable.class, tableView.getFrame() ); + closeSubComponent.close( true ); + + // create a query based on that column + database.getDatabase().getDataSource().createQuery( "q_customers", "SELECT * FROM \"customers\"" ); + + // load this query, and verify the table column settings was propagated to the query column + XFormController queryViewController = UnoRuntime.queryInterface( XFormController.class, + database.loadSubComponent( DatabaseObject.QUERY, "q_customers" ) ); + tableControlModel = UnoRuntime.queryInterface( XNameAccess.class, + queryViewController.getCurrentControl().getModel() ); + idColumn = UnoRuntime.queryInterface( XPropertySet.class, tableControlModel.getByName( "ID" ) ); + + assure( "table column alignment was not propagated to the query column", + ((Short)idColumn.getPropertyValue( "Align" )).shortValue() == TextAlign.CENTER ); + + // save close the database document + database.saveAndClose(); } } -- cgit From 73b50374f96e91248bee76b8fbda3b4dc59ce016 Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Wed, 4 Nov 2009 10:26:31 +0100 Subject: moved complex.dbaccess.CRMDatabase.java to connectivity.tools, to be able to use it outside of dbaccess --- dbaccess/qa/complex/dbaccess/CRMBasedTestCase.java | 1 + dbaccess/qa/complex/dbaccess/CRMDatabase.java | 281 --------------------- dbaccess/qa/complex/dbaccess/DataSource.java | 1 + dbaccess/qa/complex/dbaccess/Query.java | 1 + dbaccess/qa/complex/dbaccess/RowSet.java | 1 + dbaccess/qa/complex/dbaccess/UISettings.java | 5 +- 6 files changed, 6 insertions(+), 284 deletions(-) delete mode 100644 dbaccess/qa/complex/dbaccess/CRMDatabase.java (limited to 'dbaccess/qa') diff --git a/dbaccess/qa/complex/dbaccess/CRMBasedTestCase.java b/dbaccess/qa/complex/dbaccess/CRMBasedTestCase.java index 2b23defe7eec..d69da173a890 100644 --- a/dbaccess/qa/complex/dbaccess/CRMBasedTestCase.java +++ b/dbaccess/qa/complex/dbaccess/CRMBasedTestCase.java @@ -32,6 +32,7 @@ package complex.dbaccess; import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.sdb.XSingleSelectQueryComposer; import com.sun.star.uno.UnoRuntime; +import connectivity.tools.CRMDatabase; import java.util.logging.Level; import java.util.logging.Logger; diff --git a/dbaccess/qa/complex/dbaccess/CRMDatabase.java b/dbaccess/qa/complex/dbaccess/CRMDatabase.java deleted file mode 100644 index fbffa0fbea33..000000000000 --- a/dbaccess/qa/complex/dbaccess/CRMDatabase.java +++ /dev/null @@ -1,281 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2008 by Sun Microsystems, Inc. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * $RCSfile: CRMDatabase.java,v $ - * $Revision: 1.6.2.1 $ - * - * 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 - * - * for a copy of the LGPLv3 License. - * - ************************************************************************/ -package complex.dbaccess; - -import com.sun.star.container.ElementExistException; -import com.sun.star.container.NoSuchElementException; -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.sdbc.XConnection; -import com.sun.star.sdbcx.XTablesSupplier; -import com.sun.star.uno.UnoRuntime; -import com.sun.star.util.XRefreshable; -import connectivity.tools.DataSource; -import connectivity.tools.HsqlColumnDescriptor; -import connectivity.tools.HsqlDatabase; -import connectivity.tools.HsqlTableDescriptor; -import connectivity.tools.QueryDefinition; - -/** 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 XConnection m_connection; - - /** constructs the CRM database - */ - public CRMDatabase( XMultiServiceFactory _orb ) throws Exception - { - m_orb = _orb; - - m_database = new HsqlDatabase( m_orb ); - m_dataSource = m_database.getDataSource(); - 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 XConnection getConnection() - { - return m_connection; - } - - // -------------------------------------------------------------------------------------------------------- - public void saveAndClose() throws SQLException, IOException - { - getDocumentUI().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 - final XTablesSupplier suppTables = UnoRuntime.queryInterface( XTablesSupplier.class, m_connection ); - final XRefreshable refreshTables = UnoRuntime.queryInterface( XRefreshable.class, suppTables.getTables() ); - refreshTables.refresh(); - } - - // -------------------------------------------------------------------------------------------------------- - 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() ); - 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/dbaccess/qa/complex/dbaccess/DataSource.java b/dbaccess/qa/complex/dbaccess/DataSource.java index 29c9d2f2cdd7..429ac00f820f 100644 --- a/dbaccess/qa/complex/dbaccess/DataSource.java +++ b/dbaccess/qa/complex/dbaccess/DataSource.java @@ -34,6 +34,7 @@ import com.sun.star.uno.Exception; import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.XNamingService; import complexlib.ComplexTestCase; +import connectivity.tools.CRMDatabase; import connectivity.tools.HsqlDatabase; import java.util.logging.Level; import java.util.logging.Logger; diff --git a/dbaccess/qa/complex/dbaccess/Query.java b/dbaccess/qa/complex/dbaccess/Query.java index 684df2b65a25..ec13a800ea49 100644 --- a/dbaccess/qa/complex/dbaccess/Query.java +++ b/dbaccess/qa/complex/dbaccess/Query.java @@ -37,6 +37,7 @@ import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.sdb.XQueriesSupplier; import com.sun.star.sdbcx.XColumnsSupplier; import com.sun.star.uno.UnoRuntime; +import connectivity.tools.CRMDatabase; public class Query extends complexlib.ComplexTestCase { diff --git a/dbaccess/qa/complex/dbaccess/RowSet.java b/dbaccess/qa/complex/dbaccess/RowSet.java index d9145d7aaee8..e519d1737eb6 100644 --- a/dbaccess/qa/complex/dbaccess/RowSet.java +++ b/dbaccess/qa/complex/dbaccess/RowSet.java @@ -56,6 +56,7 @@ import com.sun.star.sdbcx.XTablesSupplier; import com.sun.star.uno.UnoRuntime; import com.sun.star.util.XRefreshable; import complexlib.ComplexTestCase; +import connectivity.tools.CRMDatabase; import connectivity.tools.DataSource; import connectivity.tools.HsqlDatabase; import java.lang.reflect.Method; diff --git a/dbaccess/qa/complex/dbaccess/UISettings.java b/dbaccess/qa/complex/dbaccess/UISettings.java index 7d9042d3e1dc..2f2d6f985255 100644 --- a/dbaccess/qa/complex/dbaccess/UISettings.java +++ b/dbaccess/qa/complex/dbaccess/UISettings.java @@ -40,16 +40,15 @@ import com.sun.star.sdb.application.DatabaseObject; import com.sun.star.sdb.application.XDatabaseDocumentUI; import com.sun.star.uno.UnoRuntime; import com.sun.star.util.XCloseable; +import connectivity.tools.CRMDatabase; public class UISettings extends TestCase { - private CRMDatabase m_database; - // -------------------------------------------------------------------------------------------------------- public String[] getTestMethodNames() { return new String[] { - //"checkTableFormattingPersistence", + "checkTableFormattingPersistence", "checkTransparentQueryColumnSettings" }; } -- cgit From 150d5c63409e46abde1c71e60ee20d86ad7177eb Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Wed, 4 Nov 2009 14:48:15 +0100 Subject: CRMDatabase now has built-in capabilities to load on creation --- dbaccess/qa/complex/dbaccess/CRMBasedTestCase.java | 2 +- dbaccess/qa/complex/dbaccess/DataSource.java | 2 +- dbaccess/qa/complex/dbaccess/Query.java | 2 +- dbaccess/qa/complex/dbaccess/RowSet.java | 2 +- dbaccess/qa/complex/dbaccess/UISettings.java | 21 ++------------------- 5 files changed, 6 insertions(+), 23 deletions(-) (limited to 'dbaccess/qa') diff --git a/dbaccess/qa/complex/dbaccess/CRMBasedTestCase.java b/dbaccess/qa/complex/dbaccess/CRMBasedTestCase.java index d69da173a890..69858f91439f 100644 --- a/dbaccess/qa/complex/dbaccess/CRMBasedTestCase.java +++ b/dbaccess/qa/complex/dbaccess/CRMBasedTestCase.java @@ -45,7 +45,7 @@ public abstract class CRMBasedTestCase extends TestCase { try { - m_database = new CRMDatabase( getORB() ); + m_database = new CRMDatabase( getORB(), false ); } catch ( Exception e ) { diff --git a/dbaccess/qa/complex/dbaccess/DataSource.java b/dbaccess/qa/complex/dbaccess/DataSource.java index 429ac00f820f..6cb0b7ee4b17 100644 --- a/dbaccess/qa/complex/dbaccess/DataSource.java +++ b/dbaccess/qa/complex/dbaccess/DataSource.java @@ -67,7 +67,7 @@ public class DataSource extends ComplexTestCase { if (m_database == null) { - final CRMDatabase database = new CRMDatabase(getFactory()); + final CRMDatabase database = new CRMDatabase( getFactory(), false ); m_database = database.getDatabase(); m_dataSource = m_database.getDataSource(); } diff --git a/dbaccess/qa/complex/dbaccess/Query.java b/dbaccess/qa/complex/dbaccess/Query.java index ec13a800ea49..27042767d588 100644 --- a/dbaccess/qa/complex/dbaccess/Query.java +++ b/dbaccess/qa/complex/dbaccess/Query.java @@ -63,7 +63,7 @@ public class Query extends complexlib.ComplexTestCase { { if ( m_database == null ) { - final CRMDatabase database = new CRMDatabase( getFactory() ); + final CRMDatabase database = new CRMDatabase( getFactory(), false ); m_database = database.getDatabase(); } } diff --git a/dbaccess/qa/complex/dbaccess/RowSet.java b/dbaccess/qa/complex/dbaccess/RowSet.java index e519d1737eb6..734ae25c56f9 100644 --- a/dbaccess/qa/complex/dbaccess/RowSet.java +++ b/dbaccess/qa/complex/dbaccess/RowSet.java @@ -145,7 +145,7 @@ public class RowSet extends ComplexTestCase { try { - final CRMDatabase database = new CRMDatabase(getFactory()); + final CRMDatabase database = new CRMDatabase( getFactory(), false ); m_database = database.getDatabase(); m_dataSource = m_database.getDataSource(); } diff --git a/dbaccess/qa/complex/dbaccess/UISettings.java b/dbaccess/qa/complex/dbaccess/UISettings.java index 2f2d6f985255..92be58f28dd6 100644 --- a/dbaccess/qa/complex/dbaccess/UISettings.java +++ b/dbaccess/qa/complex/dbaccess/UISettings.java @@ -59,30 +59,13 @@ public class UISettings extends TestCase return "UISettings"; } - // -------------------------------------------------------------------------------------------------------- - private CRMDatabase impl_createConnectedDatabaseDocument() throws Exception - { - final CRMDatabase database = new CRMDatabase( getORB() ); - - // load the document - String docURL = database.getDatabase().getDocumentURL(); - XModel doc = loadDocument( docURL ); - - // establish the connection - XDatabaseDocumentUI docUI = UnoRuntime.queryInterface( XDatabaseDocumentUI.class, - doc.getCurrentController() ); - docUI.connect(); - - return database; - } - // -------------------------------------------------------------------------------------------------------- /** verifies that aliases for inner queries work as expected */ public void checkTableFormattingPersistence() throws java.lang.Exception { // create, load, and connect a DB doc - CRMDatabase database = impl_createConnectedDatabaseDocument(); + CRMDatabase database = new CRMDatabase( getORB(), true ); // display a table XFormController tableViewController = UnoRuntime.queryInterface( XFormController.class, @@ -134,7 +117,7 @@ public class UISettings extends TestCase public void checkTransparentQueryColumnSettings() throws java.lang.Exception { // create, load, and connect a DB doc - CRMDatabase database = impl_createConnectedDatabaseDocument(); + CRMDatabase database = new CRMDatabase( getORB(), true ); // display a table XController tableView = database.loadSubComponent( DatabaseObject.TABLE, "customers" ); -- cgit From 6ae29346a41b1c02cbeb37672291684d5f9b3e5f Mon Sep 17 00:00:00 2001 From: "Frank Schoenheit [fs]" Date: Fri, 13 Nov 2009 08:59:36 +0100 Subject: some refactoring, done during creation of a test case for #i106643# --- .../qa/complex/dbaccess/ApplicationController.java | 19 ++---- dbaccess/qa/complex/dbaccess/CRMBasedTestCase.java | 5 +- dbaccess/qa/complex/dbaccess/Query.java | 12 ++-- dbaccess/qa/complex/dbaccess/RowSet.java | 79 ++++++++++------------ 4 files changed, 50 insertions(+), 65 deletions(-) (limited to 'dbaccess/qa') diff --git a/dbaccess/qa/complex/dbaccess/ApplicationController.java b/dbaccess/qa/complex/dbaccess/ApplicationController.java index c3661ef7ffee..fa7615809228 100644 --- a/dbaccess/qa/complex/dbaccess/ApplicationController.java +++ b/dbaccess/qa/complex/dbaccess/ApplicationController.java @@ -129,16 +129,16 @@ public class ApplicationController extends complexlib.ComplexTestCase // load it into a frame final Object object = getORB().createInstance("com.sun.star.frame.Desktop"); - final XComponentLoader xComponentLoader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, object); + final XComponentLoader xComponentLoader = UnoRuntime.queryInterface(XComponentLoader.class, object); final XComponent loadedComponent = xComponentLoader.loadComponentFromURL(m_database.getDocumentURL(), "_blank", FrameSearchFlag.ALL, new PropertyValue[0]); assure("too many document instances!", UnoRuntime.areSame(loadedComponent, m_databaseDocument)); // get the controller, which provides access to various UI operations - final XModel docModel = (XModel) UnoRuntime.queryInterface(XModel.class, + final XModel docModel = UnoRuntime.queryInterface(XModel.class, loadedComponent); - m_documentUI = (XDatabaseDocumentUI) UnoRuntime.queryInterface(XDatabaseDocumentUI.class, + m_documentUI = UnoRuntime.queryInterface(XDatabaseDocumentUI.class, docModel.getCurrentController()); } @@ -166,11 +166,8 @@ public class ApplicationController extends complexlib.ComplexTestCase final String newDocumentURL = URLHelper.getFileURLFromSystemPath(documentFile.getAbsoluteFile()); // store the doc in a new location - final XStorable storeDoc = (XStorable) UnoRuntime.queryInterface(XStorable.class, - m_databaseDocument); - storeDoc.storeAsURL(newDocumentURL, new PropertyValue[] - { - }); + final XStorable storeDoc = UnoRuntime.queryInterface( XStorable.class, m_databaseDocument ); + storeDoc.storeAsURL( newDocumentURL, new PropertyValue[] { } ); // connect m_documentUI.connect(); @@ -188,8 +185,7 @@ public class ApplicationController extends complexlib.ComplexTestCase impl_switchToDocument(oldDocumentURL); m_documentUI.connect(); assure("could not connect to " + m_database.getDocumentURL(), m_documentUI.isConnected()); - XTablesSupplier suppTables = (XTablesSupplier) UnoRuntime.queryInterface(XTablesSupplier.class, - m_documentUI.getActiveConnection()); + XTablesSupplier suppTables = UnoRuntime.queryInterface( XTablesSupplier.class, m_documentUI.getActiveConnection() ); XNameAccess tables = suppTables.getTables(); assure("the table was created in the wrong database", !tables.hasByName("abc")); @@ -198,8 +194,7 @@ public class ApplicationController extends complexlib.ComplexTestCase m_documentUI.connect(); assure("could not connect to " + m_database.getDocumentURL(), m_documentUI.isConnected()); - suppTables = (XTablesSupplier) UnoRuntime.queryInterface(XTablesSupplier.class, - m_documentUI.getActiveConnection()); + suppTables = UnoRuntime.queryInterface( XTablesSupplier.class, m_documentUI.getActiveConnection() ); tables = suppTables.getTables(); assure("the newly created table has not been written", tables.hasByName("abc")); } diff --git a/dbaccess/qa/complex/dbaccess/CRMBasedTestCase.java b/dbaccess/qa/complex/dbaccess/CRMBasedTestCase.java index 69858f91439f..b7c1ea987968 100644 --- a/dbaccess/qa/complex/dbaccess/CRMBasedTestCase.java +++ b/dbaccess/qa/complex/dbaccess/CRMBasedTestCase.java @@ -81,9 +81,6 @@ public abstract class CRMBasedTestCase extends TestCase */ protected final XSingleSelectQueryComposer createQueryComposer() throws com.sun.star.uno.Exception { - final XMultiServiceFactory connectionFactory = (XMultiServiceFactory)UnoRuntime.queryInterface( - XMultiServiceFactory.class, m_database.getConnection() ); - return (XSingleSelectQueryComposer)UnoRuntime.queryInterface( - XSingleSelectQueryComposer.class, connectionFactory.createInstance( "com.sun.star.sdb.SingleSelectQueryComposer" ) ); + return m_database.getConnection().createSingleSelectQueryComposer(); } } diff --git a/dbaccess/qa/complex/dbaccess/Query.java b/dbaccess/qa/complex/dbaccess/Query.java index 27042767d588..f39c37a8fbdb 100644 --- a/dbaccess/qa/complex/dbaccess/Query.java +++ b/dbaccess/qa/complex/dbaccess/Query.java @@ -88,8 +88,8 @@ public class Query extends complexlib.ComplexTestCase { try { - final XQueriesSupplier suppQueries = (XQueriesSupplier)UnoRuntime.queryInterface( - XQueriesSupplier.class, m_database.defaultConnection()); + final XQueriesSupplier suppQueries = UnoRuntime.queryInterface( + XQueriesSupplier.class, m_database.defaultConnection().getXConnection() ); final XNameAccess queries = suppQueries.getQueries(); final String[] queryNames = new String[] { "parseable", "parseable native", "unparseable" }; @@ -101,12 +101,12 @@ public class Query extends complexlib.ComplexTestCase { for ( int i = 0; i < queryNames.length; ++i ) { - final XPropertySet query = (XPropertySet)UnoRuntime.queryInterface( + final XPropertySet query = UnoRuntime.queryInterface( XPropertySet.class, queries.getByName( queryNames[i] ) ); - final XColumnsSupplier suppCols = (XColumnsSupplier)UnoRuntime.queryInterface( + final XColumnsSupplier suppCols = UnoRuntime.queryInterface( XColumnsSupplier.class, query); - final XIndexAccess columns = (XIndexAccess)UnoRuntime.queryInterface( + final XIndexAccess columns = UnoRuntime.queryInterface( XIndexAccess.class, suppCols.getColumns()); // check whether the columns supplied by the query match what we expected @@ -114,7 +114,7 @@ public class Query extends complexlib.ComplexTestCase { columns.getCount() == expectedColumnNames[i].length ); for ( int col = 0; col < columns.getCount(); ++col ) { - final XNamed columnName = (XNamed)UnoRuntime.queryInterface( + final XNamed columnName = UnoRuntime.queryInterface( XNamed.class, columns.getByIndex(col) ); assure( "column no. " + col + " of query \"" + queryNames[i] + "\" not matching", columnName.getName().equals( expectedColumnNames[i][col] ) ); diff --git a/dbaccess/qa/complex/dbaccess/RowSet.java b/dbaccess/qa/complex/dbaccess/RowSet.java index 734ae25c56f9..6a2b4e49c25a 100644 --- a/dbaccess/qa/complex/dbaccess/RowSet.java +++ b/dbaccess/qa/complex/dbaccess/RowSet.java @@ -41,7 +41,6 @@ import com.sun.star.sdb.XParametersSupplier; import com.sun.star.sdb.XResultSetAccess; import com.sun.star.sdb.XRowSetApproveBroadcaster; import com.sun.star.sdbc.SQLException; -import com.sun.star.sdbc.XConnection; import com.sun.star.sdbc.XParameters; import com.sun.star.sdbc.XPreparedStatement; import com.sun.star.sdbc.XResultSet; @@ -52,13 +51,12 @@ import com.sun.star.sdbc.XRowUpdate; import com.sun.star.sdbcx.XColumnsSupplier; import com.sun.star.sdbcx.XDeleteRows; import com.sun.star.sdbcx.XRowLocate; -import com.sun.star.sdbcx.XTablesSupplier; import com.sun.star.uno.UnoRuntime; -import com.sun.star.util.XRefreshable; import complexlib.ComplexTestCase; import connectivity.tools.CRMDatabase; import connectivity.tools.DataSource; import connectivity.tools.HsqlDatabase; +import connectivity.tools.sdb.Connection; import java.lang.reflect.Method; import java.util.Random; @@ -90,7 +88,7 @@ public class RowSet extends ComplexTestCase public ResultSetMovementStress(XResultSet _resultSet, int _id) throws java.lang.Exception { m_resultSet = _resultSet; - m_row = (XRow) UnoRuntime.queryInterface(XRow.class, m_resultSet); + m_row = UnoRuntime.queryInterface( XRow.class, m_resultSet ); m_id = _id; } @@ -205,23 +203,22 @@ public class RowSet extends ComplexTestCase { try { - m_rowSet = (XRowSet) UnoRuntime.queryInterface(XRowSet.class, - getFactory().createInstance("com.sun.star.sdb.RowSet")); - final XPropertySet rowSetProperties = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, m_rowSet); + m_rowSet = UnoRuntime.queryInterface( XRowSet.class, getFactory().createInstance( "com.sun.star.sdb.RowSet" ) ); + final XPropertySet rowSetProperties = UnoRuntime.queryInterface( XPropertySet.class, m_rowSet ); rowSetProperties.setPropertyValue("Command", command); rowSetProperties.setPropertyValue("CommandType", Integer.valueOf(commandType)); - rowSetProperties.setPropertyValue("ActiveConnection", m_database.defaultConnection()); + rowSetProperties.setPropertyValue("ActiveConnection", m_database.defaultConnection().getXConnection()); if (limitFetchSize) { rowSetProperties.setPropertyValue("FetchSize", Integer.valueOf(MAX_FETCH_ROWS)); } - m_resultSet = (XResultSet) UnoRuntime.queryInterface(XResultSet.class, m_rowSet); - m_resultSetUpdate = (XResultSetUpdate) UnoRuntime.queryInterface(XResultSetUpdate.class, m_rowSet); - m_row = (XRow) UnoRuntime.queryInterface(XRow.class, m_rowSet); - m_rowLocate = (XRowLocate) UnoRuntime.queryInterface(XRowLocate.class, m_resultSet); - m_rowSetProperties = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, m_rowSet); - m_paramsSupplier = (XParametersSupplier) UnoRuntime.queryInterface(XParametersSupplier.class, m_rowSet); + m_resultSet = UnoRuntime.queryInterface( XResultSet.class, m_rowSet ); + m_resultSetUpdate = UnoRuntime.queryInterface( XResultSetUpdate.class, m_rowSet ); + m_row = UnoRuntime.queryInterface( XRow.class, m_rowSet ); + m_rowLocate = UnoRuntime.queryInterface( XRowLocate.class, m_resultSet ); + m_rowSetProperties = UnoRuntime.queryInterface( XPropertySet.class, m_rowSet ); + m_paramsSupplier = UnoRuntime.queryInterface( XParametersSupplier.class, m_rowSet ); if (execute) { @@ -260,7 +257,7 @@ public class RowSet extends ComplexTestCase // -------------------------------------------------------------------------------------------------------- XResultSet createClone() throws SQLException { - final XResultSetAccess rowAcc = (XResultSetAccess) UnoRuntime.queryInterface(XResultSetAccess.class, m_rowSet); + final XResultSetAccess rowAcc = UnoRuntime.queryInterface( XResultSetAccess.class, m_rowSet ); return rowAcc.createResultSet(); } @@ -270,9 +267,9 @@ public class RowSet extends ComplexTestCase m_database.executeSQL("DROP TABLE \"TEST1\" IF EXISTS"); m_database.executeSQL("CREATE TABLE \"TEST1\" (\"ID\" integer not null primary key, \"col2\" varchar(50) )"); - final XConnection connection = m_database.defaultConnection(); + final Connection connection = m_database.defaultConnection(); final XPreparedStatement prep = connection.prepareStatement("INSERT INTO \"TEST1\" values (?,?)"); - final XParameters para = (XParameters) UnoRuntime.queryInterface(XParameters.class, prep); + final XParameters para = UnoRuntime.queryInterface( XParameters.class, prep ); for (int i = 1; i <= MAX_TABLE_ROWS; ++i) { para.setInt(1, i); @@ -280,9 +277,7 @@ public class RowSet extends ComplexTestCase prep.executeUpdate(); } - final XTablesSupplier suppTables = (XTablesSupplier) UnoRuntime.queryInterface(XTablesSupplier.class, connection); - final XRefreshable refresh = (XRefreshable) UnoRuntime.queryInterface(XRefreshable.class, suppTables.getTables()); - refresh.refresh(); + connection.refreshTables(); } // -------------------------------------------------------------------------------------------------------- @@ -336,8 +331,8 @@ public class RowSet extends ComplexTestCase { try { - final XRow _row = (XRow) UnoRuntime.queryInterface(XRow.class, _resultSet); - final XRow cloneRow = (XRow) UnoRuntime.queryInterface(XRow.class, clone); + final XRow _row = UnoRuntime.queryInterface( XRow.class, _resultSet ); + final XRow cloneRow = UnoRuntime.queryInterface( XRow.class, clone ); for (int i = 1; i <= MAX_FETCH_ROWS; ++i) { final int calcPos = (MAX_TABLE_ROWS % i) + 1; @@ -360,14 +355,14 @@ public class RowSet extends ComplexTestCase { try { - final XRow _row = (XRow) UnoRuntime.queryInterface(XRow.class, _resultSet); + final XRow _row = UnoRuntime.queryInterface( XRow.class, _resultSet ); _resultSet.beforeFirst(); for (int i = 1; i <= MAX_TABLE_ROWS; ++i) { _resultSet.next(); final XResultSet clone = createClone(); - final XRow cloneRow = (XRow) UnoRuntime.queryInterface(XRow.class, clone); + final XRow cloneRow = UnoRuntime.queryInterface( XRow.class, clone ); final int calcPos = MAX_TABLE_ROWS - 1; if (calcPos != 0 && clone.absolute(calcPos)) { @@ -421,15 +416,15 @@ public class RowSet extends ComplexTestCase // first we create our RowSet object final RowSetEventListener pRow = new RowSetEventListener(); - final XColumnsSupplier colSup = (XColumnsSupplier) UnoRuntime.queryInterface(XColumnsSupplier.class, m_rowSet); - final XPropertySet col = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, colSup.getColumns().getByName("ID")); + final XColumnsSupplier colSup = UnoRuntime.queryInterface( XColumnsSupplier.class, m_rowSet ); + final XPropertySet col = UnoRuntime.queryInterface( XPropertySet.class, colSup.getColumns().getByName( "ID" ) ); col.addPropertyChangeListener("Value", pRow); m_rowSetProperties.addPropertyChangeListener("IsModified", pRow); m_rowSetProperties.addPropertyChangeListener("IsNew", pRow); m_rowSetProperties.addPropertyChangeListener("IsRowCountFinal", pRow); m_rowSetProperties.addPropertyChangeListener("RowCount", pRow); - final XRowSetApproveBroadcaster xApBroad = (XRowSetApproveBroadcaster) UnoRuntime.queryInterface(XRowSetApproveBroadcaster.class, m_resultSet); + final XRowSetApproveBroadcaster xApBroad = UnoRuntime.queryInterface( XRowSetApproveBroadcaster.class, m_resultSet ); xApBroad.addRowSetApproveListener(pRow); m_rowSet.addRowSetListener(pRow); @@ -459,13 +454,13 @@ public class RowSet extends ComplexTestCase testCursorMove(m_resultSet, cResSet.getMethod("previous", (Class[]) null), pRow, moves, null); testCursorMove(m_resultSet, cResSet.getMethod(NEXT, (Class[]) null), pRow, moves, null); moves[RowSetEventListener.IS_MODIFIED] = true; - final XRowUpdate updRow = (XRowUpdate) UnoRuntime.queryInterface(XRowUpdate.class, m_resultSet); + final XRowUpdate updRow = UnoRuntime.queryInterface( XRowUpdate.class, m_resultSet ); updRow.updateString(2, TEST21); testCursorMove(m_resultSet, cResSet.getMethod(NEXT, (Class[]) null), pRow, moves, null); moves[RowSetEventListener.IS_MODIFIED] = false; final Class cupd = Class.forName("com.sun.star.sdbc.XResultSetUpdate"); - final XResultSetUpdate upd = (XResultSetUpdate) UnoRuntime.queryInterface(XResultSetUpdate.class, m_resultSet); + final XResultSetUpdate upd = UnoRuntime.queryInterface( XResultSetUpdate.class, m_resultSet ); testCursorMove(upd, cupd.getMethod("moveToInsertRow", (Class[]) null), pRow, moves, null); updRow.updateInt(1, MAX_TABLE_ROWS + 2); @@ -537,7 +532,7 @@ public class RowSet extends ComplexTestCase moves[RowSetEventListener.ROW_COUNT] = true; final Class cdelRows = Class.forName("com.sun.star.sdbcx.XDeleteRows"); ctemp[0] = Object[].class; - final XDeleteRows delRows = (XDeleteRows) UnoRuntime.queryInterface(XDeleteRows.class, m_resultSet); + final XDeleteRows delRows = UnoRuntime.queryInterface( XDeleteRows.class, m_resultSet ); final Object bookmarks[] = new Object[5]; m_resultSet.first(); for (int i = 0; i < bookmarks.length; ++i) @@ -550,7 +545,7 @@ public class RowSet extends ComplexTestCase testCursorMove(delRows, cdelRows.getMethod("deleteRows", ctemp), pRow, moves, temp); // now destroy the RowSet - final XComponent xComp = (XComponent) UnoRuntime.queryInterface(XComponent.class, m_resultSet); + final XComponent xComp = UnoRuntime.queryInterface( XComponent.class, m_resultSet ); xComp.dispose(); } @@ -716,7 +711,7 @@ public class RowSet extends ComplexTestCase positionRandom(); final Object deleteBookmark = m_rowLocate.getBookmark(); m_resultSetUpdate.deleteRow(); - final XDeleteRows multiDelete = (XDeleteRows) UnoRuntime.queryInterface(XDeleteRows.class, m_resultSet); + final XDeleteRows multiDelete = UnoRuntime.queryInterface( XDeleteRows.class, m_resultSet ); final int[] deleteSuccess = multiDelete.deleteRows(new Object[] { firstBookmark, deleteBookmark @@ -746,7 +741,7 @@ public class RowSet extends ComplexTestCase // ..................................................................................................... // updating values in a deleted row should fail deleteRandom(); - final XRowUpdate rowUpdated = (XRowUpdate) UnoRuntime.queryInterface(XRowUpdate.class, m_resultSet); + final XRowUpdate rowUpdated = UnoRuntime.queryInterface( XRowUpdate.class, m_resultSet ); caughtException = false; try { @@ -763,6 +758,7 @@ public class RowSet extends ComplexTestCase /** checks whether deletions on the main RowSet properly interfere (or don't interfere) with the movement * on a clone of the RowSet */ + @SuppressWarnings("empty-statement") public void testCloneMovesPlusDeletions() throws SQLException, UnknownPropertyException, WrappedTargetException { createTestCase(true); @@ -770,7 +766,7 @@ public class RowSet extends ComplexTestCase m_resultSet.last(); final XResultSet clone = createClone(); - final XRowLocate cloneRowLocate = (XRowLocate) UnoRuntime.queryInterface(XRowLocate.class, clone); + final XRowLocate cloneRowLocate = UnoRuntime.queryInterface( XRowLocate.class, clone ); positionRandom(); @@ -838,7 +834,7 @@ public class RowSet extends ComplexTestCase m_rowSetProperties.setPropertyValue("FetchSize", Integer.valueOf(10)); final XResultSet clone = createClone(); - final XRow cloneRow = (XRow) UnoRuntime.queryInterface(XRow.class, clone); + final XRow cloneRow = UnoRuntime.queryInterface( XRow.class, clone ); // ..................................................................................................... // first check the basic scenario without the |moveToInsertRow| |moveToCurrentRow|, to ensure that @@ -894,8 +890,7 @@ public class RowSet extends ComplexTestCase { createRowSet("SELECT * FROM \"customers\"", CommandType.COMMAND, true); m_rowSetProperties.setPropertyValue("Command", "SELECT * FROM \"customers\" WHERE \"City\" = :city"); - final XParameters rowsetParams = (XParameters) UnoRuntime.queryInterface(XParameters.class, - m_rowSet); + final XParameters rowsetParams = UnoRuntime.queryInterface( XParameters.class, m_rowSet ); rowsetParams.setString(1, "London"); m_rowSet.execute(); } @@ -922,8 +917,7 @@ public class RowSet extends ComplexTestCase for (int i = 0; i < expected; ++i) { - final XPropertySet parameter = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, - params.getByIndex(i)); + final XPropertySet parameter = UnoRuntime.queryInterface( XPropertySet.class, params.getByIndex( i ) ); final String expectedName = _paramNames[i]; final String foundName = (String) parameter.getPropertyValue("Name"); @@ -960,12 +954,11 @@ public class RowSet extends ComplexTestCase createRowSet("products like", CommandType.QUERY, false); // let's fill in a parameter value via XParameters, and see whether it is respected by the parameters container - final XParameters rowsetParams = (XParameters) UnoRuntime.queryInterface(XParameters.class, - m_rowSet); + final XParameters rowsetParams = UnoRuntime.queryInterface(XParameters.class, m_rowSet); rowsetParams.setString(1, "Apples"); XIndexAccess params = m_paramsSupplier.getParameters(); - XPropertySet firstParam = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, params.getByIndex(0)); + XPropertySet firstParam = UnoRuntime.queryInterface( XPropertySet.class, params.getByIndex( 0 ) ); Object firstParamValue = firstParam.getPropertyValue("Value"); assure("XParameters and the parameters container do not properly interact", @@ -979,7 +972,7 @@ public class RowSet extends ComplexTestCase // the execution of the row set. It currently doesn't (though the values it represents do). // It would be nice, but not strictly necessary, if it would. params = m_paramsSupplier.getParameters(); - firstParam = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, params.getByIndex(0)); + firstParam = UnoRuntime.queryInterface( XPropertySet.class, params.getByIndex( 0 ) ); } firstParamValue = firstParam.getPropertyValue("Value"); assure("XParameters and the parameters container do not properly interact, after the row set has been executed", -- cgit From 9bc02eaf9c7df1cf4408a2af37e9fe9c67acecb1 Mon Sep 17 00:00:00 2001 From: "Ocke Janssen [oj]" Date: Wed, 25 Nov 2009 13:48:21 +0100 Subject: dba33d: #i104869# use the interaction handler to delegate UI --- dbaccess/qa/complex/dbaccess/dbaccess.sce | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'dbaccess/qa') diff --git a/dbaccess/qa/complex/dbaccess/dbaccess.sce b/dbaccess/qa/complex/dbaccess/dbaccess.sce index 47387e459ae9..c5fa408ff273 100644 --- a/dbaccess/qa/complex/dbaccess/dbaccess.sce +++ b/dbaccess/qa/complex/dbaccess/dbaccess.sce @@ -7,6 +7,6 @@ -o complex.dbaccess.DataSource -o complex.dbaccess.Parser -o complex.dbaccess.ApplicationController -#-o complex.dbaccess.CopyTableWizard +-o complex.dbaccess.CopyTableWizard -o complex.dbaccess.UISettings -o complex.dbaccess.Beamer -- cgit