diff options
77 files changed, 5028 insertions, 6 deletions
diff --git a/Makefile.fetch b/Makefile.fetch index 20402ba1dad8..94f697ea9270 100644 --- a/Makefile.fetch +++ b/Makefile.fetch @@ -131,6 +131,7 @@ $(WORKDIR)/download: $(BUILDDIR)/config_$(gb_Side).mk $(SRCDIR)/download.lst $(S $(call fetch_Optional,GPGMEPP,GPGME_TARBALL) \ $(call fetch_Optional,GRAPHITE,GRAPHITE_TARBALL) \ $(call fetch_Optional,HARFBUZZ,HARFBUZZ_TARBALL) \ + $(call fetch_Optional,HSQLDB,HSQLDB_TARBALL) \ $(call fetch_Optional,HUNSPELL,HUNSPELL_TARBALL) \ $(call fetch_Optional,HYPHEN,HYPHEN_TARBALL) \ $(call fetch_Optional,ICU,ICU_TARBALL) \ diff --git a/Repository.mk b/Repository.mk index c57906d74c20..69bcdae4d396 100644 --- a/Repository.mk +++ b/Repository.mk @@ -604,6 +604,7 @@ $(eval $(call gb_Helper_register_libraries_for_install,PLAINLIBS_OOO,ooo, \ dict_ja \ dict_zh \ embobj \ + $(if $(ENABLE_JAVA),hsqldb) \ i18nutil \ index_data \ $(if $(and $(ENABLE_GTK3), $(filter LINUX %BSD SOLARIS,$(OS))), libreofficekitgtk) \ @@ -738,6 +739,7 @@ $(eval $(call gb_Helper_register_jars_for_install,OOO,ooo, \ $(if $(filter-out MACOSX,$(OS)),officebean) \ query \ report \ + sdbc_hsqldb \ smoketest \ table \ unoil \ diff --git a/RepositoryExternal.mk b/RepositoryExternal.mk index f6144e4fa613..aecbd71b8b43 100644 --- a/RepositoryExternal.mk +++ b/RepositoryExternal.mk @@ -2856,6 +2856,26 @@ $(call gb_LinkTarget_set_include,$(1),\ ) endef +ifneq ($(SYSTEM_HSQLDB),) + +define gb_LinkTarget__use_hsqldb + +$(call gb_LinkTarget_add_defs,$(1),\ + -DSYSTEM_HSQLDB \ + -DHSQLDB_JAR=\""file://$(HSQLDB_JAR)"\" \ +) + +endef + +else # !SYSTEM_HSQLDB + +define gb_LinkTarget__use_hsqldb + +endef + +endif # SYSTEM_HSQLDB + + ifneq ($(SYSTEM_OPENLDAP),) define gb_LinkTarget__use_openldap @@ -3612,6 +3632,33 @@ endef ### Jars ############################################################ +ifneq ($(SYSTEM_HSQLDB),) + +define gb_Jar__use_hsqldb +$(call gb_Jar_use_system_jar,$(1),$(HSQLDB_JAR)) +endef +define gb_JunitTest__use_hsqldb +$(call gb_JunitTest_use_system_jar,$(1),$(HSQLDB_JAR)) +endef + +else # !SYSTEM_HSQLDB + +ifeq ($(ENABLE_JAVA),TRUE) +$(eval $(call gb_Helper_register_jars_for_install,OOO,ooo, \ + hsqldb \ +)) +endif + +define gb_Jar__use_hsqldb +$(call gb_Jar_use_jar,$(1),hsqldb) +endef +define gb_JunitTest__use_hsqldb +$(call gb_JunitTest_use_jar,$(1),hsqldb) +endef + +endif # SYSTEM_HSQLDB + + ifeq ($(ENABLE_SCRIPTING_BEANSHELL),TRUE) ifneq ($(SYSTEM_BSH),) diff --git a/RepositoryFixes.mk b/RepositoryFixes.mk index a8536f389e0d..82c0701e59dd 100644 --- a/RepositoryFixes.mk +++ b/RepositoryFixes.mk @@ -45,6 +45,8 @@ gb_Library_FILENAMES := \ $(subst jpipe:libjpipe.dylib,jpipe:libjpipe.jnilib,$(gb_Library_FILENAMES)) gb_Library_FILENAMES := \ $(subst juh:libjuh.dylib,juh:libjuh.jnilib,$(gb_Library_FILENAMES)) +gb_Library_FILENAMES := \ + $(subst hsqldb:libhsqldb.dylib,hsqldb:libhsqldb.jnilib,$(gb_Library_FILENAMES)) endif # fixes for all the libraries that are named with too much creativity and do diff --git a/config_host.mk.in b/config_host.mk.in index 8a0722336fd7..965cdaf6887a 100644 --- a/config_host.mk.in +++ b/config_host.mk.in @@ -254,6 +254,8 @@ export HAVE_POSIX_FALLOCATE=@HAVE_POSIX_FALLOCATE@ export HELP_COMMON_ONLY=@HELP_COMMON_ONLY@ export HELP_ONLINE=@HELP_ONLINE@ export HOST_PLATFORM=@host@ +export HSQLDB_JAR=@HSQLDB_JAR@ +export HSQLDB_USE_JDBC_4_1=@HSQLDB_USE_JDBC_4_1@ export HUNSPELL_CFLAGS=$(gb_SPACE)@HUNSPELL_CFLAGS@ export HUNSPELL_LIBS=$(gb_SPACE)@HUNSPELL_LIBS@ export HYPHEN_LIB=$(gb_SPACE)@HYPHEN_LIB@ @@ -526,6 +528,7 @@ export SYSTEM_GLM=@SYSTEM_GLM@ export SYSTEM_GPGMEPP=@SYSTEM_GPGMEPP@ export SYSTEM_GRAPHITE=@SYSTEM_GRAPHITE@ export SYSTEM_HARFBUZZ=@SYSTEM_HARFBUZZ@ +export SYSTEM_HSQLDB=@SYSTEM_HSQLDB@ export SYSTEM_HUNSPELL=@SYSTEM_HUNSPELL@ export SYSTEM_HYPH=@SYSTEM_HYPH@ export SYSTEM_ICU=@SYSTEM_ICU@ diff --git a/configure.ac b/configure.ac index ce3dcd67f1d1..e4f2bb53770d 100644 --- a/configure.ac +++ b/configure.ac @@ -1739,6 +1739,15 @@ AC_ARG_WITH(system-libtommath, [Use libtommath already on system]),, [with_system_libtommath="$with_system_libs"]) +AC_ARG_WITH(system-hsqldb, + AS_HELP_STRING([--with-system-hsqldb], + [Use hsqldb already on system.])) + +AC_ARG_WITH(hsqldb-jar, + AS_HELP_STRING([--with-hsqldb-jar=JARFILE], + [Specify path to jarfile manually.]), + HSQLDB_JAR=$withval) + libo_FUZZ_ARG_ENABLE(scripting-beanshell, AS_HELP_STRING([--disable-scripting-beanshell], [Disable support for scripts in BeanShell.]), @@ -8419,6 +8428,75 @@ fi AC_SUBST(SYSTEM_MYSQL_CONNECTOR_CPP) dnl =================================================================== +dnl Check for system hsqldb +dnl =================================================================== +if test "$with_java" != "no"; then + HSQLDB_USE_JDBC_4_1= + AC_MSG_CHECKING([which hsqldb to use]) + if test "$with_system_hsqldb" = "yes"; then + AC_MSG_RESULT([external]) + SYSTEM_HSQLDB=TRUE + if test -z $HSQLDB_JAR; then + HSQLDB_JAR=/usr/share/java/hsqldb.jar + fi + if ! test -f $HSQLDB_JAR; then + AC_MSG_ERROR(hsqldb.jar not found.) + fi + AC_MSG_CHECKING([whether hsqldb is 1.8.0.x]) + export HSQLDB_JAR + if $PERL -e \ + 'use Archive::Zip; + my $file = "$ENV{'HSQLDB_JAR'}"; + my $zip = Archive::Zip->new( $file ); + my $mf = $zip->contents ( "META-INF/MANIFEST.MF" ); + if ( $mf =~ m/Specification-Version: 1.8.*/ ) + { + push @l, split(/\n/, $mf); + foreach my $line (@l) + { + if ($line =~ m/Specification-Version:/) + { + ($t, $version) = split (/:/,$line); + $version =~ s/^\s//; + ($a, $b, $c, $d) = split (/\./,$version); + if ($c == "0" && $d > "8") + { + exit 0; + } + else + { + exit 1; + } + } + } + } + else + { + exit 1; + }'; then + AC_MSG_RESULT([yes]) + else + AC_MSG_ERROR([no, you need hsqldb >= 1.8.0.9 but < 1.8.1]) + fi + else + AC_MSG_RESULT([internal]) + SYSTEM_HSQLDB= + BUILD_TYPE="$BUILD_TYPE HSQLDB" + AC_MSG_CHECKING([whether hsqldb should be built with JDBC 4.1]) + javanumver=`$JAVAINTERPRETER -version 2>&1 | $AWK -v num=true -f $SRC_ROOT/solenv/bin/getcompver.awk` + if expr "$javanumver" '>=' 000100060000 > /dev/null; then + AC_MSG_RESULT([yes]) + HSQLDB_USE_JDBC_4_1=TRUE + else + AC_MSG_RESULT([no]) + fi + fi + AC_SUBST(SYSTEM_HSQLDB) + AC_SUBST(HSQLDB_JAR) + AC_SUBST([HSQLDB_USE_JDBC_4_1]) +fi + +dnl =================================================================== dnl Check for PostgreSQL stuff dnl =================================================================== if test "x$enable_postgresql_sdbc" != "xno"; then diff --git a/connectivity/Configuration_hsqldb.mk b/connectivity/Configuration_hsqldb.mk new file mode 100644 index 000000000000..a9528cf4973c --- /dev/null +++ b/connectivity/Configuration_hsqldb.mk @@ -0,0 +1,20 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +$(eval $(call gb_Configuration_Configuration,driver_hsqldb)) + +$(eval $(call gb_Configuration_add_spool_modules,driver_hsqldb,connectivity/registry/hsqldb,\ + org/openoffice/Office/DataAccess/Drivers-hsqldb.xcu \ +)) + +$(eval $(call gb_Configuration_add_localized_datas,driver_hsqldb,connectivity/registry/hsqldb,\ + org/openoffice/Office/DataAccess/Drivers.xcu \ +)) + +# vim: set noet sw=4 ts=4: diff --git a/connectivity/Jar_sdbc_hsqldb.mk b/connectivity/Jar_sdbc_hsqldb.mk new file mode 100644 index 000000000000..20cd1f8ae044 --- /dev/null +++ b/connectivity/Jar_sdbc_hsqldb.mk @@ -0,0 +1,37 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +$(eval $(call gb_Jar_Jar,sdbc_hsqldb)) + +$(eval $(call gb_Jar_use_externals,sdbc_hsqldb,\ + hsqldb \ +)) + +$(eval $(call gb_Jar_add_manifest_classpath,sdbc_hsqldb,\ + $(if $(filter MACOSX,$(OS)),../../Frameworks/,..) \ +)) + +$(eval $(call gb_Jar_set_packageroot,sdbc_hsqldb,com)) + +$(eval $(call gb_Jar_add_packagedir,sdbc_hsqldb,org)) + +$(eval $(call gb_Jar_add_sourcefiles,sdbc_hsqldb,\ + connectivity/org/hsqldb/lib/FileSystemRuntimeException \ + connectivity/com/sun/star/sdbcx/comp/hsqldb/NativeInputStreamHelper \ + connectivity/com/sun/star/sdbcx/comp/hsqldb/NativeLibraries \ + connectivity/com/sun/star/sdbcx/comp/hsqldb/NativeOutputStreamHelper \ + connectivity/com/sun/star/sdbcx/comp/hsqldb/NativeStorageAccess \ + connectivity/com/sun/star/sdbcx/comp/hsqldb/StorageAccess \ + connectivity/com/sun/star/sdbcx/comp/hsqldb/StorageFileAccess \ + connectivity/com/sun/star/sdbcx/comp/hsqldb/StorageNativeInputStream \ + connectivity/com/sun/star/sdbcx/comp/hsqldb/StorageNativeOutputStream \ +)) + +# vim: set noet sw=4 ts=4: diff --git a/connectivity/JunitTest_complex.mk b/connectivity/JunitTest_complex.mk index 8893562589a3..78947bfc2076 100644 --- a/connectivity/JunitTest_complex.mk +++ b/connectivity/JunitTest_complex.mk @@ -22,6 +22,10 @@ $(eval $(call gb_JunitTest_use_jars,connectivity_complex,\ unoil \ )) +$(eval $(call gb_JunitTest_use_externals,connectivity_complex,\ + hsqldb \ +)) + $(eval $(call gb_JunitTest_add_classes,connectivity_complex,\ org.openoffice.test.UnoApiTest \ )) diff --git a/connectivity/Library_hsqldb.mk b/connectivity/Library_hsqldb.mk new file mode 100644 index 000000000000..0685402145bb --- /dev/null +++ b/connectivity/Library_hsqldb.mk @@ -0,0 +1,62 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +$(eval $(call gb_Library_Library,hsqldb)) + +$(eval $(call gb_Library_set_include,hsqldb,\ + -I$(SRCDIR)/connectivity/inc \ + -I$(SRCDIR)/connectivity/source/inc \ + $$(INCLUDE) \ +)) + +$(eval $(call gb_Library_use_externals,hsqldb,\ + boost_headers \ + hsqldb \ +)) + +$(eval $(call gb_Library_use_sdk_api,hsqldb)) + +$(eval $(call gb_Library_use_libraries,hsqldb,\ + comphelper \ + cppu \ + cppuhelper \ + dbtools \ + jvmfwk \ + sal \ + salhelper \ + tl \ + utl \ + i18nlangtag \ +)) + +$(eval $(call gb_Library_set_componentfile,hsqldb,connectivity/source/drivers/hsqldb/hsqldb)) + +$(eval $(call gb_Library_add_exception_objects,hsqldb,\ + connectivity/source/drivers/hsqldb/HCatalog \ + connectivity/source/drivers/hsqldb/HColumns \ + connectivity/source/drivers/hsqldb/HConnection \ + connectivity/source/drivers/hsqldb/HDriver \ + connectivity/source/drivers/hsqldb/HStorageAccess \ + connectivity/source/drivers/hsqldb/HStorageMap \ + connectivity/source/drivers/hsqldb/HTable \ + connectivity/source/drivers/hsqldb/HTables \ + connectivity/source/drivers/hsqldb/HTerminateListener \ + connectivity/source/drivers/hsqldb/HTools \ + connectivity/source/drivers/hsqldb/HUser \ + connectivity/source/drivers/hsqldb/HUsers \ + connectivity/source/drivers/hsqldb/HView \ + connectivity/source/drivers/hsqldb/HViews \ + connectivity/source/drivers/hsqldb/Hservices \ + connectivity/source/drivers/hsqldb/StorageFileAccess \ + connectivity/source/drivers/hsqldb/StorageNativeInputStream \ + connectivity/source/drivers/hsqldb/StorageNativeOutputStream \ + connectivity/source/drivers/hsqldb/accesslog \ +)) + +# vim: set noet sw=4 ts=4: diff --git a/connectivity/Module_connectivity.mk b/connectivity/Module_connectivity.mk index 4a500eb3ea3d..3ba7ecf01d41 100644 --- a/connectivity/Module_connectivity.mk +++ b/connectivity/Module_connectivity.mk @@ -40,7 +40,10 @@ $(eval $(call gb_Module_add_l10n_targets,connectivity,\ ifneq ($(ENABLE_JAVA),) $(eval $(call gb_Module_add_targets,connectivity,\ + Configuration_hsqldb \ Configuration_jdbc \ + Jar_sdbc_hsqldb \ + Library_hsqldb \ Library_jdbc \ )) endif diff --git a/connectivity/com/sun/star/sdbcx/comp/hsqldb/NativeInputStreamHelper.java b/connectivity/com/sun/star/sdbcx/comp/hsqldb/NativeInputStreamHelper.java new file mode 100644 index 000000000000..66b6f5489862 --- /dev/null +++ b/connectivity/com/sun/star/sdbcx/comp/hsqldb/NativeInputStreamHelper.java @@ -0,0 +1,62 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package com.sun.star.sdbcx.comp.hsqldb; + +public class NativeInputStreamHelper extends java.io.InputStream{ + private final String key; + private final String file; + private final StorageNativeInputStream in; + /** Creates a new instance of NativeInputStreamHelper */ + public NativeInputStreamHelper(String key,String _file) { + file = _file; + this.key = key; + in = new StorageNativeInputStream(key,file); + } + + @Override + public int read() throws java.io.IOException { + return in.read(key,file); + } + + @Override + public int read(byte[] b, int off, int len) throws java.io.IOException { + return in.read(key,file,b,off,len); + } + + @Override + public void close() throws java.io.IOException { + in.close(key,file); + } + + @Override + public long skip(long n) throws java.io.IOException { + return in.skip(key,file,n); + } + + @Override + public int available() throws java.io.IOException { + return in.available(key,file); + } + + @Override + public int read(byte[] b) throws java.io.IOException { + return in.read(key,file,b); + } + +} diff --git a/connectivity/com/sun/star/sdbcx/comp/hsqldb/NativeLibraries.java b/connectivity/com/sun/star/sdbcx/comp/hsqldb/NativeLibraries.java new file mode 100644 index 000000000000..59541556b185 --- /dev/null +++ b/connectivity/com/sun/star/sdbcx/comp/hsqldb/NativeLibraries.java @@ -0,0 +1,71 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package com.sun.star.sdbcx.comp.hsqldb; + +import java.io.File; +import java.net.URL; +import java.net.URLClassLoader; + +final class NativeLibraries { + public static void load() { + if (System.getProperty( "os.name" ).startsWith("Windows")) { + loadLibrary("msvcr71"); + loadLibrary("sal3"); + loadLibrary("dbtoolsmi"); + } + loadLibrary("hsqldb"); + } + + private static void loadLibrary(String libname) { + // At least on Mac OS X Tiger, System.loadLibrary("hsqldb2") does not + // find the hsqldb2 library one directory above sdbc_hsqldb.jar, even + // though ".." is on the jar's Class-Path; however, the alternative + // code (needing Java 1.5, which is given for Mac OS X Tiger) works + // there: + try { + System.loadLibrary(libname); + } catch (UnsatisfiedLinkError e) { + ClassLoader cl = NativeLibraries.class.getClassLoader(); + if (cl instanceof URLClassLoader) { + String sysname = System.mapLibraryName(libname); + // At least Oracle's 1.7.0_51 now maps to .dylib rather than + // .jnilib: + if (System.getProperty("os.name").startsWith("Mac") + && sysname.endsWith(".dylib")) + { + sysname + = sysname.substring( + 0, sysname.length() - "dylib".length()) + + "jnilib"; + } + URL url = ((URLClassLoader) cl).findResource(sysname); + if (url != null) { + try { + System.load(new File(url.toURI()).getAbsolutePath()); + } catch (Throwable t) { + throw new UnsatisfiedLinkError( + e.toString()+ " - " + t.toString()); + } + } + } + } + } + + private NativeLibraries() {} +} diff --git a/connectivity/com/sun/star/sdbcx/comp/hsqldb/NativeOutputStreamHelper.java b/connectivity/com/sun/star/sdbcx/comp/hsqldb/NativeOutputStreamHelper.java new file mode 100644 index 000000000000..6445f24139d4 --- /dev/null +++ b/connectivity/com/sun/star/sdbcx/comp/hsqldb/NativeOutputStreamHelper.java @@ -0,0 +1,60 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package com.sun.star.sdbcx.comp.hsqldb; + +public class NativeOutputStreamHelper extends java.io.OutputStream{ + + private final String key; + private final String file; + private final StorageNativeOutputStream out; + /** Creates a new instance of NativeOutputStreamHelper */ + public NativeOutputStreamHelper(String key,String _file) { + file = _file; + this.key = key; + out = new StorageNativeOutputStream(file,key); + } + + @Override + public void write(byte[] b, int off, int len) throws java.io.IOException{ + out.write(key,file,b, off, len); + } + + @Override + public void write(byte[] b) throws java.io.IOException{ + out.write(key,file,b); + } + + @Override + public void close() throws java.io.IOException{ + out.close(key,file); + } + + @Override + public void write(int b) throws java.io.IOException{ + out.write(key,file,b); + } + + @Override + public void flush() throws java.io.IOException{ + out.flush(key,file); + } + + public void sync() throws java.io.IOException{ + out.sync(key,file); + } +} diff --git a/connectivity/com/sun/star/sdbcx/comp/hsqldb/NativeStorageAccess.java b/connectivity/com/sun/star/sdbcx/comp/hsqldb/NativeStorageAccess.java new file mode 100644 index 000000000000..5a9bc8bb6c4c --- /dev/null +++ b/connectivity/com/sun/star/sdbcx/comp/hsqldb/NativeStorageAccess.java @@ -0,0 +1,62 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package com.sun.star.sdbcx.comp.hsqldb; + +public class NativeStorageAccess { + static { NativeLibraries.load(); } + + public static final int READ = 1; + private static final int SEEKABLE = 2; + private static final int SEEKABLEREAD = 3; + public static final int WRITE = 4; + private static final int READWRITE = 7; + public static final int TRUNCATE = 8; + + /** Creates a new instance of StorageAccess */ + public NativeStorageAccess(String name,String _mode,Object key) throws java.io.IOException{ + try { + int mode = NativeStorageAccess.SEEKABLEREAD; + if ( _mode.equals("rw") ) + mode = NativeStorageAccess.READWRITE | NativeStorageAccess.SEEKABLE; + + openStream(name, (String)key, mode); + } catch(Exception ex1){ + java.io.IOException ex2 = new java.io.IOException(); + ex2.initCause(ex1); + throw ex2; + } + } + private native void openStream(String name,String key, int mode); + public native void close(String name,String key) throws java.io.IOException; + + public native long getFilePointer(String name,String key) throws java.io.IOException; + + public native long length(String name,String key) throws java.io.IOException; + + public native int read(String name,String key) throws java.io.IOException; + + public native int read(String name,String key,byte[] b, int off, int len) throws java.io.IOException; + + + + public native void seek(String name,String key,long position) throws java.io.IOException; + + public native void write(String name,String key,byte[] b, int offset, int length) throws java.io.IOException; + + +} diff --git a/connectivity/com/sun/star/sdbcx/comp/hsqldb/StorageAccess.java b/connectivity/com/sun/star/sdbcx/comp/hsqldb/StorageAccess.java new file mode 100644 index 000000000000..6a53d110e661 --- /dev/null +++ b/connectivity/com/sun/star/sdbcx/comp/hsqldb/StorageAccess.java @@ -0,0 +1,126 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package com.sun.star.sdbcx.comp.hsqldb; + +@SuppressWarnings("ucd") +public class StorageAccess implements org.hsqldb.lib.Storage { + String key; + String name; + boolean readonly; + NativeStorageAccess access; + /** Creates a new instance of StorageAccess */ + public StorageAccess(String name,Boolean readonly,Object key) throws java.io.IOException{ + this.key = (String)key; + this.name = name; + this.readonly = readonly.booleanValue(); + try { + access = new NativeStorageAccess(name, + this.readonly ? "r" : "rw" + ,key); + } catch(Exception ex1){ + java.io.IOException ex2 = new java.io.IOException(); + ex2.initCause(ex1); + throw ex2; + } + } + public void close() throws java.io.IOException{ + access.close(name,key); + } + + public long getFilePointer() throws java.io.IOException{ + return access.getFilePointer(name,key); + } + + public long length() throws java.io.IOException{ + return access.length(name,key); + } + + public int read() throws java.io.IOException{ + return access.read(name,key); + } + + public void read(byte[] b, int off, int len) throws java.io.IOException{ + access.read(name,key,b,off,len); + } + + // based on the same code that reads an int from the .data file in HSQLDB + public int readInt() throws java.io.IOException{ + byte [] tmp = new byte [4]; + + int count = access.read(name,key,tmp,0, 4); + + if (count != 4){ + throw new java.io.IOException(); + } + + count = 0; + int ch0 = tmp[count++] & 0xff; + int ch1 = tmp[count++] & 0xff; + int ch2 = tmp[count++] & 0xff; + int ch3 = tmp[count] & 0xff; + + return ((ch0 << 24) + (ch1 << 16) + (ch2 << 8) + (ch3)); + } + + public void seek(long position) throws java.io.IOException{ + access.seek(name,key,position); + } + + public void write(byte[] b, int offset, int length) throws java.io.IOException{ + access.write(name,key,b,offset,length); + } + + public void writeInt(int v) throws java.io.IOException{ + byte [] oneByte = new byte [4]; + oneByte[0] = (byte) ((v >>> 24) & 0xFF); + oneByte[1] = (byte) ((v >>> 16) & 0xFF); + oneByte[2] = (byte) ((v >>> 8) & 0xFF); + oneByte[3] = (byte) ((v >>> 0) & 0xFF); + + write(oneByte,0,4); + } + + public boolean isReadOnly() { + return readonly; + } + + @SuppressWarnings("cast") + public long readLong() throws java.io.IOException { + return (((long) readInt()) << 32) + (((long) readInt()) & 0xFFFFFFFFL); + } + + public boolean wasNio() { + return false; + } + + public void writeLong(long v) throws java.io.IOException { + byte [] oneByte = new byte [8]; + + oneByte[0] = (byte) ((v >>> 56) & 0xFF); + oneByte[1] = (byte) ((v >>> 48) & 0xFF); + oneByte[2] = (byte) ((v >>> 40) & 0xFF); + oneByte[3] = (byte) ((v >>> 32) & 0xFF); + oneByte[4] = (byte) ((v >>> 24) & 0xFF); + oneByte[5] = (byte) ((v >>> 16) & 0xFF); + oneByte[6] = (byte) ((v >>> 8) & 0xFF); + oneByte[7] = (byte) ((v >>> 0) & 0xFF); + + write(oneByte,0,8); + } +} diff --git a/connectivity/com/sun/star/sdbcx/comp/hsqldb/StorageFileAccess.java b/connectivity/com/sun/star/sdbcx/comp/hsqldb/StorageFileAccess.java new file mode 100644 index 000000000000..0dd640c4ec57 --- /dev/null +++ b/connectivity/com/sun/star/sdbcx/comp/hsqldb/StorageFileAccess.java @@ -0,0 +1,90 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package com.sun.star.sdbcx.comp.hsqldb; + +import org.hsqldb.lib.FileAccess; +import org.hsqldb.lib.FileSystemRuntimeException; + +@SuppressWarnings("ucd") +public class StorageFileAccess implements org.hsqldb.lib.FileAccess{ + static { NativeLibraries.load(); } + + String ds_name; + String key; + /** Creates a new instance of StorageFileAccess */ + public StorageFileAccess(Object key) throws java.lang.Exception{ + this.key = (String)key; + } + + public void createParentDirs(String filename) { + } + + public boolean isStreamElement(String elementName) { + return isStreamElement(key,elementName); + } + + public java.io.InputStream openInputStreamElement(String streamName) throws java.io.IOException { + return new NativeInputStreamHelper(key,streamName); + } + + public java.io.OutputStream openOutputStreamElement(String streamName) throws java.io.IOException { + return new NativeOutputStreamHelper(key,streamName); + } + + public void removeElement(String filename) throws java.util.NoSuchElementException { + try { + if ( isStreamElement(key,filename) ) + removeElement(key,filename); + } catch (java.io.IOException e) { + throw new FileSystemRuntimeException( e ); + } + } + + public void renameElement(String oldName, String newName) throws java.util.NoSuchElementException { + try { + if ( isStreamElement(key,oldName) ){ + removeElement(key,newName); + renameElement(key,oldName, newName); + } + } catch (java.io.IOException e) { + throw new FileSystemRuntimeException( e ); + } + } + + private static class FileSync implements FileAccess.FileSync + { + private final NativeOutputStreamHelper os; + private FileSync(NativeOutputStreamHelper _os) + { + os = _os; + } + public void sync() throws java.io.IOException + { + os.sync(); + } + } + + public FileAccess.FileSync getFileSync(java.io.OutputStream os) throws java.io.IOException + { + return new FileSync((NativeOutputStreamHelper)os); + } + + static native boolean isStreamElement(String key,String elementName); + static native void removeElement(String key,String filename) throws java.util.NoSuchElementException, java.io.IOException; + static native void renameElement(String key,String oldName, String newName) throws java.util.NoSuchElementException, java.io.IOException; +} diff --git a/connectivity/com/sun/star/sdbcx/comp/hsqldb/StorageNativeInputStream.java b/connectivity/com/sun/star/sdbcx/comp/hsqldb/StorageNativeInputStream.java new file mode 100644 index 000000000000..cf147c9b5005 --- /dev/null +++ b/connectivity/com/sun/star/sdbcx/comp/hsqldb/StorageNativeInputStream.java @@ -0,0 +1,34 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package com.sun.star.sdbcx.comp.hsqldb; + +public class StorageNativeInputStream { + static { NativeLibraries.load(); } + + /** Creates a new instance of StorageNativeInputStream */ + public StorageNativeInputStream(String key,String _file) { + openStream(key,_file, NativeStorageAccess.READ); + } + private native void openStream(String key,String name, int mode); + public native int read(String key,String name) throws java.io.IOException; + public native int read(String key,String name,byte[] b, int off, int len) throws java.io.IOException; + public native void close(String key,String name) throws java.io.IOException; + public native long skip(String key,String name,long n) throws java.io.IOException; + public native int available(String key,String name) throws java.io.IOException; + public native int read(String key,String name,byte[] b) throws java.io.IOException; +} diff --git a/connectivity/com/sun/star/sdbcx/comp/hsqldb/StorageNativeOutputStream.java b/connectivity/com/sun/star/sdbcx/comp/hsqldb/StorageNativeOutputStream.java new file mode 100644 index 000000000000..8cc6cb07d353 --- /dev/null +++ b/connectivity/com/sun/star/sdbcx/comp/hsqldb/StorageNativeOutputStream.java @@ -0,0 +1,145 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package com.sun.star.sdbcx.comp.hsqldb; + +public class StorageNativeOutputStream { + static { NativeLibraries.load(); } + + /** Creates a new instance of StorageNativeOutputStream */ + public StorageNativeOutputStream(String _name, Object key) { + openStream(_name, (String)key, NativeStorageAccess.WRITE | NativeStorageAccess.TRUNCATE); + } + + private native void openStream(String name,String key, int mode); + /** + * Writes <code>len</code> bytes from the specified byte array + * starting at offset <code>off</code> to this output stream. + * The general contract for <code>write(b, off, len)</code> is that + * some of the bytes in the array <code>b</code> are written to the + * output stream in order; element <code>b[off]</code> is the first + * byte written and <code>b[off+len-1]</code> is the last byte written + * by this operation. + * <p> + * The <code>write</code> method of <code>OutputStream</code> calls + * the write method of one argument on each of the bytes to be + * written out. Subclasses are encouraged to override this method and + * provide a more efficient implementation. + * <p> + * If <code>b</code> is <code>null</code>, a + * <code>NullPointerException</code> is thrown. + * <p> + * If <code>off</code> is negative, or <code>len</code> is negative, or + * <code>off+len</code> is greater than the length of the array + * <code>b</code>, then an <tt>IndexOutOfBoundsException</tt> is thrown. + * @param key The name of the data source. + * @param _file The name of the file to write to. + * @param b the data. + * @param off the start offset in the data. + * @param len the number of bytes to write. + * @exception java.io.IOException if an I/O error occurs. In particular, + * an <code>IOException</code> is thrown if the output + * stream is closed. + */ + public native void write(String key,String _file,byte[] b, int off, int len) throws java.io.IOException; + + /** + * Writes <code>b.length</code> bytes from the specified byte array + * to this output stream. The general contract for <code>write(b)</code> + * is that it should have exactly the same effect as the call + * <code>write(b, 0, b.length)</code>. + * + * @param b the data. + * @exception java.io.IOException if an I/O error occurs. + * @see java.io.OutputStream#write(byte[], int, int) + */ + public native void write(String key,String _file,byte[] b) throws java.io.IOException; + + /** + * Closes this output stream and releases any system resources + * associated with this stream. The general contract of <code>close</code> + * is that it closes the output stream. A closed stream cannot perform + * output operations and cannot be reopened. + * <p> + * The <code>close</code> method of <code>OutputStream</code> does nothing. + * @param key The name of the data source. + * @param _file The name of the file to write to. + * + * @exception java.io.IOException if an I/O error occurs. + */ + public native void close(String key,String _file) throws java.io.IOException; + + /** + * Writes the specified byte to this output stream. The general + * contract for <code>write</code> is that one byte is written + * to the output stream. The byte to be written is the eight + * low-order bits of the argument <code>b</code>. The 24 + * high-order bits of <code>b</code> are ignored. + * <p> + * Subclasses of <code>OutputStream</code> must provide an + * implementation for this method. + * + * @param key The name of the data source. + * @param _file The name of the file to write to. + * @param b the <code>byte</code>. + * @exception java.io.IOException if an I/O error occurs. In particular, + * an <code>IOException</code> may be thrown if the + * output stream has been closed. + */ + public native void write(String key,String _file,int b) throws java.io.IOException; + + /** + * Flushes this output stream and forces any buffered output bytes + * to be written out. The general contract of <code>flush</code> is + * that calling it is an indication that, if any bytes previously + * written have been buffered by the implementation of the output + * stream, such bytes should immediately be written to their + * intended destination. + * <p> + * The <code>flush</code> method of <code>OutputStream</code> does nothing. + * @param key The name of the data source. + * @param _file The name of the file to write to. + * + * @exception java.io.IOException if an I/O error occurs. + */ + public native void flush(String key,String _file) throws java.io.IOException; + + /** + * Force all system buffers to synchronize with the underlying + * device. This method returns after all modified data and + * attributes have been written to the relevant device(s). + * + * sync is meant to be used by code that requires physical + * storage (such as a file) to be in a known state For + * example, a class that provided a simple transaction facility + * might use sync to ensure that all changes to a file caused + * by a given transaction were recorded on a storage medium. + * + * sync only affects buffers downstream. If + * any in-memory buffering is being done by the application (for + * example, by a BufferedOutputStream object), those buffers must + * be flushed (for example, by invoking + * OutputStream.flush) before that data will be affected by sync. + * + * @exception java.io.IOException + * Thrown when the buffers cannot be flushed, + * or because the system cannot guarantee that all the + * buffers have been synchronized with physical media. + */ + public native void sync(String key,String _file) throws java.io.IOException; + +} diff --git a/connectivity/registry/hsqldb/org/openoffice/Office/DataAccess/Drivers.xcu b/connectivity/registry/hsqldb/org/openoffice/Office/DataAccess/Drivers.xcu new file mode 100644 index 000000000000..59dc5b86ea21 --- /dev/null +++ b/connectivity/registry/hsqldb/org/openoffice/Office/DataAccess/Drivers.xcu @@ -0,0 +1,74 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . +--> +<oor:component-data oor:name="Drivers" oor:package="org.openoffice.Office.DataAccess" xmlns:install="http://openoffice.org/2004/installation" xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema"> + <node oor:name="Installed" install:module="hsqldb"> + <node oor:name="sdbc:embedded:hsqldb" oor:op="replace"> + <prop oor:name="Driver"> + <value>com.sun.star.sdbcx.comp.hsqldb.Driver</value> + </prop> + <prop oor:name="DriverTypeDisplayName" oor:type="xs:string"> + <value xml:lang="en-US">HSQLDB Embedded</value> + </prop> + <node oor:name="Features"> + <node oor:name="UseDOSLineEnds" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:boolean"> + <value>true</value> + </prop> + </node> + <node oor:name="FormsCheckRequiredFields" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:boolean"> + <value>true</value> + </prop> + </node> + <node oor:name="EscapeDateTime" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:boolean"> + <value>true</value> + </prop> + </node> + <node oor:name="AddIndexAppendix" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:boolean"> + <value>false</value> + </prop> + </node> + <node oor:name="UseKeywordAsBeforeAlias" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:boolean"> + <value>true</value> + </prop> + </node> + </node> + <node oor:name="MetaData"> + <node oor:name="SupportsTableCreation" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:boolean"> + <value>true</value> + </prop> + </node> + <node oor:name="UseJava" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:boolean"> + <value>true</value> + </prop> + </node> + <node oor:name="AutoIncrementIsPrimaryKey" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:boolean"> + <value>true</value> + </prop> + </node> + </node> + </node> + </node> +</oor:component-data> diff --git a/connectivity/source/commontools/DriversConfig.cxx b/connectivity/source/commontools/DriversConfig.cxx index 29f5b22de880..a6b78b0d0330 100644 --- a/connectivity/source/commontools/DriversConfig.cxx +++ b/connectivity/source/commontools/DriversConfig.cxx @@ -76,7 +76,6 @@ namespace OUString sDriverTypeDisplayName; aURLPatternNode.getNodeValue("DriverTypeDisplayName") >>= sDriverTypeDisplayName; - OSL_ENSURE(!sDriverTypeDisplayName.isEmpty(),"No valid DriverTypeDisplayName property!"); if ( !sDriverTypeDisplayName.isEmpty() ) _rInstalledDriver.sDriverTypeDisplayName = sDriverTypeDisplayName; @@ -113,7 +112,9 @@ const TInstalledDrivers& DriversConfigImpl::getInstalledDrivers(const uno::Refer { TInstalledDriver aInstalledDriver; lcl_readURLPatternNode(m_aInstalled,*pPatternIter,aInstalledDriver); - if ( !aInstalledDriver.sDriverFactory.isEmpty() ) + if ( !aInstalledDriver.sDriverFactory.isEmpty() && + ( aMiscOptions.IsExperimentalMode() || + aInstalledDriver.sDriverFactory != "com.sun.star.comp.sdbc.firebird.Driver" )) m_aDrivers.emplace(*pPatternIter,aInstalledDriver); } } // if ( m_aInstalled.isValid() ) diff --git a/connectivity/source/drivers/hsqldb/HCatalog.cxx b/connectivity/source/drivers/hsqldb/HCatalog.cxx new file mode 100644 index 000000000000..9824ead35dc8 --- /dev/null +++ b/connectivity/source/drivers/hsqldb/HCatalog.cxx @@ -0,0 +1,150 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <hsqldb/HCatalog.hxx> +#include <hsqldb/HUsers.hxx> +#include <hsqldb/HTables.hxx> +#include <hsqldb/HViews.hxx> +#include <com/sun/star/sdbc/SQLException.hpp> +#include <com/sun/star/sdbc/XRow.hpp> +#include <com/sun/star/sdbc/XResultSet.hpp> +#include <comphelper/types.hxx> + + +using namespace connectivity; +using namespace connectivity::hsqldb; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::sdbcx; +using namespace ::com::sun::star::sdbc; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::lang; + +OHCatalog::OHCatalog(const Reference< XConnection >& _xConnection) : sdbcx::OCatalog(_xConnection) + ,m_xConnection(_xConnection) +{ +} + +void OHCatalog::refreshObjects(const Sequence< OUString >& _sKindOfObject,::std::vector< OUString>& _rNames) +{ + Reference< XResultSet > xResult = m_xMetaData->getTables(Any(), + "%", + "%", + _sKindOfObject); + fillNames(xResult,_rNames); +} + +void OHCatalog::refreshTables() +{ + ::std::vector< OUString> aVector; + + Sequence< OUString > sTableTypes(2); + sTableTypes[0] = "VIEW"; + sTableTypes[1] = "TABLE"; + + refreshObjects(sTableTypes,aVector); + + if ( m_pTables ) + m_pTables->reFill(aVector); + else + m_pTables.reset( new OTables(m_xMetaData,*this,m_aMutex,aVector) ); +} + +void OHCatalog::refreshViews() +{ + Sequence< OUString > aTypes { "VIEW" }; + + bool bSupportsViews = false; + try + { + Reference<XResultSet> xRes = m_xMetaData->getTableTypes(); + Reference<XRow> xRow(xRes,UNO_QUERY); + while ( xRow.is() && xRes->next() ) + { + if ( (bSupportsViews = xRow->getString(1).equalsIgnoreAsciiCase(aTypes[0])) ) + { + break; + } + } + } + catch(const SQLException&) + { + } + + ::std::vector< OUString> aVector; + if ( bSupportsViews ) + refreshObjects(aTypes,aVector); + + if ( m_pViews ) + m_pViews->reFill(aVector); + else + m_pViews.reset( new HViews( m_xConnection, *this, m_aMutex, aVector ) ); +} + +void OHCatalog::refreshGroups() +{ +} + +void OHCatalog::refreshUsers() +{ + ::std::vector< OUString> aVector; + Reference< XStatement > xStmt = m_xConnection->createStatement( ); + Reference< XResultSet > xResult = xStmt->executeQuery("select User from hsqldb.user group by User"); + if ( xResult.is() ) + { + Reference< XRow > xRow(xResult,UNO_QUERY); + while( xResult->next() ) + aVector.push_back(xRow->getString(1)); + ::comphelper::disposeComponent(xResult); + } + ::comphelper::disposeComponent(xStmt); + + if(m_pUsers) + m_pUsers->reFill(aVector); + else + m_pUsers.reset( new OUsers(*this,m_aMutex,aVector,m_xConnection,this) ); +} + +Any SAL_CALL OHCatalog::queryInterface( const Type & rType ) +{ + if ( rType == cppu::UnoType<XGroupsSupplier>::get()) + return Any(); + + return OCatalog::queryInterface(rType); +} + +Sequence< Type > SAL_CALL OHCatalog::getTypes( ) +{ + Sequence< Type > aTypes = OCatalog::getTypes(); + std::vector<Type> aOwnTypes; + aOwnTypes.reserve(aTypes.getLength()); + const Type* pBegin = aTypes.getConstArray(); + const Type* pEnd = pBegin + aTypes.getLength(); + for(;pBegin != pEnd;++pBegin) + { + if ( !(*pBegin == cppu::UnoType<XGroupsSupplier>::get())) + { + aOwnTypes.push_back(*pBegin); + } + } + return Sequence< Type >(aOwnTypes.data(), aOwnTypes.size()); +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/hsqldb/HColumns.cxx b/connectivity/source/drivers/hsqldb/HColumns.cxx new file mode 100644 index 000000000000..da9b8bbd442b --- /dev/null +++ b/connectivity/source/drivers/hsqldb/HColumns.cxx @@ -0,0 +1,78 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <hsqldb/HColumns.hxx> +#include <TConnection.hxx> + + +using namespace ::comphelper; +using namespace connectivity::hsqldb; +using namespace connectivity::sdbcx; +using namespace connectivity; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::sdbcx; +using namespace ::com::sun::star::sdbc; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::lang; + +OHSQLColumns::OHSQLColumns( ::cppu::OWeakObject& _rParent + ,::osl::Mutex& _rMutex + ,const ::std::vector< OUString> &_rVector + ) : OColumnsHelper(_rParent,true/*_bCase*/,_rMutex,_rVector,true/*_bUseHardRef*/) +{ +} + +Reference< XPropertySet > OHSQLColumns::createDescriptor() +{ + return new OHSQLColumn; +} + + +OHSQLColumn::OHSQLColumn() + : connectivity::sdbcx::OColumn( true/*_bCase*/ ) +{ + construct(); +} + +void OHSQLColumn::construct() +{ + m_sAutoIncrement = "IDENTITY"; + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_AUTOINCREMENTCREATION),PROPERTY_ID_AUTOINCREMENTCREATION,0,&m_sAutoIncrement, cppu::UnoType<decltype(m_sAutoIncrement)>::get()); +} + +::cppu::IPropertyArrayHelper* OHSQLColumn::createArrayHelper( sal_Int32 /*_nId*/ ) const +{ + return doCreateArrayHelper(); +} + +::cppu::IPropertyArrayHelper & SAL_CALL OHSQLColumn::getInfoHelper() +{ + return *OHSQLColumn_PROP::getArrayHelper(isNew() ? 1 : 0); +} + +Sequence< OUString > SAL_CALL OHSQLColumn::getSupportedServiceNames( ) +{ + Sequence< OUString > aSupported { "com.sun.star.sdbcx.Column" }; + + return aSupported; +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/hsqldb/HStorageMap.cxx b/connectivity/source/drivers/hsqldb/HStorageMap.cxx new file mode 100644 index 000000000000..ff5df7b01fe3 --- /dev/null +++ b/connectivity/source/drivers/hsqldb/HStorageMap.cxx @@ -0,0 +1,367 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <hsqldb/HStorageMap.hxx> +#include <comphelper/types.hxx> +#include <com/sun/star/embed/XTransactionBroadcaster.hpp> +#include <com/sun/star/embed/XTransactedObject.hpp> +#include <com/sun/star/embed/ElementModes.hpp> +#include <com/sun/star/lang/DisposedException.hpp> +#include <osl/diagnose.h> +#include <osl/thread.h> +#include <uno/mapping.hxx> +#include <algorithm> + +namespace connectivity +{ + + namespace hsqldb + { + + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::lang; + using namespace ::com::sun::star::embed; + using namespace ::com::sun::star::io; + + StreamHelper::StreamHelper(const Reference< XStream>& _xStream) + : m_xStream(_xStream) + { + } + + StreamHelper::~StreamHelper() + { + try + { + m_xStream.clear(); + m_xSeek.clear(); + if ( m_xInputStream.is() ) + { + m_xInputStream->closeInput(); + m_xInputStream.clear(); + } + // this is done implicitly by the closing of the input stream + else if ( m_xOutputStream.is() ) + { + m_xOutputStream->closeOutput(); + try + { + ::comphelper::disposeComponent(m_xOutputStream); + } + catch(const DisposedException&) + { + } + catch(const Exception&) + { + OSL_FAIL("Could not dispose OutputStream"); + } + m_xOutputStream.clear(); + } + } + catch(const Exception&) + { + OSL_FAIL("Exception caught!"); + } + } + + Reference< XInputStream> const & StreamHelper::getInputStream() + { + if ( !m_xInputStream.is() ) + m_xInputStream = m_xStream->getInputStream(); + return m_xInputStream; + } + + Reference< XOutputStream> const & StreamHelper::getOutputStream() + { + if ( !m_xOutputStream.is() ) + m_xOutputStream = m_xStream->getOutputStream(); + return m_xOutputStream; + } + + Reference< XSeekable> const & StreamHelper::getSeek() + { + if ( !m_xSeek.is() ) + m_xSeek.set(m_xStream,UNO_QUERY); + return m_xSeek; + } + + css::uno::Reference<css::embed::XStorage> StorageData::mapStorage() + const + { + css::uno::Environment env(css::uno::Environment::getCurrent()); + if (!(env.is() && storageEnvironment.is())) { + throw css::uno::RuntimeException("cannot get environments"); + } + if (env.get() == storageEnvironment.get()) { + return storage; + } else { + css::uno::Mapping map(storageEnvironment, env); + if (!map.is()) { + throw css::uno::RuntimeException("cannot get mapping"); + } + css::uno::Reference<css::embed::XStorage> mapped; + map.mapInterface( + reinterpret_cast<void **>(&mapped), storage.get(), + cppu::UnoType<css::embed::XStorage>::get()); + return mapped; + } + } + + TStorages& lcl_getStorageMap() + { + static TStorages s_aMap; + return s_aMap; + } + + OUString lcl_getNextCount() + { + static sal_Int32 s_nCount = 0; + return OUString::number(s_nCount++); + } + + OUString StorageContainer::removeURLPrefix(const OUString& _sURL,const OUString& _sFileURL) + { + return _sURL.copy(_sFileURL.getLength()+1); + } + + OUString StorageContainer::removeOldURLPrefix(const OUString& _sURL) + { + OUString sRet = _sURL; +#if defined(_WIN32) + sal_Int32 nIndex = sRet.lastIndexOf('\\'); +#else + sal_Int32 nIndex = sRet.lastIndexOf('/'); +#endif + if ( nIndex != -1 ) + { + sRet = _sURL.copy(nIndex+1); + } + return sRet; + + } + /*****************************************************************************/ + /* convert jstring to rtl_uString */ + + OUString StorageContainer::jstring2ustring(JNIEnv * env, jstring jstr) + { + if (env->ExceptionCheck()) + { + env->ExceptionClear(); + OSL_FAIL("ExceptionClear"); + } + OUString aStr; + if ( jstr ) + { + jboolean bCopy(true); + const jchar* pChar = env->GetStringChars(jstr,&bCopy); + jsize len = env->GetStringLength(jstr); + aStr = OUString( + reinterpret_cast<sal_Unicode const *>(pChar), len); + + if(bCopy) + env->ReleaseStringChars(jstr,pChar); + } + + if (env->ExceptionCheck()) + { + env->ExceptionClear(); + OSL_FAIL("ExceptionClear"); + } + return aStr; + } + + + OUString StorageContainer::registerStorage(const Reference< XStorage>& _xStorage,const OUString& _sURL) + { + OSL_ENSURE(_xStorage.is(),"Storage is NULL!"); + TStorages& rMap = lcl_getStorageMap(); + // check if the storage is already in our map + TStorages::const_iterator aFind = std::find_if(rMap.begin(),rMap.end(), + [&_xStorage] (const TStorages::value_type& storage) { + return storage.second.mapStorage() == _xStorage; + }); + + if ( aFind == rMap.end() ) + { + aFind = rMap.insert(TStorages::value_type(lcl_getNextCount(), {_xStorage, css::uno::Environment::getCurrent(), _sURL, TStreamMap()})).first; + } + + return aFind->first; + } + + TStorages::mapped_type StorageContainer::getRegisteredStorage(const OUString& _sKey) + { + TStorages::mapped_type aRet; + TStorages& rMap = lcl_getStorageMap(); + TStorages::const_iterator aFind = rMap.find(_sKey); + OSL_ENSURE(aFind != rMap.end(),"Storage could not be found in list!"); + if ( aFind != rMap.end() ) + aRet = aFind->second; + + return aRet; + } + + OUString StorageContainer::getRegisteredKey(const Reference< XStorage>& _xStorage) + { + OUString sKey; + OSL_ENSURE(_xStorage.is(),"Storage is NULL!"); + TStorages& rMap = lcl_getStorageMap(); + // check if the storage is already in our map + TStorages::const_iterator aFind = std::find_if(rMap.begin(),rMap.end(), + [&_xStorage] (const TStorages::value_type& storage) { + return storage.second.mapStorage() == _xStorage; + }); + + if ( aFind != rMap.end() ) + sKey = aFind->first; + return sKey; + } + + void StorageContainer::revokeStorage(const OUString& _sKey,const Reference<XTransactionListener>& _xListener) + { + TStorages& rMap = lcl_getStorageMap(); + TStorages::iterator aFind = rMap.find(_sKey); + if ( aFind != rMap.end() ) + { + try + { + if ( _xListener.is() ) + { + Reference<XTransactionBroadcaster> xBroad(aFind->second.mapStorage(),UNO_QUERY); + if ( xBroad.is() ) + xBroad->removeTransactionListener(_xListener); + Reference<XTransactedObject> xTrans(aFind->second.mapStorage(),UNO_QUERY); + if ( xTrans.is() ) + xTrans->commit(); + } + } + catch(const Exception&) + { + } + rMap.erase(aFind); + } + } + + TStreamMap::mapped_type StorageContainer::registerStream(JNIEnv * env,jstring name, jstring key,sal_Int32 _nMode) + { + TStreamMap::mapped_type pHelper; + TStorages& rMap = lcl_getStorageMap(); + OUString sKey = jstring2ustring(env,key); + TStorages::iterator aFind = rMap.find(sKey); + OSL_ENSURE(aFind != rMap.end(),"Storage could not be found in list!"); + if ( aFind != rMap.end() ) + { + TStorages::mapped_type aStoragePair = StorageContainer::getRegisteredStorage(sKey); + auto storage = aStoragePair.mapStorage(); + OSL_ENSURE(storage.is(),"No Storage available!"); + if ( storage.is() ) + { + OUString sOrgName = StorageContainer::jstring2ustring(env,name); + OUString sName = removeURLPrefix(sOrgName,aStoragePair.url); + TStreamMap::iterator aStreamFind = aFind->second.streams.find(sName); + OSL_ENSURE( aStreamFind == aFind->second.streams.end(),"A Stream was already registered for this object!"); + if ( aStreamFind != aFind->second.streams.end() ) + { + pHelper = aStreamFind->second; + } + else + { + try + { + try + { + pHelper.reset(new StreamHelper(storage->openStreamElement(sName,_nMode))); + } + catch(const Exception&) + { + OUString sStrippedName = removeOldURLPrefix(sOrgName); + + if ( (_nMode & ElementModes::WRITE) != ElementModes::WRITE ) + { + bool bIsStream = true; + try + { + bIsStream = storage->isStreamElement(sStrippedName); + } + catch(const Exception&) + { + bIsStream = false; + } + if ( !bIsStream ) + return pHelper; // readonly file without data stream + } + pHelper.reset( new StreamHelper(storage->openStreamElement( sStrippedName, _nMode ) ) ); + } + aFind->second.streams.emplace(sName,pHelper); + } + catch(const Exception& e) + { + SAL_WARN( "connectivity.hsqldb", "[HSQLDB-SDBC] caught an exception while opening a stream\n" + "Name: " << sName + << "\nMode: 0x" << ( _nMode < 16 ? "0" : "") + << std::hex << _nMode ); + StorageContainer::throwJavaException(e,env); + } + } + } + } + return pHelper; + } + + void StorageContainer::revokeStream( JNIEnv * env,jstring name, jstring key) + { + TStorages& rMap = lcl_getStorageMap(); + TStorages::iterator aFind = rMap.find(jstring2ustring(env,key)); + OSL_ENSURE(aFind != rMap.end(),"Storage could not be found in list!"); + if ( aFind != rMap.end() ) + aFind->second.streams.erase(removeURLPrefix(jstring2ustring(env,name),aFind->second.url)); + } + + TStreamMap::mapped_type StorageContainer::getRegisteredStream( JNIEnv * env,jstring name, jstring key) + { + TStreamMap::mapped_type pRet; + TStorages& rMap = lcl_getStorageMap(); + TStorages::const_iterator aFind = rMap.find(jstring2ustring(env,key)); + OSL_ENSURE(aFind != rMap.end(),"Storage could not be found in list!"); + if ( aFind != rMap.end() ) + { + TStreamMap::const_iterator aStreamFind = aFind->second.streams.find(removeURLPrefix(jstring2ustring(env,name),aFind->second.url)); + if ( aStreamFind != aFind->second.streams.end() ) + pRet = aStreamFind->second; + } + + return pRet; + } + + void StorageContainer::throwJavaException(const Exception& _aException,JNIEnv * env) + { + if (env->ExceptionCheck()) + env->ExceptionClear(); + SAL_WARN("connectivity.hsqldb", "forwarding Exception: " << _aException ); + OString cstr( OUStringToOString(_aException.Message, RTL_TEXTENCODING_JAVA_UTF8 ) ); + env->ThrowNew(env->FindClass("java/io/IOException"), cstr.getStr()); + } + + } // namespace hsqldb + + +} +// namespace connectivity + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/hsqldb/HTables.cxx b/connectivity/source/drivers/hsqldb/HTables.cxx new file mode 100644 index 000000000000..bde5866b9d92 --- /dev/null +++ b/connectivity/source/drivers/hsqldb/HTables.cxx @@ -0,0 +1,186 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <hsqldb/HTables.hxx> +#include <hsqldb/HViews.hxx> +#include <hsqldb/HTable.hxx> +#include <com/sun/star/sdbc/XRow.hpp> +#include <com/sun/star/sdbc/XResultSet.hpp> +#include <com/sun/star/sdbc/ColumnValue.hpp> +#include <com/sun/star/sdbcx/Privilege.hpp> +#include <com/sun/star/sdbc/KeyRule.hpp> +#include <com/sun/star/sdbcx/KeyType.hpp> +#include <hsqldb/HCatalog.hxx> +#include <comphelper/extract.hxx> +#include <connectivity/dbtools.hxx> +#include <connectivity/dbexception.hxx> +#include <cppuhelper/interfacecontainer.h> +#include <comphelper/types.hxx> +#include <TConnection.hxx> + +using namespace ::comphelper; +using namespace connectivity; +using namespace ::cppu; +using namespace connectivity::hsqldb; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::sdbcx; +using namespace ::com::sun::star::sdbc; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::lang; +using namespace dbtools; + +sdbcx::ObjectType OTables::createObject(const OUString& _rName) +{ + OUString sCatalog,sSchema,sTable; + ::dbtools::qualifiedNameComponents(m_xMetaData,_rName,sCatalog,sSchema,sTable,::dbtools::EComposeRule::InDataManipulation); + + Sequence< OUString > sTableTypes(3); + sTableTypes[0] = "VIEW"; + sTableTypes[1] = "TABLE"; + sTableTypes[2] = "%"; // just to be sure to include anything else .... + + Any aCatalog; + if ( !sCatalog.isEmpty() ) + aCatalog <<= sCatalog; + Reference< XResultSet > xResult = m_xMetaData->getTables(aCatalog,sSchema,sTable,sTableTypes); + + sdbcx::ObjectType xRet = nullptr; + if ( xResult.is() ) + { + Reference< XRow > xRow(xResult,UNO_QUERY); + if ( xResult->next() ) // there can be only one table with this name + { + sal_Int32 nPrivileges = ::dbtools::getTablePrivileges( m_xMetaData, sCatalog, sSchema, sTable ); + if ( m_xMetaData->isReadOnly() ) + nPrivileges &= ~( Privilege::INSERT | Privilege::UPDATE | Privilege::DELETE | Privilege::CREATE | Privilege::ALTER | Privilege::DROP ); + + // obtain privileges + OHSQLTable* pRet = new OHSQLTable( this + ,static_cast<OHCatalog&>(m_rParent).getConnection() + ,sTable + ,xRow->getString(4) + ,xRow->getString(5) + ,sSchema + ,sCatalog + ,nPrivileges); + xRet = pRet; + } + ::comphelper::disposeComponent(xResult); + } + + return xRet; +} + +void OTables::impl_refresh( ) +{ + static_cast<OHCatalog&>(m_rParent).refreshTables(); +} + +void OTables::disposing() +{ +m_xMetaData.clear(); + OCollection::disposing(); +} + +Reference< XPropertySet > OTables::createDescriptor() +{ + return new OHSQLTable(this,static_cast<OHCatalog&>(m_rParent).getConnection()); +} + +// XAppend +sdbcx::ObjectType OTables::appendObject( const OUString& _rForName, const Reference< XPropertySet >& descriptor ) +{ + createTable(descriptor); + return createObject( _rForName ); +} + +// XDrop +void OTables::dropObject(sal_Int32 _nPos,const OUString& _sElementName) +{ + Reference< XInterface > xObject( getObject( _nPos ) ); + bool bIsNew = connectivity::sdbcx::ODescriptor::isNew( xObject ); + if (!bIsNew) + { + Reference< XConnection > xConnection = static_cast<OHCatalog&>(m_rParent).getConnection(); + + + OUString sCatalog,sSchema,sTable; + ::dbtools::qualifiedNameComponents(m_xMetaData,_sElementName,sCatalog,sSchema,sTable,::dbtools::EComposeRule::InDataManipulation); + + OUString aSql( "DROP " ); + + Reference<XPropertySet> xProp(xObject,UNO_QUERY); + bool bIsView; + if((bIsView = (xProp.is() && ::comphelper::getString(xProp->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))) == "VIEW"))) // here we have a view + aSql += "VIEW "; + else + aSql += "TABLE "; + + OUString sComposedName( + ::dbtools::composeTableName( m_xMetaData, sCatalog, sSchema, sTable, true, ::dbtools::EComposeRule::InDataManipulation ) ); + aSql += sComposedName; + Reference< XStatement > xStmt = xConnection->createStatement( ); + if ( xStmt.is() ) + { + xStmt->execute(aSql); + ::comphelper::disposeComponent(xStmt); + } + // if no exception was thrown we must delete it from the views + if ( bIsView ) + { + HViews* pViews = static_cast<HViews*>(static_cast<OHCatalog&>(m_rParent).getPrivateViews()); + if ( pViews && pViews->hasByName(_sElementName) ) + pViews->dropByNameImpl(_sElementName); + } + } +} + +void OTables::createTable( const Reference< XPropertySet >& descriptor ) +{ + Reference< XConnection > xConnection = static_cast<OHCatalog&>(m_rParent).getConnection(); + OUString aSql = ::dbtools::createSqlCreateTableStatement(descriptor,xConnection); + + Reference< XStatement > xStmt = xConnection->createStatement( ); + if ( xStmt.is() ) + { + xStmt->execute(aSql); + ::comphelper::disposeComponent(xStmt); + } +} + +void OTables::appendNew(const OUString& _rsNewTable) +{ + insertElement(_rsNewTable,nullptr); + + // notify our container listeners + ContainerEvent aEvent(static_cast<XContainer*>(this), makeAny(_rsNewTable), Any(), Any()); + OInterfaceIteratorHelper2 aListenerLoop(m_aContainerListeners); + while (aListenerLoop.hasMoreElements()) + static_cast<XContainerListener*>(aListenerLoop.next())->elementInserted(aEvent); +} + +OUString OTables::getNameForObject(const sdbcx::ObjectType& _xObject) +{ + OSL_ENSURE(_xObject.is(),"OTables::getNameForObject: Object is NULL!"); + return ::dbtools::composeTableName( m_xMetaData, _xObject, ::dbtools::EComposeRule::InDataManipulation, false ); +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/hsqldb/HTerminateListener.cxx b/connectivity/source/drivers/hsqldb/HTerminateListener.cxx new file mode 100644 index 000000000000..df325efb75e8 --- /dev/null +++ b/connectivity/source/drivers/hsqldb/HTerminateListener.cxx @@ -0,0 +1,52 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + + +#include "HTerminateListener.hxx" +#include <hsqldb/HDriver.hxx> + + +namespace connectivity +{ + + using namespace hsqldb; + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::lang; + +// XEventListener +void SAL_CALL OConnectionController::disposing( const EventObject& /*Source*/ ) +{ +} + +// XTerminateListener +void SAL_CALL OConnectionController::queryTermination( const EventObject& /*aEvent*/ ) +{ + m_pDriver->flushConnections(); +} + +void SAL_CALL OConnectionController::notifyTermination( const EventObject& /*aEvent*/ ) +{ + m_pDriver->shutdownConnections(); +} + + +} // namespace connectivity + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/hsqldb/HTerminateListener.hxx b/connectivity/source/drivers/hsqldb/HTerminateListener.hxx new file mode 100644 index 000000000000..62e8ec79d660 --- /dev/null +++ b/connectivity/source/drivers/hsqldb/HTerminateListener.hxx @@ -0,0 +1,54 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_HSQLDB_HTERMINATELISTENER_HXX +#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_HSQLDB_HTERMINATELISTENER_HXX + +#include <cppuhelper/implbase.hxx> +#include <com/sun/star/frame/XTerminateListener.hpp> + + +namespace connectivity +{ + + + namespace hsqldb + { + class ODriverDelegator; + class OConnectionController : public ::cppu::WeakImplHelper< css::frame::XTerminateListener > + { + ODriverDelegator* m_pDriver; + protected: + virtual ~OConnectionController() override {m_pDriver = nullptr;} + public: + explicit OConnectionController(ODriverDelegator* _pDriver) : m_pDriver(_pDriver){} + + // XEventListener + virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override; + + // XTerminateListener + virtual void SAL_CALL queryTermination( const css::lang::EventObject& aEvent ) override; + virtual void SAL_CALL notifyTermination( const css::lang::EventObject& aEvent ) override; + }; + } + +} // namespace connectivity + +#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_HSQLDB_HTERMINATELISTENER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/hsqldb/HTools.cxx b/connectivity/source/drivers/hsqldb/HTools.cxx new file mode 100644 index 000000000000..9a31ace4602b --- /dev/null +++ b/connectivity/source/drivers/hsqldb/HTools.cxx @@ -0,0 +1,53 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <hsqldb/HTools.hxx> + + +namespace connectivity { namespace hsqldb +{ + + void HTools::appendTableFilterCrit( OUStringBuffer& _inout_rBuffer, const OUString& _rCatalog, + const OUString& _rSchema, const OUString& _rName, bool _bShortForm ) + { + _inout_rBuffer.append( " WHERE " ); + if ( !_rCatalog.isEmpty() ) + { + _inout_rBuffer.appendAscii( _bShortForm ? "TABLE_CAT" : "TABLE_CATALOG" ); + _inout_rBuffer.append( " = '" ); + _inout_rBuffer.append ( _rCatalog ); + _inout_rBuffer.append( "' AND " ); + } + if ( !_rSchema.isEmpty() ) + { + _inout_rBuffer.appendAscii( _bShortForm ? "TABLE_SCHEM" : "TABLE_SCHEMA" ); + _inout_rBuffer.append( " = '" ); + _inout_rBuffer.append ( _rSchema ); + _inout_rBuffer.append( "' AND " ); + } + _inout_rBuffer.append( "TABLE_NAME = '" ); + _inout_rBuffer.append ( _rName ); + _inout_rBuffer.append( "'" ); + } + + +} } // namespace connectivity::hsqldb + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/hsqldb/HUser.cxx b/connectivity/source/drivers/hsqldb/HUser.cxx new file mode 100644 index 000000000000..5fd38f739a51 --- /dev/null +++ b/connectivity/source/drivers/hsqldb/HUser.cxx @@ -0,0 +1,327 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <hsqldb/HUser.hxx> +#include <com/sun/star/sdbc/XRow.hpp> +#include <com/sun/star/sdbc/XResultSet.hpp> +#include <connectivity/dbtools.hxx> +#include <connectivity/dbexception.hxx> +#include <com/sun/star/sdbcx/Privilege.hpp> +#include <com/sun/star/sdbcx/PrivilegeObject.hpp> +#include <TConnection.hxx> +#include <strings.hrc> + +using namespace connectivity; +using namespace connectivity::hsqldb; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::sdbcx; +using namespace ::com::sun::star::sdbc; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::lang; + +OHSQLUser::OHSQLUser( const css::uno::Reference< css::sdbc::XConnection >& _xConnection) : connectivity::sdbcx::OUser(true) + ,m_xConnection(_xConnection) +{ + construct(); +} + +OHSQLUser::OHSQLUser( const css::uno::Reference< css::sdbc::XConnection >& _xConnection, + const OUString& Name + ) : connectivity::sdbcx::OUser(Name,true) + ,m_xConnection(_xConnection) +{ + construct(); +} + +void OHSQLUser::refreshGroups() +{ +} + +OUserExtend::OUserExtend( const css::uno::Reference< css::sdbc::XConnection >& _xConnection) : OHSQLUser(_xConnection) +{ + construct(); +} + +void OUserExtend::construct() +{ + registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PASSWORD), PROPERTY_ID_PASSWORD,0,&m_Password,::cppu::UnoType<OUString>::get()); +} + +cppu::IPropertyArrayHelper* OUserExtend::createArrayHelper() const +{ + Sequence< Property > aProps; + describeProperties(aProps); + return new cppu::OPropertyArrayHelper(aProps); +} + +cppu::IPropertyArrayHelper & OUserExtend::getInfoHelper() +{ + return *OUserExtend_PROP::getArrayHelper(); +} +typedef connectivity::sdbcx::OUser_BASE OUser_BASE_RBHELPER; + +sal_Int32 SAL_CALL OHSQLUser::getPrivileges( const OUString& objName, sal_Int32 objType ) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OUser_BASE_RBHELPER::rBHelper.bDisposed); + + sal_Int32 nRights,nRightsWithGrant; + findPrivilegesAndGrantPrivileges(objName,objType,nRights,nRightsWithGrant); + return nRights; +} + +void OHSQLUser::findPrivilegesAndGrantPrivileges(const OUString& objName, sal_Int32 objType,sal_Int32& nRights,sal_Int32& nRightsWithGrant) +{ + nRightsWithGrant = nRights = 0; + // first we need to create the sql stmt to select the privs + Reference<XDatabaseMetaData> xMeta = m_xConnection->getMetaData(); + OUString sCatalog,sSchema,sTable; + ::dbtools::qualifiedNameComponents(xMeta,objName,sCatalog,sSchema,sTable,::dbtools::EComposeRule::InDataManipulation); + Reference<XResultSet> xRes; + switch(objType) + { + case PrivilegeObject::TABLE: + case PrivilegeObject::VIEW: + { + Any aCatalog; + if ( !sCatalog.isEmpty() ) + aCatalog <<= sCatalog; + xRes = xMeta->getTablePrivileges(aCatalog,sSchema,sTable); + } + break; + + case PrivilegeObject::COLUMN: + { + Any aCatalog; + if ( !sCatalog.isEmpty() ) + aCatalog <<= sCatalog; + xRes = xMeta->getColumnPrivileges(aCatalog,sSchema,sTable,"%"); + } + break; + } + + if ( xRes.is() ) + { + static const char sYes [] = "YES"; + + nRightsWithGrant = nRights = 0; + + Reference<XRow> xCurrentRow(xRes,UNO_QUERY); + while( xCurrentRow.is() && xRes->next() ) + { + OUString sGrantee = xCurrentRow->getString(5); + OUString sPrivilege = xCurrentRow->getString(6); + OUString sGrantable = xCurrentRow->getString(7); + + if (!m_Name.equalsIgnoreAsciiCase(sGrantee)) + continue; + + if (sPrivilege.equalsIgnoreAsciiCase("SELECT")) + { + nRights |= Privilege::SELECT; + if ( sGrantable.equalsIgnoreAsciiCase(sYes) ) + nRightsWithGrant |= Privilege::SELECT; + } + else if (sPrivilege.equalsIgnoreAsciiCase("INSERT")) + { + nRights |= Privilege::INSERT; + if ( sGrantable.equalsIgnoreAsciiCase(sYes) ) + nRightsWithGrant |= Privilege::INSERT; + } + else if (sPrivilege.equalsIgnoreAsciiCase("UPDATE")) + { + nRights |= Privilege::UPDATE; + if ( sGrantable.equalsIgnoreAsciiCase(sYes) ) + nRightsWithGrant |= Privilege::UPDATE; + } + else if (sPrivilege.equalsIgnoreAsciiCase("DELETE")) + { + nRights |= Privilege::DELETE; + if ( sGrantable.equalsIgnoreAsciiCase(sYes) ) + nRightsWithGrant |= Privilege::DELETE; + } + else if (sPrivilege.equalsIgnoreAsciiCase("READ")) + { + nRights |= Privilege::READ; + if ( sGrantable.equalsIgnoreAsciiCase(sYes) ) + nRightsWithGrant |= Privilege::READ; + } + else if (sPrivilege.equalsIgnoreAsciiCase("CREATE")) + { + nRights |= Privilege::CREATE; + if ( sGrantable.equalsIgnoreAsciiCase(sYes) ) + nRightsWithGrant |= Privilege::CREATE; + } + else if (sPrivilege.equalsIgnoreAsciiCase("ALTER")) + { + nRights |= Privilege::ALTER; + if ( sGrantable.equalsIgnoreAsciiCase(sYes) ) + nRightsWithGrant |= Privilege::ALTER; + } + else if (sPrivilege.equalsIgnoreAsciiCase("REFERENCE")) + { + nRights |= Privilege::REFERENCE; + if ( sGrantable.equalsIgnoreAsciiCase(sYes) ) + nRightsWithGrant |= Privilege::REFERENCE; + } + else if (sPrivilege.equalsIgnoreAsciiCase("DROP")) + { + nRights |= Privilege::DROP; + if ( sGrantable.equalsIgnoreAsciiCase(sYes) ) + nRightsWithGrant |= Privilege::DROP; + } + } + ::comphelper::disposeComponent(xRes); + } +} + +sal_Int32 SAL_CALL OHSQLUser::getGrantablePrivileges( const OUString& objName, sal_Int32 objType ) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OUser_BASE_RBHELPER::rBHelper.bDisposed); + + sal_Int32 nRights,nRightsWithGrant; + findPrivilegesAndGrantPrivileges(objName,objType,nRights,nRightsWithGrant); + return nRightsWithGrant; +} + +void SAL_CALL OHSQLUser::grantPrivileges( const OUString& objName, sal_Int32 objType, sal_Int32 objPrivileges ) +{ + if ( objType != PrivilegeObject::TABLE ) + { + ::connectivity::SharedResources aResources; + const OUString sError( aResources.getResourceString(STR_PRIVILEGE_NOT_GRANTED)); + ::dbtools::throwGenericSQLException(sError,*this); + } // if ( objType != PrivilegeObject::TABLE ) + + + ::osl::MutexGuard aGuard(m_aMutex); + + OUString sPrivs = getPrivilegeString(objPrivileges); + if(!sPrivs.isEmpty()) + { + Reference<XDatabaseMetaData> xMeta = m_xConnection->getMetaData(); + OUString sGrant = "GRANT " + sPrivs + + " ON " + ::dbtools::quoteTableName(xMeta,objName,::dbtools::EComposeRule::InDataManipulation) + + " TO " + ::dbtools::quoteName(xMeta->getIdentifierQuoteString(), m_Name); + + Reference<XStatement> xStmt = m_xConnection->createStatement(); + if(xStmt.is()) + xStmt->execute(sGrant); + ::comphelper::disposeComponent(xStmt); + } +} + +void SAL_CALL OHSQLUser::revokePrivileges( const OUString& objName, sal_Int32 objType, sal_Int32 objPrivileges ) +{ + if ( objType != PrivilegeObject::TABLE ) + { + ::connectivity::SharedResources aResources; + const OUString sError( aResources.getResourceString(STR_PRIVILEGE_NOT_REVOKED)); + ::dbtools::throwGenericSQLException(sError,*this); + } // if ( objType != PrivilegeObject::TABLE ) + + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OUser_BASE_RBHELPER::rBHelper.bDisposed); + OUString sPrivs = getPrivilegeString(objPrivileges); + if(!sPrivs.isEmpty()) + { + Reference<XDatabaseMetaData> xMeta = m_xConnection->getMetaData(); + OUString sGrant = "REVOKE " + sPrivs + + " ON " + ::dbtools::quoteTableName(xMeta,objName,::dbtools::EComposeRule::InDataManipulation) + + " FROM " + ::dbtools::quoteName(xMeta->getIdentifierQuoteString(), m_Name); + + Reference<XStatement> xStmt = m_xConnection->createStatement(); + if(xStmt.is()) + xStmt->execute(sGrant); + ::comphelper::disposeComponent(xStmt); + } +} + +// XUser +void SAL_CALL OHSQLUser::changePassword( const OUString& /*oldPassword*/, const OUString& newPassword ) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OUser_BASE_RBHELPER::rBHelper.bDisposed); + + Reference<XDatabaseMetaData> xMeta = m_xConnection->getMetaData(); + + if( m_Name != xMeta->getUserName() ) + { + ::dbtools::throwGenericSQLException("HSQLDB can only change password of the current user.", *this); + } + + OUString sAlterPwd = "SET PASSWORD " + + ::dbtools::quoteName(xMeta->getIdentifierQuoteString(), newPassword); + + Reference<XStatement> xStmt = m_xConnection->createStatement(); + if ( xStmt.is() ) + { + xStmt->execute(sAlterPwd); + ::comphelper::disposeComponent(xStmt); + } +} + +OUString OHSQLUser::getPrivilegeString(sal_Int32 nRights) +{ + OUString sPrivs; + if((nRights & Privilege::INSERT) == Privilege::INSERT) + sPrivs += "INSERT"; + + if((nRights & Privilege::DELETE) == Privilege::DELETE) + { + if(!sPrivs.isEmpty()) + sPrivs += ","; + sPrivs += "DELETE"; + } + + if((nRights & Privilege::UPDATE) == Privilege::UPDATE) + { + if(!sPrivs.isEmpty()) + sPrivs += ","; + sPrivs += "UPDATE"; + } + + if((nRights & Privilege::ALTER) == Privilege::ALTER) + { + if(!sPrivs.isEmpty()) + sPrivs += ","; + sPrivs += "ALTER"; + } + + if((nRights & Privilege::SELECT) == Privilege::SELECT) + { + if(!sPrivs.isEmpty()) + sPrivs += ","; + sPrivs += "SELECT"; + } + + if((nRights & Privilege::REFERENCE) == Privilege::REFERENCE) + { + if(!sPrivs.isEmpty()) + sPrivs += ","; + sPrivs += "REFERENCES"; + } + + return sPrivs; +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/hsqldb/HUsers.cxx b/connectivity/source/drivers/hsqldb/HUsers.cxx new file mode 100644 index 000000000000..c6992c9328c3 --- /dev/null +++ b/connectivity/source/drivers/hsqldb/HUsers.cxx @@ -0,0 +1,103 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <hsqldb/HUsers.hxx> +#include <hsqldb/HUser.hxx> +#include <hsqldb/HTable.hxx> +#include <com/sun/star/sdbc/XRow.hpp> +#include <com/sun/star/sdbc/XResultSet.hpp> +#include <connectivity/sdbcx/IRefreshable.hxx> +#include <comphelper/types.hxx> +#include <connectivity/dbexception.hxx> +#include <connectivity/dbtools.hxx> +#include <TConnection.hxx> + +using namespace ::comphelper; +using namespace connectivity; +using namespace connectivity::hsqldb; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::sdbc; +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::lang; + +OUsers::OUsers( ::cppu::OWeakObject& _rParent, + ::osl::Mutex& _rMutex, + const ::std::vector< OUString> &_rVector, + const css::uno::Reference< css::sdbc::XConnection >& _xConnection, + connectivity::sdbcx::IRefreshableUsers* _pParent) + : sdbcx::OCollection(_rParent, true, _rMutex, _rVector) + ,m_xConnection(_xConnection) + ,m_pParent(_pParent) +{ +} + + +sdbcx::ObjectType OUsers::createObject(const OUString& _rName) +{ + return new OHSQLUser(m_xConnection,_rName); +} + +void OUsers::impl_refresh() +{ + m_pParent->refreshUsers(); +} + +Reference< XPropertySet > OUsers::createDescriptor() +{ + OUserExtend* pNew = new OUserExtend(m_xConnection); + return pNew; +} + +// XAppend +sdbcx::ObjectType OUsers::appendObject( const OUString& _rForName, const Reference< XPropertySet >& descriptor ) +{ + OUString aQuote = m_xConnection->getMetaData()->getIdentifierQuoteString( ); + OUString sPassword; + descriptor->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PASSWORD)) >>= sPassword; + OUString aSql = "GRANT USAGE ON * TO " + + ::dbtools::quoteName(aQuote,_rForName) + " @\"%\" "; + if ( !sPassword.isEmpty() ) + { + aSql += " IDENTIFIED BY '" + sPassword + "'"; + } + + Reference< XStatement > xStmt = m_xConnection->createStatement( ); + if(xStmt.is()) + xStmt->execute(aSql); + ::comphelper::disposeComponent(xStmt); + + return createObject( _rForName ); +} + +// XDrop +void OUsers::dropObject(sal_Int32 /*nPos*/,const OUString& _sElementName) +{ + OUString aSql( "REVOKE ALL ON * FROM " ); + OUString aQuote = m_xConnection->getMetaData()->getIdentifierQuoteString( ); + aSql += ::dbtools::quoteName(aQuote,_sElementName); + + Reference< XStatement > xStmt = m_xConnection->createStatement( ); + if(xStmt.is()) + xStmt->execute(aSql); + ::comphelper::disposeComponent(xStmt); +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/hsqldb/HViews.cxx b/connectivity/source/drivers/hsqldb/HViews.cxx new file mode 100644 index 000000000000..c66d869e09a4 --- /dev/null +++ b/connectivity/source/drivers/hsqldb/HViews.cxx @@ -0,0 +1,158 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + + +#include <hsqldb/HTables.hxx> +#include <hsqldb/HViews.hxx> +#include <hsqldb/HView.hxx> +#include <com/sun/star/sdbc/XRow.hpp> +#include <com/sun/star/sdbc/XResultSet.hpp> +#include <com/sun/star/sdbc/ColumnValue.hpp> +#include <com/sun/star/sdbc/KeyRule.hpp> +#include <com/sun/star/sdbcx/KeyType.hpp> +#include <com/sun/star/sdbcx/CheckOption.hpp> +#include <hsqldb/HCatalog.hxx> +#include <comphelper/extract.hxx> +#include <connectivity/dbtools.hxx> +#include <connectivity/dbexception.hxx> +#include <cppuhelper/interfacecontainer.h> +#include <comphelper/types.hxx> +#include <TConnection.hxx> + +using namespace ::comphelper; + +using namespace ::cppu; +using namespace connectivity; +using namespace connectivity::hsqldb; +using namespace css::uno; +using namespace css::beans; +using namespace css::sdbcx; +using namespace css::sdbc; +using namespace css::container; +using namespace css::lang; +using namespace dbtools; +typedef connectivity::sdbcx::OCollection OCollection_TYPE; + + +HViews::HViews( const Reference< XConnection >& _rxConnection, ::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex, + const ::std::vector< OUString> &_rVector ) + :sdbcx::OCollection( _rParent, true, _rMutex, _rVector ) + ,m_xConnection( _rxConnection ) + ,m_xMetaData( _rxConnection->getMetaData() ) + ,m_bInDrop( false ) +{ +} + + +sdbcx::ObjectType HViews::createObject(const OUString& _rName) +{ + OUString sCatalog,sSchema,sTable; + ::dbtools::qualifiedNameComponents(m_xMetaData, + _rName, + sCatalog, + sSchema, + sTable, + ::dbtools::EComposeRule::InDataManipulation); + return new HView( m_xConnection, isCaseSensitive(), sSchema, sTable ); +} + + +void HViews::impl_refresh( ) +{ + static_cast<OHCatalog&>(m_rParent).refreshTables(); +} + +void HViews::disposing() +{ +m_xMetaData.clear(); + OCollection::disposing(); +} + +Reference< XPropertySet > HViews::createDescriptor() +{ + Reference<XConnection> xConnection = static_cast<OHCatalog&>(m_rParent).getConnection(); + connectivity::sdbcx::OView* pNew = new connectivity::sdbcx::OView(true, xConnection->getMetaData()); + return pNew; +} + +// XAppend +sdbcx::ObjectType HViews::appendObject( const OUString& _rForName, const Reference< XPropertySet >& descriptor ) +{ + createView(descriptor); + return createObject( _rForName ); +} + +// XDrop +void HViews::dropObject(sal_Int32 _nPos,const OUString& /*_sElementName*/) +{ + if ( m_bInDrop ) + return; + + Reference< XInterface > xObject( getObject( _nPos ) ); + bool bIsNew = connectivity::sdbcx::ODescriptor::isNew( xObject ); + if (!bIsNew) + { + OUString aSql( "DROP VIEW" ); + + Reference<XPropertySet> xProp(xObject,UNO_QUERY); + aSql += ::dbtools::composeTableName( m_xMetaData, xProp, ::dbtools::EComposeRule::InTableDefinitions, true ); + + Reference<XConnection> xConnection = static_cast<OHCatalog&>(m_rParent).getConnection(); + Reference< XStatement > xStmt = xConnection->createStatement( ); + xStmt->execute(aSql); + ::comphelper::disposeComponent(xStmt); + } +} + +void HViews::dropByNameImpl(const OUString& elementName) +{ + m_bInDrop = true; + OCollection_TYPE::dropByName(elementName); + m_bInDrop = false; +} + +void HViews::createView( const Reference< XPropertySet >& descriptor ) +{ + Reference<XConnection> xConnection = static_cast<OHCatalog&>(m_rParent).getConnection(); + + OUString sCommand; + descriptor->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_COMMAND)) >>= sCommand; + + OUString aSql = "CREATE VIEW " + + ::dbtools::composeTableName( m_xMetaData, descriptor, ::dbtools::EComposeRule::InTableDefinitions, true ) + + " AS " + sCommand; + + Reference< XStatement > xStmt = xConnection->createStatement( ); + if ( xStmt.is() ) + { + xStmt->execute(aSql); + ::comphelper::disposeComponent(xStmt); + } + + // insert the new view also in the tables collection + OTables* pTables = static_cast<OTables*>(static_cast<OHCatalog&>(m_rParent).getPrivateTables()); + if ( pTables ) + { + OUString sName = ::dbtools::composeTableName( m_xMetaData, descriptor, ::dbtools::EComposeRule::InDataManipulation, false ); + pTables->appendNew(sName); + } +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/hsqldb/Hservices.cxx b/connectivity/source/drivers/hsqldb/Hservices.cxx new file mode 100644 index 000000000000..6d1294b9b072 --- /dev/null +++ b/connectivity/source/drivers/hsqldb/Hservices.cxx @@ -0,0 +1,105 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + + +#include <hsqldb/HDriver.hxx> +#include <cppuhelper/factory.hxx> + +using namespace connectivity::hsqldb; +using css::uno::Reference; +using css::uno::Sequence; +using css::lang::XSingleServiceFactory; +using css::lang::XMultiServiceFactory; + +typedef Reference< XSingleServiceFactory > (*createFactoryFunc) + ( + const Reference< XMultiServiceFactory > & rServiceManager, + const OUString & rComponentName, + ::cppu::ComponentInstantiation pCreateFunction, + const Sequence< OUString > & rServiceNames, + rtl_ModuleCount* + ); + + +struct ProviderRequest +{ + Reference< XSingleServiceFactory > xRet; + Reference< XMultiServiceFactory > const xServiceManager; + OUString const sImplementationName; + + ProviderRequest( + void* pServiceManager, + sal_Char const* pImplementationName + ) + : xServiceManager(static_cast<XMultiServiceFactory*>(pServiceManager)) + , sImplementationName(OUString::createFromAscii(pImplementationName)) + { + } + + bool CREATE_PROVIDER( + const OUString& Implname, + const Sequence< OUString > & Services, + ::cppu::ComponentInstantiation Factory, + createFactoryFunc creator + ) + { + if (!xRet.is() && (Implname == sImplementationName)) + { + try + { + xRet = creator( xServiceManager, sImplementationName,Factory, Services,nullptr); + } + catch(...) + { + } + } + return xRet.is(); + } + + void* getProvider() const { return xRet.get(); } +}; + + +extern "C" SAL_DLLPUBLIC_EXPORT void* hsqldb_component_getFactory( + const sal_Char* pImplementationName, + void* pServiceManager, + void* /*pRegistryKey*/) +{ + void* pRet = nullptr; + if (pServiceManager) + { + ProviderRequest aReq(pServiceManager,pImplementationName); + + aReq.CREATE_PROVIDER( + ODriverDelegator::getImplementationName_Static(), + ODriverDelegator::getSupportedServiceNames_Static(), + ODriverDelegator_CreateInstance, ::cppu::createSingleFactory) + ; + + if(aReq.xRet.is()) + aReq.xRet->acquire(); + + pRet = aReq.getProvider(); + } + + return pRet; +}; + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/hsqldb/StorageFileAccess.cxx b/connectivity/source/drivers/hsqldb/StorageFileAccess.cxx new file mode 100644 index 000000000000..76e506595817 --- /dev/null +++ b/connectivity/source/drivers/hsqldb/StorageFileAccess.cxx @@ -0,0 +1,170 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + + +#if defined(HAVE_CONFIG_H) && HAVE_CONFIG_H +#include <config.h> +#endif +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/embed/XStorage.hpp> +#include <com/sun/star/lang/IllegalArgumentException.hpp> +#include <hsqldb/HStorageMap.hxx> +#include <osl/diagnose.h> + + +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::embed; +using namespace ::com::sun::star::io; +using namespace ::com::sun::star::lang; +using namespace ::connectivity::hsqldb; + +/* + * Class: com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess + * Method: isStreamElement + * Signature: (Ljava/lang/String;Ljava/lang/String;)Z + */ +extern "C" SAL_JNI_EXPORT jboolean JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_isStreamElement + (JNIEnv * env, jobject /*obj_this*/,jstring key, jstring name) +{ + TStorages::mapped_type aStoragePair = StorageContainer::getRegisteredStorage(StorageContainer::jstring2ustring(env,key)); + auto storage = aStoragePair.mapStorage(); + if ( storage.is() ) + { + try + { + OUString sName = StorageContainer::jstring2ustring(env,name); + try + { + OUString sOldName = StorageContainer::removeOldURLPrefix(sName); + if ( storage->isStreamElement(sOldName) ) + { + try + { + storage->renameElement(sOldName,StorageContainer::removeURLPrefix(sName,aStoragePair.url)); + } + catch(const Exception&) + { + } + } + } + catch(const NoSuchElementException&) + { + } + catch(const IllegalArgumentException&) + { + } + return storage->isStreamElement(StorageContainer::removeURLPrefix(sName,aStoragePair.url)); + } + catch(const NoSuchElementException&) + { + } + catch(const Exception& e) + { + OSL_FAIL("Exception caught! : Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_isStreamElement"); + if (env->ExceptionCheck()) + env->ExceptionClear(); + SAL_WARN("connectivity.hsqldb", "forwarding Exception: " << e); + } + } + return JNI_FALSE; +} + + +/* + * Class: com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess + * Method: removeElement + * Signature: (Ljava/lang/String;Ljava/lang/String;)V + */ +extern "C" SAL_JNI_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_removeElement + (JNIEnv * env, jobject /*obj_this*/,jstring key, jstring name) +{ +#ifdef HSQLDB_DBG + { + OUString sKey = StorageContainer::jstring2ustring(env,key); + OUString sName = StorageContainer::jstring2ustring(env,name); + } +#endif + TStorages::mapped_type aStoragePair = StorageContainer::getRegisteredStorage(StorageContainer::jstring2ustring(env,key)); + auto storage = aStoragePair.mapStorage(); + if ( storage.is() ) + { + try + { + storage->removeElement(StorageContainer::removeURLPrefix(StorageContainer::jstring2ustring(env,name),aStoragePair.url)); + } + catch(const NoSuchElementException&) + { + if (env->ExceptionCheck()) + env->ExceptionClear(); + } + catch(const Exception& e) + { + SAL_WARN("connectivity.hsqldb", "Exception caught! : Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_removeElement " << e); + StorageContainer::throwJavaException(e,env); + } + } +} + + +/* + * Class: com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess + * Method: renameElement + * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V + */ +extern "C" SAL_JNI_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_renameElement + (JNIEnv * env, jobject /*obj_this*/,jstring key, jstring oldname, jstring newname) +{ +#ifdef HSQLDB_DBG + { + OUString sKey = StorageContainer::jstring2ustring(env,key); + OUString sNewName = StorageContainer::jstring2ustring(env,newname); + OUString sOldName = StorageContainer::jstring2ustring(env,oldname); + } +#endif + TStorages::mapped_type aStoragePair = StorageContainer::getRegisteredStorage(StorageContainer::jstring2ustring(env,key)); + auto storage = aStoragePair.mapStorage(); + if ( storage.is() ) + { + try + { + storage->renameElement( + StorageContainer::removeURLPrefix(StorageContainer::jstring2ustring(env,oldname),aStoragePair.url), + StorageContainer::removeURLPrefix(StorageContainer::jstring2ustring(env,newname),aStoragePair.url) + ); +#ifdef HSQLDB_DBG + { + OUString sNewName = StorageContainer::removeURLPrefix(StorageContainer::jstring2ustring(env,newname),aStoragePair.first.second); + OSL_ENSURE(aStoragePair.first.first->isStreamElement(sNewName),"Stream could not be renamed"); + } +#endif + } + catch(const NoSuchElementException&) + { + } + catch(const Exception& e) + { + OSL_FAIL("Exception caught! : Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_renameElement"); + StorageContainer::throwJavaException(e,env); + } + } +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/hsqldb/StorageNativeInputStream.cxx b/connectivity/source/drivers/hsqldb/StorageNativeInputStream.cxx new file mode 100644 index 000000000000..2c738f15f37f --- /dev/null +++ b/connectivity/source/drivers/hsqldb/StorageNativeInputStream.cxx @@ -0,0 +1,297 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + + +#if defined(HAVE_CONFIG_H) && HAVE_CONFIG_H +#include <config.h> +#endif +#include <com/sun/star/io/XStream.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/document/XDocumentSubStorageSupplier.hpp> +#include <com/sun/star/embed/XStorage.hpp> +#include <com/sun/star/embed/ElementModes.hpp> +#include <comphelper/types.hxx> +#include <hsqldb/HStorageAccess.hxx> +#include <hsqldb/HStorageMap.hxx> + +#include <jvmaccess/virtualmachine.hxx> +#include <com/sun/star/lang/XSingleComponentFactory.hpp> +#include <osl/diagnose.h> +#include "accesslog.hxx" + +#include <limits> + + +using namespace ::com::sun::star::container; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::document; +using namespace ::com::sun::star::embed; +using namespace ::com::sun::star::io; +using namespace ::com::sun::star::lang; +using namespace ::connectivity::hsqldb; + +/*****************************************************************************/ +/* exception macros */ + +#define ThrowException(env, type, msg) { \ + env->ThrowNew(env->FindClass(type), msg); } +/* + * Class: com_sun_star_sdbcx_comp_hsqldb_StorageNativeInputStream + * Method: openStream + * Signature: (Ljava/lang/String;Ljava/lang/String;I)V + */ +extern "C" SAL_JNI_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeInputStream_openStream + (JNIEnv * env, jobject /*obj_this*/,jstring key, jstring name, jint mode) +{ +#ifdef HSQLDB_DBG + { + OperationLogFile( env, name, "input" ).logOperation( "openStream" ); + LogFile( env, name, "input" ).create(); + } +#endif + StorageContainer::registerStream(env,name,key,mode); +} + + +/* + * Class: com_sun_star_sdbcx_comp_hsqldb_StorageNativeInputStream + * Method: read + * Signature: (Ljava/lang/String;Ljava/lang/String;)I + */ +extern "C" SAL_JNI_EXPORT jint JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeInputStream_read__Ljava_lang_String_2Ljava_lang_String_2 + (JNIEnv * env, jobject /*obj_this*/, jstring key, jstring name) +{ +#ifdef HSQLDB_DBG + OperationLogFile( env, name, "input" ).logOperation( "read()" ); + + DataLogFile aDataLog( env, name, "input" ); + return read_from_storage_stream( env, obj_this, name, key, &aDataLog ); +#else + return read_from_storage_stream( env, name, key ); +#endif +} + + +/* + * Class: com_sun_star_sdbcx_comp_hsqldb_StorageNativeInputStream + * Method: read + * Signature: (Ljava/lang/String;Ljava/lang/String;[BII)I + */ +extern "C" SAL_JNI_EXPORT jint JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeInputStream_read__Ljava_lang_String_2Ljava_lang_String_2_3BII + (JNIEnv * env, jobject obj_this, jstring key, jstring name, jbyteArray buffer, jint off, jint len) +{ +#ifdef HSQLDB_DBG + OperationLogFile( env, name, "input" ).logOperation( "read( byte[], int, int )" ); + + DataLogFile aDataLog( env, name, "input" ); + return read_from_storage_stream_into_buffer( env, obj_this, name, key, buffer, off, len, &aDataLog ); +#else + (void)obj_this; + return read_from_storage_stream_into_buffer(env, name,key,buffer,off,len); +#endif +} + + +/* + * Class: com_sun_star_sdbcx_comp_hsqldb_StorageNativeInputStream + * Method: close + * Signature: (Ljava/lang/String;Ljava/lang/String;)V + */ +extern "C" SAL_JNI_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeInputStream_close + (JNIEnv * env, jobject /*obj_this*/,jstring key, jstring name) +{ +#ifdef HSQLDB_DBG + OperationLogFile aOpLog( env, name, "input" ); + aOpLog.logOperation( "close" ); + aOpLog.close(); + + LogFile aDataLog( env, name, "input" ); + aDataLog.close(); +#endif + StorageContainer::revokeStream(env,name,key); +} + + +/* + * Class: com_sun_star_sdbcx_comp_hsqldb_StorageNativeInputStream + * Method: skip + * Signature: (Ljava/lang/String;Ljava/lang/String;J)J + */ +extern "C" SAL_JNI_EXPORT jlong JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeInputStream_skip + (JNIEnv * env, jobject /*obj_this*/,jstring key, jstring name, jlong n) +{ +#ifdef HSQLDB_DBG + OperationLogFile( env, name, "input" ).logOperation( "skip()" ); +#endif + + if ( n < 0 ) + ThrowException( env, + "java/io/IOException", + "n < 0"); + + std::shared_ptr<StreamHelper> pHelper = StorageContainer::getRegisteredStream(env,name,key); + OSL_ENSURE(pHelper.get(),"No stream helper!"); + if ( pHelper.get() ) + { + Reference<XInputStream> xIn = pHelper->getInputStream(); + if ( xIn.is() ) + { + try + { + sal_Int64 tmpLongVal = n; + sal_Int32 tmpIntVal; + + try + { + do { + if (tmpLongVal >= std::numeric_limits<sal_Int64>::max() ) + tmpIntVal = std::numeric_limits<sal_Int32>::max(); + else // Casting is safe here. + tmpIntVal = static_cast<sal_Int32>(tmpLongVal); + + tmpLongVal -= tmpIntVal; + + xIn->skipBytes(tmpIntVal); + + } while (tmpLongVal > 0); + } + catch(const Exception&) + { + } + + return n - tmpLongVal; + } + catch(const Exception& e) + { + OSL_FAIL("Exception caught! : skip();"); + StorageContainer::throwJavaException(e,env); + } + } + } + else + { + ThrowException( env, + "java/io/IOException", + "Stream is not valid"); + } + return 0; +} + + +/* + * Class: com_sun_star_sdbcx_comp_hsqldb_StorageNativeInputStream + * Method: available + * Signature: (Ljava/lang/String;Ljava/lang/String;)I + */ +extern "C" SAL_JNI_EXPORT jint JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeInputStream_available + (JNIEnv * env, jobject /*obj_this*/,jstring key, jstring name) +{ +#ifdef HSQLDB_DBG + OperationLogFile aOpLog( env, name, "input" ); + aOpLog.logOperation( "available" ); +#endif + + std::shared_ptr<StreamHelper> pHelper = StorageContainer::getRegisteredStream(env,name,key); + OSL_ENSURE(pHelper.get(),"No stream helper!"); + Reference<XInputStream> xIn = pHelper.get() ? pHelper->getInputStream() : Reference<XInputStream>(); + if ( xIn.is() ) + { + try + { + jint nAvailable = xIn->available(); +#ifdef HSQLDB_DBG + aOpLog.logReturn( nAvailable ); +#endif + return nAvailable; + } + catch(const Exception& e) + { + OSL_FAIL("Exception caught! : available();"); + StorageContainer::throwJavaException(e,env); + } + } + else + { + ThrowException( env, + "java/io/IOException", + "Stream is not valid"); + } + return 0; +} + + +/* + * Class: com_sun_star_sdbcx_comp_hsqldb_StorageNativeInputStream + * Method: read + * Signature: (Ljava/lang/String;Ljava/lang/String;[B)I + */ +extern "C" SAL_JNI_EXPORT jint JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_StorageNativeInputStream_read__Ljava_lang_String_2Ljava_lang_String_2_3B + (JNIEnv * env, jobject /*obj_this*/,jstring key, jstring name, jbyteArray buffer) +{ +#ifdef HSQLDB_DBG + OperationLogFile aOpLog( env, name, "input" ); + aOpLog.logOperation( "read( byte[] )" ); + + DataLogFile aDataLog( env, name, "input" ); +#endif + + std::shared_ptr<StreamHelper> pHelper = StorageContainer::getRegisteredStream(env,name,key); + Reference< XInputStream> xIn = pHelper.get() ? pHelper->getInputStream() : Reference< XInputStream>(); + OSL_ENSURE(xIn.is(),"Input stream is NULL!"); + jint nBytesRead = 0; + if ( xIn.is() ) + { + jsize nLen = env->GetArrayLength(buffer); + Sequence< ::sal_Int8 > aData(nLen); + + try + { + nBytesRead = xIn->readBytes(aData,nLen); + } + catch(const Exception& e) + { + OSL_FAIL("Exception caught! : skip();"); + StorageContainer::throwJavaException(e,env); + } + + // Casting bytesRead to an int is okay, since the user can + // only pass in an integer length to read, so the bytesRead + // must <= len. + + if (nBytesRead <= 0) { +#ifdef HSQLDB_DBG + aOpLog.logReturn( (jint)-1 ); +#endif + return -1; + } + OSL_ENSURE(nLen >= nBytesRead,"Buffer is too small!"); + OSL_ENSURE(aData.getLength() >= nBytesRead,"Buffer is too small!"); + env->SetByteArrayRegion(buffer, 0, nBytesRead, reinterpret_cast<jbyte*>(&aData[0])); +#ifdef HSQLDB_DBG + aDataLog.write( &aData[0], nBytesRead ); +#endif + } +#ifdef HSQLDB_DBG + aOpLog.logReturn( nBytesRead ); +#endif + return nBytesRead; +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/hsqldb/accesslog.cxx b/connectivity/source/drivers/hsqldb/accesslog.cxx new file mode 100644 index 000000000000..880600a71d5a --- /dev/null +++ b/connectivity/source/drivers/hsqldb/accesslog.cxx @@ -0,0 +1,78 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <sal/config.h> + +#ifdef HSQLDB_DBG + +#include <map> + +#include "accesslog.hxx" +#include "hsqldb/HStorageMap.hxx" + +#include <osl/thread.h> + +namespace connectivity { namespace hsqldb +{ + typedef std::map<OUString, FILE *> TDebugStreamMap; + TDebugStreamMap& getStreams() + { + static TDebugStreamMap streams; + return streams; + } + + + LogFile::LogFile( JNIEnv* env, jstring streamName, const sal_Char* _pAsciiSuffix ) + { + m_sFileName = StorageContainer::jstring2ustring(env,streamName) + + "." + OUString::createFromAscii( _pAsciiSuffix ); + } + + + FILE*& LogFile::getLogFile() + { + FILE*& pLogFile = getStreams()[m_sFileName]; + if ( !pLogFile ) + { + OString sByteLogName = OUStringToOString(m_sFileName,osl_getThreadTextEncoding()); + pLogFile = fopen( sByteLogName.getStr(), "a+" ); + } + return pLogFile; + } + + + void LogFile::writeString( const sal_Char* _pString, bool _bEndLine ) + { + FILE* pLogFile = getLogFile(); + fwrite( _pString, sizeof( *_pString ), strlen( _pString ), pLogFile ); + if ( _bEndLine ) + fwrite( "\n", sizeof( *_pString ), strlen( "\n" ), pLogFile ); + fflush( pLogFile ); + } + + + void LogFile::close() + { + fclose( getLogFile() ); + getLogFile() = NULL; + } +} } +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/hsqldb/accesslog.hxx b/connectivity/source/drivers/hsqldb/accesslog.hxx new file mode 100644 index 000000000000..bf34d9ffc190 --- /dev/null +++ b/connectivity/source/drivers/hsqldb/accesslog.hxx @@ -0,0 +1,138 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_HSQLDB_ACCESSLOG_HXX +#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_HSQLDB_ACCESSLOG_HXX + +#ifdef HSQLDB_DBG + +#include <jni.h> +#include <rtl/ustring.hxx> +#include <rtl/string.hxx> + +namespace connectivity { namespace hsqldb +{ + class LogFile + { + private: + OUString m_sFileName; + + public: + LogFile( JNIEnv* env, jstring streamName, const sal_Char* _pAsciiSuffix ); + + public: + void writeString( const sal_Char* _pString, bool _bEndLine = true ); + void create() { getLogFile(); } + virtual void close(); + + protected: + FILE*& getLogFile(); + }; + + class OperationLogFile : public LogFile + { + public: + OperationLogFile( JNIEnv* env, jstring streamName, const sal_Char* _pAsciiSuffix ) + :LogFile( env, streamName, ( OString( _pAsciiSuffix ) += ".op" ).getStr() ) + { + } + + void logOperation( const sal_Char* _pOp ) + { + writeString( _pOp, true ); + } + + void logOperation( const sal_Char* _pOp, jlong _nLongArg ) + { + OString sLine( _pOp ); + sLine += "( "; + sLine += OString::number( _nLongArg ); + sLine += " )"; + writeString( sLine.getStr(), true ); + } + + void logReturn( jlong _nRetVal ) + { + OString sLine( " -> " ); + sLine += OString::number( _nRetVal ); + writeString( sLine.getStr(), true ); + } + + void logReturn( jint _nRetVal ) + { + OString sLine( " -> " ); + sLine += OString::number( _nRetVal ); + writeString( sLine.getStr(), true ); + } + + virtual void close() + { + writeString( "-------------------------------", true ); + writeString( "", true ); + LogFile::close(); + } + }; + + class DataLogFile : public LogFile + { + public: + DataLogFile( JNIEnv* env, jstring streamName, const sal_Char* _pAsciiSuffix ) + :LogFile( env, streamName, _pAsciiSuffix ) + { + } + + void write( jint value ) + { + fputc( value, getLogFile() ); + fflush( getLogFile() ); + } + + void write( const sal_Int8* buffer, sal_Int32 bytesRead ) + { + fwrite( buffer, sizeof(sal_Int8), bytesRead, getLogFile() ); + fflush( getLogFile() ); + } + + sal_Int64 seek( sal_Int64 pos ) + { + FILE* pFile = getLogFile(); + fseek( pFile, 0, SEEK_END ); + if ( ftell( pFile ) < pos ) + { + sal_Int8 filler( 0 ); + while ( ftell( pFile ) < pos ) + fwrite( &filler, sizeof( sal_Int8 ), 1, pFile ); + fflush( pFile ); + } + fseek( pFile, pos, SEEK_SET ); + return ftell( pFile ); + } + + sal_Int64 tell() + { + return ftell( getLogFile() ); + } + }; + +} } +#endif + +#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_HSQLDB_ACCESSLOG_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/hsqldb/hsqldb.component b/connectivity/source/drivers/hsqldb/hsqldb.component new file mode 100644 index 000000000000..ab8318861416 --- /dev/null +++ b/connectivity/source/drivers/hsqldb/hsqldb.component @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + --> + +<component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@" + prefix="hsqldb" xmlns="http://openoffice.org/2010/uno-components"> + <implementation name="com.sun.star.sdbcx.comp.hsqldb.Driver"> + <service name="com.sun.star.sdbc.Driver"/> + <service name="com.sun.star.sdbcx.Driver"/> + </implementation> +</component> diff --git a/connectivity/source/inc/hsqldb/HCatalog.hxx b/connectivity/source/inc/hsqldb/HCatalog.hxx new file mode 100644 index 000000000000..f953c9f30ae1 --- /dev/null +++ b/connectivity/source/inc/hsqldb/HCatalog.hxx @@ -0,0 +1,64 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HCATALOG_HXX +#define INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HCATALOG_HXX + +#include <connectivity/sdbcx/VCatalog.hxx> + +namespace connectivity +{ + namespace hsqldb + { + // please don't name the class the same name as in an other namespaces + // some compilers have problems with this task as I noticed on windows + class OHCatalog : public connectivity::sdbcx::OCatalog + { + css::uno::Reference< css::sdbc::XConnection > m_xConnection; + + /** calls XDatabaseMetaData::getTables. + @param _sKindOfObject + The type of tables to be fetched. + @param _rNames + The container for the names to be filled. + */ + void refreshObjects(const css::uno::Sequence< OUString >& _sKindOfObject,::std::vector< OUString>& _rNames); + + public: + // implementation of the pure virtual methods + virtual void refreshTables() override; + virtual void refreshViews() override ; + virtual void refreshGroups() override; + virtual void refreshUsers() override ; + + public: + OHCatalog(const css::uno::Reference< css::sdbc::XConnection >& _xConnection); + + sdbcx::OCollection* getPrivateTables() const { return m_pTables.get(); } + sdbcx::OCollection* getPrivateViews() const { return m_pViews.get(); } + const css::uno::Reference< css::sdbc::XConnection >& getConnection() const { return m_xConnection; } + + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; + // ::cppu::OComponentHelper + virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; + }; + } +} +#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HCATALOG_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/hsqldb/HColumns.hxx b/connectivity/source/inc/hsqldb/HColumns.hxx new file mode 100644 index 000000000000..f3fd008cd92f --- /dev/null +++ b/connectivity/source/inc/hsqldb/HColumns.hxx @@ -0,0 +1,60 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HCOLUMNS_HXX +#define INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HCOLUMNS_HXX +#include <connectivity/TColumnsHelper.hxx> +#include <connectivity/sdbcx/VColumn.hxx> + +namespace connectivity +{ + namespace hsqldb + { + class OHSQLColumns : public OColumnsHelper + { + protected: + virtual css::uno::Reference< css::beans::XPropertySet > createDescriptor() override; + public: + OHSQLColumns( ::cppu::OWeakObject& _rParent + ,::osl::Mutex& _rMutex + ,const ::std::vector< OUString> &_rVector + ); + }; + + class OHSQLColumn; + typedef ::comphelper::OIdPropertyArrayUsageHelper<OHSQLColumn> OHSQLColumn_PROP; + + class OHSQLColumn : public sdbcx::OColumn, + public OHSQLColumn_PROP + { + OUString m_sAutoIncrement; + protected: + virtual ::cppu::IPropertyArrayHelper* createArrayHelper( sal_Int32 _nId) const override; + virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper() override; + + public: + OHSQLColumn(); + virtual void construct() override; + + virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override; + }; + } +} +#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HCOLUMNS_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/hsqldb/HConnection.hxx b/connectivity/source/inc/hsqldb/HConnection.hxx new file mode 100644 index 000000000000..19739437bf82 --- /dev/null +++ b/connectivity/source/inc/hsqldb/HConnection.hxx @@ -0,0 +1,150 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HCONNECTION_HXX +#define INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HCONNECTION_HXX + +#include <connectivity/ConnectionWrapper.hxx> +#include <com/sun/star/util/XFlushable.hpp> +#include <com/sun/star/sdbc/XDriver.hpp> +#include <com/sun/star/sdb/application/XTableUIProvider.hpp> +#include <com/sun/star/ui/dialogs/XExecutableDialog.hpp> +#include <cppuhelper/compbase.hxx> +#include <cppuhelper/basemutex.hxx> +#include <comphelper/uno3.hxx> +#include <comphelper/interfacecontainer2.hxx> + +namespace connectivity +{ + namespace hsqldb + { + class SAL_NO_VTABLE IMethodGuardAccess + { + public: + virtual ::osl::Mutex& getMutex() const = 0; + virtual void checkDisposed() const = 0; + + protected: + ~IMethodGuardAccess() {} + }; + + + // OHsqlConnection - wraps all methods to the real connection from the driver + // but when disposed it doesn't dispose the real connection + + typedef ::cppu::WeakComponentImplHelper< css::util::XFlushable + , css::sdb::application::XTableUIProvider + > OHsqlConnection_BASE; + + class OHsqlConnection :public cppu::BaseMutex + ,public OHsqlConnection_BASE + ,public OConnectionWrapper + ,public IMethodGuardAccess + { + private: + ::comphelper::OInterfaceContainerHelper2 m_aFlushListeners; + css::uno::Reference< css::sdbc::XDriver > m_xDriver; + css::uno::Reference< css::uno::XComponentContext > m_xContext; + bool m_bIni; + bool m_bReadOnly; + + protected: + virtual void SAL_CALL disposing() override; + virtual ~OHsqlConnection() override; + + public: + OHsqlConnection( + const css::uno::Reference< css::sdbc::XDriver >& _rxDriver, + const css::uno::Reference< css::sdbc::XConnection >& _xConnection, + const css::uno::Reference< css::uno::XComponentContext>& _rxContext + ); + + // XServiceInfo + DECLARE_SERVICE_INFO(); + DECLARE_XTYPEPROVIDER() + DECLARE_XINTERFACE( ) + + // IMethodGuardAccess + virtual ::osl::Mutex& getMutex() const override; + virtual void checkDisposed() const override; + + // XFlushable + virtual void SAL_CALL flush( ) override; + virtual void SAL_CALL addFlushListener( const css::uno::Reference< css::util::XFlushListener >& l ) override; + virtual void SAL_CALL removeFlushListener( const css::uno::Reference< css::util::XFlushListener >& l ) override; + + // XTableUIProvider + virtual css::uno::Reference< css::graphic::XGraphic > SAL_CALL getTableIcon( const OUString& TableName, ::sal_Int32 ColorMode ) override; + virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getTableEditor( const css::uno::Reference< css::sdb::application::XDatabaseDocumentUI >& DocumentUI, const OUString& TableName ) override; + + private: + + /** retrieves our table container + @return + our table container. Guaranteed to not be <NULL/>. + @throws css::lang::WrappedTargetException + if a non-RuntimeException is caught during obtaining the container. + @throws css::uno::RuntimeException + if a serious error occurs + @precond + We're not disposed. + */ + css::uno::Reference< css::container::XNameAccess > + impl_getTableContainer_throw(); + + /** checks whether the given table name denotes an existing table + @param _rTableName + the fully name of the table to check for existence + @throws css::lang::IllegalArgumentException + if the name does not denote an existing table + @precond + We're not disposed. + */ + void impl_checkExistingTable_throw( const OUString& _rTableName ); + + /** checks whether the given table name refers to a HSQL TEXT TABLE + */ + bool impl_isTextTable_nothrow( const OUString& _rTableName ); + + /** retrieves the icon for HSQL TEXT TABLEs + */ + css::uno::Reference< css::graphic::XGraphic > + impl_getTextTableIcon_nothrow(); + }; + + + // OHsqlConnection + + class MethodGuard : public ::osl::MutexGuard + { + private: + typedef ::osl::MutexGuard BaseGuard; + + public: + MethodGuard( const IMethodGuardAccess& _rComponent ) + :BaseGuard( _rComponent.getMutex() ) + { + _rComponent.checkDisposed(); + } + }; + } +} +#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HCONNECTION_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/hsqldb/HDriver.hxx b/connectivity/source/inc/hsqldb/HDriver.hxx new file mode 100644 index 000000000000..b88e1227de1c --- /dev/null +++ b/connectivity/source/inc/hsqldb/HDriver.hxx @@ -0,0 +1,140 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HDRIVER_HXX +#define INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HDRIVER_HXX + +#include <com/sun/star/sdbc/XDriver.hpp> +#include <com/sun/star/sdbcx/XDataDefinitionSupplier.hpp> +#include <com/sun/star/sdbcx/XCreateCatalog.hpp> +#include <com/sun/star/embed/XTransactionListener.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <cppuhelper/compbase.hxx> +#include <cppuhelper/basemutex.hxx> +#include <comphelper/uno3.hxx> +#include <connectivity/CommonTools.hxx> + + +namespace connectivity +{ + + + namespace hsqldb + { + /// @throws css::uno::Exception + css::uno::Reference< css::uno::XInterface > ODriverDelegator_CreateInstance(const css::uno::Reference< css::lang::XMultiServiceFactory >& _rxFactory); + + typedef ::cppu::WeakComponentImplHelper< css::sdbc::XDriver + , css::sdbcx::XDataDefinitionSupplier + , css::lang::XServiceInfo + , css::sdbcx::XCreateCatalog + , css::embed::XTransactionListener + > ODriverDelegator_BASE; + + typedef std::pair< css::uno::WeakReferenceHelper,css::uno::WeakReferenceHelper> TWeakRefPair; + typedef std::pair< OUString ,TWeakRefPair > TWeakConnectionPair; + + typedef std::pair< css::uno::WeakReferenceHelper,TWeakConnectionPair> TWeakPair; + typedef std::vector< TWeakPair > TWeakPairVector; + + + /** delegates all calls to the original driver and extend the existing one with the SDBCX layer. + + */ + class ODriverDelegator final : public ::cppu::BaseMutex + ,public ODriverDelegator_BASE + { + TWeakPairVector m_aConnections; // vector containing a list + // of all the Connection objects + // for this Driver + css::uno::Reference< css::sdbc::XDriver > m_xDriver; + css::uno::Reference< css::uno::XComponentContext > m_xContext; + bool m_bInShutDownConnections; + + /** load the driver we want to delegate. + The <member>m_xDriver</member> may be <NULL/> if the driver could not be loaded. + @return + The driver which was currently selected. + */ + css::uno::Reference< css::sdbc::XDriver > const & loadDriver( ); + + /** shut down the connection and revoke the storage from the map + @param _aIter + The connection to shut down and storage to revoke. + */ + void shutdownConnection(const TWeakPairVector::iterator& _aIter); + + public: + /** creates a new delegator for a HSQLDB driver + */ + ODriverDelegator(const css::uno::Reference< css::uno::XComponentContext >& _rxContext); + + // XServiceInfo + DECLARE_SERVICE_INFO(); + /// @throws css::uno::RuntimeException + static OUString getImplementationName_Static( ); + /// @throws css::uno::RuntimeException + static css::uno::Sequence< OUString > getSupportedServiceNames_Static( ); + + // XDriver + virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL connect( const OUString& url, const css::uno::Sequence< css::beans::PropertyValue >& info ) override; + virtual sal_Bool SAL_CALL acceptsURL( const OUString& url ) override; + virtual css::uno::Sequence< css::sdbc::DriverPropertyInfo > SAL_CALL getPropertyInfo( const OUString& url, const css::uno::Sequence< css::beans::PropertyValue >& info ) override; + virtual sal_Int32 SAL_CALL getMajorVersion( ) override; + virtual sal_Int32 SAL_CALL getMinorVersion( ) override; + + // XDataDefinitionSupplier + virtual css::uno::Reference< css::sdbcx::XTablesSupplier > SAL_CALL getDataDefinitionByConnection( const css::uno::Reference< css::sdbc::XConnection >& connection ) override; + virtual css::uno::Reference< css::sdbcx::XTablesSupplier > SAL_CALL getDataDefinitionByURL( const OUString& url, const css::uno::Sequence< css::beans::PropertyValue >& info ) override; + + // XCreateCatalog + virtual void SAL_CALL createCatalog( const css::uno::Sequence< css::beans::PropertyValue >& info ) override; + + // XEventListener + virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override; + + // XTransactionListener + virtual void SAL_CALL preCommit( const css::lang::EventObject& aEvent ) override; + virtual void SAL_CALL commited( const css::lang::EventObject& aEvent ) override; + virtual void SAL_CALL preRevert( const css::lang::EventObject& aEvent ) override; + virtual void SAL_CALL reverted( const css::lang::EventObject& aEvent ) override; + + void shutdownConnections(); + void flushConnections(); + private: + /// dtor + virtual ~ODriverDelegator() override; + // OComponentHelper + virtual void SAL_CALL disposing() override; + + /** called when we connected to a newly created embedded database + */ + void onConnectedNewDatabase( + const css::uno::Reference< css::sdbc::XConnection >& _rxConnection + ); + }; + } + + +} // namespace connectivity + +#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HDRIVER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/hsqldb/HStorageAccess.hxx b/connectivity/source/inc/hsqldb/HStorageAccess.hxx new file mode 100644 index 000000000000..c0ae65541530 --- /dev/null +++ b/connectivity/source/inc/hsqldb/HStorageAccess.hxx @@ -0,0 +1,39 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HSTORAGEACCESS_HXX +#define INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HSTORAGEACCESS_HXX + +#include <sal/config.h> + +#include <jni.h> + +namespace connectivity { namespace hsqldb +{ + class DataLogFile; +} } + +jint read_from_storage_stream( JNIEnv * env, jstring name, jstring key ); +jint read_from_storage_stream_into_buffer( JNIEnv * env, jstring name, jstring key, jbyteArray buffer, jint off, jint len ); +void write_to_storage_stream_from_buffer( JNIEnv* env, jstring name, jstring key, jbyteArray buffer, jint off, jint len ); +void write_to_storage_stream( JNIEnv* env, jstring name, jstring key, jint v ); + +#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HSTORAGEACCESS_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/hsqldb/HStorageMap.hxx b/connectivity/source/inc/hsqldb/HStorageMap.hxx new file mode 100644 index 000000000000..62ae7ec3d233 --- /dev/null +++ b/connectivity/source/inc/hsqldb/HStorageMap.hxx @@ -0,0 +1,97 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HSTORAGEMAP_HXX +#define INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HSTORAGEMAP_HXX + +#include <sal/config.h> + +#include <map> +#include <memory> + +#include <com/sun/star/embed/XStorage.hpp> +#include <com/sun/star/embed/XTransactionListener.hpp> +#include <com/sun/star/io/XStream.hpp> +#include <com/sun/star/io/XOutputStream.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/io/XSeekable.hpp> +#include <jni.h> +#include <uno/environment.hxx> + +namespace connectivity +{ + + namespace hsqldb + { + class StreamHelper + { + css::uno::Reference< css::io::XStream> m_xStream; + css::uno::Reference< css::io::XSeekable> m_xSeek; + css::uno::Reference< css::io::XOutputStream> m_xOutputStream; + css::uno::Reference< css::io::XInputStream> m_xInputStream; + public: + StreamHelper(const css::uno::Reference< css::io::XStream>& _xStream); + ~StreamHelper(); + + css::uno::Reference< css::io::XInputStream> const & getInputStream(); + css::uno::Reference< css::io::XOutputStream> const & getOutputStream(); + css::uno::Reference< css::io::XSeekable> const & getSeek(); + }; + + + typedef std::map< OUString, std::shared_ptr<StreamHelper> > TStreamMap; + + struct StorageData { + css::uno::Reference<css::embed::XStorage> storage; + css::uno::Environment storageEnvironment; + OUString url; + TStreamMap streams; + + css::uno::Reference<css::embed::XStorage> mapStorage() const; + }; + + typedef std::map<OUString, StorageData> TStorages; + /** contains all storages so far accessed. + */ + class StorageContainer + { + public: + static OUString registerStorage(const css::uno::Reference< css::embed::XStorage>& _xStorage,const OUString& _sURL); + static TStorages::mapped_type getRegisteredStorage(const OUString& _sKey); + static OUString getRegisteredKey(const css::uno::Reference< css::embed::XStorage>& _xStorage); + static void revokeStorage(const OUString& _sKey,const css::uno::Reference< css::embed::XTransactionListener>& _xListener); + + static TStreamMap::mapped_type registerStream(JNIEnv * env,jstring name, jstring key,sal_Int32 _nMode); + static void revokeStream(JNIEnv * env,jstring name, jstring key); + static TStreamMap::mapped_type getRegisteredStream( JNIEnv * env, jstring name, jstring key); + + static OUString jstring2ustring(JNIEnv * env, jstring jstr); + static OUString removeURLPrefix(const OUString& _sURL,const OUString& _sFileURL); + static OUString removeOldURLPrefix(const OUString& _sURL); + static void throwJavaException(const css::uno::Exception& _aException,JNIEnv * env); + }; + + } // namespace hsqldb + + +} // namespace connectivity + + +#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HSTORAGEMAP_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/hsqldb/HTable.hxx b/connectivity/source/inc/hsqldb/HTable.hxx new file mode 100644 index 000000000000..b479039cc7b0 --- /dev/null +++ b/connectivity/source/inc/hsqldb/HTable.hxx @@ -0,0 +1,116 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HTABLE_HXX +#define INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HTABLE_HXX + +#include <connectivity/TTableHelper.hxx> +#include <com/sun/star/sdbc/XDatabaseMetaData.hpp> +#include <comphelper/IdPropArrayHelper.hxx> + +namespace connectivity +{ + namespace hsqldb + { + + class OHSQLTable; + typedef ::comphelper::OIdPropertyArrayUsageHelper< OHSQLTable > OHSQLTable_PROP; + class OHSQLTable : public OTableHelper + ,public OHSQLTable_PROP + { + sal_Int32 m_nPrivileges; // we have to set our privileges by our own + + /** executes the statmenmt. + @param _rStatement + The statement to execute. + */ + void executeStatement(const OUString& _rStatement ); + protected: + + /** creates the column collection for the table + @param _rNames + The column names. + */ + virtual sdbcx::OCollection* createColumns(const ::std::vector< OUString>& _rNames) override; + + /** creates the key collection for the table + @param _rNames + The key names. + */ + virtual sdbcx::OCollection* createKeys(const ::std::vector< OUString>& _rNames) override; + + /** creates the index collection for the table + @param _rNames + The index names. + */ + virtual sdbcx::OCollection* createIndexes(const ::std::vector< OUString>& _rNames) override; + + /** used to implement the creation of the array helper which is shared amongst all instances of the class. + This method needs to be implemented in derived classes. + <BR> + The method gets called with s_aMutex acquired. + @return an pointer to the newly created array helper. Must not be NULL. + */ + virtual ::cppu::IPropertyArrayHelper* createArrayHelper(sal_Int32 nId) const override; + virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper() override; + + public: + OHSQLTable( sdbcx::OCollection* _pTables, + const css::uno::Reference< css::sdbc::XConnection >& _xConnection); + OHSQLTable( sdbcx::OCollection* _pTables, + const css::uno::Reference< css::sdbc::XConnection >& _xConnection, + const OUString& Name, + const OUString& Type, + const OUString& Description, + const OUString& SchemaName, + const OUString& CatalogName, + sal_Int32 _nPrivileges + ); + + // ODescriptor + virtual void construct() override; + // css::lang::XUnoTunnel + virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override; + static css::uno::Sequence< sal_Int8 > getUnoTunnelImplementationId(); + + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; + //XTypeProvider + virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; + // XAlterTable + virtual void SAL_CALL alterColumnByName( const OUString& colName, const css::uno::Reference< css::beans::XPropertySet >& descriptor ) override; + + // XRename + virtual void SAL_CALL rename( const OUString& newName ) override; + + /** + returns the ALTER TABLE XXX COLUMN statement + */ + OUString getAlterTableColumnPart(); + + // some methods to alter table structures + void alterColumnType(sal_Int32 nNewType,const OUString& _rColName,const css::uno::Reference< css::beans::XPropertySet >& _xDescriptor); + void alterDefaultValue(const OUString& _sNewDefault,const OUString& _rColName); + void dropDefaultValue(const OUString& _sNewDefault); + + }; + } +} +#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HTABLE_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/hsqldb/HTables.hxx b/connectivity/source/inc/hsqldb/HTables.hxx new file mode 100644 index 000000000000..bf0580396df2 --- /dev/null +++ b/connectivity/source/inc/hsqldb/HTables.hxx @@ -0,0 +1,56 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HTABLES_HXX +#define INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HTABLES_HXX + +#include <connectivity/sdbcx/VCollection.hxx> +#include <com/sun/star/sdbc/XDatabaseMetaData.hpp> +namespace connectivity +{ + namespace hsqldb + { + class OTables final : public sdbcx::OCollection + { + css::uno::Reference< css::sdbc::XDatabaseMetaData > m_xMetaData; + + virtual sdbcx::ObjectType createObject(const OUString& _rName) override; + virtual void impl_refresh() override; + virtual css::uno::Reference< css::beans::XPropertySet > createDescriptor() override; + virtual sdbcx::ObjectType appendObject( const OUString& _rForName, const css::uno::Reference< css::beans::XPropertySet >& descriptor ) override; + virtual void dropObject(sal_Int32 _nPos, const OUString& _sElementName) override; + + void createTable( const css::uno::Reference< css::beans::XPropertySet >& descriptor ); + virtual OUString getNameForObject(const sdbcx::ObjectType& _xObject) override; + public: + OTables(const css::uno::Reference< css::sdbc::XDatabaseMetaData >& _rMetaData,::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex, + const ::std::vector< OUString> &_rVector) : sdbcx::OCollection(_rParent, true, _rMutex, _rVector) + ,m_xMetaData(_rMetaData) + {} + + // only the name is identical to ::cppu::OComponentHelper + virtual void disposing() override; + + // XDrop + void appendNew(const OUString& _rsNewTable); + }; + } +} +#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HTABLES_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/hsqldb/HTools.hxx b/connectivity/source/inc/hsqldb/HTools.hxx new file mode 100644 index 000000000000..1c568ccc30cf --- /dev/null +++ b/connectivity/source/inc/hsqldb/HTools.hxx @@ -0,0 +1,52 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HTOOLS_HXX +#define INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HTOOLS_HXX + +#include <rtl/ustrbuf.hxx> + + +namespace connectivity { namespace hsqldb +{ + + class HTools + { + public: + /** appends a proper WHERE clause to the given buffer, which filters + for a given table name + + @param _bShortForm + <TRUE/> if the column names of the system table which is being asked + have the short form (TABLE_CAT instead of TABLE_CATALOG, and so on) + */ + static void appendTableFilterCrit( + OUStringBuffer& _inout_rBuffer, const OUString& _rCatalog, + const OUString& _rSchema, const OUString& _rName, + bool _bShortForm + ); + }; + + +} } // namespace connectivity::hsqldb + + +#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HTOOLS_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/hsqldb/HUser.hxx b/connectivity/source/inc/hsqldb/HUser.hxx new file mode 100644 index 000000000000..4e1e98c92290 --- /dev/null +++ b/connectivity/source/inc/hsqldb/HUser.hxx @@ -0,0 +1,77 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HUSER_HXX +#define INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HUSER_HXX + +#include <connectivity/sdbcx/VUser.hxx> +#include <com/sun/star/sdbc/XConnection.hpp> + +namespace connectivity +{ + namespace hsqldb + { + typedef connectivity::sdbcx::OUser OUser_TYPEDEF; + + class OHSQLUser : public OUser_TYPEDEF + { + css::uno::Reference< css::sdbc::XConnection > m_xConnection; + + static OUString getPrivilegeString(sal_Int32 nRights); + // return the privileges and additional the grant rights + /// @throws css::sdbc::SQLException + /// @throws css::uno::RuntimeException + void findPrivilegesAndGrantPrivileges(const OUString& objName, sal_Int32 objType,sal_Int32& nRights,sal_Int32& nRightsWithGrant); + public: + virtual void refreshGroups() override; + public: + OHSQLUser( const css::uno::Reference< css::sdbc::XConnection >& _xConnection); + OHSQLUser( const css::uno::Reference< css::sdbc::XConnection >& _xConnection,const OUString& Name); + + // XUser + virtual void SAL_CALL changePassword( const OUString& objPassword, const OUString& newPassword ) override; + // XAuthorizable + virtual sal_Int32 SAL_CALL getPrivileges( const OUString& objName, sal_Int32 objType ) override; + virtual sal_Int32 SAL_CALL getGrantablePrivileges( const OUString& objName, sal_Int32 objType ) override; + virtual void SAL_CALL grantPrivileges( const OUString& objName, sal_Int32 objType, sal_Int32 objPrivileges ) override; + virtual void SAL_CALL revokePrivileges( const OUString& objName, sal_Int32 objType, sal_Int32 objPrivileges ) override; + }; + + class OUserExtend; + typedef ::comphelper::OPropertyArrayUsageHelper<OUserExtend> OUserExtend_PROP; + + class OUserExtend : public OHSQLUser, + public OUserExtend_PROP + { + protected: + OUString m_Password; + // OPropertyArrayUsageHelper + virtual ::cppu::IPropertyArrayHelper* createArrayHelper() const override; + // OPropertySetHelper + virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper() override; + public: + OUserExtend(const css::uno::Reference< css::sdbc::XConnection >& _xConnection); + + virtual void construct() override; + }; + } +} +#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HUSER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/hsqldb/HUsers.hxx b/connectivity/source/inc/hsqldb/HUsers.hxx new file mode 100644 index 000000000000..392b3412a39b --- /dev/null +++ b/connectivity/source/inc/hsqldb/HUsers.hxx @@ -0,0 +1,55 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HUSERS_HXX +#define INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HUSERS_HXX + +#include <connectivity/sdbcx/VCollection.hxx> +#include <com/sun/star/sdbc/XConnection.hpp> +namespace connectivity +{ + namespace sdbcx + { + class IRefreshableUsers; + } + namespace hsqldb + { + class OUsers : public sdbcx::OCollection + { + css::uno::Reference< css::sdbc::XConnection > m_xConnection; + connectivity::sdbcx::IRefreshableUsers* m_pParent; + public: + virtual sdbcx::ObjectType createObject(const OUString& _rName) override; + virtual css::uno::Reference< css::beans::XPropertySet > createDescriptor() override; + virtual void impl_refresh() override; + virtual sdbcx::ObjectType appendObject( const OUString& _rForName, const css::uno::Reference< css::beans::XPropertySet >& descriptor ) override; + virtual void dropObject(sal_Int32 _nPos, const OUString& _sElementName) override; + public: + OUsers( ::cppu::OWeakObject& _rParent, + ::osl::Mutex& _rMutex, + const ::std::vector< OUString> &_rVector, + const css::uno::Reference< css::sdbc::XConnection >& _xConnection, + connectivity::sdbcx::IRefreshableUsers* _pParent); + }; + } +} + +#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HUSERS_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/hsqldb/HView.hxx b/connectivity/source/inc/hsqldb/HView.hxx new file mode 100644 index 000000000000..6e333bb1081d --- /dev/null +++ b/connectivity/source/inc/hsqldb/HView.hxx @@ -0,0 +1,90 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HVIEW_HXX +#define INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HVIEW_HXX + +#include <connectivity/sdbcx/VView.hxx> + +#include <com/sun/star/sdbcx/XAlterView.hpp> + +#include <comphelper/uno3.hxx> +#include <cppuhelper/implbase1.hxx> + + +namespace connectivity { namespace hsqldb +{ + + typedef ::connectivity::sdbcx::OView HView_Base; + typedef ::cppu::ImplHelper1< css::sdbcx::XAlterView > HView_IBASE; + class HView :public HView_Base + ,public HView_IBASE + { + public: + HView( + const css::uno::Reference< css::sdbc::XConnection >& _rxConnection, + bool _bCaseSensitive, + const OUString& _rSchemaName, + const OUString& _rName + ); + + // UNO + DECLARE_XINTERFACE() + DECLARE_XTYPEPROVIDER() + + // XAlterView + virtual void SAL_CALL alterCommand( const OUString& NewCommand ) override; + + protected: + virtual ~HView() override; + + protected: + // OPropertyContainer + virtual void SAL_CALL getFastPropertyValue( css::uno::Any& _rValue, sal_Int32 _nHandle ) const override; + + private: + /** retrieves the current command of the View */ + OUString impl_getCommand() const; + + /** retrieves the current command of the View + + @throws css::lang::WrappedTargetException + if an error occurs while retrieving the command from the database. + */ + OUString impl_getCommand_wrapSQLException() const; + /** retrieves the current command of the View + + @throws css::sdbc::SQLException + if an error occurs while retrieving the command from the database. + */ + OUString impl_getCommand_throwSQLException() const; + + private: + css::uno::Reference< css::sdbc::XConnection > m_xConnection; + private: + using HView_Base::getFastPropertyValue; + }; + + +} } // namespace connectivity::hsqldb + + +#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HVIEW_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/hsqldb/HViews.hxx b/connectivity/source/inc/hsqldb/HViews.hxx new file mode 100644 index 000000000000..6f6724383e32 --- /dev/null +++ b/connectivity/source/inc/hsqldb/HViews.hxx @@ -0,0 +1,55 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HVIEWS_HXX +#define INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HVIEWS_HXX + +#include <connectivity/sdbcx/VCollection.hxx> +#include <com/sun/star/sdbc/XDatabaseMetaData.hpp> +namespace connectivity +{ + namespace hsqldb + { + class HViews final : public sdbcx::OCollection + { + css::uno::Reference< css::sdbc::XConnection > m_xConnection; + css::uno::Reference< css::sdbc::XDatabaseMetaData > m_xMetaData; + bool m_bInDrop; + + virtual sdbcx::ObjectType createObject(const OUString& _rName) override; + virtual void impl_refresh() override; + virtual css::uno::Reference< css::beans::XPropertySet > createDescriptor() override; + virtual sdbcx::ObjectType appendObject( const OUString& _rForName, const css::uno::Reference< css::beans::XPropertySet >& descriptor ) override; + virtual void dropObject(sal_Int32 _nPos, const OUString& _sElementName) override; + + void createView( const css::uno::Reference< css::beans::XPropertySet >& descriptor ); + public: + HViews( + const css::uno::Reference< css::sdbc::XConnection >& _rxConnection, + ::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex, const ::std::vector< OUString> &_rVector ); + + // only the name is identical to ::cppu::OComponentHelper + virtual void disposing() override; + + void dropByNameImpl(const OUString& elementName); + }; + } +} +#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_HSQLDB_HVIEWS_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/CppunitTest_dbaccess_RowSetClones.mk b/dbaccess/CppunitTest_dbaccess_RowSetClones.mk index ddf69296cb28..2240a82b8761 100644 --- a/dbaccess/CppunitTest_dbaccess_RowSetClones.mk +++ b/dbaccess/CppunitTest_dbaccess_RowSetClones.mk @@ -17,6 +17,10 @@ $(eval $(call gb_CppunitTest_use_externals,dbaccess_RowSetClones,\ boost_headers \ )) +$(eval $(call gb_CppunitTest_use_jars,dbaccess_RowSetClones, \ + sdbc_hsqldb \ +)) + $(eval $(call gb_CppunitTest_use_libraries,dbaccess_RowSetClones, \ basegfx \ comphelper \ @@ -68,6 +72,8 @@ $(eval $(call gb_CppunitTest_use_components,dbaccess_RowSetClones,\ comphelper/util/comphelp \ configmgr/source/configmgr \ connectivity/source/drivers/firebird/firebird_sdbc \ + connectivity/source/drivers/hsqldb/hsqldb \ + connectivity/source/drivers/jdbc/jdbc \ connectivity/source/manager/sdbc2 \ dbaccess/util/dba \ dbaccess/util/dbu \ diff --git a/dbaccess/CppunitTest_dbaccess_embeddeddb_performancetest.mk b/dbaccess/CppunitTest_dbaccess_embeddeddb_performancetest.mk index 6a92256937b3..07de4d9e104f 100644 --- a/dbaccess/CppunitTest_dbaccess_embeddeddb_performancetest.mk +++ b/dbaccess/CppunitTest_dbaccess_embeddeddb_performancetest.mk @@ -47,6 +47,8 @@ $(eval $(call gb_CppunitTest_use_components,dbaccess_embeddeddb_performancetest, configmgr/source/configmgr \ connectivity/source/cpool/dbpool2 \ connectivity/source/drivers/firebird/firebird_sdbc \ + connectivity/source/drivers/hsqldb/hsqldb \ + connectivity/source/drivers/jdbc/jdbc \ connectivity/source/manager/sdbc2 \ dbaccess/util/dba \ dbaccess/source/filter/xml/dbaxml \ diff --git a/dbaccess/CppunitTest_dbaccess_hsqldb_test.mk b/dbaccess/CppunitTest_dbaccess_hsqldb_test.mk index bb4fd0c8e2d6..0a300f83f249 100644 --- a/dbaccess/CppunitTest_dbaccess_hsqldb_test.mk +++ b/dbaccess/CppunitTest_dbaccess_hsqldb_test.mk @@ -47,6 +47,8 @@ $(eval $(call gb_CppunitTest_use_components,dbaccess_hsqldb_test,\ configmgr/source/configmgr \ connectivity/source/cpool/dbpool2 \ connectivity/source/drivers/firebird/firebird_sdbc \ + connectivity/source/drivers/hsqldb/hsqldb \ + connectivity/source/drivers/jdbc/jdbc \ connectivity/source/manager/sdbc2 \ dbaccess/util/dba \ dbaccess/source/filter/xml/dbaxml \ @@ -69,6 +71,10 @@ $(eval $(call gb_CppunitTest_use_components,dbaccess_hsqldb_test,\ xmloff/util/xo \ )) +$(eval $(call gb_CppunitTest_use_jars,dbaccess_hsqldb_test,\ + sdbc_hsqldb \ +)) + $(eval $(call gb_CppunitTest_use_configuration,dbaccess_hsqldb_test)) # vim: set noet sw=4 ts=4: diff --git a/dbaccess/source/core/dataaccess/ModelImpl.cxx b/dbaccess/source/core/dataaccess/ModelImpl.cxx index 104c6328510a..d7e47ad61b05 100644 --- a/dbaccess/source/core/dataaccess/ModelImpl.cxx +++ b/dbaccess/source/core/dataaccess/ModelImpl.cxx @@ -382,7 +382,7 @@ ODatabaseModelImpl::ODatabaseModelImpl( const Reference< XComponentContext >& _r ,m_nControllerLockCount(0) { // some kind of default - m_sConnectURL = "sdbc:embedded:firebird"; + m_sConnectURL = "jdbc:"; m_aTableFilter.realloc(1); m_aTableFilter[0] = "%"; impl_construct_nothrow(); diff --git a/dbaccess/source/core/misc/dsntypes.cxx b/dbaccess/source/core/misc/dsntypes.cxx index ca10538029ab..361208c161d5 100644 --- a/dbaccess/source/core/misc/dsntypes.cxx +++ b/dbaccess/source/core/misc/dsntypes.cxx @@ -297,7 +297,7 @@ OUString ODsnTypeCollection::getEmbeddedDatabase() const } } if ( sEmbeddedDatabaseURL.isEmpty() ) - sEmbeddedDatabaseURL = "sdbc:embedded:firebird"; + sEmbeddedDatabaseURL = "sdbc:embedded:hsqldb"; return sEmbeddedDatabaseURL; } diff --git a/dbaccess/source/ui/dlg/generalpage.cxx b/dbaccess/source/ui/dlg/generalpage.cxx index 6dbfbe6d1285..12bfe24197b7 100644 --- a/dbaccess/source/ui/dlg/generalpage.cxx +++ b/dbaccess/source/ui/dlg/generalpage.cxx @@ -588,7 +588,7 @@ namespace dbaui { // Sets jdbc as the default selected database on startup. if (m_pRB_CreateDatabase->IsChecked() ) - return m_pCollection->getTypeDisplayName( "sdbc:embedded:firebird" ); + return m_pCollection->getTypeDisplayName( "jdbc:" ); return OGeneralPage::getDatasourceName( _rSet ); } diff --git a/distro-configs/LibreOfficeCoverity.conf b/distro-configs/LibreOfficeCoverity.conf index 376b9fbe577e..9d55f6811732 100644 --- a/distro-configs/LibreOfficeCoverity.conf +++ b/distro-configs/LibreOfficeCoverity.conf @@ -22,5 +22,7 @@ --enable-ext-wiki-publisher --enable-ext-nlpsolver --enable-online-update +--with-system-hsqldb +--with-hsqldb-jar=/home/coverity/hsqldb.jar --with-system-rhino --with-rhino-jar=/home/coverity/js.jar diff --git a/download.lst b/download.lst index 84faee431766..354c39285f43 100644 --- a/download.lst +++ b/download.lst @@ -96,6 +96,8 @@ export GRAPHITE_SHA256SUM := aa5e58356cd084000609ebbd93fef456a1bc0ab9e46fea20e81 export GRAPHITE_TARBALL := graphite2-minimal-1.3.10.tgz export HARFBUZZ_SHA256SUM := b5d6ac8415f97f3540d73f3f91c41c5c10f8a4d76350f11a7184062aae88ac0b export HARFBUZZ_TARBALL := harfbuzz-1.7.4.tar.bz2 +export HSQLDB_SHA256SUM := d30b13f4ba2e3b6a2d4f020c0dee0a9fb9fc6fbcc2d561f36b78da4bf3802370 +export HSQLDB_TARBALL := 17410483b5b5f267aa18b7e00b65e6e0-hsqldb_1_8_0.zip export HUNSPELL_SHA256SUM := 3cd9ceb062fe5814f668e4f22b2fa6e3ba0b339b921739541ce180cac4d6f4c4 export HUNSPELL_TARBALL := hunspell-1.6.2.tar.gz export HYPHEN_SHA256SUM := 304636d4eccd81a14b6914d07b84c79ebb815288c76fe027b9ebff6ff24d5705 diff --git a/external/Module_external.mk b/external/Module_external.mk index 57fff5b75dfc..317c14d64d87 100644 --- a/external/Module_external.mk +++ b/external/Module_external.mk @@ -45,6 +45,7 @@ $(eval $(call gb_Module_add_moduledirs,external,\ $(call gb_Helper_optional,GPGMEPP,gpgmepp) \ $(call gb_Helper_optional,GRAPHITE,graphite) \ $(call gb_Helper_optional,HARFBUZZ,harfbuzz) \ + $(call gb_Helper_optional,HSQLDB,hsqldb) \ $(call gb_Helper_optional,HUNSPELL,hunspell) \ $(call gb_Helper_optional,HYPHEN,hyphen) \ $(call gb_Helper_optional,ICU,icu) \ diff --git a/external/hsqldb/ExternalPackage_hsqldb.mk b/external/hsqldb/ExternalPackage_hsqldb.mk new file mode 100644 index 000000000000..e4dbb363b7d0 --- /dev/null +++ b/external/hsqldb/ExternalPackage_hsqldb.mk @@ -0,0 +1,16 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +$(eval $(call gb_ExternalPackage_ExternalPackage,hsqldb_project,hsqldb)) + +$(eval $(call gb_ExternalPackage_use_external_project,hsqldb_project,hsqldb)) + +$(eval $(call gb_ExternalPackage_add_file,hsqldb_project,$(LIBO_SHARE_JAVA_FOLDER)/hsqldb.jar,lib/hsqldb.jar)) + +# vim: set noet sw=4 ts=4: diff --git a/external/hsqldb/ExternalProject_hsqldb.mk b/external/hsqldb/ExternalProject_hsqldb.mk new file mode 100644 index 000000000000..4ecc00af978f --- /dev/null +++ b/external/hsqldb/ExternalProject_hsqldb.mk @@ -0,0 +1,28 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +$(eval $(call gb_ExternalProject_ExternalProject,hsqldb)) + +$(eval $(call gb_ExternalProject_register_targets,hsqldb,\ + build \ +)) + +$(call gb_ExternalProject_get_state_target,hsqldb,build) : + $(call gb_ExternalProject_run,build,\ + $(ICECREAM_RUN) "$(ANT)" \ + $(if $(verbose),-v,-q) \ + -f build/build.xml \ + -Dbuild.label="build-$(LIBO_VERSION_MAJOR).$(LIBO_VERSION_MINOR).$(LIBO_VERSION_MICRO).$(LIBO_VERSION_PATCH)" \ + -Dant.build.javac.source=$(JAVA_SOURCE_VER) \ + -Dant.build.javac.target=$(JAVA_TARGET_VER) \ + $(if $(debug),-Dbuild.debug="on") \ + jar \ + ) + +# vim: set noet sw=4 ts=4: diff --git a/external/hsqldb/Makefile b/external/hsqldb/Makefile new file mode 100644 index 000000000000..e4968cf85fb6 --- /dev/null +++ b/external/hsqldb/Makefile @@ -0,0 +1,7 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- + +module_directory:=$(dir $(realpath $(firstword $(MAKEFILE_LIST)))) + +include $(module_directory)/../../solenv/gbuild/partial_build.mk + +# vim: set noet sw=4 ts=4: diff --git a/external/hsqldb/Module_hsqldb.mk b/external/hsqldb/Module_hsqldb.mk new file mode 100644 index 000000000000..d748faa2e0e2 --- /dev/null +++ b/external/hsqldb/Module_hsqldb.mk @@ -0,0 +1,18 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +$(eval $(call gb_Module_Module,hsqldb)) + +$(eval $(call gb_Module_add_targets,hsqldb,\ + ExternalPackage_hsqldb \ + ExternalProject_hsqldb \ + UnpackedTarball_hsqldb \ +)) + +# vim: set noet sw=4 ts=4: diff --git a/external/hsqldb/README b/external/hsqldb/README new file mode 100644 index 000000000000..7d7f89f0407c --- /dev/null +++ b/external/hsqldb/README @@ -0,0 +1,11 @@ +Java database engine from [http://hsqldb.org/]. + +Default database format for LibreOffice. + +At some point the plan was to replace it as default by Firebird, but +that seems increasingly unlikely to happen. + +See: +https://bugs.freedesktop.org/show_bug.cgi?id=51781 +http://www.firebirdsql.org + diff --git a/external/hsqldb/UnpackedTarball_hsqldb.mk b/external/hsqldb/UnpackedTarball_hsqldb.mk new file mode 100644 index 000000000000..fc6c18f77c23 --- /dev/null +++ b/external/hsqldb/UnpackedTarball_hsqldb.mk @@ -0,0 +1,33 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +$(eval $(call gb_UnpackedTarball_UnpackedTarball,hsqldb)) + +$(eval $(call gb_UnpackedTarball_set_tarball,hsqldb,$(HSQLDB_TARBALL),,hsqldb)) + +$(eval $(call gb_UnpackedTarball_fix_end_of_line,hsqldb,\ + build/build.xml \ + src/org/hsqldb/Library.java \ + src/org/hsqldb/persist/HsqlDatabaseProperties.java \ +)) + +$(eval $(call gb_UnpackedTarball_add_patches,hsqldb,\ + external/hsqldb/patches/i96823.patch \ + external/hsqldb/patches/i97032.patch \ + external/hsqldb/patches/i103528.patch \ + external/hsqldb/patches/i104901.patch \ + external/hsqldb/patches/fdo36824.patch \ + external/hsqldb/patches/limit_as_table_alias.patch \ + $(if $(HSQLDB_USE_JDBC_4_1),\ + external/hsqldb/patches/jdbc-4.1.patch \ + external/hsqldb/patches/multipleResultSets.patch \ + ) \ +)) + +# vim: set noet sw=4 ts=4: diff --git a/external/hsqldb/patches/fdo36824.patch b/external/hsqldb/patches/fdo36824.patch new file mode 100644 index 000000000000..ad753e335bad --- /dev/null +++ b/external/hsqldb/patches/fdo36824.patch @@ -0,0 +1,11 @@ +--- misc/hsqldb/src/org/hsqldb/Expression.java 2012-07-03 19:49:00.000000000 +0200 ++++ misc/build/hsqldb/src/org/hsqldb/Expression.java 2012-07-03 19:39:00.000000000 +0200 +@@ -1552,7 +1552,7 @@ + return columnQuoted; + } + +- return false; ++ return true; + } + + /** diff --git a/external/hsqldb/patches/i103528.patch b/external/hsqldb/patches/i103528.patch new file mode 100644 index 000000000000..3cc7d2f1d80d --- /dev/null +++ b/external/hsqldb/patches/i103528.patch @@ -0,0 +1,11 @@ +--- misc/hsqldb/src/org/hsqldb/Library.java ++++ misc/build/hsqldb/src/org/hsqldb/Library.java +@@ -1957,7 +1957,7 @@ + functionMap.put("bitand", bitand); + functionMap.put("bitlength", bitLength); + functionMap.put("bitor", bitor); +- functionMap.put("bitxor", bitor); ++ functionMap.put("bitxor", bitxor); + functionMap.put("character", character); + functionMap.put("concat", concat); + functionMap.put("cot", cot); diff --git a/external/hsqldb/patches/i104901.patch b/external/hsqldb/patches/i104901.patch new file mode 100644 index 000000000000..a38773f4ba1e --- /dev/null +++ b/external/hsqldb/patches/i104901.patch @@ -0,0 +1,27 @@ +--- misc/hsqldb/src/org/hsqldb/Table.java 2007-10-19 23:59:07.000000000 +0200 ++++ misc/build/hsqldb/src/org/hsqldb/Table.java 2009-09-11 13:45:42.939231519 +0200 +@@ -149,10 +149,10 @@ + Constraint[] constraintList; // constrainst for the table + HsqlArrayList[] triggerLists; // array of trigger lists + private int[] colTypes; // fredt - types of columns +- private int[] colSizes; // fredt - copy of SIZE values for columns ++ int[] colSizes; // fredt - copy of SIZE values for columns + private int[] colScales; // fredt - copy of SCALE values for columns + private boolean[] colNullable; // fredt - modified copy of isNullable() values +- private Expression[] colDefaults; // fredt - expressions of DEFAULT values ++ Expression[] colDefaults; // fredt - expressions of DEFAULT values + private int[] defaultColumnMap; // fred - holding 0,1,2,3,... + private boolean hasDefaultValues; //fredt - shortcut for above + boolean sqlEnforceSize; // inherited from the database - +--- misc/hsqldb/src/org/hsqldb/TableWorks.java 2007-01-14 06:48:16.000000000 +0100 ++++ misc/build/hsqldb/src/org/hsqldb/TableWorks.java 2009-09-11 13:47:50.328667463 +0200 +@@ -670,7 +670,8 @@ + // default expressions can change + oldCol.setType(newCol); + oldCol.setDefaultExpression(newCol.getDefaultExpression()); +- table.setColumnTypeVars(colIndex); ++ table.colSizes[colIndex] = oldCol.getSize(); ++ table.colDefaults[colIndex] = oldCol.getDefaultExpression(); + table.resetDefaultsFlag(); + + return; diff --git a/external/hsqldb/patches/i96823.patch b/external/hsqldb/patches/i96823.patch new file mode 100644 index 000000000000..bea4a2b7e4f5 --- /dev/null +++ b/external/hsqldb/patches/i96823.patch @@ -0,0 +1,94 @@ +--- misc/hsqldb/src/org/hsqldb/Expression.java 2008-05-27 17:15:05.000000000 +0200 ++++ misc/build/hsqldb/src/org/hsqldb/Expression.java 2009-01-27 11:42:16.890625000 +0100 +@@ -803,61 +803,62 @@ + + case EXISTS : + buf.append(' ').append(Token.T_EXISTS).append(' '); +- break; ++ ++ return buf.toString(); + + case COUNT : + buf.append(' ').append(Token.T_COUNT).append('('); +- break; ++ if ( "(*)".equals(left))buf.append('*');else buf.append(left); buf.append(')'); return buf.toString(); + + case SUM : + buf.append(' ').append(Token.T_SUM).append('('); + buf.append(left).append(')'); +- break; ++ return buf.toString(); + + case MIN : + buf.append(' ').append(Token.T_MIN).append('('); + buf.append(left).append(')'); +- break; ++ return buf.toString(); + + case MAX : + buf.append(' ').append(Token.T_MAX).append('('); + buf.append(left).append(')'); +- break; ++ return buf.toString(); + + case AVG : + buf.append(' ').append(Token.T_AVG).append('('); + buf.append(left).append(')'); +- break; ++ return buf.toString(); + + case EVERY : + buf.append(' ').append(Token.T_EVERY).append('('); + buf.append(left).append(')'); +- break; ++ return buf.toString(); + + case SOME : + buf.append(' ').append(Token.T_SOME).append('('); + buf.append(left).append(')'); +- break; ++ return buf.toString(); + + case STDDEV_POP : + buf.append(' ').append(Token.T_STDDEV_POP).append('('); + buf.append(left).append(')'); +- break; ++ return buf.toString(); + + case STDDEV_SAMP : + buf.append(' ').append(Token.T_STDDEV_SAMP).append('('); + buf.append(left).append(')'); +- break; ++ return buf.toString(); + + case VAR_POP : + buf.append(' ').append(Token.T_VAR_POP).append('('); + buf.append(left).append(')'); +- break; ++ return buf.toString(); + + case VAR_SAMP : + buf.append(' ').append(Token.T_VAR_SAMP).append('('); + buf.append(left).append(')'); +- break; ++ return buf.toString(); + } + + throw Trace.error(Trace.EXPRESSION_NOT_SUPPORTED); +@@ -1522,6 +1523,16 @@ + if (exprType == COLUMN) { + return columnName; + } ++ if ( isAggregate(exprType) ) ++ { ++ try ++ { ++ return getDDL(); ++ } ++ catch(Exception e) ++ { ++ } ++ } + + return ""; + } diff --git a/external/hsqldb/patches/i97032.patch b/external/hsqldb/patches/i97032.patch new file mode 100644 index 000000000000..9703b89613d4 --- /dev/null +++ b/external/hsqldb/patches/i97032.patch @@ -0,0 +1,10 @@ +--- misc/hsqldb/src/org/hsqldb/persist/HsqlDatabaseProperties.java 2008-03-17 17:05:41.000000000 +0100 ++++ misc/build/hsqldb/src/org/hsqldb/persist/HsqlDatabaseProperties.java 2009-01-21 13:09:24.493470142 +0100 +@@ -429,6 +429,7 @@ + setProperty(hsqldb_log_size, 10); + setProperty(sql_enforce_strict_size, true); + setProperty(hsqldb_nio_data_file, false); ++ setProperty(hsqldb_lock_file, true); + } + + // OOo end diff --git a/external/hsqldb/patches/jdbc-4.1.patch b/external/hsqldb/patches/jdbc-4.1.patch new file mode 100644 index 000000000000..7884148c5fb4 --- /dev/null +++ b/external/hsqldb/patches/jdbc-4.1.patch @@ -0,0 +1,320 @@ +--- misc/hsqldb/build/build.xml 2012-07-12 10:58:11.000000000 +0200 ++++ misc/build/hsqldb/build/build.xml 2012-07-12 10:49:28.000000000 +0200 +@@ -98,16 +98,24 @@ + <echo message="ant.java.hasjsse=${ant.java.hasjsse}" /> + </target> + +- <target name="javaversion6"> ++ <target name="javaversion7" unless="ant.java.iscjavaset"> ++ <available classname="java.util.Objects" property="ant.java.iscjava17"/> ++ <available classname="java.util.Objects" property="ant.java.iscjavaset"/> ++ </target> ++ ++ <target name="javaversion6" depends="javaversion7" unless="ant.java.iscjavaset"> + <available classname="java.net.IDN" property="ant.java.iscjava16"/> ++ <available classname="java.net.IDN" property="ant.java.iscjavaset"/> + </target> + +- <target name="javaversion4" depends="javaversion6" unless="ant.java.iscjava16"> ++ <target name="javaversion4" depends="javaversion6" unless="ant.java.iscjavaset"> + <available classname="java.nio.Buffer" property="ant.java.iscjava14"/> ++ <available classname="java.nio.Buffer" property="ant.java.iscjavaset"/> + </target> + +- <target name="javaversion2" depends="javaversion4" unless="ant.java.iscjava14"> ++ <target name="javaversion2" depends="javaversion4" unless="ant.java.iscjavaset"> + <available classname="java.lang.ref.Reference" property="ant.java.iscjava12"/> ++ <available classname="java.lang.ref.Reference" property="ant.java.iscjavaset"/> + </target> + + <target name="-prepare" depends="init,javaversion2"> +@@ -166,6 +177,7 @@ + <java classname="org.hsqldb.util.CodeSwitcher" classpath="classes" > + <arg file="${src}/org/hsqldb/lib/java/JavaSystem.java"/> + <arg file="${src}/org/hsqldb/lib/HsqlTimer.java"/> ++ <arg file="${src}/org/hsqldb/jdbcDriver.java"/> + <arg file="${src}/org/hsqldb/jdbc/jdbcStatement.java"/> + <arg file="${src}/org/hsqldb/persist/LockFile.java"/> + <arg file="${src}/org/hsqldb/persist/Logger.java"/> +@@ -183,6 +195,7 @@ + <java classname="org.hsqldb.util.CodeSwitcher" classpath="classes" > + <arg file="${src}/org/hsqldb/lib/java/JavaSystem.java"/> + <arg file="${src}/org/hsqldb/lib/HsqlTimer.java"/> ++ <arg file="${src}/org/hsqldb/jdbcDriver.java"/> + <arg file="${src}/org/hsqldb/jdbc/jdbcBlob.java"/> + <arg file="${src}/org/hsqldb/jdbc/jdbcDatabaseMetaData.java"/> + <arg file="${src}/org/hsqldb/jdbc/jdbcDataSource.java"/> +@@ -210,6 +223,7 @@ + <arg value="+JAVA2FULL"/> + <arg value="-JAVA4"/> + <arg value="-JAVA6"/> ++ <arg value="-JAVA7"/> + </java> + </target> + +@@ -218,6 +232,7 @@ + <java classname="org.hsqldb.util.CodeSwitcher" classpath="classes" > + <arg file="${src}/org/hsqldb/lib/java/JavaSystem.java"/> + <arg file="${src}/org/hsqldb/lib/HsqlTimer.java"/> ++ <arg file="${src}/org/hsqldb/jdbcDriver.java"/> + <arg file="${src}/org/hsqldb/jdbc/jdbcBlob.java"/> + <arg file="${src}/org/hsqldb/jdbc/jdbcDatabaseMetaData.java"/> + <arg file="${src}/org/hsqldb/jdbc/jdbcDataSource.java"/> +@@ -244,6 +259,7 @@ + <arg value="+JAVA2FULL"/> + <arg value="+JAVA4"/> + <arg value="-JAVA6"/> ++ <arg value="-JAVA7"/> + </java> + </target> + +@@ -253,6 +269,43 @@ + <java classname="org.hsqldb.util.CodeSwitcher" classpath="classes" > + <arg file="${src}/org/hsqldb/lib/java/JavaSystem.java"/> + <arg file="${src}/org/hsqldb/lib/HsqlTimer.java"/> ++ <arg file="${src}/org/hsqldb/jdbcDriver.java"/> ++ <arg file="${src}/org/hsqldb/jdbc/jdbcBlob.java"/> ++ <arg file="${src}/org/hsqldb/jdbc/jdbcDatabaseMetaData.java"/> ++ <arg file="${src}/org/hsqldb/jdbc/jdbcDataSource.java"/> ++ <arg file="${src}/org/hsqldb/jdbc/jdbcCallableStatement.java"/> ++ <arg file="${src}/org/hsqldb/jdbc/jdbcClob.java"/> ++ <arg file="${src}/org/hsqldb/jdbc/jdbcConnection.java"/> ++ <arg file="${src}/org/hsqldb/jdbc/jdbcParameterMetaData.java"/> ++ <arg file="${src}/org/hsqldb/jdbc/jdbcPreparedStatement.java"/> ++ <arg file="${src}/org/hsqldb/jdbc/jdbcResultSet.java"/> ++ <arg file="${src}/org/hsqldb/jdbc/jdbcResultSetMetaData.java"/> ++ <arg file="${src}/org/hsqldb/jdbc/jdbcStatement.java"/> ++ <arg file="${src}/org/hsqldb/persist/LockFile.java"/> ++ <arg file="${src}/org/hsqldb/persist/Logger.java"/> ++ <arg file="${src}/org/hsqldb/persist/ScaledRAFile.java"/> ++ <arg file="${src}/org/hsqldb/rowio/RowInputTextLog.java"/> ++ <arg file="${src}/org/hsqldb/util/DatabaseManager.java"/> ++ <arg file="${src}/org/hsqldb/util/ConnectionDialogCommon.java"/> ++ <arg file="${src}/org/hsqldb/lib/SimpleLog.java"/> ++ <arg file="${src}/org/hsqldb/rowio/RowInputTextLog.java"/> ++ <arg file="${src}/org/hsqldb/lib/SimpleLog.java"/> ++ <arg file="${src}/org/hsqldb/rowio/RowInputTextLog.java"/> ++ <arg file="${src}/org/hsqldb/HsqlDateTime.java"/> ++ <arg value="+JAVA2"/> ++ <arg value="+JAVA2FULL"/> ++ <arg value="+JAVA4"/> ++ <arg value="+JAVA6"/> ++ <arg value="-JAVA7"/> ++ </java> ++ </target> ++ ++ <target name="switchtojdk17" depends="switchtojdk16" ++ description="self explanatory" if="ant.java.iscjava17"> ++ <java classname="org.hsqldb.util.CodeSwitcher" classpath="classes" > ++ <arg file="${src}/org/hsqldb/lib/java/JavaSystem.java"/> ++ <arg file="${src}/org/hsqldb/lib/HsqlTimer.java"/> ++ <arg file="${src}/org/hsqldb/jdbcDriver.java"/> + <arg file="${src}/org/hsqldb/jdbc/jdbcBlob.java"/> + <arg file="${src}/org/hsqldb/jdbc/jdbcDatabaseMetaData.java"/> + <arg file="${src}/org/hsqldb/jdbc/jdbcDataSource.java"/> +@@ -279,10 +332,11 @@ + <arg value="+JAVA2FULL"/> + <arg value="+JAVA4"/> + <arg value="+JAVA6"/> ++ <arg value="+JAVA7"/> + </java> + </target> + +- <target name="store" depends="switchtojdk16" ++ <target name="store" depends="switchtojdk17" + description="compiles the /store folder"> + <javac srcdir="${src}" + destdir="classes" +--- misc/hsqldb/src/org/hsqldb/jdbc/jdbcCallableStatement.java 2012-02-08 15:14:42.802123563 +0000 ++++ misc/build/hsqldb/src/org/hsqldb/jdbc/jdbcCallableStatement.java 2012-02-08 15:47:35.842635642 +0000 +@@ -3375,4 +3375,18 @@ + */ + + //#endif JAVA6 ++ ++//#ifdef JAVA7 ++ public <T> T getObject(String columnLabel, Class<T> type) throws SQLException ++ { ++ throw new UnsupportedOperationException("Not supported yet."); ++ } ++ ++ public <T> T getObject(int ColumnIndex, Class<T> type) throws SQLException ++ { ++ throw new UnsupportedOperationException("Not supported yet."); ++ } ++ ++ ++//#endif JAVA7 + } +--- misc/hsqldb/src/org/hsqldb/jdbc/jdbcConnection.java 2012-02-08 15:14:42.802123563 +0000 ++++ misc/build/hsqldb/src/org/hsqldb/jdbc/jdbcConnection.java 2012-02-08 15:47:35.851635628 +0000 +@@ -48,6 +48,12 @@ + */ + + //#endif JAVA6 ++ ++//#ifdef JAVA7 ++import java.util.concurrent.Executor; ++ ++//#endif JAVA7 ++ + import java.sql.PreparedStatement; + import java.sql.SQLException; + import java.sql.SQLWarning; +@@ -2793,4 +2799,31 @@ + */ + + //#endif JAVA6 ++ ++//#ifdef JAVA7 ++ public int getNetworkTimeout() throws SQLException ++ { ++ throw new UnsupportedOperationException("Not supported yet."); ++ } ++ ++ public void setNetworkTimeout(Executor executor, int millis) throws SQLException ++ { ++ throw new UnsupportedOperationException("Not supported yet."); ++ } ++ ++ public void abort(Executor executor) throws SQLException ++ { ++ throw new UnsupportedOperationException("Not supported yet."); ++ } ++ ++ public String getSchema() throws SQLException ++ { ++ throw new UnsupportedOperationException("Not supported yet."); ++ } ++ ++ public void setSchema(String schema) throws SQLException ++ { ++ throw new UnsupportedOperationException("Not supported yet."); ++ } ++//#endif JAVA7 + } +--- misc/hsqldb/src/org/hsqldb/jdbc/jdbcDatabaseMetaData.java 2012-02-08 15:14:42.802123563 +0000 ++++ misc/build/hsqldb/src/org/hsqldb/jdbc/jdbcDatabaseMetaData.java 2012-02-08 15:47:35.835635654 +0000 +@@ -5693,4 +5693,21 @@ + */ + + //#endif JAVA6 ++ ++ ++//#ifdef JAVA7 ++ public boolean generatedKeyAlwaysReturned() throws SQLException ++ { ++ throw new UnsupportedOperationException("Not supported yet."); ++ } ++ ++ public ResultSet getPseudoColumns(String catalog, String schemaPattern, ++ String tableNamePattern, String columnNamePattern) throws SQLException ++ { ++ throw new UnsupportedOperationException("Not supported yet."); ++ } ++ ++ ++//#endif JAVA7 ++ + } +--- misc/hsqldb/src/org/hsqldb/jdbc/jdbcDataSource.java 2012-02-08 15:14:42.802123563 +0000 ++++ misc/build/hsqldb/src/org/hsqldb/jdbc/jdbcDataSource.java 2012-02-08 15:47:35.836635653 +0000 +@@ -47,6 +47,11 @@ + //#endif JAVA4 + import org.hsqldb.jdbcDriver; + ++//#ifdef JAVA7 ++import java.sql.SQLFeatureNotSupportedException; ++import java.util.logging.Logger; ++//#endif JAVA7 ++ + // boucherb@users 20040411 - doc 1.7.2 - javadoc updates toward 1.7.2 final + + /** +@@ -323,4 +328,15 @@ + */ + + //#endif JAVA6 ++ ++//#ifdef JAVA7 ++ public Logger getParentLogger() throws SQLFeatureNotSupportedException ++ { ++ throw new AbstractMethodError( ++ "org.hsqldb.jdbc.jdbcDataSource.getParentLogger should throw" + ++ " SQLFeatureNotSupportedException, but that is not yet available" + ++ " in Java 5"); ++ } ++ ++//#endif JAVA7 + } +--- misc/hsqldb/src/org/hsqldb/jdbc/jdbcResultSet.java 2012-02-08 15:14:42.802123563 +0000 ++++ misc/build/hsqldb/src/org/hsqldb/jdbc/jdbcResultSet.java 2012-02-08 15:47:35.866635606 +0000 +@@ -5324,4 +5324,19 @@ + */ + + //#endif JAVA6 ++ ++//#ifdef JAVA7 ++ ++ public <T> T getObject(String columnLabel, Class<T> type) throws SQLException ++ { ++ throw new UnsupportedOperationException("Not supported yet."); ++ } ++ ++ public <T> T getObject(int columnNum, Class<T> type) throws SQLException ++ { ++ throw new UnsupportedOperationException("Not supported yet."); ++ } ++ ++//#endif JAVA7 ++ + } +--- misc/hsqldb/src/org/hsqldb/jdbc/jdbcStatement.java 2012-02-08 15:14:42.802123563 +0000 ++++ misc/build/hsqldb/src/org/hsqldb/jdbc/jdbcStatement.java 2012-02-08 15:47:35.872635595 +0000 +@@ -1608,4 +1608,16 @@ + } + */ + //#endif JAVA6 ++ ++//#ifdef JAVA7 ++ public boolean isCloseOnCompletion() throws SQLException ++ { ++ throw new UnsupportedOperationException("Not supported yet."); ++ } ++ ++ public void closeOnCompletion() throws SQLException ++ { ++ throw new UnsupportedOperationException("Not supported yet."); ++ } ++//#endif JAVA7 + } +--- misc/hsqldb/src/org/hsqldb/jdbcDriver.java 2012-02-08 15:14:42.800123566 +0000 ++++ misc/build/hsqldb/src/org/hsqldb/jdbcDriver.java 2012-02-08 15:47:35.826635667 +0000 +@@ -42,6 +42,11 @@ + import org.hsqldb.persist.HsqlDatabaseProperties; + import org.hsqldb.persist.HsqlProperties; + ++//#ifdef JAVA7 ++import java.sql.SQLFeatureNotSupportedException; ++import java.util.logging.Logger; ++//#endif JAVA7 ++ + // fredt@users 20011220 - patch 1.7.0 by fredt + // new version numbering scheme + // fredt@users 20020320 - patch 1.7.0 - JDBC 2 support and error trapping +@@ -321,4 +326,15 @@ + DriverManager.registerDriver(new jdbcDriver()); + } catch (Exception e) {} + } ++ ++//#ifdef JAVA7 ++ public Logger getParentLogger() throws SQLFeatureNotSupportedException ++ { ++ throw new AbstractMethodError( ++ "org.hsqldb.jdbcDriver.getParentLogger should throw" + ++ " SQLFeatureNotSupportedException, but that is not yet available" + ++ " in Java 5"); ++ } ++ ++//#endif JAVA7 + } diff --git a/external/hsqldb/patches/limit_as_table_alias.patch b/external/hsqldb/patches/limit_as_table_alias.patch new file mode 100644 index 000000000000..09f49ccd561d --- /dev/null +++ b/external/hsqldb/patches/limit_as_table_alias.patch @@ -0,0 +1,11 @@ +--- misc/hsqldb/src/org/hsqldb/Token.java 2013-06-13 10:04:28.975934479 +0200 ++++ misc/build/hsqldb/src/org/hsqldb/Token.java 2013-06-13 10:06:09.915931966 +0200 +@@ -819,7 +819,7 @@ + Token.T_EXTRACT, Token.T_FOR, Token.T_FROM, Token.T_GROUP, + Token.T_HAVING, Token.T_IF, Token.T_INTO, Token.T_IFNULL, + Token.T_IS, Token.T_IN, Token.T_INTERSECT, Token.T_JOIN, +- Token.T_INNER, Token.T_LEADING, Token.T_LIKE, Token.T_MAX, ++ Token.T_INNER, Token.T_LEADING, Token.T_LIKE, Token.T_LIMIT, Token.T_MAX, + Token.T_MIN, Token.T_NEXT, Token.T_NULLIF, Token.T_NOT, + Token.T_NVL, Token.T_MINUS, Token.T_ON, Token.T_ORDER, Token.T_OR, + Token.T_OUTER, Token.T_POSITION, Token.T_PRIMARY, Token.T_SELECT, diff --git a/external/hsqldb/patches/multipleResultSets.patch b/external/hsqldb/patches/multipleResultSets.patch new file mode 100644 index 000000000000..56ddb13b449a --- /dev/null +++ b/external/hsqldb/patches/multipleResultSets.patch @@ -0,0 +1,11 @@ +--- misc/hsqldb/src/org/hsqldb/jdbc/jdbcDatabaseMetaData.java 2012-02-08 15:14:42.802123563 +0000 ++++ misc/build/hsqldb/src/org/hsqldb/jdbc/jdbcDatabaseMetaData.java 2012-02-08 15:47:35.835635654 +0000 +@@ -1347,7 +1347,7 @@ + * @exception SQLException if a database access error occurs + */ + public boolean supportsMultipleResultSets() throws SQLException { +- return false; ++ return true; + } + + /** diff --git a/include/sal/log-areas.dox b/include/sal/log-areas.dox index 3203e74a3b7c..0f8927cc89ff 100644 --- a/include/sal/log-areas.dox +++ b/include/sal/log-areas.dox @@ -78,6 +78,7 @@ certain functionality. @li @c connectivity.evoab2 @li @c connectivity.firebird @li @c connectivity.flat +@li @c connectivity.hsqldb @li @c connectivity.jdbc @li @c connectivity.kab @li @c connectivity.macab diff --git a/officecfg/registry/schema/org/openoffice/Office/DataAccess.xcs b/officecfg/registry/schema/org/openoffice/Office/DataAccess.xcs index 754c598da9b9..98a581786d32 100644 --- a/officecfg/registry/schema/org/openoffice/Office/DataAccess.xcs +++ b/officecfg/registry/schema/org/openoffice/Office/DataAccess.xcs @@ -810,6 +810,21 @@ <value>false</value> </prop> </group> + <group oor:name="com.sun.star.sdbcx.comp.hsqldb.Driver"> + <info> + <desc>Specifies settings for the driver accessing HSQL databases embedded into OpenOffice.org + database documents (.odb)</desc> + </info> + <group oor:name="PermittedJavaMethods" oor:extensible="true"> + <info> + <desc>HSQLDB features calling Java code directly from SQL statements. For security + reasons, this is restricted to classes from the org.hsqldb.Library package, + the java.lang.math package, plus any methods specified in this configuration + setting. If a method specification ends with .*, then all methods + from the respective package are permitted.</desc> + </info> + </group> + </group> </group> <group oor:name="FormSearchOptions"> <info> diff --git a/postprocess/CustomTarget_registry.mk b/postprocess/CustomTarget_registry.mk index 25b34359c7be..f89b0b0bd96c 100644 --- a/postprocess/CustomTarget_registry.mk +++ b/postprocess/CustomTarget_registry.mk @@ -331,8 +331,9 @@ postprocess_DRIVERS += evoab endif ifeq ($(ENABLE_JAVA),TRUE) postprocess_FILES_main += \ + $(call gb_XcuModuleTarget_get_target,connectivity/registry/hsqldb)/org/openoffice/Office/DataAccess/Drivers-hsqldb.xcu \ $(call gb_XcuModuleTarget_get_target,connectivity/registry/jdbc)/org/openoffice/Office/DataAccess/Drivers-jdbc.xcu -postprocess_DRIVERS += jdbc +postprocess_DRIVERS += hsqldb jdbc endif ifeq ($(ENABLE_FIREBIRD_SDBC),TRUE) postprocess_FILES_main += \ diff --git a/postprocess/Rdb_services.mk b/postprocess/Rdb_services.mk index fb8feec06adf..5fcd89c7d1c4 100644 --- a/postprocess/Rdb_services.mk +++ b/postprocess/Rdb_services.mk @@ -261,6 +261,7 @@ $(eval $(call gb_Rdb_add_components,services,\ connectivity/source/drivers/macab/macab1 \ ) \ $(if $(ENABLE_JAVA), \ + connectivity/source/drivers/hsqldb/hsqldb \ connectivity/source/drivers/jdbc/jdbc \ ) \ connectivity/source/manager/sdbc2 \ |