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.grandin@collabora.co.uk>
diff --git a/ucb/source/ucp/file/filrow.cxx b/ucb/source/ucp/file/filrow.cxx
index a615682..67845ea4 100644
--- a/ucb/source/ucp/file/filrow.cxx
+++ b/ucb/source/ucp/file/filrow.cxx
@@ -101,19 +101,16 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 d4008ff..eaeed2b 100644
--- a/ucb/source/ucp/file/filrow.hxx
+++ b/ucb/source/ucp/file/filrow.hxx
@@ -104,6 +104,10 @@
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