User: hr      
Date: 2006/08/15 03:44:53

Modified:
   dba/dbaccess/source/core/dataaccess/datasource.cxx

Log:
 INTEGRATION: CWS dba30 (1.59.2); FILE MERGED
 2006/07/19 12:18:11 fs 1.59.2.10: RESYNC: (1.68-1.70); FILE MERGED
 2006/05/22 10:01:25 fs 1.59.2.9: #i65678# when setting the Info property, 
ensure that all properties not present in the new sequence are reset 
respectively deleted from the Settings bag
 2006/05/08 11:19:01 fs 1.59.2.8: RESYNC: (1.67-1.68); FILE MERGED
 2006/04/20 06:45:52 oj 1.59.2.7: RESYNC: (1.66-1.67); FILE MERGED
 2006/03/21 18:24:21 fs 1.59.2.6: RESYNC: (1.64-1.66); FILE MERGED
 2005/11/23 10:15:05 fs 1.59.2.5: RESYNC: (1.63-1.64); FILE MERGED
 2005/10/13 14:52:19 fs 1.59.2.4: RESYNC: (1.62-1.63); FILE MERGED
 2005/09/30 06:15:47 fs 1.59.2.3: RESYNC: (1.59-1.62); FILE MERGED
 2005/04/06 09:53:33 fs 1.59.2.2: #i10000#
 2005/04/06 07:20:16 fs 1.59.2.1: #i46768# implement a Settings property, 
wrapping (as PropertyBag) the Info property

File Changes:

Directory: /dba/dbaccess/source/core/dataaccess/
================================================

File [changed]: datasource.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/dataaccess/datasource.cxx?r1=1.70&r2=1.71
Delta lines:  +146 -47
----------------------
--- datasource.cxx      10 Jul 2006 15:10:15 -0000      1.70
+++ datasource.cxx      15 Aug 2006 10:44:50 -0000      1.71
@@ -94,6 +94,18 @@
 #ifndef _COM_SUN_STAR_REFLECTION_XPROXYFACTORY_HPP_
 #include <com/sun/star/reflection/XProxyFactory.hpp>
 #endif
+#ifndef _COM_SUN_STAR_BEANS_NAMEDVALUE_HPP_
+#include <com/sun/star/beans/NamedValue.hpp>
+#endif
+#ifndef _COM_SUN_STAR_BEANS_XPROPERTYCONTAINER_HPP_
+#include <com/sun/star/beans/XPropertyContainer.hpp>
+#endif
+#ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_
+#include <com/sun/star/beans/PropertyAttribute.hpp>
+#endif
+#ifndef _COM_SUN_STAR_BEANS_PROPERTYSTATE_HPP_
+#include <com/sun/star/beans/PropertyState.hpp>
+#endif
 #ifndef _TYPELIB_TYPEDESCRIPTION_HXX_
 #include <typelib/typedescription.hxx>
 #endif
@@ -432,7 +444,7 @@
                Reference<XConnection> getConnection(   const rtl::OUString& 
url,
                                                                                
                const rtl::OUString& user,
                                                                                
                const rtl::OUString& password,
-                                                                               
                Sequence< PropertyValue >& _aInfo,
+                                                                               
                const Sequence< PropertyValue >& _aInfo,
                                                                                
                ODatabaseSource* _pDataSource);
                void addEventListener(const Reference<XConnection>& 
_rxConnection,TConnectionMap::iterator& _rIter);
        };
@@ -469,7 +481,7 @@
        Reference<XConnection> OSharedConnectionManager::getConnection( const 
rtl::OUString& url,
                                                                                
        const rtl::OUString& user,
                                                                                
        const rtl::OUString& password,
-                                                                               
        Sequence< PropertyValue >& _aInfo,
+                                                                               
        const Sequence< PropertyValue >& _aInfo,
                                                                                
        ODatabaseSource* _pDataSource)
        {
                MutexGuard aGuard(m_aMutex);
@@ -523,37 +535,16 @@
                osl_incrementInterlockedCount(&_rIter->second.nALiveCount);
        }
 
+    //----------------------------------------------------------------------
        namespace
        {
-               Sequence< PropertyValue > lcl_filterDriverProperties(const 
Reference< XDriver >& _xDriver,const ::rtl::OUString& _sUrl,const Sequence< 
PropertyValue >& _rDataSourceSettings)
+        //------------------------------------------------------------------
+        Sequence< PropertyValue > lcl_filterDriverProperties( const Reference< 
XDriver >& _xDriver, const ::rtl::OUString& _sUrl,
+            const Sequence< PropertyValue >& _rDataSourceSettings, const 
AsciiPropertyValue* _pKnownSettings )
                {
                        if ( _xDriver.is() )
                        {
                                Sequence< DriverPropertyInfo > 
aDriverInfo(_xDriver->getPropertyInfo(_sUrl,_rDataSourceSettings));
-                               const char* pKnownSettings[] = {
-                                            // known JDBC settings
-                                            "JavaDriverClass",
-                                            // known settings for file-based 
drivers
-                                            "Extension", "CharSet", 
"HeaderLine",
-                                            "FieldDelimiter", 
"StringDelimiter", "DecimalDelimiter",
-                                            "ThousandDelimiter", "ShowDeleted",
-                                            // known ODBC settings
-                                            "SystemDriverSettings", 
"UseCatalog",
-                                            // settings related to auto 
increment handling
-                                            "AutoIncrementCreation", 
"AutoRetrievingStatement", "IsAutoRetrievingEnabled",
-                                            // known Adabas driver setting
-                                            "ShutdownDatabase", 
"DataCacheSizeIncrement", "DataCacheSize",
-                                            "ControlUser", "ControlPassword",
-                                            // known LDAP driver settings
-                                            "HostName", "PortNumber", 
"BaseDN", "MaxRowCount"
-                                            // misc known driver settings
-                                            "ParameterNameSubstitution", 
"AddIndexAppendix",
-                                            // known SDB level settings
-                                            "IgnoreDriverPrivileges", 
"NoNameLengthLimit", "AppendTableAliasName",
-                                            "EnableSQL92Check", 
"BooleanComparisonMode", "TableTypeFilterMode",
-                                            "RespectDriverResultSetType", 
"UseSchemaInSelect", "UseCatalogInSelect"
-                                                                               
};
-                               sal_Int32 nKnownSettings = 
sizeof(pKnownSettings) / sizeof(pKnownSettings[0]);
 
                                const PropertyValue* pDataSourceSetting = 
_rDataSourceSettings.getConstArray();
                                const PropertyValue* pEnd = pDataSourceSetting 
+ _rDataSourceSettings.getLength();
@@ -563,17 +554,17 @@
                                for ( ; pDataSourceSetting != pEnd ; 
++pDataSourceSetting )
                                {
                                        sal_Bool bAllowSetting = sal_False;
-                                       sal_Int32 i;
-                                       for ( i=0; i < nKnownSettings; ++i )
+                    const AsciiPropertyValue* pSetting = _pKnownSettings;
+                                       for ( ; pSetting->AsciiName; ++pSetting 
)
                                        {
-                                               if ( 
!pDataSourceSetting->Name.compareToAscii( pKnownSettings[i] ) )
-                                               {   // the particular setting 
is known
+                                               if ( 
!pDataSourceSetting->Name.compareToAscii( pSetting->AsciiName ) )
+                                               {   // the particular data 
source setting is known
 
                             const DriverPropertyInfo* pAllowedDriverSetting = 
aDriverInfo.getConstArray();
                                                        const 
DriverPropertyInfo* pDriverSettingsEnd = pAllowedDriverSetting + 
aDriverInfo.getLength();
                                                        for ( ; 
pAllowedDriverSetting != pDriverSettingsEnd; ++pAllowedDriverSetting )
                                                        {
-                                                               if ( 
!pAllowedDriverSetting->Name.compareToAscii( pKnownSettings[i] ) )
+                                                               if ( 
!pAllowedDriverSetting->Name.compareToAscii( pSetting->AsciiName ) )
                                                                {   // the 
driver also allows this setting
                                                                        
bAllowSetting = sal_True;
                                                                        break;
@@ -582,7 +573,7 @@
                                                        break;
                                                }
                                        }
-                                       if ( bAllowSetting || ( i == 
nKnownSettings ) )
+                                       if ( bAllowSetting || 
!pSetting->AsciiName )
                                        {   // if the driver allows this 
particular setting, or if the setting is completely unknown,
                         // we pass it to the driver
                                                aRet.push_back( 
*pDataSourceSetting );
@@ -593,6 +584,15 @@
                        }
                        return Sequence< PropertyValue >();
                }
+
+        //------------------------------------------------------------------
+        struct CheckForDefaultPropertyValue : public ::std::unary_function< 
PropertyValue, bool >
+        {
+            bool operator()( const PropertyValue& _rProp )
+            {
+                return _rProp.State == PropertyState_DEFAULT_VALUE;
+            }
+        };
        }
 //============================================================
 //= ODatabaseContext
@@ -814,7 +814,12 @@
                        nExceptionMessageId = RID_STR_COULDNOTCONNECT_NODRIVER;
                else
                {
-                       Sequence< PropertyValue > aDriverInfo = 
lcl_filterDriverProperties(xDriver,m_pImpl->m_sConnectURL,m_pImpl->m_aInfo);
+                       Sequence< PropertyValue > aDriverInfo = 
lcl_filterDriverProperties(
+                xDriver,
+                m_pImpl->m_sConnectURL,
+                m_pImpl->m_xSettings->getPropertyValues(),
+                m_pImpl->getDefaultDataSourceSettings()
+            );
 
                        if ( m_pImpl->isEmbeddedDatabase() )
                        {
@@ -870,14 +875,15 @@
 
//------------------------------------------------------------------------------
 ::cppu::IPropertyArrayHelper* ODatabaseSource::createArrayHelper( ) const
 {
-       BEGIN_PROPERTY_HELPER(12)
-               DECL_PROP1(INFO,                                                
Sequence< PropertyValue >,BOUND);
+       BEGIN_PROPERTY_HELPER(13)
+               DECL_PROP1(INFO,                                                
Sequence< PropertyValue >,  BOUND);
                DECL_PROP1_BOOL(ISPASSWORDREQUIRED,                             
                                        BOUND);
                DECL_PROP1_BOOL(ISREADONLY,                                     
                                                READONLY);
-               DECL_PROP1(LAYOUTINFORMATION,                   Sequence< 
::com::sun::star::beans::PropertyValue >,BOUND);
+               DECL_PROP1(LAYOUTINFORMATION,                   Sequence< 
PropertyValue >,  BOUND);
                DECL_PROP1(NAME,                                                
::rtl::OUString,                        READONLY);
                DECL_PROP2_IFACE(NUMBERFORMATSSUPPLIER, XNumberFormatsSupplier, 
        READONLY, TRANSIENT);
                DECL_PROP1(PASSWORD,                                    
::rtl::OUString,                        TRANSIENT);
+               DECL_PROP2_IFACE(SETTINGS,              XPropertySet,           
    BOUND, READONLY);
                DECL_PROP1_BOOL(SUPPRESSVERSIONCL,                              
                                        BOUND);
                DECL_PROP1(TABLEFILTER,                                 
Sequence< ::rtl::OUString >,BOUND);
                DECL_PROP1(TABLETYPEFILTER,                             
Sequence< ::rtl::OUString >,BOUND);
@@ -943,11 +949,11 @@
                                            throw IllegalArgumentException();
                            }
 
-
-                           bModified = m_pImpl->m_aInfo.getLength() != 
aValues.getLength();
+                Sequence< PropertyValue > aSettings = 
m_pImpl->m_xSettings->getPropertyValues();
+                bModified = aSettings.getLength() != aValues.getLength();
                            if ( !bModified )
                            {
-                                   const PropertyValue* pInfoIter = 
m_pImpl->m_aInfo.getConstArray();
+                    const PropertyValue* pInfoIter = aSettings.getConstArray();
                                    const PropertyValue* checkValue = 
aValues.getConstArray();
                                    for ( ;!bModified && checkValue != valueEnd 
; ++checkValue,++pInfoIter)
                                    {
@@ -960,16 +966,90 @@
                            }
 
                            rConvertedValue = rValue;
-                           rOldValue <<= m_pImpl->m_aInfo;
-                   }   break;
+                rOldValue <<= aSettings;
+            }
+            break;
                    default:
-                           DBG_ERROR("unknown Property");
+                DBG_ERROR( "ODatabaseSource::convertFastPropertyValue: unknown 
or readonly Property!" );
            }
     }
        return bModified;
 }
 
 
//------------------------------------------------------------------------------
+namespace
+{
+    struct SelectPropertyName : public ::std::unary_function< PropertyValue, 
::rtl::OUString >
+    {
+    public:
+        const ::rtl::OUString& operator()( const PropertyValue& _lhs )
+        {
+            return _lhs.Name;
+        }
+    };
+
+    /** sets a new set of property values at a given property bag instance
+
+        The methods takes a property bag, and a sequence of property values to 
set at this bag.
+        Upon return, every property which is not part of the given sequence is
+        <ul><li>removed from the bag, if it's a removeable property</li>
+            <li><em>or</em>reset to its default value, if it's not a 
removeable property</li>
+        </ul>.
+
+        @param  _rxPropertyBag
+            the property bag to operate on
+        @param  _rAllNewPropertyValues
+            the new property values to set at the bag
+    */
+    void lcl_setPropertyValues_resetOrRemoveOther( const Reference< 
XPropertyAccess >& _rxPropertyBag, const Sequence< PropertyValue >& 
_rAllNewPropertyValues )
+    {
+        // sequences are ugly to operate on
+        typedef ::std::set< ::rtl::OUString >   StringSet;
+        StringSet aToBeSetPropertyNames;
+        ::std::transform(
+            _rAllNewPropertyValues.getConstArray(),
+            _rAllNewPropertyValues.getConstArray() + 
_rAllNewPropertyValues.getLength(),
+            ::std::insert_iterator< StringSet >( aToBeSetPropertyNames, 
aToBeSetPropertyNames.end() ),
+            SelectPropertyName()
+        );
+
+        try
+        {
+            // obtain all properties currently known at the bag
+            Reference< XPropertySet > xPropertySet( _rxPropertyBag, 
UNO_QUERY_THROW );
+            Reference< XPropertySetInfo > xPSI( 
xPropertySet->getPropertySetInfo(), UNO_QUERY_THROW );
+            Sequence< Property > aAllExistentProperties( xPSI->getProperties() 
);
+
+            Reference< XPropertyState > xPropertyState( _rxPropertyBag, 
UNO_QUERY_THROW );
+            Reference< XPropertyContainer > xPropertyContainer( 
_rxPropertyBag, UNO_QUERY_THROW );
+
+            // loop through them, and reset resp. default properties which are 
not to be set
+            const Property* pExistentProperty( 
aAllExistentProperties.getConstArray() );
+            const Property* pExistentPropertyEnd( 
aAllExistentProperties.getConstArray() + aAllExistentProperties.getLength() );
+            for ( ; pExistentProperty != pExistentPropertyEnd; 
++pExistentProperty )
+            {
+                if ( aToBeSetPropertyNames.find( pExistentProperty->Name ) != 
aToBeSetPropertyNames.end() )
+                    continue;
+
+                // this property is not to be set, but currently exists in the 
bag.
+                // -> Remove, respectively default, it
+                if ( ( pExistentProperty->Attributes & 
PropertyAttribute::REMOVEABLE ) != 0 )
+                    xPropertyContainer->removeProperty( 
pExistentProperty->Name );
+                else
+                    xPropertyState->setPropertyToDefault( 
pExistentProperty->Name );
+            }
+
+            // finally, set the new property values
+            _rxPropertyBag->setPropertyValues( _rAllNewPropertyValues );
+        }
+        catch( const Exception& )
+        {
+               DBG_UNHANDLED_EXCEPTION();
+        }
+    }
+}
+
+//------------------------------------------------------------------------------
 void ODatabaseSource::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, 
const Any& rValue ) throw (Exception)
 {
     if ( m_pImpl.is() )
@@ -1000,7 +1080,11 @@
                            rValue >>= m_pImpl->m_sConnectURL;
                            break;
                    case PROPERTY_ID_INFO:
-                           rValue >>= m_pImpl->m_aInfo;
+            {
+                Sequence< PropertyValue > aInfo;
+                OSL_VERIFY( rValue >>= aInfo );
+                lcl_setPropertyValues_resetOrRemoveOther( 
m_pImpl->m_xSettings, aInfo );
+            }
                            break;
                    case PROPERTY_ID_LAYOUTINFORMATION:
                            rValue >>= m_pImpl->m_aLayoutInformation;
@@ -1039,7 +1123,21 @@
                            rValue = bool2any(m_pImpl->m_bReadOnly);
                            break;
                    case PROPERTY_ID_INFO:
-                           rValue <<= m_pImpl->m_aInfo;
+            {
+                Sequence< PropertyValue > aValues( 
m_pImpl->m_xSettings->getPropertyValues() );
+                Sequence< PropertyValue > aNonDefaultValues( 
aValues.getLength() );
+                const PropertyValue* pCopyEnd = ::std::remove_copy_if(
+                    aValues.getConstArray(),
+                    aValues.getConstArray() + aValues.getLength(),
+                    aNonDefaultValues.getArray(),
+                    CheckForDefaultPropertyValue()
+                );
+                aNonDefaultValues.realloc( pCopyEnd - 
aNonDefaultValues.getArray() );
+                rValue <<= aNonDefaultValues;
+            }
+            break;
+            case PROPERTY_ID_SETTINGS:
+                rValue <<= m_pImpl->m_xSettings;
                            break;
                    case PROPERTY_ID_URL:
                            rValue <<= m_pImpl->m_sConnectURL;
@@ -1203,7 +1301,8 @@
                        m_pImpl->m_pSharedConnectionManager = new 
OSharedConnectionManager(m_pImpl->m_xServiceFactory);
                        m_pImpl->m_xSharedConnectionManager = 
m_pImpl->m_pSharedConnectionManager;
                }
-               xConn = 
m_pImpl->m_pSharedConnectionManager->getConnection(m_pImpl->m_sConnectURL,user,password,m_pImpl->m_aInfo,this);
+               xConn = m_pImpl->m_pSharedConnectionManager->getConnection(
+            m_pImpl->m_sConnectURL, user, password, 
m_pImpl->m_xSettings->getPropertyValues(), this );
        }
 
        if ( xConn.is() )




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

Reply via email to