24#include <com/sun/star/sdbc/SQLException.hpp>
25#include <com/sun/star/sdbc/XRow.hpp>
44 using namespace ::
osl;
46 using namespace ::
cppu;
55 OUString* pTableFilters = _rTableFilter.getArray();
56 OUString* pEnd = pTableFilters + _rTableFilter.getLength();
57 sal_Int32 nShiftPos = 0;
58 for (sal_Int32
i=0; pEnd != pTableFilters; ++pTableFilters,++
i)
60 if (pTableFilters->indexOf(
'%') != -1)
62 _rOut.emplace_back(pTableFilters->replace(
'%',
'*'));
68 _rTableFilter.getArray()[nShiftPos] = _rTableFilter.getArray()[
i];
74 _rTableFilter.realloc(nShiftPos);
79 const Sequence< OUString >& _rTableFilter,
80 const std::vector< WildCard >& _rWCSearch )
82 sal_Int32 nTableFilterLen = _rTableFilter.getLength();
84 const OUString* tableFilter = _rTableFilter.getConstArray();
85 const OUString* tableFilterEnd = _rTableFilter.getConstArray() + nTableFilterLen;
86 bool bFilterMatch = std::find( tableFilter, tableFilterEnd, _rName ) != tableFilterEnd;
88 if (!bFilterMatch && !_rWCSearch.empty())
90 for (
auto const& elem : _rWCSearch)
92 bFilterMatch = elem.Matches( _rName );
113 explicit TableInfo(
const OUString& _composedName )
118 TableInfo(
const OUString& _catalog,
const OUString& _schema,
const OUString& _name,
119 const OUString& _type )
134 if ( !_metaData.is() )
135 throw RuntimeException(
"lcl_ensureComposedName: _metaData cannot be null!");
137 if ( !_io_tableInfo.sComposedName )
139 OSL_ENSURE( !!_io_tableInfo.sCatalog && !!_io_tableInfo.sSchema && !!_io_tableInfo.sName,
"lcl_ensureComposedName: How should I composed the name from nothing!?" );
142 composeTableName( _metaData, *_io_tableInfo.sCatalog, *_io_tableInfo.sSchema, *_io_tableInfo.sName,
143 false, ::dbtools::EComposeRule::InDataManipulation )
148 static void lcl_ensureType( TableInfo& _io_tableInfo,
const Reference< XDatabaseMetaData >& _metaData,
const Reference< XNameAccess >& _masterContainer )
150 if ( !!_io_tableInfo.sType )
155 if ( !_masterContainer.is() )
161 Reference< XPropertySet > xTable( _masterContainer->getByName( *_io_tableInfo.sComposedName ), UNO_QUERY_THROW );
162 OSL_VERIFY( xTable->getPropertyValue(
PROPERTY_TYPE ) >>= sTypeName );
172 const Sequence< OUString >& _tableFilter,
const Sequence< OUString >& _tableTypeFilter,
173 const Reference< XDatabaseMetaData >& _metaData,
const Reference< XNameAccess >& _masterContainer )
178 sal_Int32 nTableFilterCount = _tableFilter.getLength();
179 bool dontFilterTableNames = ( ( nTableFilterCount == 1 ) && _tableFilter[0] ==
"%" );
180 if( dontFilterTableNames )
182 aFilteredTables = std::move(_unfilteredTables);
188 std::vector< WildCard > aWildCardTableFilter;
189 Sequence< OUString > aNonWildCardTableFilter = _tableFilter;
192 TableInfos aUnfilteredTables( std::move(_unfilteredTables) );
193 aUnfilteredTables.reserve( nTableFilterCount + ( aWildCardTableFilter.size() * 10 ) );
195 for (
auto & unfilteredTable : aUnfilteredTables)
199 if (
lcl_isElementAllowed( *unfilteredTable.sComposedName, aNonWildCardTableFilter, aWildCardTableFilter ) )
200 aFilteredTables.push_back(unfilteredTable);
205 sal_Int32 nTableTypeFilterCount = _tableTypeFilter.getLength();
206 bool dontFilterTableTypes = ( ( nTableTypeFilterCount == 1 ) && _tableTypeFilter[0] ==
"%" );
207 dontFilterTableTypes = dontFilterTableTypes || ( nTableTypeFilterCount == 0 );
209 if ( !dontFilterTableTypes )
212 aUnfilteredTables.swap( aFilteredTables );
214 const OUString* pTableTypeFilterBegin = _tableTypeFilter.getConstArray();
215 const OUString* pTableTypeFilterEnd = pTableTypeFilterBegin + _tableTypeFilter.getLength();
217 for (
auto & unfilteredTable : aUnfilteredTables)
222 if ( std::find( pTableTypeFilterBegin, pTableTypeFilterEnd, *unfilteredTable.sType ) != pTableTypeFilterEnd )
223 aFilteredTables.push_back(unfilteredTable);
227 ::std::vector< OUString> aReturn;
228 for (
auto & filteredTable : aFilteredTables)
231 aReturn.push_back(*filteredTable.sComposedName);
238 ::osl::Mutex& _rMutex,
239 const Reference< XConnection >& _xCon,
242 std::atomic<std::size_t>& _nInAppend)
243 :OCollection(_rParent,_bCase,_rMutex,
std::vector< OUString>())
244 ,m_bConstructed(false)
245 ,m_pRefreshListener(_pRefreshListener)
246 ,m_nInAppend(_nInAppend)
252 const Sequence< OUString >& _rTableFilter,
253 const Sequence< OUString >& _rTableTypeFilter)
275 const OUString*
name = aNames.getConstArray();
276 const OUString* nameEnd =
name + aNames.getLength();
278 aUnfilteredTables.emplace_back( *name );
287 construct( _rTableFilter, _rTableTypeFilter );
294 Sequence< OUString > aTableFilter(_rTableFilter);
298 std::vector< WildCard > aWCSearch;
303 Reference< XConnection > xCon(
m_xConnection, UNO_SET_THROW );
304 m_xMetaData.set( xCon->getMetaData(), UNO_SET_THROW );
309 Sequence< OUString > aTableTypeFilter;
311 if ( !sInherentTableTypeRestriction.isEmpty() )
313 if ( _rTableTypeFilter.hasElements() )
315 const OUString* tableType = _rTableTypeFilter.getConstArray();
316 const OUString* tableTypeEnd = tableType + _rTableTypeFilter.getLength();
317 for ( ; tableType != tableTypeEnd; ++tableType )
319 if ( *tableType == sInherentTableTypeRestriction )
322 if ( tableType == tableTypeEnd )
329 aTableTypeFilter = { sInherentTableTypeRestriction };
334 if ( !_rTableTypeFilter.hasElements() )
340 aTableTypeFilter = _rTableTypeFilter;
344 static constexpr OUStringLiteral sAll =
u"%";
345 Reference< XResultSet > xTables =
m_xMetaData->getTables(
Any(), sAll, sAll, aTableTypeFilter );
346 Reference< XRow > xCurrentRow( xTables, UNO_QUERY_THROW );
351 while ( xTables->next() )
353 sCatalog = xCurrentRow->getString(1);
354 sSchema = xCurrentRow->getString(2);
355 sName = xCurrentRow->getString(3);
356 sType = xCurrentRow->getString(4);
362 _rTableFilter, aTableTypeFilter,
m_xMetaData,
nullptr ) );
366 catch (
const Exception&)
378 OCollection::disposing();
403 OSL_ENSURE( _xObject.is(),
"OFilteredContainer::getNameForObject: Object is NULL!" );
404 return ::dbtools::composeTableName(
m_xMetaData, _xObject, ::dbtools::EComposeRule::InDataManipulation,
false );
411 #define FILTER_MODE_STANDARD 0
413 #define FILTER_MODE_WILDCARD 1
415 #define FILTER_MODE_FIXED 2
418 #define FILTER_MODE_MIX_ALL 3
427 Any aFilterModeSetting;
430 OSL_VERIFY( aFilterModeSetting >>= nFilterMode );
433 static constexpr OUStringLiteral sAll(
u"%" );
434 static constexpr OUStringLiteral sView(
u"VIEW" );
435 static constexpr OUStringLiteral sTable(
u"TABLE" );
437 switch ( nFilterMode )
440 SAL_WARN(
"dbaccess",
"OTableContainer::getAllTableTypeFilter: unknown TableTypeFilterMode!" );
443 _rFilter = { sView, sTable, sAll };
446 _rFilter = { sView, sTable };
452 _rFilter.realloc( 0 );
OptionalString sComposedName
#define FILTER_MODE_WILDCARD
#define FILTER_MODE_MIX_ALL
#define FILTER_MODE_STANDARD
#define FILTER_MODE_FIXED
void reFill(const ::std::vector< OUString > &_rVector)
::cppu::OWeakObject & m_rParent
virtual void refresh(const css::uno::Reference< css::container::XNameAccess > &_rToBeRefreshed)=0
virtual void impl_refresh() override
virtual void removeMasterContainerListener()
IRefreshListener * m_pRefreshListener
virtual void addMasterContainerListener()
css::uno::Reference< css::container::XNameAccess > m_xMasterContainer
void getAllTableTypeFilter(css::uno::Sequence< OUString > &_rFilter) const
retrieve a table type filter to pass to <member scope="css::sdbc">XDatabaseMetaData::getTables</membe...
virtual OUString getNameForObject(const ::connectivity::sdbcx::ObjectType &_xObject) override
virtual void disposing() override
tell the container to free all elements and all additional resources.
css::uno::WeakReference< css::sdbc::XConnection > m_xConnection
css::uno::Reference< css::sdbc::XDatabaseMetaData > m_xMetaData
virtual OUString getTableTypeRestriction() const =0
returns a string denoting the only type of tables allowed in this container, or an empty string if th...
OFilteredContainer(::cppu::OWeakObject &_rParent, ::osl::Mutex &_rMutex, const css::uno::Reference< css::sdbc::XConnection > &_xCon, bool _bCase, IRefreshListener *_pRefreshListener, std::atomic< std::size_t > &_nInAppend)
ctor of the container.
void construct(const css::uno::Sequence< OUString > &_rTableFilter, const css::uno::Sequence< OUString > &_rTableTypeFilter)
late ctor.
#define DBG_UNHANDLED_EXCEPTION(...)
#define SAL_WARN(area, stream)
::std::optional< OUString > OptionalString
void disposeComponent(css::uno::Reference< TYPE > &_rxComp)
static bool lcl_isElementAllowed(const OUString &_rName, const Sequence< OUString > &_rTableFilter, const std::vector< WildCard > &_rWCSearch)
static void lcl_ensureComposedName(TableInfo &_io_tableInfo, const Reference< XDatabaseMetaData > &_metaData)
css::uno::Reference< css::uno::XInterface > getDataSource(const css::uno::Reference< css::uno::XInterface > &_rxDependentObject)
static void lcl_ensureType(TableInfo &_io_tableInfo, const Reference< XDatabaseMetaData > &_metaData, const Reference< XNameAccess > &_masterContainer)
::std::optional< OUString > OptionalString
static ::std::vector< OUString > lcl_filter(TableInfos &&_unfilteredTables, const Sequence< OUString > &_tableFilter, const Sequence< OUString > &_tableTypeFilter, const Reference< XDatabaseMetaData > &_metaData, const Reference< XNameAccess > &_masterContainer)
std::vector< TableInfo > TableInfos
static sal_Int32 createWildCardVector(Sequence< OUString > &_rTableFilter, std::vector< WildCard > &_rOut)
creates a vector of WildCards and reduce the _rTableFilter of the length of WildCards
Reference< XConnection > m_xConnection
constexpr OUStringLiteral PROPERTY_TYPE(u"Type")