Tag: cws_src680_dba24d
User: fs      
Date: 2007-11-15 10:05:01+0000
Modified:
   dba/dbaccess/source/ui/misc/WCopyTable.cxx

Log:
 #i81658# removed m_xSourceObject, hide it behind some ICopyTableSourceObject, 
to allow copying tables at SDBC level where we cannot describe the source as 
object, but as table name only

File Changes:

Directory: /dba/dbaccess/source/ui/misc/
========================================

File [changed]: WCopyTable.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/dbaccess/source/ui/misc/WCopyTable.cxx?r1=1.53.28.1&r2=1.53.28.2
Delta lines:  +346 -179
-----------------------
--- WCopyTable.cxx      2007-11-08 14:25:11+0000        1.53.28.1
+++ WCopyTable.cxx      2007-11-15 10:04:59+0000        1.53.28.2
@@ -4,9 +4,9 @@
  *
  *  $RCSfile: WCopyTable.cxx,v $
  *
- *  $Revision: 1.53.28.1 $
+ *  $Revision: 1.53.28.2 $
  *
- *  last change: $Author: fs $ $Date: 2007/11/08 14:25:11 $
+ *  last change: $Author: fs $ $Date: 2007/11/15 10:04:59 $
  *
  *  The Contents of this file are made available subject to
  *  the terms of GNU Lesser General Public License Version 2.1.
@@ -127,6 +127,10 @@
 #ifndef _DBAUI_SQLMESSAGE_HXX_
 #include "sqlmessage.hxx"
 #endif
+#ifndef _RTL_USTRBUF_HXX_
+#include <rtl/ustrbuf.hxx>
+#endif
+
 #include <functional>
 
 using namespace ::dbaui;
@@ -157,18 +161,51 @@
                _rColumnsVec.clear();
                _rColumns.clear();
        }
+}
 
-    //....................................................................
-    bool lcl_isViewObject_nothrow( const Reference< XPropertySet >& _rxObject )
-    {
+//========================================================================
+//= ICopyTableSourceObject
+//========================================================================
+//------------------------------------------------------------------------
+ICopyTableSourceObject::~ICopyTableSourceObject()
+{
+}
+
+//========================================================================
+//= ObjectCopySource
+//========================================================================
+//------------------------------------------------------------------------
+ObjectCopySource::ObjectCopySource( const Reference< XConnection >& 
_rxConnection, const Reference< XPropertySet >& _rxObject )
+    :m_xConnection( _rxConnection, UNO_SET_THROW )
+    ,m_xMetaData( _rxConnection->getMetaData(), UNO_SET_THROW )
+    ,m_xObject( _rxObject, UNO_SET_THROW )
+    ,m_xObjectPSI( _rxObject->getPropertySetInfo(), UNO_SET_THROW )
+    ,m_xObjectColumns( Reference< XColumnsSupplier >( _rxObject, 
UNO_QUERY_THROW )->getColumns(), UNO_SET_THROW )
+{
+}
+
+//------------------------------------------------------------------------
+::rtl::OUString ObjectCopySource::getQualifiedObjectName() const
+{
+    ::rtl::OUString sName;
+
+       if ( !m_xObjectPSI->hasPropertyByName( PROPERTY_COMMAND ) )
+               sName = ::dbtools::composeTableName( m_xMetaData, m_xObject, 
::dbtools::eInDataManipulation, false, false, false );
+       else
+               m_xObject->getPropertyValue( PROPERTY_NAME ) >>= sName;
+    return sName;
+}
+
+//------------------------------------------------------------------------
+bool ObjectCopySource::isView() const
+{
                bool bIsView = false;
         try
         {
-            Reference< XPropertySetInfo > xPSI( 
_rxObject->getPropertySetInfo(), UNO_SET_THROW );
-            if ( xPSI->hasPropertyByName( PROPERTY_TYPE ) )
+        if ( m_xObjectPSI->hasPropertyByName( PROPERTY_TYPE ) )
             {
                 ::rtl::OUString sObjectType;
-                OSL_VERIFY( _rxObject->getPropertyValue( PROPERTY_TYPE ) >>= 
sObjectType );
+            OSL_VERIFY( m_xObject->getPropertyValue( PROPERTY_TYPE ) >>= 
sObjectType );
                 bIsView = sObjectType.equalsAscii( "VIEW" );
             }
         }
@@ -177,12 +214,236 @@
            DBG_UNHANDLED_EXCEPTION();
         }
         return bIsView;
+}
+
+//------------------------------------------------------------------------
+void ObjectCopySource::copyUISettingsTo( const Reference< XPropertySet >& 
_rxObject ) const
+{
+    const ::rtl::OUString aCopyProperties[] = {
+        PROPERTY_FONT, PROPERTY_ROW_HEIGHT, PROPERTY_TEXTCOLOR
+    };
+    for ( size_t i=0; i < sizeof( aCopyProperties ) / sizeof( 
aCopyProperties[0] ); ++i )
+    {
+               if ( m_xObjectPSI->hasPropertyByName( aCopyProperties[i] ) )
+                       _rxObject->setPropertyValue( aCopyProperties[i], 
m_xObject->getPropertyValue( aCopyProperties[i] ) );
+    }
+}
+
+//------------------------------------------------------------------------
+Sequence< ::rtl::OUString > ObjectCopySource::getColumnNames() const
+{
+    return m_xObjectColumns->getElementNames();
+}
+
+//------------------------------------------------------------------------
+Sequence< ::rtl::OUString > ObjectCopySource::getPrimaryKeyColumnNames() const
+{
+    ::std::vector< Reference< XNameAccess > > aPrimaryKeyColumns( 
::dbaui::getKeyColumns( m_xObject, 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];
+
+    Sequence< ::rtl::OUString > aKeyColNames;
+    if ( xKeyCols.is() )
+        aKeyColNames = xKeyCols->getElementNames();
+    return aKeyColNames;
+}
+
+//------------------------------------------------------------------------
+OFieldDescription* ObjectCopySource::createFieldDescription( const 
::rtl::OUString& _rColumnName ) const
+{
+    Reference< XPropertySet > xColumn( m_xObjectColumns->getByName( 
_rColumnName ), UNO_QUERY_THROW );
+    return new OFieldDescription( xColumn );
+}
+
+//------------------------------------------------------------------------
+::rtl::OUString ObjectCopySource::getSelectStatement() const
+{
+    ::rtl::OUString sSelectStatement;
+    if ( m_xObjectPSI->hasPropertyByName( PROPERTY_COMMAND ) )
+    {   // query
+        OSL_VERIFY( m_xObject->getPropertyValue( PROPERTY_COMMAND ) >>= 
sSelectStatement );
+    }
+    else
+    {   // table
+        ::rtl::OUStringBuffer aSQL;
+        aSQL.appendAscii( "SELECT " );
+
+        // we need to create the sql stmt with column names
+        // otherwise it is possible that names don't match
+        const ::rtl::OUString sQuote = m_xMetaData->getIdentifierQuoteString();
+
+        Sequence< ::rtl::OUString > aColumnNames = getColumnNames();
+        const ::rtl::OUString* pColumnName = aColumnNames.getConstArray();
+        const ::rtl::OUString* pEnd = pColumnName + aColumnNames.getLength();
+        for ( ; pColumnName != pEnd; )
+        {
+            aSQL.append( ::dbtools::quoteName( sQuote, *pColumnName++ ) );
+
+            if ( pColumnName == pEnd )
+                aSQL.appendAscii( " " );
+            else
+                aSQL.appendAscii( ", " );
     }
+
+        aSQL.appendAscii( "FROM " );
+        aSQL.append( ::dbtools::composeTableNameForSelect( m_xConnection, 
m_xObject ) );
+
+        sSelectStatement = aSQL.makeStringAndClear();
+    }
+
+    return sSelectStatement;
+}
+
+//========================================================================
+//= NamedTableCopySource
+//========================================================================
+//------------------------------------------------------------------------
+NamedTableCopySource::NamedTableCopySource( const Reference< XConnection >& 
_rxConnection, const ::rtl::OUString& _rTableName )
+    :m_xConnection( _rxConnection, UNO_SET_THROW )
+    ,m_xMetaData( _rxConnection->getMetaData(), UNO_SET_THROW )
+    ,m_sTableName( _rTableName )
+{
+}
+
+//------------------------------------------------------------------------
+::rtl::OUString NamedTableCopySource::getQualifiedObjectName() const
+{
+    return m_sTableName;
+}
+
+//------------------------------------------------------------------------
+bool NamedTableCopySource::isView() const
+{
+    // TODO: ask the meta data
+    return false;
+}
+
+//------------------------------------------------------------------------
+void NamedTableCopySource::copyUISettingsTo( const Reference< XPropertySet >& 
/*_rxObject*/ ) const
+{
+    // not supported: we do not have UI settings to copy
+}
+
+//------------------------------------------------------------------------
+Sequence< ::rtl::OUString > NamedTableCopySource::getColumnNames() const
+{
+    // TODO: ask the meta data
+    return Sequence< ::rtl::OUString >();
+}
+
+//------------------------------------------------------------------------
+Sequence< ::rtl::OUString > NamedTableCopySource::getPrimaryKeyColumnNames() 
const
+{
+    // TODO: ask the meta data
+    return Sequence< ::rtl::OUString >();
 }
 
 //------------------------------------------------------------------------
+OFieldDescription* NamedTableCopySource::createFieldDescription( const 
::rtl::OUString& /*_rColumnName*/ ) const
+{
+    // TODO
+    return NULL;
+}
+
+//------------------------------------------------------------------------
+::rtl::OUString NamedTableCopySource::getSelectStatement() const
+{
+    ::rtl::OUStringBuffer aSQL;
+    aSQL.appendAscii( "SELECT * FROM " );
+
+    ::rtl::OUString sCatalog, sSchema, sName;
+    ::dbtools::qualifiedNameComponents( m_xMetaData, getQualifiedObjectName(), 
sCatalog, sSchema, sName, ::dbtools::eComplete );
+    aSQL.append( ::dbtools::composeTableNameForSelect( m_xConnection, 
sCatalog, sSchema, sName ) );
+
+    return aSQL.makeStringAndClear();
+}
+
+// ========================================================
+// DummyCopySource
+// ========================================================
+class DummyCopySource : public ICopyTableSourceObject
+{
+public:
+    DummyCopySource() { }
+
+    static const DummyCopySource& Instance();
+
+    // ICopyTableSourceObject overridables
+    virtual ::rtl::OUString     getQualifiedObjectName() const;
+    virtual bool                isView() const;
+    virtual void                copyUISettingsTo( const 
::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& 
_rxObject ) const;
+    virtual ::com::sun::star::uno::Sequence< ::rtl::OUString >
+                                getColumnNames() const;
+    virtual ::com::sun::star::uno::Sequence< ::rtl::OUString >
+                                getPrimaryKeyColumnNames() const;
+    virtual OFieldDescription*  createFieldDescription( const ::rtl::OUString& 
_rColumnName ) const;
+    virtual ::rtl::OUString     getSelectStatement() const;
+};
+
+//------------------------------------------------------------------------
+const DummyCopySource& DummyCopySource::Instance()
+{
+    static DummyCopySource s_aTheInstance;
+    return s_aTheInstance;
+}
+
+//------------------------------------------------------------------------
+::rtl::OUString DummyCopySource::getQualifiedObjectName() const
+{
+    OSL_ENSURE( false, "DummyCopySource::getQualifiedObjectName: not to be 
called!" );
+    return ::rtl::OUString();
+}
+
+//------------------------------------------------------------------------
+bool DummyCopySource::isView() const
+{
+    OSL_ENSURE( false, "DummyCopySource::isView: not to be called!" );
+    return false;
+}
+
+//------------------------------------------------------------------------
+void DummyCopySource::copyUISettingsTo( const Reference< XPropertySet >& 
/*_rxObject*/ ) const
+{
+    // no support
+}
+
+//------------------------------------------------------------------------
+Sequence< ::rtl::OUString > DummyCopySource::getColumnNames() const
+{
+    return Sequence< ::rtl::OUString >();
+}
+
+//------------------------------------------------------------------------
+Sequence< ::rtl::OUString > DummyCopySource::getPrimaryKeyColumnNames() const
+{
+    OSL_ENSURE( false, "DummyCopySource::getPrimaryKeyColumnNames: not to be 
called!" );
+    return Sequence< ::rtl::OUString >();
+}
+
+//------------------------------------------------------------------------
+OFieldDescription* DummyCopySource::createFieldDescription( const 
::rtl::OUString& /*_rColumnName*/ ) const
+{
+    OSL_ENSURE( false, "DummyCopySource::createFieldDescription: not to be 
called!" );
+    return NULL;
+}
+
+//------------------------------------------------------------------------
+::rtl::OUString DummyCopySource::getSelectStatement() const
+{
+    OSL_ENSURE( false, "DummyCopySource::getSelectStatement: not to be 
called!" );
+    return ::rtl::OUString();
+}
+
+//========================================================================
+//= OCopyTableWizard
+//========================================================================
+//------------------------------------------------------------------------
 OCopyTableWizard::OCopyTableWizard( Window * pParent, const ::rtl::OUString& 
_rDefaultName, sal_Int16 _nOperation,
-        const Reference< XPropertySet >& _xSourceObject, const Reference< 
XConnection >& _xSourceConnection,
+        const ICopyTableSourceObject& _rSourceObject, const Reference< 
XConnection >& _xSourceConnection,
         const Reference< XConnection >& _xConnection, const Reference< 
XMultiServiceFactory >& _rxORB )
        : WizardDialog( pParent, ModuleRes(WIZ_RTFCOPYTABLE))
     ,m_pbHelp( this , ModuleRes(PB_HELP))
@@ -192,7 +453,7 @@
        ,m_pbFinish( this , ModuleRes(PB_OK))
        ,m_mNameMapping(_xConnection->getMetaData().is() && 
_xConnection->getMetaData()->supportsMixedCaseQuotedIdentifiers())
     ,m_xDestConnection( _xConnection )
-       ,m_xSourceObject(_xSourceObject)
+       ,m_rSourceObject( _rSourceObject )
        ,m_xSourceConnection(_xSourceConnection)
     ,m_xFormatter( getNumberFormatter( _xConnection, _rxORB ) )
        ,m_xFactory(_rxORB)
@@ -211,17 +472,8 @@
     ::rtl::OUString sInitialTableName( _rDefaultName );
        try
        {
-               if ( m_xSourceObject.is() )
-               {
-                       Reference< XColumnsSupplier > xColSupp( 
m_xSourceObject, UNO_QUERY );
-                       if ( xColSupp.is() )
-                               m_xSourceColumns = xColSupp->getColumns();
-
-                       if ( 
!m_xSourceObject->getPropertySetInfo()->hasPropertyByName(PROPERTY_COMMAND) )
-                               m_sSourceName = ::dbtools::composeTableName( 
m_xDestConnection->getMetaData(), m_xSourceObject, 
::dbtools::eInDataManipulation, false, false, false );
-                       else
-                               _xSourceObject->getPropertyValue(PROPERTY_NAME) 
>>= m_sSourceName;
-               }
+        m_sSourceName = m_rSourceObject.getQualifiedObjectName();
+        OSL_ENSURE( m_sSourceName.getLength() > 0, 
"OCopyTableWizard::OCopyTableWizard: unable to retrieve the source object's 
name!" );
 
         if ( !sInitialTableName.getLength() )
             sInitialTableName = m_sSourceName;
@@ -243,11 +495,10 @@
        }
 
     impl_fillTypeInfo();
-     // create the field description
-       loadData( m_xSourceObject, m_vSourceColumns, m_vSourceVec );
+       impl_loadSourceData();
 
        OCopyTable* pPage1( new OCopyTable( this ) );
-    if ( lcl_isViewObject_nothrow( m_xSourceObject ) )
+    if ( m_rSourceObject.isView() )
         // if it is a view disable the view checkbox #100644#
         pPage1->disallowViews();
        pPage1->setCreateStyleAction();
@@ -273,6 +524,7 @@
        ,m_pbFinish( this , ModuleRes(PB_OK))
        ,m_mNameMapping(_xConnection->getMetaData().is() && 
_xConnection->getMetaData()->supportsMixedCaseQuotedIdentifiers())
     ,m_xDestConnection( _xConnection )
+    ,m_rSourceObject( DummyCopySource::Instance() )
        ,m_xSourceConnection(_xConnection) // in this case source connection 
and dest connection are the same
        ,m_xFormatter(_xFormatter)
        ,m_xFactory(_rM)
@@ -367,7 +619,6 @@
 // -----------------------------------------------------------------------
 IMPL_LINK( OCopyTableWizard, ImplPrevHdl, PushButton*, EMPTYARG )
 {
-       DBG_CHKTHIS(OCopyTableWizard,NULL);
        m_ePressed = WIZARD_PREV;
        if ( GetCurLevel() )
        {
@@ -388,7 +639,6 @@
 
 IMPL_LINK( OCopyTableWizard, ImplNextHdl, PushButton*, EMPTYARG )
 {
-       DBG_CHKTHIS(OCopyTableWizard,NULL);
        m_ePressed = WIZARD_NEXT;
        if ( GetCurLevel() < MAX_PAGES )
        {
@@ -407,7 +657,6 @@
 // -----------------------------------------------------------------------
 sal_Bool OCopyTableWizard::CheckColumns(sal_Int32& _rnBreakPos)
 {
-       DBG_CHKTHIS(OCopyTableWizard,NULL);
        sal_Bool bRet = sal_True;
        m_vColumnPos.clear();
        m_vColumnTypes.clear();
@@ -574,7 +823,6 @@
 //------------------------------------------------------------------------
 sal_Bool OCopyTableWizard::shouldCreatePrimaryKey() const
 {
-       DBG_CHKTHIS(OCopyTableWizard,NULL);
        return m_bCreatePrimaryKeyColumn;
 }
 
@@ -606,7 +854,6 @@
 // -----------------------------------------------------------------------
 void OCopyTableWizard::CheckButtons()
 {
-       DBG_CHKTHIS(OCopyTableWizard,NULL);
        if(GetCurLevel() == 0) // erste Seite hat kein PrevButton
        {
                if(m_nPageCount > 1)
@@ -630,7 +877,6 @@
 // -----------------------------------------------------------------------
 void OCopyTableWizard::EnableButton(Wizard_Button_Style eStyle,sal_Bool 
bEnable)
 {
-       DBG_CHKTHIS(OCopyTableWizard,NULL);
 //     CheckButtons();
        Button* pButton;
        if(eStyle == WIZARD_NEXT)
@@ -645,21 +891,18 @@
 // -----------------------------------------------------------------------
 long OCopyTableWizard::DeactivatePage()
 {
-       DBG_CHKTHIS(OCopyTableWizard,NULL);
        OWizardPage* pPage = (OWizardPage*)GetPage(GetCurLevel());
        return pPage ? pPage->LeavePage() : sal_False;
 }
 // -----------------------------------------------------------------------
 void OCopyTableWizard::AddWizardPage(OWizardPage* pPage)
 {
-       DBG_CHKTHIS(OCopyTableWizard,NULL);
        AddPage(pPage);
        ++m_nPageCount;
 }
 // 
-----------------------------------------------------------------------------
 void OCopyTableWizard::insertColumn(sal_Int32 _nPos,OFieldDescription* _pField)
 {
-       DBG_CHKTHIS(OCopyTableWizard,NULL);
        OSL_ENSURE(_pField,"FieldDescrioption is null!");
        if ( _pField )
        {
@@ -677,7 +920,6 @@
 // 
-----------------------------------------------------------------------------
 void OCopyTableWizard::replaceColumn(sal_Int32 _nPos,OFieldDescription* 
_pField,const ::rtl::OUString& _sOldName)
 {
-       DBG_CHKTHIS(OCopyTableWizard,NULL);
        OSL_ENSURE(_pField,"FieldDescrioption is null!");
        if ( _pField )
        {
@@ -689,29 +931,20 @@
        }
 }
 // 
-----------------------------------------------------------------------------
-void OCopyTableWizard::loadData(const Reference<XPropertySet>& _xTable,
-                                                               
ODatabaseExport::TColumns& _rColumns,
-                                                               
ODatabaseExport::TColumnVector& _rColVector)
+void OCopyTableWizard::impl_loadSourceData()
 {
-       DBG_CHKTHIS(OCopyTableWizard,NULL);
-       ODatabaseExport::TColumns::iterator aIter = _rColumns.begin();
+    loadData( m_rSourceObject, m_vSourceColumns, m_vSourceVec );
+}
 
-       for(;aIter != _rColumns.end();++aIter)
-               delete aIter->second;
+// 
-----------------------------------------------------------------------------
+void OCopyTableWizard::loadData(  const ICopyTableSourceObject& 
_rSourceObject, ODatabaseExport::TColumns& _rColumns, 
ODatabaseExport::TColumnVector& _rColVector )
+{
+       for ( ODatabaseExport::TColumns::iterator col = _rColumns.begin(); col 
!= _rColumns.end(); ++col )
+               delete col->second;
 
        _rColVector.clear();
        _rColumns.clear();
 
-       OSL_ENSURE( m_xDestConnection.is(), "OCopyTableWizard::CheckColumns: No 
connection!" );
-       if ( m_xDestConnection.is() )
-       {
-               
//////////////////////////////////////////////////////////////////////
-               // Datenstruktur mit Daten aus DatenDefinitionsObjekt fuellen
-               if(_xTable.is())
-               {
-                       Reference<XColumnsSupplier> xColSup(_xTable,UNO_QUERY);
-                       OSL_ENSURE(xColSup.is(),"No XColumnsSupplier!");
-                       Reference<XNameAccess> xColumns = xColSup->getColumns();
                        OFieldDescription* pActFieldDescr = NULL;
                        String aType;
                        ::rtl::OUString 
sCreateParam(RTL_CONSTASCII_USTRINGPARAM("x"));
@@ -720,29 +953,20 @@
                        // Bei Drop darf keine Zeile editierbar sein.
                        // Bei Add duerfen nur die leeren Zeilen editierbar 
sein.
                        // Bei Add und Drop koennen alle Zeilen editiert werden.
-                       Sequence< ::rtl::OUString> aColumns = 
xColumns->getElementNames();
-                       const ::rtl::OUString* pIter    = 
aColumns.getConstArray();
-                       const ::rtl::OUString* pEnd             = pIter + 
aColumns.getLength();
+       Sequence< ::rtl::OUString > aColumns( _rSourceObject.getColumnNames() );
+       const ::rtl::OUString* pColumn      = aColumns.getConstArray();
+       const ::rtl::OUString* pColumnEnd   = pColumn + aColumns.getLength();
+
+       for ( ; pColumn != pColumnEnd; ++pColumn )
+       {
+               // get the properties of the column
+               pActFieldDescr = _rSourceObject.createFieldDescription( 
*pColumn );
+               sal_Int32 nType                   = pActFieldDescr->GetType();
+               sal_Int32 nScale                  = pActFieldDescr->GetScale();
+               sal_Int32 nPrecision      = pActFieldDescr->GetPrecision();
+               sal_Bool bAutoIncrement   = pActFieldDescr->IsAutoIncrement();
+               ::rtl::OUString sTypeName = pActFieldDescr->GetTypeName();
 
-                       for(;pIter != pEnd;++pIter)
-                       {
-                               Reference<XPropertySet> xColumn;
-                               xColumns->getByName(*pIter) >>= xColumn;
-
-                               sal_Int32 nType                 = 0;
-                               sal_Int32 nScale                = 0;
-                               sal_Int32 nPrecision    = 0;
-                               sal_Bool bAutoIncrement = sal_False;
-                               ::rtl::OUString sTypeName;
-
-                               // get the properties from the column
-                               xColumn->getPropertyValue(PROPERTY_TYPENAME)    
        >>= sTypeName;
-                               xColumn->getPropertyValue(PROPERTY_TYPE)        
                >>= nType;
-                               xColumn->getPropertyValue(PROPERTY_SCALE)       
                >>= nScale;
-                               xColumn->getPropertyValue(PROPERTY_PRECISION)   
        >>= nPrecision;
-                               
xColumn->getPropertyValue(PROPERTY_ISAUTOINCREMENT)     >>= bAutoIncrement;
-
-                               pActFieldDescr = new OFieldDescription(xColumn);
                                // search for type
                                sal_Bool bForce;
                                TOTypeInfoSP pTypeInfo = 
::dbaui::getTypeInfoFromType(m_aTypeInfo,nType,sTypeName,sCreateParam,nPrecision,nScale,bAutoIncrement,bForce);
@@ -752,70 +976,31 @@
                                
pActFieldDescr->FillFromTypeInfo(pTypeInfo,sal_True,sal_False);
                                
_rColVector.push_back(_rColumns.insert(ODatabaseExport::TColumns::value_type(pActFieldDescr->GetName(),pActFieldDescr)).first);
                        }
-                       // fill the primary  key information
-                       Reference<XNameAccess> xKeyColumns      = 
getKeyColumns(_xTable);
-                       if(xKeyColumns.is())
-                       {
-                               Sequence< ::rtl::OUString> aKeyColumns = 
xKeyColumns->getElementNames();
-                               const ::rtl::OUString* pKeyBegin        = 
aKeyColumns.getConstArray();
-                               const ::rtl::OUString* pKeyEnd          = 
pKeyBegin + aKeyColumns.getLength();
 
-                               for(;pKeyBegin != pKeyEnd;++pKeyBegin)
+    // determine which coumns belong to the primary key
+    Sequence< ::rtl::OUString > aPrimaryKeyColumns( 
_rSourceObject.getPrimaryKeyColumnNames() );
+    const ::rtl::OUString* pKeyColName  = aPrimaryKeyColumns.getConstArray();
+    const ::rtl::OUString* pKeyColEnd   = pKeyColName + 
aPrimaryKeyColumns.getLength();
+
+    for( ; pKeyColName != pKeyColEnd; ++pKeyColName )
                                {
-                                       ODatabaseExport::TColumns::iterator 
keyPos = _rColumns.find(*pKeyBegin);
+        ODatabaseExport::TColumns::iterator keyPos = _rColumns.find( 
*pKeyColName );
                                        if ( keyPos != _rColumns.end() )
                                        {
-                                               
keyPos->second->SetPrimaryKey(sal_True);
-                                               
keyPos->second->SetIsNullable(ColumnValue::NO_NULLS);
-                                       }
-                               }
-                       }
+            keyPos->second->SetPrimaryKey( sal_True );
+            keyPos->second->SetIsNullable( ColumnValue::NO_NULLS );
                }
        }
 }
 // 
-----------------------------------------------------------------------------
 void OCopyTableWizard::clearDestColumns()
 {
-       DBG_CHKTHIS(OCopyTableWizard,NULL);
        clearColumns(m_vDestColumns,m_aDestVec);
 }
-// 
-----------------------------------------------------------------------------
-Reference<XNameAccess> OCopyTableWizard::getKeyColumns(const 
Reference<XPropertySet>& _xTable) const
-{
-       DBG_CHKTHIS(OCopyTableWizard,NULL);
-       // use keys and indexes for excat postioning
-       // first the keys
-       Reference<XKeysSupplier> xKeySup(_xTable,UNO_QUERY);
-       Reference<XIndexAccess> xKeys;
-       if(xKeySup.is())
-               xKeys = xKeySup->getKeys();
-
-       Reference<XColumnsSupplier> xKeyColsSup;
-       Reference<XNameAccess> xKeyColumns;
-       if(xKeys.is())
-       {
-               Reference<XPropertySet> xProp;
-               for(sal_Int32 i=0;i< xKeys->getCount();++i)
-               {
-                       xKeys->getByIndex(i) >>= xProp;
-                       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;
-}
 // 
-----------------------------------------------------------------------------
 void OCopyTableWizard::appendColumns( Reference<XColumnsSupplier>& _rxColSup, 
const ODatabaseExport::TColumnVector* _pVec, sal_Bool _bKeyColumns) const
 {
-       DBG_CHKTHIS(OCopyTableWizard,NULL);
        // now append the columns
        OSL_ENSURE(_rxColSup.is(),"No columns supplier");
        if(!_rxColSup.is())
@@ -865,7 +1050,6 @@
 // 
-----------------------------------------------------------------------------
 void OCopyTableWizard::appendKey( Reference<XKeysSupplier>& _rxSup, const 
ODatabaseExport::TColumnVector* _pVec) const
 {
-       DBG_CHKTHIS(OCopyTableWizard,NULL);
        if(!_rxSup.is())
                return; // the database doesn't support keys
        OSL_ENSURE(_rxSup.is(),"No XKeysSupplier!");
@@ -893,14 +1077,15 @@
 // 
-----------------------------------------------------------------------------
 Reference< XPropertySet > OCopyTableWizard::createView() const
 {
-       DBG_CHKTHIS(OCopyTableWizard,NULL);
-    return ::dbaui::createView( m_sName, m_xDestConnection, m_xSourceObject );
+    ::rtl::OUString sCommand( m_rSourceObject.getSelectStatement() );
+    OSL_ENSURE( sCommand.getLength(), "OCopyTableWizard::createView: no 
statement in the source object!" );
+        // there are legitimate cases in which getSelectStatement does not 
provide a statement,
+        // but in all those cases, this method here should never be called.
+    return ::dbaui::createView( m_sName, m_xDestConnection, sCommand );
 }
 // 
-----------------------------------------------------------------------------
 Reference< XPropertySet > OCopyTableWizard::createTable()
 {
-       DBG_CHKTHIS(OCopyTableWizard,NULL);
-
     Reference< XPropertySet > xTable;
 
        Reference<XTablesSupplier> xSup( m_xDestConnection, UNO_QUERY );
@@ -942,16 +1127,7 @@
                xTable->setPropertyValue(PROPERTY_SCHEMANAME,makeAny(sSchema));
                xTable->setPropertyValue(PROPERTY_NAME,makeAny(sTable));
 
-               if(m_xSourceObject.is()) // can be null when importing data 
from html or rtf format
-               {
-                       if ( 
m_xSourceObject->getPropertySetInfo()->hasPropertyByName(PROPERTY_FONT) )
-                               
xTable->setPropertyValue(PROPERTY_FONT,m_xSourceObject->getPropertyValue(PROPERTY_FONT));
-                       if ( 
m_xSourceObject->getPropertySetInfo()->hasPropertyByName(PROPERTY_ROW_HEIGHT) )
-                               
xTable->setPropertyValue(PROPERTY_ROW_HEIGHT,m_xSourceObject->getPropertyValue(PROPERTY_ROW_HEIGHT));
-                       if ( 
m_xSourceObject->getPropertySetInfo()->hasPropertyByName(PROPERTY_TEXTCOLOR) )
-                               
xTable->setPropertyValue(PROPERTY_TEXTCOLOR,m_xSourceObject->getPropertyValue(PROPERTY_TEXTCOLOR));
-                       // can not be copied yet, because the filter or and 
order clause could the old table name
-               }
+        m_rSourceObject.copyUISettingsTo( xTable );
 
                Reference< XColumnsSupplier > xSuppDestinationColumns( xTable, 
UNO_QUERY );
                // now append the columns
@@ -1120,7 +1296,6 @@
 // 
-----------------------------------------------------------------------------
 sal_Int32 OCopyTableWizard::getMaxColumnNameLength() const
 {
-       DBG_CHKTHIS(OCopyTableWizard,NULL);
        sal_Int32 nLen = 0;
        if ( m_xDestConnection.is() )
        {
@@ -1139,13 +1314,11 @@
 // 
-----------------------------------------------------------------------------
 void OCopyTableWizard::setOperation( const sal_Int16 _nOperation )
 {
-       DBG_CHKTHIS(OCopyTableWizard,NULL);
        m_nOperation = _nOperation;
 }
 // 
-----------------------------------------------------------------------------
 sal_Int16 OCopyTableWizard::getOperation() const
 {
-       DBG_CHKTHIS(OCopyTableWizard,NULL);
        return m_nOperation;
 }
 // 
-----------------------------------------------------------------------------
@@ -1154,8 +1327,6 @@
                                                                                
                        const ::rtl::OUString&  _sExtraChars,
                                                                                
                        sal_Int32                               _nMaxNameLen)
 {
-       DBG_CHKTHIS(OCopyTableWizard,NULL);
-       
        ::rtl::OUString sAlias = _sColumnName;
        if ( isSQL92CheckEnabled( m_xDestConnection ) )
                sAlias = 
::dbtools::convertName2SQLName(_sColumnName,_sExtraChars);
@@ -1196,7 +1367,6 @@
 // 
-----------------------------------------------------------------------------
 sal_Bool OCopyTableWizard::supportsType(sal_Int32 _nDataType,sal_Int32& 
_rNewDataType)
 {
-       DBG_CHKTHIS(OCopyTableWizard,NULL);
        sal_Bool bRet = m_aDestTypeInfo.find(_nDataType) != 
m_aDestTypeInfo.end();
        if ( bRet )
                _rNewDataType = _nDataType;
@@ -1206,7 +1376,6 @@
 // 
-----------------------------------------------------------------------------
 TOTypeInfoSP OCopyTableWizard::convertType(const TOTypeInfoSP& 
_pType,sal_Bool& _bNotConvert)
 {
-       DBG_CHKTHIS(OCopyTableWizard,NULL);
        if ( m_xSourceConnection == m_xDestConnection )
                return _pType;
 
@@ -1284,10 +1453,10 @@
 // 
-----------------------------------------------------------------------------
 ::rtl::OUString OCopyTableWizard::createUniqueName(const ::rtl::OUString& 
_sName)
 {
-       DBG_CHKTHIS(OCopyTableWizard,NULL);
        ::rtl::OUString sName = _sName;
-       if ( m_xSourceColumns.is() )
-               sName = 
::dbtools::createUniqueName(m_xSourceColumns,sName,sal_False);
+    Sequence< ::rtl::OUString > aColumnNames( m_rSourceObject.getColumnNames() 
);
+       if ( aColumnNames.getLength() )
+               sName = ::dbtools::createUniqueName( aColumnNames, sName, 
sal_False );
        else
        {
                if ( m_vSourceColumns.find(sName) != m_vSourceColumns.end())
@@ -1305,14 +1474,12 @@
 // 
-----------------------------------------------------------------------------
 void OCopyTableWizard::impl_fillTypeInfo()
 {
-       DBG_CHKTHIS(OCopyTableWizard,NULL);
        ::dbaui::fillTypeInfo( m_xSourceConnection, m_sTypeNames, m_aTypeInfo, 
m_aTypeInfoIndex );
        ::dbaui::fillTypeInfo( m_xDestConnection, m_sTypeNames, 
m_aDestTypeInfo, m_aDestTypeInfoIndex );
 }
 // 
-----------------------------------------------------------------------------
 void OCopyTableWizard::showColumnTypeNotSupported(const ::rtl::OUString& 
_rColumnName)
 {
-       DBG_CHKTHIS(OCopyTableWizard,NULL);
        UniString sTitle(ModuleRes(STR_STAT_WARNING));
        UniString sMessage(ModuleRes(STR_UNKNOWN_TYPE_FOUND));
 




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to