Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : : #include "dbu_reghelper.hxx"
21 : : #include <sfx2/sfxsids.hrc>
22 : : #include "dbu_rel.hrc"
23 : : #include <vcl/svapp.hxx>
24 : : #include "browserids.hxx"
25 : : #include <comphelper/types.hxx>
26 : : #include "dbustrings.hrc"
27 : : #include <connectivity/dbtools.hxx>
28 : : #include <com/sun/star/frame/FrameSearchFlag.hpp>
29 : : #include <comphelper/extract.hxx>
30 : : #include <com/sun/star/container/XChild.hpp>
31 : : #include <com/sun/star/container/XNameContainer.hpp>
32 : : #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
33 : : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
34 : : #include <com/sun/star/sdbcx/KeyType.hpp>
35 : : #include <com/sun/star/sdbcx/XDrop.hpp>
36 : : #include <com/sun/star/sdbcx/XAlterTable.hpp>
37 : : #include <com/sun/star/sdbcx/XAppend.hpp>
38 : : #include <com/sun/star/sdbcx/XKeysSupplier.hpp>
39 : : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
40 : : #include <com/sun/star/sdb/SQLContext.hpp>
41 : : #include <com/sun/star/sdbc/SQLWarning.hpp>
42 : : #include <com/sun/star/sdbc/ColumnValue.hpp>
43 : : #include <com/sun/star/sdbc/XRow.hpp>
44 : : #include <connectivity/dbexception.hxx>
45 : : #include <connectivity/dbmetadata.hxx>
46 : : #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
47 : : #include <comphelper/streamsection.hxx>
48 : : #include <comphelper/basicio.hxx>
49 : : #include <comphelper/seqstream.hxx>
50 : : #include <com/sun/star/io/XActiveDataSource.hpp>
51 : : #include <com/sun/star/io/XActiveDataSink.hpp>
52 : : #include "sqlmessage.hxx"
53 : : #include "RelationController.hxx"
54 : : #include <vcl/msgbox.hxx>
55 : : #include "TableWindowData.hxx"
56 : : #include "UITools.hxx"
57 : : #include "RTableConnectionData.hxx"
58 : : #include "RelationTableView.hxx"
59 : : #include "RelationDesignView.hxx"
60 : : #include <tools/debug.hxx>
61 : : #include <tools/diagnose_ex.h>
62 : : #include <vcl/waitobj.hxx>
63 : : #include <osl/thread.hxx>
64 : : #include <osl/mutex.hxx>
65 : :
66 : :
67 : : #define MAX_THREADS 10
68 : :
69 : 8 : extern "C" void SAL_CALL createRegistryInfo_ORelationControl()
70 : : {
71 [ + - ][ + - ]: 8 : static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::ORelationController > aAutoRegistration;
[ + - ][ # # ]
72 : 8 : }
73 : :
74 : :
75 : : using namespace ::com::sun::star::uno;
76 : : using namespace ::com::sun::star::io;
77 : : using namespace ::com::sun::star::beans;
78 : : using namespace ::com::sun::star::frame;
79 : : using namespace ::com::sun::star::util;
80 : : using namespace ::com::sun::star::lang;
81 : : using namespace ::com::sun::star::container;
82 : : using namespace ::com::sun::star::sdbcx;
83 : : using namespace ::com::sun::star::sdbc;
84 : : using namespace ::com::sun::star::sdb;
85 : : using namespace ::com::sun::star::ui::dialogs;
86 : : using namespace ::com::sun::star::util;
87 : : using namespace ::dbtools;
88 : : using namespace ::dbaui;
89 : : using namespace ::comphelper;
90 : : using namespace ::osl;
91 : :
92 : : //------------------------------------------------------------------------------
93 : 0 : ::rtl::OUString SAL_CALL ORelationController::getImplementationName() throw( RuntimeException )
94 : : {
95 : 0 : return getImplementationName_Static();
96 : : }
97 : :
98 : : //------------------------------------------------------------------------------
99 : 16 : ::rtl::OUString ORelationController::getImplementationName_Static() throw( RuntimeException )
100 : : {
101 : 16 : return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.comp.dbu.ORelationDesign"));
102 : : }
103 : : //------------------------------------------------------------------------------
104 : 8 : Sequence< ::rtl::OUString> ORelationController::getSupportedServiceNames_Static(void) throw( RuntimeException )
105 : : {
106 : 8 : Sequence< ::rtl::OUString> aSupported(1);
107 [ + - ][ + - ]: 8 : aSupported.getArray()[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.RelationDesign"));
108 : 8 : return aSupported;
109 : : }
110 : : //-------------------------------------------------------------------------
111 : 0 : Sequence< ::rtl::OUString> SAL_CALL ORelationController::getSupportedServiceNames() throw(RuntimeException)
112 : : {
113 : 0 : return getSupportedServiceNames_Static();
114 : : }
115 : : // -------------------------------------------------------------------------
116 : 0 : Reference< XInterface > SAL_CALL ORelationController::Create(const Reference<XMultiServiceFactory >& _rxFactory)
117 : : {
118 [ # # ]: 0 : return *(new ORelationController(_rxFactory));
119 : : }
120 : : DBG_NAME(ORelationController);
121 : : // -----------------------------------------------------------------------------
122 : 0 : ORelationController::ORelationController(const Reference< XMultiServiceFactory >& _rM)
123 : : : OJoinController(_rM)
124 : : ,m_nThreadEvent(0)
125 : 0 : ,m_bRelationsPossible(sal_True)
126 : : {
127 : : DBG_CTOR(ORelationController,NULL);
128 [ # # ]: 0 : InvalidateAll();
129 : 0 : }
130 : : // -----------------------------------------------------------------------------
131 [ # # ]: 0 : ORelationController::~ORelationController()
132 : : {
133 : : DBG_DTOR(ORelationController,NULL);
134 [ # # ]: 0 : }
135 : : // -----------------------------------------------------------------------------
136 : 0 : FeatureState ORelationController::GetState(sal_uInt16 _nId) const
137 : : {
138 : 0 : FeatureState aReturn;
139 : 0 : aReturn.bEnabled = m_bRelationsPossible;
140 [ # # # ]: 0 : switch (_nId)
141 : : {
142 : : case SID_RELATION_ADD_RELATION:
143 [ # # ][ # # ]: 0 : aReturn.bEnabled = !m_vTableData.empty() && isConnected() && isEditable();
[ # # ][ # # ]
[ # # ]
144 [ # # ]: 0 : aReturn.bChecked = false;
145 : 0 : break;
146 : : case ID_BROWSER_SAVEDOC:
147 [ # # ][ # # ]: 0 : aReturn.bEnabled = haveDataSource() && impl_isModified();
[ # # ][ # # ]
148 : 0 : break;
149 : : default:
150 [ # # ][ # # ]: 0 : aReturn = OJoinController::GetState(_nId);
[ # # ]
151 : 0 : break;
152 : : }
153 : 0 : return aReturn;
154 : : }
155 : : // -----------------------------------------------------------------------------
156 : 0 : void ORelationController::Execute(sal_uInt16 _nId, const Sequence< PropertyValue >& aArgs)
157 : : {
158 [ # # # ]: 0 : switch(_nId)
159 : : {
160 : : case ID_BROWSER_SAVEDOC:
161 : : {
162 : : OSL_ENSURE(isEditable(),"Slot ID_BROWSER_SAVEDOC should not be enabled!");
163 [ # # ][ # # ]: 0 : if(!::dbaui::checkDataSourceAvailable(::comphelper::getString(getDataSource()->getPropertyValue(PROPERTY_NAME)),getORB()))
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
164 : : {
165 [ # # ][ # # ]: 0 : String aMessage(ModuleRes(STR_DATASOURCE_DELETED));
166 [ # # ][ # # ]: 0 : OSQLWarningBox( getView(), aMessage ).Execute();
[ # # ][ # # ]
167 : : }
168 : : else
169 : : {
170 : : // now we save the layout information
171 : : // create the output stream
172 : : try
173 : : {
174 [ # # ][ # # ]: 0 : if ( haveDataSource() && getDataSource()->getPropertySetInfo()->hasPropertyByName(PROPERTY_LAYOUTINFORMATION) )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # #
# # # # ]
175 : : {
176 [ # # ]: 0 : ::comphelper::NamedValueCollection aWindowsData;
177 [ # # ]: 0 : saveTableWindows( aWindowsData );
178 [ # # ][ # # ]: 0 : getDataSource()->setPropertyValue( PROPERTY_LAYOUTINFORMATION, makeAny( aWindowsData.getPropertyValues() ) );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
179 [ # # ][ # # ]: 0 : setModified(sal_False);
[ # # ]
180 : : }
181 : : }
182 : 0 : catch ( const Exception& )
183 : : {
184 : : DBG_UNHANDLED_EXCEPTION();
185 : : }
186 : : }
187 : : }
188 : 0 : break;
189 : : case SID_RELATION_ADD_RELATION:
190 : 0 : static_cast<ORelationTableView*>(static_cast<ORelationDesignView*>( getView() )->getTableView())->AddNewRelation();
191 : 0 : break;
192 : : default:
193 : 0 : OJoinController::Execute(_nId,aArgs);
194 : 0 : return;
195 : : }
196 [ # # ]: 0 : InvalidateFeature(_nId);
197 : : }
198 : : // -----------------------------------------------------------------------------
199 : 0 : void ORelationController::impl_initialize()
200 : : {
201 [ # # ]: 0 : OJoinController::impl_initialize();
202 : :
203 [ # # ][ # # ]: 0 : if( !getSdbMetaData().supportsRelations() )
[ # # ]
204 : : {// check if this database supports relations
205 : :
206 [ # # ]: 0 : setEditable(sal_False);
207 : 0 : m_bRelationsPossible = sal_False;
208 : : {
209 [ # # ][ # # ]: 0 : String sTitle(ModuleRes(STR_RELATIONDESIGN));
210 [ # # ]: 0 : sTitle.Erase(0,3);
211 [ # # ][ # # ]: 0 : OSQLMessageBox aDlg(NULL,sTitle,ModuleRes(STR_RELATIONDESIGN_NOT_AVAILABLE));
[ # # ][ # # ]
212 [ # # ][ # # ]: 0 : aDlg.Execute();
[ # # ]
213 : : }
214 [ # # ]: 0 : disconnect();
215 [ # # ]: 0 : throw SQLException();
216 : : }
217 : :
218 [ # # ]: 0 : if(!m_bRelationsPossible)
219 [ # # ]: 0 : InvalidateAll();
220 : :
221 : : // we need a datasource
222 : : OSL_ENSURE(haveDataSource(),"ORelationController::initialize: need a datasource!");
223 : :
224 [ # # ][ # # ]: 0 : Reference<XTablesSupplier> xSup(getConnection(),UNO_QUERY);
225 : : OSL_ENSURE(xSup.is(),"Connection isn't a XTablesSupplier!");
226 [ # # ]: 0 : if(xSup.is())
227 [ # # ][ # # ]: 0 : m_xTables = xSup->getTables();
[ # # ]
228 : : // load the layoutInformation
229 [ # # ]: 0 : loadLayoutInformation();
230 : : try
231 : : {
232 [ # # ]: 0 : loadData();
233 [ # # ]: 0 : if ( !m_nThreadEvent )
234 [ # # ][ # # ]: 0 : Application::PostUserEvent(LINK(this, ORelationController, OnThreadFinished));
[ # # ]
235 : : }
236 [ # # ]: 0 : catch( const Exception& )
237 : : {
238 : : DBG_UNHANDLED_EXCEPTION();
239 : 0 : }
240 : :
241 : 0 : }
242 : : // -----------------------------------------------------------------------------
243 : 0 : ::rtl::OUString ORelationController::getPrivateTitle( ) const
244 : : {
245 [ # # ]: 0 : ::rtl::OUString sName = getDataSourceName();
246 [ # # ][ # # ]: 0 : return ::dbaui::getStrippedDatabaseName(getDataSource(),sName);
247 : : }
248 : : // -----------------------------------------------------------------------------
249 : 0 : sal_Bool ORelationController::Construct(Window* pParent)
250 : : {
251 [ # # ][ # # ]: 0 : setView( * new ORelationDesignView( pParent, *this, getORB() ) );
252 : 0 : OJoinController::Construct(pParent);
253 : 0 : return sal_True;
254 : : }
255 : : // -----------------------------------------------------------------------------
256 : 0 : short ORelationController::saveModified()
257 : : {
258 : 0 : short nSaved = RET_YES;
259 [ # # ][ # # ]: 0 : if(haveDataSource() && isModified())
[ # # ]
260 : : {
261 [ # # ][ # # ]: 0 : QueryBox aQry(getView(), ModuleRes(RELATION_DESIGN_SAVEMODIFIED));
262 [ # # ]: 0 : nSaved = aQry.Execute();
263 [ # # ]: 0 : if(nSaved == RET_YES)
264 [ # # ][ # # ]: 0 : Execute(ID_BROWSER_SAVEDOC,Sequence<PropertyValue>());
[ # # ][ # # ]
265 : : }
266 : 0 : return nSaved;
267 : : }
268 : : // -----------------------------------------------------------------------------
269 : 0 : void ORelationController::describeSupportedFeatures()
270 : : {
271 : 0 : OJoinController::describeSupportedFeatures();
272 : 0 : implDescribeSupportedFeature( ".uno:DBAddRelation", SID_RELATION_ADD_RELATION, CommandGroup::EDIT );
273 : 0 : }
274 : : namespace
275 : : {
276 : : class RelationLoader : public ::osl::Thread
277 : : {
278 : : DECLARE_STL_MAP(::rtl::OUString,::boost::shared_ptr<OTableWindowData>,::comphelper::UStringMixLess,TTableDataHelper);
279 : : TTableDataHelper m_aTableData;
280 : : TTableConnectionData m_vTableConnectionData;
281 : : const Sequence< ::rtl::OUString> m_aTableList;
282 : : ORelationController* m_pParent;
283 : : const Reference< XDatabaseMetaData> m_xMetaData;
284 : : const Reference< XNameAccess > m_xTables;
285 : : const sal_Int32 m_nStartIndex;
286 : : const sal_Int32 m_nEndIndex;
287 : :
288 : : public:
289 : 0 : RelationLoader(ORelationController* _pParent
290 : : ,const Reference< XDatabaseMetaData>& _xMetaData
291 : : ,const Reference< XNameAccess >& _xTables
292 : : ,const Sequence< ::rtl::OUString>& _aTableList
293 : : ,const sal_Int32 _nStartIndex
294 : : ,const sal_Int32 _nEndIndex)
295 [ # # ][ # # ]: 0 : :m_aTableData(_xMetaData.is() && _xMetaData->supportsMixedCaseQuotedIdentifiers())
296 : : ,m_aTableList(_aTableList)
297 : : ,m_pParent(_pParent)
298 : : ,m_xMetaData(_xMetaData)
299 : : ,m_xTables(_xTables)
300 : : ,m_nStartIndex(_nStartIndex)
301 [ # # ][ # # ]: 0 : ,m_nEndIndex(_nEndIndex)
[ # # ][ # # ]
[ # # ]
302 : : {
303 : 0 : }
304 : :
305 : : /// Working method which should be overridden.
306 : : virtual void SAL_CALL run();
307 : : virtual void SAL_CALL onTerminated();
308 : : protected:
309 [ # # ][ # # ]: 0 : virtual ~RelationLoader(){}
310 : :
311 : : void loadTableData(const Any& _aTable);
312 : : };
313 : :
314 : 0 : void SAL_CALL RelationLoader::run()
315 : : {
316 : 0 : const ::rtl::OUString* pIter = m_aTableList.getConstArray() + m_nStartIndex;
317 [ # # ]: 0 : for(sal_Int32 i = m_nStartIndex; i < m_nEndIndex;++i,++pIter)
318 : : {
319 : 0 : ::rtl::OUString sCatalog,sSchema,sTable;
320 : : ::dbtools::qualifiedNameComponents(m_xMetaData,
321 : : *pIter,
322 : : sCatalog,
323 : : sSchema,
324 : : sTable,
325 [ # # ]: 0 : ::dbtools::eInDataManipulation);
326 : 0 : Any aCatalog;
327 [ # # ]: 0 : if ( !sCatalog.isEmpty() )
328 [ # # ]: 0 : aCatalog <<= sCatalog;
329 : :
330 : : try
331 : : {
332 [ # # ][ # # ]: 0 : Reference< XResultSet > xResult = m_xMetaData->getImportedKeys(aCatalog, sSchema,sTable);
333 [ # # ][ # # ]: 0 : if ( xResult.is() && xResult->next() )
[ # # ][ # # ]
[ # # ]
334 : : {
335 [ # # ]: 0 : ::comphelper::disposeComponent(xResult);
336 [ # # ][ # # ]: 0 : loadTableData(m_xTables->getByName(*pIter));
[ # # ]
337 [ # # ]: 0 : }
338 : : }
339 [ # # ]: 0 : catch( const Exception& )
340 : : {
341 : : DBG_UNHANDLED_EXCEPTION();
342 : : }
343 : 0 : }
344 : 0 : }
345 : 0 : void SAL_CALL RelationLoader::onTerminated()
346 : : {
347 : 0 : m_pParent->mergeData(m_vTableConnectionData);
348 [ # # ]: 0 : delete this;
349 : 0 : }
350 : :
351 : 0 : void RelationLoader::loadTableData(const Any& _aTable)
352 : : {
353 [ # # ]: 0 : Reference<XPropertySet> xTableProp(_aTable,UNO_QUERY);
354 [ # # ]: 0 : const ::rtl::OUString sSourceName = ::dbtools::composeTableName( m_xMetaData, xTableProp, ::dbtools::eInTableDefinitions, false, false, false );
355 [ # # ]: 0 : TTableDataHelper::iterator aFind = m_aTableData.find(sSourceName);
356 [ # # ]: 0 : if ( aFind == m_aTableData.end() )
357 : : {
358 [ # # ][ # # ]: 0 : aFind = m_aTableData.insert(TTableDataHelper::value_type(sSourceName,::boost::shared_ptr<OTableWindowData>(new OTableWindowData(xTableProp,sSourceName, sSourceName)))).first;
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
359 : 0 : aFind->second->ShowAll(sal_False);
360 : : }
361 [ # # ]: 0 : TTableWindowData::value_type pReferencingTable = aFind->second;
362 [ # # ]: 0 : Reference<XIndexAccess> xKeys = pReferencingTable->getKeys();
363 [ # # ]: 0 : const Reference<XKeysSupplier> xKeySup(xTableProp,UNO_QUERY);
364 : :
365 [ # # ][ # # ]: 0 : if ( !xKeys.is() && xKeySup.is() )
[ # # ]
366 : : {
367 [ # # ][ # # ]: 0 : xKeys = xKeySup->getKeys();
[ # # ]
368 : : }
369 : :
370 [ # # ]: 0 : if ( xKeys.is() )
371 : : {
372 : 0 : Reference<XPropertySet> xKey;
373 [ # # ][ # # ]: 0 : const sal_Int32 nCount = xKeys->getCount();
374 [ # # ]: 0 : for(sal_Int32 i = 0 ; i < nCount ; ++i)
375 : : {
376 [ # # ][ # # ]: 0 : xKeys->getByIndex(i) >>= xKey;
[ # # ]
377 : 0 : sal_Int32 nKeyType = 0;
378 [ # # ][ # # ]: 0 : xKey->getPropertyValue(PROPERTY_TYPE) >>= nKeyType;
[ # # ]
379 [ # # ]: 0 : if ( KeyType::FOREIGN == nKeyType )
380 : : {
381 : 0 : ::rtl::OUString sReferencedTable;
382 [ # # ][ # # ]: 0 : xKey->getPropertyValue(PROPERTY_REFERENCEDTABLE) >>= sReferencedTable;
[ # # ]
383 : : //////////////////////////////////////////////////////////////////////
384 : : // insert windows
385 [ # # ]: 0 : TTableDataHelper::iterator aRefFind = m_aTableData.find(sReferencedTable);
386 [ # # ]: 0 : if ( aRefFind == m_aTableData.end() )
387 : : {
388 [ # # ][ # # ]: 0 : if ( m_xTables->hasByName(sReferencedTable) )
[ # # ]
389 : : {
390 [ # # ][ # # ]: 0 : Reference<XPropertySet> xReferencedTable(m_xTables->getByName(sReferencedTable),UNO_QUERY);
[ # # ]
391 [ # # ][ # # ]: 0 : aRefFind = m_aTableData.insert(TTableDataHelper::value_type(sReferencedTable,::boost::shared_ptr<OTableWindowData>(new OTableWindowData(xReferencedTable,sReferencedTable, sReferencedTable)))).first;
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
392 : 0 : aRefFind->second->ShowAll(sal_False);
393 : : }
394 : : else
395 : 0 : continue; // table name could not be found so we do not show this table releation
396 : : }
397 [ # # ]: 0 : TTableWindowData::value_type pReferencedTable = aRefFind->second;
398 : :
399 : 0 : ::rtl::OUString sKeyName;
400 [ # # ][ # # ]: 0 : xKey->getPropertyValue(PROPERTY_NAME) >>= sKeyName;
[ # # ]
401 : : //////////////////////////////////////////////////////////////////////
402 : : // insert connection
403 [ # # ][ # # ]: 0 : ORelationTableConnectionData* pTabConnData = new ORelationTableConnectionData( pReferencingTable, pReferencedTable, sKeyName );
404 [ # # ][ # # ]: 0 : m_vTableConnectionData.push_back(TTableConnectionData::value_type(pTabConnData));
[ # # ]
405 : : //////////////////////////////////////////////////////////////////////
406 : : // insert columns
407 [ # # ]: 0 : const Reference<XColumnsSupplier> xColsSup(xKey,UNO_QUERY);
408 : : OSL_ENSURE(xColsSup.is(),"Key is no XColumnsSupplier!");
409 [ # # ][ # # ]: 0 : const Reference<XNameAccess> xColumns = xColsSup->getColumns();
410 [ # # ][ # # ]: 0 : const Sequence< ::rtl::OUString> aNames = xColumns->getElementNames();
411 : 0 : const ::rtl::OUString* pIter = aNames.getConstArray();
412 : 0 : const ::rtl::OUString* pEnd = pIter + aNames.getLength();
413 : 0 : ::rtl::OUString sColumnName,sRelatedName;
414 [ # # ]: 0 : for(sal_uInt16 j=0;pIter != pEnd;++pIter,++j)
415 : : {
416 [ # # ][ # # ]: 0 : const Reference<XPropertySet> xPropSet(xColumns->getByName(*pIter),UNO_QUERY);
[ # # ]
417 : : OSL_ENSURE(xPropSet.is(),"Invalid column found in KeyColumns!");
418 [ # # ]: 0 : if ( xPropSet.is() )
419 : : {
420 [ # # ][ # # ]: 0 : xPropSet->getPropertyValue(PROPERTY_NAME) >>= sColumnName;
[ # # ]
421 [ # # ][ # # ]: 0 : xPropSet->getPropertyValue(PROPERTY_RELATEDCOLUMN) >>= sRelatedName;
[ # # ]
422 : : }
423 [ # # ][ # # ]: 0 : pTabConnData->SetConnLine( j, sColumnName, sRelatedName );
[ # # ][ # # ]
[ # # ]
424 : 0 : }
425 : : //////////////////////////////////////////////////////////////////////
426 : : // Update/Del-Flags setzen
427 : 0 : sal_Int32 nUpdateRule = 0;
428 : 0 : sal_Int32 nDeleteRule = 0;
429 [ # # ][ # # ]: 0 : xKey->getPropertyValue(PROPERTY_UPDATERULE) >>= nUpdateRule;
[ # # ]
430 [ # # ][ # # ]: 0 : xKey->getPropertyValue(PROPERTY_DELETERULE) >>= nDeleteRule;
[ # # ]
431 : :
432 : 0 : pTabConnData->SetUpdateRules( nUpdateRule );
433 : 0 : pTabConnData->SetDeleteRules( nDeleteRule );
434 : :
435 : : //////////////////////////////////////////////////////////////////////
436 : : // Kardinalitaet setzen
437 [ # # ][ # # ]: 0 : pTabConnData->SetCardinality();
[ # # ][ # # ]
438 : : }
439 : 0 : }
440 [ # # ]: 0 : }
441 : 0 : }
442 : : }
443 : :
444 : 0 : void ORelationController::mergeData(const TTableConnectionData& _aConnectionData)
445 : : {
446 [ # # ][ # # ]: 0 : ::osl::MutexGuard aGuard( getMutex() );
447 : :
448 [ # # ][ # # ]: 0 : ::std::copy( _aConnectionData.begin(), _aConnectionData.end(), ::std::back_inserter( m_vTableConnectionData ));
449 : : //const Reference< XDatabaseMetaData> xMetaData = getConnection()->getMetaData();
450 : 0 : const sal_Bool bCase = sal_True;//xMetaData.is() && xMetaData->supportsMixedCaseQuotedIdentifiers();
451 : : // here we are finished, so we can collect the table from connection data
452 : 0 : TTableConnectionData::iterator aConnDataIter = m_vTableConnectionData.begin();
453 : 0 : TTableConnectionData::iterator aConnDataEnd = m_vTableConnectionData.end();
454 [ # # ][ # # ]: 0 : for(;aConnDataIter != aConnDataEnd;++aConnDataIter)
455 : : {
456 [ # # ][ # # ]: 0 : if ( !existsTable((*aConnDataIter)->getReferencingTable()->GetComposedName(),bCase) )
[ # # ][ # # ]
[ # # ]
457 : : {
458 [ # # ][ # # ]: 0 : m_vTableData.push_back((*aConnDataIter)->getReferencingTable());
[ # # ]
459 : : }
460 [ # # ][ # # ]: 0 : if ( !existsTable((*aConnDataIter)->getReferencedTable()->GetComposedName(),bCase) )
[ # # ][ # # ]
[ # # ]
461 : : {
462 [ # # ][ # # ]: 0 : m_vTableData.push_back((*aConnDataIter)->getReferencedTable());
[ # # ]
463 : : }
464 : : }
465 [ # # ]: 0 : if ( m_nThreadEvent )
466 : : {
467 : 0 : --m_nThreadEvent;
468 [ # # ]: 0 : if ( !m_nThreadEvent )
469 [ # # ][ # # ]: 0 : Application::PostUserEvent(LINK(this, ORelationController, OnThreadFinished));
470 [ # # ]: 0 : }
471 : 0 : }
472 : : // -----------------------------------------------------------------------------
473 : 0 : IMPL_LINK( ORelationController, OnThreadFinished, void*, /*NOTINTERESTEDIN*/ )
474 : : {
475 [ # # ]: 0 : ::SolarMutexGuard aSolarGuard;
476 [ # # ][ # # ]: 0 : ::osl::MutexGuard aGuard( getMutex() );
477 : : try
478 : : {
479 [ # # ]: 0 : getView()->initialize(); // show the windows and fill with our informations
480 [ # # ]: 0 : getView()->Invalidate(INVALIDATE_NOERASE);
481 [ # # ]: 0 : ClearUndoManager();
482 [ # # ]: 0 : setModified(sal_False); // and we are not modified yet
483 : :
484 [ # # ]: 0 : if(m_vTableData.empty())
485 [ # # ][ # # ]: 0 : Execute(ID_BROWSER_ADDTABLE,Sequence<PropertyValue>());
[ # # ][ # # ]
486 : : }
487 [ # # ]: 0 : catch( const Exception& )
488 : : {
489 : : DBG_UNHANDLED_EXCEPTION();
490 : : }
491 : 0 : m_pWaitObject.reset();
492 [ # # ][ # # ]: 0 : return 0L;
493 : : }
494 : : // -----------------------------------------------------------------------------
495 : 0 : void ORelationController::loadData()
496 : : {
497 [ # # ]: 0 : m_pWaitObject.reset( new WaitObject(getView()) );
498 : : try
499 : : {
500 [ # # ]: 0 : if ( !m_xTables.is() )
501 : 0 : return;
502 [ # # ][ # # ]: 0 : DatabaseMetaData aMeta(getConnection());
503 : : // this may take some time
504 [ # # ][ # # ]: 0 : const Reference< XDatabaseMetaData> xMetaData = getConnection()->getMetaData();
[ # # ]
505 [ # # ][ # # ]: 0 : const Sequence< ::rtl::OUString> aNames = m_xTables->getElementNames();
506 : 0 : const sal_Int32 nCount = aNames.getLength();
507 [ # # ][ # # ]: 0 : if ( aMeta.supportsThreads() )
508 : : {
509 : 0 : const sal_Int32 nMaxElements = (nCount / MAX_THREADS) +1;
510 [ # # ]: 0 : sal_Int32 nStart = 0,nEnd = ::std::min(nMaxElements,nCount);
511 [ # # ]: 0 : while(nStart != nEnd)
512 : : {
513 : 0 : ++m_nThreadEvent;
514 [ # # ]: 0 : RelationLoader* pThread = new RelationLoader(this,xMetaData,m_xTables,aNames,nStart,nEnd);
515 [ # # ]: 0 : pThread->createSuspended();
516 [ # # ]: 0 : pThread->setPriority(osl_Thread_PriorityBelowNormal);
517 [ # # ]: 0 : pThread->resume();
518 : 0 : nStart = nEnd;
519 : 0 : nEnd += nMaxElements;
520 [ # # ]: 0 : nEnd = ::std::min(nEnd,nCount);
521 : : }
522 : : }
523 : : else
524 : : {
525 [ # # ]: 0 : RelationLoader* pThread = new RelationLoader(this,xMetaData,m_xTables,aNames,0,nCount);
526 [ # # ]: 0 : pThread->run();
527 [ # # ]: 0 : pThread->onTerminated();
528 [ # # ][ # # ]: 0 : }
529 : : }
530 [ # # # ]: 0 : catch(SQLException& e)
531 : : {
532 [ # # # # : 0 : showError(SQLExceptionInfo(e));
# # ]
533 : : }
534 : 0 : catch(const Exception&)
535 : : {
536 : : DBG_UNHANDLED_EXCEPTION();
537 : : }
538 : : }
539 : : // -----------------------------------------------------------------------------
540 : 0 : TTableWindowData::value_type ORelationController::existsTable(const ::rtl::OUString& _rComposedTableName,sal_Bool _bCase) const
541 : : {
542 : 0 : ::comphelper::UStringMixEqual bCase(_bCase);
543 : 0 : TTableWindowData::const_iterator aIter = m_vTableData.begin();
544 : 0 : TTableWindowData::const_iterator aEnd = m_vTableData.end();
545 [ # # ][ # # ]: 0 : for(;aIter != aEnd;++aIter)
546 : : {
547 [ # # ]: 0 : if(bCase((*aIter)->GetComposedName(),_rComposedTableName))
548 : 0 : break;
549 : : }
550 [ # # ][ # # ]: 0 : return ( aIter != aEnd) ? *aIter : TTableWindowData::value_type();
[ # # ][ # # ]
551 : : }
552 : : // -----------------------------------------------------------------------------
553 : 0 : void ORelationController::loadLayoutInformation()
554 : : {
555 : : try
556 : : {
557 : : OSL_ENSURE(haveDataSource(),"We need a datasource from our connection!");
558 [ # # ][ # # ]: 0 : if ( haveDataSource() )
559 : : {
560 [ # # ][ # # ]: 0 : if ( getDataSource()->getPropertySetInfo()->hasPropertyByName(PROPERTY_LAYOUTINFORMATION) )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
561 : : {
562 [ # # ]: 0 : Sequence<PropertyValue> aWindows;
563 [ # # ][ # # ]: 0 : getDataSource()->getPropertyValue(PROPERTY_LAYOUTINFORMATION) >>= aWindows;
[ # # ][ # # ]
[ # # ]
564 [ # # ][ # # ]: 0 : loadTableWindows(aWindows);
[ # # ][ # # ]
[ # # ]
565 : : }
566 : : }
567 : : }
568 : 0 : catch(Exception&)
569 : : {
570 : : }
571 : 0 : }
572 : : // -----------------------------------------------------------------------------
573 : 0 : void ORelationController::reset()
574 : : {
575 : 0 : loadLayoutInformation();
576 : 0 : ODataView* pView = getView();
577 : : OSL_ENSURE(pView,"No current view!");
578 [ # # ]: 0 : if(pView)
579 : : {
580 : 0 : pView->initialize();
581 : 0 : pView->Invalidate(INVALIDATE_NOERASE);
582 : : }
583 : 0 : }
584 : :
585 : : // -----------------------------------------------------------------------------
586 : 0 : bool ORelationController::allowViews() const
587 : : {
588 : 0 : return false;
589 : : }
590 : :
591 : : // -----------------------------------------------------------------------------
592 : 0 : bool ORelationController::allowQueries() const
593 : : {
594 : 0 : return false;
595 : : }
596 : :
597 : : // -----------------------------------------------------------------------------
598 : :
599 : :
600 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|