diff options
Diffstat (limited to 'connectivity/qa/connectivity/tools')
-rwxr-xr-x | connectivity/qa/connectivity/tools/AbstractDatabase.java | 24 | ||||
-rwxr-xr-x[-rw-r--r--] | connectivity/qa/connectivity/tools/CRMDatabase.java | 0 | ||||
-rwxr-xr-x | connectivity/qa/connectivity/tools/CsvDatabase.java | 18 | ||||
-rwxr-xr-x[-rw-r--r--] | connectivity/qa/connectivity/tools/DataSource.java | 38 | ||||
-rwxr-xr-x | connectivity/qa/connectivity/tools/DbaseDatabase.java | 90 | ||||
-rwxr-xr-x | connectivity/qa/connectivity/tools/FlatFileDatabase.java | 116 | ||||
-rwxr-xr-x[-rw-r--r--] | connectivity/qa/connectivity/tools/HsqlColumnDescriptor.java | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | connectivity/qa/connectivity/tools/HsqlDatabase.java | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | connectivity/qa/connectivity/tools/HsqlTableDescriptor.java | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | connectivity/qa/connectivity/tools/QueryDefinition.java | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | connectivity/qa/connectivity/tools/RowSet.java | 17 | ||||
-rwxr-xr-x[-rw-r--r--] | connectivity/qa/connectivity/tools/makefile.mk | 8 | ||||
-rwxr-xr-x[-rw-r--r--] | connectivity/qa/connectivity/tools/sdb/Connection.java | 0 |
13 files changed, 192 insertions, 119 deletions
diff --git a/connectivity/qa/connectivity/tools/AbstractDatabase.java b/connectivity/qa/connectivity/tools/AbstractDatabase.java index 0137dbc9ab..738a348840 100755 --- a/connectivity/qa/connectivity/tools/AbstractDatabase.java +++ b/connectivity/qa/connectivity/tools/AbstractDatabase.java @@ -47,18 +47,6 @@ import java.io.File; */ public abstract class AbstractDatabase implements DatabaseAccess { - // the service factory - - protected final XMultiServiceFactory m_orb; - // the URL of the temporary file used for the database document - protected String m_databaseDocumentFile; - // the database document - protected XOfficeDatabaseDocument m_databaseDocument; - // the data source belonging to the database document - protected DataSource m_dataSource; - // the default connection - protected Connection m_connection; - public AbstractDatabase(final XMultiServiceFactory orb) throws Exception { m_orb = orb; @@ -75,7 +63,6 @@ public abstract class AbstractDatabase implements DatabaseAccess * * Multiple calls to this method return the same connection. The DbaseDatabase object keeps * the ownership of the connection, so you don't need to (and should not) dispose/close it. - * */ public Connection defaultConnection() throws SQLException { @@ -219,4 +206,15 @@ public abstract class AbstractDatabase implements DatabaseAccess closeAndDelete(); super.finalize(); } + + // the service factory + protected final XMultiServiceFactory m_orb; + // the URL of the temporary file used for the database document + protected String m_databaseDocumentFile; + // the database document + protected XOfficeDatabaseDocument m_databaseDocument; + // the data source belonging to the database document + protected DataSource m_dataSource; + // the default connection + protected Connection m_connection; } diff --git a/connectivity/qa/connectivity/tools/CRMDatabase.java b/connectivity/qa/connectivity/tools/CRMDatabase.java index aa5811e746..aa5811e746 100644..100755 --- a/connectivity/qa/connectivity/tools/CRMDatabase.java +++ b/connectivity/qa/connectivity/tools/CRMDatabase.java diff --git a/connectivity/qa/connectivity/tools/CsvDatabase.java b/connectivity/qa/connectivity/tools/CsvDatabase.java new file mode 100755 index 0000000000..f9f16a7182 --- /dev/null +++ b/connectivity/qa/connectivity/tools/CsvDatabase.java @@ -0,0 +1,18 @@ +package connectivity.tools; + +import com.sun.star.lang.XMultiServiceFactory; + +public class CsvDatabase extends FlatFileDatabase +{ + // -------------------------------------------------------------------------------------------------------- + public CsvDatabase( final XMultiServiceFactory i_orb ) throws Exception + { + super( i_orb, "flat" ); + } + + // -------------------------------------------------------------------------------------------------------- + protected CsvDatabase( final XMultiServiceFactory i_orb, final String i_existingDocumentURL ) throws Exception + { + super( i_orb, i_existingDocumentURL, "flat" ); + } +} diff --git a/connectivity/qa/connectivity/tools/DataSource.java b/connectivity/qa/connectivity/tools/DataSource.java index 3c2d2ff5c2..a692ae0d81 100644..100755 --- a/connectivity/qa/connectivity/tools/DataSource.java +++ b/connectivity/qa/connectivity/tools/DataSource.java @@ -69,6 +69,14 @@ public class DataSource return m_dataSource; } + /** + * retrieves the data source's settings + */ + public XPropertySet geSettings() + { + return UnoRuntime.queryInterface( XPropertySet.class, impl_getPropertyValue( "Settings" ) ); + } + /** creates a query with a given name and SQL command */ public void createQuery(final String _name, final String _sqlCommand) throws ElementExistException, WrappedTargetException, com.sun.star.lang.IllegalArgumentException @@ -121,25 +129,35 @@ public class DataSource return suppQueries.getQueryDefinitions(); } - /** returns the name of the data source - * - * If a data source is registered at the database context, the name is the registration - * name. Otherwise, its the URL which the respective database document is based on. - * - * Note that the above definition is from the UNO API, not from this wrapper here. + /** + * retrieves a property value from the data source + * @param i_propertyName + * the name of the property whose value is to be returned. */ - public String getName() + private Object impl_getPropertyValue( final String i_propertyName ) { - String name = null; + Object propertyValue = null; try { final XPropertySet dataSourceProps = UnoRuntime.queryInterface( XPropertySet.class, m_dataSource ); - name = (String) dataSourceProps.getPropertyValue("Name"); + propertyValue = dataSourceProps.getPropertyValue( i_propertyName ); } catch (Exception ex) { Logger.getLogger(DataSource.class.getName()).log(Level.SEVERE, null, ex); } - return name; + return propertyValue; + } + + /** returns the name of the data source + * + * If a data source is registered at the database context, the name is the registration + * name. Otherwise, its the URL which the respective database document is based on. + * + * Note that the above definition is from the UNO API, not from this wrapper here. + */ + public String getName() + { + return (String)impl_getPropertyValue( "Name" ); } }; diff --git a/connectivity/qa/connectivity/tools/DbaseDatabase.java b/connectivity/qa/connectivity/tools/DbaseDatabase.java index 63c8acb118..19a44132ad 100755 --- a/connectivity/qa/connectivity/tools/DbaseDatabase.java +++ b/connectivity/qa/connectivity/tools/DbaseDatabase.java @@ -1,98 +1,18 @@ -/************************************************************************* - * - * 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.XPropertySet; -import com.sun.star.frame.XStorable; import com.sun.star.lang.XMultiServiceFactory; -import com.sun.star.sdb.XOfficeDatabaseDocument; -import com.sun.star.sdbc.SQLException; -import com.sun.star.uno.UnoRuntime; -import helper.URLHelper; -import java.io.File; - -/** - * - * @author Ocke - */ -public class DbaseDatabase extends AbstractDatabase +public class DbaseDatabase extends FlatFileDatabase { // -------------------------------------------------------------------------------------------------------- - - public DbaseDatabase(final XMultiServiceFactory orb) throws Exception + public DbaseDatabase( final XMultiServiceFactory i_orb ) throws Exception { - super(orb); - createDBDocument(); + super( i_orb, "dbase" ); } // -------------------------------------------------------------------------------------------------------- - public DbaseDatabase(final XMultiServiceFactory orb, final String _existingDocumentURL) throws Exception - { - super(orb, _existingDocumentURL); - } - - /** creates an empty database document in a temporary location - */ - private void createDBDocument() throws Exception - { - final File documentFile = File.createTempFile("dbase", ".odb"); - if ( documentFile.exists() ) - documentFile.delete(); - final File subPath = new File(documentFile.getParent() + File.separator + documentFile.getName().replaceAll(".odb", "") + File.separator ); - subPath.mkdir(); - //subPath.deleteOnExit(); - m_databaseDocumentFile = URLHelper.getFileURLFromSystemPath(documentFile); - final String path = URLHelper.getFileURLFromSystemPath(subPath.getPath()); - - m_databaseDocument = (XOfficeDatabaseDocument) UnoRuntime.queryInterface( - XOfficeDatabaseDocument.class, m_orb.createInstance("com.sun.star.sdb.OfficeDatabaseDocument")); - m_dataSource = new DataSource(m_orb, m_databaseDocument.getDataSource()); - - final XPropertySet dsProperties = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, m_databaseDocument.getDataSource()); - dsProperties.setPropertyValue("URL", "sdbc:dbase:" + path); - - final XStorable storable = (XStorable) UnoRuntime.queryInterface(XStorable.class, m_databaseDocument); - storable.storeAsURL(m_databaseDocumentFile, new PropertyValue[] - { - }); - } - - /** drops the table with a given name - - @param _name - the name of the table to drop - @param _ifExists - TRUE if it should be dropped only when it exists. - */ - public void dropTable(final String _name,final boolean _ifExists) throws SQLException + protected DbaseDatabase( final XMultiServiceFactory i_orb, final String i_existingDocumentURL ) throws Exception { - String dropStatement = "DROP TABLE \"" + _name; - executeSQL(dropStatement); + super( i_orb, i_existingDocumentURL, "dbase" ); } } diff --git a/connectivity/qa/connectivity/tools/FlatFileDatabase.java b/connectivity/qa/connectivity/tools/FlatFileDatabase.java new file mode 100755 index 0000000000..b0eca7c414 --- /dev/null +++ b/connectivity/qa/connectivity/tools/FlatFileDatabase.java @@ -0,0 +1,116 @@ +/************************************************************************* + * + * 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.XPropertySet; +import com.sun.star.frame.XStorable; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.sdb.XOfficeDatabaseDocument; +import com.sun.star.sdbc.SQLException; +import com.sun.star.uno.UnoRuntime; + +import helper.URLHelper; +import java.io.File; + +class FlatFileDatabase extends AbstractDatabase +{ + // -------------------------------------------------------------------------------------------------------- + protected FlatFileDatabase( final XMultiServiceFactory i_orb, final String i_urlSubScheme ) throws Exception + { + super(i_orb); + m_urlSubScheme = i_urlSubScheme; + createDBDocument(); + } + + // -------------------------------------------------------------------------------------------------------- + protected FlatFileDatabase(final XMultiServiceFactory i_orb, final String i_existingDocumentURL, + final String i_urlSubScheme ) throws Exception + { + super( i_orb, i_existingDocumentURL ); + m_urlSubScheme = i_urlSubScheme; + + final XPropertySet dsProperties = UnoRuntime.queryInterface(XPropertySet.class, m_databaseDocument.getDataSource()); + final String url = (String)dsProperties.getPropertyValue( "URL" ); + final String expectedURLPrefix = "sdbc:" + m_urlSubScheme + ":"; + if ( !url.startsWith( expectedURLPrefix ) ) + throw new IllegalArgumentException( i_existingDocumentURL + " is of wrong type" ); + + final String location = url.substring( expectedURLPrefix.length() ); + m_tableFileLocation = new File( location ); + if ( m_tableFileLocation.isDirectory() ) + throw new IllegalArgumentException( "unsupported table file location (must be a folder)" ); + } + + /** + * returns a {@link File} which represents the folder where the database's table files reside. + */ + public File getTableFileLocation() + { + return m_tableFileLocation; + } + + /** creates an empty database document in a temporary location + */ + private void createDBDocument() throws Exception + { + final File documentFile = File.createTempFile( m_urlSubScheme, ".odb" ); + if ( documentFile.exists() ) + documentFile.delete(); + m_tableFileLocation = new File(documentFile.getParent() + File.separator + documentFile.getName().replace(".odb", "") + File.separator ); + m_tableFileLocation.mkdir(); + //subPath.deleteOnExit(); + m_databaseDocumentFile = URLHelper.getFileURLFromSystemPath(documentFile); + final String path = URLHelper.getFileURLFromSystemPath( m_tableFileLocation.getPath() ); + + m_databaseDocument = UnoRuntime.queryInterface( XOfficeDatabaseDocument.class, + m_orb.createInstance("com.sun.star.sdb.OfficeDatabaseDocument")); + m_dataSource = new DataSource(m_orb, m_databaseDocument.getDataSource()); + + final XPropertySet dsProperties = UnoRuntime.queryInterface(XPropertySet.class, m_databaseDocument.getDataSource()); + dsProperties.setPropertyValue("URL", "sdbc:" + m_urlSubScheme + ":" + path); + + final XStorable storable = UnoRuntime.queryInterface( XStorable.class, m_databaseDocument ); + storable.storeAsURL( m_databaseDocumentFile, new PropertyValue[] { } ); + } + + /** drops the table with a given name + + @param _name + the name of the table to drop + @param _ifExists + TRUE if it should be dropped only when it exists. + */ + public void dropTable(final String _name,final boolean _ifExists) throws SQLException + { + String dropStatement = "DROP TABLE \"" + _name; + executeSQL(dropStatement); + } + + final String m_urlSubScheme; + File m_tableFileLocation = null; +} diff --git a/connectivity/qa/connectivity/tools/HsqlColumnDescriptor.java b/connectivity/qa/connectivity/tools/HsqlColumnDescriptor.java index 824f7ebd2f..824f7ebd2f 100644..100755 --- a/connectivity/qa/connectivity/tools/HsqlColumnDescriptor.java +++ b/connectivity/qa/connectivity/tools/HsqlColumnDescriptor.java diff --git a/connectivity/qa/connectivity/tools/HsqlDatabase.java b/connectivity/qa/connectivity/tools/HsqlDatabase.java index d39a322f2f..d39a322f2f 100644..100755 --- a/connectivity/qa/connectivity/tools/HsqlDatabase.java +++ b/connectivity/qa/connectivity/tools/HsqlDatabase.java diff --git a/connectivity/qa/connectivity/tools/HsqlTableDescriptor.java b/connectivity/qa/connectivity/tools/HsqlTableDescriptor.java index b4d1f656dc..b4d1f656dc 100644..100755 --- a/connectivity/qa/connectivity/tools/HsqlTableDescriptor.java +++ b/connectivity/qa/connectivity/tools/HsqlTableDescriptor.java diff --git a/connectivity/qa/connectivity/tools/QueryDefinition.java b/connectivity/qa/connectivity/tools/QueryDefinition.java index 4ca3ca0ef2..4ca3ca0ef2 100644..100755 --- a/connectivity/qa/connectivity/tools/QueryDefinition.java +++ b/connectivity/qa/connectivity/tools/QueryDefinition.java diff --git a/connectivity/qa/connectivity/tools/RowSet.java b/connectivity/qa/connectivity/tools/RowSet.java index 7581804e33..4ad99a9c9b 100644..100755 --- a/connectivity/qa/connectivity/tools/RowSet.java +++ b/connectivity/qa/connectivity/tools/RowSet.java @@ -31,6 +31,7 @@ import com.sun.star.beans.XPropertySet; import com.sun.star.container.XIndexAccess; import com.sun.star.container.XNameAccess; import com.sun.star.io.XInputStream; +import com.sun.star.lang.XComponent; import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.sdbc.SQLException; import com.sun.star.sdbc.XArray; @@ -48,7 +49,6 @@ import com.sun.star.util.Time; public class RowSet implements XRowSet, XRow { - private XMultiServiceFactory m_orb; private XRowSet m_rowSet; private XRow m_row; private XPropertySet m_rowSetProps; @@ -57,14 +57,13 @@ public class RowSet implements XRowSet, XRow { try { - m_rowSetProps = (XPropertySet)UnoRuntime.queryInterface( - XPropertySet.class, _orb.createInstance("com.sun.star.sdb.RowSet") ); + m_rowSetProps = UnoRuntime.queryInterface( XPropertySet.class, _orb.createInstance( "com.sun.star.sdb.RowSet" ) ); m_rowSetProps.setPropertyValue( "DataSourceName", _dataSource ); m_rowSetProps.setPropertyValue( "CommandType", new Integer( _commandType ) ); m_rowSetProps.setPropertyValue( "Command", _command ); - m_rowSet = (XRowSet)UnoRuntime.queryInterface( XRowSet.class, m_rowSetProps ); - m_row = (XRow)UnoRuntime.queryInterface( XRow.class, m_rowSetProps ); + m_rowSet = UnoRuntime.queryInterface( XRowSet.class, m_rowSetProps ); + m_row = UnoRuntime.queryInterface( XRow.class, m_rowSetProps ); } catch ( Exception e ) { @@ -289,4 +288,12 @@ public class RowSet implements XRowSet, XRow { return m_row.getArray(i); } + + public void dispose() + { + if ( m_rowSet == null ) + return; + XComponent rowSetComp = UnoRuntime.queryInterface( XComponent.class, m_rowSet ); + rowSetComp.dispose(); + } }; diff --git a/connectivity/qa/connectivity/tools/makefile.mk b/connectivity/qa/connectivity/tools/makefile.mk index 07490532a1..d77da7f1b9 100644..100755 --- a/connectivity/qa/connectivity/tools/makefile.mk +++ b/connectivity/qa/connectivity/tools/makefile.mk @@ -42,15 +42,11 @@ all: JARFILES = ridl.jar unoil.jar jurt.jar juh.jar java_uno.jar OOoRunnerLight.jar JAVAFILES := $(shell @$(FIND) . -name "*.java") -JAVACLASSFILES := $(foreach,i,$(JAVAFILES) $(CLASSDIR)/$(PACKAGE)/$(i:d)$(i:b).class) #----- make a jar from compiled files ------------------------------ -MAXLINELENGTH = 100000 - -JARCLASSDIRS = $(PACKAGE) -JARTARGET = $(TARGET).jar -JARCOMPRESS = TRUE +JARCLASSDIRS = $(PACKAGE) +JARTARGET = $(TARGET).jar # --- Targets ------------------------------------------------------ diff --git a/connectivity/qa/connectivity/tools/sdb/Connection.java b/connectivity/qa/connectivity/tools/sdb/Connection.java index aac120fb1e..aac120fb1e 100644..100755 --- a/connectivity/qa/connectivity/tools/sdb/Connection.java +++ b/connectivity/qa/connectivity/tools/sdb/Connection.java |