30#include <core_resource.hxx>
32#include <com/sun/star/sdbcx/XTablesSupplier.hpp>
33#include <com/sun/star/sdbcx/KeyType.hpp>
34#include <com/sun/star/sdbcx/XKeysSupplier.hpp>
35#include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
36#include <com/sun/star/sdbc/SQLException.hpp>
37#include <com/sun/star/sdbc/XRow.hpp>
48#include <osl/thread.hxx>
49#include <osl/mutex.hxx>
53extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
55 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any>
const& )
57 return cppu::acquire(new ::dbaui::ORelationController(context));
72using namespace ::
dbaui;
76OUString SAL_CALL ORelationController::getImplementationName()
78 return "org.openoffice.comp.dbu.ORelationDesign";
83 return {
"com.sun.star.sdb.RelationDesign" };
89 ,m_bRelationsPossible(true)
104 case SID_RELATION_ADD_RELATION:
109 aReturn.
bEnabled = haveDataSource() && impl_isModified();
124 OSL_ENSURE(isEditable(),
"Slot ID_BROWSER_SAVEDOC should not be enabled!");
127 OUString aMessage(
DBA_RES(STR_DATASOURCE_DELETED));
152 case SID_RELATION_ADD_RELATION:
159 InvalidateFeature(_nId);
164 OJoinController::impl_initialize();
166 if( !getSdbMetaData().supportsRelations() )
172 OUString sTitle(
DBA_RES(STR_RELATIONDESIGN));
173 sTitle = sTitle.copy(3);
178 throw SQLException();
185 OSL_ENSURE(haveDataSource(),
"ORelationController::initialize: need a datasource!");
188 OSL_ENSURE(xSup.is(),
"Connection isn't a XTablesSupplier!");
208 OUString
sName = getDataSourceName();
215 OJoinController::Construct(pParent);
222 if(haveDataSource() && isModified())
224 std::unique_ptr<weld::Builder> xBuilder(
Application::CreateBuilder(getFrameWeld(),
"dbaccess/ui/designsavemodifieddialog.ui"));
225 std::unique_ptr<weld::MessageDialog> xQuery(xBuilder->weld_message_dialog(
"DesignSaveModifiedDialog"));
226 nSaved = xQuery->run();
236 implDescribeSupportedFeature(
".uno:DBAddRelation", SID_RELATION_ADD_RELATION, CommandGroup::EDIT );
241 class RelationLoader :
public ::osl::Thread
244 TTableDataHelper m_aTableData;
250 const sal_Int32 m_nStartIndex;
251 const sal_Int32 m_nEndIndex;
258 ,
const sal_Int32 _nStartIndex
259 ,
const sal_Int32 _nEndIndex)
260 :m_aTableData(_xMetaData.is() && _xMetaData->supportsMixedCaseQuotedIdentifiers())
263 ,m_xMetaData(_xMetaData)
265 ,m_nStartIndex(_nStartIndex)
266 ,m_nEndIndex(_nEndIndex)
271 virtual void SAL_CALL
run()
override;
272 virtual void SAL_CALL onTerminated()
override;
274 virtual ~RelationLoader()
override {}
276 void loadTableData(
const Any& _aTable);
279 void SAL_CALL RelationLoader::run()
281 osl_setThreadName(
"RelationLoader");
283 for(sal_Int32 i = m_nStartIndex;
i < m_nEndIndex; ++
i)
286 ::dbtools::qualifiedNameComponents(m_xMetaData,
291 ::dbtools::EComposeRule::InDataManipulation);
298 Reference< XResultSet > xResult = m_xMetaData->getImportedKeys(aCatalog,
sSchema,sTable);
299 if ( xResult.is() && xResult->next() )
301 ::comphelper::disposeComponent(xResult);
302 loadTableData(m_xTables->getByName(m_aTableList[i]));
305 catch(
const Exception& )
311 void SAL_CALL RelationLoader::onTerminated()
313 m_pParent->mergeData(m_vTableConnectionData);
317 void RelationLoader::loadTableData(
const Any& _aTable)
319 Reference<XPropertySet> xTableProp(_aTable,UNO_QUERY);
320 const OUString sSourceName = ::dbtools::composeTableName( m_xMetaData, xTableProp, ::dbtools::EComposeRule::InTableDefinitions,
false );
321 TTableDataHelper::const_iterator aFind = m_aTableData.find(sSourceName);
322 if ( aFind == m_aTableData.end() )
324 aFind = m_aTableData.emplace(sSourceName,std::make_shared<OTableWindowData>(xTableProp,sSourceName, sSourceName, OUString())).first;
325 aFind->second->ShowAll(
false);
327 TTableWindowData::value_type pReferencingTable = aFind->second;
328 Reference<XIndexAccess> xKeys = pReferencingTable->getKeys();
329 const Reference<XKeysSupplier> xKeySup(xTableProp,UNO_QUERY);
331 if ( !xKeys.is() && xKeySup.is() )
333 xKeys = xKeySup->getKeys();
339 Reference<XPropertySet> xKey;
340 const sal_Int32
nCount = xKeys->getCount();
341 for(sal_Int32 i = 0 ;
i <
nCount ; ++
i)
343 xKeys->getByIndex(i) >>= xKey;
344 sal_Int32 nKeyType = 0;
346 if ( KeyType::FOREIGN == nKeyType )
348 OUString sReferencedTable;
352 TTableDataHelper::const_iterator aRefFind = m_aTableData.find(sReferencedTable);
353 if ( aRefFind == m_aTableData.end() )
355 if ( m_xTables->hasByName(sReferencedTable) )
357 Reference<XPropertySet> xReferencedTable(m_xTables->getByName(sReferencedTable),UNO_QUERY);
358 aRefFind = m_aTableData.emplace(sReferencedTable,std::make_shared<OTableWindowData>(xReferencedTable,sReferencedTable, sReferencedTable, OUString())).first;
359 aRefFind->second->ShowAll(
false);
364 TTableWindowData::value_type pReferencedTable = aRefFind->second;
369 auto xTabConnData = std::make_shared<ORelationTableConnectionData>( pReferencingTable, pReferencedTable, sKeyName );
370 m_vTableConnectionData.push_back(xTabConnData);
372 const Reference<XColumnsSupplier> xColsSup(xKey,UNO_QUERY);
373 OSL_ENSURE(xColsSup.is(),
"Key is no XColumnsSupplier!");
374 const Reference<XNameAccess> xColumns = xColsSup->getColumns();
375 const Sequence< OUString> aNames = xColumns->getElementNames();
376 OUString sColumnName,sRelatedName;
377 for(sal_Int32 j=0;j<aNames.getLength();++j)
379 const Reference<XPropertySet> xPropSet(xColumns->getByName(aNames[j]),UNO_QUERY);
380 OSL_ENSURE(xPropSet.is(),
"Invalid column found in KeyColumns!");
386 xTabConnData->SetConnLine( j, sColumnName, sRelatedName );
389 sal_Int32 nUpdateRule = 0;
390 sal_Int32 nDeleteRule = 0;
394 xTabConnData->SetUpdateRules( nUpdateRule );
395 xTabConnData->SetDeleteRules( nDeleteRule );
398 xTabConnData->SetCardinality();
406 ::osl::MutexGuard aGuard(
getMutex() );
412 if ( !
existsTable(elem->getReferencingTable()->GetComposedName()) )
416 if ( !
existsTable(elem->getReferencedTable()->GetComposedName()) )
432 ::osl::MutexGuard aGuard(
getMutex() );
436 getView()->Invalidate(InvalidateFlags::NoErase);
440 if(m_vTableData.empty())
447 m_xWaitObject.reset();
461 const sal_Int32
nCount = aNames.getLength();
465 sal_Int32 nStart = 0,nEnd = std::min(nMaxElements,
nCount);
466 while(nStart != nEnd)
469 RelationLoader* pThread =
new RelationLoader(
this,xMetaData,
m_xTables,aNames,nStart,nEnd);
470 pThread->createSuspended();
471 pThread->setPriority(osl_Thread_PriorityBelowNormal);
474 nEnd += nMaxElements;
475 nEnd = std::min(nEnd,
nCount);
480 RelationLoader* pThread =
new RelationLoader(
this,xMetaData,
m_xTables,aNames,0,
nCount);
482 pThread->onTerminated();
485 catch(SQLException& e)
500 if(bCase(elem->GetComposedName(),_rComposedTableName))
503 return TTableWindowData::value_type();
510 OSL_ENSURE(haveDataSource(),
"We need a datasource from our connection!");
511 if ( haveDataSource() )
530 OSL_ENSURE(pView,
"No current view!");
std::array< RawFontData, NUM_TAGS > m_aTableList
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * org_openoffice_comp_dbu_ORelationDesign_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
#define ID_BROWSER_ADDTABLE
#define ID_BROWSER_SAVEDOC
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
static std::unique_ptr< weld::Builder > CreateBuilder(weld::Widget *pParent, const OUString &rUIFile, bool bMobile=false, sal_uInt64 nLOKWindowId=0)
css::uno::Sequence< css::beans::PropertyValue > getPropertyValues() const
virtual void initialize()
void loadTableWindows(const ::comphelper::NamedValueCollection &i_rViewSettings)
loads the information for the windows.
virtual void Execute(sal_uInt16 nId, const css::uno::Sequence< css::beans::PropertyValue > &aArgs) override
void saveTableWindows(::comphelper::NamedValueCollection &o_rViewSettings) const
saves the TableWindows structure in a sequence of property values
virtual FeatureState GetState(sal_uInt16 nId) const override
virtual void describeSupportedFeatures() override
TTableConnectionData m_vTableConnectionData
TTableWindowData m_vTableData
virtual bool Construct(vcl::Window *pParent) override
void mergeData(const TTableConnectionData &_aConnectionData)
virtual bool allowQueries() const override
determines whether or not it's allowed for queries to participate in the game
virtual void reset() override
virtual void describeSupportedFeatures() override
css::uno::Reference< css::container::XNameAccess > m_xTables
void loadLayoutInformation()
virtual bool allowViews() const override
determines whether or not it's allowed for database views to participate in the game
bool m_bRelationsPossible
virtual void impl_initialize() override
std::unique_ptr< weld::WaitObject > m_xWaitObject
virtual ~ORelationController() override
TTableWindowData::value_type existsTable(std::u16string_view _rComposedTableName) const
virtual short saveModified() override
virtual FeatureState GetState(sal_uInt16 nId) const override
virtual OUString getPrivateTitle() const override
virtual void Execute(sal_uInt16 nId, const css::uno::Sequence< css::beans::PropertyValue > &aArgs) override
void Invalidate(InvalidateFlags nFlags=InvalidateFlags::NONE)
#define DBG_UNHANDLED_EXCEPTION(...)
#define LINK(Instance, Class, Member)
def run(arg=None, arg2=-1)
css::uno::Reference< css::uno::XInterface > getDataSource(const css::uno::Reference< css::uno::XInterface > &_rxDependentObject)
IMPL_LINK_NOARG(OApplicationController, OnClipboardChanged, TransferableDataHelper *, void)
std::vector< std::shared_ptr< OTableConnectionData > > TTableConnectionData
bool checkDataSourceAvailable(const OUString &_sDataSourceName, const css::uno::Reference< css::uno::XComponentContext > &_rxContext)
checks if the given name exists in the database context
OUString getStrippedDatabaseName(const css::uno::Reference< css::beans::XPropertySet > &_xDataSource, OUString &_rsDatabaseName)
returns the stripped database name.
::osl::Mutex & getMutex()
SwView * getView(const uno::Reference< frame::XModel > &xModel)
bool getPropertyValue(ValueType &rValue, css::uno::Reference< css::beans::XPropertySet > const &xPropSet, OUString const &propName)
constexpr OUStringLiteral PROPERTY_UPDATERULE(u"UpdateRule")
constexpr OUStringLiteral PROPERTY_DELETERULE(u"DeleteRule")
constexpr OUStringLiteral PROPERTY_RELATEDCOLUMN(u"RelatedColumn")
constexpr OUStringLiteral PROPERTY_TYPE(u"Type")
constexpr OUStringLiteral PROPERTY_REFERENCEDTABLE(u"ReferencedTable")
constexpr OUStringLiteral PROPERTY_NAME(u"Name")
constexpr OUStringLiteral PROPERTY_LAYOUTINFORMATION(u"LayoutInformation")
describes the state of a feature
std::optional< bool > bChecked