summaryrefslogtreecommitdiff
path: root/dbaccess/qa/complex
diff options
context:
space:
mode:
authorFrank Schoenheit [fs] <frank.schoenheit@sun.com>2009-11-04 10:26:31 +0100
committerFrank Schoenheit [fs] <frank.schoenheit@sun.com>2009-11-04 10:26:31 +0100
commit73b50374f96e91248bee76b8fbda3b4dc59ce016 (patch)
tree574f315de47ca87d96929ba2bed98a3e935a12a8 /dbaccess/qa/complex
parentdf3a4b31dc7311fbac90747809d301aa392ac327 (diff)
moved complex.dbaccess.CRMDatabase.java to connectivity.tools, to be able to use it outside of dbaccess
Diffstat (limited to 'dbaccess/qa/complex')
-rw-r--r--dbaccess/qa/complex/dbaccess/CRMBasedTestCase.java1
-rw-r--r--dbaccess/qa/complex/dbaccess/CRMDatabase.java281
-rw-r--r--dbaccess/qa/complex/dbaccess/DataSource.java1
-rw-r--r--dbaccess/qa/complex/dbaccess/Query.java1
-rw-r--r--dbaccess/qa/complex/dbaccess/RowSet.java1
-rw-r--r--dbaccess/qa/complex/dbaccess/UISettings.java5
6 files changed, 6 insertions, 284 deletions
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
- * <http://www.openoffice.org/license.html>
- * 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"
};
}