ucb/source/ucp/file/filrow.cxx |  118 +++++++++++++++--------------------------
 ucb/source/ucp/file/filrow.hxx |    4 +
 2 files changed, 48 insertions(+), 74 deletions(-)

New commits:
commit 639698862d16310b60514277d59227eec37eb02a
Author:     Arkadiy Illarionov <qar...@gmail.com>
AuthorDate: Sat Jun 29 16:44:52 2019 +0300
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Sun Jun 30 11:46:28 2019 +0200

    tdf#39593 Reduce copy-paste in XRow_impl::get*
    
    Add isIndexOutOfBounds and template getValue methods
    
    Change-Id: I2eab7a86329b68d659b4780be50826da42c631aa
    Reviewed-on: https://gerrit.libreoffice.org/74885
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/ucb/source/ucp/file/filrow.cxx b/ucb/source/ucp/file/filrow.cxx
index a6156823bbf0..67845ea426d7 100644
--- a/ucb/source/ucp/file/filrow.cxx
+++ b/ucb/source/ucp/file/filrow.cxx
@@ -101,19 +101,16 @@ OUString SAL_CALL
 XRow_impl::getString(
              sal_Int32 columnIndex )
 {
-  if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
+  if( isIndexOutOfBounds( columnIndex ) )
     throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface 
>(), OUString(), 0, uno::Any() );
-  OUString  Value;
-  osl::MutexGuard aGuard( m_aMutex );
-  m_nWasNull = ::convert<OUString>( m_pMyShell,m_xTypeConverter,m_aValueMap[ 
--columnIndex ],Value );
-  return Value;
+  return getValue<OUString>(columnIndex);
 }
 
 sal_Bool SAL_CALL
 XRow_impl::getBoolean(
     sal_Int32 columnIndex )
 {
-    if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
+    if( isIndexOutOfBounds( columnIndex ) )
         throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface 
>(), OUString(), 0, uno::Any() );
     bool  Value( false );
     osl::MutexGuard aGuard( m_aMutex );
@@ -126,7 +123,7 @@ sal_Int8 SAL_CALL
 XRow_impl::getByte(
     sal_Int32 columnIndex )
 {
-    if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
+    if( isIndexOutOfBounds( columnIndex ) )
         throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface 
>(), OUString(), 0, uno::Any() );
     sal_Int8  Value( 0 );
     osl::MutexGuard aGuard( m_aMutex );
@@ -138,7 +135,7 @@ sal_Int16 SAL_CALL
 XRow_impl::getShort(
     sal_Int32 columnIndex )
 {
-    if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
+    if( isIndexOutOfBounds( columnIndex ) )
         throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface 
>(), OUString(), 0, uno::Any() );
     sal_Int16  Value( 0 );
     osl::MutexGuard aGuard( m_aMutex );
@@ -151,7 +148,7 @@ sal_Int32 SAL_CALL
 XRow_impl::getInt(
           sal_Int32 columnIndex )
 {
-    if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
+    if( isIndexOutOfBounds( columnIndex ) )
         throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface 
>(), OUString(), 0, uno::Any() );
     sal_Int32  Value( 0 );
     osl::MutexGuard aGuard( m_aMutex );
@@ -163,7 +160,7 @@ sal_Int64 SAL_CALL
 XRow_impl::getLong(
            sal_Int32 columnIndex )
 {
-    if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
+    if( isIndexOutOfBounds( columnIndex ) )
         throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface 
>(), OUString(), 0, uno::Any() );
     sal_Int64  Value( 0 );
     osl::MutexGuard aGuard( m_aMutex );
@@ -175,7 +172,7 @@ float SAL_CALL
 XRow_impl::getFloat(
     sal_Int32 columnIndex )
 {
-    if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
+    if( isIndexOutOfBounds( columnIndex ) )
         throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface 
>(), OUString(), 0, uno::Any() );
     float  Value( 0 );
     osl::MutexGuard aGuard( m_aMutex );
@@ -187,7 +184,7 @@ double SAL_CALL
 XRow_impl::getDouble(
     sal_Int32 columnIndex )
 {
-    if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
+    if( isIndexOutOfBounds( columnIndex ) )
         throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface 
>(), OUString(), 0, uno::Any() );
     double  Value( 0 );
     osl::MutexGuard aGuard( m_aMutex );
@@ -199,48 +196,36 @@ uno::Sequence< sal_Int8 > SAL_CALL
 XRow_impl::getBytes(
     sal_Int32 columnIndex )
 {
-    if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
+    if( isIndexOutOfBounds( columnIndex ) )
         throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface 
>(), OUString(), 0, uno::Any() );
-    uno::Sequence< sal_Int8 >  Value(0);
-    osl::MutexGuard aGuard( m_aMutex );
-    m_nWasNull = ::convert<uno::Sequence< sal_Int8 > >( 
m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
-    return Value;
+    return getValue<uno::Sequence< sal_Int8 >>(columnIndex);
 }
 
 util::Date SAL_CALL
 XRow_impl::getDate(
     sal_Int32 columnIndex )
 {
-    if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
+    if( isIndexOutOfBounds( columnIndex ) )
         throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface 
>(), OUString(), 0, uno::Any() );
-    util::Date  Value;
-    osl::MutexGuard aGuard( m_aMutex );
-    m_nWasNull = ::convert<util::Date>( 
m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
-    return Value;
+    return getValue<util::Date>(columnIndex);
 }
 
 util::Time SAL_CALL
 XRow_impl::getTime(
     sal_Int32 columnIndex )
 {
-    if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
+    if( isIndexOutOfBounds( columnIndex ) )
         throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface 
>(), OUString(), 0, uno::Any() );
-    util::Time  Value;
-    osl::MutexGuard aGuard( m_aMutex );
-    m_nWasNull = ::convert<util::Time>( 
m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
-    return Value;
+    return getValue<util::Time>(columnIndex);
 }
 
 util::DateTime SAL_CALL
 XRow_impl::getTimestamp(
             sal_Int32 columnIndex )
 {
-  if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
+  if( isIndexOutOfBounds( columnIndex ) )
     throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface 
>(), OUString(), 0, uno::Any() );
-  util::DateTime  Value;
-  osl::MutexGuard aGuard( m_aMutex );
-  m_nWasNull = ::convert<util::DateTime>( 
m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
-  return Value;
+  return getValue<util::DateTime>(columnIndex);
 }
 
 
@@ -248,12 +233,9 @@ uno::Reference< io::XInputStream > SAL_CALL
 XRow_impl::getBinaryStream(
                sal_Int32 columnIndex )
 {
-  if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
+  if( isIndexOutOfBounds( columnIndex ) )
     throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface 
>(), OUString(), 0, uno::Any() );
-  uno::Reference< io::XInputStream >  Value;
-  osl::MutexGuard aGuard( m_aMutex );
-  m_nWasNull = ::convert<uno::Reference< io::XInputStream > >( 
m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
-  return Value;
+  return getValue<uno::Reference< io::XInputStream >>(columnIndex);
 }
 
 
@@ -261,12 +243,9 @@ uno::Reference< io::XInputStream > SAL_CALL
 XRow_impl::getCharacterStream(
                   sal_Int32 columnIndex )
 {
-  if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
+  if( isIndexOutOfBounds( columnIndex ) )
       throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface 
>(), OUString(), 0, uno::Any() );
-  uno::Reference< io::XInputStream > Value;
-  osl::MutexGuard aGuard( m_aMutex );
-  m_nWasNull = ::convert< uno::Reference< io::XInputStream> >( 
m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
-  return Value;
+  return getValue<uno::Reference< io::XInputStream >>(columnIndex);
 }
 
 
@@ -275,7 +254,7 @@ XRow_impl::getObject(
     sal_Int32 columnIndex,
     const uno::Reference< container::XNameAccess >& )
 {
-    if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
+    if( isIndexOutOfBounds( columnIndex ) )
         throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface 
>(), OUString(), 0, uno::Any() );
     osl::MutexGuard aGuard( m_aMutex );
     uno::Any Value = m_aValueMap[columnIndex - 1];
@@ -287,45 +266,27 @@ uno::Reference< sdbc::XRef > SAL_CALL
 XRow_impl::getRef(
     sal_Int32 columnIndex )
 {
-    if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
+    if( isIndexOutOfBounds( columnIndex ) )
         throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface 
>(), OUString(), 0, uno::Any() );
-    uno::Reference< sdbc::XRef > Value;
-    osl::MutexGuard aGuard( m_aMutex );
-    m_nWasNull = ::convert<uno::Reference< sdbc::XRef> >( m_pMyShell,
-                                                          m_xTypeConverter,
-                                                          m_aValueMap[ 
--columnIndex ],
-                                                          Value );
-    return Value;
+    return getValue<uno::Reference< sdbc::XRef >>(columnIndex);
 }
 
 uno::Reference< sdbc::XBlob > SAL_CALL
 XRow_impl::getBlob(
            sal_Int32 columnIndex )
 {
-    if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
+    if( isIndexOutOfBounds( columnIndex ) )
         throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface 
>(), OUString(), 0, uno::Any() );
-    uno::Reference< sdbc::XBlob > Value;
-    osl::MutexGuard aGuard( m_aMutex );
-    m_nWasNull = ::convert<uno::Reference< sdbc::XBlob> >( m_pMyShell,
-                                                           m_xTypeConverter,
-                                                           m_aValueMap[ 
--columnIndex ],
-                                                           Value );
-    return Value;
+    return getValue<uno::Reference< sdbc::XBlob >>(columnIndex);
 }
 
 uno::Reference< sdbc::XClob > SAL_CALL
 XRow_impl::getClob(
            sal_Int32 columnIndex )
 {
-    if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
+    if( isIndexOutOfBounds( columnIndex ) )
         throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface 
>(), OUString(), 0, uno::Any() );
-    uno::Reference< sdbc::XClob > Value;
-    osl::MutexGuard aGuard( m_aMutex );
-    m_nWasNull = ::convert<uno::Reference< sdbc::XClob> >( m_pMyShell,
-                                                           m_xTypeConverter,
-                                                           m_aValueMap[ 
--columnIndex ],
-                                                           Value );
-    return Value;
+    return getValue<uno::Reference< sdbc::XClob >>(columnIndex);
 }
 
 
@@ -333,15 +294,24 @@ uno::Reference< sdbc::XArray > SAL_CALL
 XRow_impl::getArray(
     sal_Int32 columnIndex )
 {
-    if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
+    if( isIndexOutOfBounds( columnIndex ) )
         throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface 
>(), OUString(), 0, uno::Any() );
-    uno::Reference< sdbc::XArray > Value;
+    return getValue<uno::Reference< sdbc::XArray >>(columnIndex);
+}
+
+bool
+XRow_impl::isIndexOutOfBounds(sal_Int32 nIndex)
+{
+    return nIndex < 1 || m_aValueMap.getLength() < nIndex;
+}
+
+template<typename T>
+T XRow_impl::getValue(sal_Int32 columnIndex)
+{
+    T aValue;
     osl::MutexGuard aGuard( m_aMutex );
-    m_nWasNull = ::convert<uno::Reference< sdbc::XArray> >( m_pMyShell,
-                                                            m_xTypeConverter,
-                                                            m_aValueMap[ 
--columnIndex ],
-                                                            Value );
-    return Value;
+    m_nWasNull = ::convert<T>( m_pMyShell, m_xTypeConverter, m_aValueMap[ 
--columnIndex ], aValue );
+    return aValue;
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/ucb/source/ucp/file/filrow.hxx b/ucb/source/ucp/file/filrow.hxx
index d4008ff8110f..eaeed2b7f387 100644
--- a/ucb/source/ucp/file/filrow.hxx
+++ b/ucb/source/ucp/file/filrow.hxx
@@ -104,6 +104,10 @@ namespace fileaccess {
         bool                                               m_nWasNull;
         TaskManager* const                                 m_pMyShell;
         css::uno::Reference< css::script::XTypeConverter > m_xTypeConverter;
+
+        bool isIndexOutOfBounds( sal_Int32 nIndex );
+        template<typename T>
+        T getValue(sal_Int32 columnIndex);
     };
 
 } // end namespace fileaccess
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to