Tag: cws_src680_oj14 User: fs Date: 2007-06-06 09:02:02+0000 Modified: dba/dbaccess/qa/complex/dbaccess/CRMDatabase.java dba/dbaccess/qa/complex/dbaccess/Query.java
Log: outsourced some query creation into the CRMDatabase, for easier re-use File Changes: Directory: /dba/dbaccess/qa/complex/dbaccess/ ============================================= File [changed]: CRMDatabase.java Url: http://dba.openoffice.org/source/browse/dba/dbaccess/qa/complex/dbaccess/CRMDatabase.java?r1=1.2&r2=1.2.84.1 Delta lines: +48 -3 -------------------- --- CRMDatabase.java 2006-07-10 14:58:33+0000 1.2 +++ CRMDatabase.java 2007-06-06 09:01:59+0000 1.2.84.1 @@ -4,9 +4,9 @@ * * $RCSfile: CRMDatabase.java,v $ * - * $Revision: 1.2 $ + * $Revision: 1.2.84.1 $ * - * last change: $Author: obo $ $Date: 2006/07/10 14:58:33 $ + * last change: $Author: fs $ $Date: 2007/06/06 09:01:59 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -37,6 +37,7 @@ import com.sun.star.container.ElementExistException; import com.sun.star.lang.WrappedTargetException; 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.sdbcx.XTablesSupplier; @@ -46,6 +47,9 @@ import connectivity.tools.HsqlColumnDescriptor; import connectivity.tools.HsqlDatabase; import connectivity.tools.HsqlTableDescriptor; +import connectivity.tools.QueryDefinition; + +import complexlib.ComplexTestCase.AssureException; /** implements a small Customer Relationship Management database * @@ -143,6 +147,41 @@ refreshTables.refresh(); } + // -------------------------------------------------------------------------------------------------------- + private void validateUnparseable() + { + // The "unparseable" query should be indeed be unparseable by OOo (though a valid HSQL query) + XSingleSelectQueryComposer composer = null; + QueryDefinition unparseableQuery = null; + try + { + XMultiServiceFactory factory = (XMultiServiceFactory)UnoRuntime.queryInterface( + XMultiServiceFactory.class, m_database.defaultConnection() ); + composer = (XSingleSelectQueryComposer)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( @@ -166,7 +205,13 @@ "unshipped orders", "SELECT * " + "FROM \"all orders\"" + - "WHERE ( \"ShipDate\" IS NULL" + "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 \"Postal\" || ' - ' || \"City\" AS \"concat\" FROM \"customers\"", false ); + + validateUnparseable(); } } File [changed]: Query.java Url: http://dba.openoffice.org/source/browse/dba/dbaccess/qa/complex/dbaccess/Query.java?r1=1.2&r2=1.2.84.1 Delta lines: +5 -69 -------------------- --- Query.java 2006-07-10 14:58:58+0000 1.2 +++ Query.java 2007-06-06 09:01:59+0000 1.2.84.1 @@ -4,9 +4,9 @@ * * $RCSfile: Query.java,v $ * - * $Revision: 1.2 $ + * $Revision: 1.2.84.1 $ * - * last change: $Author: obo $ $Date: 2006/07/10 14:58:58 $ + * last change: $Author: fs $ $Date: 2007/06/06 09:01:59 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -67,80 +67,16 @@ } // -------------------------------------------------------------------------------------------------------- - private void createTables() throws SQLException - { - m_database.dropTable( "test", true ); - HsqlTableDescriptor table = new HsqlTableDescriptor( "test", - new HsqlColumnDescriptor[] { - new HsqlColumnDescriptor( "ID", "INTEGER", HsqlColumnDescriptor.PRIMARY ), - new HsqlColumnDescriptor( "left", "VARCHAR(50)" ), - new HsqlColumnDescriptor( "right", "VARCHAR(50)" ) } ); - m_database.createTable(table); - } - - // -------------------------------------------------------------------------------------------------------- - private void validateUnparseable() - { - // The "unparseable" query should be indeed be unparseable by OOo (though a valid HSQL query) - XSingleSelectQueryComposer composer = null; - QueryDefinition unparseableQuery = null; - try - { - XMultiServiceFactory factory = (XMultiServiceFactory)UnoRuntime.queryInterface( - XMultiServiceFactory.class, m_database.defaultConnection() ); - composer = (XSingleSelectQueryComposer)UnoRuntime.queryInterface( - XSingleSelectQueryComposer.class, factory.createInstance( "com.sun.star.sdb.SingleSelectQueryComposer" ) ); - unparseableQuery = m_dataSource.getQueryDefinition( "unparseable" ); - } - catch( Exception e ) - { - assure( "caught an unexpected exception: " + e.getMessage(), false ); - } - - boolean caughtExpected = false; - try - { - composer.setQuery( unparseableQuery.getCommand() ); - } - catch (WrappedTargetException e) { } - catch( SQLException e ) - { - caughtExpected = true; - } - - assure( "Somebody improved the parser! This is bad :), since we need an unparsable query here!", caughtExpected ); - } - - // -------------------------------------------------------------------------------------------------------- - private void createQueries() throws SQLException - { - try - { - m_dataSource.createQuery( "parseable", "SELECT * FROM \"test\"" ); - m_dataSource.createQuery( "parseable native", "SELECT * FROM INFORMATION_SCHEMA.SYSTEM_VIEWS", false ); - m_dataSource.createQuery( "unparseable", "SELECT \"left\" || ' - ' || \"right\" AS \"concat\" FROM \"test\"", false ); - } - catch ( Exception e ) - { - assure( "caught an unexpected exception:" + e.getMessage(), false ); - } - - validateUnparseable(); - } - - // -------------------------------------------------------------------------------------------------------- private void createTestCase() { try { if ( m_database == null ) { - m_database = new HsqlDatabase( getFactory() ); + CRMDatabase database = new CRMDatabase( getFactory() ); + m_database = database.getDatabase(); m_dataSource = m_database.getDataSource(); } - - createTables(); - createQueries(); } catch( Exception e ) { @@ -169,7 +105,7 @@ String[] queryNames = new String[] { "parseable", "parseable native", "unparseable" }; String[][] expectedColumnNames = new String[][] { - new String[] { "ID", "left", "right" }, + new String[] { "ID", "Name", "Address", "City", "Postal" }, new String[] { "TABLE_CATALOG", "TABLE_SCHEMA", "TABLE_NAME", "VIEW_DEFINITION", "CHECK_OPTION", "IS_UPDATABLE", "VALID" }, new String[] { "concat" } }; --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
