diff options
Diffstat (limited to 'connectivity/source/drivers/hsqldb')
19 files changed, 206 insertions, 236 deletions
diff --git a/connectivity/source/drivers/hsqldb/HCatalog.cxx b/connectivity/source/drivers/hsqldb/HCatalog.cxx index 029e60f9450a..c51c9d15a520 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) @@ -54,9 +51,7 @@ void OHCatalog::refreshTables() { ::std::vector< OUString> aVector; - Sequence< OUString > sTableTypes(2); - sTableTypes[0] = "VIEW"; - sTableTypes[1] = "TABLE"; + Sequence< OUString > sTableTypes {"VIEW", "TABLE"}; refreshObjects(sTableTypes,aVector); diff --git a/connectivity/source/drivers/hsqldb/HColumns.cxx b/connectivity/source/drivers/hsqldb/HColumns.cxx index 3f03c3616bc1..e37f9fbd3a5e 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 diff --git a/connectivity/source/drivers/hsqldb/HConnection.cxx b/connectivity/source/drivers/hsqldb/HConnection.cxx index c3ff0169cea7..28feb95fce9b 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> @@ -280,8 +281,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 +315,12 @@ 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( + "URL", OUString( + // load the graphic from the global graphic repository + "private:graphicrepository/" + // the relative path within the images.zip + LINKED_TEXT_TABLE_IMAGE_RESOURCE)) }; 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 87c940a1c17c..234fc969db63 100644 --- a/connectivity/source/drivers/hsqldb/HDriver.cxx +++ b/connectivity/source/drivers/hsqldb/HDriver.cxx @@ -41,7 +41,6 @@ #include <osl/file.h> #include <osl/process.h> #include <comphelper/namedvaluecollection.hxx> -#include <comphelper/processfactory.hxx> #include <comphelper/propertysequence.hxx> #include <comphelper/servicehelper.hxx> #include <cppuhelper/supportsservice.hxx> @@ -51,7 +50,8 @@ #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 <memory> @@ -69,9 +69,8 @@ namespace connectivity using namespace css::embed; using namespace css::io; using namespace css::util; - using namespace css::reflection; - constexpr OUStringLiteral IMPL_NAME = "com.sun.star.sdbcx.comp.hsqldb.Driver"; + constexpr OUString IMPL_NAME = u"com.sun.star.sdbcx.comp.hsqldb.Driver"_ustr; @@ -214,14 +213,12 @@ namespace connectivity aProperties.put( "JavaDriverClass", OUString( "org.hsqldb.jdbcDriver" ) ); aProperties.put( "JavaDriverClassPath", - OUString( #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 ); @@ -236,14 +233,14 @@ namespace connectivity // security: permitted Java classes NamedValue aPermittedClasses( "hsqldb.method_class_names", - makeAny( lcl_getPermittedJavaMethods_nothrow( m_xContext ) ) + Any( lcl_getPermittedJavaMethods_nothrow( m_xContext ) ) ); aProperties.put( "SystemProperties", Sequence< NamedValue >( &aPermittedClasses, 1 ) ); - const OUString sProperties( "properties" ); OUString sMessage; try { + static constexpr OUString sProperties( u"properties"_ustr ); if ( !bIsNewDatabase && xStorage->isStreamElement(sProperties) ) { Reference<XStream > xStream = xStorage->openStreamElement(sProperties,ElementModes::READ); @@ -252,15 +249,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; @@ -276,9 +273,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 ) ) @@ -291,6 +288,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&) { @@ -334,7 +362,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); @@ -347,7 +375,7 @@ namespace connectivity { Reference< XDesktop2 > xDesktop = Desktop::create( m_xContext ); - auto tmp = new OConnectionController(this); + rtl::Reference<OConnectionController> tmp = new OConnectionController(this); xDesktop->addTerminateListener(tmp); return tmp; }(); @@ -358,8 +386,7 @@ namespace connectivity Reference<XTransactionBroadcaster> xBroad(xStorage,UNO_QUERY); if ( xBroad.is() ) { - Reference<XTransactionListener> xListener(*this,UNO_QUERY); - xBroad->addTransactionListener(xListener); + xBroad->addTransactionListener(Reference<XTransactionListener>(this)); } } } @@ -394,29 +421,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 + { + { + "Storage", + "Defines the storage where the database will be stored.", + true, + {}, + {} + }, + { + "URL", + "Defines the url of the data source.", + true, + {}, + {} + }, + { + "AutoRetrievingStatement", + "Defines the statement which will be executed to retrieve auto increment values.", + false, + "CALL IDENTITY()", + {} + } + }; } @@ -833,8 +861,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 7bb868d2ff1a..8d15d487372a 100644 --- a/connectivity/source/drivers/hsqldb/HStorageAccess.cxx +++ b/connectivity/source/drivers/hsqldb/HStorageAccess.cxx @@ -22,14 +22,14 @@ #include <hsqldb/HStorageMap.hxx> #include "accesslog.hxx" #include <osl/diagnose.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) { \ @@ -76,7 +76,7 @@ extern "C" SAL_JNI_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_Nativ } catch(const Exception&) { - OSL_FAIL( "NativeStorageAccess::close: caught an exception while flushing!" ); + TOOLS_WARN_EXCEPTION( "connectivity.hsqldb", "NativeStorageAccess::close: caught an exception while flushing!" ); } #ifdef HSQLDB_DBG { @@ -145,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; } @@ -228,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; } @@ -298,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) { @@ -340,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 @@ -426,7 +429,7 @@ void write_to_storage_stream_from_buffer( JNIEnv* env, jstring name, jstring key } catch(const Exception& e) { - OSL_FAIL("Exception caught! : write [BII)V"); + TOOLS_WARN_EXCEPTION( "connectivity.hsqldb", "Exception caught! : write [BII)V"); StorageContainer::throwJavaException(e,env); } } @@ -462,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); } @@ -479,7 +484,7 @@ void write_to_storage_stream( JNIEnv* env, jstring name, jstring key, jint v ) } catch(const Exception& e) { - OSL_FAIL("Exception caught! : writeBytes(aData);"); + TOOLS_WARN_EXCEPTION( "connectivity.hsqldb", "writeBytes(aData);"); StorageContainer::throwJavaException(e,env); } } diff --git a/connectivity/source/drivers/hsqldb/HStorageMap.cxx b/connectivity/source/drivers/hsqldb/HStorageMap.cxx index d10ee29a69f6..01a9c3d34be3 100644 --- a/connectivity/source/drivers/hsqldb/HStorageMap.cxx +++ b/connectivity/source/drivers/hsqldb/HStorageMap.cxx @@ -27,6 +27,7 @@ #include <sal/log.hxx> #include <uno/mapping.hxx> #include <algorithm> +#include <comphelper/diagnose_ex.hxx> namespace connectivity::hsqldb { @@ -72,7 +73,7 @@ namespace connectivity::hsqldb } catch(const Exception&) { - OSL_FAIL("Exception caught!"); + TOOLS_WARN_EXCEPTION( "connectivity.hsqldb", ""); } } @@ -131,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) @@ -308,7 +309,7 @@ namespace connectivity::hsqldb } catch(const Exception& e) { - SAL_WARN( "connectivity.hsqldb", "[HSQLDB-SDBC] caught an exception while opening a stream\n" + TOOLS_WARN_EXCEPTION( "connectivity.hsqldb", "[HSQLDB-SDBC] caught an exception while opening a stream\n" "Name: " << sName << "\nMode: 0x" << ( _nMode < 16 ? "0" : "") << std::hex << _nMode ); diff --git a/connectivity/source/drivers/hsqldb/HTable.cxx b/connectivity/source/drivers/hsqldb/HTable.cxx index f8dee57c510c..63fe36a34a34 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,16 +244,15 @@ 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); } -void OHSQLTable::alterDefaultValue(const OUString& _sNewDefault,const OUString& _rColName) +void OHSQLTable::alterDefaultValue(std::u16string_view _sNewDefault,const OUString& _rColName) { const OUString sQuote = getMetaData()->getIdentifierQuoteString( ); OUString sSql = getAlterTableColumnPart() + @@ -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() ) diff --git a/connectivity/source/drivers/hsqldb/HTables.cxx b/connectivity/source/drivers/hsqldb/HTables.cxx index 787af894b992..002dfbf9a295 100644 --- a/connectivity/source/drivers/hsqldb/HTables.cxx +++ b/connectivity/source/drivers/hsqldb/HTables.cxx @@ -37,7 +37,6 @@ 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) @@ -45,10 +44,7 @@ sdbcx::ObjectType OTables::createObject(const OUString& _rName) OUString sCatalog,sSchema,sTable; ::dbtools::qualifiedNameComponents(m_xMetaData,_rName,sCatalog,sSchema,sTable,::dbtools::EComposeRule::InDataManipulation); - Sequence< OUString > sTableTypes(3); - sTableTypes[0] = "VIEW"; - sTableTypes[1] = "TABLE"; - sTableTypes[2] = "%"; // just to be sure to include anything else... + Sequence< OUString > sTableTypes {"VIEW", "TABLE", "%"}; // this last one just to be sure to include anything else... Any aCatalog; if ( !sCatalog.isEmpty() ) @@ -66,7 +62,7 @@ sdbcx::ObjectType OTables::createObject(const OUString& _rName) nPrivileges &= ~( Privilege::INSERT | Privilege::UPDATE | Privilege::DELETE | Privilege::CREATE | Privilege::ALTER | Privilege::DROP ); // obtain privileges - OHSQLTable* pRet = new OHSQLTable( this + xRet = new OHSQLTable( this ,static_cast<OHCatalog&>(m_rParent).getConnection() ,sTable ,xRow->getString(4) @@ -74,7 +70,6 @@ sdbcx::ObjectType OTables::createObject(const OUString& _rName) ,sSchema ,sCatalog ,nPrivileges); - xRet = pRet; } ::comphelper::disposeComponent(xResult); } @@ -164,10 +159,10 @@ 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) diff --git a/connectivity/source/drivers/hsqldb/HTerminateListener.cxx b/connectivity/source/drivers/hsqldb/HTerminateListener.cxx index df325efb75e8..7c6b494488db 100644 --- a/connectivity/source/drivers/hsqldb/HTerminateListener.cxx +++ b/connectivity/source/drivers/hsqldb/HTerminateListener.cxx @@ -17,36 +17,28 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ - #include "HTerminateListener.hxx" #include <hsqldb/HDriver.hxx> - namespace connectivity { - - using namespace hsqldb; - using namespace ::com::sun::star::uno; - using namespace ::com::sun::star::lang; +using namespace hsqldb; +using namespace ::com::sun::star::lang; // XEventListener -void SAL_CALL OConnectionController::disposing( const EventObject& /*Source*/ ) -{ -} +void SAL_CALL OConnectionController::disposing(const EventObject& /*Source*/) {} // XTerminateListener -void SAL_CALL OConnectionController::queryTermination( const EventObject& /*aEvent*/ ) +void SAL_CALL OConnectionController::queryTermination(const EventObject& /*aEvent*/) { m_pDriver->flushConnections(); } -void SAL_CALL OConnectionController::notifyTermination( const EventObject& /*aEvent*/ ) +void SAL_CALL OConnectionController::notifyTermination(const EventObject& /*aEvent*/) { m_pDriver->shutdownConnections(); } - -} // namespace connectivity - +} // namespace connectivity /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/hsqldb/HTerminateListener.hxx b/connectivity/source/drivers/hsqldb/HTerminateListener.hxx index 62e8ec79d660..baf66e90eb1e 100644 --- a/connectivity/source/drivers/hsqldb/HTerminateListener.hxx +++ b/connectivity/source/drivers/hsqldb/HTerminateListener.hxx @@ -16,18 +16,13 @@ * 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 -{ - - - namespace hsqldb +namespace connectivity::hsqldb { class ODriverDelegator; class OConnectionController : public ::cppu::WeakImplHelper< css::frame::XTerminateListener > @@ -45,10 +40,7 @@ namespace connectivity virtual void SAL_CALL queryTermination( const css::lang::EventObject& aEvent ) override; virtual void SAL_CALL notifyTermination( const css::lang::EventObject& aEvent ) override; }; - } - -} // namespace connectivity -#endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_HSQLDB_HTERMINATELISTENER_HXX +} // namespace connectivity::hsqldb /* 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..f493e282a2b1 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(); } diff --git a/connectivity/source/drivers/hsqldb/HUsers.cxx b/connectivity/source/drivers/hsqldb/HUsers.cxx index 40d1f5243cb6..07a91e7cbed2 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,16 +31,14 @@ 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) { } @@ -57,8 +56,7 @@ void OUsers::impl_refresh() Reference< XPropertySet > OUsers::createDescriptor() { - OUserExtend* pNew = new OUserExtend(m_xConnection); - return pNew; + return new OUserExtend(m_xConnection); } // XAppend 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..f80ec7716f09 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; @@ -78,8 +75,7 @@ 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 diff --git a/connectivity/source/drivers/hsqldb/StorageFileAccess.cxx b/connectivity/source/drivers/hsqldb/StorageFileAccess.cxx index 3e8461a95f8f..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; } @@ -159,7 +158,7 @@ extern "C" SAL_JNI_EXPORT void JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_Stora } catch(const Exception& e) { - OSL_FAIL("Exception caught! : Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_renameElement"); + TOOLS_WARN_EXCEPTION( "connectivity.hsqldb", "Java_com_sun_star_sdbcx_comp_hsqldb_StorageFileAccess_renameElement"); StorageContainer::throwJavaException(e,env); } } diff --git a/connectivity/source/drivers/hsqldb/StorageNativeInputStream.cxx b/connectivity/source/drivers/hsqldb/StorageNativeInputStream.cxx index b16eaf742e1c..58d351673480 100644 --- a/connectivity/source/drivers/hsqldb/StorageNativeInputStream.cxx +++ b/connectivity/source/drivers/hsqldb/StorageNativeInputStream.cxx @@ -27,17 +27,16 @@ #include <hsqldb/HStorageMap.hxx> #include <osl/diagnose.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; /*****************************************************************************/ @@ -173,7 +172,7 @@ extern "C" SAL_JNI_EXPORT jlong JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_Stor } catch(const Exception& e) { - OSL_FAIL("Exception caught! : skip();"); + TOOLS_WARN_EXCEPTION( "connectivity.hsqldb", "skip();"); StorageContainer::throwJavaException(e,env); } } @@ -216,7 +215,7 @@ extern "C" SAL_JNI_EXPORT jint JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_Stora } catch(const Exception& e) { - OSL_FAIL("Exception caught! : available();"); + TOOLS_WARN_EXCEPTION( "connectivity.hsqldb", "available();"); StorageContainer::throwJavaException(e,env); } } @@ -260,7 +259,7 @@ extern "C" SAL_JNI_EXPORT jint JNICALL Java_com_sun_star_sdbcx_comp_hsqldb_Stora } catch(const Exception& e) { - OSL_FAIL("Exception caught! : skip();"); + TOOLS_WARN_EXCEPTION( "connectivity.hsqldb", "skip();"); StorageContainer::throwJavaException(e,env); } @@ -276,7 +275,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: */ |