Tag: cws_dev300_odbmacros3
User: fs      
Date: 2008-07-23 10:05:09+0000
Modified:
   dba/dbaccess/source/core/dataaccess/databasecontext.cxx

Log:
 #i76128# support for XLoadable at the database document

File Changes:

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

File [changed]: databasecontext.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/dataaccess/databasecontext.cxx?r1=1.43&r2=1.43.4.1
Delta lines:  +20 -12
---------------------
--- databasecontext.cxx 2008-06-25 12:31:13+0000        1.43
+++ databasecontext.cxx 2008-07-23 10:05:05+0000        1.43.4.1
@@ -7,7 +7,7 @@
  * OpenOffice.org - a multi-platform office productivity suite
  *
  * $RCSfile: databasecontext.cxx,v $
- * $Revision: 1.43 $
+ * $Revision: 1.43.4.1 $
  *
  * This file is part of OpenOffice.org.
  *
@@ -193,7 +193,14 @@
 Reference< XInterface > SAL_CALL ODatabaseContext::createInstance(  ) throw 
(Exception, RuntimeException)
 {
        ::rtl::Reference<ODatabaseModelImpl> pImpl( new ODatabaseModelImpl( 
m_aContext.getLegacyServiceFactory(), *this ) );
-    Reference< XDataSource > xDataSource( pImpl->getDataSource() );
+    Reference< XDataSource > xDataSource( pImpl->getOrCreateDataSource() );
+
+    // for convenience of the API user, we ensure the document is fully 
initialized (effectively: XLoadable::initNew
+    // has been called at the DatabaseDocument).
+    // We delete this to the ODatabaseModelImpl, which can create and 
initialize the DatabaseDocument instance
+    // itself. This instance is then immediately closed, since it's not needed 
anymore.
+    ::utl::CloseableComponent aEnsureClose( 
pImpl->createNewModel_deliverOwnership( true ) );
+
     return xDataSource.get();
 }
 
@@ -233,7 +240,6 @@
                        ++aIter
                )
        {
-               OSL_ENSURE(aIter->second->m_refCount != 0,"Object is already 
disposed");
                aIter->second->dispose();
        }
        m_aDatabaseObjects.clear();
@@ -333,22 +339,24 @@
     {
                pExistent.set( new ODatabaseModelImpl( _rName, 
m_aContext.getLegacyServiceFactory(), *this ) );
 
+           Reference< XModel > xModel( 
pExistent->createNewModel_deliverOwnership( false ), UNO_SET_THROW );
+        Reference< XLoadable > xLoad( xModel, UNO_QUERY_THROW );
+
         ::comphelper::NamedValueCollection aArgs;
         aArgs.put( "FileName", _sURL );
         aArgs.put( "MacroExecutionMode", MacroExecMode::USE_CONFIG );
         aArgs.put( "InteractionHandler", m_aContext.createComponent( 
"com.sun.star.sdb.InteractionHandler" ) );
 
-           Reference< XModel > xModel = 
pExistent->createNewModel_deliverOwnership();
-        DBG_ASSERT( xModel.is(), "ODatabaseContext::loadObjectFromURL: no 
model?" );
-
-        xModel->attachResource( _sURL, aArgs.getPropertyValues() );
+        Sequence< PropertyValue > aResource( aArgs.getPropertyValues() );
+        xLoad->load( aResource );
+        xModel->attachResource( _sURL, aResource );
 
         ::utl::CloseableComponent aEnsureClose( xModel );
     }
 
     setTransientProperties( _sURL, *pExistent );
 
-    return pExistent->getDataSource().get();
+    return pExistent->getOrCreateDataSource().get();
 }
 // 
-----------------------------------------------------------------------------
 void ODatabaseContext::setTransientProperties(const ::rtl::OUString& _sURL, 
ODatabaseModelImpl& _rDataSourceModel )
@@ -358,7 +366,7 @@
     try
     {
         ::rtl::OUString sAuthFailedPassword;
-           Reference< XPropertySet > xDSProps( 
_rDataSourceModel.getDataSource(), UNO_QUERY_THROW );
+           Reference< XPropertySet > xDSProps( 
_rDataSourceModel.getOrCreateDataSource(), UNO_QUERY_THROW );
                const Sequence< PropertyValue >& rSessionPersistentProps = 
m_aDatasourceProperties[_sURL];
                const PropertyValue* pProp = 
rSessionPersistentProps.getConstArray();
                const PropertyValue* pPropsEnd = 
rSessionPersistentProps.getConstArray() + rSessionPersistentProps.getLength();
@@ -428,7 +436,7 @@
 
//------------------------------------------------------------------------------
 void ODatabaseContext::storeTransientProperties( ODatabaseModelImpl& 
_rModelImpl)
 {
-    Reference< XPropertySet > xSource(_rModelImpl.getDataSource(),UNO_QUERY);
+    Reference< XPropertySet > xSource( _rModelImpl.getOrCreateDataSource(), 
UNO_QUERY );
     ::comphelper::NamedValueCollection aRememberProps;
 
        try
@@ -641,7 +649,7 @@
        ObjectCacheIterator aFind = m_aDatabaseObjects.find(_rName);
        Reference< XInterface > xExistent;
        if ( aFind != m_aDatabaseObjects.end() )
-               xExistent = aFind->second->getDataSource();
+               xExistent = aFind->second->getOrCreateDataSource();
        return xExistent;
 }
 // 
-----------------------------------------------------------------------------




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

Reply via email to