dba33f: don't ask every driver for a tables keys and consolidate some code fragments
This commit is contained in:
@@ -1108,7 +1108,11 @@ SvLBoxEntry* SbaTableQueryBrowser::getObjectEntry(const ::rtl::OUString& _rDataS
|
||||
{
|
||||
// expand if required so
|
||||
if (_bExpandAncestors)
|
||||
{
|
||||
m_sToBeLoaded = _rCommand;
|
||||
m_pTreeView->getListBox().Expand(pCommandType);
|
||||
m_sToBeLoaded = ::rtl::OUString();
|
||||
}
|
||||
|
||||
// look for the object
|
||||
::rtl::OUString sCommand = _rCommand;
|
||||
@@ -2057,7 +2061,7 @@ void SbaTableQueryBrowser::populateTree(const Reference<XNameAccess>& _xNameAcce
|
||||
const ::rtl::OUString* pEnd = pIter + aNames.getLength();
|
||||
for (; pIter != pEnd; ++pIter)
|
||||
{
|
||||
if(!m_pTreeView->getListBox().GetEntryPosByName(*pIter,_pParent))
|
||||
if( (!m_sToBeLoaded.getLength() || m_sToBeLoaded == *pIter) && !m_pTreeView->getListBox().GetEntryPosByName(*pIter,_pParent))
|
||||
{
|
||||
Reference<XNameAccess> xChild(_xNameAccess->getByName(*pIter),UNO_QUERY);
|
||||
DBTreeListUserData* pEntryData = new DBTreeListUserData;
|
||||
|
@@ -64,9 +64,9 @@ namespace dbaui
|
||||
sal_Int32 m_nDeleteRules;
|
||||
sal_Int32 m_nCardinality;
|
||||
|
||||
BOOL checkPrimaryKey(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess>& _xKeys,EConnectionSide _eEConnectionSide) const;
|
||||
BOOL IsSourcePrimKey() const { return checkPrimaryKey(getReferencingTable()->getKeys(),JTCS_FROM); }
|
||||
BOOL IsDestPrimKey() const { return checkPrimaryKey(getReferencedTable()->getKeys(),JTCS_TO); }
|
||||
BOOL checkPrimaryKey(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& i_xTable,EConnectionSide _eEConnectionSide) const;
|
||||
BOOL IsSourcePrimKey() const { return checkPrimaryKey(getReferencingTable()->getTable(),JTCS_FROM); }
|
||||
BOOL IsDestPrimKey() const { return checkPrimaryKey(getReferencedTable()->getTable(),JTCS_TO); }
|
||||
|
||||
protected:
|
||||
virtual OConnectionLineDataRef CreateLineDataObj();
|
||||
|
@@ -160,6 +160,7 @@ namespace dbaui
|
||||
OTableCopyHelper m_aTableCopyHelper;
|
||||
|
||||
::rtl::OUString m_sQueryCommand; // the command of the query currently loaded (if any)
|
||||
::rtl::OUString m_sToBeLoaded; // contains the element name which should be loaded if any
|
||||
|
||||
DBTreeView* m_pTreeView;
|
||||
Splitter* m_pSplitter;
|
||||
|
@@ -233,22 +233,10 @@ Sequence< ::rtl::OUString > ObjectCopySource::getColumnNames() const
|
||||
//------------------------------------------------------------------------
|
||||
Sequence< ::rtl::OUString > ObjectCopySource::getPrimaryKeyColumnNames() const
|
||||
{
|
||||
Reference<XKeysSupplier> xSup(m_xObject,UNO_QUERY);
|
||||
Reference< XIndexAccess> xKeys;
|
||||
if(xSup.is() )
|
||||
xKeys = xSup->getKeys();
|
||||
|
||||
::std::vector< Reference< XNameAccess > > aPrimaryKeyColumns( ::dbaui::getKeyColumns( xKeys, KeyType::PRIMARY ) );
|
||||
OSL_ENSURE( ( aPrimaryKeyColumns.size() == 1 ) || aPrimaryKeyColumns.empty(),
|
||||
"ObjectCopySource::getPrimaryKeyColumnNames: more than one primary key?!" );
|
||||
|
||||
Reference< XNameAccess > xKeyCols;
|
||||
if ( !aPrimaryKeyColumns.empty() )
|
||||
xKeyCols = aPrimaryKeyColumns[0];
|
||||
|
||||
const Reference<XNameAccess> xPrimaryKeyColumns = getPrimaryKeyColumns_throw(m_xObject);
|
||||
Sequence< ::rtl::OUString > aKeyColNames;
|
||||
if ( xKeyCols.is() )
|
||||
aKeyColNames = xKeyCols->getElementNames();
|
||||
if ( xPrimaryKeyColumns.is() )
|
||||
aKeyColNames = xPrimaryKeyColumns->getElementNames();
|
||||
return aKeyColNames;
|
||||
}
|
||||
|
||||
|
@@ -62,8 +62,6 @@
|
||||
#endif
|
||||
|
||||
#include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
|
||||
#include <com/sun/star/sdbcx/XKeysSupplier.hpp>
|
||||
#include <com/sun/star/sdbcx/KeyType.hpp>
|
||||
#include <com/sun/star/container/XNameAccess.hpp>
|
||||
#include <com/sun/star/beans/XPropertySet.hpp>
|
||||
#include <com/sun/star/accessibility/AccessibleEventId.hpp>
|
||||
@@ -76,6 +74,7 @@
|
||||
#include "UITools.hxx"
|
||||
#include "TableWindowAccess.hxx"
|
||||
#include "browserids.hxx"
|
||||
#include <connectivity/dbtools.hxx>
|
||||
|
||||
|
||||
using namespace dbaui;
|
||||
@@ -224,30 +223,7 @@ BOOL OTableWindow::FillListBox()
|
||||
Reference<XNameAccess> xPKeyColumns;
|
||||
try
|
||||
{
|
||||
// first we need the keys from the table
|
||||
Reference< XIndexAccess> xKeyIndex = m_pData->getKeys();
|
||||
// search the one and only primary key
|
||||
if ( xKeyIndex.is() )
|
||||
{
|
||||
Reference<XColumnsSupplier> xColumnsSupplier;
|
||||
for(sal_Int32 i=0;i< xKeyIndex->getCount();++i)
|
||||
{
|
||||
Reference<XPropertySet> xProp;
|
||||
xKeyIndex->getByIndex(i) >>= xProp;
|
||||
if ( xProp.is() )
|
||||
{
|
||||
sal_Int32 nKeyType = 0;
|
||||
xProp->getPropertyValue(PROPERTY_TYPE) >>= nKeyType;
|
||||
if(KeyType::PRIMARY == nKeyType)
|
||||
{
|
||||
xColumnsSupplier.set(xProp,UNO_QUERY);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( xColumnsSupplier.is() )
|
||||
xPKeyColumns = xColumnsSupplier->getColumns();
|
||||
}
|
||||
xPKeyColumns = dbtools::getPrimaryKeyColumns_throw(m_pData->getTable());
|
||||
}
|
||||
catch(Exception&)
|
||||
{
|
||||
|
@@ -45,6 +45,7 @@
|
||||
#include "UITools.hxx"
|
||||
#include "moduledbu.hxx"
|
||||
#include <connectivity/dbexception.hxx>
|
||||
#include <connectivity/dbtools.hxx>
|
||||
|
||||
using namespace dbaui;
|
||||
using namespace ::com::sun::star::sdbc;
|
||||
@@ -176,35 +177,29 @@ void ORelationTableConnectionData::SetCardinality()
|
||||
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
BOOL ORelationTableConnectionData::checkPrimaryKey(const Reference< XIndexAccess>& _xKeys,EConnectionSide _eEConnectionSide) const
|
||||
BOOL ORelationTableConnectionData::checkPrimaryKey(const Reference< XPropertySet>& i_xTable,EConnectionSide _eEConnectionSide) const
|
||||
{
|
||||
// check if Table has the primary key column dependig on _eEConnectionSide
|
||||
USHORT nPrimKeysCount = 0,
|
||||
nValidLinesCount = 0;
|
||||
::std::vector<Reference<XNameAccess> > vKeyColumns = ::dbaui::getKeyColumns(_xKeys,KeyType::PRIMARY);
|
||||
if ( vKeyColumns.size() == 1 )
|
||||
const Reference< XNameAccess> xKeyColumns = dbtools::getPrimaryKeyColumns_throw(i_xTable);
|
||||
if ( xKeyColumns.is() )
|
||||
{
|
||||
// OSL_ENSURE(vKeyColumns.size()==1,"There can be only one primary key in a table!");
|
||||
Sequence< ::rtl::OUString> aKeyColumns;
|
||||
Reference<XNameAccess> xKeyColumns = *vKeyColumns.begin();
|
||||
if ( xKeyColumns.is() )
|
||||
{
|
||||
aKeyColumns = xKeyColumns->getElementNames();
|
||||
const ::rtl::OUString* pKeyIter = aKeyColumns.getConstArray();
|
||||
const ::rtl::OUString* pKeyEnd = pKeyIter + aKeyColumns.getLength();
|
||||
Sequence< ::rtl::OUString> aKeyColumns = xKeyColumns->getElementNames();
|
||||
const ::rtl::OUString* pKeyIter = aKeyColumns.getConstArray();
|
||||
const ::rtl::OUString* pKeyEnd = pKeyIter + aKeyColumns.getLength();
|
||||
|
||||
for(;pKeyIter != pKeyEnd;++pKeyIter)
|
||||
for(;pKeyIter != pKeyEnd;++pKeyIter)
|
||||
{
|
||||
OConnectionLineDataVec::const_iterator aIter = m_vConnLineData.begin();
|
||||
OConnectionLineDataVec::const_iterator aEnd = m_vConnLineData.end();
|
||||
for(;aIter != aEnd;++aIter)
|
||||
{
|
||||
OConnectionLineDataVec::const_iterator aIter = m_vConnLineData.begin();
|
||||
OConnectionLineDataVec::const_iterator aEnd = m_vConnLineData.end();
|
||||
for(;aIter != aEnd;++aIter)
|
||||
++nValidLinesCount;
|
||||
if ( (*aIter)->GetFieldName(_eEConnectionSide) == *pKeyIter )
|
||||
{
|
||||
++nValidLinesCount;
|
||||
if ( (*aIter)->GetFieldName(_eEConnectionSide) == *pKeyIter )
|
||||
{
|
||||
++nPrimKeysCount;
|
||||
break;
|
||||
}
|
||||
++nPrimKeysCount;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -228,9 +228,8 @@ void ORelationTableView::AddConnection(const OJoinExchangeData& jxdSource, const
|
||||
::rtl::OUString sDestFieldName = jxdDest.pListBox->GetEntryText(jxdDest.pEntry);
|
||||
|
||||
// die Anzahl der PKey-Felder in der Quelle
|
||||
|
||||
::std::vector< Reference< XNameAccess> > aPkeys = ::dbaui::getKeyColumns(pSourceWin->GetData()->getKeys(),KeyType::PRIMARY);
|
||||
bool bAskUser = aPkeys.size() == 1 && Reference< XIndexAccess>(aPkeys[0],UNO_QUERY)->getCount() > 1;
|
||||
const Reference< XNameAccess> xPrimaryKeyColumns = getPrimaryKeyColumns_throw(pSourceWin->GetData()->getTable());
|
||||
bool bAskUser = xPrimaryKeyColumns.is() && Reference< XIndexAccess>(xPrimaryKeyColumns,UNO_QUERY)->getCount() > 1;
|
||||
|
||||
pTabConnData->SetConnLine( 0, sSourceFieldName, sDestFieldName );
|
||||
|
||||
|
@@ -971,39 +971,7 @@ void OTableController::loadData()
|
||||
// -----------------------------------------------------------------------------
|
||||
Reference<XNameAccess> OTableController::getKeyColumns() const
|
||||
{
|
||||
// use keys and indexes for excat postioning
|
||||
// first the keys
|
||||
Reference<XKeysSupplier> xKeySup(m_xTable,UNO_QUERY);
|
||||
Reference<XIndexAccess> xKeys;
|
||||
if(xKeySup.is())
|
||||
xKeys = xKeySup->getKeys();
|
||||
|
||||
Reference<XColumnsSupplier> xKeyColsSup;
|
||||
Reference<XNameAccess> xKeyColumns;
|
||||
if(xKeys.is())
|
||||
{
|
||||
Reference<XPropertySet> xProp;
|
||||
sal_Int32 nCount = xKeys->getCount();
|
||||
for(sal_Int32 i=0;i< nCount;++i)
|
||||
{
|
||||
xKeys->getByIndex(i) >>= xProp;
|
||||
OSL_ENSURE(xProp.is(),"Key is invalid: NULL!");
|
||||
if ( xProp.is() )
|
||||
{
|
||||
sal_Int32 nKeyType = 0;
|
||||
xProp->getPropertyValue(PROPERTY_TYPE) >>= nKeyType;
|
||||
if(KeyType::PRIMARY == nKeyType)
|
||||
{
|
||||
xKeyColsSup.set(xProp,UNO_QUERY);
|
||||
OSL_ENSURE(xKeyColsSup.is(),"Columnsupplier is null!");
|
||||
xKeyColumns = xKeyColsSup->getColumns();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return xKeyColumns;
|
||||
return getPrimaryKeyColumns_throw(m_xTable);
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
sal_Bool OTableController::checkColumns(sal_Bool _bNew) throw(::com::sun::star::sdbc::SQLException)
|
||||
|
Reference in New Issue
Block a user