diff options
Diffstat (limited to 'connectivity/source/drivers/hsqldb')
19 files changed, 316 insertions, 333 deletions
diff --git a/connectivity/source/drivers/hsqldb/HCatalog.cxx b/connectivity/source/drivers/hsqldb/HCatalog.cxx index 029e60f9450a..d905e67399f0 100644 --- a/connectivity/source/drivers/hsqldb/HCatalog.cxx +++ b/connectivity/source/drivers/hsqldb/HCatalog.cxx @@ -30,11 +30,8 @@ using namespace connectivity; using namespace connectivity::hsqldb; using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::beans; using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::container; -using namespace ::com::sun::star::lang; OHCatalog::OHCatalog(const Reference< XConnection >& _xConnection) : sdbcx::OCatalog(_xConnection) ,m_xConnection(_xConnection) @@ -44,8 +41,8 @@ OHCatalog::OHCatalog(const Reference< XConnection >& _xConnection) : sdbcx::OCat void OHCatalog::refreshObjects(const Sequence< OUString >& _sKindOfObject,::std::vector< OUString>& _rNames) { Reference< XResultSet > xResult = m_xMetaData->getTables(Any(), - "%", - "%", + u"%"_ustr, + u"%"_ustr, _sKindOfObject); fillNames(xResult,_rNames); } @@ -54,9 +51,7 @@ void OHCatalog::refreshTables() { ::std::vector< OUString> aVector; - Sequence< OUString > sTableTypes(2); - sTableTypes[0] = "VIEW"; - sTableTypes[1] = "TABLE"; + Sequence< OUString > sTableTypes {u"VIEW"_ustr, u"TABLE"_ustr}; refreshObjects(sTableTypes,aVector); @@ -68,7 +63,7 @@ void OHCatalog::refreshTables() void OHCatalog::refreshViews() { - Sequence< OUString > aTypes { "VIEW" }; + Sequence< OUString > aTypes { u"VIEW"_ustr }; bool bSupportsViews = false; try @@ -105,7 +100,7 @@ void OHCatalog::refreshUsers() { ::std::vector< OUString> aVector; Reference< XStatement > xStmt = m_xConnection->createStatement( ); - Reference< XResultSet > xResult = xStmt->executeQuery("select User from hsqldb.user group by User"); + Reference< XResultSet > xResult = xStmt->executeQuery(u"select User from hsqldb.user group by User"_ustr); if ( xResult.is() ) { Reference< XRow > xRow(xResult,UNO_QUERY); diff --git a/connectivity/source/drivers/hsqldb/HColumns.cxx b/connectivity/source/drivers/hsqldb/HColumns.cxx index 3f03c3616bc1..6906bde4435a 100644 --- a/connectivity/source/drivers/hsqldb/HColumns.cxx +++ b/connectivity/source/drivers/hsqldb/HColumns.cxx @@ -27,10 +27,6 @@ using namespace connectivity::sdbcx; using namespace connectivity; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; -using namespace ::com::sun::star::sdbcx; -using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::container; -using namespace ::com::sun::star::lang; OHSQLColumns::OHSQLColumns( ::cppu::OWeakObject& _rParent ,::osl::Mutex& _rMutex @@ -69,7 +65,7 @@ void OHSQLColumn::construct() Sequence< OUString > SAL_CALL OHSQLColumn::getSupportedServiceNames( ) { - return { "com.sun.star.sdbcx.Column" }; + return { u"com.sun.star.sdbcx.Column"_ustr }; } diff --git a/connectivity/source/drivers/hsqldb/HConnection.cxx b/connectivity/source/drivers/hsqldb/HConnection.cxx index c3ff0169cea7..032d02d90e8a 100644 --- a/connectivity/source/drivers/hsqldb/HConnection.cxx +++ b/connectivity/source/drivers/hsqldb/HConnection.cxx @@ -32,10 +32,11 @@ #include <com/sun/star/beans/PropertyValue.hpp> #include <com/sun/star/sdbc/XDatabaseMetaData2.hpp> +#include <comphelper/propertyvalue.hxx> #include <cppuhelper/exc_hlp.hxx> #include <rtl/ustrbuf.hxx> #include <sal/log.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <resource/sharedresources.hxx> #include <strings.hrc> @@ -75,19 +76,17 @@ namespace connectivity::hsqldb { m_aFlushListeners.disposeAndClear( EventObject( *this ) ); OHsqlConnection_BASE::disposing(); - OConnectionWrapper::disposing(); } OHsqlConnection::OHsqlConnection( const Reference< XDriver >& _rxDriver, const Reference< XConnection >& _xConnection ,const Reference< XComponentContext >& _rxContext ) - :OHsqlConnection_BASE( m_aMutex ) - ,m_aFlushListeners( m_aMutex ) + :m_aFlushListeners( m_aMutex ) ,m_xDriver( _rxDriver ) ,m_xContext( _rxContext ) ,m_bIni(true) ,m_bReadOnly(false) { - setDelegation(_xConnection,_rxContext,m_refCount); + setDelegation(_xConnection, _rxContext); } OHsqlConnection::~OHsqlConnection() @@ -99,9 +98,7 @@ namespace connectivity::hsqldb } } - IMPLEMENT_FORWARD_XINTERFACE2(OHsqlConnection,OHsqlConnection_BASE,OConnectionWrapper) - IMPLEMENT_SERVICE_INFO(OHsqlConnection, "com.sun.star.sdbc.drivers.hsqldb.OHsqlConnection", "com.sun.star.sdbc.Connection") - IMPLEMENT_FORWARD_XTYPEPROVIDER2(OHsqlConnection,OHsqlConnection_BASE,OConnectionWrapper) + IMPLEMENT_SERVICE_INFO(OHsqlConnection, u"com.sun.star.sdbc.drivers.hsqldb.OHsqlConnection"_ustr, u"com.sun.star.sdbc.Connection"_ustr) ::osl::Mutex& OHsqlConnection::getMutex() const @@ -143,7 +140,7 @@ namespace connectivity::hsqldb if ( !m_bReadOnly ) { Reference< XStatement > xStmt( m_xConnection->createStatement(), css::uno::UNO_SET_THROW ); - xStmt->execute( "CHECKPOINT DEFRAG" ); + xStmt->execute( u"CHECKPOINT DEFRAG"_ustr ); } } catch(const Exception& ) @@ -280,8 +277,7 @@ namespace connectivity::hsqldb ::dbtools::qualifiedNameComponents( xMetaData, _rTableName, sCatalog, sSchema, sName, ::dbtools::EComposeRule::Complete ); // get the table information - OUStringBuffer sSQL; - sSQL.append( "SELECT HSQLDB_TYPE FROM INFORMATION_SCHEMA.SYSTEM_TABLES" ); + OUStringBuffer sSQL( "SELECT HSQLDB_TYPE FROM INFORMATION_SCHEMA.SYSTEM_TABLES" ); HTools::appendTableFilterCrit( sSQL, sCatalog, sSchema, sName, true ); sSQL.append( " AND TABLE_TYPE = 'TABLE'" ); @@ -315,13 +311,10 @@ namespace connectivity::hsqldb xProvider.set( GraphicProvider::create(m_xContext) ); // ask the provider to obtain a graphic - Sequence< PropertyValue > aMediaProperties( 1 ); - aMediaProperties[0].Name = "URL"; - aMediaProperties[0].Value <<= OUString( - // load the graphic from the global graphic repository - "private:graphicrepository/" - // the relative path within the images.zip - LINKED_TEXT_TABLE_IMAGE_RESOURCE); + Sequence< PropertyValue > aMediaProperties{ comphelper::makePropertyValue( + u"URL"_ustr, u"private:graphicrepository/" + // the relative path within the images.zip + LINKED_TEXT_TABLE_IMAGE_RESOURCE ""_ustr) }; xGraphic = xProvider->queryGraphic( aMediaProperties ); OSL_ENSURE( xGraphic.is(), "OHsqlConnection::impl_getTextTableIcon_nothrow: the provider did not give us a graphic object!" ); } diff --git a/connectivity/source/drivers/hsqldb/HDriver.cxx b/connectivity/source/drivers/hsqldb/HDriver.cxx index 6ff0f539407b..f43584d1f169 100644 --- a/connectivity/source/drivers/hsqldb/HDriver.cxx +++ b/connectivity/source/drivers/hsqldb/HDriver.cxx @@ -50,7 +50,9 @@ #include <strings.hrc> #include <resource/sharedresources.hxx> #include <i18nlangtag/languagetag.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> +#include <o3tl/string_view.hxx> +#include <vcl/svapp.hxx> #include <memory> @@ -68,9 +70,8 @@ namespace connectivity using namespace css::embed; using namespace css::io; using namespace css::util; - using namespace css::reflection; - constexpr OUStringLiteral IMPL_NAME = u"com.sun.star.sdbcx.comp.hsqldb.Driver"; + constexpr OUString IMPL_NAME = u"com.sun.star.sdbcx.comp.hsqldb.Driver"_ustr; @@ -102,7 +103,7 @@ namespace connectivity { for (const auto& rConnection : m_aConnections) { - Reference<XInterface > xTemp = rConnection.first.get(); + Reference<XConnection> xTemp(rConnection.xOrigConn); ::comphelper::disposeComponent(xTemp); } } @@ -111,7 +112,6 @@ namespace connectivity // not interested in } m_aConnections.clear(); - TWeakPairVector().swap(m_aConnections); cppu::WeakComponentImplHelperBase::disposing(); } @@ -121,7 +121,7 @@ namespace connectivity if ( !m_xDriver.is() ) { Reference<XDriverManager2> xDriverAccess = DriverManager::create( m_xContext ); - m_xDriver = xDriverAccess->getDriverByURL("jdbc:hsqldb:db"); + m_xDriver = xDriverAccess->getDriverByURL(u"jdbc:hsqldb:db"_ustr); } return m_xDriver; @@ -203,46 +203,43 @@ namespace connectivity // properties for accessing the embedded storage OUString sKey = StorageContainer::registerStorage( xStorage, sSystemPath ); - aProperties.put( "storage_key", sKey ); - aProperties.put( "storage_class_name", - OUString( "com.sun.star.sdbcx.comp.hsqldb.StorageAccess" ) ); - aProperties.put( "fileaccess_class_name", - OUString( "com.sun.star.sdbcx.comp.hsqldb.StorageFileAccess" ) ); + aProperties.put( u"storage_key"_ustr, sKey ); + aProperties.put( u"storage_class_name"_ustr, + u"com.sun.star.sdbcx.comp.hsqldb.StorageAccess"_ustr ); + aProperties.put( u"fileaccess_class_name"_ustr, + u"com.sun.star.sdbcx.comp.hsqldb.StorageFileAccess"_ustr ); // JDBC driver and driver's classpath - aProperties.put( "JavaDriverClass", - OUString( "org.hsqldb.jdbcDriver" ) ); - aProperties.put( "JavaDriverClassPath", - OUString( + aProperties.put( u"JavaDriverClass"_ustr, u"org.hsqldb.jdbcDriver"_ustr ); + aProperties.put( u"JavaDriverClassPath"_ustr, #ifdef SYSTEM_HSQLDB - HSQLDB_JAR + u"" HSQLDB_JAR #else - "vnd.sun.star.expand:$LO_JAVA_DIR/hsqldb.jar" + u"vnd.sun.star.expand:$LO_JAVA_DIR/hsqldb.jar" #endif - " vnd.sun.star.expand:$LO_JAVA_DIR/sdbc_hsqldb.jar" - ) ); + " vnd.sun.star.expand:$LO_JAVA_DIR/sdbc_hsqldb.jar"_ustr ); // auto increment handling - aProperties.put( "IsAutoRetrievingEnabled", true ); - aProperties.put( "AutoRetrievingStatement", - OUString( "CALL IDENTITY()" ) ); - aProperties.put( "IgnoreDriverPrivileges", true ); + aProperties.put( u"IsAutoRetrievingEnabled"_ustr, true ); + aProperties.put( u"AutoRetrievingStatement"_ustr, + u"CALL IDENTITY()"_ustr ); + aProperties.put( u"IgnoreDriverPrivileges"_ustr, true ); // don't want to expose HSQLDB's schema capabilities which exist since 1.8.0RC10 - aProperties.put( "default_schema", - OUString( "true" ) ); + aProperties.put( u"default_schema"_ustr, + u"true"_ustr ); // security: permitted Java classes NamedValue aPermittedClasses( - "hsqldb.method_class_names", - makeAny( lcl_getPermittedJavaMethods_nothrow( m_xContext ) ) + u"hsqldb.method_class_names"_ustr, + Any( lcl_getPermittedJavaMethods_nothrow( m_xContext ) ) ); - aProperties.put( "SystemProperties", Sequence< NamedValue >( &aPermittedClasses, 1 ) ); + aProperties.put( u"SystemProperties"_ustr, Sequence< NamedValue >( &aPermittedClasses, 1 ) ); OUString sMessage; try { - const OUString sProperties( "properties" ); + static constexpr OUString sProperties( u"properties"_ustr ); if ( !bIsNewDatabase && xStorage->isStreamElement(sProperties) ) { Reference<XStream > xStream = xStorage->openStreamElement(sProperties,ElementModes::READ); @@ -251,15 +248,15 @@ namespace connectivity std::unique_ptr<SvStream> pStream( ::utl::UcbStreamHelper::CreateStream(xStream) ); if (pStream) { - OString sLine; + OStringBuffer sLine; OString sVersionString; while ( pStream->ReadLine(sLine) ) { if ( sLine.isEmpty() ) continue; sal_Int32 nIdx {0}; - const OString sIniKey = sLine.getToken(0, '=', nIdx); - const OString sValue = sLine.getToken(0, '=', nIdx); + const std::string_view sIniKey = o3tl::getToken(sLine, 0, '=', nIdx); + const OString sValue(o3tl::getToken(sLine, 0, '=', nIdx)); if( sIniKey == "hsqldb.compatible_version" ) { sVersionString = sValue; @@ -275,9 +272,9 @@ namespace connectivity if (!sVersionString.isEmpty()) { sal_Int32 nIdx {0}; - const sal_Int32 nMajor = sVersionString.getToken(0, '.', nIdx).toInt32(); - const sal_Int32 nMinor = sVersionString.getToken(0, '.', nIdx).toInt32(); - const sal_Int32 nMicro = sVersionString.getToken(0, '.', nIdx).toInt32(); + const sal_Int32 nMajor = o3tl::toInt32(o3tl::getToken(sVersionString, 0, '.', nIdx)); + const sal_Int32 nMinor = o3tl::toInt32(o3tl::getToken(sVersionString, 0, '.', nIdx)); + const sal_Int32 nMicro = o3tl::toInt32(o3tl::getToken(sVersionString, 0, '.', nIdx)); if ( nMajor > 1 || ( nMajor == 1 && nMinor > 8 ) || ( nMajor == 1 && nMinor == 8 && nMicro > 0 ) ) @@ -290,6 +287,37 @@ namespace connectivity } // if ( xStream.is() ) ::comphelper::disposeComponent(xStream); } + + // disallow any database/script files that contain a "SCRIPT[.*]" entry (this is belt and braces + // in that bundled hsqldb 1.8.0 is patched to also reject them) + // + // hsqldb 2.6.0 release notes have: added system role SCRIPT_OPS for export / import of database structure and data + // which seems to provide a builtin way to do this with contemporary hsqldb + static constexpr OUString sScript(u"script"_ustr); + if (!bIsNewDatabase && xStorage->isStreamElement(sScript)) + { + Reference<XStream > xStream = xStorage->openStreamElement(sScript, ElementModes::READ); + if (xStream.is()) + { + std::unique_ptr<SvStream> pStream(::utl::UcbStreamHelper::CreateStream(xStream)); + if (pStream) + { + OStringBuffer sLine; + while (pStream->ReadLine(sLine)) + { + OString sText = sLine.makeStringAndClear().trim(); + if (sText.startsWithIgnoreAsciiCase("SCRIPT")) + { + ::connectivity::SharedResources aResources; + sMessage = aResources.getResourceString(STR_COULD_NOT_LOAD_FILE).replaceFirst("$filename$", sSystemPath); + break; + } + } + } + } // if ( xStream.is() ) + ::comphelper::disposeComponent(xStream); + } + } catch(Exception&) { @@ -304,10 +332,10 @@ namespace connectivity if ( xProp.is() ) { sal_Int32 nMode = 0; - xProp->getPropertyValue("OpenMode") >>= nMode; + xProp->getPropertyValue(u"OpenMode"_ustr) >>= nMode; if ( (nMode & ElementModes::WRITE) != ElementModes::WRITE ) { - aProperties.put( "readonly", OUString( "true" ) ); + aProperties.put( u"readonly"_ustr, u"true"_ustr ); } } @@ -333,7 +361,7 @@ namespace connectivity if ( xOrig.is() ) { // now we have to set the URL to get the correct answer for metadata()->getURL() - auto pMetaConnection = comphelper::getUnoTunnelImplementation<OMetaConnection>(xOrig); + auto pMetaConnection = comphelper::getFromUnoTunnel<OMetaConnection>(xOrig); if ( pMetaConnection ) pMetaConnection->setURL(url); @@ -342,23 +370,22 @@ namespace connectivity xComp->addEventListener(this); // we want to close all connections when the office shuts down - static Reference< XTerminateListener> s_xTerminateListener = [&]() + static rtl::Reference< OConnectionController > s_xTerminateListener = [&]() { Reference< XDesktop2 > xDesktop = Desktop::create( m_xContext ); - auto tmp = new OConnectionController(this); + rtl::Reference<OConnectionController> tmp = new OConnectionController(this); xDesktop->addTerminateListener(tmp); return tmp; }(); Reference< XComponent> xIfc = new OHsqlConnection( this, xOrig, m_xContext ); xConnection.set(xIfc,UNO_QUERY); - m_aConnections.push_back(TWeakPair(WeakReferenceHelper(xOrig),TWeakConnectionPair(sKey,TWeakRefPair(WeakReferenceHelper(xConnection),WeakReferenceHelper())))); + m_aConnections.push_back( { xOrig, sKey, xConnection, nullptr } ); Reference<XTransactionBroadcaster> xBroad(xStorage,UNO_QUERY); if ( xBroad.is() ) { - Reference<XTransactionListener> xListener(*this,UNO_QUERY); - xBroad->addTransactionListener(xListener); + xBroad->addTransactionListener(Reference<XTransactionListener>(this)); } } } @@ -393,29 +420,30 @@ namespace connectivity { if ( !acceptsURL(url) ) return Sequence< DriverPropertyInfo >(); - std::vector< DriverPropertyInfo > aDriverInfo; - aDriverInfo.push_back(DriverPropertyInfo( - "Storage" - ,"Defines the storage where the database will be stored." - ,true - ,OUString() - ,Sequence< OUString >()) - ); - aDriverInfo.push_back(DriverPropertyInfo( - "URL" - ,"Defines the url of the data source." - ,true - ,OUString() - ,Sequence< OUString >()) - ); - aDriverInfo.push_back(DriverPropertyInfo( - "AutoRetrievingStatement" - ,"Defines the statement which will be executed to retrieve auto increment values." - ,false - ,"CALL IDENTITY()" - ,Sequence< OUString >()) - ); - return Sequence< DriverPropertyInfo >(aDriverInfo.data(),aDriverInfo.size()); + return + { + { + u"Storage"_ustr, + u"Defines the storage where the database will be stored."_ustr, + true, + {}, + {} + }, + { + u"URL"_ustr, + u"Defines the url of the data source."_ustr, + true, + {}, + {} + }, + { + u"AutoRetrievingStatement"_ustr, + u"Defines the statement which will be executed to retrieve auto increment values."_ustr, + false, + u"CALL IDENTITY()"_ustr, + {} + } + }; } @@ -436,18 +464,18 @@ namespace connectivity ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(ODriverDelegator_BASE::rBHelper.bDisposed); - Reference< XTablesSupplier > xTab; + rtl::Reference< OHCatalog > xTab; - TWeakPairVector::iterator i = std::find_if(m_aConnections.begin(), m_aConnections.end(), - [&connection](const TWeakPairVector::value_type& rConnection) { - return rConnection.second.second.first.get() == connection.get(); }); + auto i = std::find_if(m_aConnections.begin(), m_aConnections.end(), + [&connection](const TConnectionInfo& rConnection) { + return rConnection.xConn.get() == connection.get(); }); if (i != m_aConnections.end()) { - xTab.set(i->second.second.second,UNO_QUERY); + xTab = i->xCatalog.get(); if ( !xTab.is() ) { xTab = new OHCatalog(connection); - i->second.second.second = WeakReferenceHelper(xTab); + i->xCatalog = xTab.get(); } } @@ -481,33 +509,40 @@ namespace connectivity Sequence< OUString > SAL_CALL ODriverDelegator::getSupportedServiceNames( ) { - return { "com.sun.star.sdbc.Driver", "com.sun.star.sdbcx.Driver" }; + return { u"com.sun.star.sdbc.Driver"_ustr, u"com.sun.star.sdbcx.Driver"_ustr }; } void SAL_CALL ODriverDelegator::createCatalog( const Sequence< PropertyValue >& /*info*/ ) { - ::dbtools::throwFeatureNotImplementedSQLException( "XCreateCatalog::createCatalog", *this ); + ::dbtools::throwFeatureNotImplementedSQLException( u"XCreateCatalog::createCatalog"_ustr, *this ); } - void ODriverDelegator::shutdownConnection(const TWeakPairVector::iterator& _aIter ) + void ODriverDelegator::shutdownConnection(const std::vector<TConnectionInfo>::iterator& _aIter ) { OSL_ENSURE(m_aConnections.end() != _aIter,"Iterator equals .end()"); bool bLastOne = true; try { - Reference<XConnection> _xConnection(_aIter->first.get(),UNO_QUERY); + Reference<XConnection> _xConnection(_aIter->xOrigConn); if ( _xConnection.is() ) { Reference<XStatement> xStmt = _xConnection->createStatement(); if ( xStmt.is() ) { - Reference<XResultSet> xRes = xStmt->executeQuery("SELECT COUNT(*) FROM INFORMATION_SCHEMA.SYSTEM_SESSIONS WHERE USER_NAME ='SA'"); + Reference<XResultSet> xRes = xStmt->executeQuery(u"SELECT COUNT(*) FROM INFORMATION_SCHEMA.SYSTEM_SESSIONS WHERE USER_NAME ='SA'"_ustr); Reference<XRow> xRow(xRes,UNO_QUERY); if ( xRow.is() && xRes->next() ) bLastOne = xRow->getInt(1) == 1; if ( bLastOne ) - xStmt->execute("SHUTDOWN"); + { + // during shutdown, we are running on the main thread, and if we call this, + // it might trigger dbaccess::DocumentEventNotifier_Impl::impl_notifyEvent_nothrow + // which is running on a different thread, and that will call other code that tries + // to take the solar mutex. + SolarMutexReleaser aReleaser; + xStmt->execute(u"SHUTDOWN"_ustr); + } } } } @@ -518,7 +553,7 @@ namespace connectivity { // Reference<XTransactionListener> xListener(*this,UNO_QUERY); // a shutdown should commit all changes to the db files - StorageContainer::revokeStorage(_aIter->second.first,nullptr); + StorageContainer::revokeStorage(_aIter->sKey,nullptr); } if ( !m_bInShutDownConnections ) m_aConnections.erase(_aIter); @@ -530,8 +565,8 @@ namespace connectivity Reference<XConnection> xCon(Source.Source,UNO_QUERY); if ( xCon.is() ) { - TWeakPairVector::iterator i = std::find_if(m_aConnections.begin(), m_aConnections.end(), - [&xCon](const TWeakPairVector::value_type& rConnection) { return rConnection.first.get() == xCon.get(); }); + auto i = std::find_if(m_aConnections.begin(), m_aConnections.end(), + [&xCon](const TConnectionInfo& rConnection) { return rConnection.xOrigConn.get() == xCon.get(); }); if (i != m_aConnections.end()) shutdownConnection(i); @@ -542,9 +577,9 @@ namespace connectivity if ( xStorage.is() ) { OUString sKey = StorageContainer::getRegisteredKey(xStorage); - TWeakPairVector::iterator i = std::find_if(m_aConnections.begin(),m_aConnections.end(), - [&sKey] (const TWeakPairVector::value_type& conn) { - return conn.second.first == sKey; + auto i = std::find_if(m_aConnections.begin(),m_aConnections.end(), + [&sKey] (const TConnectionInfo& conn) { + return conn.sKey == sKey; }); if ( i != m_aConnections.end() ) @@ -560,7 +595,7 @@ namespace connectivity { try { - Reference<XConnection> xCon(rConnection.first,UNO_QUERY); + Reference<XConnection> xCon(rConnection.xOrigConn); ::comphelper::disposeComponent(xCon); } catch(Exception&) @@ -577,7 +612,7 @@ namespace connectivity { try { - Reference<XFlushable> xCon(rConnection.second.second.first.get(),UNO_QUERY); + Reference<XFlushable> xCon(rConnection.xConn.get(),UNO_QUERY); if (xCon.is()) xCon->flush(); } @@ -597,9 +632,9 @@ namespace connectivity if ( sKey.isEmpty() ) return; - TWeakPairVector::const_iterator i = std::find_if(m_aConnections.begin(), m_aConnections.end(), - [&sKey] (const TWeakPairVector::value_type& conn) { - return conn.second.first == sKey; + auto i = std::find_if(m_aConnections.begin(), m_aConnections.end(), + [&sKey] (const TConnectionInfo& conn) { + return conn.sKey == sKey; }); OSL_ENSURE( i != m_aConnections.end(), "ODriverDelegator::preCommit: they're committing a storage which I do not know!" ); @@ -608,13 +643,13 @@ namespace connectivity try { - Reference<XConnection> xConnection(i->first,UNO_QUERY); + Reference<XConnection> xConnection(i->xOrigConn); if ( xConnection.is() ) { Reference< XStatement> xStmt = xConnection->createStatement(); OSL_ENSURE( xStmt.is(), "ODriverDelegator::preCommit: no statement!" ); if ( xStmt.is() ) - xStmt->execute( "SET WRITE_DELAY 0" ); + xStmt->execute( u"SET WRITE_DELAY 0"_ustr ); bool bPreviousAutoCommit = xConnection->getAutoCommit(); xConnection->setAutoCommit( false ); @@ -622,7 +657,7 @@ namespace connectivity xConnection->setAutoCommit( bPreviousAutoCommit ); if ( xStmt.is() ) - xStmt->execute( "SET WRITE_DELAY 60" ); + xStmt->execute( u"SET WRITE_DELAY 60"_ustr ); } } catch(Exception&) @@ -783,7 +818,7 @@ namespace connectivity OUString lcl_getSystemLocale( const Reference< XComponentContext >& _rxContext ) { - OUString sLocaleString = "en-US"; + OUString sLocaleString = u"en-US"_ustr; try { @@ -794,13 +829,13 @@ namespace connectivity // arguments for creating the config access Sequence<Any> aArguments(comphelper::InitAnyPropertySequence( { - {"nodepath", Any(OUString("/org.openoffice.Setup/L10N" ))}, // the path to the node to open + {"nodepath", Any(u"/org.openoffice.Setup/L10N"_ustr)}, // the path to the node to open {"depth", Any(sal_Int32(-1))}, // the depth: -1 means unlimited })); // create the access Reference< XPropertySet > xNode( xConfigProvider->createInstanceWithArguments( - "com.sun.star.configuration.ConfigurationAccess", + u"com.sun.star.configuration.ConfigurationAccess"_ustr, aArguments ), UNO_QUERY ); OSL_ENSURE( xNode.is(), "lcl_getSystemLocale: invalid access returned (should throw an exception instead)!" ); @@ -808,7 +843,7 @@ namespace connectivity // ask for the system locale setting if ( xNode.is() ) - xNode->getPropertyValue("ooSetupSystemLocale") >>= sLocaleString; + xNode->getPropertyValue(u"ooSetupSystemLocale"_ustr) >>= sLocaleString; } catch( const Exception& ) { @@ -832,8 +867,7 @@ namespace connectivity OSL_ENSURE( xStatement.is(), "ODriverDelegator::onConnectedNewDatabase: could not create a statement!" ); if ( xStatement.is() ) { - OUStringBuffer aStatement; - aStatement.append( "SET DATABASE COLLATION \"" ); + OUStringBuffer aStatement( "SET DATABASE COLLATION \"" ); aStatement.appendAscii( lcl_getCollationForLocale( lcl_getSystemLocale( m_xContext ) ) ); aStatement.append( "\"" ); diff --git a/connectivity/source/drivers/hsqldb/HStorageAccess.cxx b/connectivity/source/drivers/hsqldb/HStorageAccess.cxx index 91b8324008e3..3e874dbbeddc 100644 --- a/connectivity/source/drivers/hsqldb/HStorageAccess.cxx +++ b/connectivity/source/drivers/hsqldb/HStorageAccess.cxx @@ -22,15 +22,14 @@ #include <hsqldb/HStorageMap.hxx> #include "accesslog.hxx" #include <osl/diagnose.h> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <string.h> -using namespace ::com::sun::star::container; +#include <algorithm> + using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::embed; using namespace ::com::sun::star::io; -using namespace ::com::sun::star::lang; using namespace ::connectivity::hsqldb; #define ThrowException(env, type, msg) { \ @@ -146,28 +145,28 @@ jint read_from_storage_stream( JNIEnv * env, jstring name, jstring key ) std::shared_ptr<StreamHelper> pHelper = StorageContainer::getRegisteredStream(env,name,key); Reference< XInputStream> xIn = pHelper ? pHelper->getInputStream() : Reference< XInputStream>(); OSL_ENSURE(xIn.is(),"Input stream is NULL!"); - if ( xIn.is() ) + if ( !xIn.is() ) + return -1; + + Sequence< ::sal_Int8 > aData(1); + sal_Int32 nBytesRead = -1; + try { - Sequence< ::sal_Int8 > aData(1); - sal_Int32 nBytesRead = -1; - try - { - nBytesRead = xIn->readBytes(aData,1); - } - catch(const Exception& e) - { - StorageContainer::throwJavaException(e,env); - return -1; + nBytesRead = xIn->readBytes(aData,1); + } + catch(const Exception& e) + { + StorageContainer::throwJavaException(e,env); + return -1; - } - if (nBytesRead <= 0) - { - return -1; - } - else - { - return static_cast<unsigned char>(aData[0]); - } + } + if (nBytesRead <= 0) + { + return -1; + } + else + { + return static_cast<unsigned char>(aData[0]); } return -1; } @@ -229,7 +228,7 @@ jint read_from_storage_stream_into_buffer( JNIEnv * env, jstring name, jstring k if (nBytesRead <= 0) return -1; - env->SetByteArrayRegion(buffer,off,nBytesRead,reinterpret_cast<jbyte*>(&aData[0])); + env->SetByteArrayRegion(buffer,off,nBytesRead,reinterpret_cast<const jbyte*>(&aData[0])); return nBytesRead; } @@ -299,10 +298,8 @@ extern "C" SAL_JNI_EXPORT jint JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_Nativ } Sequence< sal_Int32 > ch(4); - for(sal_Int32 i = 0;i < 4; ++i) - { - ch[i] = static_cast<unsigned char>(aData[i]); - } + std::transform(aData.begin(), aData.end(), ch.getArray(), + [](auto c) { return static_cast<unsigned char>(c); }); if ((ch[0] | ch[1] | ch[2] | ch[3]) < 0) { @@ -341,10 +338,15 @@ extern "C" SAL_JNI_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_Nativ #endif std::shared_ptr<StreamHelper> pHelper = StorageContainer::getRegisteredStream(env,name,key); - Reference< XSeekable> xSeek = pHelper ? pHelper->getSeek() : Reference< XSeekable>(); - OSL_ENSURE(xSeek.is(),"No Seekable stream!"); - if ( !xSeek.is() ) + OSL_ENSURE(pHelper, "No StreamHelper!"); + if (!pHelper) + return; + + Reference< XSeekable> xSeek = pHelper->getSeek(); + + OSL_ENSURE(xSeek.is(), "No Seekable stream!"); + if (!xSeek) return; #ifdef HSQLDB_DBG @@ -362,22 +364,22 @@ extern "C" SAL_JNI_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_Nativ Reference< XOutputStream> xOut = pHelper->getOutputStream(); OSL_ENSURE(xOut.is(),"No output stream!"); - ::sal_Int64 diff = position - nLen; - sal_Int32 n; - while( diff != 0 ) + sal_Int64 diff = position - nLen, n; + while (diff != 0) { - if ( BUFFER_SIZE < diff ) + if (diff > BUFFER_SIZE) { - n = static_cast<sal_Int32>(BUFFER_SIZE); + n = BUFFER_SIZE; diff = diff - BUFFER_SIZE; } else { - n = static_cast<sal_Int32>(diff); + n = diff; diff = 0; } - Sequence< ::sal_Int8 > aData(n); - memset(aData.getArray(),0,n); + assert(n >= 0 && n <= SAL_MAX_INT32 && "this fits in sal_Int32"); + Sequence<sal_Int8> aData(n); + memset(aData.getArray(), 0, n); xOut->writeBytes(aData); #ifdef HSQLDB_DBG aDataLog.write( aData.getConstArray(), n ); @@ -463,11 +465,13 @@ void write_to_storage_stream( JNIEnv* env, jstring name, jstring key, jint v ) { if ( xOut.is() ) { - Sequence< ::sal_Int8 > oneByte(4); - oneByte[0] = static_cast<sal_Int8>((v >> 24) & 0xFF); - oneByte[1] = static_cast<sal_Int8>((v >> 16) & 0xFF); - oneByte[2] = static_cast<sal_Int8>((v >> 8) & 0xFF); - oneByte[3] = static_cast<sal_Int8>((v >> 0) & 0xFF); + Sequence< ::sal_Int8 > oneByte + { + static_cast<sal_Int8>((v >> 24) & 0xFF), + static_cast<sal_Int8>((v >> 16) & 0xFF), + static_cast<sal_Int8>((v >> 8) & 0xFF), + static_cast<sal_Int8>((v >> 0) & 0xFF) + }; xOut->writeBytes(oneByte); } diff --git a/connectivity/source/drivers/hsqldb/HStorageMap.cxx b/connectivity/source/drivers/hsqldb/HStorageMap.cxx index 63b5e0481c5c..822a655675d2 100644 --- a/connectivity/source/drivers/hsqldb/HStorageMap.cxx +++ b/connectivity/source/drivers/hsqldb/HStorageMap.cxx @@ -27,7 +27,7 @@ #include <sal/log.hxx> #include <uno/mapping.hxx> #include <algorithm> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> namespace connectivity::hsqldb { @@ -103,14 +103,14 @@ namespace connectivity::hsqldb { css::uno::Environment env(css::uno::Environment::getCurrent()); if (!(env.is() && storageEnvironment.is())) { - throw css::uno::RuntimeException("cannot get environments"); + throw css::uno::RuntimeException(u"cannot get environments"_ustr); } if (env.get() == storageEnvironment.get()) { return storage; } else { css::uno::Mapping map(storageEnvironment, env); if (!map.is()) { - throw css::uno::RuntimeException("cannot get mapping"); + throw css::uno::RuntimeException(u"cannot get mapping"_ustr); } css::uno::Reference<css::embed::XStorage> mapped; map.mapInterface( @@ -132,9 +132,9 @@ namespace connectivity::hsqldb return OUString::number(s_nCount++); } - OUString StorageContainer::removeURLPrefix(const OUString& _sURL,const OUString& _sFileURL) + OUString StorageContainer::removeURLPrefix(std::u16string_view _sURL, std::u16string_view _sFileURL) { - return _sURL.copy(_sFileURL.getLength()+1); + return OUString(_sURL.substr(_sFileURL.size()+1)); } OUString StorageContainer::removeOldURLPrefix(const OUString& _sURL) diff --git a/connectivity/source/drivers/hsqldb/HTable.cxx b/connectivity/source/drivers/hsqldb/HTable.cxx index 0049ff919fc3..05338f21aef2 100644 --- a/connectivity/source/drivers/hsqldb/HTable.cxx +++ b/connectivity/source/drivers/hsqldb/HTable.cxx @@ -18,7 +18,6 @@ */ #include <hsqldb/HTable.hxx> -#include <cppuhelper/typeprovider.hxx> #include <com/sun/star/beans/PropertyAttribute.hpp> #include <com/sun/star/sdbcx/Privilege.hpp> #include <comphelper/property.hxx> @@ -30,7 +29,7 @@ #include <hsqldb/HColumns.hxx> #include <TConnection.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> using namespace ::comphelper; @@ -116,21 +115,6 @@ sdbcx::OCollection* OHSQLTable::createIndexes(const ::std::vector< OUString>& _r return new OIndexesHelper(this,m_aMutex,_rNames); } -Sequence< sal_Int8 > OHSQLTable::getUnoTunnelId() -{ - static ::cppu::OImplementationId implId; - - return implId.getImplementationId(); -} - -// css::lang::XUnoTunnel - -sal_Int64 OHSQLTable::getSomething( const Sequence< sal_Int8 > & rId ) -{ - return (isUnoTunnelId<OHSQLTable>(rId)) - ? reinterpret_cast< sal_Int64 >( this ) - : OTable_TYPEDEF::getSomething(rId); -} // XAlterTable void SAL_CALL OHSQLTable::alterColumnByName( const OUString& colName, const Reference< XPropertySet >& descriptor ) @@ -260,12 +244,11 @@ void OHSQLTable::alterColumnType(sal_Int32 nNewType,const OUString& _rColName, c (void)_rColName; #endif - OHSQLColumn* pColumn = new OHSQLColumn; - Reference<XPropertySet> xProp = pColumn; - ::comphelper::copyProperties(_xDescriptor,xProp); - xProp->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE),makeAny(nNewType)); + rtl::Reference<OHSQLColumn> pColumn = new OHSQLColumn; + ::comphelper::copyProperties(_xDescriptor,pColumn); + pColumn->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE),Any(nNewType)); - sSql += ::dbtools::createStandardColumnPart(xProp,getConnection()); + sSql += ::dbtools::createStandardColumnPart(pColumn,getConnection()); executeStatement(sSql); } @@ -293,7 +276,7 @@ void OHSQLTable::dropDefaultValue(const OUString& _rColName) OUString OHSQLTable::getAlterTableColumnPart() const { - OUString sSql( "ALTER TABLE " ); + OUString sSql( u"ALTER TABLE "_ustr ); OUString sComposedName( ::dbtools::composeTableName( getMetaData(), m_CatalogName, m_SchemaName, m_Name, true, ::dbtools::EComposeRule::InTableDefinitions ) ); sSql += sComposedName; @@ -305,7 +288,7 @@ void OHSQLTable::executeStatement(const OUString& _rStatement ) { OUString sSQL = _rStatement; if(sSQL.endsWith(",")) - sSQL = sSQL.replaceAt(sSQL.getLength()-1, 1, ")"); + sSQL = sSQL.replaceAt(sSQL.getLength()-1, 1, u")"); Reference< XStatement > xStmt = getConnection()->createStatement( ); if ( xStmt.is() ) @@ -355,7 +338,7 @@ void SAL_CALL OHSQLTable::rename( const OUString& newName ) if(!isNew()) { - OUString sSql = "ALTER "; + OUString sSql = u"ALTER "_ustr; if ( m_Type == "VIEW" ) sSql += " VIEW "; else diff --git a/connectivity/source/drivers/hsqldb/HTables.cxx b/connectivity/source/drivers/hsqldb/HTables.cxx index 787af894b992..dcb1ee1a33d9 100644 --- a/connectivity/source/drivers/hsqldb/HTables.cxx +++ b/connectivity/source/drivers/hsqldb/HTables.cxx @@ -37,47 +37,42 @@ using namespace ::com::sun::star::beans; using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::container; -using namespace ::com::sun::star::lang; using namespace dbtools; -sdbcx::ObjectType OTables::createObject(const OUString& _rName) +css::uno::Reference< css::beans::XPropertySet > OTables::createObject(const OUString& _rName) { OUString sCatalog,sSchema,sTable; ::dbtools::qualifiedNameComponents(m_xMetaData,_rName,sCatalog,sSchema,sTable,::dbtools::EComposeRule::InDataManipulation); - Sequence< OUString > sTableTypes(3); - sTableTypes[0] = "VIEW"; - sTableTypes[1] = "TABLE"; - sTableTypes[2] = "%"; // just to be sure to include anything else... + Sequence< OUString > sTableTypes {u"VIEW"_ustr, u"TABLE"_ustr, u"%"_ustr}; // this last one just to be sure to include anything else... Any aCatalog; if ( !sCatalog.isEmpty() ) aCatalog <<= sCatalog; Reference< XResultSet > xResult = m_xMetaData->getTables(aCatalog,sSchema,sTable,sTableTypes); - sdbcx::ObjectType xRet; - if ( xResult.is() ) + if ( !xResult.is() ) + return nullptr; + + rtl::Reference< OHSQLTable > xRet; + Reference< XRow > xRow(xResult,UNO_QUERY); + if ( xResult->next() ) // there can be only one table with this name { - Reference< XRow > xRow(xResult,UNO_QUERY); - if ( xResult->next() ) // there can be only one table with this name - { - sal_Int32 nPrivileges = ::dbtools::getTablePrivileges( m_xMetaData, sCatalog, sSchema, sTable ); - if ( m_xMetaData->isReadOnly() ) - nPrivileges &= ~( Privilege::INSERT | Privilege::UPDATE | Privilege::DELETE | Privilege::CREATE | Privilege::ALTER | Privilege::DROP ); - - // obtain privileges - OHSQLTable* pRet = new OHSQLTable( this - ,static_cast<OHCatalog&>(m_rParent).getConnection() - ,sTable - ,xRow->getString(4) - ,xRow->getString(5) - ,sSchema - ,sCatalog - ,nPrivileges); - xRet = pRet; - } - ::comphelper::disposeComponent(xResult); + sal_Int32 nPrivileges = ::dbtools::getTablePrivileges( m_xMetaData, sCatalog, sSchema, sTable ); + if ( m_xMetaData->isReadOnly() ) + nPrivileges &= ~( Privilege::INSERT | Privilege::UPDATE | Privilege::DELETE | Privilege::CREATE | Privilege::ALTER | Privilege::DROP ); + + // obtain privileges + xRet = new OHSQLTable( this + ,static_cast<OHCatalog&>(m_rParent).getConnection() + ,sTable + ,xRow->getString(4) + ,xRow->getString(5) + ,sSchema + ,sCatalog + ,nPrivileges); } + ::comphelper::disposeComponent(xResult); return xRet; } @@ -99,7 +94,7 @@ Reference< XPropertySet > OTables::createDescriptor() } // XAppend -sdbcx::ObjectType OTables::appendObject( const OUString& _rForName, const Reference< XPropertySet >& descriptor ) +css::uno::Reference< css::beans::XPropertySet > OTables::appendObject( const OUString& _rForName, const Reference< XPropertySet >& descriptor ) { createTable(descriptor); return createObject( _rForName ); @@ -119,7 +114,7 @@ void OTables::dropObject(sal_Int32 _nPos,const OUString& _sElementName) OUString sCatalog,sSchema,sTable; ::dbtools::qualifiedNameComponents(m_xMetaData,_sElementName,sCatalog,sSchema,sTable,::dbtools::EComposeRule::InDataManipulation); - OUString aSql( "DROP " ); + OUString aSql( u"DROP "_ustr ); Reference<XPropertySet> xProp(xObject,UNO_QUERY); bool bIsView; @@ -164,13 +159,13 @@ void OTables::appendNew(const OUString& _rsNewTable) insertElement(_rsNewTable,nullptr); // notify our container listeners - ContainerEvent aEvent(static_cast<XContainer*>(this), makeAny(_rsNewTable), Any(), Any()); - OInterfaceIteratorHelper2 aListenerLoop(m_aContainerListeners); + ContainerEvent aEvent(static_cast<XContainer*>(this), Any(_rsNewTable), Any(), Any()); + OInterfaceIteratorHelper3 aListenerLoop(m_aContainerListeners); while (aListenerLoop.hasMoreElements()) - static_cast<XContainerListener*>(aListenerLoop.next())->elementInserted(aEvent); + aListenerLoop.next()->elementInserted(aEvent); } -OUString OTables::getNameForObject(const sdbcx::ObjectType& _xObject) +OUString OTables::getNameForObject(const css::uno::Reference< css::beans::XPropertySet >& _xObject) { OSL_ENSURE(_xObject.is(),"OTables::getNameForObject: Object is NULL!"); return ::dbtools::composeTableName( m_xMetaData, _xObject, ::dbtools::EComposeRule::InDataManipulation, false ); diff --git a/connectivity/source/drivers/hsqldb/HTerminateListener.cxx b/connectivity/source/drivers/hsqldb/HTerminateListener.cxx index a9df5ccc9b9a..7c6b494488db 100644 --- a/connectivity/source/drivers/hsqldb/HTerminateListener.cxx +++ b/connectivity/source/drivers/hsqldb/HTerminateListener.cxx @@ -23,7 +23,6 @@ namespace connectivity { using namespace hsqldb; -using namespace ::com::sun::star::uno; using namespace ::com::sun::star::lang; // XEventListener diff --git a/connectivity/source/drivers/hsqldb/HTerminateListener.hxx b/connectivity/source/drivers/hsqldb/HTerminateListener.hxx index 63d69b29e64b..265be80ef5b9 100644 --- a/connectivity/source/drivers/hsqldb/HTerminateListener.hxx +++ b/connectivity/source/drivers/hsqldb/HTerminateListener.hxx @@ -16,34 +16,31 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_HSQLDB_HTERMINATELISTENER_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_HSQLDB_HTERMINATELISTENER_HXX +#pragma once #include <cppuhelper/implbase.hxx> #include <com/sun/star/frame/XTerminateListener.hpp> namespace connectivity::hsqldb +{ + class ODriverDelegator; + class OConnectionController : public ::cppu::WeakImplHelper< css::frame::XTerminateListener > { - class ODriverDelegator; - class OConnectionController : public ::cppu::WeakImplHelper< css::frame::XTerminateListener > - { - ODriverDelegator* m_pDriver; - protected: - virtual ~OConnectionController() override {m_pDriver = nullptr;} - public: - explicit OConnectionController(ODriverDelegator* _pDriver) : m_pDriver(_pDriver){} + ODriverDelegator* m_pDriver; + protected: + virtual ~OConnectionController() override {m_pDriver = nullptr;} + public: + explicit OConnectionController(ODriverDelegator* _pDriver) : m_pDriver(_pDriver){} - // XEventListener - virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override; + // XEventListener + virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override; - // XTerminateListener - virtual void SAL_CALL queryTermination( const css::lang::EventObject& aEvent ) override; - virtual void SAL_CALL notifyTermination( const css::lang::EventObject& aEvent ) override; - }; + // XTerminateListener + virtual void SAL_CALL queryTermination( const css::lang::EventObject& aEvent ) override; + virtual void SAL_CALL notifyTermination( const css::lang::EventObject& aEvent ) override; + }; } // namespace connectivity::hsqldb -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_HSQLDB_HTERMINATELISTENER_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/hsqldb/HTools.cxx b/connectivity/source/drivers/hsqldb/HTools.cxx index b9854c01ce67..3dd388aceecb 100644 --- a/connectivity/source/drivers/hsqldb/HTools.cxx +++ b/connectivity/source/drivers/hsqldb/HTools.cxx @@ -23,18 +23,18 @@ namespace connectivity::hsqldb { - void HTools::appendTableFilterCrit( OUStringBuffer& _inout_rBuffer, const OUString& _rCatalog, - const OUString& _rSchema, const OUString& _rName, bool _bShortForm ) + void HTools::appendTableFilterCrit( OUStringBuffer& _inout_rBuffer, std::u16string_view _rCatalog, + std::u16string_view _rSchema, std::u16string_view _rName, bool _bShortForm ) { _inout_rBuffer.append( " WHERE " ); - if ( !_rCatalog.isEmpty() ) + if ( !_rCatalog.empty() ) { _inout_rBuffer.appendAscii( _bShortForm ? "TABLE_CAT" : "TABLE_CATALOG" ); _inout_rBuffer.append( " = '" ); _inout_rBuffer.append ( _rCatalog ); _inout_rBuffer.append( "' AND " ); } - if ( !_rSchema.isEmpty() ) + if ( !_rSchema.empty() ) { _inout_rBuffer.appendAscii( _bShortForm ? "TABLE_SCHEM" : "TABLE_SCHEMA" ); _inout_rBuffer.append( " = '" ); diff --git a/connectivity/source/drivers/hsqldb/HUser.cxx b/connectivity/source/drivers/hsqldb/HUser.cxx index 2ed0c06262ff..95cb68ea517f 100644 --- a/connectivity/source/drivers/hsqldb/HUser.cxx +++ b/connectivity/source/drivers/hsqldb/HUser.cxx @@ -27,6 +27,7 @@ #include <com/sun/star/sdbcx/PrivilegeObject.hpp> #include <TConnection.hxx> #include <strings.hrc> +#include <utility> using namespace connectivity; using namespace connectivity::hsqldb; @@ -37,16 +38,16 @@ using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::container; using namespace ::com::sun::star::lang; -OHSQLUser::OHSQLUser( const css::uno::Reference< css::sdbc::XConnection >& _xConnection) : connectivity::sdbcx::OUser(true) - ,m_xConnection(_xConnection) +OHSQLUser::OHSQLUser( css::uno::Reference< css::sdbc::XConnection > _xConnection) : connectivity::sdbcx::OUser(true) + ,m_xConnection(std::move(_xConnection)) { construct(); } -OHSQLUser::OHSQLUser( const css::uno::Reference< css::sdbc::XConnection >& _xConnection, +OHSQLUser::OHSQLUser( css::uno::Reference< css::sdbc::XConnection > _xConnection, const OUString& Name ) : connectivity::sdbcx::OUser(Name,true) - ,m_xConnection(_xConnection) + ,m_xConnection(std::move(_xConnection)) { construct(); } @@ -113,7 +114,7 @@ void OHSQLUser::findPrivilegesAndGrantPrivileges(const OUString& objName, sal_In Any aCatalog; if ( !sCatalog.isEmpty() ) aCatalog <<= sCatalog; - xRes = xMeta->getColumnPrivileges(aCatalog,sSchema,sTable,"%"); + xRes = xMeta->getColumnPrivileges(aCatalog,sSchema,sTable,u"%"_ustr); } break; } @@ -266,7 +267,7 @@ void SAL_CALL OHSQLUser::changePassword( const OUString& /*oldPassword*/, const if( m_Name != xMeta->getUserName() ) { - ::dbtools::throwGenericSQLException("HSQLDB can only change password of the current user.", *this); + ::dbtools::throwGenericSQLException(u"HSQLDB can only change password of the current user."_ustr, *this); } OUString sAlterPwd = "SET PASSWORD " + diff --git a/connectivity/source/drivers/hsqldb/HUsers.cxx b/connectivity/source/drivers/hsqldb/HUsers.cxx index 40d1f5243cb6..2141a0045d58 100644 --- a/connectivity/source/drivers/hsqldb/HUsers.cxx +++ b/connectivity/source/drivers/hsqldb/HUsers.cxx @@ -23,6 +23,7 @@ #include <comphelper/types.hxx> #include <connectivity/dbtools.hxx> #include <TConnection.hxx> +#include <utility> using namespace ::comphelper; using namespace connectivity; @@ -30,22 +31,20 @@ using namespace connectivity::hsqldb; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::sdbc; -using namespace ::com::sun::star::container; -using namespace ::com::sun::star::lang; OUsers::OUsers( ::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex, const ::std::vector< OUString> &_rVector, - const css::uno::Reference< css::sdbc::XConnection >& _xConnection, + css::uno::Reference< css::sdbc::XConnection > _xConnection, connectivity::sdbcx::IRefreshableUsers* _pParent) : sdbcx::OCollection(_rParent, true, _rMutex, _rVector) - ,m_xConnection(_xConnection) + ,m_xConnection(std::move(_xConnection)) ,m_pParent(_pParent) { } -sdbcx::ObjectType OUsers::createObject(const OUString& _rName) +css::uno::Reference< css::beans::XPropertySet > OUsers::createObject(const OUString& _rName) { return new OHSQLUser(m_xConnection,_rName); } @@ -57,12 +56,11 @@ void OUsers::impl_refresh() Reference< XPropertySet > OUsers::createDescriptor() { - OUserExtend* pNew = new OUserExtend(m_xConnection); - return pNew; + return new OUserExtend(m_xConnection); } // XAppend -sdbcx::ObjectType OUsers::appendObject( const OUString& _rForName, const Reference< XPropertySet >& descriptor ) +css::uno::Reference< css::beans::XPropertySet > OUsers::appendObject( const OUString& _rForName, const Reference< XPropertySet >& descriptor ) { OUString aQuote = m_xConnection->getMetaData()->getIdentifierQuoteString( ); OUString sPassword; @@ -85,7 +83,7 @@ sdbcx::ObjectType OUsers::appendObject( const OUString& _rForName, const Referen // XDrop void OUsers::dropObject(sal_Int32 /*nPos*/,const OUString& _sElementName) { - OUString aSql( "REVOKE ALL ON * FROM " ); + OUString aSql( u"REVOKE ALL ON * FROM "_ustr ); OUString aQuote = m_xConnection->getMetaData()->getIdentifierQuoteString( ); aSql += ::dbtools::quoteName(aQuote,_sElementName); diff --git a/connectivity/source/drivers/hsqldb/HView.cxx b/connectivity/source/drivers/hsqldb/HView.cxx index 0a09ec0d201b..83946ee86f86 100644 --- a/connectivity/source/drivers/hsqldb/HView.cxx +++ b/connectivity/source/drivers/hsqldb/HView.cxx @@ -31,7 +31,7 @@ #include <com/sun/star/sdbc/SQLException.hpp> #include <cppuhelper/exc_hlp.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <unotools/sharedunocomponent.hxx> @@ -90,12 +90,11 @@ namespace connectivity::hsqldb // create a statement which can be used to re-create the original view, in case // dropping it succeeds, but creating it with a new statement fails - OUStringBuffer aRestoreCommand; - aRestoreCommand.append( "CREATE VIEW " ); - aRestoreCommand.append ( sQualifiedName ); - aRestoreCommand.append( " AS " ); - aRestoreCommand.append ( impl_getCommand_throwSQLException() ); - OUString sRestoreCommand( aRestoreCommand.makeStringAndClear() ); + OUString sRestoreCommand = + "CREATE VIEW " + + sQualifiedName + + " AS " + + impl_getCommand_throwSQLException(); bool bDropSucceeded( false ); try @@ -147,8 +146,8 @@ namespace connectivity::hsqldb OUString HView::impl_getCommand() const { - OUStringBuffer aCommand; - aCommand.append( "SELECT VIEW_DEFINITION FROM INFORMATION_SCHEMA.SYSTEM_VIEWS " ); + OUStringBuffer aCommand( + "SELECT VIEW_DEFINITION FROM INFORMATION_SCHEMA.SYSTEM_VIEWS " ); HTools::appendTableFilterCrit( aCommand, m_CatalogName, m_SchemaName, m_Name, false ); ::utl::SharedUNOComponent< XStatement > xStatement; xStatement.set( m_xConnection->createStatement(), UNO_QUERY_THROW ); Reference< XResultSet > xResult( xStatement->executeQuery( aCommand.makeStringAndClear() ), css::uno::UNO_SET_THROW ); diff --git a/connectivity/source/drivers/hsqldb/HViews.cxx b/connectivity/source/drivers/hsqldb/HViews.cxx index e67a9fa14f86..880b7bc4ce51 100644 --- a/connectivity/source/drivers/hsqldb/HViews.cxx +++ b/connectivity/source/drivers/hsqldb/HViews.cxx @@ -33,10 +33,7 @@ using namespace connectivity; using namespace connectivity::hsqldb; using namespace css::uno; using namespace css::beans; -using namespace css::sdbcx; using namespace css::sdbc; -using namespace css::container; -using namespace css::lang; using namespace dbtools; typedef connectivity::sdbcx::OCollection OCollection_TYPE; @@ -51,7 +48,7 @@ HViews::HViews( const Reference< XConnection >& _rxConnection, ::cppu::OWeakObje } -sdbcx::ObjectType HViews::createObject(const OUString& _rName) +css::uno::Reference< css::beans::XPropertySet > HViews::createObject(const OUString& _rName) { OUString sCatalog,sSchema,sTable; ::dbtools::qualifiedNameComponents(m_xMetaData, @@ -78,12 +75,11 @@ void HViews::disposing() Reference< XPropertySet > HViews::createDescriptor() { Reference<XConnection> xConnection = static_cast<OHCatalog&>(m_rParent).getConnection(); - connectivity::sdbcx::OView* pNew = new connectivity::sdbcx::OView(true, xConnection->getMetaData()); - return pNew; + return new connectivity::sdbcx::OView(true, xConnection->getMetaData()); } // XAppend -sdbcx::ObjectType HViews::appendObject( const OUString& _rForName, const Reference< XPropertySet >& descriptor ) +css::uno::Reference< css::beans::XPropertySet > HViews::appendObject( const OUString& _rForName, const Reference< XPropertySet >& descriptor ) { createView(descriptor); return createObject( _rForName ); @@ -99,7 +95,7 @@ void HViews::dropObject(sal_Int32 _nPos,const OUString& /*_sElementName*/) bool bIsNew = connectivity::sdbcx::ODescriptor::isNew( xObject ); if (!bIsNew) { - OUString aSql( "DROP VIEW" ); + OUString aSql( u"DROP VIEW"_ustr ); Reference<XPropertySet> xProp(xObject,UNO_QUERY); aSql += ::dbtools::composeTableName( m_xMetaData, xProp, ::dbtools::EComposeRule::InTableDefinitions, true ); diff --git a/connectivity/source/drivers/hsqldb/StorageFileAccess.cxx b/connectivity/source/drivers/hsqldb/StorageFileAccess.cxx index 65457ab1d129..bb07d6673fb1 100644 --- a/connectivity/source/drivers/hsqldb/StorageFileAccess.cxx +++ b/connectivity/source/drivers/hsqldb/StorageFileAccess.cxx @@ -24,8 +24,7 @@ #include <com/sun/star/embed/XStorage.hpp> #include <com/sun/star/lang/IllegalArgumentException.hpp> #include <hsqldb/HStorageMap.hxx> -#include <osl/diagnose.h> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> using namespace ::com::sun::star::container; using namespace ::com::sun::star::uno; @@ -44,42 +43,42 @@ extern "C" SAL_JNI_EXPORT jboolean JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_S { TStorages::mapped_type aStoragePair = StorageContainer::getRegisteredStorage(StorageContainer::jstring2ustring(env,key)); auto storage = aStoragePair.mapStorage(); - if ( storage.is() ) + if ( !storage ) + return JNI_FALSE; + + try { + OUString sName = StorageContainer::jstring2ustring(env,name); try { - OUString sName = StorageContainer::jstring2ustring(env,name); - try + OUString sOldName = StorageContainer::removeOldURLPrefix(sName); + if ( storage->isStreamElement(sOldName) ) { - OUString sOldName = StorageContainer::removeOldURLPrefix(sName); - if ( storage->isStreamElement(sOldName) ) + try + { + storage->renameElement(sOldName,StorageContainer::removeURLPrefix(sName,aStoragePair.url)); + } + catch(const Exception&) { - try - { - storage->renameElement(sOldName,StorageContainer::removeURLPrefix(sName,aStoragePair.url)); - } - catch(const Exception&) - { - } } } - catch(const NoSuchElementException&) - { - } - catch(const IllegalArgumentException&) - { - } - return storage->isStreamElement(StorageContainer::removeURLPrefix(sName,aStoragePair.url)); } catch(const NoSuchElementException&) { } - catch(const Exception&) + catch(const IllegalArgumentException&) { - TOOLS_WARN_EXCEPTION("connectivity.hsqldb", "forwarding"); - if (env->ExceptionCheck()) - env->ExceptionClear(); } + return storage->isStreamElement(StorageContainer::removeURLPrefix(sName,aStoragePair.url)); + } + catch(const NoSuchElementException&) + { + } + catch(const Exception&) + { + TOOLS_WARN_EXCEPTION("connectivity.hsqldb", "forwarding"); + if (env->ExceptionCheck()) + env->ExceptionClear(); } return JNI_FALSE; } diff --git a/connectivity/source/drivers/hsqldb/StorageNativeInputStream.cxx b/connectivity/source/drivers/hsqldb/StorageNativeInputStream.cxx index 7ddf79aa5e77..3336c7f78bb0 100644 --- a/connectivity/source/drivers/hsqldb/StorageNativeInputStream.cxx +++ b/connectivity/source/drivers/hsqldb/StorageNativeInputStream.cxx @@ -27,18 +27,16 @@ #include <hsqldb/HStorageMap.hxx> #include <osl/diagnose.h> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include "accesslog.hxx" #include <limits> -using namespace ::com::sun::star::container; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::document; using namespace ::com::sun::star::embed; using namespace ::com::sun::star::io; -using namespace ::com::sun::star::lang; using namespace ::connectivity::hsqldb; /*****************************************************************************/ @@ -136,9 +134,12 @@ extern "C" SAL_JNI_EXPORT jlong JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_Stor #endif if ( n < 0 ) + { ThrowException( env, "java/io/IOException", "n < 0"); + return 0; + } std::shared_ptr<StreamHelper> pHelper = StorageContainer::getRegisteredStream(env,name,key); OSL_ENSURE(pHelper,"No stream helper!"); @@ -155,10 +156,10 @@ extern "C" SAL_JNI_EXPORT jlong JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_Stor try { do { - if (tmpLongVal >= std::numeric_limits<sal_Int64>::max() ) + if (tmpLongVal > std::numeric_limits<sal_Int32>::max() ) tmpIntVal = std::numeric_limits<sal_Int32>::max(); else // Casting is safe here. - tmpIntVal = static_cast<sal_Int32>(tmpLongVal); + tmpIntVal = static_cast<sal_Int32>(tmpLongVal & 0xFFFFFFFF); tmpLongVal -= tmpIntVal; @@ -277,7 +278,7 @@ extern "C" SAL_JNI_EXPORT jint JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_Stora } OSL_ENSURE(nLen >= nBytesRead,"Buffer is too small!"); OSL_ENSURE(aData.getLength() >= nBytesRead,"Buffer is too small!"); - env->SetByteArrayRegion(buffer, 0, nBytesRead, reinterpret_cast<jbyte*>(&aData[0])); + env->SetByteArrayRegion(buffer, 0, nBytesRead, reinterpret_cast<const jbyte*>(&aData[0])); #ifdef HSQLDB_DBG aDataLog.write( &aData[0], nBytesRead ); #endif diff --git a/connectivity/source/drivers/hsqldb/StorageNativeOutputStream.cxx b/connectivity/source/drivers/hsqldb/StorageNativeOutputStream.cxx index f766696e0d9b..bccbec20fcd2 100644 --- a/connectivity/source/drivers/hsqldb/StorageNativeOutputStream.cxx +++ b/connectivity/source/drivers/hsqldb/StorageNativeOutputStream.cxx @@ -30,12 +30,8 @@ #include <hsqldb/HStorageAccess.hxx> #include <hsqldb/HStorageMap.hxx> -using namespace ::com::sun::star::container; using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::document; -using namespace ::com::sun::star::embed; using namespace ::com::sun::star::io; -using namespace ::com::sun::star::lang; using namespace ::connectivity::hsqldb; diff --git a/connectivity/source/drivers/hsqldb/accesslog.hxx b/connectivity/source/drivers/hsqldb/accesslog.hxx index a4dc41f2d35e..81db98ae7750 100644 --- a/connectivity/source/drivers/hsqldb/accesslog.hxx +++ b/connectivity/source/drivers/hsqldb/accesslog.hxx @@ -17,8 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_HSQLDB_ACCESSLOG_HXX -#define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_HSQLDB_ACCESSLOG_HXX +#pragma once #ifdef HSQLDB_DBG @@ -133,6 +132,4 @@ namespace connectivity::hsqldb } } #endif -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_HSQLDB_ACCESSLOG_HXX - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |