Repository.mk | 1 connectivity/Configuration_writer.mk | 20 connectivity/Library_calc.mk | 4 connectivity/Library_file.mk | 4 connectivity/Library_writer.mk | 49 + connectivity/Module_connectivity.mk | 2 connectivity/registry/writer/org/openoffice/Office/DataAccess/Drivers.xcu | 44 + connectivity/source/drivers/calc/CConnection.cxx | 8 connectivity/source/drivers/calc/CTable.cxx | 4 connectivity/source/drivers/component/CColumns.cxx | 11 connectivity/source/drivers/component/CPreparedStatement.cxx | 12 connectivity/source/drivers/component/CResultSet.cxx | 56 - connectivity/source/drivers/component/CStatement.cxx | 12 connectivity/source/drivers/writer/WCatalog.cxx | 63 + connectivity/source/drivers/writer/WConnection.cxx | 257 ++++++ connectivity/source/drivers/writer/WDatabaseMetaData.cxx | 325 +++++++ connectivity/source/drivers/writer/WDriver.cxx | 90 ++ connectivity/source/drivers/writer/WTable.cxx | 420 ++++++++++ connectivity/source/drivers/writer/WTables.cxx | 50 + connectivity/source/drivers/writer/Wservices.cxx | 102 ++ connectivity/source/drivers/writer/writer.component | 17 connectivity/source/inc/component/CColumns.hxx | 13 connectivity/source/inc/component/CPreparedStatement.hxx | 13 connectivity/source/inc/component/CResultSet.hxx | 25 connectivity/source/inc/component/CStatement.hxx | 13 connectivity/source/inc/writer/WCatalog.hxx | 45 + connectivity/source/inc/writer/WConnection.hxx | 170 ++++ connectivity/source/inc/writer/WDatabaseMetaData.hxx | 52 + connectivity/source/inc/writer/WDriver.hxx | 58 + connectivity/source/inc/writer/WTable.hxx | 116 ++ connectivity/source/inc/writer/WTables.hxx | 45 + dbaccess/inc/dbaccess_helpid.hrc | 1 dbaccess/source/core/misc/dsntypes.cxx | 4 dbaccess/source/inc/dsntypes.hxx | 3 dbaccess/source/ui/dlg/AutoControls.src | 5 dbaccess/source/ui/dlg/ConnectionHelper.cxx | 13 dbaccess/source/ui/dlg/ConnectionPage.cxx | 4 dbaccess/source/ui/dlg/DBSetupConnectionPages.cxx | 2 dbaccess/source/ui/dlg/DBSetupConnectionPages.hxx | 2 dbaccess/source/ui/dlg/DbAdminImpl.cxx | 1 dbaccess/source/ui/dlg/dbadminsetup.src | 4 dbaccess/source/ui/dlg/dbwiz.cxx | 1 dbaccess/source/ui/dlg/dbwizsetup.cxx | 10 dbaccess/source/ui/inc/dbu_dlg.hrc | 4 dbaccess/source/ui/inc/dbwizsetup.hxx | 2 include/sal/log-areas.dox | 1 postprocess/CustomTarget_registry.mk | 6 postprocess/Rdb_services.mk | 1 sw/CppunitTest_sw_mailmerge.mk | 1 sw/inc/dbmgr.hxx | 3 sw/inc/dbui.hrc | 2 sw/qa/extras/mailmerge/data/10-testing-addresses-writer.odt |binary sw/qa/extras/mailmerge/data/writer-mail-merge.odt |binary sw/qa/extras/mailmerge/mailmerge.cxx | 14 sw/source/ui/dbui/dbui.src | 10 sw/source/uibase/dbui/dbmgr.cxx | 19 56 files changed, 2108 insertions(+), 106 deletions(-)
New commits: commit c478d1b3cc371d3b9e8147ff57347f99d25c565e Author: Miklos Vajna <vmik...@collabora.co.uk> Date: Mon Jul 17 08:02:54 2017 +0200 Implement mail merge data source from Writer tables This is a combination of 17 commits: connectivity: add initial writer backend Similar to the calc one. As a first step the Driver and the Connection interfaces are implemented, though the later has some stubs. (cherry picked from commit 69068f2228147ca0d252762612edbcab0713cdfa) connectivity writer driver: initial DatabaseMetaData implementation With this the list of tables is visible in Data Sources. (cherry picked from commit d7ac239793905564d2754edc52611930b6ba2cdc) connectivity writer driver: add Catalog implementation But leave OWriterCatalog::refreshTables() as a stub for now. (cherry picked from commit 6fb3e3a9c1dd1aec8a1ba90fea51e32048e609bf) connectivity writer driver: add Tables implementation But leave OWriterTables::createObject() as a stub for now. (cherry picked from commit 60020f61339e5836f5a481909c1183af2734f569) connectivity writer driver: add Table implementation Gets rid of the stub warnings in OWriterTables::createObject(). (cherry picked from commit bec2da98c74dc4c02561641862de15e5d2630fa2) connectivity writer driver: add Columns implementation Gets rid of the stub warnings in OWriterTable::refreshColumns(). (cherry picked from commit a11ddfdcf3f5021cbeb0f065694d875bb748dc76) connectivity writer driver: add PreparedStatement implementation Gets rid of the stub warnings in OWriterConnection::prepareStatement(). (cherry picked from commit ac3c24bec925dd53f07b2827dab0d71c0dbaedee) Conflicts: connectivity/source/drivers/writer/WConnection.cxx connectivity writer driver: add ResultSet implementation Now column headers and table data show up on the UI. (cherry picked from commit a93c89894feb663df37609c95d4db523120c0bc1) connectivity writer driver: add Statement implementation Gets rid of the OWriterConnection::createStatement() stub warning. This is the last interface which was not supported by the writer driver, as far as I see. (cherry picked from commit cad0d8df38cf390d0615668ce2ab7c8f7ee42cde) connectivity writer driver: mention Writer in display name It was just "Document" to be consistent with Calc's "Spreadsheet", but it's confusing as we have a Text driver as well. (cherry picked from commit 5445de1432fd65fb3ef613d1dafd2bbb9b99b265) dbaccess: introduce DATASOURCE_TYPE::DST_WRITER By mostly reusing the spreadsheet code. This way the UI allows creating a data source where the backend is a Writer document (containing at least one Writer table). (cherry picked from commit 36f2df84fcfc21038b4d20df38a9e5addfcbde3f) sw mail merge: add support for the new 'writer' connectivity driver By mapping the .odt, .sxw, .doc and .docx extensions to sdbc:writer:. If we are at it, also accept xlsx next to xls. (cherry picked from commit 83b43ef2223b66484e0e90e7b614886e06f955b5) Conflicts: sw/inc/dbui.hrc sw/source/uibase/dbui/dbmgr.cxx sw mailmerge: add writer data source testcase Fails with commit 83b43ef2223b66484e0e90e7b614886e06f955b5 (sw mail merge: add support for the new 'writer' connectivity driver, 2017-07-18) reverted. (cherry picked from commit d9b0108e3af7244179bcc7b07db9d0826c3ac8a6) connectivity: merge OCalcResultSet and OWriterResultSet Into a single OComponentResultSet, as both of them just provide data source functionality based on a file loaded into an LO component, so they can share code. (cherry picked from commit e473d49acc127ece76eb31cb3610e3950f35d9d9) Conflicts: connectivity/source/drivers/component/CResultSet.cxx connectivity/source/drivers/writer/WResultSet.cxx connectivity/source/inc/writer/WResultSet.hxx connectivity: merge OCalcStatement and OWriterStatement Into a single OComponentStatement, as both of them just provide statement functionality based on a file loaded into an LO component, so they can share code. (cherry picked from commit 4073bc15d1aa1b46b2e0953d6316f2ab6a23dc87) connectivity: merge OCalcPreparedStatement and OWriterPreparedStatement Into a single OComponentPreparedStatement, as both of them just provide prepared statement functionality based on a file loaded into an LO component, so they can share code. (cherry picked from commit 196ee66d4aab62678a8cfb762379909bdda16051) connectivity: merge OCalcColumns and OWriterColumns Turns out createObject() only needs the base class OFileTable, and then these can be shared. (cherry picked from commit d3d9292a0fb414e6721b2f3b12b7e283caed946d) Change-Id: I6e8a83155dbbbc3d85794e190c2e710d01902017 Reviewed-on: https://gerrit.libreoffice.org/40231 Reviewed-by: Jan Holesovsky <ke...@collabora.com> Tested-by: Jan Holesovsky <ke...@collabora.com> diff --git a/Repository.mk b/Repository.mk index 6eade9020edd..3635ccfadada 100644 --- a/Repository.mk +++ b/Repository.mk @@ -480,6 +480,7 @@ $(eval $(call gb_Helper_register_libraries_for_install,OOOLIBS,writer, \ $(call gb_Helper_optional,SCRIPTING,vbaswobj) \ wpftwriter \ writerfilter \ + $(call gb_Helper_optional,DBCONNECTIVITY,writer) \ )) # cli_cppuhelper is NONE even though it is actually in URE because it is CliNativeLibrary diff --git a/connectivity/Configuration_writer.mk b/connectivity/Configuration_writer.mk new file mode 100644 index 000000000000..c14030b11cc5 --- /dev/null +++ b/connectivity/Configuration_writer.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_writer)) + +$(eval $(call gb_Configuration_add_spool_modules,driver_writer,connectivity/registry/writer,\ + org/openoffice/Office/DataAccess/Drivers-writer.xcu \ +)) + +$(eval $(call gb_Configuration_add_localized_datas,driver_writer,connectivity/registry/writer,\ + org/openoffice/Office/DataAccess/Drivers.xcu \ +)) + +# vim: set noet sw=4 ts=4: diff --git a/connectivity/Library_calc.mk b/connectivity/Library_calc.mk index a2b355813412..0c0d2ad4bc0c 100644 --- a/connectivity/Library_calc.mk +++ b/connectivity/Library_calc.mk @@ -40,12 +40,8 @@ $(eval $(call gb_Library_use_libraries,calc,\ )) $(eval $(call gb_Library_add_exception_objects,calc,\ - connectivity/source/drivers/calc/CResultSet \ - connectivity/source/drivers/calc/CStatement \ - connectivity/source/drivers/calc/CPreparedStatement \ connectivity/source/drivers/calc/CDatabaseMetaData \ connectivity/source/drivers/calc/CCatalog \ - connectivity/source/drivers/calc/CColumns \ connectivity/source/drivers/calc/CTable \ connectivity/source/drivers/calc/CTables \ connectivity/source/drivers/calc/CConnection \ diff --git a/connectivity/Library_file.mk b/connectivity/Library_file.mk index 765b13bf9998..ba07f5031909 100644 --- a/connectivity/Library_file.mk +++ b/connectivity/Library_file.mk @@ -42,6 +42,10 @@ $(eval $(call gb_Library_use_libraries,file,\ )) $(eval $(call gb_Library_add_exception_objects,file,\ + connectivity/source/drivers/component/CColumns \ + connectivity/source/drivers/component/CPreparedStatement \ + connectivity/source/drivers/component/CResultSet \ + connectivity/source/drivers/component/CStatement \ connectivity/source/drivers/file/FCatalog \ connectivity/source/drivers/file/FColumns \ connectivity/source/drivers/file/FConnection \ diff --git a/connectivity/Library_writer.mk b/connectivity/Library_writer.mk new file mode 100644 index 000000000000..d07f572a3227 --- /dev/null +++ b/connectivity/Library_writer.mk @@ -0,0 +1,49 @@ +# -*- 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,writer)) + +$(eval $(call gb_Library_set_componentfile,writer,connectivity/source/drivers/writer/writer)) + +$(eval $(call gb_Library_use_external,writer,boost_headers)) + +$(eval $(call gb_Library_use_sdk_api,writer)) + +$(eval $(call gb_Library_set_include,writer,\ + $$(INCLUDE) \ + -I$(SRCDIR)/connectivity/inc \ + -I$(SRCDIR)/connectivity/source/inc \ + -I$(WORKDIR)/YaccTarget/connectivity/source/parse \ +)) + +$(eval $(call gb_Library_use_libraries,writer,\ + cppu \ + cppuhelper \ + svl \ + tl \ + utl \ + sal \ + salhelper \ + dbtools \ + file \ + comphelper \ +)) + +$(eval $(call gb_Library_add_exception_objects,writer,\ + connectivity/source/drivers/writer/WCatalog \ + connectivity/source/drivers/writer/WConnection \ + connectivity/source/drivers/writer/WDatabaseMetaData \ + connectivity/source/drivers/writer/WDriver \ + connectivity/source/drivers/writer/WTable \ + connectivity/source/drivers/writer/WTables \ + connectivity/source/drivers/writer/Wservices \ +)) + +# vim: set noet sw=4 ts=4: diff --git a/connectivity/Module_connectivity.mk b/connectivity/Module_connectivity.mk index aee317867501..c9275b0f6883 100644 --- a/connectivity/Module_connectivity.mk +++ b/connectivity/Module_connectivity.mk @@ -16,6 +16,7 @@ $(eval $(call gb_Module_add_targets,connectivity,\ Configuration_flat \ Configuration_mysql \ Configuration_odbc \ + Configuration_writer \ Library_calc \ Library_dbase \ Library_dbpool2 \ @@ -25,6 +26,7 @@ $(eval $(call gb_Module_add_targets,connectivity,\ Library_mysql \ $(if $(filter ANDROID IOS,$(OS)),,Library_odbc) \ Library_sdbc2 \ + Library_writer \ )) $(eval $(call gb_Module_add_l10n_targets,connectivity,\ diff --git a/connectivity/registry/writer/org/openoffice/Office/DataAccess/Drivers.xcu b/connectivity/registry/writer/org/openoffice/Office/DataAccess/Drivers.xcu new file mode 100644 index 000000000000..69ed08e1c63d --- /dev/null +++ b/connectivity/registry/writer/org/openoffice/Office/DataAccess/Drivers.xcu @@ -0,0 +1,44 @@ +<?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/. + --> +<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="writer"> + <node oor:name="sdbc:writer:*" oor:op="replace"> + <prop oor:name="Driver"> + <value>com.sun.star.comp.sdbc.writer.ODriver</value> + </prop> + <prop oor:name="DriverTypeDisplayName" oor:type="xs:string"> + <value xml:lang="en-US">Writer Document</value> + </prop> + <node oor:name="Features"> + <node oor:name="EscapeDateTime" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:boolean"> + <value>true</value> + </prop> + </node> + </node> + <node oor:name="MetaData"> + <node oor:name="SupportsBrowsing" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:boolean"> + <value>true</value> + </prop> + </node> + <node oor:name="FileSystemBased" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:boolean"> + <value>true</value> + </prop> + </node> + <node oor:name="MediaType" oor:op="replace"> + <prop oor:name="Value" oor:type="xs:string"> + <value>application/vnd.oasis.opendocument.text</value> + </prop> + </node> + </node> + </node> + </node> +</oor:component-data> diff --git a/connectivity/source/drivers/calc/CConnection.cxx b/connectivity/source/drivers/calc/CConnection.cxx index a315bc6b7c45..75746504ef97 100644 --- a/connectivity/source/drivers/calc/CConnection.cxx +++ b/connectivity/source/drivers/calc/CConnection.cxx @@ -28,8 +28,8 @@ #include <com/sun/star/frame/XComponentLoader.hpp> #include <com/sun/star/sheet/XSpreadsheetDocument.hpp> #include <tools/urlobj.hxx> -#include "calc/CPreparedStatement.hxx" -#include "calc/CStatement.hxx" +#include "component/CPreparedStatement.hxx" +#include "component/CStatement.hxx" #include <unotools/pathoptions.hxx> #include <connectivity/dbexception.hxx> #include <cppuhelper/exc_hlp.hxx> @@ -239,7 +239,7 @@ Reference< XStatement > SAL_CALL OCalcConnection::createStatement( ) throw(SQLE checkDisposed(OConnection_BASE::rBHelper.bDisposed); - Reference< XStatement > xReturn = new OCalcStatement(this); + Reference< XStatement > xReturn = new connectivity::component::OComponentStatement(this); m_aStatements.push_back(WeakReferenceHelper(xReturn)); return xReturn; } @@ -252,7 +252,7 @@ Reference< XPreparedStatement > SAL_CALL OCalcConnection::prepareStatement( cons checkDisposed(OConnection_BASE::rBHelper.bDisposed); - OCalcPreparedStatement* pStmt = new OCalcPreparedStatement(this); + auto pStmt = new connectivity::component::OComponentPreparedStatement(this); Reference< XPreparedStatement > xHoldAlive = pStmt; pStmt->construct(sql); m_aStatements.push_back(WeakReferenceHelper(*pStmt)); diff --git a/connectivity/source/drivers/calc/CTable.cxx b/connectivity/source/drivers/calc/CTable.cxx index cae94275f944..5b73750b9af0 100644 --- a/connectivity/source/drivers/calc/CTable.cxx +++ b/connectivity/source/drivers/calc/CTable.cxx @@ -36,7 +36,7 @@ #include <com/sun/star/text/XText.hpp> #include <svl/converter.hxx> #include "calc/CConnection.hxx" -#include "calc/CColumns.hxx" +#include "component/CColumns.hxx" #include <connectivity/sdbcx/VColumn.hxx> #include <rtl/ustrbuf.hxx> #include <osl/thread.h> @@ -622,7 +622,7 @@ void OCalcTable::refreshColumns() if(m_pColumns) m_pColumns->reFill(aVector); else - m_pColumns = new OCalcColumns(this,m_aMutex,aVector); + m_pColumns = new component::OComponentColumns(this,m_aMutex,aVector); } void OCalcTable::refreshIndexes() diff --git a/connectivity/source/drivers/calc/CColumns.cxx b/connectivity/source/drivers/component/CColumns.cxx similarity index 83% rename from connectivity/source/drivers/calc/CColumns.cxx rename to connectivity/source/drivers/component/CColumns.cxx index 3cd002cd3681..68dcba53d9f4 100644 --- a/connectivity/source/drivers/calc/CColumns.cxx +++ b/connectivity/source/drivers/component/CColumns.cxx @@ -17,11 +17,11 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#include "calc/CColumns.hxx" -#include "calc/CTable.hxx" +#include "component/CColumns.hxx" +#include "file/FTable.hxx" #include <connectivity/sdbcx/VColumn.hxx> -using namespace connectivity::calc; +using namespace connectivity::component; using namespace connectivity; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; @@ -30,10 +30,9 @@ using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::container; -sdbcx::ObjectType OCalcColumns::createObject(const OUString& _rName) +sdbcx::ObjectType OComponentColumns::createObject(const OUString& _rName) { - OCalcTable* pTable = static_cast<OCalcTable*>(m_pTable); - ::rtl::Reference<OSQLColumns> aCols = pTable->getTableColumns(); + ::rtl::Reference<OSQLColumns> aCols = m_pTable->getTableColumns(); OSQLColumns::Vector::const_iterator aIter = find(aCols->get().begin(),aCols->get().end(),_rName,::comphelper::UStringMixEqual(isCaseSensitive())); sdbcx::ObjectType xRet; diff --git a/connectivity/source/drivers/calc/CPreparedStatement.cxx b/connectivity/source/drivers/component/CPreparedStatement.cxx similarity index 71% rename from connectivity/source/drivers/calc/CPreparedStatement.cxx rename to connectivity/source/drivers/component/CPreparedStatement.cxx index 96eb9a2672a8..a2b1161fb7cb 100644 --- a/connectivity/source/drivers/calc/CPreparedStatement.cxx +++ b/connectivity/source/drivers/component/CPreparedStatement.cxx @@ -17,18 +17,18 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#include "calc/CPreparedStatement.hxx" -#include "calc/CResultSet.hxx" +#include "component/CPreparedStatement.hxx" +#include "component/CResultSet.hxx" -using namespace connectivity::calc; +using namespace connectivity::component; using namespace connectivity::file; using namespace com::sun::star::uno; -OResultSet* OCalcPreparedStatement::createResultSet() +OResultSet* OComponentPreparedStatement::createResultSet() { - return new OCalcResultSet(this,m_aSQLIterator); + return new connectivity::component::OComponentResultSet(this,m_aSQLIterator); } -IMPLEMENT_SERVICE_INFO(OCalcPreparedStatement,"com.sun.star.sdbc.driver.calc.PreparedStatement","com.sun.star.sdbc.PreparedStatement"); +IMPLEMENT_SERVICE_INFO(OComponentPreparedStatement,"com.sun.star.sdbc.driver.component.PreparedStatement","com.sun.star.sdbc.PreparedStatement"); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/calc/CResultSet.cxx b/connectivity/source/drivers/component/CResultSet.cxx similarity index 58% rename from connectivity/source/drivers/calc/CResultSet.cxx rename to connectivity/source/drivers/component/CResultSet.cxx index dc175865151e..989839d61437 100644 --- a/connectivity/source/drivers/calc/CResultSet.cxx +++ b/connectivity/source/drivers/component/CResultSet.cxx @@ -18,7 +18,7 @@ */ #include <com/sun/star/sdbcx/CompareBookmark.hpp> -#include "calc/CResultSet.hxx" +#include "component/CResultSet.hxx" #include <com/sun/star/lang/DisposedException.hpp> #include <comphelper/sequence.hxx> #include <comphelper/types.hxx> @@ -26,7 +26,7 @@ #include <connectivity/dbexception.hxx> using namespace ::comphelper; -using namespace connectivity::calc; +using namespace connectivity::component; using namespace connectivity::file; using namespace ::cppu; using namespace com::sun::star::uno; @@ -36,19 +36,19 @@ using namespace com::sun::star::sdbc; using namespace com::sun::star::sdbcx; -OCalcResultSet::OCalcResultSet( OStatement_Base* pStmt,connectivity::OSQLParseTreeIterator& _aSQLIterator) +OComponentResultSet::OComponentResultSet( OStatement_Base* pStmt,connectivity::OSQLParseTreeIterator& _aSQLIterator) : file::OResultSet(pStmt,_aSQLIterator) ,m_bBookmarkable(true) { registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISBOOKMARKABLE), PROPERTY_ID_ISBOOKMARKABLE, PropertyAttribute::READONLY,&m_bBookmarkable, cppu::UnoType<bool>::get()); } -OUString SAL_CALL OCalcResultSet::getImplementationName( ) throw ( RuntimeException, std::exception) +OUString SAL_CALL OComponentResultSet::getImplementationName( ) throw ( RuntimeException, std::exception) { - return OUString("com.sun.star.sdbcx.calc.ResultSet"); + return OUString("com.sun.star.sdbcx.component.ResultSet"); } -Sequence< OUString > SAL_CALL OCalcResultSet::getSupportedServiceNames( ) throw( RuntimeException, std::exception) +Sequence< OUString > SAL_CALL OComponentResultSet::getSupportedServiceNames( ) throw( RuntimeException, std::exception) { Sequence< OUString > aSupported(2); aSupported[0] = "com.sun.star.sdbc.ResultSet"; @@ -56,25 +56,25 @@ Sequence< OUString > SAL_CALL OCalcResultSet::getSupportedServiceNames( ) throw return aSupported; } -sal_Bool SAL_CALL OCalcResultSet::supportsService( const OUString& _rServiceName ) throw( RuntimeException, std::exception) +sal_Bool SAL_CALL OComponentResultSet::supportsService( const OUString& _rServiceName ) throw( RuntimeException, std::exception) { return cppu::supportsService(this, _rServiceName); } -Any SAL_CALL OCalcResultSet::queryInterface( const Type & rType ) throw(RuntimeException, std::exception) +Any SAL_CALL OComponentResultSet::queryInterface( const Type & rType ) throw(RuntimeException, std::exception) { Any aRet = OResultSet::queryInterface(rType); - return aRet.hasValue() ? aRet : OCalcResultSet_BASE::queryInterface(rType); + return aRet.hasValue() ? aRet : OComponentResultSet_BASE::queryInterface(rType); } - Sequence< Type > SAL_CALL OCalcResultSet::getTypes( ) throw( RuntimeException, std::exception) + Sequence< Type > SAL_CALL OComponentResultSet::getTypes( ) throw( RuntimeException, std::exception) { - return ::comphelper::concatSequences(OResultSet::getTypes(),OCalcResultSet_BASE::getTypes()); + return ::comphelper::concatSequences(OResultSet::getTypes(),OComponentResultSet_BASE::getTypes()); } // XRowLocate -Any SAL_CALL OCalcResultSet::getBookmark( ) throw( SQLException, RuntimeException, std::exception) +Any SAL_CALL OComponentResultSet::getBookmark( ) throw( SQLException, RuntimeException, std::exception) { ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(OResultSet_BASE::rBHelper.bDisposed); @@ -83,7 +83,7 @@ Any SAL_CALL OCalcResultSet::getBookmark( ) throw( SQLException, RuntimeExcept return makeAny((sal_Int32)(m_aRow->get())[0]->getValue()); } -sal_Bool SAL_CALL OCalcResultSet::moveToBookmark( const Any& bookmark ) throw( SQLException, RuntimeException, std::exception) +sal_Bool SAL_CALL OComponentResultSet::moveToBookmark( const Any& bookmark ) throw( SQLException, RuntimeException, std::exception) { ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(OResultSet_BASE::rBHelper.bDisposed); @@ -94,7 +94,7 @@ sal_Bool SAL_CALL OCalcResultSet::moveToBookmark( const Any& bookmark ) throw( return Move(IResultSetHelper::BOOKMARK,comphelper::getINT32(bookmark),true); } -sal_Bool SAL_CALL OCalcResultSet::moveRelativeToBookmark( const Any& bookmark, sal_Int32 rows ) throw( SQLException, RuntimeException, std::exception) +sal_Bool SAL_CALL OComponentResultSet::moveRelativeToBookmark( const Any& bookmark, sal_Int32 rows ) throw( SQLException, RuntimeException, std::exception) { ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(OResultSet_BASE::rBHelper.bDisposed); @@ -108,17 +108,17 @@ sal_Bool SAL_CALL OCalcResultSet::moveRelativeToBookmark( const Any& bookmark, } -sal_Int32 SAL_CALL OCalcResultSet::compareBookmarks( const Any& lhs, const Any& rhs ) throw( SQLException, RuntimeException, std::exception) +sal_Int32 SAL_CALL OComponentResultSet::compareBookmarks( const Any& lhs, const Any& rhs ) throw( SQLException, RuntimeException, std::exception) { return (lhs == rhs) ? CompareBookmark::EQUAL : CompareBookmark::NOT_EQUAL; } -sal_Bool SAL_CALL OCalcResultSet::hasOrderedBookmarks( ) throw( SQLException, RuntimeException, std::exception) +sal_Bool SAL_CALL OComponentResultSet::hasOrderedBookmarks( ) throw( SQLException, RuntimeException, std::exception) { return true; } -sal_Int32 SAL_CALL OCalcResultSet::hashBookmark( const Any& bookmark ) throw( SQLException, RuntimeException, std::exception) +sal_Int32 SAL_CALL OComponentResultSet::hashBookmark( const Any& bookmark ) throw( SQLException, RuntimeException, std::exception) { ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(OResultSet_BASE::rBHelper.bDisposed); @@ -128,7 +128,7 @@ sal_Int32 SAL_CALL OCalcResultSet::hashBookmark( const Any& bookmark ) throw( S } // XDeleteRows -Sequence< sal_Int32 > SAL_CALL OCalcResultSet::deleteRows( const Sequence< Any >& /*rows*/ ) throw( SQLException, RuntimeException, std::exception) +Sequence< sal_Int32 > SAL_CALL OComponentResultSet::deleteRows( const Sequence< Any >& /*rows*/ ) throw( SQLException, RuntimeException, std::exception) { ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(OResultSet_BASE::rBHelper.bDisposed); @@ -137,18 +137,18 @@ Sequence< sal_Int32 > SAL_CALL OCalcResultSet::deleteRows( const Sequence< Any return Sequence< sal_Int32 >(); } -bool OCalcResultSet::fillIndexValues(const Reference< XColumnsSupplier> &/*_xIndex*/) +bool OComponentResultSet::fillIndexValues(const Reference< XColumnsSupplier> &/*_xIndex*/) { - // Calc table has no index + // Writer or Calc table has no index return false; } -::cppu::IPropertyArrayHelper & OCalcResultSet::getInfoHelper() +::cppu::IPropertyArrayHelper & OComponentResultSet::getInfoHelper() { - return *OCalcResultSet_BASE3::getArrayHelper(); + return *OComponentResultSet_BASE3::getArrayHelper(); } -::cppu::IPropertyArrayHelper* OCalcResultSet::createArrayHelper() const +::cppu::IPropertyArrayHelper* OComponentResultSet::createArrayHelper() const { Sequence< Property > aProps; describeProperties(aProps); @@ -156,17 +156,17 @@ bool OCalcResultSet::fillIndexValues(const Reference< XColumnsSupplier> &/*_xInd } -void SAL_CALL OCalcResultSet::acquire() throw() +void SAL_CALL OComponentResultSet::acquire() throw() { - OCalcResultSet_BASE2::acquire(); + OComponentResultSet_BASE2::acquire(); } -void SAL_CALL OCalcResultSet::release() throw() +void SAL_CALL OComponentResultSet::release() throw() { - OCalcResultSet_BASE2::release(); + OComponentResultSet_BASE2::release(); } -css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL OCalcResultSet::getPropertySetInfo( ) throw(css::uno::RuntimeException, std::exception) +css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL OComponentResultSet::getPropertySetInfo( ) throw(css::uno::RuntimeException, std::exception) { return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper()); } diff --git a/connectivity/source/drivers/calc/CStatement.cxx b/connectivity/source/drivers/component/CStatement.cxx similarity index 73% rename from connectivity/source/drivers/calc/CStatement.cxx rename to connectivity/source/drivers/component/CStatement.cxx index 15d4e45a04b8..a83ff8587e20 100644 --- a/connectivity/source/drivers/calc/CStatement.cxx +++ b/connectivity/source/drivers/component/CStatement.cxx @@ -17,18 +17,18 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#include "calc/CStatement.hxx" -#include "calc/CResultSet.hxx" +#include "component/CStatement.hxx" +#include "component/CResultSet.hxx" -using namespace connectivity::calc; +using namespace connectivity::component; using namespace connectivity::file; using namespace com::sun::star::uno; -OResultSet* OCalcStatement::createResultSet() +OResultSet* OComponentStatement::createResultSet() { - return new OCalcResultSet(this,m_aSQLIterator); + return new connectivity::component::OComponentResultSet(this,m_aSQLIterator); } -IMPLEMENT_SERVICE_INFO(OCalcStatement,"com.sun.star.sdbc.driver.calc.Statement","com.sun.star.sdbc.Statement"); +IMPLEMENT_SERVICE_INFO(OComponentStatement,"com.sun.star.sdbc.driver.component.Statement","com.sun.star.sdbc.Statement"); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/writer/WCatalog.cxx b/connectivity/source/drivers/writer/WCatalog.cxx new file mode 100644 index 000000000000..0cf4a1626e40 --- /dev/null +++ b/connectivity/source/drivers/writer/WCatalog.cxx @@ -0,0 +1,63 @@ +/* -*- 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 "writer/WCatalog.hxx" +#include "writer/WTables.hxx" + +#include <com/sun/star/sdbc/XRow.hpp> +#include <com/sun/star/sdbc/XResultSet.hpp> + +#include <connectivity/sdbcx/VCollection.hxx> + +#include "writer/WConnection.hxx" + +using namespace ::com::sun::star; + +namespace connectivity +{ +namespace writer +{ + +OWriterCatalog::OWriterCatalog(OWriterConnection* pConnection) : file::OFileCatalog(pConnection) +{ +} + +void OWriterCatalog::refreshTables() +{ + TStringVector aVector; + uno::Sequence<OUString> aTypes; + OWriterConnection::ODocHolder aDocHolder(static_cast<OWriterConnection*>(m_pConnection)); + uno::Reference< sdbc::XResultSet > xResult = m_xMetaData->getTables(uno::Any(), "%", "%", aTypes); + + if (xResult.is()) + { + uno::Reference< sdbc::XRow > xRow(xResult, uno::UNO_QUERY); + while (xResult->next()) + aVector.push_back(xRow->getString(3)); + } + if (m_pTables) + m_pTables->reFill(aVector); + else + m_pTables = new OWriterTables(m_xMetaData, *this, m_aMutex, aVector); +} + +} // namespace writer +} // namespace connectivity + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/writer/WConnection.cxx b/connectivity/source/drivers/writer/WConnection.cxx new file mode 100644 index 000000000000..8b46b949965c --- /dev/null +++ b/connectivity/source/drivers/writer/WConnection.cxx @@ -0,0 +1,257 @@ +/* -*- 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 "writer/WConnection.hxx" +#include "writer/WDatabaseMetaData.hxx" +#include "writer/WCatalog.hxx" +#include "writer/WDriver.hxx" +#include "resource/sharedresources.hxx" +#include "resource/common_res.hrc" +#include <com/sun/star/lang/DisposedException.hpp> +#include <com/sun/star/frame/Desktop.hpp> +#include <com/sun/star/text/XTextDocument.hpp> +#include <tools/urlobj.hxx> +#include "component/CPreparedStatement.hxx" +#include "component/CStatement.hxx" +#include <unotools/pathoptions.hxx> +#include <connectivity/dbexception.hxx> +#include <cppuhelper/exc_hlp.hxx> +#include <comphelper/processfactory.hxx> + +typedef connectivity::file::OConnection OConnection_BASE; + +using namespace ::com::sun::star; + +namespace connectivity +{ +namespace writer +{ + +OWriterConnection::OWriterConnection(ODriver* _pDriver) : OConnection(_pDriver),m_nDocCount(0) +{ + // m_aFilenameExtension is not used +} + +OWriterConnection::~OWriterConnection() +{ +} + +void OWriterConnection::construct(const OUString& url,const uno::Sequence< beans::PropertyValue >& info) throw(sdbc::SQLException, uno::RuntimeException, uno::DeploymentException, std::exception) +{ + // open file + + sal_Int32 nLen = url.indexOf(':'); + nLen = url.indexOf(':',nLen+1); + OUString aDSN(url.copy(nLen+1)); + + m_aFileName = aDSN; + INetURLObject aURL; + aURL.SetSmartProtocol(INetProtocol::File); + { + SvtPathOptions aPathOptions; + m_aFileName = aPathOptions.SubstituteVariable(m_aFileName); + } + aURL.SetSmartURL(m_aFileName); + if (aURL.GetProtocol() == INetProtocol::NotValid) + { + // don't pass invalid URL to loadComponentFromURL + throw sdbc::SQLException(); + } + m_aFileName = aURL.GetMainURL(INetURLObject::NO_DECODE); + + m_sPassword.clear(); + const char pPwd[] = "password"; + + const beans::PropertyValue* pIter = info.getConstArray(); + const beans::PropertyValue* pEnd = pIter + info.getLength(); + for (; pIter != pEnd; ++pIter) + { + if (pIter->Name == pPwd) + { + pIter->Value >>= m_sPassword; + break; + } + } // for(;pIter != pEnd;++pIter) + ODocHolder aDocHolder(this); // just to test that the doc can be loaded + acquireDoc(); +} + +uno::Reference<text::XTextDocument> const& OWriterConnection::acquireDoc() +{ + if (m_xDoc.is()) + { + osl_atomic_increment(&m_nDocCount); + return m_xDoc; + } + // open read-only as long as updating isn't implemented + uno::Sequence<beans::PropertyValue> aArgs(2); + aArgs[0].Name = "Hidden"; + aArgs[0].Value <<= true; + aArgs[1].Name = "ReadOnly"; + aArgs[1].Value <<= true; + + if (!m_sPassword.isEmpty()) + { + const sal_Int32 nPos = aArgs.getLength(); + aArgs.realloc(nPos+1); + aArgs[nPos].Name = "Password"; + aArgs[nPos].Value <<= m_sPassword; + } + + uno::Reference< frame::XDesktop2 > xDesktop = frame::Desktop::create(getDriver()->getComponentContext()); + uno::Reference< lang::XComponent > xComponent; + uno::Any aLoaderException; + try + { + xComponent = xDesktop->loadComponentFromURL( + m_aFileName, "_blank", 0, aArgs); + } + catch (const uno::Exception&) + { + aLoaderException = ::cppu::getCaughtException(); + } + + m_xDoc.set(xComponent, uno::UNO_QUERY); + + // if the URL is not a text document, throw the exception here + // instead of at the first access to it + if (!m_xDoc.is()) + { + if (aLoaderException.hasValue()) + { + uno::Exception aLoaderError; + OSL_VERIFY(aLoaderException >>= aLoaderError); + + SAL_WARN("connectivity.writer", "empty m_xDoc, exception type: " << aLoaderException.getValueTypeName() << ", error message: " << aLoaderError.Message); + } + + const OUString sError(m_aResources.getResourceStringWithSubstitution( + STR_COULD_NOT_LOAD_FILE, + "$filename$", m_aFileName + )); + ::dbtools::throwGenericSQLException(sError, *this); + } + osl_atomic_increment(&m_nDocCount); + m_xCloseVetoButTerminateListener.set(new CloseVetoButTerminateListener); + m_xCloseVetoButTerminateListener->start(m_xDoc, xDesktop); + return m_xDoc; +} + +void OWriterConnection::releaseDoc() +{ + if (osl_atomic_decrement(&m_nDocCount) == 0) + { + if (m_xCloseVetoButTerminateListener.is()) + { + m_xCloseVetoButTerminateListener->stop(); // dispose m_xDoc + m_xCloseVetoButTerminateListener.clear(); + } + m_xDoc.clear(); + } +} + +void OWriterConnection::disposing() +{ + ::osl::MutexGuard aGuard(m_aMutex); + + m_nDocCount = 0; + if (m_xCloseVetoButTerminateListener.is()) + { + m_xCloseVetoButTerminateListener->stop(); // dispose m_xDoc + m_xCloseVetoButTerminateListener.clear(); + } + m_xDoc.clear(); + + OConnection::disposing(); +} + +// XServiceInfo + + +IMPLEMENT_SERVICE_INFO(OWriterConnection, "com.sun.star.sdbc.drivers.writer.Connection", "com.sun.star.sdbc.Connection") + + +uno::Reference< sdbc::XDatabaseMetaData > SAL_CALL OWriterConnection::getMetaData() throw(sdbc::SQLException, uno::RuntimeException, std::exception) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OConnection_BASE::rBHelper.bDisposed); + + + uno::Reference< sdbc::XDatabaseMetaData > xMetaData = m_xMetaData; + if (!xMetaData.is()) + { + xMetaData = new OWriterDatabaseMetaData(this); + m_xMetaData = xMetaData; + } + + return xMetaData; +} + + +css::uno::Reference< css::sdbcx::XTablesSupplier > OWriterConnection::createCatalog() +{ + ::osl::MutexGuard aGuard(m_aMutex); + uno::Reference< css::sdbcx::XTablesSupplier > xTab = m_xCatalog; + if (!xTab.is()) + { + OWriterCatalog* pCat = new OWriterCatalog(this); + xTab = pCat; + m_xCatalog = xTab; + } + return xTab; +} + + +uno::Reference< sdbc::XStatement > SAL_CALL OWriterConnection::createStatement() throw(sdbc::SQLException, uno::RuntimeException, std::exception) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OConnection_BASE::rBHelper.bDisposed); + + uno::Reference<sdbc::XStatement> xReturn = new component::OComponentStatement(this); + m_aStatements.push_back(uno::WeakReferenceHelper(xReturn)); + return xReturn; +} + + +uno::Reference< sdbc::XPreparedStatement > SAL_CALL OWriterConnection::prepareStatement(const OUString& sql) throw(sdbc::SQLException, uno::RuntimeException, std::exception) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OConnection_BASE::rBHelper.bDisposed); + + auto pStmt = new component::OComponentPreparedStatement(this); + uno::Reference<sdbc::XPreparedStatement> xHoldAlive = pStmt; + pStmt->construct(sql); + m_aStatements.push_back(uno::WeakReferenceHelper(*pStmt)); + return pStmt; +} + + +uno::Reference< sdbc::XPreparedStatement > SAL_CALL OWriterConnection::prepareCall(const OUString& /*sql*/) throw(sdbc::SQLException, uno::RuntimeException, std::exception) +{ + ::osl::MutexGuard aGuard(m_aMutex); + checkDisposed(OConnection_BASE::rBHelper.bDisposed); + + ::dbtools::throwFeatureNotImplementedSQLException("XConnection::prepareCall", *this); + return nullptr; +} + +} // namespace writer +} // namespace connectivity + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/writer/WDatabaseMetaData.cxx b/connectivity/source/drivers/writer/WDatabaseMetaData.cxx new file mode 100644 index 000000000000..730b085cb110 --- /dev/null +++ b/connectivity/source/drivers/writer/WDatabaseMetaData.cxx @@ -0,0 +1,325 @@ +/* -*- 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 "writer/WDatabaseMetaData.hxx" +#include "writer/WConnection.hxx" +#include <com/sun/star/sdbc/DataType.hpp> +#include <com/sun/star/sdbc/ResultSetType.hpp> +#include <com/sun/star/sdbc/ColumnValue.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/sdbc/ResultSetConcurrency.hpp> +#include <com/sun/star/sdbcx/XColumnsSupplier.hpp> +#include <com/sun/star/sdbcx/XIndexesSupplier.hpp> +#include <com/sun/star/text/XTextDocument.hpp> +#include <com/sun/star/text/XTextTablesSupplier.hpp> +#include "FDatabaseMetaDataResultSet.hxx" +#include <com/sun/star/lang/XUnoTunnel.hpp> +#include <comphelper/types.hxx> + +using namespace connectivity::file; +using namespace ::com::sun::star; + +namespace connectivity +{ +namespace writer +{ + +OWriterDatabaseMetaData::OWriterDatabaseMetaData(OConnection* pConnection) :ODatabaseMetaData(pConnection) +{ +} + +OWriterDatabaseMetaData::~OWriterDatabaseMetaData() +{ +} + +uno::Reference<sdbc::XResultSet> OWriterDatabaseMetaData::impl_getTypeInfo_throw() +{ + ::osl::MutexGuard aGuard(m_aMutex); + + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTypeInfo); + uno::Reference<sdbc::XResultSet> xRef = pResult; + + static ODatabaseMetaDataResultSet::ORows aRows; + if (aRows.empty()) + { + ODatabaseMetaDataResultSet::ORow aRow; + + aRows.reserve(6); + aRow.reserve(18); + + aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); + aRow.push_back(new ORowSetValueDecorator(OUString("VARCHAR"))); + aRow.push_back(new ORowSetValueDecorator(sdbc::DataType::VARCHAR)); + aRow.push_back(new ORowSetValueDecorator((sal_Int32)65535)); + aRow.push_back(ODatabaseMetaDataResultSet::getQuoteValue()); + aRow.push_back(ODatabaseMetaDataResultSet::getQuoteValue()); + aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); + aRow.push_back(ODatabaseMetaDataResultSet::get1Value()); // ORowSetValue((sal_Int32)ColumnValue::NULLABLE) + aRow.push_back(ODatabaseMetaDataResultSet::get1Value()); + aRow.push_back(new ORowSetValueDecorator((sal_Int32)sdbc::ColumnSearch::CHAR)); + aRow.push_back(ODatabaseMetaDataResultSet::get1Value()); + aRow.push_back(ODatabaseMetaDataResultSet::get0Value()); + aRow.push_back(ODatabaseMetaDataResultSet::get0Value()); + aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); + aRow.push_back(ODatabaseMetaDataResultSet::get0Value()); + aRow.push_back(ODatabaseMetaDataResultSet::get0Value()); + aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); + aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); + aRow.push_back(new ORowSetValueDecorator((sal_Int32)10)); + aRows.push_back(aRow); + + aRow[1] = new ORowSetValueDecorator(OUString("DECIMAL")); + aRow[2] = new ORowSetValueDecorator(sdbc::DataType::DECIMAL); + aRow[3] = ODatabaseMetaDataResultSet::get0Value(); + aRow[9] = ODatabaseMetaDataResultSet::getBasicValue(); + aRow[15] = ODatabaseMetaDataResultSet::get0Value(); + aRows.push_back(aRow); + + aRow[1] = new ORowSetValueDecorator(OUString("BOOL")); + aRow[2] = new ORowSetValueDecorator(sdbc::DataType::BIT); + aRow[3] = new ORowSetValueDecorator((sal_Int32)20); + aRow[9] = ODatabaseMetaDataResultSet::getBasicValue(); + aRow[15] = new ORowSetValueDecorator((sal_Int32)15); + aRows.push_back(aRow); + + aRow[1] = new ORowSetValueDecorator(OUString("DATE")); + aRow[2] = new ORowSetValueDecorator(sdbc::DataType::DATE); + aRow[3] = ODatabaseMetaDataResultSet::get0Value(); + aRow[9] = ODatabaseMetaDataResultSet::getBasicValue(); + aRow[15] = ODatabaseMetaDataResultSet::get0Value(); + aRows.push_back(aRow); + + aRow[1] = new ORowSetValueDecorator(OUString("TIME")); + aRow[2] = new ORowSetValueDecorator(sdbc::DataType::TIME); + aRow[3] = ODatabaseMetaDataResultSet::get0Value(); + aRow[9] = ODatabaseMetaDataResultSet::getBasicValue(); + aRow[15] = ODatabaseMetaDataResultSet::get0Value(); + aRows.push_back(aRow); + + aRow[1] = new ORowSetValueDecorator(OUString("TIMESTAMP")); + aRow[2] = new ORowSetValueDecorator(sdbc::DataType::TIMESTAMP); + aRow[3] = ODatabaseMetaDataResultSet::get0Value(); + aRow[9] = ODatabaseMetaDataResultSet::getBasicValue(); + aRow[15] = ODatabaseMetaDataResultSet::get0Value(); + aRows.push_back(aRow); + } + + pResult->setRows(aRows); + return xRef; +} + + +uno::Reference<sdbc::XResultSet> SAL_CALL OWriterDatabaseMetaData::getColumns( + const uno::Any& /*catalog*/, const OUString& /*schemaPattern*/, const OUString& tableNamePattern, + const OUString& columnNamePattern) throw(css::sdbc::SQLException, css::uno::RuntimeException, std::exception) +{ + ::osl::MutexGuard aGuard(m_aMutex); + + uno::Reference<sdbcx::XTablesSupplier> xTables = m_pConnection->createCatalog(); + if (!xTables.is()) + throw sdbc::SQLException(); + + uno::Reference<container::XNameAccess> xNames = xTables->getTables(); + if (!xNames.is()) + throw sdbc::SQLException(); + + ODatabaseMetaDataResultSet::ORows aRows; + ODatabaseMetaDataResultSet::ORow aRow(19); + + aRow[10] = new ORowSetValueDecorator((sal_Int32)10); + + uno::Sequence<OUString> aTabNames(xNames->getElementNames()); + const OUString* pTabIter = aTabNames.getConstArray(); + const OUString* pTabEnd = pTabIter + aTabNames.getLength(); + for (; pTabIter != pTabEnd; ++pTabIter) + { + if (match(tableNamePattern,*pTabIter,'\0')) + { + uno::Reference<sdbcx::XColumnsSupplier> xTable(xNames->getByName(*pTabIter), uno::UNO_QUERY_THROW); + aRow[3] = new ORowSetValueDecorator(*pTabIter); + + uno::Reference<container::XNameAccess> xColumns = xTable->getColumns(); + if (!xColumns.is()) + throw sdbc::SQLException(); + + uno::Sequence<OUString> aColNames(xColumns->getElementNames()); + + const OUString* pColumnIter = aColNames.getConstArray(); + const OUString* pEnd = pColumnIter + aColNames.getLength(); + uno::Reference<beans::XPropertySet> xColumn; + for (sal_Int32 i=1; pColumnIter != pEnd; ++pColumnIter,++i) + { + if (match(columnNamePattern,*pColumnIter,'\0')) + { + aRow[4] = new ORowSetValueDecorator(*pColumnIter); + + xColumns->getByName(*pColumnIter) >>= xColumn; + OSL_ENSURE(xColumn.is(),"Columns contains a column who isn't a fastpropertyset!"); + aRow[5] = new ORowSetValueDecorator(::comphelper::getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE)))); + aRow[6] = new ORowSetValueDecorator(::comphelper::getString(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME)))); + aRow[7] = new ORowSetValueDecorator(::comphelper::getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION)))); + // aRow[8] = xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME)); + aRow[9] = new ORowSetValueDecorator(::comphelper::getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE)))); + aRow[11] = new ORowSetValueDecorator(::comphelper::getINT32(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE)))); + // aRow[12] = xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME)); + aRow[13] = new ORowSetValueDecorator(::comphelper::getString(xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE)))); + // aRow[14] = xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME)); + // aRow[15] = xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME)); + switch (sal_Int32(aRow[5]->getValue())) + { + case sdbc::DataType::CHAR: + case sdbc::DataType::VARCHAR: + aRow[16] = new ORowSetValueDecorator((sal_Int32)254); + break; + case sdbc::DataType::LONGVARCHAR: + aRow[16] = new ORowSetValueDecorator((sal_Int32)65535); + break; + default: + aRow[16] = new ORowSetValueDecorator((sal_Int32)0); + } + aRow[17] = new ORowSetValueDecorator(i); + switch (sal_Int32(aRow[11]->getValue())) + { + case sdbc::ColumnValue::NO_NULLS: + aRow[18] = new ORowSetValueDecorator(OUString("NO")); + break; + case sdbc::ColumnValue::NULLABLE: + aRow[18] = new ORowSetValueDecorator(OUString("YES")); + break; + default: + aRow[18] = new ORowSetValueDecorator(OUString()); + } + aRows.push_back(aRow); + } + } + } + } + + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eColumns); + uno::Reference<sdbc::XResultSet> xRef = pResult; + pResult->setRows(aRows); + + return xRef; +} + + +OUString SAL_CALL OWriterDatabaseMetaData::getURL() throw(css::sdbc::SQLException, css::uno::RuntimeException, std::exception) +{ + ::osl::MutexGuard aGuard(m_aMutex); + + return "sdbc:writer:" + m_pConnection->getURL(); +} + + +sal_Int32 SAL_CALL OWriterDatabaseMetaData::getMaxBinaryLiteralLength() throw(css::sdbc::SQLException, css::uno::RuntimeException, std::exception) +{ + return SAL_MAX_INT32; +} + + +sal_Int32 SAL_CALL OWriterDatabaseMetaData::getMaxCharLiteralLength() throw(css::sdbc::SQLException, css::uno::RuntimeException, std::exception) +{ + return SAL_MAX_INT32; +} + +sal_Int32 SAL_CALL OWriterDatabaseMetaData::getMaxColumnNameLength() throw(css::sdbc::SQLException, css::uno::RuntimeException, std::exception) +{ + return SAL_MAX_INT32; +} + +sal_Int32 SAL_CALL OWriterDatabaseMetaData::getMaxColumnsInIndex() throw(css::sdbc::SQLException, css::uno::RuntimeException, std::exception) +{ + return 1; +} + +sal_Int32 SAL_CALL OWriterDatabaseMetaData::getMaxColumnsInTable() throw(css::sdbc::SQLException, css::uno::RuntimeException, std::exception) +{ + return 256; +} + +uno::Reference<sdbc::XResultSet> SAL_CALL OWriterDatabaseMetaData::getTables( + const uno::Any& /*catalog*/, const OUString& /*schemaPattern*/, + const OUString& tableNamePattern, const uno::Sequence< OUString >& types) throw(css::sdbc::SQLException, css::uno::RuntimeException, std::exception) +{ + ::osl::MutexGuard aGuard(m_aMutex); + + ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTables); + uno::Reference<sdbc::XResultSet> xRef = pResult; + + // check if ORowSetValue type is given + // when no types are given then we have to return all tables e.g. TABLE + + OUString aTable("TABLE"); + + bool bTableFound = true; + sal_Int32 nLength = types.getLength(); + if (nLength) + { + bTableFound = false; + + const OUString* pIter = types.getConstArray(); + const OUString* pEnd = pIter + nLength; + for (; pIter != pEnd; ++pIter) + { + if (*pIter == aTable) + { + bTableFound = true; + break; + } + } + } + if (!bTableFound) + return xRef; + + // get the table names from the document + + OWriterConnection::ODocHolder aDocHolder(static_cast<OWriterConnection*>(m_pConnection)); + uno::Reference<text::XTextTablesSupplier> xDoc(aDocHolder.getDoc(), uno::UNO_QUERY); + if (!xDoc.is()) + throw sdbc::SQLException(); + uno::Reference<container::XNameAccess> xTables = xDoc->getTextTables(); + if (!xTables.is()) + throw sdbc::SQLException(); + uno::Sequence<OUString> aTableNames = xTables->getElementNames(); + + ODatabaseMetaDataResultSet::ORows aRows; + sal_Int32 nTableCount = aTableNames.getLength(); + for (sal_Int32 nTable=0; nTable<nTableCount; nTable++) + { + OUString aName = aTableNames[nTable]; + if (match(tableNamePattern,aName,'\0')) + { + ODatabaseMetaDataResultSet::ORow aRow { nullptr, nullptr, nullptr }; + aRow.reserve(6); + aRow.push_back(new ORowSetValueDecorator(aName)); + aRow.push_back(new ORowSetValueDecorator(aTable)); + aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); + aRows.push_back(aRow); + } + } + + pResult->setRows(aRows); + + return xRef; +} + +} // namespace writer +} // namespace connectivity + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/writer/WDriver.cxx b/connectivity/source/drivers/writer/WDriver.cxx new file mode 100644 index 000000000000..2e3d81be5a5b --- /dev/null +++ b/connectivity/source/drivers/writer/WDriver.cxx @@ -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 . + */ + +#include "writer/WDriver.hxx" +#include "writer/WConnection.hxx" +#include <com/sun/star/lang/DisposedException.hpp> +#include <connectivity/dbexception.hxx> +#include "resource/sharedresources.hxx" +#include "resource/common_res.hrc" +#include <comphelper/processfactory.hxx> + +using namespace connectivity::file; +using namespace ::com::sun::star; + +namespace connectivity +{ +namespace writer +{ + +OUString ODriver::getImplementationName_Static() throw(uno::RuntimeException) +{ + return OUString("com.sun.star.comp.sdbc.writer.ODriver"); +} + +OUString SAL_CALL ODriver::getImplementationName() throw(uno::RuntimeException, std::exception) +{ + return getImplementationName_Static(); +} + +uno::Reference< css::uno::XInterface > SAL_CALL +ODriver_CreateInstance(const uno::Reference< + lang::XMultiServiceFactory >& _rxFactory) throw( css::uno::Exception ) +{ + return *(new ODriver(comphelper::getComponentContext(_rxFactory))); +} + +uno::Reference< sdbc::XConnection > SAL_CALL ODriver::connect(const OUString& url, + const uno::Sequence< beans::PropertyValue >& info) throw(sdbc::SQLException, uno::RuntimeException, std::exception) +{ + ::osl::MutexGuard aGuard(m_aMutex); + if (ODriver_BASE::rBHelper.bDisposed) + throw lang::DisposedException(); + + if (! acceptsURL(url)) + return nullptr; + + OWriterConnection* pCon = new OWriterConnection(this); + pCon->construct(url, info); + uno::Reference< sdbc::XConnection > xCon = pCon; + m_xConnections.push_back(uno::WeakReferenceHelper(*pCon)); + + return xCon; +} + +sal_Bool SAL_CALL ODriver::acceptsURL(const OUString& url) throw(sdbc::SQLException, uno::RuntimeException, std::exception) +{ + return url.startsWith("sdbc:writer:"); +} + +uno::Sequence< sdbc::DriverPropertyInfo > SAL_CALL ODriver::getPropertyInfo(const OUString& url, const uno::Sequence< beans::PropertyValue >& /*info*/) throw(sdbc::SQLException, uno::RuntimeException, std::exception) +{ + if (!acceptsURL(url)) + { + SharedResources aResources; + const OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR); + ::dbtools::throwGenericSQLException(sMessage,*this); + } + return uno::Sequence< sdbc::DriverPropertyInfo >(); +} + +} // namespace writer +} // namespace connectivity + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/writer/WTable.cxx b/connectivity/source/drivers/writer/WTable.cxx new file mode 100644 index 000000000000..b8facb1d14cf --- /dev/null +++ b/connectivity/source/drivers/writer/WTable.cxx @@ -0,0 +1,420 @@ +/* -*- 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 "writer/WTable.hxx" +#include <com/sun/star/sdbc/ColumnValue.hpp> +#include <com/sun/star/sdbc/DataType.hpp> +#include <com/sun/star/sdbc/XRow.hpp> +#include <com/sun/star/text/XTextDocument.hpp> +#include <com/sun/star/text/XTextTable.hpp> +#include <com/sun/star/text/XTextTablesSupplier.hpp> +#include <com/sun/star/table/XCellRange.hpp> +#include <com/sun/star/util/NumberFormat.hpp> +#include <com/sun/star/util/XNumberFormatsSupplier.hpp> +#include <com/sun/star/text/XText.hpp> +#include <svl/converter.hxx> +#include "writer/WConnection.hxx" +#include "component/CColumns.hxx" +#include <connectivity/sdbcx/VColumn.hxx> +#include <rtl/ustrbuf.hxx> +#include <osl/thread.h> +#include <cppuhelper/queryinterface.hxx> +#include <comphelper/sequence.hxx> +#include <svl/zforlist.hxx> +#include <rtl/math.hxx> +#include <comphelper/extract.hxx> +#include <connectivity/dbexception.hxx> +#include <connectivity/dbconversion.hxx> +#include <comphelper/types.hxx> +#include <connectivity/StdTypeDefs.hxx> +#include <connectivity/sdbcx/VCollection.hxx> + +using namespace ::com::sun::star; + +static void lcl_GetDataArea(const uno::Reference<text::XTextTable>& xTable, sal_Int32& rColumnCount, sal_Int32& rRowCount) +{ + uno::Reference<container::XIndexAccess> xColumns(xTable->getColumns(), uno::UNO_QUERY); + if (xColumns.is()) + rColumnCount = xColumns->getCount(); + + uno::Reference<container::XIndexAccess> xRows(xTable->getRows(), uno::UNO_QUERY); + if (xRows.is()) + rRowCount = xRows->getCount() - 1; // first row (headers) is not counted + +} + +static void lcl_GetColumnInfo(const uno::Reference<text::XTextTable>& xTable, + sal_Int32 nDocColumn, sal_Int32 nStartRow, bool bHasHeaders, + OUString& rName, sal_Int32& rDataType, bool& rCurrency) +{ + uno::Reference<table::XCellRange> xCellRange(xTable, uno::UNO_QUERY); + // get column name from first row, if range contains headers + if (bHasHeaders) + { + uno::Reference<text::XText> xHeaderText(xCellRange->getCellByPosition(nDocColumn, nStartRow), uno::UNO_QUERY); + if (xHeaderText.is()) + rName = xHeaderText->getString(); + } + + rCurrency = false; + rDataType = sdbc::DataType::VARCHAR; +} + + +static void lcl_SetValue(connectivity::ORowSetValue& rValue, const uno::Reference<text::XTextTable>& xTable, + sal_Int32 nStartCol, sal_Int32 nStartRow, bool bHasHeaders, + sal_Int32 nDBRow, sal_Int32 nDBColumn) +{ + sal_Int32 nDocColumn = nStartCol + nDBColumn - 1; // database counts from 1 + sal_Int32 nDocRow = nStartRow + nDBRow - 1; + if (bHasHeaders) + ++nDocRow; + + uno::Reference<table::XCellRange> xCellRange(xTable, uno::UNO_QUERY); + const uno::Reference<table::XCell> xCell = xCellRange->getCellByPosition(nDocColumn, nDocRow); + if (xCell.is()) + { + const uno::Reference<text::XText> xText(xCell, uno::UNO_QUERY); + if (xText.is()) + rValue = xText->getString(); + } +} + +namespace connectivity +{ +namespace writer +{ + +void OWriterTable::fillColumns() +{ + if (!m_xTable.is()) + throw sdbc::SQLException(); + + OUString aTypeName; + ::comphelper::UStringMixEqual aCase(m_pConnection->getMetaData()->supportsMixedCaseQuotedIdentifiers()); + const bool bStoresMixedCaseQuotedIdentifiers = getConnection()->getMetaData()->supportsMixedCaseQuotedIdentifiers(); + + for (sal_Int32 i = 0; i < m_nDataCols; i++) + { + OUString aColumnName; + sal_Int32 eType = sdbc::DataType::OTHER; + bool bCurrency = false; + + lcl_GetColumnInfo(m_xTable, m_nStartCol + i, m_nStartRow, m_bHasHeaders, + aColumnName, eType, bCurrency); + + sal_Int32 nPrecision = 0; //! ... + sal_Int32 nDecimals = 0; //! ... + + switch (eType) + { + case sdbc::DataType::VARCHAR: + aTypeName = "VARCHAR"; + break; + case sdbc::DataType::DECIMAL: + aTypeName = "DECIMAL"; + break; + case sdbc::DataType::BIT: + aTypeName = "BOOL"; + break; + case sdbc::DataType::DATE: + aTypeName = "DATE"; + break; + case sdbc::DataType::TIME: + aTypeName = "TIME"; + break; + case sdbc::DataType::TIMESTAMP: + aTypeName = "TIMESTAMP"; + break; + default: + SAL_WARN("connectivity.writer", "missing type name"); + aTypeName.clear(); + } + + // check if the column name already exists + OUString aAlias = aColumnName; + OSQLColumns::Vector::const_iterator aFind = connectivity::find(m_aColumns->get().begin(),m_aColumns->get().end(),aAlias,aCase); + sal_Int32 nExprCnt = 0; + while (aFind != m_aColumns->get().end()) + { + (aAlias = aColumnName) += OUString::number(++nExprCnt); + aFind = connectivity::find(m_aColumns->get().begin(),m_aColumns->get().end(),aAlias,aCase); + } + + sdbcx::OColumn* pColumn = new sdbcx::OColumn(aAlias, aTypeName, OUString(),OUString(), + sdbc::ColumnValue::NULLABLE, nPrecision, nDecimals, + eType, false, false, bCurrency, + bStoresMixedCaseQuotedIdentifiers, + m_CatalogName, getSchema(), getName()); + uno::Reference< XPropertySet> xCol = pColumn; + m_aColumns->get().push_back(xCol); + m_aTypes.push_back(eType); + m_aPrecisions.push_back(nPrecision); + m_aScales.push_back(nDecimals); + } +} + + +OWriterTable::OWriterTable(sdbcx::OCollection* _pTables, OWriterConnection* _pConnection, + const OUString& Name, + const OUString& Type, + const OUString& Description, + const OUString& SchemaName, + const OUString& CatalogName + ) : OWriterTable_BASE(_pTables,_pConnection,Name, + Type, + Description, + SchemaName, + CatalogName) + ,m_pWriterConnection(_pConnection) + ,m_nStartCol(0) + ,m_nStartRow(0) + ,m_nDataCols(0) + ,m_nDataRows(0) + ,m_bHasHeaders(false) + ,m_aNullDate(::Date::EMPTY) +{ +} + +void OWriterTable::construct() +{ + uno::Reference<text::XTextDocument> xDoc = m_pWriterConnection->acquireDoc(); + if (xDoc.is()) + { + uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(xDoc, uno::UNO_QUERY); + uno::Reference<container::XNameAccess> xTables = xTextTablesSupplier->getTextTables(); + if (xTables.is() && xTables->hasByName(m_Name)) + { + m_xTable.set(xTables->getByName(m_Name), uno::UNO_QUERY); + if (m_xTable.is()) + { + lcl_GetDataArea(m_xTable, m_nDataCols, m_nDataRows); + m_bHasHeaders = true; + } + } + + uno::Reference<util::XNumberFormatsSupplier> xSupp(xDoc, uno::UNO_QUERY); + if (xSupp.is()) + m_xFormats = xSupp->getNumberFormats(); + } + + fillColumns(); + + refreshColumns(); +} + +void OWriterTable::refreshColumns() +{ + ::osl::MutexGuard aGuard(m_aMutex); + + TStringVector aVector; + + OSQLColumns::Vector::const_iterator aEnd = m_aColumns->get().end(); + for (OSQLColumns::Vector::const_iterator aIter = m_aColumns->get().begin(); aIter != aEnd; ++aIter) + aVector.push_back(uno::Reference<XNamed>(*aIter, uno::UNO_QUERY)->getName()); + + if (m_pColumns) + m_pColumns->reFill(aVector); + else + m_pColumns = new component::OComponentColumns(this, m_aMutex, aVector); +} + +void OWriterTable::refreshIndexes() +{ + // Writer table has no index +} + + +void SAL_CALL OWriterTable::disposing() +{ + OFileTable::disposing(); + ::osl::MutexGuard aGuard(m_aMutex); + m_aColumns = nullptr; + if (m_pWriterConnection) + m_pWriterConnection->releaseDoc(); + m_pWriterConnection = nullptr; + +} + +uno::Sequence< uno::Type > SAL_CALL OWriterTable::getTypes() throw(css::uno::RuntimeException, std::exception) +{ + uno::Sequence< uno::Type > aTypes = file::OTable_TYPEDEF::getTypes(); + std::vector<uno::Type> aOwnTypes; + aOwnTypes.reserve(aTypes.getLength()); + + const uno::Type* pBegin = aTypes.getConstArray(); + const uno::Type* pEnd = pBegin + aTypes.getLength(); + for (; pBegin != pEnd; ++pBegin) + { + if (!(*pBegin == cppu::UnoType<XKeysSupplier>::get()|| + *pBegin == cppu::UnoType<XIndexesSupplier>::get()|| + *pBegin == cppu::UnoType<XRename>::get()|| + *pBegin == cppu::UnoType<XAlterTable>::get()|| + *pBegin == cppu::UnoType<XDataDescriptorFactory>::get())) + aOwnTypes.push_back(*pBegin); + } + aOwnTypes.push_back(cppu::UnoType<css::lang::XUnoTunnel>::get()); + + return uno::Sequence< uno::Type >(aOwnTypes.data(), aOwnTypes.size()); +} + + +uno::Any SAL_CALL OWriterTable::queryInterface(const uno::Type& rType) throw(css::uno::RuntimeException, std::exception) +{ + if (rType == cppu::UnoType<XKeysSupplier>::get()|| + rType == cppu::UnoType<XIndexesSupplier>::get()|| + rType == cppu::UnoType<XRename>::get()|| + rType == cppu::UnoType<XAlterTable>::get()|| + rType == cppu::UnoType<XDataDescriptorFactory>::get()) + return uno::Any(); + + const uno::Any aRet = ::cppu::queryInterface(rType,static_cast< css::lang::XUnoTunnel*>(this)); + return aRet.hasValue() ? aRet : file::OTable_TYPEDEF::queryInterface(rType); +} + + +uno::Sequence< sal_Int8 > OWriterTable::getUnoTunnelImplementationId() +{ + static ::cppu::OImplementationId implId; + + return implId.getImplementationId(); +} + +sal_Int64 OWriterTable::getSomething(const uno::Sequence< sal_Int8 >& rId) throw(css::uno::RuntimeException, std::exception) +{ + return (rId.getLength() == 16 && 0 == memcmp(getUnoTunnelImplementationId().getConstArray(), rId.getConstArray(), 16)) + ? reinterpret_cast< sal_Int64 >(this) + : OWriterTable_BASE::getSomething(rId); +} + +sal_Int32 OWriterTable::getCurrentLastPos() const +{ + return m_nDataRows; +} + +bool OWriterTable::seekRow(IResultSetHelper::Movement eCursorPosition, sal_Int32 nOffset, sal_Int32& nCurPos) +{ + // prepare positioning: + + sal_uInt32 nNumberOfRecords = m_nDataRows; + sal_uInt32 nTempPos = m_nFilePos; + m_nFilePos = nCurPos; + + switch (eCursorPosition) + { + case IResultSetHelper::NEXT: + m_nFilePos++; + break; + case IResultSetHelper::PRIOR: + if (m_nFilePos > 0) + m_nFilePos--; + break; + case IResultSetHelper::FIRST: + m_nFilePos = 1; + break; + case IResultSetHelper::LAST: + m_nFilePos = nNumberOfRecords; + break; + case IResultSetHelper::RELATIVE1: + m_nFilePos = (m_nFilePos + nOffset < 0) ? 0L + : (sal_uInt32)(m_nFilePos + nOffset); + break; + case IResultSetHelper::ABSOLUTE1: + case IResultSetHelper::BOOKMARK: + m_nFilePos = (sal_uInt32)nOffset; + break; + } + + if (m_nFilePos > (sal_Int32)nNumberOfRecords) + m_nFilePos = (sal_Int32)nNumberOfRecords + 1; + + if (m_nFilePos == 0 || m_nFilePos == (sal_Int32)nNumberOfRecords + 1) + goto Error; + else + { + //! read buffer / setup row object etc? + } + goto End; + +Error: + switch (eCursorPosition) + { + case IResultSetHelper::PRIOR: + case IResultSetHelper::FIRST: + m_nFilePos = 0; + break; + case IResultSetHelper::LAST: + case IResultSetHelper::NEXT: + case IResultSetHelper::ABSOLUTE1: + case IResultSetHelper::RELATIVE1: + if (nOffset > 0) + m_nFilePos = nNumberOfRecords + 1; + else if (nOffset < 0) + m_nFilePos = 0; + break; + case IResultSetHelper::BOOKMARK: + m_nFilePos = nTempPos; // previous position + } + // aStatus.Set(SDB_STAT_NO_DATA_FOUND); + return false; + +End: + nCurPos = m_nFilePos; + return true; +} + +bool OWriterTable::fetchRow(OValueRefRow& _rRow, const OSQLColumns& _rCols, + bool bRetrieveData) +{ + // read the bookmark + + _rRow->setDeleted(false); + *(_rRow->get())[0] = m_nFilePos; + + if (!bRetrieveData) + return true; + + // fields + + OSQLColumns::Vector::const_iterator aIter = _rCols.get().begin(); + OSQLColumns::Vector::const_iterator aEnd = _rCols.get().end(); + const OValueRefVector::Vector::size_type nCount = _rRow->get().size(); + for (OValueRefVector::Vector::size_type i = 1; aIter != aEnd && i < nCount; + ++aIter, i++) + { + if ((_rRow->get())[i]->isBound()) + { + lcl_SetValue((_rRow->get())[i]->get(), m_xTable, m_nStartCol, m_nStartRow, m_bHasHeaders, + m_nFilePos, i); + } + } + return true; +} + +void OWriterTable::FileClose() +{ + ::osl::MutexGuard aGuard(m_aMutex); + + OWriterTable_BASE::FileClose(); +} + +} // namespace writer +} // namespace connectivity + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/writer/WTables.cxx b/connectivity/source/drivers/writer/WTables.cxx new file mode 100644 index 000000000000..685a5b778c54 --- /dev/null +++ b/connectivity/source/drivers/writer/WTables.cxx @@ -0,0 +1,50 @@ +/* -*- 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 "writer/WTables.hxx" + +#include <sal/config.h> + +#include <comphelper/types.hxx> + +#include <writer/WConnection.hxx> +#include "file/FCatalog.hxx" +#include "file/FConnection.hxx" +#include "writer/WCatalog.hxx" +#include "writer/WTable.hxx" + +using namespace ::com::sun::star; + +namespace connectivity +{ +namespace writer +{ + +sdbcx::ObjectType OWriterTables::createObject(const OUString& rName) +{ + OWriterTable* pTable = new OWriterTable(this, static_cast<OWriterConnection*>(static_cast<file::OFileCatalog&>(m_rParent).getConnection()), rName, "TABLE"); + sdbcx::ObjectType xRet = pTable; + pTable->construct(); + return xRet; +} + +} // namespace writer +} // namespace connectivity + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/writer/Wservices.cxx b/connectivity/source/drivers/writer/Wservices.cxx new file mode 100644 index 000000000000..4e439bece7e0 --- /dev/null +++ b/connectivity/source/drivers/writer/Wservices.cxx @@ -0,0 +1,102 @@ +/* -*- 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 "writer/WDriver.hxx" +#include <cppuhelper/factory.hxx> + +using namespace com::sun::star; + +typedef uno::Reference< lang::XSingleServiceFactory > (SAL_CALL* createFactoryFunc) +( + const uno::Reference< lang::XMultiServiceFactory >& rServiceManager, + const OUString& rComponentName, + ::cppu::ComponentInstantiation pCreateFunction, + const uno::Sequence< OUString >& rServiceNames, + rtl_ModuleCount* +); + + +struct ProviderRequest +{ + uno::Reference< lang::XSingleServiceFactory > xRet; + uno::Reference< lang::XMultiServiceFactory > const xServiceManager; + OUString const sImplementationName; + + ProviderRequest( + void* pServiceManager, + sal_Char const* pImplementationName + ) + : xServiceManager(static_cast<lang::XMultiServiceFactory*>(pServiceManager)) + , sImplementationName(OUString::createFromAscii(pImplementationName)) + { + } + + bool CREATE_PROVIDER( + const OUString& Implname, + const uno::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* SAL_CALL connectivity_writer_component_getFactory( + const sal_Char* pImplementationName, + void* pServiceManager, + void* /*pRegistryKey*/) +{ + void* pRet = nullptr; + if (pServiceManager) + { + ProviderRequest aReq(pServiceManager,pImplementationName); + + aReq.CREATE_PROVIDER( + connectivity::writer::ODriver::getImplementationName_Static(), + connectivity::writer::ODriver::getSupportedServiceNames_Static(), + connectivity::writer::ODriver_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/writer/writer.component b/connectivity/source/drivers/writer/writer.component new file mode 100644 index 000000000000..3bf9d6e79292 --- /dev/null +++ b/connectivity/source/drivers/writer/writer.component @@ -0,0 +1,17 @@ +<?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/. + --> + +<component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@" + prefix="connectivity_writer" + xmlns="http://openoffice.org/2010/uno-components"> + <implementation name="com.sun.star.comp.sdbc.writer.ODriver"> + <service name="com.sun.star.sdbc.Driver"/> + <service name="com.sun.star.sdbcx.Driver"/> + </implementation> +</component> diff --git a/connectivity/source/inc/calc/CColumns.hxx b/connectivity/source/inc/component/CColumns.hxx similarity index 76% rename from connectivity/source/inc/calc/CColumns.hxx rename to connectivity/source/inc/component/CColumns.hxx index f178e80a396c..3ecec1d0b637 100644 --- a/connectivity/source/inc/calc/CColumns.hxx +++ b/connectivity/source/inc/component/CColumns.hxx @@ -17,21 +17,22 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_CALC_CCOLUMNS_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_CALC_CCOLUMNS_HXX +#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_COMPONENT_CCOLUMNS_HXX +#define INCLUDED_CONNECTIVITY_SOURCE_INC_COMPONENT_CCOLUMNS_HXX #include "file/FColumns.hxx" namespace connectivity { - namespace calc + namespace component { - class OCalcColumns : public file::OColumns + /// Columns implementation for Writer tables and Calc sheets. + class OOO_DLLPUBLIC_FILE OComponentColumns : public file::OColumns { protected: virtual sdbcx::ObjectType createObject(const OUString& _rName) override; public: - OCalcColumns(file::OFileTable* _pTable, + OComponentColumns(file::OFileTable* _pTable, ::osl::Mutex& _rMutex, const TStringVector &_rVector ) : file::OColumns(_pTable,_rMutex,_rVector) @@ -41,6 +42,6 @@ namespace connectivity } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_CALC_CCOLUMNS_HXX +#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_COMPONENT_CCOLUMNS_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/calc/CPreparedStatement.hxx b/connectivity/source/inc/component/CPreparedStatement.hxx similarity index 69% rename from connectivity/source/inc/calc/CPreparedStatement.hxx rename to connectivity/source/inc/component/CPreparedStatement.hxx index 91507792dc10..55f8bf9f84c0 100644 --- a/connectivity/source/inc/calc/CPreparedStatement.hxx +++ b/connectivity/source/inc/component/CPreparedStatement.hxx @@ -17,27 +17,28 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_CALC_CPREPAREDSTATEMENT_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_CALC_CPREPAREDSTATEMENT_HXX +#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_COMPONENT_CPREPAREDSTATEMENT_HXX +#define INCLUDED_CONNECTIVITY_SOURCE_INC_COMPONENT_CPREPAREDSTATEMENT_HXX #include "file/FPreparedStatement.hxx" namespace connectivity { - namespace calc + namespace component { class OConnection; - class OCalcPreparedStatement : public file::OPreparedStatement + /// Prepared statement implementation for Writer tables and Calc sheets. + class OOO_DLLPUBLIC_FILE OComponentPreparedStatement : public file::OPreparedStatement { protected: virtual file::OResultSet* createResultSet() override; public: - OCalcPreparedStatement( file::OConnection* _pConnection) : file::OPreparedStatement( _pConnection){} + OComponentPreparedStatement( file::OConnection* _pConnection) : file::OPreparedStatement( _pConnection){} DECLARE_SERVICE_INFO(); }; } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_CALC_CPREPAREDSTATEMENT_HXX +#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_COMPONENT_CPREPAREDSTATEMENT_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/calc/CResultSet.hxx b/connectivity/source/inc/component/CResultSet.hxx similarity index 82% rename from connectivity/source/inc/calc/CResultSet.hxx rename to connectivity/source/inc/component/CResultSet.hxx index aa8278a41417..b9fc94d03437 100644 --- a/connectivity/source/inc/calc/CResultSet.hxx +++ b/connectivity/source/inc/component/CResultSet.hxx @@ -16,8 +16,8 @@ * 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_CALC_CRESULTSET_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_CALC_CRESULTSET_HXX +#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_COMPONENT_CRESULTSET_HXX +#define INCLUDED_CONNECTIVITY_SOURCE_INC_COMPONENT_CRESULTSET_HXX #include "file/FResultSet.hxx" #include <com/sun/star/sdbcx/XRowLocate.hpp> @@ -26,19 +26,20 @@ namespace connectivity { - namespace calc + namespace component { - class OCalcResultSet; + class OComponentResultSet; // these typedef's are only necessary for the compiler typedef ::cppu::ImplHelper2< css::sdbcx::XRowLocate, - css::sdbcx::XDeleteRows> OCalcResultSet_BASE; - typedef file::OResultSet OCalcResultSet_BASE2; - typedef ::comphelper::OPropertyArrayUsageHelper<OCalcResultSet> OCalcResultSet_BASE3; + css::sdbcx::XDeleteRows> OComponentResultSet_BASE; + typedef file::OResultSet OComponentResultSet_BASE2; + typedef ::comphelper::OPropertyArrayUsageHelper<OComponentResultSet> OComponentResultSet_BASE3; - class OCalcResultSet : public OCalcResultSet_BASE2, - public OCalcResultSet_BASE, - public OCalcResultSet_BASE3 + /// ResultSet implementation for Writer tables and Calc sheets. + class OOO_DLLPUBLIC_FILE OComponentResultSet : public OComponentResultSet_BASE2, + public OComponentResultSet_BASE, + public OComponentResultSet_BASE3 { bool m_bBookmarkable; protected: @@ -50,7 +51,7 @@ namespace connectivity public: DECLARE_SERVICE_INFO(); - OCalcResultSet( file::OStatement_Base* pStmt,connectivity::OSQLParseTreeIterator& _aSQLIterator); + OComponentResultSet( file::OStatement_Base* pStmt,connectivity::OSQLParseTreeIterator& _aSQLIterator); private: // XInterface @@ -78,6 +79,6 @@ namespace connectivity } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_CALC_CRESULTSET_HXX +#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_COMPONENT_CRESULTSET_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/calc/CStatement.hxx b/connectivity/source/inc/component/CStatement.hxx similarity index 71% rename from connectivity/source/inc/calc/CStatement.hxx rename to connectivity/source/inc/component/CStatement.hxx index e9a3d552eab0..695d92a4e225 100644 --- a/connectivity/source/inc/calc/CStatement.hxx +++ b/connectivity/source/inc/component/CStatement.hxx @@ -17,27 +17,28 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_CALC_CSTATEMENT_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_INC_CALC_CSTATEMENT_HXX +#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_COMPONENT_CSTATEMENT_HXX +#define INCLUDED_CONNECTIVITY_SOURCE_INC_COMPONENT_CSTATEMENT_HXX #include "file/FStatement.hxx" namespace connectivity { - namespace calc + namespace component { class OConnection; - class OCalcStatement : public file::OStatement + /// Statement implementation for Writer tables and Calc sheets. + class OOO_DLLPUBLIC_FILE OComponentStatement : public file::OStatement { protected: virtual file::OResultSet* createResultSet() override; public: - OCalcStatement( file::OConnection* _pConnection) : file::OStatement( _pConnection){} + OComponentStatement( file::OConnection* _pConnection) : file::OStatement( _pConnection){} DECLARE_SERVICE_INFO(); }; } } -#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_CALC_CSTATEMENT_HXX +#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_COMPONENT_CSTATEMENT_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/writer/WCatalog.hxx b/connectivity/source/inc/writer/WCatalog.hxx new file mode 100644 index 000000000000..b1ba9a582714 --- /dev/null +++ b/connectivity/source/inc/writer/WCatalog.hxx @@ -0,0 +1,45 @@ +/* -*- 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_WRITER_WCATALOG_HXX +#define INCLUDED_CONNECTIVITY_SOURCE_INC_WRITER_WCATALOG_HXX + +#include "file/FCatalog.hxx" + +namespace connectivity +{ +namespace writer +{ + +class OWriterConnection; +class OWriterCatalog : public file::OFileCatalog +{ +public: + void refreshTables() override; + +public: + OWriterCatalog(OWriterConnection* _pCon); +}; + +} // namespace writer +} // namespace connectivity + +#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_WRITER_WCATALOG_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/writer/WConnection.hxx b/connectivity/source/inc/writer/WConnection.hxx new file mode 100644 index 000000000000..d0aaaa911ba4 --- /dev/null +++ b/connectivity/source/inc/writer/WConnection.hxx @@ -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 . + */ + +#ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_WRITER_WCONNECTION_HXX +#define INCLUDED_CONNECTIVITY_SOURCE_INC_WRITER_WCONNECTION_HXX + +#include <memory> +#include "file/FConnection.hxx" +#include <com/sun/star/frame/XDesktop2.hpp> +#include <com/sun/star/frame/XTerminateListener.hpp> +#include <com/sun/star/uno/DeploymentException.hpp> +#include <unotools/closeveto.hxx> + +namespace com +{ +namespace sun +{ +namespace star +{ +namespace text +{ +class XTextDocument; +} +} +} +} + +namespace utl +{ +class CloseVeto; +} + + +namespace connectivity +{ +namespace writer +{ +class ODriver; +class OWriterConnection : public file::OConnection +{ + // the spreadsheet document: + css::uno::Reference< css::text::XTextDocument > m_xDoc; + OUString m_sPassword; + OUString m_aFileName; + oslInterlockedCount m_nDocCount; + + class CloseVetoButTerminateListener : public cppu::WeakComponentImplHelper<css::frame::XTerminateListener> + { + private: + /// close listener that vetoes so nobody else disposes m_xDoc + std::unique_ptr<utl::CloseVeto> m_pCloseListener; + /// but also listen to XDesktop and if app is terminating anyway, dispose m_xDoc while + /// its still possible to do so properly + css::uno::Reference<css::frame::XDesktop2> m_xDesktop; + osl::Mutex m_aMutex; + public: + CloseVetoButTerminateListener() + : cppu::WeakComponentImplHelper<css::frame::XTerminateListener>(m_aMutex) + { + } + + void start(const css::uno::Reference<css::uno::XInterface>& rCloseable, + const css::uno::Reference<css::frame::XDesktop2>& rDesktop) + { + m_xDesktop = rDesktop; + m_xDesktop->addTerminateListener(this); + m_pCloseListener.reset(new utl::CloseVeto(rCloseable, true)); + } + + void stop() + { + m_pCloseListener.reset(); + if (!m_xDesktop.is()) + return; + m_xDesktop->removeTerminateListener(this); + m_xDesktop.clear(); + } + + // XTerminateListener + virtual void SAL_CALL queryTermination(const css::lang::EventObject& /*rEvent*/) throw(css::frame::TerminationVetoException, css::uno::RuntimeException, std::exception) override + { + } + + virtual void SAL_CALL notifyTermination(const css::lang::EventObject& /*rEvent*/) throw(css::uno::RuntimeException, std::exception) override + { + stop(); + } + + virtual void SAL_CALL disposing() throw(css::uno::RuntimeException, std::exception) override + { + stop(); + cppu::WeakComponentImplHelperBase::disposing(); + } + + virtual void SAL_CALL disposing(const css::lang::EventObject& rEvent) override + { + const bool bShutDown = (rEvent.Source == m_xDesktop); + if (bShutDown) + stop(); + } + }; + + rtl::Reference<CloseVetoButTerminateListener> m_xCloseVetoButTerminateListener; + +public: + OWriterConnection(ODriver* _pDriver); + virtual ~OWriterConnection() override; + + virtual void construct(const OUString& _rUrl, + const css::uno::Sequence< css::beans::PropertyValue >& _rInfo) throw( css::sdbc::SQLException, css::uno::RuntimeException, css::uno::DeploymentException, std::exception) override; + + // XServiceInfo + DECLARE_SERVICE_INFO(); + + // OComponentHelper + virtual void SAL_CALL disposing() override; + + // XConnection + virtual css::uno::Reference< css::sdbc::XDatabaseMetaData > SAL_CALL getMetaData() throw(css::sdbc::SQLException, css::uno::RuntimeException, std::exception) override; + virtual css::uno::Reference< css::sdbcx::XTablesSupplier > createCatalog() override; + virtual css::uno::Reference< css::sdbc::XStatement > SAL_CALL createStatement() throw(css::sdbc::SQLException, css::uno::RuntimeException, std::exception) override; + virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareStatement(const OUString& sql) throw(css::sdbc::SQLException, css::uno::RuntimeException, std::exception) override; + virtual css::uno::Reference< css::sdbc::XPreparedStatement > SAL_CALL prepareCall(const OUString& sql) throw(css::sdbc::SQLException, css::uno::RuntimeException, std::exception) override; + + // no interface methods + css::uno::Reference< css::text::XTextDocument> const& acquireDoc(); + void releaseDoc(); + + class ODocHolder + { + OWriterConnection* m_pConnection; + css::uno::Reference< css::text::XTextDocument> m_xDoc; + public: + ODocHolder(OWriterConnection* _pConnection) : m_pConnection(_pConnection) + { + m_xDoc = m_pConnection->acquireDoc(); + } + ~ODocHolder() + { + m_xDoc.clear(); + m_pConnection->releaseDoc(); + } + const css::uno::Reference< css::text::XTextDocument>& getDoc() const + { + return m_xDoc; + } + }; +}; +} +} + +#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_WRITER_WCONNECTION_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/writer/WDatabaseMetaData.hxx b/connectivity/source/inc/writer/WDatabaseMetaData.hxx new file mode 100644 index 000000000000..ef499f1c9880 --- /dev/null +++ b/connectivity/source/inc/writer/WDatabaseMetaData.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_WRITER_WDATABASEMETADATA_HXX +#define INCLUDED_CONNECTIVITY_SOURCE_INC_WRITER_WDATABASEMETADATA_HXX + +#include "file/FDatabaseMetaData.hxx" + +namespace connectivity +{ +namespace writer +{ + +class OWriterDatabaseMetaData : public file::ODatabaseMetaData +{ + virtual css::uno::Reference< css::sdbc::XResultSet > impl_getTypeInfo_throw() override; + virtual OUString SAL_CALL getURL() throw(css::sdbc::SQLException, css::uno::RuntimeException, std::exception) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getColumns(const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& tableNamePattern, const OUString& columnNamePattern) throw(css::sdbc::SQLException, css::uno::RuntimeException, std::exception) override; + virtual sal_Int32 SAL_CALL getMaxBinaryLiteralLength() throw(css::sdbc::SQLException, css::uno::RuntimeException, std::exception) override; + virtual sal_Int32 SAL_CALL getMaxCharLiteralLength() throw(css::sdbc::SQLException, css::uno::RuntimeException, std::exception) override; + virtual sal_Int32 SAL_CALL getMaxColumnNameLength() throw(css::sdbc::SQLException, css::uno::RuntimeException, std::exception) override; + virtual sal_Int32 SAL_CALL getMaxColumnsInIndex() throw(css::sdbc::SQLException, css::uno::RuntimeException, std::exception) override; + virtual sal_Int32 SAL_CALL getMaxColumnsInTable() throw(css::sdbc::SQLException, css::uno::RuntimeException, std::exception) override; + virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL getTables(const css::uno::Any& catalog, const OUString& schemaPattern, const OUString& tableNamePattern, const css::uno::Sequence< OUString >& types) throw(css::sdbc::SQLException, css::uno::RuntimeException, std::exception) override; +protected: + virtual ~OWriterDatabaseMetaData() override; +public: + OWriterDatabaseMetaData(file::OConnection* pConnection); +}; + +} // namespace writer +} // namespace connectivity + +#endif // INCLUDED_CONNECTIVITY_SOURCE_INC_WRITER_WDATABASEMETADATA_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/inc/writer/WDriver.hxx b/connectivity/source/inc/writer/WDriver.hxx new file mode 100644 index 000000000000..0e6075b0d1ff --- /dev/null +++ b/connectivity/source/inc/writer/WDriver.hxx @@ -0,0 +1,58 @@ +/* -*- 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_WRITER_WDRIVER_HXX +#define INCLUDED_CONNECTIVITY_SOURCE_INC_WRITER_WDRIVER_HXX + +#include "file/FDriver.hxx" + +#include <com/sun/star/lang/XMultiServiceFactory.hpp> + +namespace connectivity +{ +namespace writer +{ +/// @throws css::uno::Exception +css::uno::Reference< css::uno::XInterface > SAL_CALL +ODriver_CreateInstance(const css::uno::Reference< css::lang::XMultiServiceFactory >& _rxFactory) throw( css::uno::Exception ); + +class ODriver : public file::OFileDriver +{ +public: + ODriver(const css::uno::Reference< + css::uno::XComponentContext >& _rxContext) : + file::OFileDriver(_rxContext) {} + + /// @throws css::uno::RuntimeException + static OUString getImplementationName_Static() throw(css::uno::RuntimeException); + OUString SAL_CALL getImplementationName() throw(css::uno::RuntimeException, std::exception) override; + + // XDriver + virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL + connect(const OUString& url, const css::uno::Sequence< ... etc. - the rest is truncated _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits