summaryrefslogtreecommitdiff
path: root/dbaccess
diff options
context:
space:
mode:
Diffstat (limited to 'dbaccess')
-rw-r--r--dbaccess/inc/IEnvironment.hxx32
-rw-r--r--dbaccess/inc/genericcontroller.hxx24
-rw-r--r--dbaccess/inc/singledoccontroller.hxx22
-rw-r--r--dbaccess/qa/complex/dbaccess/ApplicationController.java203
-rw-r--r--dbaccess/qa/complex/dbaccess/dbaccess.sce1
-rw-r--r--dbaccess/source/core/api/RowSet.cxx2
-rw-r--r--dbaccess/source/core/api/RowSetCache.cxx4
-rw-r--r--dbaccess/source/core/api/SingleSelectQueryComposer.cxx1
-rw-r--r--dbaccess/source/core/api/preparedstatement.cxx3
-rw-r--r--dbaccess/source/core/api/query.cxx2
-rw-r--r--dbaccess/source/core/dataaccess/ComponentDefinition.cxx4
-rw-r--r--dbaccess/source/core/dataaccess/ContentHelper.cxx1
-rw-r--r--dbaccess/source/core/dataaccess/ModelImpl.cxx2924
-rw-r--r--dbaccess/source/core/dataaccess/ModelImpl.hxx1313
-rw-r--r--dbaccess/source/core/dataaccess/databasecontext.cxx2
-rw-r--r--dbaccess/source/core/dataaccess/databasedocument.cxx39
-rw-r--r--dbaccess/source/core/dataaccess/datasource.cxx4
-rw-r--r--dbaccess/source/core/dataaccess/documentcontainer.cxx4
-rw-r--r--dbaccess/source/core/dataaccess/documentdefinition.cxx4
-rw-r--r--dbaccess/source/core/dataaccess/documenteventnotifier.cxx9
-rw-r--r--dbaccess/source/core/inc/ContentHelper.hxx3
-rw-r--r--dbaccess/source/core/misc/dsntypes.cxx5
-rw-r--r--dbaccess/source/filter/xml/xmlExport.cxx105
-rw-r--r--dbaccess/source/filter/xml/xmlfilter.cxx30
-rw-r--r--dbaccess/source/ui/app/AppController.cxx210
-rw-r--r--dbaccess/source/ui/app/AppController.hxx66
-rw-r--r--dbaccess/source/ui/app/AppControllerDnD.cxx75
-rw-r--r--dbaccess/source/ui/app/AppControllerGen.cxx181
-rw-r--r--dbaccess/source/ui/app/AppDetailPageHelper.cxx63
-rw-r--r--dbaccess/source/ui/app/AppDetailPageHelper.hxx12
-rw-r--r--dbaccess/source/ui/app/IApplicationController.hxx32
-rw-r--r--dbaccess/source/ui/app/makefile.mk5
-rw-r--r--dbaccess/source/ui/app/subcomponentmanager.cxx432
-rw-r--r--dbaccess/source/ui/app/subcomponentmanager.hxx115
-rw-r--r--dbaccess/source/ui/browser/brwctrlr.cxx6
-rw-r--r--dbaccess/source/ui/browser/dbloader.cxx4
-rw-r--r--dbaccess/source/ui/browser/dbtreeview.cxx4
-rw-r--r--dbaccess/source/ui/browser/dbtreeview.hxx2
-rw-r--r--dbaccess/source/ui/browser/dsbrowserDnD.cxx12
-rw-r--r--dbaccess/source/ui/browser/genericcontroller.cxx51
-rw-r--r--dbaccess/source/ui/browser/unodatbr.cxx64
-rw-r--r--dbaccess/source/ui/control/dbtreelistbox.cxx108
-rw-r--r--dbaccess/source/ui/dlg/dbadmin.src15
-rw-r--r--dbaccess/source/ui/dlg/paramdialog.cxx5
-rw-r--r--dbaccess/source/ui/inc/QueryDesignView.hxx13
-rw-r--r--dbaccess/source/ui/inc/QueryViewSwitch.hxx21
-rw-r--r--dbaccess/source/ui/inc/RTableConnectionData.hxx3
-rw-r--r--dbaccess/source/ui/inc/UITools.hxx8
-rw-r--r--dbaccess/source/ui/inc/WNameMatch.hxx4
-rw-r--r--dbaccess/source/ui/inc/datasourceconnector.hxx22
-rw-r--r--dbaccess/source/ui/inc/dbtreelistbox.hxx63
-rw-r--r--dbaccess/source/ui/inc/querycontainerwindow.hxx9
-rw-r--r--dbaccess/source/ui/inc/querycontroller.hxx11
-rw-r--r--dbaccess/source/ui/inc/unodatbr.hxx7
-rw-r--r--dbaccess/source/ui/misc/UITools.cxx21
-rw-r--r--dbaccess/source/ui/misc/WNameMatch.cxx4
-rw-r--r--dbaccess/source/ui/misc/databaseobjectview.cxx17
-rw-r--r--dbaccess/source/ui/misc/datasourceconnector.cxx94
-rw-r--r--dbaccess/source/ui/misc/dsmeta.cxx6
-rw-r--r--dbaccess/source/ui/misc/singledoccontroller.cxx65
-rw-r--r--dbaccess/source/ui/querydesign/JoinController.cxx2
-rw-r--r--dbaccess/source/ui/querydesign/QueryDesignView.cxx55
-rw-r--r--dbaccess/source/ui/querydesign/QueryViewSwitch.cxx35
-rw-r--r--dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx37
-rw-r--r--dbaccess/source/ui/querydesign/querycontainerwindow.cxx4
-rw-r--r--dbaccess/source/ui/querydesign/querycontroller.cxx158
-rw-r--r--dbaccess/source/ui/tabledesign/TableController.cxx2
-rw-r--r--dbaccess/source/ui/uno/unoDirectSql.cxx2
68 files changed, 3783 insertions, 3083 deletions
diff --git a/dbaccess/inc/IEnvironment.hxx b/dbaccess/inc/IEnvironment.hxx
index 18652be7781b..4ea2a5e7dbb6 100644
--- a/dbaccess/inc/IEnvironment.hxx
+++ b/dbaccess/inc/IEnvironment.hxx
@@ -30,38 +30,46 @@
#ifndef DBAUI_IENVIRONMENT_HXX
#define DBAUI_IENVIRONMENT_HXX
-#ifndef _COM_SUN_STAR_SDBC_SQLEXCEPTION_HPP_
#include <com/sun/star/sdbc/SQLException.hpp>
-#endif
+
+#include <connectivity/standardsqlstate.hxx>
+
+namespace dbtools
+{
+ class SQLExceptionInfo;
+}
namespace dbaui
{
// interface class for a generell environment
class IEnvironment
{
- protected:
public:
/** appends an error in the current environment.
- @param _aException
- contains a description of the error or the error directly
*/
- virtual void appendError(const ::com::sun::star::sdbc::SQLException& _aException) = 0;
+ virtual void appendError(
+ const ::rtl::OUString& _rErrorMessage,
+ const ::dbtools::StandardSQLState _eSQLState = ::dbtools::SQL_GENERAL_ERROR,
+ const sal_Int32 _nErrorCode = 1000
+ ) = 0;
/** clears the error state.
*/
virtual void clearError() = 0;
- /** set the current error in the given parameter.
- @param _rException
- will contain the current error
- */
- virtual void getError(::com::sun::star::sdbc::SQLException& _rException ) const = 0;
-
/** @retrun
returns <TRUE/> when an error was set otherwise <FALSE/>
*/
virtual sal_Bool hasError() const = 0;
+ /** returns the current error
+ */
+ virtual const ::dbtools::SQLExceptionInfo& getError() const = 0;
+
+ /** displays the current error, or does nothing if there is no current error
+ */
+ virtual void displayError() = 0;
+
/** gives access to the currently used connection
@return
the currently used connection.
diff --git a/dbaccess/inc/genericcontroller.hxx b/dbaccess/inc/genericcontroller.hxx
index df84edac9d52..190cd8485713 100644
--- a/dbaccess/inc/genericcontroller.hxx
+++ b/dbaccess/inc/genericcontroller.hxx
@@ -59,6 +59,7 @@
/** === end UNO includes === **/
#include <comphelper/broadcasthelper.hxx>
+#include <comphelper/sharedmutex.hxx>
#include <comphelper/namedvaluecollection.hxx>
#include <comphelper/stl_types.hxx>
#include <connectivity/dbexception.hxx>
@@ -68,6 +69,11 @@
#include <boost/optional.hpp>
#include <sfx2/userinputinterception.hxx>
+namespace dbtools
+{
+ class SQLExceptionInfo;
+}
+
class Window;
class VCLXWindow;
namespace dbaui
@@ -179,7 +185,7 @@ namespace dbaui
};
// ....................................................................
- typedef ::comphelper::OBaseMutex OGenericUnoController_MBASE;
+ typedef ::comphelper::SharedMutexBase OGenericUnoController_MBASE;
typedef ::cppu::WeakComponentImplHelper11 < ::com::sun::star::frame::XDispatch
, ::com::sun::star::frame::XDispatchProviderInterceptor
@@ -255,8 +261,8 @@ namespace dbaui
// ----------------------------------------------------------------
// attribute access
- ::osl::Mutex& getMutex( ) { return OGenericUnoController_MBASE::m_aMutex; }
- ::cppu::OBroadcastHelper& getBroadcastHelper() { return OGenericUnoController_Base::rBHelper; }
+ ::osl::Mutex& getMutex() const { return OGenericUnoController_MBASE::getMutex(); }
+ ::cppu::OBroadcastHelper& getBroadcastHelper() { return OGenericUnoController_Base::rBHelper; }
// ----------------------------------------------------------------
// methods
@@ -347,21 +353,15 @@ namespace dbaui
// connect to a datasource
::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > connect(
- const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDataSource>& _xDataSource
- ,sal_Bool _bStartListening = sal_False
- );
-
- // connect to a datasource
- ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > connect(
- const ::rtl::OUString& _rDataSourceName,
- sal_Bool _bStartListening = sal_False
+ const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDataSource>& _xDataSource,
+ ::dbtools::SQLExceptionInfo* _pErrorInfo
);
// connect to a datasource
::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > connect(
const ::rtl::OUString& _rsDataSourceName,
const ::rtl::OUString& _rContextInformation,
- sal_Bool _bStartListening = sal_False
+ ::dbtools::SQLExceptionInfo* _pErrorInfo
);
void startConnectionListening(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection);
diff --git a/dbaccess/inc/singledoccontroller.hxx b/dbaccess/inc/singledoccontroller.hxx
index 7c22bd301837..f63d1c02fdf2 100644
--- a/dbaccess/inc/singledoccontroller.hxx
+++ b/dbaccess/inc/singledoccontroller.hxx
@@ -136,26 +136,30 @@ namespace dbaui
// IEnvironment
/** appends an error in the current environment.
- @param _aException
- contains a description of the error or the error directly
*/
- virtual void appendError(const ::com::sun::star::sdbc::SQLException& _aException);
+ virtual void appendError(
+ const ::rtl::OUString& _rErrorMessage,
+ const ::dbtools::StandardSQLState _eSQLState = ::dbtools::SQL_GENERAL_ERROR,
+ const sal_Int32 _nErrorCode = 1000
+ );
/** clears the error state.
*/
virtual void clearError();
- /** set the current error in the given parameter.
- @param _rException
- will contain the current error
- */
- virtual void getError(::com::sun::star::sdbc::SQLException& _rException ) const;
-
/** @return
<TRUE/> when an error was set otherwise <FALSE/>
*/
virtual sal_Bool hasError() const;
+ /** returns the current error
+ */
+ virtual const ::dbtools::SQLExceptionInfo& getError() const;
+
+ /** displays the current error, or does nothing if there is no current error
+ */
+ virtual void displayError();
+
/** shows an info box with the string conntection lost.
*/
void connectionLostMessage() const;
diff --git a/dbaccess/qa/complex/dbaccess/ApplicationController.java b/dbaccess/qa/complex/dbaccess/ApplicationController.java
new file mode 100644
index 000000000000..41bf379f7a91
--- /dev/null
+++ b/dbaccess/qa/complex/dbaccess/ApplicationController.java
@@ -0,0 +1,203 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: ApplicationController.java,v $
+ * $Revision: 1.1.2.1 $
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+package complex.dbaccess;
+
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.container.XNameAccess;
+import com.sun.star.frame.FrameSearchFlag;
+import com.sun.star.frame.XComponentLoader;
+import com.sun.star.frame.XModel;
+import com.sun.star.frame.XStorable;
+import com.sun.star.lang.XComponent;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.sdb.XOfficeDatabaseDocument;
+import com.sun.star.sdb.application.XDatabaseDocumentUI;
+import com.sun.star.sdbcx.XTablesSupplier;
+import com.sun.star.uno.Exception;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XComponentContext;
+import connectivity.tools.HsqlColumnDescriptor;
+import connectivity.tools.HsqlDatabase;
+import connectivity.tools.HsqlTableDescriptor;
+import helper.URLHelper;
+import java.io.File;
+import java.io.IOException;
+
+/** complex test case for Base's application UI
+ */
+public class ApplicationController extends complexlib.ComplexTestCase
+{
+ private HsqlDatabase m_database;
+ private XOfficeDatabaseDocument m_databaseDocument;
+ private XDatabaseDocumentUI m_documentUI;
+
+ public ApplicationController()
+ {
+ super();
+ }
+
+ // --------------------------------------------------------------------------------------------------------
+ public String[] getTestMethodNames()
+ {
+ return new String[] {
+ "checkSaveAs"
+ };
+ }
+
+ // --------------------------------------------------------------------------------------------------------
+ public String getTestObjectName()
+ {
+ return getClass().getName();
+ }
+
+ // --------------------------------------------------------------------------------------------------------
+ protected final XMultiServiceFactory getORB()
+ {
+ return (XMultiServiceFactory)param.getMSF();
+ }
+
+ // --------------------------------------------------------------------------------------------------------
+ protected final XComponentContext getComponentContext()
+ {
+ XComponentContext context = null;
+ try
+ {
+ XPropertySet orbProps = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, getORB() );
+ context = (XComponentContext)UnoRuntime.queryInterface( XComponentContext.class,
+ orbProps.getPropertyValue( "DefaultContext" ) );
+ }
+ catch ( Exception ex )
+ {
+ failed( "could not retrieve the ComponentContext" );
+ }
+ return context;
+ }
+
+ // --------------------------------------------------------------------------------------------------------
+ private void impl_closeDocument()
+ {
+ if ( m_database != null )
+ {
+ m_database.close();
+ m_database = null;
+ m_databaseDocument = null;
+ m_documentUI = null;
+ }
+ }
+
+ // --------------------------------------------------------------------------------------------------------
+ private void impl_switchToDocument( String _documentURL ) throws java.lang.Exception
+ {
+ // close previous database document
+ impl_closeDocument();
+
+ // create/load the new database document
+ m_database = ( _documentURL == null )
+ ? new HsqlDatabase( getORB() )
+ : new HsqlDatabase( getORB(), _documentURL );
+ m_databaseDocument = m_database.getDatabaseDocument();
+
+ // load it into a frame
+ Object object = getORB().createInstance( "com.sun.star.frame.Desktop" );
+ XComponentLoader xComponentLoader = (XComponentLoader)UnoRuntime.queryInterface( XComponentLoader.class, object );
+ XComponent loadedComponent = xComponentLoader.loadComponentFromURL( m_database.getDocumentURL(), "_blank", FrameSearchFlag.ALL, new PropertyValue[0] );
+
+ assure( "too many document instances!",
+ UnoRuntime.areSame( loadedComponent, m_databaseDocument ) );
+
+ // get the controller, which provides access to various UI operations
+ XModel docModel = (XModel)UnoRuntime.queryInterface( XModel.class,
+ loadedComponent );
+ m_documentUI = (XDatabaseDocumentUI)UnoRuntime.queryInterface( XDatabaseDocumentUI.class,
+ docModel.getCurrentController() );
+ }
+
+ // --------------------------------------------------------------------------------------------------------
+ public void before() throws Exception, java.lang.Exception
+ {
+ impl_switchToDocument( null );
+ }
+
+ // --------------------------------------------------------------------------------------------------------
+ public void after()
+ {
+ impl_closeDocument();
+ }
+
+ // --------------------------------------------------------------------------------------------------------
+ public void checkSaveAs() throws Exception, IOException, java.lang.Exception
+ {
+ // issue 93737 describes the problem that when you save-as a database document, and do changes to it,
+ // then those changes are saved in the old document, actually
+ String oldDocumentURL = m_database.getDocumentURL();
+
+ File documentFile = java.io.File.createTempFile( getTestObjectName(), ".odb" );
+ documentFile.deleteOnExit();
+ String newDocumentURL = URLHelper.getFileURLFromSystemPath( documentFile.getAbsoluteFile() );
+
+ // store the doc in a new location
+ XStorable storeDoc = (XStorable)UnoRuntime.queryInterface( XStorable.class,
+ m_databaseDocument );
+ storeDoc.storeAsURL( newDocumentURL, new PropertyValue[] {} );
+
+ // connect
+ m_documentUI.connect();
+ assure( "could not connect to " + m_database.getDocumentURL(), m_documentUI.isConnected() );
+
+ // create a table in the database
+ m_database.createTable( new HsqlTableDescriptor( "abc", new HsqlColumnDescriptor[] {
+ new HsqlColumnDescriptor( "a", "VARCHAR(50)" ),
+ new HsqlColumnDescriptor( "b", "VARCHAR(50)" ),
+ new HsqlColumnDescriptor( "c", "VARCHAR(50)" )
+ }
+ ) );
+
+ // load the old document, and verify there is *no* table therein
+ impl_switchToDocument( oldDocumentURL );
+ m_documentUI.connect();
+ assure( "could not connect to " + m_database.getDocumentURL(), m_documentUI.isConnected() );
+ XTablesSupplier suppTables = (XTablesSupplier)UnoRuntime.queryInterface( XTablesSupplier.class,
+ m_documentUI.getActiveConnection() );
+ XNameAccess tables = suppTables.getTables();
+ assure( "the table was created in the wrong database", !tables.hasByName( "abc" ) );
+
+ // load the new document, and verify there *is* a table therein
+ impl_switchToDocument( newDocumentURL );
+ m_documentUI.connect();
+ assure( "could not connect to " + m_database.getDocumentURL(), m_documentUI.isConnected() );
+
+ suppTables = (XTablesSupplier)UnoRuntime.queryInterface( XTablesSupplier.class,
+ m_documentUI.getActiveConnection() );
+ tables = suppTables.getTables();
+ assure( "the newly created table has not been written", tables.hasByName( "abc" ) );
+ }
+}
diff --git a/dbaccess/qa/complex/dbaccess/dbaccess.sce b/dbaccess/qa/complex/dbaccess/dbaccess.sce
index 3e0357af2727..b546f6ee7496 100644
--- a/dbaccess/qa/complex/dbaccess/dbaccess.sce
+++ b/dbaccess/qa/complex/dbaccess/dbaccess.sce
@@ -6,3 +6,4 @@
-o complex.dbaccess.DatabaseDocument
-o complex.dbaccess.DataSource
-o complex.dbaccess.Parser
+-o complex.dbaccess.ApplicationController
diff --git a/dbaccess/source/core/api/RowSet.cxx b/dbaccess/source/core/api/RowSet.cxx
index e2f14fcd9f8c..06e10a34405b 100644
--- a/dbaccess/source/core/api/RowSet.cxx
+++ b/dbaccess/source/core/api/RowSet.cxx
@@ -884,7 +884,7 @@ void SAL_CALL ORowSet::updateBinaryStream( sal_Int32 columnIndex, const Referenc
{
Sequence<sal_Int8> aSeq;
if(x.is())
- x->readSomeBytes(aSeq,length);
+ x->readBytes(aSeq,length);
updateValue(columnIndex,aSeq);
aOldValue = (*(*m_aCurrentRow))[columnIndex];
(*(*m_aCurrentRow))[columnIndex] = aSeq;
diff --git a/dbaccess/source/core/api/RowSetCache.cxx b/dbaccess/source/core/api/RowSetCache.cxx
index 33bb22dc2864..318b49e247bc 100644
--- a/dbaccess/source/core/api/RowSetCache.cxx
+++ b/dbaccess/source/core/api/RowSetCache.cxx
@@ -575,7 +575,7 @@ void ORowSetCache::updateBinaryStream( sal_Int32 columnIndex, const Reference< :
Sequence<sal_Int8> aSeq;
if(x.is())
- x->readSomeBytes(aSeq,length);
+ x->readBytes(aSeq,length);
updateValue(columnIndex,aSeq);
}
// -------------------------------------------------------------------------
@@ -586,7 +586,7 @@ void ORowSetCache::updateCharacterStream( sal_Int32 columnIndex, const Reference
Sequence<sal_Int8> aSeq;
if(x.is())
- x->readSomeBytes(aSeq,length);
+ x->readBytes(aSeq,length);
updateValue(columnIndex,aSeq);
}
diff --git a/dbaccess/source/core/api/SingleSelectQueryComposer.cxx b/dbaccess/source/core/api/SingleSelectQueryComposer.cxx
index 3eddeb562c3f..4dfd571f1148 100644
--- a/dbaccess/source/core/api/SingleSelectQueryComposer.cxx
+++ b/dbaccess/source/core/api/SingleSelectQueryComposer.cxx
@@ -1548,6 +1548,7 @@ void OSingleSelectQueryComposer::setConditionByColumn( const Reference< XPropert
::rtl::OUString sColumnExp = aSQL.makeStringAndClear();
getBoleanComparisonPredicate( sColumnExp, bValue, m_nBoolCompareMode, aSQL );
}
+ break;
default:
aSQL.append( STR_EQUAL );
aSQL.append( DBTypeConversion::toSQLString( nType, aValue, sal_True, m_xTypeConverter ) );
diff --git a/dbaccess/source/core/api/preparedstatement.cxx b/dbaccess/source/core/api/preparedstatement.cxx
index 48427e47faa6..761b27fc94ed 100644
--- a/dbaccess/source/core/api/preparedstatement.cxx
+++ b/dbaccess/source/core/api/preparedstatement.cxx
@@ -81,9 +81,10 @@ OPreparedStatement::OPreparedStatement(const Reference< XConnection > & _xConn,
:OStatementBase(_xConn, _xStatement)
{
DBG_CTOR(OPreparedStatement, NULL);
+ m_xAggregateAsParameters = Reference< XParameters >( m_xAggregateAsSet, UNO_QUERY_THROW );
+
Reference<XDatabaseMetaData> xMeta = _xConn->getMetaData();
m_pColumns = new OColumns(*this, m_aMutex, xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers(),::std::vector< ::rtl::OUString>(), NULL,NULL);
- m_xAggregateAsParameters = Reference< XParameters > (m_xAggregateAsSet, UNO_QUERY);
}
//--------------------------------------------------------------------------
diff --git a/dbaccess/source/core/api/query.cxx b/dbaccess/source/core/api/query.cxx
index 812d7bd85df5..a3a66290d5b5 100644
--- a/dbaccess/source/core/api/query.cxx
+++ b/dbaccess/source/core/api/query.cxx
@@ -138,7 +138,7 @@ OQuery::OQuery( const Reference< XPropertySet >& _rxCommandDefinition
,const Reference< XMultiServiceFactory >& _xORB)
:OContentHelper(_xORB,NULL,TContentPtr(new OContentHelper_Impl))
,OQueryDescriptor_Base(m_aMutex,*this)
- ,ODataSettings(m_aBHelper,sal_True)
+ ,ODataSettings(OContentHelper::rBHelper,sal_True)
,m_xCommandDefinition(_rxCommandDefinition)
,m_xConnection(_rxConn)
,m_pColumnMediator( NULL )
diff --git a/dbaccess/source/core/dataaccess/ComponentDefinition.cxx b/dbaccess/source/core/dataaccess/ComponentDefinition.cxx
index ea5524d89cd2..b26a7c46f9f9 100644
--- a/dbaccess/source/core/dataaccess/ComponentDefinition.cxx
+++ b/dbaccess/source/core/dataaccess/ComponentDefinition.cxx
@@ -147,7 +147,7 @@ OComponentDefinition::OComponentDefinition(const Reference< XMultiServiceFactory
,const TContentPtr& _pImpl
,sal_Bool _bTable)
:OContentHelper(_xORB,_xParentContainer,_pImpl)
- ,ODataSettings(m_aBHelper,!_bTable)
+ ,ODataSettings(OContentHelper::rBHelper,!_bTable)
,m_bTable(_bTable)
{
DBG_CTOR(OComponentDefinition, NULL);
@@ -166,7 +166,7 @@ OComponentDefinition::OComponentDefinition( const Reference< XInterface >& _rxCo
,const TContentPtr& _pImpl
,sal_Bool _bTable)
:OContentHelper(_xORB,_rxContainer,_pImpl)
- ,ODataSettings(m_aBHelper,!_bTable)
+ ,ODataSettings(OContentHelper::rBHelper,!_bTable)
,m_bTable(_bTable)
{
DBG_CTOR(OComponentDefinition, NULL);
diff --git a/dbaccess/source/core/dataaccess/ContentHelper.cxx b/dbaccess/source/core/dataaccess/ContentHelper.cxx
index a74e13f8eefa..e4c1d781d63b 100644
--- a/dbaccess/source/core/dataaccess/ContentHelper.cxx
+++ b/dbaccess/source/core/dataaccess/ContentHelper.cxx
@@ -667,6 +667,7 @@ void SAL_CALL OContentHelper::setParent( const Reference< XInterface >& _xParent
::osl::MutexGuard aGuard(m_aMutex);
m_xParentContainer = _xParent;
}
+
// -----------------------------------------------------------------------------
void SAL_CALL OContentHelper::rename( const ::rtl::OUString& newName ) throw (SQLException, ElementExistException, RuntimeException)
{
diff --git a/dbaccess/source/core/dataaccess/ModelImpl.cxx b/dbaccess/source/core/dataaccess/ModelImpl.cxx
index 7638609062d9..b3e329c6889a 100644
--- a/dbaccess/source/core/dataaccess/ModelImpl.cxx
+++ b/dbaccess/source/core/dataaccess/ModelImpl.cxx
@@ -1,1472 +1,1452 @@
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2008 by Sun Microsystems, Inc.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * $RCSfile: ModelImpl.cxx,v $
- * $Revision: 1.25.6.12 $
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-
-// MARKER(update_precomp.py): autogen include statement, do not remove
-#include "precompiled_dbaccess.hxx"
-
-#include "commandcontainer.hxx"
-#include "connection.hxx"
-#include "core_resource.hrc"
-#include "core_resource.hxx"
-#include "databasecontext.hxx"
-#include "databasedocument.hxx"
-#include "datasource.hxx"
-#include "dbastrings.hrc"
-#include "ModelImpl.hxx"
-#include "userinformation.hxx"
-
-/** === begin UNO includes === **/
-#include <com/sun/star/container/XSet.hpp>
-#include <com/sun/star/document/MacroExecMode.hpp>
-#include <com/sun/star/embed/XTransactedObject.hpp>
-#include <com/sun/star/embed/XTransactionBroadcaster.hpp>
-#include <com/sun/star/sdb/BooleanComparisonMode.hpp>
-#include <com/sun/star/script/DocumentScriptLibraryContainer.hpp>
-#include <com/sun/star/script/DocumentDialogLibraryContainer.hpp>
-#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
-#include <com/sun/star/form/XLoadable.hpp>
-/** === end UNO includes === **/
-
-#include <comphelper/interaction.hxx>
-#include <comphelper/mediadescriptor.hxx>
-#include <comphelper/namedvaluecollection.hxx>
-#include <comphelper/seqstream.hxx>
-#include <comphelper/sequence.hxx>
-#include <connectivity/dbexception.hxx>
-#include <cppuhelper/exc_hlp.hxx>
-#include <cppuhelper/typeprovider.hxx>
-#include <rtl/digest.h>
-#include <sfx2/signaturestate.hxx>
-#include <tools/debug.hxx>
-#include <tools/diagnose_ex.h>
-#include <tools/errcode.hxx>
-#include <tools/urlobj.hxx>
-#include <unotools/sharedunocomponent.hxx>
-
-#include <algorithm>
-
-using namespace ::com::sun::star::document;
-using namespace ::com::sun::star::sdbc;
-using namespace ::com::sun::star::sdbcx;
-using namespace ::com::sun::star::sdb;
-using namespace ::com::sun::star::beans;
-using namespace ::com::sun::star::uno;
-using namespace ::com::sun::star::lang;
-using namespace ::com::sun::star::embed;
-using namespace ::com::sun::star::container;
-using namespace ::com::sun::star::util;
-using namespace ::com::sun::star::io;
-using namespace ::com::sun::star::task;
-using namespace ::com::sun::star::ucb;
-using namespace ::com::sun::star::frame;
-using namespace ::com::sun::star::view;
-using namespace ::com::sun::star::task;
-using namespace ::com::sun::star::reflection;
-using namespace ::com::sun::star::script;
-using namespace ::cppu;
-using namespace ::osl;
-using namespace ::vos;
-using namespace ::dbtools;
-using namespace ::comphelper;
-namespace css = ::com::sun::star;
-
-//........................................................................
-namespace dbaccess
-{
-//........................................................................
-
-//========================================================================
-//= SharedMutex
-//========================================================================
-//------------------------------------------------------------------------
-SharedMutex::SharedMutex()
- :m_refCount( 0 )
-{
-}
-
-//------------------------------------------------------------------------
-SharedMutex::~SharedMutex()
-{
-}
-
-//------------------------------------------------------------------------
-void SAL_CALL SharedMutex::acquire()
-{
- osl_incrementInterlockedCount( &m_refCount );
-}
-
-//------------------------------------------------------------------------
-void SAL_CALL SharedMutex::release()
-{
- if ( 0 == osl_decrementInterlockedCount( &m_refCount ) )
- delete this;
-}
-
-//============================================================
-//= VosMutexFacade
-//============================================================
-//------------------------------------------------------------------------
-VosMutexFacade::VosMutexFacade( ::osl::Mutex& _rMutex )
- :m_rMutex( _rMutex )
-{
-}
-
-//------------------------------------------------------------------------
-void SAL_CALL VosMutexFacade::acquire()
-{
- m_rMutex.acquire();
-}
-
-//------------------------------------------------------------------------
-sal_Bool SAL_CALL VosMutexFacade::tryToAcquire()
-{
- return m_rMutex.tryToAcquire();
-}
-
-//------------------------------------------------------------------------
-void SAL_CALL VosMutexFacade::release()
-{
- m_rMutex.release();
-}
-
-//============================================================
-//= DocumentStorageAccess
-//============================================================
-DBG_NAME( DocumentStorageAccess )
-class DocumentStorageAccess : public ::cppu::WeakImplHelper2< XDocumentSubStorageSupplier
- , XTransactionListener >
-{
- typedef ::std::map< ::rtl::OUString, Reference< XStorage > > NamedStorages;
-
- ::osl::Mutex m_aMutex;
- /// all sub storages which we ever gave to the outer world
- NamedStorages m_aExposedStorages;
- ODatabaseModelImpl* m_pModelImplementation;
- bool m_bPropagateCommitToRoot;
-
-public:
- DocumentStorageAccess( ODatabaseModelImpl& _rModelImplementation )
- :m_pModelImplementation( &_rModelImplementation )
- ,m_bPropagateCommitToRoot( true )
- {
- DBG_CTOR( DocumentStorageAccess, NULL );
- }
-
-protected:
- ~DocumentStorageAccess()
- {
- DBG_DTOR( DocumentStorageAccess, NULL );
- }
-
-public:
- void dispose();
-
- void suspendCommitPropagation()
- {
- DBG_ASSERT( m_bPropagateCommitToRoot, "DocumentStorageAccess:: suspendCommitPropagation: already suspended" );
- m_bPropagateCommitToRoot = false;
- }
- void resumeCommitPropagation()
- {
- DBG_ASSERT( !m_bPropagateCommitToRoot, "DocumentStorageAccess:: suspendCommitPropagation: already suspended" );
- m_bPropagateCommitToRoot = true;
- }
-
- // XDocumentSubStorageSupplier
- virtual Reference< XStorage > SAL_CALL getDocumentSubStorage( const ::rtl::OUString& aStorageName, ::sal_Int32 nMode ) throw (RuntimeException);
- virtual Sequence< ::rtl::OUString > SAL_CALL getDocumentSubStoragesNames( ) throw (IOException, RuntimeException);
-
- // XTransactionListener
- virtual void SAL_CALL preCommit( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
- virtual void SAL_CALL commited( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
- virtual void SAL_CALL preRevert( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
- virtual void SAL_CALL reverted( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
-
- // XEventListener
- virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
-};
-
-//--------------------------------------------------------------------------
-void DocumentStorageAccess::dispose()
-{
- ::osl::MutexGuard aGuard( m_aMutex );
-
- for ( NamedStorages::iterator loop = m_aExposedStorages.begin();
- loop != m_aExposedStorages.end();
- ++loop
- )
- {
- try
- {
- Reference< XTransactionBroadcaster > xBroadcaster( loop->second, UNO_QUERY );
- if ( xBroadcaster.is() )
- xBroadcaster->removeTransactionListener( this );
- }
- catch( const Exception& )
- {
- DBG_UNHANDLED_EXCEPTION();
- }
- }
-
- m_aExposedStorages.clear();
-
- m_pModelImplementation = NULL;
-}
-
-//--------------------------------------------------------------------------
-Reference< XStorage > SAL_CALL DocumentStorageAccess::getDocumentSubStorage( const ::rtl::OUString& aStorageName, ::sal_Int32 nMode ) throw (RuntimeException)
-{
- ::osl::MutexGuard aGuard( m_aMutex );
- NamedStorages::iterator pos = m_aExposedStorages.find( aStorageName );
- if ( pos == m_aExposedStorages.end() )
- {
- Reference< XStorage > xResult = m_pModelImplementation->getStorage( aStorageName, nMode );
- Reference< XTransactionBroadcaster > xBroadcaster( xResult, UNO_QUERY );
- if ( xBroadcaster.is() )
- xBroadcaster->addTransactionListener( this );
-
- pos = m_aExposedStorages.insert( NamedStorages::value_type( aStorageName, xResult ) ).first;
- }
-
- return pos->second;
-}
-
-//--------------------------------------------------------------------------
-Sequence< ::rtl::OUString > SAL_CALL DocumentStorageAccess::getDocumentSubStoragesNames( ) throw (IOException, RuntimeException)
-{
- Reference< XStorage > xRootStor( m_pModelImplementation->getRootStorage() );
- if ( !xRootStor.is() )
- return Sequence< ::rtl::OUString >();
-
- ::std::vector< ::rtl::OUString > aNames;
-
- Reference< XNameAccess > xNames( xRootStor, UNO_QUERY_THROW );
- Sequence< ::rtl::OUString > aElementNames( xNames->getElementNames() );
- for ( sal_Int32 i=0; i<aElementNames.getLength(); ++i )
- {
- if ( xRootStor->isStorageElement( aElementNames[i] ) )
- aNames.push_back( aElementNames[i] );
- }
- return aNames.empty()
- ? Sequence< ::rtl::OUString >()
- : Sequence< ::rtl::OUString >( &aNames[0], aNames.size() );
-}
-
-//--------------------------------------------------------------------------
-void SAL_CALL DocumentStorageAccess::preCommit( const css::lang::EventObject& /*aEvent*/ ) throw (Exception, RuntimeException)
-{
- // not interested in
-}
-
-//--------------------------------------------------------------------------
-void SAL_CALL DocumentStorageAccess::commited( const css::lang::EventObject& aEvent ) throw (RuntimeException)
-{
- ::osl::MutexGuard aGuard( m_aMutex );
-
- if ( m_pModelImplementation )
- m_pModelImplementation->setModified( sal_True );
-
- if ( m_pModelImplementation && m_bPropagateCommitToRoot )
- {
- Reference< XStorage > xStorage( aEvent.Source, UNO_QUERY );
- if ( m_pModelImplementation->isDatabaseStorage( xStorage ) )
- {
- m_pModelImplementation->commitRootStorage();
- }
- }
-}
-
-//--------------------------------------------------------------------------
-void SAL_CALL DocumentStorageAccess::preRevert( const css::lang::EventObject& /*aEvent*/ ) throw (Exception, RuntimeException)
-{
- // not interested in
-}
-
-//--------------------------------------------------------------------------
-void SAL_CALL DocumentStorageAccess::reverted( const css::lang::EventObject& /*aEvent*/ ) throw (RuntimeException)
-{
- // not interested in
-}
-
-//--------------------------------------------------------------------------
-void SAL_CALL DocumentStorageAccess::disposing( const css::lang::EventObject& Source ) throw ( RuntimeException )
-{
- ODatabaseModelImpl* pImpl = m_pModelImplementation;
- if ( pImpl )
- pImpl->disposing( Source );
-
- for ( NamedStorages::iterator find = m_aExposedStorages.begin();
- find != m_aExposedStorages.end();
- ++find
- )
- if ( find->second == Source.Source )
- {
- m_aExposedStorages.erase( find );
- break;
- }
-}
-
-//============================================================
-//= ODatabaseModelImpl
-//============================================================
-DBG_NAME(ODatabaseModelImpl)
-//--------------------------------------------------------------------------
-ODatabaseModelImpl::ODatabaseModelImpl( const Reference< XMultiServiceFactory >& _rxFactory, ODatabaseContext& _rDBContext )
- :m_xModel()
- ,m_xDataSource()
- ,m_pStorageAccess( NULL )
- ,m_aMutexFacade( m_xMutex->getMutex() )
- ,m_aContainer(4)
- ,m_aStorages()
- ,m_aMacroMode( *this )
- ,m_nImposedMacroExecMode( MacroExecMode::NEVER_EXECUTE )
- ,m_pDBContext( &_rDBContext )
- ,m_refCount(0)
- ,m_bHasAnyObjectWithMacros( false )
- ,m_bHasMacroStorages( false )
- ,m_bModificationLock( false )
- ,m_bDocumentInitialized( false )
- ,m_aContext( _rxFactory )
- ,m_nLoginTimeout(0)
- ,m_bReadOnly(sal_False)
- ,m_bPasswordRequired(sal_False)
- ,m_bSuppressVersionColumns(sal_True)
- ,m_bModified(sal_False)
- ,m_bDocumentReadOnly(sal_False)
- ,m_bDisposingSubStorages( sal_False )
- ,m_pSharedConnectionManager(NULL)
- ,m_nControllerLockCount(0)
-{
- // some kind of default
- DBG_CTOR(ODatabaseModelImpl,NULL);
- m_sConnectURL = ::rtl::OUString::createFromAscii("jdbc:");
- m_aTableFilter.realloc(1);
- m_aTableFilter[0] = ::rtl::OUString::createFromAscii("%");
- impl_construct_nothrow();
-}
-
-//--------------------------------------------------------------------------
-ODatabaseModelImpl::ODatabaseModelImpl(
- const ::rtl::OUString& _rRegistrationName,
- const Reference< XMultiServiceFactory >& _rxFactory,
- ODatabaseContext& _rDBContext
- )
- :m_xModel()
- ,m_xDataSource()
- ,m_pStorageAccess( NULL )
- ,m_aMutexFacade( m_xMutex->getMutex() )
- ,m_aContainer(4)
- ,m_aStorages()
- ,m_aMacroMode( *this )
- ,m_nImposedMacroExecMode( MacroExecMode::NEVER_EXECUTE )
- ,m_pDBContext( &_rDBContext )
- ,m_refCount(0)
- ,m_bHasAnyObjectWithMacros( false )
- ,m_bHasMacroStorages( false )
- ,m_bModificationLock( false )
- ,m_bDocumentInitialized( false )
- ,m_aContext( _rxFactory )
- ,m_sName(_rRegistrationName)
- ,m_nLoginTimeout(0)
- ,m_bReadOnly(sal_False)
- ,m_bPasswordRequired(sal_False)
- ,m_bSuppressVersionColumns(sal_True)
- ,m_bModified(sal_False)
- ,m_bDocumentReadOnly(sal_False)
- ,m_bDisposingSubStorages( sal_False )
- ,m_pSharedConnectionManager(NULL)
- ,m_nControllerLockCount(0)
-{
- DBG_CTOR(ODatabaseModelImpl,NULL);
- impl_construct_nothrow();
-}
-
-//--------------------------------------------------------------------------
-ODatabaseModelImpl::~ODatabaseModelImpl()
-{
- DBG_DTOR(ODatabaseModelImpl,NULL);
-}
-
-// -----------------------------------------------------------------------------
-void ODatabaseModelImpl::impl_construct_nothrow()
-{
- // create the property bag to hold the settings (also known as "Info" property)
- try
- {
- // the set of property value types in the bag is limited:
- Sequence< Type > aAllowedTypes(6);
- Type* pAllowedType = aAllowedTypes.getArray();
- *pAllowedType++ = ::getCppuType( static_cast< sal_Bool* >( NULL ) );
- *pAllowedType++ = ::getCppuType( static_cast< double* >( NULL ) );
- *pAllowedType++ = ::getCppuType( static_cast< ::rtl::OUString* >( NULL ) );
- *pAllowedType++ = ::getCppuType( static_cast< sal_Int32* >( NULL ) );
- *pAllowedType++ = ::getCppuType( static_cast< sal_Int16* >( NULL ) );
- *pAllowedType++ = ::getCppuType( static_cast< Sequence< Any >* >( NULL ) );
-
- Sequence< Any > aInitArgs( 2 );
- aInitArgs[0] <<= NamedValue(
- ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AutomaticAddition" ) ),
- makeAny( (sal_Bool)sal_True )
- );
- aInitArgs[1] <<= NamedValue(
- ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AllowedTypes" ) ),
- makeAny( aAllowedTypes )
- );
-
- m_xSettings.set( m_aContext.createComponentWithArguments( "com.sun.star.beans.PropertyBag", aInitArgs ), UNO_QUERY_THROW );
-
- // insert the default settings
- Reference< XPropertyContainer > xContainer( m_xSettings, UNO_QUERY_THROW );
- const AsciiPropertyValue* pSettings = getDefaultDataSourceSettings();
- for ( ; pSettings->AsciiName; ++pSettings )
- {
- xContainer->addProperty(
- ::rtl::OUString::createFromAscii( pSettings->AsciiName ),
- PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
- pSettings->DefaultValue
- );
- }
- }
- catch( const Exception& )
- {
- DBG_UNHANDLED_EXCEPTION();
- }
-}
-
-// -----------------------------------------------------------------------------
-namespace
-{
- // .........................................................................
- ::rtl::OUString lcl_getContainerStorageName_throw( ODatabaseModelImpl::ObjectType _eType )
- {
- const sal_Char* pAsciiName( NULL );
- switch ( _eType )
- {
- case ODatabaseModelImpl::E_FORM: pAsciiName = "forms"; break;
- case ODatabaseModelImpl::E_REPORT: pAsciiName = "reports"; break;
- case ODatabaseModelImpl::E_QUERY: pAsciiName = "queries"; break;
- case ODatabaseModelImpl::E_TABLE: pAsciiName = "tables"; break;
- default:
- throw RuntimeException();
- }
- return ::rtl::OUString::createFromAscii( pAsciiName );
- }
-
- // .........................................................................
- bool lcl_hasObjectWithMacros_throw( const ODefinitionContainer_Impl& _rObjectDefinitions, const Reference< XStorage >& _rxContainerStorage )
- {
- bool bSomeDocHasMacros = false;
-
- for ( ODefinitionContainer_Impl::const_iterator object = _rObjectDefinitions.begin();
- ( object != _rObjectDefinitions.end() ) && !bSomeDocHasMacros;
- ++object
- )
- {
-#if OSL_DEBUG_LEVEL > 0
- const ::rtl::OUString& rName( object->first ); (void)rName;
-#endif
-
- const TContentPtr& rDefinition( object->second );
- const ::rtl::OUString& rPersistentName( rDefinition->m_aProps.sPersistentName );
-
- if ( !rPersistentName.getLength() )
- { // it's a logical sub folder used to organize the real objects
- const ODefinitionContainer_Impl& rSubFoldersObjectDefinitions( dynamic_cast< const ODefinitionContainer_Impl& >( *rDefinition.get() ) );
- bSomeDocHasMacros = lcl_hasObjectWithMacros_throw( rSubFoldersObjectDefinitions, _rxContainerStorage );
- continue;
- }
-
- bSomeDocHasMacros = ODatabaseModelImpl::objectHasMacros( _rxContainerStorage, rPersistentName );
- }
- return bSomeDocHasMacros;
- }
-
- // .........................................................................
- bool lcl_hasObjectsWithMacros_nothrow( ODatabaseModelImpl& _rModel, const ODatabaseModelImpl::ObjectType _eType )
- {
- bool bSomeDocHasMacros = false;
-
- const OContentHelper_Impl& rContainerData( *_rModel.getObjectContainer( _eType ).get() );
- const ODefinitionContainer_Impl& rObjectDefinitions = dynamic_cast< const ODefinitionContainer_Impl& >( rContainerData );
-
- try
- {
- Reference< XStorage > xContainerStorage( _rModel.getStorage(
- _rModel.getObjectContainerStorageName( _eType ), ElementModes::READWRITE ) );
- // note the READWRITE here: If the storage already existed before, then the OpenMode will
- // be ignored, anyway.
- // If the storage did not yet exist, then it will be created. If the database document
- // is read-only, the OpenMode will be automatically downgraded to READ. Otherwise,
- // the storage will in fact be created as READWRITE. While this is not strictly necessary
- // for this particular use case here, it is required since the storage is *cached*, and
- // later use cases will need the READWRITE mode.
-
- if ( xContainerStorage.is() )
- bSomeDocHasMacros = lcl_hasObjectWithMacros_throw( rObjectDefinitions, xContainerStorage );
- }
- catch( const Exception& )
- {
- DBG_UNHANDLED_EXCEPTION();
- // be on the safe side: If we can't reliably determine whether there are macros,
- // assume there actually are. Better this way, than the other way round.
- bSomeDocHasMacros = true;
- }
-
- return bSomeDocHasMacros;
- }
-}
-
-// -----------------------------------------------------------------------------
-bool ODatabaseModelImpl::objectHasMacros( const Reference< XStorage >& _rxContainerStorage, const ::rtl::OUString& _rPersistentName )
-{
- OSL_PRECOND( _rxContainerStorage.is(), "ODatabaseModelImpl::objectHasMacros: this will crash!" );
-
- bool bHasMacros = true;
- try
- {
- if ( !_rxContainerStorage->hasByName( _rPersistentName ) )
- return false;
-
- Reference< XStorage > xObjectStor( _rxContainerStorage->openStorageElement(
- _rPersistentName, ElementModes::READ ) );
-
- bHasMacros = ::sfx2::DocumentMacroMode::storageHasMacros( xObjectStor );
- }
- catch( const Exception& )
- {
- DBG_UNHANDLED_EXCEPTION();
- }
- return bHasMacros;
-}
-
-// -----------------------------------------------------------------------------
-void ODatabaseModelImpl::reset()
-{
- m_bReadOnly = sal_False;
- ::std::vector< TContentPtr > aEmptyContainers( 4 );
- m_aContainer.swap( aEmptyContainers );
-
- if ( m_pStorageAccess )
- {
- m_pStorageAccess->dispose();
- m_pStorageAccess->release();
- m_pStorageAccess = NULL;
- }
-}
-// -----------------------------------------------------------------------------
-void SAL_CALL ODatabaseModelImpl::disposing( const ::com::sun::star::lang::EventObject& Source ) throw(RuntimeException)
-{
- Reference<XConnection> xCon(Source.Source,UNO_QUERY);
- if ( xCon.is() )
- {
- bool bStore = false;
- OWeakConnectionArray::iterator aEnd = m_aConnections.end();
- for (OWeakConnectionArray::iterator i = m_aConnections.begin(); aEnd != i; ++i)
- {
- if ( xCon == i->get() )
- {
- *i = OWeakConnection();
- bStore = true;
- break;
- }
- }
-
- if ( bStore )
- commitRootStorage();
- }
- else // storage
- {
- if ( !m_bDisposingSubStorages )
- {
- Reference<XStorage> xStorage(Source.Source,UNO_QUERY);
- TStorages::iterator aFind = ::std::find_if(m_aStorages.begin(),m_aStorages.end(),
- ::std::compose1(::std::bind2nd(::std::equal_to<Reference<XStorage> >(),xStorage),::std::select2nd<TStorages::value_type>()));
- if ( aFind != m_aStorages.end() )
- m_aStorages.erase(aFind);
- }
- }
-}
-//------------------------------------------------------------------------------
-void ODatabaseModelImpl::clearConnections()
-{
- OWeakConnectionArray aConnections;
- aConnections.swap( m_aConnections );
-
- Reference< XConnection > xConn;
- for ( OWeakConnectionArray::iterator i = aConnections.begin(); aConnections.end() != i; ++i )
- {
- xConn = *i;
- if ( xConn.is() )
- {
- try
- {
- xConn->close();
- }
- catch(const Exception&)
- {
- DBG_UNHANDLED_EXCEPTION();
- }
- }
- }
-
- m_pSharedConnectionManager = NULL;
- m_xSharedConnectionManager = NULL;
-}
-//------------------------------------------------------------------------------
-void ODatabaseModelImpl::dispose()
-{
- // dispose the data source and the model
- try
- {
- Reference< XDataSource > xDS( m_xDataSource );
- ::comphelper::disposeComponent( xDS );
-
- Reference< XModel > xModel( m_xModel );
- ::comphelper::disposeComponent( xModel );
- }
- catch( const Exception& )
- {
- DBG_UNHANDLED_EXCEPTION();
- }
- m_xDataSource = WeakReference<XDataSource>();
- m_xModel = WeakReference< XModel >();
-
- ::std::vector<TContentPtr>::iterator aIter = m_aContainer.begin();
- ::std::vector<TContentPtr>::iterator aEnd = m_aContainer.end();
- for (;aIter != aEnd ; ++aIter)
- {
- if ( aIter->get() )
- (*aIter)->m_pDataSource = NULL;
- }
- m_aContainer.clear();
-
- clearConnections();
-
- m_xNumberFormatsSupplier = NULL;
-
- try
- {
- sal_Bool bStore = commitEmbeddedStorage();
- disposeStorages();
- if ( bStore )
- commitRootStorage();
-
- impl_switchToStorage_throw( NULL );
- }
- catch( const Exception& )
- {
- DBG_UNHANDLED_EXCEPTION();
- }
-
- if ( m_pStorageAccess )
- {
- m_pStorageAccess->dispose();
- m_pStorageAccess->release();
- m_pStorageAccess = NULL;
- }
-}
-// -----------------------------------------------------------------------------
-const Reference< XNumberFormatsSupplier > & ODatabaseModelImpl::getNumberFormatsSupplier()
-{
- if (!m_xNumberFormatsSupplier.is())
- {
- // the arguments : the locale of the current user
- UserInformation aUserInfo;
- Sequence< Any > aArguments(1);
- aArguments.getArray()[0] <<= aUserInfo.getUserLanguage();
-
- m_xNumberFormatsSupplier.set(
- m_aContext.createComponentWithArguments( "com.sun.star.util.NumberFormatsSupplier", aArguments ), UNO_QUERY_THROW );
- DBG_ASSERT(m_xNumberFormatsSupplier.is(), "ODatabaseModelImpl::getNumberFormatsSupplier : could not instantiate the formats supplier !");
- }
- return m_xNumberFormatsSupplier;
-}
-// -----------------------------------------------------------------------------
-void ODatabaseModelImpl::attachResource( const ::rtl::OUString& _rURL, const Sequence< PropertyValue >& _rArgs )
-{
- ::comphelper::NamedValueCollection aMediaDescriptor( _rArgs );
-
- ::rtl::OUString sDocumentLocation( aMediaDescriptor.getOrDefault( "SalvagedFile", _rURL ) );
- if ( !sDocumentLocation.getLength() )
- // this indicates "the document is being recovered, but _rURL already is the real document URL,
- // not the temporary document location"
- sDocumentLocation = _rURL;
-
- if ( aMediaDescriptor.has( "SalvagedFile" ) )
- aMediaDescriptor.remove( "SalvagedFile" );
-
- m_aArgs = stripLoadArguments( aMediaDescriptor );
-
- switchToURL( sDocumentLocation, _rURL );
-}
-
-// -----------------------------------------------------------------------------
-Sequence< PropertyValue > ODatabaseModelImpl::stripLoadArguments( const ::comphelper::NamedValueCollection& _rArguments )
-{
- OSL_ENSURE( !_rArguments.has( "Model" ), "ODatabaseModelImpl::stripLoadArguments: this is suspicious (1)!" );
- OSL_ENSURE( !_rArguments.has( "ViewName" ), "ODatabaseModelImpl::stripLoadArguments: this is suspicious (2)!" );
-
- ::comphelper::NamedValueCollection aMutableArgs( _rArguments );
- aMutableArgs.remove( "Model" );
- aMutableArgs.remove( "ViewName" );
- return aMutableArgs.getPropertyValues();
-}
-
-// -----------------------------------------------------------------------------
-void ODatabaseModelImpl::disposeStorages() SAL_THROW(())
-{
- m_bDisposingSubStorages = sal_True;
-
- TStorages::iterator aEnd = m_aStorages.end();
- for ( TStorages::iterator aIter = m_aStorages.begin();
- aIter != aEnd ;
- ++aIter
- )
- {
- try
- {
- ::comphelper::disposeComponent( aIter->second );
- }
- catch( const Exception& )
- {
- DBG_UNHANDLED_EXCEPTION();
- }
- }
- m_aStorages.clear();
-
- m_bDisposingSubStorages = sal_False;
-}
-// -----------------------------------------------------------------------------
-Reference< XSingleServiceFactory > ODatabaseModelImpl::createStorageFactory() const
-{
- return Reference< XSingleServiceFactory >( m_aContext.createComponent( "com.sun.star.embed.StorageFactory" ), UNO_QUERY_THROW );
-}
-// -----------------------------------------------------------------------------
-void ODatabaseModelImpl::commitRootStorage()
-{
- Reference< XStorage > xStorage( getOrCreateRootStorage() );
-#if OSL_DEBUG_LEVEL > 0
- bool bSuccess =
-#endif
- commitStorageIfWriteable_ignoreErrors( xStorage );
- OSL_ENSURE( bSuccess || !xStorage.is(),
- "ODatabaseModelImpl::commitRootStorage: could commit the storage!" );
-}
-// -----------------------------------------------------------------------------
-Reference< XStorage > ODatabaseModelImpl::getOrCreateRootStorage()
-{
- if ( !m_xDocumentStorage.is() )
- {
- Reference< XSingleServiceFactory> xStorageFactory = createStorageFactory();
- if ( xStorageFactory.is() )
- {
- Any aSource;
- ::comphelper::NamedValueCollection aArgs( m_aArgs );
-
- aSource = aArgs.get( "Stream" );
- if ( !aSource.hasValue() )
- aSource = aArgs.get( "InputStream" );
- if ( !aSource.hasValue() && m_sDocFileLocation.getLength() )
- aSource <<= m_sDocFileLocation;
- // TODO: shouldn't we also check URL?
-
- OSL_ENSURE( aSource.hasValue(), "ODatabaseModelImpl::getOrCreateRootStorage: no source to create the storage from!" );
-
- if ( aSource.hasValue() )
- {
- Sequence< Any > aStorageCreationArgs(2);
- aStorageCreationArgs[0] = aSource;
- aStorageCreationArgs[1] <<= ElementModes::READWRITE;
-
- Reference< XStorage > xDocumentStorage;
- try
- {
- xDocumentStorage.set( xStorageFactory->createInstanceWithArguments( aStorageCreationArgs ), UNO_QUERY_THROW );
- }
- catch( const Exception& )
- {
- m_bDocumentReadOnly = sal_True;
- aStorageCreationArgs[1] <<= ElementModes::READ;
- try
- {
- xDocumentStorage.set( xStorageFactory->createInstanceWithArguments( aStorageCreationArgs ), UNO_QUERY_THROW );
- }
- catch( const Exception& )
- {
- DBG_UNHANDLED_EXCEPTION();
- }
- }
-
- impl_switchToStorage_throw( xDocumentStorage );
- }
- }
- }
- return m_xDocumentStorage.getTyped();
-}
-// -----------------------------------------------------------------------------
-DocumentStorageAccess* ODatabaseModelImpl::getDocumentStorageAccess()
-{
- if ( !m_pStorageAccess )
- {
- m_pStorageAccess = new DocumentStorageAccess( *this );
- m_pStorageAccess->acquire();
- }
- return m_pStorageAccess;
-}
-
-// -----------------------------------------------------------------------------
-void ODatabaseModelImpl::modelIsDisposing( const bool _wasInitialized, ResetModelAccess )
-{
- m_xModel = Reference< XModel >();
-
- // Basic libraries and Dialog libraries are a model facet, though held at this impl class.
- // They automatically dispose themself when the model they belong to is being disposed.
- // So, to not be tempted to do anything with them, again, we reset them.
- m_xBasicLibraries.clear();
- m_xDialogLibraries.clear();
-
- m_bDocumentInitialized = _wasInitialized;
-}
-
-// -----------------------------------------------------------------------------
-Reference< XDocumentSubStorageSupplier > ODatabaseModelImpl::getDocumentSubStorageSupplier()
-{
- return getDocumentStorageAccess();
-}
-// -----------------------------------------------------------------------------
-Reference<XStorage> ODatabaseModelImpl::getStorage( const ::rtl::OUString& _sStorageName, sal_Int32 _nMode )
-{
- OSL_ENSURE(_sStorageName.getLength(),"ODatabaseModelImpl::getStorage: Invalid storage name!");
- Reference<XStorage> xStorage;
- TStorages::iterator aFind = m_aStorages.find(_sStorageName);
- if ( aFind == m_aStorages.end() )
- {
- try
- {
- Reference< XStorage > xMyStorage( getOrCreateRootStorage() );
- if ( xMyStorage.is() )
- {
- sal_Int32 nMode = m_bDocumentReadOnly ? ElementModes::READ : _nMode;
- if ( nMode == ElementModes::READ )
- {
- Reference< XNameAccess > xSubStorageNames( xMyStorage, UNO_QUERY );
- if ( xSubStorageNames.is() && !xSubStorageNames->hasByName( _sStorageName ) )
- return xStorage;
- }
-
- xStorage = xMyStorage->openStorageElement( _sStorageName, nMode );
- Reference< XTransactionBroadcaster > xBroad( xStorage, UNO_QUERY );
- if ( xBroad.is() )
- xBroad->addTransactionListener( getDocumentStorageAccess() );
- aFind = m_aStorages.insert( TStorages::value_type( _sStorageName, xStorage ) ).first;
- }
- }
- catch( const Exception& )
- {
- DBG_UNHANDLED_EXCEPTION();
- }
- }
-
- if ( aFind != m_aStorages.end() )
- xStorage = aFind->second;
-
- return xStorage;
-}
-// -----------------------------------------------------------------------------
-sal_Bool ODatabaseModelImpl::commitEmbeddedStorage( sal_Bool _bPreventRootCommits )
-{
- if ( _bPreventRootCommits && m_pStorageAccess )
- m_pStorageAccess->suspendCommitPropagation();
-
- sal_Bool bStore = sal_False;
- try
- {
- TStorages::iterator aFind = m_aStorages.find(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("database")));
- if ( aFind != m_aStorages.end() )
- bStore = commitStorageIfWriteable(aFind->second);
- }
- catch(Exception&)
- {
- OSL_ENSURE(0,"Exception Caught: Could not store embedded database!");
- }
-
- if ( _bPreventRootCommits && m_pStorageAccess )
- m_pStorageAccess->resumeCommitPropagation();
-
- return bStore;
-
-}
-
-// -----------------------------------------------------------------------------
-namespace
-{
- bool lcl_storageIsWritable_nothrow( const Reference< XStorage >& _rxStorage )
- {
- if ( !_rxStorage.is() )
- return false;
-
- sal_Int32 nMode = ElementModes::READ;
- try
- {
- Reference< XPropertySet > xStorageProps( _rxStorage, UNO_QUERY_THROW );
- xStorageProps->getPropertyValue(
- ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OpenMode" ) ) ) >>= nMode;
- }
- catch( const Exception& )
- {
- DBG_UNHANDLED_EXCEPTION();
- }
- return ( nMode & ElementModes::WRITE ) != 0;
- }
-}
-
-// -----------------------------------------------------------------------------
-bool ODatabaseModelImpl::commitStorageIfWriteable( const Reference< XStorage >& _rxStorage ) SAL_THROW(( IOException, WrappedTargetException, RuntimeException ))
-{
- bool bSuccess = false;
- Reference<XTransactedObject> xTrans( _rxStorage, UNO_QUERY );
- if ( xTrans.is() )
- {
- if ( lcl_storageIsWritable_nothrow( _rxStorage ) )
- xTrans->commit();
- bSuccess = true;
- }
- return bSuccess;
-}
-// -----------------------------------------------------------------------------
-bool ODatabaseModelImpl::commitStorageIfWriteable_ignoreErrors( const Reference< XStorage >& _rxStorage ) SAL_THROW(())
-{
- bool bSuccess = false;
- try
- {
- bSuccess = commitStorageIfWriteable( _rxStorage );
- }
- catch( const Exception& )
- {
- DBG_UNHANDLED_EXCEPTION();
- }
- return bSuccess;
-}
-// -----------------------------------------------------------------------------
-void ODatabaseModelImpl::setModified( sal_Bool _bModified )
-{
- if ( isModifyLocked() )
- return;
-
- try
- {
- Reference< XModifiable > xModi( m_xModel.get(), UNO_QUERY );
- if ( xModi.is() )
- xModi->setModified( _bModified );
- else
- m_bModified = _bModified;
- }
- catch( const Exception& )
- {
- DBG_UNHANDLED_EXCEPTION();
- }
-}
-
-// -----------------------------------------------------------------------------
-Reference<XDataSource> ODatabaseModelImpl::getOrCreateDataSource()
-{
- Reference<XDataSource> xDs = m_xDataSource;
- if ( !xDs.is() )
- {
- xDs = new ODatabaseSource(this);
- m_xDataSource = xDs;
- }
- return xDs;
-}
-// -----------------------------------------------------------------------------
-Reference< XModel> ODatabaseModelImpl::getModel_noCreate() const
-{
- return m_xModel;
-}
-// -----------------------------------------------------------------------------
-Reference< XModel > ODatabaseModelImpl::createNewModel_deliverOwnership( bool _bInitialize )
-{
- Reference< XModel > xModel( m_xModel );
- OSL_PRECOND( !xModel.is(), "ODatabaseModelImpl::createNewModel_deliverOwnership: not to be called if there already is a model!" );
- if ( !xModel.is() )
- {
- xModel = ODatabaseDocument::createDatabaseDocument( this, ODatabaseDocument::FactoryAccess() );
- m_xModel = xModel;
-
- try
- {
- Reference< XSet > xModelCollection;
- if ( m_aContext.createComponent( "com.sun.star.frame.GlobalEventBroadcaster", xModelCollection ) )
- xModelCollection->insert( makeAny( xModel ) );
- }
- catch( const Exception& )
- {
- DBG_UNHANDLED_EXCEPTION();
- }
-
- if ( _bInitialize )
- {
- try
- {
- Reference< XLoadable > xLoad( xModel, UNO_QUERY_THROW );
- xLoad->initNew();
- }
- catch( RuntimeException& ) { throw; }
- catch( const Exception& )
- {
- DBG_UNHANDLED_EXCEPTION();
- }
- }
- }
- return xModel;
-}
-// -----------------------------------------------------------------------------
-oslInterlockedCount SAL_CALL ODatabaseModelImpl::acquire()
-{
- return osl_incrementInterlockedCount(&m_refCount);
-}
-// -----------------------------------------------------------------------------
-oslInterlockedCount SAL_CALL ODatabaseModelImpl::release()
-{
- if ( osl_decrementInterlockedCount(&m_refCount) == 0 )
- {
- acquire(); // prevent multiple releases
- dispose();
- m_pDBContext->storeTransientProperties(*this);
- revokeDataSource();
- delete this;
- return 0;
- }
- return m_refCount;
-}
-// -----------------------------------------------------------------------------
-void ODatabaseModelImpl::commitStorages() SAL_THROW(( IOException, RuntimeException ))
-{
- try
- {
- TStorages::iterator aIter = m_aStorages.begin();
- TStorages::iterator aEnd = m_aStorages.end();
- for (; aIter != aEnd ; ++aIter)
- commitStorageIfWriteable( aIter->second );
- }
- catch(const WrappedTargetException&)
- {
- // WrappedTargetException not allowed to leave
- throw IOException();
- }
-}
-
-// -----------------------------------------------------------------------------
-const AsciiPropertyValue* ODatabaseModelImpl::getDefaultDataSourceSettings()
-{
- static const AsciiPropertyValue aKnownSettings[] =
- {
- // known JDBC settings
- AsciiPropertyValue( "JavaDriverClass", makeAny( ::rtl::OUString() ) ),
- // known settings for file-based drivers
- AsciiPropertyValue( "Extension", makeAny( ::rtl::OUString() ) ),
- AsciiPropertyValue( "CharSet", makeAny( ::rtl::OUString() ) ),
- AsciiPropertyValue( "HeaderLine", makeAny( (sal_Bool)sal_True ) ),
- AsciiPropertyValue( "FieldDelimiter", makeAny( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "," ) ) ) ),
- AsciiPropertyValue( "StringDelimiter", makeAny( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "\"" ) ) ) ),
- AsciiPropertyValue( "DecimalDelimiter", makeAny( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "." ) ) ) ),
- AsciiPropertyValue( "ThousandDelimiter", makeAny( ::rtl::OUString() ) ),
- AsciiPropertyValue( "ShowDeleted", makeAny( (sal_Bool)sal_False ) ),
- // known ODBC settings
- AsciiPropertyValue( "SystemDriverSettings", makeAny( ::rtl::OUString() ) ),
- AsciiPropertyValue( "UseCatalog", makeAny( (sal_Bool)sal_False ) ),
- // settings related to auto increment handling
- AsciiPropertyValue( "AutoIncrementCreation", makeAny( ::rtl::OUString() ) ),
- AsciiPropertyValue( "AutoRetrievingStatement", makeAny( ::rtl::OUString() ) ),
- AsciiPropertyValue( "IsAutoRetrievingEnabled", makeAny( (sal_Bool)sal_False ) ),
- // known Adabas D driver setting
- AsciiPropertyValue( "ShutdownDatabase", makeAny( (sal_Bool)sal_False ) ),
- AsciiPropertyValue( "DataCacheSizeIncrement", makeAny( (sal_Int32)20 ) ),
- AsciiPropertyValue( "DataCacheSize", makeAny( (sal_Int32)20 ) ),
- AsciiPropertyValue( "ControlUser", makeAny( ::rtl::OUString() ) ),
- AsciiPropertyValue( "ControlPassword", makeAny( ::rtl::OUString() ) ),
- // known LDAP driver settings
- AsciiPropertyValue( "HostName", makeAny( ::rtl::OUString() ) ),
- AsciiPropertyValue( "PortNumber", makeAny( (sal_Int32)389 ) ),
- AsciiPropertyValue( "BaseDN", makeAny( ::rtl::OUString() ) ),
- AsciiPropertyValue( "MaxRowCount", makeAny( (sal_Int32)100 ) ),
- // misc known driver settings
- AsciiPropertyValue( "ParameterNameSubstitution", makeAny( (sal_Bool)sal_False ) ),
- AsciiPropertyValue( "AddIndexAppendix", makeAny( (sal_Bool)sal_True ) ),
- // known SDB level settings
- AsciiPropertyValue( "IgnoreDriverPrivileges", makeAny( (sal_Bool)sal_True ) ),
- AsciiPropertyValue( "NoNameLengthLimit", makeAny( (sal_Bool)sal_False ) ),
- AsciiPropertyValue( "AppendTableAliasName", makeAny( (sal_Bool)sal_False ) ),
- AsciiPropertyValue( "GenerateASBeforeCorrelationName", makeAny( (sal_Bool)sal_True ) ),
- AsciiPropertyValue( "ColumnAliasInOrderBy", makeAny( (sal_Bool)sal_True ) ),
- AsciiPropertyValue( "EnableSQL92Check", makeAny( (sal_Bool)sal_False ) ),
- AsciiPropertyValue( "BooleanComparisonMode", makeAny( BooleanComparisonMode::EQUAL_INTEGER ) ),
- AsciiPropertyValue( "TableTypeFilterMode", makeAny( (sal_Int32)3 ) ),
- AsciiPropertyValue( "RespectDriverResultSetType", makeAny( (sal_Bool)sal_False ) ),
- AsciiPropertyValue( "UseSchemaInSelect", makeAny( (sal_Bool)sal_True ) ),
- AsciiPropertyValue( "UseCatalogInSelect", makeAny( (sal_Bool)sal_True ) ),
- AsciiPropertyValue( "EnableOuterJoinEscape", makeAny( (sal_Bool)sal_True ) ),
- AsciiPropertyValue( "PreferDosLikeLineEnds", makeAny( (sal_Bool)sal_False ) ),
- AsciiPropertyValue( "FormsCheckRequiredFields", makeAny( (sal_Bool)sal_True ) ),
- AsciiPropertyValue( "EscapeDateTime", makeAny( (sal_Bool)sal_True ) ),
- AsciiPropertyValue( "IgnoreCurrency", makeAny( (sal_Bool)sal_False ) ),
- AsciiPropertyValue( "TypeInfoSettings", makeAny( Sequence< Any >()) ),
- AsciiPropertyValue( "LocalSocket", makeAny( ::rtl::OUString() ) ),
-
- AsciiPropertyValue( NULL, Any() )
- };
- return aKnownSettings;
-}
-
-// -----------------------------------------------------------------------------
-TContentPtr& ODatabaseModelImpl::getObjectContainer( ObjectType _eType )
-{
- OSL_PRECOND( _eType >= E_FORM && _eType <= E_TABLE, "ODatabaseModelImpl::getObjectContainer: illegal index!" );
- TContentPtr& rContentPtr = m_aContainer[ _eType ];
-
- if ( !rContentPtr.get() )
- {
- rContentPtr = TContentPtr( new ODefinitionContainer_Impl );
- rContentPtr->m_pDataSource = this;
- rContentPtr->m_aProps.aTitle = lcl_getContainerStorageName_throw( _eType );
- }
- return rContentPtr;
-}
-
-// -----------------------------------------------------------------------------
-void ODatabaseModelImpl::revokeDataSource() const
-{
- if ( m_pDBContext && m_sDocumentURL.getLength() )
- m_pDBContext->deregisterPrivate( m_sDocumentURL );
-}
-
-// -----------------------------------------------------------------------------
-bool ODatabaseModelImpl::adjustMacroMode_AutoReject()
-{
- return m_aMacroMode.adjustMacroMode( NULL );
-}
-
-// -----------------------------------------------------------------------------
-bool ODatabaseModelImpl::checkMacrosOnLoading()
-{
- ::comphelper::NamedValueCollection aArgs( m_aArgs );
- Reference< XInteractionHandler > xInteraction;
- xInteraction = aArgs.getOrDefault( "InteractionHandler", xInteraction );
- return m_aMacroMode.checkMacrosOnLoading( xInteraction );
-}
-
-// -----------------------------------------------------------------------------
-void ODatabaseModelImpl::resetMacroExecutionMode()
-{
- m_aMacroMode = ::sfx2::DocumentMacroMode( *this );
-}
-
-// -----------------------------------------------------------------------------
-Reference< XStorageBasedLibraryContainer > ODatabaseModelImpl::getLibraryContainer( bool _bScript )
-{
- Reference< XStorageBasedLibraryContainer >& rxContainer( _bScript ? m_xBasicLibraries : m_xDialogLibraries );
- if ( rxContainer.is() )
- return rxContainer;
-
- Reference< XStorageBasedDocument > xDocument( getModel_noCreate(), UNO_QUERY_THROW );
- // this is only to be called if there already exists a document model - in fact, it is
- // to be called by the document model only
-
- try
- {
- Reference< XStorageBasedLibraryContainer > (*Factory)( const Reference< XComponentContext >&, const Reference< XStorageBasedDocument >&)
- = _bScript ? &DocumentScriptLibraryContainer::create : &DocumentDialogLibraryContainer::create;
-
- rxContainer.set(
- (*Factory)( m_aContext.getUNOContext(), xDocument ),
- UNO_QUERY_THROW
- );
- }
- catch( const RuntimeException& )
- {
- throw;
- }
- catch( const Exception& )
- {
- throw WrappedTargetRuntimeException(
- ::rtl::OUString(),
- xDocument,
- ::cppu::getCaughtException()
- );
- }
- return rxContainer;
-}
-
-// -----------------------------------------------------------------------------
-void ODatabaseModelImpl::storeLibraryContainersTo( const Reference< XStorage >& _rxToRootStorage )
-{
- if ( m_xBasicLibraries.is() )
- m_xBasicLibraries->storeLibrariesToStorage( _rxToRootStorage );
-
- if ( m_xDialogLibraries.is() )
- m_xDialogLibraries->storeLibrariesToStorage( _rxToRootStorage );
-}
-
-// -----------------------------------------------------------------------------
-Reference< XStorage > ODatabaseModelImpl::switchToStorage( const Reference< XStorage >& _rxNewRootStorage )
-{
- if ( !_rxNewRootStorage.is() )
- throw IllegalArgumentException();
-
- return impl_switchToStorage_throw( _rxNewRootStorage );
-}
-
-// -----------------------------------------------------------------------------
-namespace
-{
- void lcl_modifyListening( ::sfx2::IModifiableDocument& _rDocument,
- const Reference< XStorage >& _rxStorage, ::rtl::Reference< ::sfx2::DocumentStorageModifyListener >& _inout_rListener,
- ::vos::IMutex& _rMutex, bool _bListen )
- {
- Reference< XModifiable > xModify( _rxStorage, UNO_QUERY );
- OSL_ENSURE( xModify.is() || !_rxStorage.is(), "lcl_modifyListening: storage can't notify us!" );
-
- if ( xModify.is() && !_bListen && _inout_rListener.is() )
- {
- xModify->removeModifyListener( _inout_rListener.get() );
- }
-
- if ( _inout_rListener.is() )
- {
- _inout_rListener->dispose();
- _inout_rListener = NULL;
- }
-
- if ( xModify.is() && _bListen )
- {
- // the listener from sfx2 uses SolarMutex internally
- _inout_rListener = new ::sfx2::DocumentStorageModifyListener( _rDocument, _rMutex );
- xModify->addModifyListener( _inout_rListener.get() );
- }
- }
-
- // -------------------------------------------------------------------------
- static void lcl_rebaseScriptStorage_throw( const Reference< XStorageBasedLibraryContainer >& _rxContainer,
- const Reference< XStorage >& _rxNewRootStorage )
- {
- if ( _rxContainer.is() )
- {
- if ( _rxNewRootStorage.is() )
- _rxContainer->setRootStorage( _rxNewRootStorage );
-// else
- // TODO: what to do here? dispose the container?
- }
- }
-}
-
-// -----------------------------------------------------------------------------
-Reference< XStorage > ODatabaseModelImpl::impl_switchToStorage_throw( const Reference< XStorage >& _rxNewRootStorage )
-{
- // stop listening for modifications at the old storage
- lcl_modifyListening( *this, m_xDocumentStorage.getTyped(), m_pStorageModifyListener, m_aMutexFacade, false );
-
- // set new storage
- m_xDocumentStorage.reset( _rxNewRootStorage, SharedStorage::TakeOwnership );
-
- // start listening for modifications
- lcl_modifyListening( *this, m_xDocumentStorage.getTyped(), m_pStorageModifyListener, m_aMutexFacade, true );
-
- // forward new storage to Basic and Dialog library containers
- lcl_rebaseScriptStorage_throw( m_xBasicLibraries, m_xDocumentStorage.getTyped() );
- lcl_rebaseScriptStorage_throw( m_xDialogLibraries, m_xDocumentStorage.getTyped() );
-
- m_bReadOnly = !lcl_storageIsWritable_nothrow( m_xDocumentStorage.getTyped() );
- // TODO: our data source, if it exists, must broadcast the change of its ReadOnly property
-
- return m_xDocumentStorage.getTyped();
-}
-
-// -----------------------------------------------------------------------------
-void ODatabaseModelImpl::switchToURL( const ::rtl::OUString& _rDocumentLocation, const ::rtl::OUString& _rDocumentURL )
-{
- // register at the database context, or change registration
- if ( _rDocumentURL != m_sDocumentURL )
- {
- if ( m_pDBContext )
- {
- if ( m_sDocumentURL.getLength() )
- m_pDBContext->nameChangePrivate( m_sDocumentURL, _rDocumentURL );
- else
- m_pDBContext->registerPrivate( _rDocumentURL, this );
- }
-
- // if we do not have a name, yet (i.e. are not registered at the database context),
- // then use the URL as name
- if ( !m_sName.getLength() )
- {
- INetURLObject aURL( _rDocumentURL );
- if ( aURL.GetProtocol() != INET_PROT_NOT_VALID )
- m_sName = _rDocumentURL;
- }
- }
-
- // remember both
- m_sDocFileLocation = _rDocumentLocation.getLength() ? _rDocumentLocation : _rDocumentURL;
- m_sDocumentURL = _rDocumentURL;
-}
-
-// -----------------------------------------------------------------------------
-bool ODatabaseModelImpl::isDatabaseStorage( const Reference< XStorage >& _rxStorage ) const
-{
- TStorages::const_iterator pos = m_aStorages.find( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "database" ) ) );
- if ( ( pos != m_aStorages.end() )
- && ( pos->second == _rxStorage )
- )
- {
- return true;
- }
- return false;
-}
-
-// -----------------------------------------------------------------------------
-::rtl::OUString ODatabaseModelImpl::getObjectContainerStorageName( const ObjectType _eType )
-{
- return lcl_getContainerStorageName_throw( _eType );
-}
-
-// -----------------------------------------------------------------------------
-sal_Int16 ODatabaseModelImpl::getCurrentMacroExecMode() const
-{
- sal_Int16 nCurrentMode = MacroExecMode::NEVER_EXECUTE;
- try
- {
- ::comphelper::NamedValueCollection aArgs( m_aArgs );
- nCurrentMode = aArgs.getOrDefault( "MacroExecutionMode", nCurrentMode );
- }
- catch( const Exception& )
- {
- DBG_UNHANDLED_EXCEPTION();
- }
- return nCurrentMode;
-}
-
-// -----------------------------------------------------------------------------
-sal_Bool ODatabaseModelImpl::setCurrentMacroExecMode( sal_uInt16 nMacroMode )
-{
- try
- {
- ::comphelper::NamedValueCollection aArgs( m_aArgs );
- aArgs.put( "MacroExecutionMode", nMacroMode );
- aArgs >>= m_aArgs;
- return sal_True;
- }
- catch( const Exception& )
- {
- DBG_UNHANDLED_EXCEPTION();
- }
-
- return sal_False;
-}
-
-// -----------------------------------------------------------------------------
-::rtl::OUString ODatabaseModelImpl::getDocumentLocation() const
-{
- // don't return getURL() (or m_sDocumentURL, which is the same). In case we were recovered
- // after a previous crash of OOo, m_sDocFileLocation points to the file which were loaded from,
- // and this is the one we need for security checks.
- return getDocFileLocation();
-}
-
-// -----------------------------------------------------------------------------
-Reference< XStorage > ODatabaseModelImpl::getLastCommitDocumentStorage()
-{
- // we do not support signing the scripting storages, so we're allowed to
- // return <NULL/> here.
- return Reference< XStorage >();
-}
-
-// -----------------------------------------------------------------------------
-sal_Bool ODatabaseModelImpl::documentStorageHasMacros() const
-{
- // does our root storage contain macros?
- if ( ::sfx2::DocumentMacroMode::storageHasMacros( m_xDocumentStorage ) )
- {
- const_cast< ODatabaseModelImpl* >( this )->m_bHasMacroStorages = true;
- return true;
- }
-
- // do we have forms or reports with macros?
- if ( lcl_hasObjectsWithMacros_nothrow( const_cast< ODatabaseModelImpl& >( *this ), E_FORM )
- || lcl_hasObjectsWithMacros_nothrow( const_cast< ODatabaseModelImpl& >( *this ), E_REPORT )
- )
- {
- const_cast< ODatabaseModelImpl* >( this )->m_bHasAnyObjectWithMacros = true;
- return true;
- }
-
- return false;
-}
-
-// -----------------------------------------------------------------------------
-Reference< XEmbeddedScripts > ODatabaseModelImpl::getEmbeddedDocumentScripts() const
-{
- return Reference< XEmbeddedScripts >( getModel_noCreate(), UNO_QUERY );
-}
-
-// -----------------------------------------------------------------------------
-sal_Int16 ODatabaseModelImpl::getScriptingSignatureState() const
-{
- // no support for signatures at the moment
- return SIGNATURESTATE_NOSIGNATURES;
-}
-
-// -----------------------------------------------------------------------------
-void ODatabaseModelImpl::showBrokenSignatureWarning( const Reference< XInteractionHandler >& /*_rxInteraction*/ ) const
-{
- OSL_ENSURE( false, "ODatabaseModelImpl::showBrokenSignatureWarning: signatures can't be broken - we do not support them!" );
-}
-
-// -----------------------------------------------------------------------------
-void ODatabaseModelImpl::storageIsModified()
-{
- setModified( sal_True );
-}
-
-// -----------------------------------------------------------------------------
-ModelDependentComponent::ModelDependentComponent( const ::rtl::Reference< ODatabaseModelImpl >& _model )
- :m_pImpl( _model )
- ,m_xMutex( _model->getSharedMutex() )
-{
-}
-
-// -----------------------------------------------------------------------------
-ModelDependentComponent::~ModelDependentComponent()
-{
-}
-
-//........................................................................
-} // namespace dbaccess
-//........................................................................
-
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: ModelImpl.cxx,v $
+ * $Revision: 1.25.6.12 $
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_dbaccess.hxx"
+
+#include "commandcontainer.hxx"
+#include "connection.hxx"
+#include "core_resource.hrc"
+#include "core_resource.hxx"
+#include "databasecontext.hxx"
+#include "databasedocument.hxx"
+#include "datasource.hxx"
+#include "dbastrings.hrc"
+#include "ModelImpl.hxx"
+#include "userinformation.hxx"
+
+/** === begin UNO includes === **/
+#include <com/sun/star/container/XSet.hpp>
+#include <com/sun/star/document/MacroExecMode.hpp>
+#include <com/sun/star/embed/XTransactedObject.hpp>
+#include <com/sun/star/embed/XTransactionBroadcaster.hpp>
+#include <com/sun/star/sdb/BooleanComparisonMode.hpp>
+#include <com/sun/star/script/DocumentScriptLibraryContainer.hpp>
+#include <com/sun/star/script/DocumentDialogLibraryContainer.hpp>
+#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
+#include <com/sun/star/form/XLoadable.hpp>
+/** === end UNO includes === **/
+
+#include <comphelper/interaction.hxx>
+#include <comphelper/mediadescriptor.hxx>
+#include <comphelper/namedvaluecollection.hxx>
+#include <comphelper/seqstream.hxx>
+#include <comphelper/sequence.hxx>
+#include <connectivity/dbexception.hxx>
+#include <cppuhelper/exc_hlp.hxx>
+#include <cppuhelper/typeprovider.hxx>
+#include <rtl/digest.h>
+#include <sfx2/signaturestate.hxx>
+#include <tools/debug.hxx>
+#include <tools/diagnose_ex.h>
+#include <tools/errcode.hxx>
+#include <tools/urlobj.hxx>
+#include <unotools/sharedunocomponent.hxx>
+
+#include <algorithm>
+
+using namespace ::com::sun::star::document;
+using namespace ::com::sun::star::sdbc;
+using namespace ::com::sun::star::sdbcx;
+using namespace ::com::sun::star::sdb;
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::embed;
+using namespace ::com::sun::star::container;
+using namespace ::com::sun::star::util;
+using namespace ::com::sun::star::io;
+using namespace ::com::sun::star::task;
+using namespace ::com::sun::star::ucb;
+using namespace ::com::sun::star::frame;
+using namespace ::com::sun::star::view;
+using namespace ::com::sun::star::task;
+using namespace ::com::sun::star::reflection;
+using namespace ::com::sun::star::script;
+using namespace ::cppu;
+using namespace ::osl;
+using namespace ::vos;
+using namespace ::dbtools;
+using namespace ::comphelper;
+namespace css = ::com::sun::star;
+
+//........................................................................
+namespace dbaccess
+{
+//........................................................................
+
+//============================================================
+//= VosMutexFacade
+//============================================================
+//------------------------------------------------------------------------
+VosMutexFacade::VosMutexFacade( ::osl::Mutex& _rMutex )
+ :m_rMutex( _rMutex )
+{
+}
+
+//------------------------------------------------------------------------
+void SAL_CALL VosMutexFacade::acquire()
+{
+ m_rMutex.acquire();
+}
+
+//------------------------------------------------------------------------
+sal_Bool SAL_CALL VosMutexFacade::tryToAcquire()
+{
+ return m_rMutex.tryToAcquire();
+}
+
+//------------------------------------------------------------------------
+void SAL_CALL VosMutexFacade::release()
+{
+ m_rMutex.release();
+}
+
+//============================================================
+//= DocumentStorageAccess
+//============================================================
+DBG_NAME( DocumentStorageAccess )
+class DocumentStorageAccess : public ::cppu::WeakImplHelper2< XDocumentSubStorageSupplier
+ , XTransactionListener >
+{
+ typedef ::std::map< ::rtl::OUString, Reference< XStorage > > NamedStorages;
+
+ ::osl::Mutex m_aMutex;
+ /// all sub storages which we ever gave to the outer world
+ NamedStorages m_aExposedStorages;
+ ODatabaseModelImpl* m_pModelImplementation;
+ bool m_bPropagateCommitToRoot;
+
+public:
+ DocumentStorageAccess( ODatabaseModelImpl& _rModelImplementation )
+ :m_pModelImplementation( &_rModelImplementation )
+ ,m_bPropagateCommitToRoot( true )
+ {
+ DBG_CTOR( DocumentStorageAccess, NULL );
+ }
+
+protected:
+ ~DocumentStorageAccess()
+ {
+ DBG_DTOR( DocumentStorageAccess, NULL );
+ }
+
+public:
+ void dispose();
+
+ void suspendCommitPropagation()
+ {
+ DBG_ASSERT( m_bPropagateCommitToRoot, "DocumentStorageAccess:: suspendCommitPropagation: already suspended" );
+ m_bPropagateCommitToRoot = false;
+ }
+ void resumeCommitPropagation()
+ {
+ DBG_ASSERT( !m_bPropagateCommitToRoot, "DocumentStorageAccess:: suspendCommitPropagation: already suspended" );
+ m_bPropagateCommitToRoot = true;
+ }
+
+ // XDocumentSubStorageSupplier
+ virtual Reference< XStorage > SAL_CALL getDocumentSubStorage( const ::rtl::OUString& aStorageName, ::sal_Int32 nMode ) throw (RuntimeException);
+ virtual Sequence< ::rtl::OUString > SAL_CALL getDocumentSubStoragesNames( ) throw (IOException, RuntimeException);
+
+ // XTransactionListener
+ virtual void SAL_CALL preCommit( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL commited( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL preRevert( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL reverted( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
+
+ // XEventListener
+ virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
+};
+
+//--------------------------------------------------------------------------
+void DocumentStorageAccess::dispose()
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+
+ for ( NamedStorages::iterator loop = m_aExposedStorages.begin();
+ loop != m_aExposedStorages.end();
+ ++loop
+ )
+ {
+ try
+ {
+ Reference< XTransactionBroadcaster > xBroadcaster( loop->second, UNO_QUERY );
+ if ( xBroadcaster.is() )
+ xBroadcaster->removeTransactionListener( this );
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+ }
+
+ m_aExposedStorages.clear();
+
+ m_pModelImplementation = NULL;
+}
+
+//--------------------------------------------------------------------------
+Reference< XStorage > SAL_CALL DocumentStorageAccess::getDocumentSubStorage( const ::rtl::OUString& aStorageName, ::sal_Int32 nMode ) throw (RuntimeException)
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ NamedStorages::iterator pos = m_aExposedStorages.find( aStorageName );
+ if ( pos == m_aExposedStorages.end() )
+ {
+ Reference< XStorage > xResult = m_pModelImplementation->getStorage( aStorageName, nMode );
+ Reference< XTransactionBroadcaster > xBroadcaster( xResult, UNO_QUERY );
+ if ( xBroadcaster.is() )
+ xBroadcaster->addTransactionListener( this );
+
+ pos = m_aExposedStorages.insert( NamedStorages::value_type( aStorageName, xResult ) ).first;
+ }
+
+ return pos->second;
+}
+
+//--------------------------------------------------------------------------
+Sequence< ::rtl::OUString > SAL_CALL DocumentStorageAccess::getDocumentSubStoragesNames( ) throw (IOException, RuntimeException)
+{
+ Reference< XStorage > xRootStor( m_pModelImplementation->getRootStorage() );
+ if ( !xRootStor.is() )
+ return Sequence< ::rtl::OUString >();
+
+ ::std::vector< ::rtl::OUString > aNames;
+
+ Reference< XNameAccess > xNames( xRootStor, UNO_QUERY_THROW );
+ Sequence< ::rtl::OUString > aElementNames( xNames->getElementNames() );
+ for ( sal_Int32 i=0; i<aElementNames.getLength(); ++i )
+ {
+ if ( xRootStor->isStorageElement( aElementNames[i] ) )
+ aNames.push_back( aElementNames[i] );
+ }
+ return aNames.empty()
+ ? Sequence< ::rtl::OUString >()
+ : Sequence< ::rtl::OUString >( &aNames[0], aNames.size() );
+}
+
+//--------------------------------------------------------------------------
+void SAL_CALL DocumentStorageAccess::preCommit( const css::lang::EventObject& /*aEvent*/ ) throw (Exception, RuntimeException)
+{
+ // not interested in
+}
+
+//--------------------------------------------------------------------------
+void SAL_CALL DocumentStorageAccess::commited( const css::lang::EventObject& aEvent ) throw (RuntimeException)
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+
+ if ( m_pModelImplementation )
+ m_pModelImplementation->setModified( sal_True );
+
+ if ( m_pModelImplementation && m_bPropagateCommitToRoot )
+ {
+ Reference< XStorage > xStorage( aEvent.Source, UNO_QUERY );
+ if ( m_pModelImplementation->isDatabaseStorage( xStorage ) )
+ {
+ m_pModelImplementation->commitRootStorage();
+ }
+ }
+}
+
+//--------------------------------------------------------------------------
+void SAL_CALL DocumentStorageAccess::preRevert( const css::lang::EventObject& /*aEvent*/ ) throw (Exception, RuntimeException)
+{
+ // not interested in
+}
+
+//--------------------------------------------------------------------------
+void SAL_CALL DocumentStorageAccess::reverted( const css::lang::EventObject& /*aEvent*/ ) throw (RuntimeException)
+{
+ // not interested in
+}
+
+//--------------------------------------------------------------------------
+void SAL_CALL DocumentStorageAccess::disposing( const css::lang::EventObject& Source ) throw ( RuntimeException )
+{
+ ODatabaseModelImpl* pImpl = m_pModelImplementation;
+ if ( pImpl )
+ pImpl->disposing( Source );
+
+ for ( NamedStorages::iterator find = m_aExposedStorages.begin();
+ find != m_aExposedStorages.end();
+ ++find
+ )
+ if ( find->second == Source.Source )
+ {
+ m_aExposedStorages.erase( find );
+ break;
+ }
+}
+
+//============================================================
+//= ODatabaseModelImpl
+//============================================================
+DBG_NAME(ODatabaseModelImpl)
+//--------------------------------------------------------------------------
+ODatabaseModelImpl::ODatabaseModelImpl( const Reference< XMultiServiceFactory >& _rxFactory, ODatabaseContext& _rDBContext )
+ :m_xModel()
+ ,m_xDataSource()
+ ,m_pStorageAccess( NULL )
+ ,m_aMutex()
+ ,m_aMutexFacade( m_aMutex )
+ ,m_aContainer(4)
+ ,m_aStorages()
+ ,m_aMacroMode( *this )
+ ,m_nImposedMacroExecMode( MacroExecMode::NEVER_EXECUTE )
+ ,m_pDBContext( &_rDBContext )
+ ,m_refCount(0)
+ ,m_bHasAnyObjectWithMacros( false )
+ ,m_bHasMacroStorages( false )
+ ,m_bModificationLock( false )
+ ,m_bDocumentInitialized( false )
+ ,m_aContext( _rxFactory )
+ ,m_nLoginTimeout(0)
+ ,m_bReadOnly(sal_False)
+ ,m_bPasswordRequired(sal_False)
+ ,m_bSuppressVersionColumns(sal_True)
+ ,m_bModified(sal_False)
+ ,m_bDocumentReadOnly(sal_False)
+ ,m_bDisposingSubStorages( sal_False )
+ ,m_pSharedConnectionManager(NULL)
+ ,m_nControllerLockCount(0)
+{
+ // some kind of default
+ DBG_CTOR(ODatabaseModelImpl,NULL);
+ m_sConnectURL = ::rtl::OUString::createFromAscii("jdbc:");
+ m_aTableFilter.realloc(1);
+ m_aTableFilter[0] = ::rtl::OUString::createFromAscii("%");
+ impl_construct_nothrow();
+}
+
+//--------------------------------------------------------------------------
+ODatabaseModelImpl::ODatabaseModelImpl(
+ const ::rtl::OUString& _rRegistrationName,
+ const Reference< XMultiServiceFactory >& _rxFactory,
+ ODatabaseContext& _rDBContext
+ )
+ :m_xModel()
+ ,m_xDataSource()
+ ,m_pStorageAccess( NULL )
+ ,m_aMutex()
+ ,m_aMutexFacade( m_aMutex )
+ ,m_aContainer(4)
+ ,m_aStorages()
+ ,m_aMacroMode( *this )
+ ,m_nImposedMacroExecMode( MacroExecMode::NEVER_EXECUTE )
+ ,m_pDBContext( &_rDBContext )
+ ,m_refCount(0)
+ ,m_bHasAnyObjectWithMacros( false )
+ ,m_bHasMacroStorages( false )
+ ,m_bModificationLock( false )
+ ,m_bDocumentInitialized( false )
+ ,m_aContext( _rxFactory )
+ ,m_sName(_rRegistrationName)
+ ,m_nLoginTimeout(0)
+ ,m_bReadOnly(sal_False)
+ ,m_bPasswordRequired(sal_False)
+ ,m_bSuppressVersionColumns(sal_True)
+ ,m_bModified(sal_False)
+ ,m_bDocumentReadOnly(sal_False)
+ ,m_bDisposingSubStorages( sal_False )
+ ,m_pSharedConnectionManager(NULL)
+ ,m_nControllerLockCount(0)
+{
+ DBG_CTOR(ODatabaseModelImpl,NULL);
+ impl_construct_nothrow();
+}
+
+//--------------------------------------------------------------------------
+ODatabaseModelImpl::~ODatabaseModelImpl()
+{
+ DBG_DTOR(ODatabaseModelImpl,NULL);
+}
+
+// -----------------------------------------------------------------------------
+void ODatabaseModelImpl::impl_construct_nothrow()
+{
+ // create the property bag to hold the settings (also known as "Info" property)
+ try
+ {
+ // the set of property value types in the bag is limited:
+ Sequence< Type > aAllowedTypes(6);
+ Type* pAllowedType = aAllowedTypes.getArray();
+ *pAllowedType++ = ::getCppuType( static_cast< sal_Bool* >( NULL ) );
+ *pAllowedType++ = ::getCppuType( static_cast< double* >( NULL ) );
+ *pAllowedType++ = ::getCppuType( static_cast< ::rtl::OUString* >( NULL ) );
+ *pAllowedType++ = ::getCppuType( static_cast< sal_Int32* >( NULL ) );
+ *pAllowedType++ = ::getCppuType( static_cast< sal_Int16* >( NULL ) );
+ *pAllowedType++ = ::getCppuType( static_cast< Sequence< Any >* >( NULL ) );
+
+ Sequence< Any > aInitArgs( 2 );
+ aInitArgs[0] <<= NamedValue(
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AutomaticAddition" ) ),
+ makeAny( (sal_Bool)sal_True )
+ );
+ aInitArgs[1] <<= NamedValue(
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AllowedTypes" ) ),
+ makeAny( aAllowedTypes )
+ );
+
+ m_xSettings.set( m_aContext.createComponentWithArguments( "com.sun.star.beans.PropertyBag", aInitArgs ), UNO_QUERY_THROW );
+
+ // insert the default settings
+ Reference< XPropertyContainer > xContainer( m_xSettings, UNO_QUERY_THROW );
+ const AsciiPropertyValue* pSettings = getDefaultDataSourceSettings();
+ for ( ; pSettings->AsciiName; ++pSettings )
+ {
+ xContainer->addProperty(
+ ::rtl::OUString::createFromAscii( pSettings->AsciiName ),
+ PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
+ pSettings->DefaultValue
+ );
+ }
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+}
+
+// -----------------------------------------------------------------------------
+namespace
+{
+ // .........................................................................
+ ::rtl::OUString lcl_getContainerStorageName_throw( ODatabaseModelImpl::ObjectType _eType )
+ {
+ const sal_Char* pAsciiName( NULL );
+ switch ( _eType )
+ {
+ case ODatabaseModelImpl::E_FORM: pAsciiName = "forms"; break;
+ case ODatabaseModelImpl::E_REPORT: pAsciiName = "reports"; break;
+ case ODatabaseModelImpl::E_QUERY: pAsciiName = "queries"; break;
+ case ODatabaseModelImpl::E_TABLE: pAsciiName = "tables"; break;
+ default:
+ throw RuntimeException();
+ }
+ return ::rtl::OUString::createFromAscii( pAsciiName );
+ }
+
+ // .........................................................................
+ bool lcl_hasObjectWithMacros_throw( const ODefinitionContainer_Impl& _rObjectDefinitions, const Reference< XStorage >& _rxContainerStorage )
+ {
+ bool bSomeDocHasMacros = false;
+
+ for ( ODefinitionContainer_Impl::const_iterator object = _rObjectDefinitions.begin();
+ ( object != _rObjectDefinitions.end() ) && !bSomeDocHasMacros;
+ ++object
+ )
+ {
+#if OSL_DEBUG_LEVEL > 0
+ const ::rtl::OUString& rName( object->first ); (void)rName;
+#endif
+
+ const TContentPtr& rDefinition( object->second );
+ const ::rtl::OUString& rPersistentName( rDefinition->m_aProps.sPersistentName );
+
+ if ( !rPersistentName.getLength() )
+ { // it's a logical sub folder used to organize the real objects
+ const ODefinitionContainer_Impl& rSubFoldersObjectDefinitions( dynamic_cast< const ODefinitionContainer_Impl& >( *rDefinition.get() ) );
+ bSomeDocHasMacros = lcl_hasObjectWithMacros_throw( rSubFoldersObjectDefinitions, _rxContainerStorage );
+ continue;
+ }
+
+ bSomeDocHasMacros = ODatabaseModelImpl::objectHasMacros( _rxContainerStorage, rPersistentName );
+ }
+ return bSomeDocHasMacros;
+ }
+
+ // .........................................................................
+ bool lcl_hasObjectsWithMacros_nothrow( ODatabaseModelImpl& _rModel, const ODatabaseModelImpl::ObjectType _eType )
+ {
+ bool bSomeDocHasMacros = false;
+
+ const OContentHelper_Impl& rContainerData( *_rModel.getObjectContainer( _eType ).get() );
+ const ODefinitionContainer_Impl& rObjectDefinitions = dynamic_cast< const ODefinitionContainer_Impl& >( rContainerData );
+
+ try
+ {
+ Reference< XStorage > xContainerStorage( _rModel.getStorage(
+ _rModel.getObjectContainerStorageName( _eType ), ElementModes::READWRITE ) );
+ // note the READWRITE here: If the storage already existed before, then the OpenMode will
+ // be ignored, anyway.
+ // If the storage did not yet exist, then it will be created. If the database document
+ // is read-only, the OpenMode will be automatically downgraded to READ. Otherwise,
+ // the storage will in fact be created as READWRITE. While this is not strictly necessary
+ // for this particular use case here, it is required since the storage is *cached*, and
+ // later use cases will need the READWRITE mode.
+
+ if ( xContainerStorage.is() )
+ bSomeDocHasMacros = lcl_hasObjectWithMacros_throw( rObjectDefinitions, xContainerStorage );
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ // be on the safe side: If we can't reliably determine whether there are macros,
+ // assume there actually are. Better this way, than the other way round.
+ bSomeDocHasMacros = true;
+ }
+
+ return bSomeDocHasMacros;
+ }
+}
+
+// -----------------------------------------------------------------------------
+bool ODatabaseModelImpl::objectHasMacros( const Reference< XStorage >& _rxContainerStorage, const ::rtl::OUString& _rPersistentName )
+{
+ OSL_PRECOND( _rxContainerStorage.is(), "ODatabaseModelImpl::objectHasMacros: this will crash!" );
+
+ bool bHasMacros = true;
+ try
+ {
+ if ( !_rxContainerStorage->hasByName( _rPersistentName ) )
+ return false;
+
+ Reference< XStorage > xObjectStor( _rxContainerStorage->openStorageElement(
+ _rPersistentName, ElementModes::READ ) );
+
+ bHasMacros = ::sfx2::DocumentMacroMode::storageHasMacros( xObjectStor );
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+ return bHasMacros;
+}
+
+// -----------------------------------------------------------------------------
+void ODatabaseModelImpl::reset()
+{
+ m_bReadOnly = sal_False;
+ ::std::vector< TContentPtr > aEmptyContainers( 4 );
+ m_aContainer.swap( aEmptyContainers );
+
+ if ( m_pStorageAccess )
+ {
+ m_pStorageAccess->dispose();
+ m_pStorageAccess->release();
+ m_pStorageAccess = NULL;
+ }
+}
+// -----------------------------------------------------------------------------
+void SAL_CALL ODatabaseModelImpl::disposing( const ::com::sun::star::lang::EventObject& Source ) throw(RuntimeException)
+{
+ Reference<XConnection> xCon(Source.Source,UNO_QUERY);
+ if ( xCon.is() )
+ {
+ bool bStore = false;
+ OWeakConnectionArray::iterator aEnd = m_aConnections.end();
+ for (OWeakConnectionArray::iterator i = m_aConnections.begin(); aEnd != i; ++i)
+ {
+ if ( xCon == i->get() )
+ {
+ *i = OWeakConnection();
+ bStore = true;
+ break;
+ }
+ }
+
+ if ( bStore )
+ commitRootStorage();
+ }
+ else // storage
+ {
+ if ( !m_bDisposingSubStorages )
+ {
+ Reference<XStorage> xStorage(Source.Source,UNO_QUERY);
+ TStorages::iterator aFind = ::std::find_if(m_aStorages.begin(),m_aStorages.end(),
+ ::std::compose1(::std::bind2nd(::std::equal_to<Reference<XStorage> >(),xStorage),::std::select2nd<TStorages::value_type>()));
+ if ( aFind != m_aStorages.end() )
+ m_aStorages.erase(aFind);
+ }
+ }
+}
+//------------------------------------------------------------------------------
+void ODatabaseModelImpl::clearConnections()
+{
+ OWeakConnectionArray aConnections;
+ aConnections.swap( m_aConnections );
+
+ Reference< XConnection > xConn;
+ for ( OWeakConnectionArray::iterator i = aConnections.begin(); aConnections.end() != i; ++i )
+ {
+ xConn = *i;
+ if ( xConn.is() )
+ {
+ try
+ {
+ xConn->close();
+ }
+ catch(const Exception&)
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+ }
+ }
+
+ m_pSharedConnectionManager = NULL;
+ m_xSharedConnectionManager = NULL;
+}
+//------------------------------------------------------------------------------
+void ODatabaseModelImpl::dispose()
+{
+ // dispose the data source and the model
+ try
+ {
+ Reference< XDataSource > xDS( m_xDataSource );
+ ::comphelper::disposeComponent( xDS );
+
+ Reference< XModel > xModel( m_xModel );
+ ::comphelper::disposeComponent( xModel );
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+ m_xDataSource = WeakReference<XDataSource>();
+ m_xModel = WeakReference< XModel >();
+
+ ::std::vector<TContentPtr>::iterator aIter = m_aContainer.begin();
+ ::std::vector<TContentPtr>::iterator aEnd = m_aContainer.end();
+ for (;aIter != aEnd ; ++aIter)
+ {
+ if ( aIter->get() )
+ (*aIter)->m_pDataSource = NULL;
+ }
+ m_aContainer.clear();
+
+ clearConnections();
+
+ m_xNumberFormatsSupplier = NULL;
+
+ try
+ {
+ sal_Bool bStore = commitEmbeddedStorage();
+ disposeStorages();
+ if ( bStore )
+ commitRootStorage();
+
+ impl_switchToStorage_throw( NULL );
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+
+ if ( m_pStorageAccess )
+ {
+ m_pStorageAccess->dispose();
+ m_pStorageAccess->release();
+ m_pStorageAccess = NULL;
+ }
+}
+// -----------------------------------------------------------------------------
+const Reference< XNumberFormatsSupplier > & ODatabaseModelImpl::getNumberFormatsSupplier()
+{
+ if (!m_xNumberFormatsSupplier.is())
+ {
+ // the arguments : the locale of the current user
+ UserInformation aUserInfo;
+ Sequence< Any > aArguments(1);
+ aArguments.getArray()[0] <<= aUserInfo.getUserLanguage();
+
+ m_xNumberFormatsSupplier.set(
+ m_aContext.createComponentWithArguments( "com.sun.star.util.NumberFormatsSupplier", aArguments ), UNO_QUERY_THROW );
+ DBG_ASSERT(m_xNumberFormatsSupplier.is(), "ODatabaseModelImpl::getNumberFormatsSupplier : could not instantiate the formats supplier !");
+ }
+ return m_xNumberFormatsSupplier;
+}
+// -----------------------------------------------------------------------------
+void ODatabaseModelImpl::attachResource( const ::rtl::OUString& _rURL, const Sequence< PropertyValue >& _rArgs )
+{
+ ::comphelper::NamedValueCollection aMediaDescriptor( _rArgs );
+
+ ::rtl::OUString sDocumentLocation( aMediaDescriptor.getOrDefault( "SalvagedFile", _rURL ) );
+ if ( !sDocumentLocation.getLength() )
+ // this indicates "the document is being recovered, but _rURL already is the real document URL,
+ // not the temporary document location"
+ sDocumentLocation = _rURL;
+
+ if ( aMediaDescriptor.has( "SalvagedFile" ) )
+ aMediaDescriptor.remove( "SalvagedFile" );
+
+ m_aArgs = stripLoadArguments( aMediaDescriptor );
+
+ switchToURL( sDocumentLocation, _rURL );
+}
+
+// -----------------------------------------------------------------------------
+Sequence< PropertyValue > ODatabaseModelImpl::stripLoadArguments( const ::comphelper::NamedValueCollection& _rArguments )
+{
+ OSL_ENSURE( !_rArguments.has( "Model" ), "ODatabaseModelImpl::stripLoadArguments: this is suspicious (1)!" );
+ OSL_ENSURE( !_rArguments.has( "ViewName" ), "ODatabaseModelImpl::stripLoadArguments: this is suspicious (2)!" );
+
+ ::comphelper::NamedValueCollection aMutableArgs( _rArguments );
+ aMutableArgs.remove( "Model" );
+ aMutableArgs.remove( "ViewName" );
+ return aMutableArgs.getPropertyValues();
+}
+
+// -----------------------------------------------------------------------------
+void ODatabaseModelImpl::disposeStorages() SAL_THROW(())
+{
+ m_bDisposingSubStorages = sal_True;
+
+ TStorages::iterator aEnd = m_aStorages.end();
+ for ( TStorages::iterator aIter = m_aStorages.begin();
+ aIter != aEnd ;
+ ++aIter
+ )
+ {
+ try
+ {
+ ::comphelper::disposeComponent( aIter->second );
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+ }
+ m_aStorages.clear();
+
+ m_bDisposingSubStorages = sal_False;
+}
+// -----------------------------------------------------------------------------
+Reference< XSingleServiceFactory > ODatabaseModelImpl::createStorageFactory() const
+{
+ return Reference< XSingleServiceFactory >( m_aContext.createComponent( "com.sun.star.embed.StorageFactory" ), UNO_QUERY_THROW );
+}
+// -----------------------------------------------------------------------------
+void ODatabaseModelImpl::commitRootStorage()
+{
+ Reference< XStorage > xStorage( getOrCreateRootStorage() );
+#if OSL_DEBUG_LEVEL > 0
+ bool bSuccess =
+#endif
+ commitStorageIfWriteable_ignoreErrors( xStorage );
+ OSL_ENSURE( bSuccess || !xStorage.is(),
+ "ODatabaseModelImpl::commitRootStorage: could commit the storage!" );
+}
+// -----------------------------------------------------------------------------
+Reference< XStorage > ODatabaseModelImpl::getOrCreateRootStorage()
+{
+ if ( !m_xDocumentStorage.is() )
+ {
+ Reference< XSingleServiceFactory> xStorageFactory = createStorageFactory();
+ if ( xStorageFactory.is() )
+ {
+ Any aSource;
+ ::comphelper::NamedValueCollection aArgs( m_aArgs );
+
+ aSource = aArgs.get( "Stream" );
+ if ( !aSource.hasValue() )
+ aSource = aArgs.get( "InputStream" );
+ if ( !aSource.hasValue() && m_sDocFileLocation.getLength() )
+ aSource <<= m_sDocFileLocation;
+ // TODO: shouldn't we also check URL?
+
+ OSL_ENSURE( aSource.hasValue(), "ODatabaseModelImpl::getOrCreateRootStorage: no source to create the storage from!" );
+
+ if ( aSource.hasValue() )
+ {
+ Sequence< Any > aStorageCreationArgs(2);
+ aStorageCreationArgs[0] = aSource;
+ aStorageCreationArgs[1] <<= ElementModes::READWRITE;
+
+ Reference< XStorage > xDocumentStorage;
+ try
+ {
+ xDocumentStorage.set( xStorageFactory->createInstanceWithArguments( aStorageCreationArgs ), UNO_QUERY_THROW );
+ }
+ catch( const Exception& )
+ {
+ m_bDocumentReadOnly = sal_True;
+ aStorageCreationArgs[1] <<= ElementModes::READ;
+ try
+ {
+ xDocumentStorage.set( xStorageFactory->createInstanceWithArguments( aStorageCreationArgs ), UNO_QUERY_THROW );
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+ }
+
+ impl_switchToStorage_throw( xDocumentStorage );
+ }
+ }
+ }
+ return m_xDocumentStorage.getTyped();
+}
+// -----------------------------------------------------------------------------
+DocumentStorageAccess* ODatabaseModelImpl::getDocumentStorageAccess()
+{
+ if ( !m_pStorageAccess )
+ {
+ m_pStorageAccess = new DocumentStorageAccess( *this );
+ m_pStorageAccess->acquire();
+ }
+ return m_pStorageAccess;
+}
+
+// -----------------------------------------------------------------------------
+void ODatabaseModelImpl::modelIsDisposing( const bool _wasInitialized, ResetModelAccess )
+{
+ m_xModel = Reference< XModel >();
+
+ // Basic libraries and Dialog libraries are a model facet, though held at this impl class.
+ // They automatically dispose themself when the model they belong to is being disposed.
+ // So, to not be tempted to do anything with them, again, we reset them.
+ m_xBasicLibraries.clear();
+ m_xDialogLibraries.clear();
+
+ m_bDocumentInitialized = _wasInitialized;
+}
+
+// -----------------------------------------------------------------------------
+Reference< XDocumentSubStorageSupplier > ODatabaseModelImpl::getDocumentSubStorageSupplier()
+{
+ return getDocumentStorageAccess();
+}
+// -----------------------------------------------------------------------------
+Reference<XStorage> ODatabaseModelImpl::getStorage( const ::rtl::OUString& _sStorageName, sal_Int32 _nMode )
+{
+ OSL_ENSURE(_sStorageName.getLength(),"ODatabaseModelImpl::getStorage: Invalid storage name!");
+ Reference<XStorage> xStorage;
+ TStorages::iterator aFind = m_aStorages.find(_sStorageName);
+ if ( aFind == m_aStorages.end() )
+ {
+ try
+ {
+ Reference< XStorage > xMyStorage( getOrCreateRootStorage() );
+ if ( xMyStorage.is() )
+ {
+ sal_Int32 nMode = m_bDocumentReadOnly ? ElementModes::READ : _nMode;
+ if ( nMode == ElementModes::READ )
+ {
+ Reference< XNameAccess > xSubStorageNames( xMyStorage, UNO_QUERY );
+ if ( xSubStorageNames.is() && !xSubStorageNames->hasByName( _sStorageName ) )
+ return xStorage;
+ }
+
+ xStorage = xMyStorage->openStorageElement( _sStorageName, nMode );
+ Reference< XTransactionBroadcaster > xBroad( xStorage, UNO_QUERY );
+ if ( xBroad.is() )
+ xBroad->addTransactionListener( getDocumentStorageAccess() );
+ aFind = m_aStorages.insert( TStorages::value_type( _sStorageName, xStorage ) ).first;
+ }
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+ }
+
+ if ( aFind != m_aStorages.end() )
+ xStorage = aFind->second;
+
+ return xStorage;
+}
+// -----------------------------------------------------------------------------
+sal_Bool ODatabaseModelImpl::commitEmbeddedStorage( sal_Bool _bPreventRootCommits )
+{
+ if ( _bPreventRootCommits && m_pStorageAccess )
+ m_pStorageAccess->suspendCommitPropagation();
+
+ sal_Bool bStore = sal_False;
+ try
+ {
+ TStorages::iterator aFind = m_aStorages.find(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("database")));
+ if ( aFind != m_aStorages.end() )
+ bStore = commitStorageIfWriteable(aFind->second);
+ }
+ catch(Exception&)
+ {
+ OSL_ENSURE(0,"Exception Caught: Could not store embedded database!");
+ }
+
+ if ( _bPreventRootCommits && m_pStorageAccess )
+ m_pStorageAccess->resumeCommitPropagation();
+
+ return bStore;
+
+}
+
+// -----------------------------------------------------------------------------
+namespace
+{
+ bool lcl_storageIsWritable_nothrow( const Reference< XStorage >& _rxStorage )
+ {
+ if ( !_rxStorage.is() )
+ return false;
+
+ sal_Int32 nMode = ElementModes::READ;
+ try
+ {
+ Reference< XPropertySet > xStorageProps( _rxStorage, UNO_QUERY_THROW );
+ xStorageProps->getPropertyValue(
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OpenMode" ) ) ) >>= nMode;
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+ return ( nMode & ElementModes::WRITE ) != 0;
+ }
+}
+
+// -----------------------------------------------------------------------------
+bool ODatabaseModelImpl::commitStorageIfWriteable( const Reference< XStorage >& _rxStorage ) SAL_THROW(( IOException, WrappedTargetException, RuntimeException ))
+{
+ bool bSuccess = false;
+ Reference<XTransactedObject> xTrans( _rxStorage, UNO_QUERY );
+ if ( xTrans.is() )
+ {
+ if ( lcl_storageIsWritable_nothrow( _rxStorage ) )
+ xTrans->commit();
+ bSuccess = true;
+ }
+ return bSuccess;
+}
+// -----------------------------------------------------------------------------
+bool ODatabaseModelImpl::commitStorageIfWriteable_ignoreErrors( const Reference< XStorage >& _rxStorage ) SAL_THROW(())
+{
+ bool bSuccess = false;
+ try
+ {
+ bSuccess = commitStorageIfWriteable( _rxStorage );
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+ return bSuccess;
+}
+// -----------------------------------------------------------------------------
+void ODatabaseModelImpl::setModified( sal_Bool _bModified )
+{
+ if ( isModifyLocked() )
+ return;
+
+ try
+ {
+ Reference< XModifiable > xModi( m_xModel.get(), UNO_QUERY );
+ if ( xModi.is() )
+ xModi->setModified( _bModified );
+ else
+ m_bModified = _bModified;
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+}
+
+// -----------------------------------------------------------------------------
+Reference<XDataSource> ODatabaseModelImpl::getOrCreateDataSource()
+{
+ Reference<XDataSource> xDs = m_xDataSource;
+ if ( !xDs.is() )
+ {
+ xDs = new ODatabaseSource(this);
+ m_xDataSource = xDs;
+ }
+ return xDs;
+}
+// -----------------------------------------------------------------------------
+Reference< XModel> ODatabaseModelImpl::getModel_noCreate() const
+{
+ return m_xModel;
+}
+// -----------------------------------------------------------------------------
+Reference< XModel > ODatabaseModelImpl::createNewModel_deliverOwnership( bool _bInitialize )
+{
+ Reference< XModel > xModel( m_xModel );
+ OSL_PRECOND( !xModel.is(), "ODatabaseModelImpl::createNewModel_deliverOwnership: not to be called if there already is a model!" );
+ if ( !xModel.is() )
+ {
+ xModel = ODatabaseDocument::createDatabaseDocument( this, ODatabaseDocument::FactoryAccess() );
+ m_xModel = xModel;
+
+ try
+ {
+ Reference< XSet > xModelCollection;
+ if ( m_aContext.createComponent( "com.sun.star.frame.GlobalEventBroadcaster", xModelCollection ) )
+ xModelCollection->insert( makeAny( xModel ) );
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+
+ if ( _bInitialize )
+ {
+ try
+ {
+ Reference< XLoadable > xLoad( xModel, UNO_QUERY_THROW );
+ xLoad->initNew();
+ }
+ catch( RuntimeException& ) { throw; }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+ }
+ }
+ return xModel;
+}
+// -----------------------------------------------------------------------------
+oslInterlockedCount SAL_CALL ODatabaseModelImpl::acquire()
+{
+ return osl_incrementInterlockedCount(&m_refCount);
+}
+// -----------------------------------------------------------------------------
+oslInterlockedCount SAL_CALL ODatabaseModelImpl::release()
+{
+ if ( osl_decrementInterlockedCount(&m_refCount) == 0 )
+ {
+ acquire(); // prevent multiple releases
+ dispose();
+ m_pDBContext->storeTransientProperties(*this);
+ revokeDataSource();
+ delete this;
+ return 0;
+ }
+ return m_refCount;
+}
+// -----------------------------------------------------------------------------
+void ODatabaseModelImpl::commitStorages() SAL_THROW(( IOException, RuntimeException ))
+{
+ try
+ {
+ TStorages::iterator aIter = m_aStorages.begin();
+ TStorages::iterator aEnd = m_aStorages.end();
+ for (; aIter != aEnd ; ++aIter)
+ commitStorageIfWriteable( aIter->second );
+ }
+ catch(const WrappedTargetException&)
+ {
+ // WrappedTargetException not allowed to leave
+ throw IOException();
+ }
+}
+
+// -----------------------------------------------------------------------------
+const AsciiPropertyValue* ODatabaseModelImpl::getDefaultDataSourceSettings()
+{
+ static const AsciiPropertyValue aKnownSettings[] =
+ {
+ // known JDBC settings
+ AsciiPropertyValue( "JavaDriverClass", makeAny( ::rtl::OUString() ) ),
+ // known settings for file-based drivers
+ AsciiPropertyValue( "Extension", makeAny( ::rtl::OUString() ) ),
+ AsciiPropertyValue( "CharSet", makeAny( ::rtl::OUString() ) ),
+ AsciiPropertyValue( "HeaderLine", makeAny( (sal_Bool)sal_True ) ),
+ AsciiPropertyValue( "FieldDelimiter", makeAny( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "," ) ) ) ),
+ AsciiPropertyValue( "StringDelimiter", makeAny( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "\"" ) ) ) ),
+ AsciiPropertyValue( "DecimalDelimiter", makeAny( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "." ) ) ) ),
+ AsciiPropertyValue( "ThousandDelimiter", makeAny( ::rtl::OUString() ) ),
+ AsciiPropertyValue( "ShowDeleted", makeAny( (sal_Bool)sal_False ) ),
+ // known ODBC settings
+ AsciiPropertyValue( "SystemDriverSettings", makeAny( ::rtl::OUString() ) ),
+ AsciiPropertyValue( "UseCatalog", makeAny( (sal_Bool)sal_False ) ),
+ // settings related to auto increment handling
+ AsciiPropertyValue( "AutoIncrementCreation", makeAny( ::rtl::OUString() ) ),
+ AsciiPropertyValue( "AutoRetrievingStatement", makeAny( ::rtl::OUString() ) ),
+ AsciiPropertyValue( "IsAutoRetrievingEnabled", makeAny( (sal_Bool)sal_False ) ),
+ // known Adabas D driver setting
+ AsciiPropertyValue( "ShutdownDatabase", makeAny( (sal_Bool)sal_False ) ),
+ AsciiPropertyValue( "DataCacheSizeIncrement", makeAny( (sal_Int32)20 ) ),
+ AsciiPropertyValue( "DataCacheSize", makeAny( (sal_Int32)20 ) ),
+ AsciiPropertyValue( "ControlUser", makeAny( ::rtl::OUString() ) ),
+ AsciiPropertyValue( "ControlPassword", makeAny( ::rtl::OUString() ) ),
+ // known LDAP driver settings
+ AsciiPropertyValue( "HostName", makeAny( ::rtl::OUString() ) ),
+ AsciiPropertyValue( "PortNumber", makeAny( (sal_Int32)389 ) ),
+ AsciiPropertyValue( "BaseDN", makeAny( ::rtl::OUString() ) ),
+ AsciiPropertyValue( "MaxRowCount", makeAny( (sal_Int32)100 ) ),
+ // misc known driver settings
+ AsciiPropertyValue( "ParameterNameSubstitution", makeAny( (sal_Bool)sal_False ) ),
+ AsciiPropertyValue( "AddIndexAppendix", makeAny( (sal_Bool)sal_True ) ),
+ // known SDB level settings
+ AsciiPropertyValue( "IgnoreDriverPrivileges", makeAny( (sal_Bool)sal_True ) ),
+ AsciiPropertyValue( "NoNameLengthLimit", makeAny( (sal_Bool)sal_False ) ),
+ AsciiPropertyValue( "AppendTableAliasName", makeAny( (sal_Bool)sal_False ) ),
+ AsciiPropertyValue( "GenerateASBeforeCorrelationName", makeAny( (sal_Bool)sal_True ) ),
+ AsciiPropertyValue( "ColumnAliasInOrderBy", makeAny( (sal_Bool)sal_True ) ),
+ AsciiPropertyValue( "EnableSQL92Check", makeAny( (sal_Bool)sal_False ) ),
+ AsciiPropertyValue( "BooleanComparisonMode", makeAny( BooleanComparisonMode::EQUAL_INTEGER ) ),
+ AsciiPropertyValue( "TableTypeFilterMode", makeAny( (sal_Int32)3 ) ),
+ AsciiPropertyValue( "RespectDriverResultSetType", makeAny( (sal_Bool)sal_False ) ),
+ AsciiPropertyValue( "UseSchemaInSelect", makeAny( (sal_Bool)sal_True ) ),
+ AsciiPropertyValue( "UseCatalogInSelect", makeAny( (sal_Bool)sal_True ) ),
+ AsciiPropertyValue( "EnableOuterJoinEscape", makeAny( (sal_Bool)sal_True ) ),
+ AsciiPropertyValue( "PreferDosLikeLineEnds", makeAny( (sal_Bool)sal_False ) ),
+ AsciiPropertyValue( "FormsCheckRequiredFields", makeAny( (sal_Bool)sal_True ) ),
+ AsciiPropertyValue( "EscapeDateTime", makeAny( (sal_Bool)sal_True ) ),
+ AsciiPropertyValue( "IgnoreCurrency", makeAny( (sal_Bool)sal_False ) ),
+ AsciiPropertyValue( "TypeInfoSettings", makeAny( Sequence< Any >()) ),
+ AsciiPropertyValue( "LocalSocket", makeAny( ::rtl::OUString() ) ),
+
+ AsciiPropertyValue( NULL, Any() )
+ };
+ return aKnownSettings;
+}
+
+// -----------------------------------------------------------------------------
+TContentPtr& ODatabaseModelImpl::getObjectContainer( ObjectType _eType )
+{
+ OSL_PRECOND( _eType >= E_FORM && _eType <= E_TABLE, "ODatabaseModelImpl::getObjectContainer: illegal index!" );
+ TContentPtr& rContentPtr = m_aContainer[ _eType ];
+
+ if ( !rContentPtr.get() )
+ {
+ rContentPtr = TContentPtr( new ODefinitionContainer_Impl );
+ rContentPtr->m_pDataSource = this;
+ rContentPtr->m_aProps.aTitle = lcl_getContainerStorageName_throw( _eType );
+ }
+ return rContentPtr;
+}
+
+// -----------------------------------------------------------------------------
+void ODatabaseModelImpl::revokeDataSource() const
+{
+ if ( m_pDBContext && m_sDocumentURL.getLength() )
+ m_pDBContext->deregisterPrivate( m_sDocumentURL );
+}
+
+// -----------------------------------------------------------------------------
+bool ODatabaseModelImpl::adjustMacroMode_AutoReject()
+{
+ return m_aMacroMode.adjustMacroMode( NULL );
+}
+
+// -----------------------------------------------------------------------------
+bool ODatabaseModelImpl::checkMacrosOnLoading()
+{
+ ::comphelper::NamedValueCollection aArgs( m_aArgs );
+ Reference< XInteractionHandler > xInteraction;
+ xInteraction = aArgs.getOrDefault( "InteractionHandler", xInteraction );
+ return m_aMacroMode.checkMacrosOnLoading( xInteraction );
+}
+
+// -----------------------------------------------------------------------------
+void ODatabaseModelImpl::resetMacroExecutionMode()
+{
+ m_aMacroMode = ::sfx2::DocumentMacroMode( *this );
+}
+
+// -----------------------------------------------------------------------------
+Reference< XStorageBasedLibraryContainer > ODatabaseModelImpl::getLibraryContainer( bool _bScript )
+{
+ Reference< XStorageBasedLibraryContainer >& rxContainer( _bScript ? m_xBasicLibraries : m_xDialogLibraries );
+ if ( rxContainer.is() )
+ return rxContainer;
+
+ Reference< XStorageBasedDocument > xDocument( getModel_noCreate(), UNO_QUERY_THROW );
+ // this is only to be called if there already exists a document model - in fact, it is
+ // to be called by the document model only
+
+ try
+ {
+ Reference< XStorageBasedLibraryContainer > (*Factory)( const Reference< XComponentContext >&, const Reference< XStorageBasedDocument >&)
+ = _bScript ? &DocumentScriptLibraryContainer::create : &DocumentDialogLibraryContainer::create;
+
+ rxContainer.set(
+ (*Factory)( m_aContext.getUNOContext(), xDocument ),
+ UNO_QUERY_THROW
+ );
+ }
+ catch( const RuntimeException& )
+ {
+ throw;
+ }
+ catch( const Exception& )
+ {
+ throw WrappedTargetRuntimeException(
+ ::rtl::OUString(),
+ xDocument,
+ ::cppu::getCaughtException()
+ );
+ }
+ return rxContainer;
+}
+
+// -----------------------------------------------------------------------------
+void ODatabaseModelImpl::storeLibraryContainersTo( const Reference< XStorage >& _rxToRootStorage )
+{
+ if ( m_xBasicLibraries.is() )
+ m_xBasicLibraries->storeLibrariesToStorage( _rxToRootStorage );
+
+ if ( m_xDialogLibraries.is() )
+ m_xDialogLibraries->storeLibrariesToStorage( _rxToRootStorage );
+}
+
+// -----------------------------------------------------------------------------
+Reference< XStorage > ODatabaseModelImpl::switchToStorage( const Reference< XStorage >& _rxNewRootStorage )
+{
+ if ( !_rxNewRootStorage.is() )
+ throw IllegalArgumentException();
+
+ return impl_switchToStorage_throw( _rxNewRootStorage );
+}
+
+// -----------------------------------------------------------------------------
+namespace
+{
+ void lcl_modifyListening( ::sfx2::IModifiableDocument& _rDocument,
+ const Reference< XStorage >& _rxStorage, ::rtl::Reference< ::sfx2::DocumentStorageModifyListener >& _inout_rListener,
+ ::vos::IMutex& _rMutex, bool _bListen )
+ {
+ Reference< XModifiable > xModify( _rxStorage, UNO_QUERY );
+ OSL_ENSURE( xModify.is() || !_rxStorage.is(), "lcl_modifyListening: storage can't notify us!" );
+
+ if ( xModify.is() && !_bListen && _inout_rListener.is() )
+ {
+ xModify->removeModifyListener( _inout_rListener.get() );
+ }
+
+ if ( _inout_rListener.is() )
+ {
+ _inout_rListener->dispose();
+ _inout_rListener = NULL;
+ }
+
+ if ( xModify.is() && _bListen )
+ {
+ _inout_rListener = new ::sfx2::DocumentStorageModifyListener( _rDocument, _rMutex );
+ xModify->addModifyListener( _inout_rListener.get() );
+ }
+ }
+}
+
+// -----------------------------------------------------------------------------
+namespace
+{
+ static void lcl_rebaseScriptStorage_throw( const Reference< XStorageBasedLibraryContainer >& _rxContainer,
+ const Reference< XStorage >& _rxNewRootStorage )
+ {
+ if ( _rxContainer.is() )
+ {
+ if ( _rxNewRootStorage.is() )
+ _rxContainer->setRootStorage( _rxNewRootStorage );
+// else
+ // TODO: what to do here? dispose the container?
+ }
+ }
+}
+
+// -----------------------------------------------------------------------------
+Reference< XStorage > ODatabaseModelImpl::impl_switchToStorage_throw( const Reference< XStorage >& _rxNewRootStorage )
+{
+ // stop listening for modifications at the old storage
+ lcl_modifyListening( *this, m_xDocumentStorage.getTyped(), m_pStorageModifyListener, m_aMutexFacade, false );
+
+ // set new storage
+ m_xDocumentStorage.reset( _rxNewRootStorage, SharedStorage::TakeOwnership );
+
+ // start listening for modifications
+ lcl_modifyListening( *this, m_xDocumentStorage.getTyped(), m_pStorageModifyListener, m_aMutexFacade, true );
+
+ // forward new storage to Basic and Dialog library containers
+ lcl_rebaseScriptStorage_throw( m_xBasicLibraries, m_xDocumentStorage.getTyped() );
+ lcl_rebaseScriptStorage_throw( m_xDialogLibraries, m_xDocumentStorage.getTyped() );
+
+ m_bReadOnly = !lcl_storageIsWritable_nothrow( m_xDocumentStorage.getTyped() );
+ // TODO: our data source, if it exists, must broadcast the change of its ReadOnly property
+
+ return m_xDocumentStorage.getTyped();
+}
+
+// -----------------------------------------------------------------------------
+void ODatabaseModelImpl::switchToURL( const ::rtl::OUString& _rDocumentLocation, const ::rtl::OUString& _rDocumentURL )
+{
+ // register at the database context, or change registration
+ if ( _rDocumentURL != m_sDocumentURL )
+ {
+ if ( m_pDBContext )
+ {
+ if ( m_sDocumentURL.getLength() )
+ m_pDBContext->nameChangePrivate( m_sDocumentURL, _rDocumentURL );
+ else
+ m_pDBContext->registerPrivate( _rDocumentURL, this );
+ }
+
+ if ( ( m_sName == m_sDocumentURL ) // our name is our old URL
+ || ( !m_sName.getLength() ) // we do not have a name, yet (i.e. are not registered at the database context)
+ )
+ {
+ INetURLObject aURL( _rDocumentURL );
+ if ( aURL.GetProtocol() != INET_PROT_NOT_VALID )
+ {
+ m_sName = _rDocumentURL;
+ // TODO: our data source must broadcast the change of the Name property
+ }
+ }
+ }
+
+ // remember both
+ m_sDocFileLocation = _rDocumentLocation.getLength() ? _rDocumentLocation : _rDocumentURL;
+ m_sDocumentURL = _rDocumentURL;
+}
+
+// -----------------------------------------------------------------------------
+bool ODatabaseModelImpl::isDatabaseStorage( const Reference< XStorage >& _rxStorage ) const
+{
+ TStorages::const_iterator pos = m_aStorages.find( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "database" ) ) );
+ if ( ( pos != m_aStorages.end() )
+ && ( pos->second == _rxStorage )
+ )
+ {
+ return true;
+ }
+ return false;
+}
+
+// -----------------------------------------------------------------------------
+::rtl::OUString ODatabaseModelImpl::getObjectContainerStorageName( const ObjectType _eType )
+{
+ return lcl_getContainerStorageName_throw( _eType );
+}
+
+// -----------------------------------------------------------------------------
+sal_Int16 ODatabaseModelImpl::getCurrentMacroExecMode() const
+{
+ sal_Int16 nCurrentMode = MacroExecMode::NEVER_EXECUTE;
+ try
+ {
+ ::comphelper::NamedValueCollection aArgs( m_aArgs );
+ nCurrentMode = aArgs.getOrDefault( "MacroExecutionMode", nCurrentMode );
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+ return nCurrentMode;
+}
+
+// -----------------------------------------------------------------------------
+sal_Bool ODatabaseModelImpl::setCurrentMacroExecMode( sal_uInt16 nMacroMode )
+{
+ try
+ {
+ ::comphelper::NamedValueCollection aArgs( m_aArgs );
+ aArgs.put( "MacroExecutionMode", nMacroMode );
+ aArgs >>= m_aArgs;
+ return sal_True;
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+
+ return sal_False;
+}
+
+// -----------------------------------------------------------------------------
+::rtl::OUString ODatabaseModelImpl::getDocumentLocation() const
+{
+ // don't return getURL() (or m_sDocumentURL, which is the same). In case we were recovered
+ // after a previous crash of OOo, m_sDocFileLocation points to the file which were loaded from,
+ // and this is the one we need for security checks.
+ return getDocFileLocation();
+}
+
+// -----------------------------------------------------------------------------
+Reference< XStorage > ODatabaseModelImpl::getLastCommitDocumentStorage()
+{
+ // we do not support signing the scripting storages, so we're allowed to
+ // return <NULL/> here.
+ return Reference< XStorage >();
+}
+
+// -----------------------------------------------------------------------------
+sal_Bool ODatabaseModelImpl::documentStorageHasMacros() const
+{
+ // does our root storage contain macros?
+ if ( ::sfx2::DocumentMacroMode::storageHasMacros( m_xDocumentStorage ) )
+ {
+ const_cast< ODatabaseModelImpl* >( this )->m_bHasMacroStorages = true;
+ return true;
+ }
+
+ // do we have forms or reports with macros?
+ if ( lcl_hasObjectsWithMacros_nothrow( const_cast< ODatabaseModelImpl& >( *this ), E_FORM )
+ || lcl_hasObjectsWithMacros_nothrow( const_cast< ODatabaseModelImpl& >( *this ), E_REPORT )
+ )
+ {
+ const_cast< ODatabaseModelImpl* >( this )->m_bHasAnyObjectWithMacros = true;
+ return true;
+ }
+
+ return false;
+}
+
+// -----------------------------------------------------------------------------
+Reference< XEmbeddedScripts > ODatabaseModelImpl::getEmbeddedDocumentScripts() const
+{
+ return Reference< XEmbeddedScripts >( getModel_noCreate(), UNO_QUERY );
+}
+
+// -----------------------------------------------------------------------------
+sal_Int16 ODatabaseModelImpl::getScriptingSignatureState() const
+{
+ // no support for signatures at the moment
+ return SIGNATURESTATE_NOSIGNATURES;
+}
+
+// -----------------------------------------------------------------------------
+void ODatabaseModelImpl::showBrokenSignatureWarning( const Reference< XInteractionHandler >& /*_rxInteraction*/ ) const
+{
+ OSL_ENSURE( false, "ODatabaseModelImpl::showBrokenSignatureWarning: signatures can't be broken - we do not support them!" );
+}
+
+// -----------------------------------------------------------------------------
+void ODatabaseModelImpl::storageIsModified()
+{
+ setModified( sal_True );
+}
+
+// -----------------------------------------------------------------------------
+ModelDependentComponent::ModelDependentComponent( const ::rtl::Reference< ODatabaseModelImpl >& _model )
+ :m_pImpl( _model )
+ ,m_aMutex( _model->getSharedMutex() )
+{
+}
+
+// -----------------------------------------------------------------------------
+ModelDependentComponent::~ModelDependentComponent()
+{
+}
+
+//........................................................................
+} // namespace dbaccess
+//........................................................................
+
diff --git a/dbaccess/source/core/dataaccess/ModelImpl.hxx b/dbaccess/source/core/dataaccess/ModelImpl.hxx
index 9c845c7c171d..f7628aa45b40 100644
--- a/dbaccess/source/core/dataaccess/ModelImpl.hxx
+++ b/dbaccess/source/core/dataaccess/ModelImpl.hxx
@@ -1,676 +1,637 @@
-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * Copyright 2008 by Sun Microsystems, Inc.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * $RCSfile: ModelImpl.hxx,v $
- * $Revision: 1.24.26.1 $
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org. If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-
-#ifndef _DBA_COREDATAACCESS_MODELIMPL_HXX_
-#define _DBA_COREDATAACCESS_MODELIMPL_HXX_
-
-#include "apitools.hxx"
-#include "bookmarkcontainer.hxx"
-#include "ContentHelper.hxx"
-#include "core_resource.hxx"
-
-/** === begin UNO includes === **/
-#include <com/sun/star/beans/PropertyAttribute.hpp>
-#include <com/sun/star/beans/PropertyValue.hpp>
-#include <com/sun/star/beans/XPropertyAccess.hpp>
-#include <com/sun/star/container/XContainerListener.hpp>
-#include <com/sun/star/document/XDocumentSubStorageSupplier.hpp>
-#include <com/sun/star/document/XEventListener.hpp>
-#include <com/sun/star/document/XStorageBasedDocument.hpp>
-#include <com/sun/star/embed/ElementModes.hpp>
-#include <com/sun/star/embed/XStorage.hpp>
-#include <com/sun/star/embed/XTransactionListener.hpp>
-#include <com/sun/star/frame/XModel.hpp>
-#include <com/sun/star/frame/XStorable.hpp>
-#include <com/sun/star/lang/NotInitializedException.hpp>
-#include <com/sun/star/lang/XMultiServiceFactory.hpp>
-#include <com/sun/star/lang/XServiceInfo.hpp>
-#include <com/sun/star/lang/XSingleServiceFactory.hpp>
-#include <com/sun/star/sdb/XBookmarksSupplier.hpp>
-#include <com/sun/star/sdb/XCompletedConnection.hpp>
-#include <com/sun/star/sdb/XFormDocumentsSupplier.hpp>
-#include <com/sun/star/sdb/XQueryDefinitionsSupplier.hpp>
-#include <com/sun/star/sdb/XReportDocumentsSupplier.hpp>
-#include <com/sun/star/sdbc/XDataSource.hpp>
-#include <com/sun/star/sdbc/XIsolatedConnection.hpp>
-#include <com/sun/star/sdbcx/XTablesSupplier.hpp>
-#include <com/sun/star/util/XCloseable.hpp>
-#include <com/sun/star/util/XFlushable.hpp>
-#include <com/sun/star/util/XModifiable.hpp>
-#include <com/sun/star/util/XNumberFormatsSupplier.hpp>
-#include <com/sun/star/util/XNumberFormatter.hpp>
-#include <com/sun/star/util/XRefreshable.hpp>
-#include <com/sun/star/sdb/XDocumentDataSource.hpp>
-#include <com/sun/star/frame/DoubleInitializationException.hpp>
-/** === end UNO includes === **/
-
-#include <comphelper/broadcasthelper.hxx>
-#include <comphelper/proparrhlp.hxx>
-#include <connectivity/CommonTools.hxx>
-#include <cppuhelper/propshlp.hxx>
-#include <cppuhelper/weakref.hxx>
-#include <sfx2/docmacromode.hxx>
-#include <sfx2/docstoragemodifylistener.hxx>
-#include <tools/string.hxx>
-#include <unotools/sharedunocomponent.hxx>
-#include <vos/mutex.hxx>
-
-#include <memory>
-
-namespace comphelper
-{
- class NamedValueCollection;
-}
-
-//........................................................................
-namespace dbaccess
-{
-//........................................................................
-
-typedef ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XConnection > OWeakConnection;
-typedef std::vector< OWeakConnection > OWeakConnectionArray;
-
-struct AsciiPropertyValue
-{
- // note: the canonic member order would be AsciiName / DefaultValue, but
- // this crashes on unxlngi6.pro, since there's a bug which somehow results in
- // getDefaultDataSourceSettings returning corrupted Any instances then.
- ::com::sun::star::uno::Any DefaultValue;
- const sal_Char* AsciiName;
-
- AsciiPropertyValue( const sal_Char* _pAsciiName, const ::com::sun::star::uno::Any& _rDefaultValue )
- :DefaultValue( _rDefaultValue )
- ,AsciiName( _pAsciiName )
- {
- }
-};
-
-class ODatabaseContext;
-class OSharedConnectionManager;
-
-//============================================================
-//= SharedMutex
-//============================================================
-/** a shared mutex, which deletes itself as soon as the last reference
- to it dies.
-*/
-class SharedMutex
-{
-private:
- oslInterlockedCount m_refCount;
- mutable ::osl::Mutex m_aMutex;
-
-public:
- SharedMutex();
-
- void SAL_CALL acquire();
- void SAL_CALL release();
-
- inline ::osl::Mutex& getMutex() const { return m_aMutex; }
-
-private:
- ~SharedMutex();
-};
-
-//============================================================
-//= SharedMutexHolder
-//============================================================
-/** a base class merely holding a SharedMutex instance. Useful if you
- need to ensure the SharedMutex is to be initialized before other
- of your members, in this case just derive from SharedMutexHolder.
-*/
-class SharedMutexHolder
-{
-protected:
- SharedMutexHolder() : m_xMutex( new SharedMutex ) { }
- ~SharedMutexHolder() { }
-
-protected:
- ::rtl::Reference< SharedMutex > m_xMutex;
-};
-
-//============================================================
-//= VosMutexFacade
-//============================================================
-/** a class which provides an IMutex interface to an OSL-based mutex
-*/
-class VosMutexFacade : public ::vos::IMutex
-{
-public:
- /** beware of life time: the mutex you pass here must live as least as long
- as the VosMutexFacade instance lives.
- */
- VosMutexFacade( ::osl::Mutex& _rMutex );
-
- // IMutex
- virtual void SAL_CALL acquire();
- virtual sal_Bool SAL_CALL tryToAcquire();
- virtual void SAL_CALL release();
-
-private:
- ::osl::Mutex& m_rMutex;
-};
-
-//============================================================
-//= ODatabaseModelImpl
-//============================================================
-DECLARE_STL_USTRINGACCESS_MAP(::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >,TStorages);
-
-typedef ::utl::SharedUNOComponent< ::com::sun::star::embed::XStorage > SharedStorage;
-
-class ODatabaseContext;
-class DocumentStorageAccess;
-class OSharedConnectionManager;
-class ODatabaseModelImpl :public SharedMutexHolder
- ,public ::rtl::IReference
- ,public ::sfx2::IMacroDocumentAccess
- ,public ::sfx2::IModifiableDocument
-{
-public:
- enum ObjectType
- {
- E_FORM = 0,
- E_REPORT = 1,
- E_QUERY = 2,
- E_TABLE = 3
- };
-
-private:
- OModuleClient m_aModuleClient;
- ::com::sun::star::uno::WeakReference< ::com::sun::star::frame::XModel > m_xModel;
- ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XDataSource > m_xDataSource;
-
- DocumentStorageAccess* m_pStorageAccess;
- VosMutexFacade m_aMutexFacade;
- ::std::vector< TContentPtr > m_aContainer; // one for each ObjectType
- TStorages m_aStorages;
- ::sfx2::DocumentMacroMode m_aMacroMode;
- sal_Int16 m_nImposedMacroExecMode;
-
- ::com::sun::star::uno::Reference< ::com::sun::star::script::XStorageBasedLibraryContainer > m_xBasicLibraries;
- ::com::sun::star::uno::Reference< ::com::sun::star::script::XStorageBasedLibraryContainer > m_xDialogLibraries;
-
- SharedStorage m_xDocumentStorage;
- ::rtl::Reference< ::sfx2::DocumentStorageModifyListener > m_pStorageModifyListener;
- ODatabaseContext* m_pDBContext;
-
- ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > m_aArgs;
- /// the URL the document was loaded from
- ::rtl::OUString m_sDocFileLocation;
-
- oslInterlockedCount m_refCount;
-
- /// do we have any object (forms/reports) which contains macros?
- bool m_bHasAnyObjectWithMacros;
- /// does our root storage have macro/script sub storages?
- bool m_bHasMacroStorages;
-
- /// true if setting the Modified flag of the document is currently locked
- bool m_bModificationLock;
-
- /// true if and only if a database document existed previously (though meanwhile disposed), and was already initialized
- bool m_bDocumentInitialized;
-
- /** the URL which the document should report as it's URL
-
- This might differ from ->m_sDocFileLocation in case the document was loaded
- as part of a crash recovery process. In this case, ->m_sDocFileLocation points to
- the temporary file where the DB had been saved to, after a crash.
- ->m_sDocumentURL then is the URL of the document which actually had
- been recovered.
- */
- ::rtl::OUString m_sDocumentURL;
-
-public:
- OWeakConnectionArray m_aConnections;
- const ::comphelper::ComponentContext m_aContext;
-
-public:
- ::com::sun::star::uno::WeakReference< ::com::sun::star::container::XNameAccess > m_xCommandDefinitions;
- ::com::sun::star::uno::WeakReference< ::com::sun::star::container::XNameAccess > m_xTableDefinitions;
-
- ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier >
- m_xNumberFormatsSupplier;
- ::rtl::OUString m_sConnectURL;
- ::rtl::OUString m_sName; // transient, our creator has to tell us the title
- ::rtl::OUString m_sUser;
- ::rtl::OUString m_aPassword; // transient !
- ::rtl::OUString m_sFailedPassword;
- ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>
- m_aLayoutInformation;
- sal_Int32 m_nLoginTimeout;
- sal_Bool m_bReadOnly : 1;
- sal_Bool m_bPasswordRequired : 1;
- sal_Bool m_bSuppressVersionColumns : 1;
- sal_Bool m_bModified : 1;
- sal_Bool m_bDocumentReadOnly : 1;
- sal_Bool m_bDisposingSubStorages;
- ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyAccess >
- m_xSettings;
- ::com::sun::star::uno::Sequence< ::rtl::OUString > m_aTableFilter;
- ::com::sun::star::uno::Sequence< ::rtl::OUString > m_aTableTypeFilter;
- OSharedConnectionManager* m_pSharedConnectionManager;
- ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >
- m_xSharedConnectionManager;
- sal_uInt16 m_nControllerLockCount;
-
- void reset();
-
- /** determines whether the database document has an embedded data storage
- */
- inline bool isEmbeddedDatabase() const { return ( m_sConnectURL.compareToAscii( "sdbc:embedded:", 14 ) == 0 ); }
-
- /** stores the embedded storage ("database")
-
- @param _bPreventRootCommits
- Normally, committing the embedded storage results in also commiting the root storage
- - this is an automatism for data safety reasons.
- If you pass <TRUE/> here, committing the root storage is prevented for this particular
- call.
- @return <TRUE/> if the storage could be commited, otherwise <FALSE/>
- */
- sal_Bool commitEmbeddedStorage( sal_Bool _bPreventRootCommits = sal_False );
-
- /** commits all storages storages which have been obtained via getStorage
- */
- void commitStorages()
- SAL_THROW(( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException ));
-
- ODatabaseModelImpl(
- const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory,
- ODatabaseContext& _pDBContext
- );
- virtual ~ODatabaseModelImpl();
-
- ODatabaseModelImpl(
- const ::rtl::OUString& _rRegistrationName,
- const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory,
- ODatabaseContext& _rDBContext
- );
-
- // XEventListener
- void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);
-
- void setModified( sal_Bool bModified );
-
- void dispose();
-
- inline ::rtl::OUString getURL() const { return m_sDocumentURL; }
- inline ::rtl::OUString getDocFileLocation() const { return m_sDocFileLocation; }
-
- ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage> getStorage(const ::rtl::OUString& _sStorageName,sal_Int32 nMode = ::com::sun::star::embed::ElementModes::READWRITE);
-// helper
- const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier >&
- getNumberFormatsSupplier();
-
- const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >&
- getResource() const { return m_aArgs; }
-
- void attachResource(
- const ::rtl::OUString& _rURL,
- const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rArgs );
-
- static ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >
- stripLoadArguments( const ::comphelper::NamedValueCollection& _rArguments );
-
-// other stuff
- void flushTables();
-
- // disposes all elements in m_aStorages, and clears it
- void disposeStorages() SAL_THROW(());
-
- /// creates a ->com::sun::star::embed::StorageFactory
- ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory >
- createStorageFactory() const;
-
- /// commits our storage
- void commitRootStorage();
-
- /// commits a given storage if it's not readonly
- static bool commitStorageIfWriteable(
- const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxStorage
- )
- SAL_THROW((
- ::com::sun::star::io::IOException,
- ::com::sun::star::lang::WrappedTargetException,
- ::com::sun::star::uno::RuntimeException
- ));
-
- /// commits a given storage if it's not readonly, ignoring (but asserting) all errors
- static bool commitStorageIfWriteable_ignoreErrors(
- const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxStorage
- )
- SAL_THROW(());
-
- void clearConnections();
-
- ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > getOrCreateRootStorage();
- inline ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > getRootStorage() const { return m_xDocumentStorage.getTyped(); }
- inline void resetRootStroage() { impl_switchToStorage_throw( NULL ); }
-
- /** returns the data source. If it doesn't exist it will be created
- */
- ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDataSource> getOrCreateDataSource();
-
- /** returns the model, if there already exists one
- */
- ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > getModel_noCreate() const;
-
- /** returns a new ->ODatabaseDocument
-
- @param _bInitializeIfNecessary
- calls XLoadable::initNew on the newly created model, if necessary
-
- @precond
- No ->ODatabaseDocument exists so far
-
- @seealso
- getModel_noCreate
- */
- ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > createNewModel_deliverOwnership( bool _bInitialize );
-
- struct ResetModelAccess { friend class ODatabaseDocument; private: ResetModelAccess() { } };
-
- /** resets the model to NULL
-
- Only to be called when the model is being disposed
- */
- void modelIsDisposing( const bool _wasInitialized, ResetModelAccess );
-
- bool hadInitializedDocument() const { return m_bDocumentInitialized; }
-
- DocumentStorageAccess*
- getDocumentStorageAccess();
-
- ::com::sun::star::uno::Reference< ::com::sun::star::document::XDocumentSubStorageSupplier >
- getDocumentSubStorageSupplier();
-
- inline ::rtl::Reference< SharedMutex > getSharedMutex() const { return m_xMutex; }
-
- /** @see osl_incrementInterlockedCount.
- */
- virtual oslInterlockedCount SAL_CALL acquire();
-
- /** @see osl_decrementInterlockedCount.
- */
- virtual oslInterlockedCount SAL_CALL release();
-
- /// returns a all known data source settings, including their default values
- static const AsciiPropertyValue* getDefaultDataSourceSettings();
-
- /** retrieves the requested container of objects (forms/reports/tables/queries)
- */
- TContentPtr& getObjectContainer( const ObjectType _eType );
-
- /** determines whether the given storage is the storage of our embedded database (named "database"), if any
- */
- bool isDatabaseStorage( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxStorage ) const;
-
- /** returns the name of the storage which is used to stored objects of the given type, if applicable
- */
- static ::rtl::OUString
- getObjectContainerStorageName( const ObjectType _eType );
-
- /** revokes the data source registration at the database context
- */
- void revokeDataSource() const;
-
- /** determines whether a given object storage contains macros
- */
- static bool objectHasMacros(
- const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxContainerStorage,
- const ::rtl::OUString& _rPersistentName
- );
-
- /** determines whether the database document has any object (form/report) which contains macros
-
- In such a case, *all* objects in the document keep the macro capability, and the database document
- itself does *not* allow embedding macros.
- */
- bool hasAnyObjectWithMacros() const { return m_bHasAnyObjectWithMacros; }
-
- /** determines whether the document storage has sub storages used to store macros/scripts
-
- Though the current version does not allow creating such documents, later versions will, so
- we need to be prepared when we encounter them.
- */
- bool hasMacroStorages() const { return m_bHasMacroStorages; }
-
- /** checks our document's macro execution mode, using the interaction handler as supplied with our
- load arguments
- */
- bool checkMacrosOnLoading();
-
- /** adjusts our document's macro execution mode, without using any UI, assuming the user
- would reject execution of macros, if she would have been asked.
-
- If checkMacrosOnLoading has been called before (and thus the macro execution mode
- is already adjusted), then the current execution mode is simply returned.
-
- @return
- whether or not macro execution is allowed
- */
- bool adjustMacroMode_AutoReject();
-
- /** resets our macro execute mode, so next time the checkMacrosOnLoading is called, it will
- behave as if it has never been called before
- */
- void resetMacroExecutionMode();
-
- /** ensures that ->m_xBasicLibraries resp. m_xDialogLibraries exists
-
- @return
- the requested library container. Is never <NULL/>.
-
- @throws RuntimeException
- if something does wrong, which indicates a server error in the installation
- */
- ::com::sun::star::uno::Reference< ::com::sun::star::script::XStorageBasedLibraryContainer >
- getLibraryContainer( bool _bScript );
-
- /** lets our library containers store themself into the given root storage
- */
- void storeLibraryContainersTo( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxToRootStorage );
-
- /** rebases the document to the given storage
-
- No actual committing, copying, saving, whatsoever happens. The storage is just remembered as the documents
- new storage, nothing more.
-
- @throws ::com::sun::star::lang::IllegalArgumentException
- if the given storage is <NULL/>
- @throws ::com::sun::star::lang::RuntimeException
- if any of the invoked operations does so
- */
- ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >
- switchToStorage(
- const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxNewRootStorage
- );
-
- /** switches to the given document location/URL
-
- The document location is the URL of the file from which the document has been loaded.
- The document URL is the "intended location" of the document. It differs from the location
- if and only if the document was loaded as part of a document recovery process. In this case,
- the location points to some temporary file, but the URL is the URL of the file which has been
- just recovered. The next store operation would operate on the URL, not the location.
- */
- void switchToURL(
- const ::rtl::OUString& _rDocumentLocation,
- const ::rtl::OUString& _rDocumentURL
- );
-
- /** returns the macro mode imposed by an external instance, which passed it to attachResource
- */
- sal_Int16 getImposedMacroExecMode() const
- {
- return m_nImposedMacroExecMode;
- }
- void setImposedMacroExecMode( const sal_Int16 _nMacroMode )
- {
- m_nImposedMacroExecMode = _nMacroMode;
- }
-
-public:
- // IMacroDocumentAccess overridables
- virtual sal_Int16 getCurrentMacroExecMode() const;
- virtual sal_Bool setCurrentMacroExecMode( sal_uInt16 );
- virtual ::rtl::OUString getDocumentLocation() const;
- virtual ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > getLastCommitDocumentStorage();
- virtual sal_Bool documentStorageHasMacros() const;
- virtual ::com::sun::star::uno::Reference< ::com::sun::star::document::XEmbeddedScripts > getEmbeddedDocumentScripts() const;
- virtual sal_Int16 getScriptingSignatureState() const;
- virtual void showBrokenSignatureWarning( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& _rxInteraction ) const;
-
- // IModifiableDocument
- virtual void storageIsModified();
-
- // don't use directly, use the ModifyLock class instead
- void lockModify() { m_bModificationLock = true; }
- void unlockModify() { m_bModificationLock = false; }
- bool isModifyLocked() const { return m_bModificationLock; }
-
-private:
- void impl_construct_nothrow();
- ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >
- impl_switchToStorage_throw( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxNewRootStorage );
-};
-
-/** a small base class for UNO components whose functionality depends on a ODatabaseModelImpl
-*/
-class ModelDependentComponent
-{
-protected:
- ::rtl::Reference< ODatabaseModelImpl > m_pImpl;
- ::rtl::Reference< SharedMutex > m_xMutex;
-
-protected:
- ModelDependentComponent( const ::rtl::Reference< ODatabaseModelImpl >& _model );
- virtual ~ModelDependentComponent();
-
- /** returns the component itself
- */
- virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > getThis() const = 0;
-
- inline ::osl::Mutex& getMutex() const
- {
- return m_xMutex->getMutex();
- }
-
-public:
- struct GuardAccess { friend class ModelMethodGuard; private: GuardAccess() { } };
-
- /** returns the mutex used for thread safety
-
- @throws ::com::sun::star::lang::DisposedException
- if m_pImpl is <NULL/>. Usually, you will set this member in your derived
- component's <code>dispose</code> method to <NULL/>.
- */
- inline ::osl::Mutex& getMutex( GuardAccess ) const
- {
- return getMutex();
- }
- inline ::rtl::Reference< ODatabaseModelImpl > getImpl( GuardAccess )
- {
- return m_pImpl;
- }
-
- /// checks whether the component is already disposed, throws a DisposedException if so
- inline void checkDisposed() const
- {
- if ( !m_pImpl.is() )
- throw ::com::sun::star::lang::DisposedException( ::rtl::OUString::createFromAscii( "Component is already disposed." ), getThis() );
- }
-
- inline void lockModify()
- {
- m_pImpl->lockModify();
- }
-
- inline void unlockModify()
- {
- m_pImpl->unlockModify();
- }
-};
-
-class ModifyLock
-{
-public:
- ModifyLock( ModelDependentComponent& _component )
- :m_rComponent( _component )
- {
- m_rComponent.lockModify();
- }
-
- ~ModifyLock()
- {
- m_rComponent.unlockModify();
- }
-
-private:
- ModelDependentComponent& m_rComponent;
-};
-
-/** a guard for public methods of objects dependent on a ODatabaseModelImpl instance
-
- Just put this guard onto the stack at the beginning of your method. Don't bother yourself
- with a MutexGuard, checks for being disposed, and the like.
-*/
-class ModelMethodGuard : public ::osl::ResettableMutexGuard
-{
-private:
- typedef ::osl::ResettableMutexGuard BaseMutexGuard;
-
-public:
- /** constructs the guard
-
- @param _component
- the component whose functionality depends on a ODatabaseModelImpl instance
-
- @throws ::com::sun::star::lang::DisposedException
- If the given component is already disposed
- */
- ModelMethodGuard( const ModelDependentComponent& _component )
- :BaseMutexGuard( _component.getMutex( ModelDependentComponent::GuardAccess() ) )
- {
- _component.checkDisposed();
- }
-
- ~ModelMethodGuard()
- {
- }
-};
-
-//........................................................................
-} // namespace dbaccess
-//........................................................................
-
-#endif // _DBA_COREDATAACCESS_DATALINK_HXX_
-
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: ModelImpl.hxx,v $
+ * $Revision: 1.24.26.1 $
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _DBA_COREDATAACCESS_MODELIMPL_HXX_
+#define _DBA_COREDATAACCESS_MODELIMPL_HXX_
+
+#include "apitools.hxx"
+#include "bookmarkcontainer.hxx"
+#include "ContentHelper.hxx"
+#include "core_resource.hxx"
+
+/** === begin UNO includes === **/
+#include <com/sun/star/beans/PropertyAttribute.hpp>
+#include <com/sun/star/beans/PropertyValue.hpp>
+#include <com/sun/star/beans/XPropertyAccess.hpp>
+#include <com/sun/star/container/XContainerListener.hpp>
+#include <com/sun/star/document/XDocumentSubStorageSupplier.hpp>
+#include <com/sun/star/document/XEventListener.hpp>
+#include <com/sun/star/document/XStorageBasedDocument.hpp>
+#include <com/sun/star/embed/ElementModes.hpp>
+#include <com/sun/star/embed/XStorage.hpp>
+#include <com/sun/star/embed/XTransactionListener.hpp>
+#include <com/sun/star/frame/XModel.hpp>
+#include <com/sun/star/frame/XStorable.hpp>
+#include <com/sun/star/lang/NotInitializedException.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/lang/XSingleServiceFactory.hpp>
+#include <com/sun/star/sdb/XBookmarksSupplier.hpp>
+#include <com/sun/star/sdb/XCompletedConnection.hpp>
+#include <com/sun/star/sdb/XFormDocumentsSupplier.hpp>
+#include <com/sun/star/sdb/XQueryDefinitionsSupplier.hpp>
+#include <com/sun/star/sdb/XReportDocumentsSupplier.hpp>
+#include <com/sun/star/sdbc/XDataSource.hpp>
+#include <com/sun/star/sdbc/XIsolatedConnection.hpp>
+#include <com/sun/star/sdbcx/XTablesSupplier.hpp>
+#include <com/sun/star/util/XCloseable.hpp>
+#include <com/sun/star/util/XFlushable.hpp>
+#include <com/sun/star/util/XModifiable.hpp>
+#include <com/sun/star/util/XNumberFormatsSupplier.hpp>
+#include <com/sun/star/util/XNumberFormatter.hpp>
+#include <com/sun/star/util/XRefreshable.hpp>
+#include <com/sun/star/sdb/XDocumentDataSource.hpp>
+#include <com/sun/star/frame/DoubleInitializationException.hpp>
+/** === end UNO includes === **/
+
+#include <comphelper/broadcasthelper.hxx>
+#include <comphelper/proparrhlp.hxx>
+#include <comphelper/sharedmutex.hxx>
+#include <connectivity/CommonTools.hxx>
+#include <cppuhelper/propshlp.hxx>
+#include <cppuhelper/weakref.hxx>
+#include <sfx2/docmacromode.hxx>
+#include <sfx2/docstoragemodifylistener.hxx>
+#include <tools/string.hxx>
+#include <unotools/sharedunocomponent.hxx>
+#include <vos/mutex.hxx>
+
+#include <memory>
+
+namespace comphelper
+{
+ class NamedValueCollection;
+}
+
+//........................................................................
+namespace dbaccess
+{
+//........................................................................
+
+typedef ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XConnection > OWeakConnection;
+typedef std::vector< OWeakConnection > OWeakConnectionArray;
+
+struct AsciiPropertyValue
+{
+ // note: the canonic member order would be AsciiName / DefaultValue, but
+ // this crashes on unxlngi6.pro, since there's a bug which somehow results in
+ // getDefaultDataSourceSettings returning corrupted Any instances then.
+ ::com::sun::star::uno::Any DefaultValue;
+ const sal_Char* AsciiName;
+
+ AsciiPropertyValue( const sal_Char* _pAsciiName, const ::com::sun::star::uno::Any& _rDefaultValue )
+ :DefaultValue( _rDefaultValue )
+ ,AsciiName( _pAsciiName )
+ {
+ }
+};
+
+class ODatabaseContext;
+class OSharedConnectionManager;
+
+//============================================================
+//= VosMutexFacade
+//============================================================
+/** a class which provides an IMutex interface to an OSL-based mutex
+*/
+class VosMutexFacade : public ::vos::IMutex
+{
+public:
+ /** beware of life time: the mutex you pass here must live as least as long
+ as the VosMutexFacade instance lives.
+ */
+ VosMutexFacade( ::osl::Mutex& _rMutex );
+
+ // IMutex
+ virtual void SAL_CALL acquire();
+ virtual sal_Bool SAL_CALL tryToAcquire();
+ virtual void SAL_CALL release();
+
+private:
+ ::osl::Mutex& m_rMutex;
+};
+
+
+//============================================================
+//= ODatabaseModelImpl
+//============================================================
+DECLARE_STL_USTRINGACCESS_MAP(::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >,TStorages);
+
+typedef ::utl::SharedUNOComponent< ::com::sun::star::embed::XStorage > SharedStorage;
+
+class ODatabaseContext;
+class DocumentStorageAccess;
+class OSharedConnectionManager;
+class ODatabaseModelImpl :public ::rtl::IReference
+ ,public ::sfx2::IMacroDocumentAccess
+ ,public ::sfx2::IModifiableDocument
+{
+public:
+ enum ObjectType
+ {
+ E_FORM = 0,
+ E_REPORT = 1,
+ E_QUERY = 2,
+ E_TABLE = 3
+ };
+
+private:
+ OModuleClient m_aModuleClient;
+ ::com::sun::star::uno::WeakReference< ::com::sun::star::frame::XModel > m_xModel;
+ ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XDataSource > m_xDataSource;
+
+ DocumentStorageAccess* m_pStorageAccess;
+ ::comphelper::SharedMutex m_aMutex;
+ VosMutexFacade m_aMutexFacade;
+ ::std::vector< TContentPtr > m_aContainer; // one for each ObjectType
+ TStorages m_aStorages;
+ ::sfx2::DocumentMacroMode m_aMacroMode;
+ sal_Int16 m_nImposedMacroExecMode;
+
+ ::com::sun::star::uno::Reference< ::com::sun::star::script::XStorageBasedLibraryContainer > m_xBasicLibraries;
+ ::com::sun::star::uno::Reference< ::com::sun::star::script::XStorageBasedLibraryContainer > m_xDialogLibraries;
+
+ SharedStorage m_xDocumentStorage;
+ ::rtl::Reference< ::sfx2::DocumentStorageModifyListener > m_pStorageModifyListener;
+ ODatabaseContext* m_pDBContext;
+
+ ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > m_aArgs;
+ /// the URL the document was loaded from
+ ::rtl::OUString m_sDocFileLocation;
+
+ oslInterlockedCount m_refCount;
+
+ /// do we have any object (forms/reports) which contains macros?
+ bool m_bHasAnyObjectWithMacros;
+ /// does our root storage have macro/script sub storages?
+ bool m_bHasMacroStorages;
+
+ /// true if setting the Modified flag of the document is currently locked
+ bool m_bModificationLock;
+
+ /// true if and only if a database document existed previously (though meanwhile disposed), and was already initialized
+ bool m_bDocumentInitialized;
+
+ /** the URL which the document should report as it's URL
+
+ This might differ from ->m_sDocFileLocation in case the document was loaded
+ as part of a crash recovery process. In this case, ->m_sDocFileLocation points to
+ the temporary file where the DB had been saved to, after a crash.
+ ->m_sDocumentURL then is the URL of the document which actually had
+ been recovered.
+ */
+ ::rtl::OUString m_sDocumentURL;
+
+public:
+ OWeakConnectionArray m_aConnections;
+ const ::comphelper::ComponentContext m_aContext;
+
+public:
+ ::com::sun::star::uno::WeakReference< ::com::sun::star::container::XNameAccess > m_xCommandDefinitions;
+ ::com::sun::star::uno::WeakReference< ::com::sun::star::container::XNameAccess > m_xTableDefinitions;
+
+ ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier >
+ m_xNumberFormatsSupplier;
+ ::rtl::OUString m_sConnectURL;
+ ::rtl::OUString m_sName; // transient, our creator has to tell us the title
+ ::rtl::OUString m_sUser;
+ ::rtl::OUString m_aPassword; // transient !
+ ::rtl::OUString m_sFailedPassword;
+ ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>
+ m_aLayoutInformation;
+ sal_Int32 m_nLoginTimeout;
+ sal_Bool m_bReadOnly : 1;
+ sal_Bool m_bPasswordRequired : 1;
+ sal_Bool m_bSuppressVersionColumns : 1;
+ sal_Bool m_bModified : 1;
+ sal_Bool m_bDocumentReadOnly : 1;
+ sal_Bool m_bDisposingSubStorages;
+ ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyAccess >
+ m_xSettings;
+ ::com::sun::star::uno::Sequence< ::rtl::OUString > m_aTableFilter;
+ ::com::sun::star::uno::Sequence< ::rtl::OUString > m_aTableTypeFilter;
+ OSharedConnectionManager* m_pSharedConnectionManager;
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >
+ m_xSharedConnectionManager;
+ sal_uInt16 m_nControllerLockCount;
+
+ void reset();
+
+ /** determines whether the database document has an embedded data storage
+ */
+ inline bool isEmbeddedDatabase() const { return ( m_sConnectURL.compareToAscii( "sdbc:embedded:", 14 ) == 0 ); }
+
+ /** stores the embedded storage ("database")
+
+ @param _bPreventRootCommits
+ Normally, committing the embedded storage results in also commiting the root storage
+ - this is an automatism for data safety reasons.
+ If you pass <TRUE/> here, committing the root storage is prevented for this particular
+ call.
+ @return <TRUE/> if the storage could be commited, otherwise <FALSE/>
+ */
+ sal_Bool commitEmbeddedStorage( sal_Bool _bPreventRootCommits = sal_False );
+
+ /** commits all storages storages which have been obtained via getStorage
+ */
+ void commitStorages()
+ SAL_THROW(( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException ));
+
+ ODatabaseModelImpl(
+ const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory,
+ ODatabaseContext& _pDBContext
+ );
+ virtual ~ODatabaseModelImpl();
+
+ ODatabaseModelImpl(
+ const ::rtl::OUString& _rRegistrationName,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory,
+ ODatabaseContext& _rDBContext
+ );
+
+ // XEventListener
+ void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);
+
+ void setModified( sal_Bool bModified );
+
+ void dispose();
+
+ inline ::rtl::OUString getURL() const { return m_sDocumentURL; }
+ inline ::rtl::OUString getDocFileLocation() const { return m_sDocFileLocation; }
+
+ ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage> getStorage(const ::rtl::OUString& _sStorageName,sal_Int32 nMode = ::com::sun::star::embed::ElementModes::READWRITE);
+// helper
+ const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier >&
+ getNumberFormatsSupplier();
+
+ const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >&
+ getResource() const { return m_aArgs; }
+
+ void attachResource(
+ const ::rtl::OUString& _rURL,
+ const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rArgs );
+
+ static ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >
+ stripLoadArguments( const ::comphelper::NamedValueCollection& _rArguments );
+
+// other stuff
+ void flushTables();
+
+ // disposes all elements in m_aStorages, and clears it
+ void disposeStorages() SAL_THROW(());
+
+ /// creates a ->com::sun::star::embed::StorageFactory
+ ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory >
+ createStorageFactory() const;
+
+ /// commits our storage
+ void commitRootStorage();
+
+ /// commits a given storage if it's not readonly
+ static bool commitStorageIfWriteable(
+ const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxStorage
+ )
+ SAL_THROW((
+ ::com::sun::star::io::IOException,
+ ::com::sun::star::lang::WrappedTargetException,
+ ::com::sun::star::uno::RuntimeException
+ ));
+
+ /// commits a given storage if it's not readonly, ignoring (but asserting) all errors
+ static bool commitStorageIfWriteable_ignoreErrors(
+ const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxStorage
+ )
+ SAL_THROW(());
+
+ void clearConnections();
+
+ ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > getOrCreateRootStorage();
+ inline ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > getRootStorage() const { return m_xDocumentStorage.getTyped(); }
+ inline void resetRootStroage() { impl_switchToStorage_throw( NULL ); }
+
+ /** returns the data source. If it doesn't exist it will be created
+ */
+ ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDataSource> getOrCreateDataSource();
+
+ /** returns the model, if there already exists one
+ */
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > getModel_noCreate() const;
+
+ /** returns a new ->ODatabaseDocument
+
+ @param _bInitializeIfNecessary
+ calls XLoadable::initNew on the newly created model, if necessary
+
+ @precond
+ No ->ODatabaseDocument exists so far
+
+ @seealso
+ getModel_noCreate
+ */
+ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > createNewModel_deliverOwnership( bool _bInitialize );
+
+ struct ResetModelAccess { friend class ODatabaseDocument; private: ResetModelAccess() { } };
+
+ /** resets the model to NULL
+
+ Only to be called when the model is being disposed
+ */
+ void modelIsDisposing( const bool _wasInitialized, ResetModelAccess );
+
+ bool hadInitializedDocument() const { return m_bDocumentInitialized; }
+
+ DocumentStorageAccess*
+ getDocumentStorageAccess();
+
+ ::com::sun::star::uno::Reference< ::com::sun::star::document::XDocumentSubStorageSupplier >
+ getDocumentSubStorageSupplier();
+
+ inline const ::comphelper::SharedMutex& getSharedMutex() const { return m_aMutex; }
+
+ /** @see osl_incrementInterlockedCount.
+ */
+ virtual oslInterlockedCount SAL_CALL acquire();
+
+ /** @see osl_decrementInterlockedCount.
+ */
+ virtual oslInterlockedCount SAL_CALL release();
+
+ /// returns a all known data source settings, including their default values
+ static const AsciiPropertyValue* getDefaultDataSourceSettings();
+
+ /** retrieves the requested container of objects (forms/reports/tables/queries)
+ */
+ TContentPtr& getObjectContainer( const ObjectType _eType );
+
+ /** determines whether the given storage is the storage of our embedded database (named "database"), if any
+ */
+ bool isDatabaseStorage( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxStorage ) const;
+
+ /** returns the name of the storage which is used to stored objects of the given type, if applicable
+ */
+ static ::rtl::OUString
+ getObjectContainerStorageName( const ObjectType _eType );
+
+ /** revokes the data source registration at the database context
+ */
+ void revokeDataSource() const;
+
+ /** determines whether a given object storage contains macros
+ */
+ static bool objectHasMacros(
+ const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxContainerStorage,
+ const ::rtl::OUString& _rPersistentName
+ );
+
+ /** determines whether the database document has any object (form/report) which contains macros
+
+ In such a case, *all* objects in the document keep the macro capability, and the database document
+ itself does *not* allow embedding macros.
+ */
+ bool hasAnyObjectWithMacros() const { return m_bHasAnyObjectWithMacros; }
+
+ /** determines whether the document storage has sub storages used to store macros/scripts
+
+ Though the current version does not allow creating such documents, later versions will, so
+ we need to be prepared when we encounter them.
+ */
+ bool hasMacroStorages() const { return m_bHasMacroStorages; }
+
+ /** checks our document's macro execution mode, using the interaction handler as supplied with our
+ load arguments
+ */
+ bool checkMacrosOnLoading();
+
+ /** adjusts our document's macro execution mode, without using any UI, assuming the user
+ would reject execution of macros, if she would have been asked.
+
+ If checkMacrosOnLoading has been called before (and thus the macro execution mode
+ is already adjusted), then the current execution mode is simply returned.
+
+ @return
+ whether or not macro execution is allowed
+ */
+ bool adjustMacroMode_AutoReject();
+
+ /** resets our macro execute mode, so next time the checkMacrosOnLoading is called, it will
+ behave as if it has never been called before
+ */
+ void resetMacroExecutionMode();
+
+ /** ensures that ->m_xBasicLibraries resp. m_xDialogLibraries exists
+
+ @return
+ the requested library container. Is never <NULL/>.
+
+ @throws RuntimeException
+ if something does wrong, which indicates a server error in the installation
+ */
+ ::com::sun::star::uno::Reference< ::com::sun::star::script::XStorageBasedLibraryContainer >
+ getLibraryContainer( bool _bScript );
+
+ /** lets our library containers store themself into the given root storage
+ */
+ void storeLibraryContainersTo( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxToRootStorage );
+
+ /** rebases the document to the given storage
+
+ No actual committing, copying, saving, whatsoever happens. The storage is just remembered as the documents
+ new storage, nothing more.
+
+ @throws ::com::sun::star::lang::IllegalArgumentException
+ if the given storage is <NULL/>
+ @throws ::com::sun::star::lang::RuntimeException
+ if any of the invoked operations does so
+ */
+ ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >
+ switchToStorage(
+ const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxNewRootStorage
+ );
+
+ /** switches to the given document location/URL
+
+ The document location is the URL of the file from which the document has been loaded.
+ The document URL is the "intended location" of the document. It differs from the location
+ if and only if the document was loaded as part of a document recovery process. In this case,
+ the location points to some temporary file, but the URL is the URL of the file which has been
+ just recovered. The next store operation would operate on the URL, not the location.
+ */
+ void switchToURL(
+ const ::rtl::OUString& _rDocumentLocation,
+ const ::rtl::OUString& _rDocumentURL
+ );
+
+ /** returns the macro mode imposed by an external instance, which passed it to attachResource
+ */
+ sal_Int16 getImposedMacroExecMode() const
+ {
+ return m_nImposedMacroExecMode;
+ }
+ void setImposedMacroExecMode( const sal_Int16 _nMacroMode )
+ {
+ m_nImposedMacroExecMode = _nMacroMode;
+ }
+
+public:
+ // IMacroDocumentAccess overridables
+ virtual sal_Int16 getCurrentMacroExecMode() const;
+ virtual sal_Bool setCurrentMacroExecMode( sal_uInt16 );
+ virtual ::rtl::OUString getDocumentLocation() const;
+ virtual ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > getLastCommitDocumentStorage();
+ virtual sal_Bool documentStorageHasMacros() const;
+ virtual ::com::sun::star::uno::Reference< ::com::sun::star::document::XEmbeddedScripts > getEmbeddedDocumentScripts() const;
+ virtual sal_Int16 getScriptingSignatureState() const;
+ virtual void showBrokenSignatureWarning( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& _rxInteraction ) const;
+
+ // IModifiableDocument
+ virtual void storageIsModified();
+
+ // don't use directly, use the ModifyLock class instead
+ void lockModify() { m_bModificationLock = true; }
+ void unlockModify() { m_bModificationLock = false; }
+ bool isModifyLocked() const { return m_bModificationLock; }
+
+private:
+ void impl_construct_nothrow();
+ ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >
+ impl_switchToStorage_throw( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _rxNewRootStorage );
+};
+
+/** a small base class for UNO components whose functionality depends on a ODatabaseModelImpl
+*/
+class ModelDependentComponent
+{
+protected:
+ ::rtl::Reference< ODatabaseModelImpl > m_pImpl;
+ mutable ::comphelper::SharedMutex m_aMutex;
+
+protected:
+ ModelDependentComponent( const ::rtl::Reference< ODatabaseModelImpl >& _model );
+ virtual ~ModelDependentComponent();
+
+ /** returns the component itself
+ */
+ virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > getThis() const = 0;
+
+ inline ::osl::Mutex& getMutex() const
+ {
+ return m_aMutex;
+ }
+
+public:
+ struct GuardAccess { friend class ModelMethodGuard; private: GuardAccess() { } };
+
+ /** returns the mutex used for thread safety
+
+ @throws ::com::sun::star::lang::DisposedException
+ if m_pImpl is <NULL/>. Usually, you will set this member in your derived
+ component's <code>dispose</code> method to <NULL/>.
+ */
+ inline ::osl::Mutex& getMutex( GuardAccess ) const
+ {
+ return getMutex();
+ }
+ inline ::rtl::Reference< ODatabaseModelImpl > getImpl( GuardAccess )
+ {
+ return m_pImpl;
+ }
+
+ /// checks whether the component is already disposed, throws a DisposedException if so
+ inline void checkDisposed() const
+ {
+ if ( !m_pImpl.is() )
+ throw ::com::sun::star::lang::DisposedException( ::rtl::OUString::createFromAscii( "Component is already disposed." ), getThis() );
+ }
+
+ inline void lockModify()
+ {
+ m_pImpl->lockModify();
+ }
+
+ inline void unlockModify()
+ {
+ m_pImpl->unlockModify();
+ }
+};
+
+class ModifyLock
+{
+public:
+ ModifyLock( ModelDependentComponent& _component )
+ :m_rComponent( _component )
+ {
+ m_rComponent.lockModify();
+ }
+
+ ~ModifyLock()
+ {
+ m_rComponent.unlockModify();
+ }
+
+private:
+ ModelDependentComponent& m_rComponent;
+};
+
+/** a guard for public methods of objects dependent on a ODatabaseModelImpl instance
+
+ Just put this guard onto the stack at the beginning of your method. Don't bother yourself
+ with a MutexGuard, checks for being disposed, and the like.
+*/
+class ModelMethodGuard : public ::osl::ResettableMutexGuard
+{
+private:
+ typedef ::osl::ResettableMutexGuard BaseMutexGuard;
+
+public:
+ /** constructs the guard
+
+ @param _component
+ the component whose functionality depends on a ODatabaseModelImpl instance
+
+ @throws ::com::sun::star::lang::DisposedException
+ If the given component is already disposed
+ */
+ ModelMethodGuard( const ModelDependentComponent& _component )
+ :BaseMutexGuard( _component.getMutex( ModelDependentComponent::GuardAccess() ) )
+ {
+ _component.checkDisposed();
+ }
+
+ ~ModelMethodGuard()
+ {
+ }
+};
+
+//........................................................................
+} // namespace dbaccess
+//........................................................................
+
+#endif // _DBA_COREDATAACCESS_DATALINK_HXX_
+
diff --git a/dbaccess/source/core/dataaccess/databasecontext.cxx b/dbaccess/source/core/dataaccess/databasecontext.cxx
index 0c333cf0b7be..0d5bcb3e7081 100644
--- a/dbaccess/source/core/dataaccess/databasecontext.cxx
+++ b/dbaccess/source/core/dataaccess/databasecontext.cxx
@@ -339,7 +339,7 @@ Reference< XInterface > ODatabaseContext::loadObjectFromURL(const ::rtl::OUStrin
Reference< XLoadable > xLoad( xModel, UNO_QUERY_THROW );
::comphelper::NamedValueCollection aArgs;
- aArgs.put( "FileName", _sURL );
+ aArgs.put( "URL", _sURL );
aArgs.put( "MacroExecutionMode", MacroExecMode::USE_CONFIG );
aArgs.put( "InteractionHandler", m_aContext.createComponent( "com.sun.star.sdb.InteractionHandler" ) );
diff --git a/dbaccess/source/core/dataaccess/databasedocument.cxx b/dbaccess/source/core/dataaccess/databasedocument.cxx
index e12e3e4cb764..37d80067a573 100644
--- a/dbaccess/source/core/dataaccess/databasedocument.cxx
+++ b/dbaccess/source/core/dataaccess/databasedocument.cxx
@@ -40,11 +40,16 @@
#include "databasecontext.hxx"
#include "documentcontainer.hxx"
+#include <comphelper/documentconstants.hxx>
+#include <comphelper/namedvaluecollection.hxx>
+#include <comphelper/enumhelper.hxx>
+#include <comphelper/numberedcollection.hxx>
#include <comphelper/genericpropertyset.hxx>
#include <comphelper/property.hxx>
-
#include <svtools/saveopt.hxx>
+#include <framework/titlehelper.hxx>
+
/** === begin UNO includes === **/
#include <com/sun/star/document/XExporter.hpp>
#include <com/sun/star/document/XFilter.hpp>
@@ -378,12 +383,12 @@ void ODatabaseDocument::impl_import_throw( const ::comphelper::NamedValueCollect
/** property map for import info set */
comphelper::PropertyMapEntry aExportInfoMap[] =
- {
+ {
{ MAP_LEN( "BaseURI"), 0,&::getCppuType( (::rtl::OUString *)0 ),beans::PropertyAttribute::MAYBEVOID, 0 },
{ MAP_LEN( "StreamName"), 0,&::getCppuType( (::rtl::OUString *)0 ),beans::PropertyAttribute::MAYBEVOID, 0 },
- { NULL, 0, 0, NULL, 0, 0 }
- };
- uno::Reference< beans::XPropertySet > xInfoSet( comphelper::GenericPropertySet_CreateInstance( new comphelper::PropertySetInfo( aExportInfoMap ) ) );
+ { NULL, 0, 0, NULL, 0, 0 }
+ };
+ uno::Reference< beans::XPropertySet > xInfoSet( comphelper::GenericPropertySet_CreateInstance( new comphelper::PropertySetInfo( aExportInfoMap ) ) );
xInfoSet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BaseURI")), uno::makeAny(_rResource.getOrDefault("URL",::rtl::OUString())));
xInfoSet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StreamName")), uno::makeAny(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("content.xml"))));
@@ -392,8 +397,8 @@ void ODatabaseDocument::impl_import_throw( const ::comphelper::NamedValueCollect
aFilterArgs[nCount] <<= xInfoSet;
Reference< XImporter > xImporter(
- m_pImpl->m_aContext.createComponentWithArguments( "com.sun.star.comp.sdb.DBFilter", aFilterArgs ),
- UNO_QUERY_THROW );
+ m_pImpl->m_aContext.createComponentWithArguments( "com.sun.star.comp.sdb.DBFilter", aFilterArgs ),
+ UNO_QUERY_THROW );
Reference< XComponent > xComponent( *this, UNO_QUERY_THROW );
xImporter->setTargetDocument( xComponent );
@@ -446,6 +451,14 @@ void SAL_CALL ODatabaseDocument::load( const Sequence< PropertyValue >& _Argumen
impl_reset_nothrow();
::comphelper::NamedValueCollection aResource( _Arguments );
+ if ( aResource.has( "FileName" ) && !aResource.has( "URL" ) )
+ // FileName is the compatibility name for URL, so we might have clients passing
+ // a FileName only. However, some of our code works with the URL only, so ensure
+ // we have one.
+ aResource.put( "URL", aResource.get( "FileName" ) );
+ if ( aResource.has( "URL" ) && !aResource.has( "FileName" ) )
+ // similar ... just in case there is legacy code which expects a FileName only
+ aResource.put( "FileName", aResource.get( "URL" ) );
// now that somebody (perhaps) told us an macro execution mode, remember it as
// ImposedMacroExecMode
@@ -1146,13 +1159,13 @@ void SAL_CALL ODatabaseDocument::close( sal_Bool _bDeliverOwnership ) throw (Clo
}
catch ( const Exception& )
{
- ::osl::MutexGuard aGuard( m_xMutex->getMutex() );
+ ::osl::MutexGuard aGuard( m_aMutex );
m_bClosing = false;
throw;
}
// SYNCHRONIZED ->
- ::osl::MutexGuard aGuard( m_xMutex->getMutex() );
+ ::osl::MutexGuard aGuard( m_aMutex );
m_bClosing = false;
// <- SYNCHRONIZED
}
@@ -1261,14 +1274,18 @@ void ODatabaseDocument::writeStorage( const Reference< XStorage >& _rxTargetStor
/** property map for export info set */
comphelper::PropertyMapEntry aExportInfoMap[] =
{
- { MAP_LEN( "UsePrettyPrinting" ), 0, &::getCppuType((sal_Bool*)0), beans::PropertyAttribute::MAYBEVOID, 0},
+ { MAP_LEN( "BaseURI"), 0,&::getCppuType( (::rtl::OUString *)0 ),beans::PropertyAttribute::MAYBEVOID, 0 },
{ MAP_LEN( "StreamName"), 0,&::getCppuType( (::rtl::OUString *)0 ),beans::PropertyAttribute::MAYBEVOID, 0 },
+ { MAP_LEN( "UsePrettyPrinting" ), 0, &::getCppuType((sal_Bool*)0), beans::PropertyAttribute::MAYBEVOID, 0},
{ NULL, 0, 0, NULL, 0, 0 }
};
uno::Reference< beans::XPropertySet > xInfoSet( comphelper::GenericPropertySet_CreateInstance( new comphelper::PropertySetInfo( aExportInfoMap ) ) );
SvtSaveOptions aSaveOpt;
xInfoSet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("UsePrettyPrinting")), uno::makeAny(aSaveOpt.IsPrettyPrinting()));
+ if ( aSaveOpt.IsSaveRelFSys() )
+ xInfoSet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BaseURI")), uno::makeAny(_rMediaDescriptor.getOrDefault("URL",::rtl::OUString())));
+
sal_Int32 nArgsLen = aDelegatorArguments.getLength();
aDelegatorArguments.realloc(nArgsLen+1);
aDelegatorArguments[nArgsLen++] <<= xInfoSet;
@@ -1380,7 +1397,7 @@ void ODatabaseDocument::disposing()
m_aStorageListeners.disposeAndClear( aDisposeEvent );
// SYNCHRONIZED ->
- ::osl::MutexGuard aGuard( m_xMutex->getMutex() );
+ ::osl::MutexGuard aGuard( m_aMutex );
DBG_ASSERT( m_aControllers.empty(), "ODatabaseDocument::disposing: there still are controllers!" );
// normally, nobody should explicitly dispose, but only XCloseable::close the document. And upon
diff --git a/dbaccess/source/core/dataaccess/datasource.cxx b/dbaccess/source/core/dataaccess/datasource.cxx
index 18869c3f9b67..fe2f1d8ecd59 100644
--- a/dbaccess/source/core/dataaccess/datasource.cxx
+++ b/dbaccess/source/core/dataaccess/datasource.cxx
@@ -586,7 +586,7 @@ void ODatabaseSource::setName( const Reference< XDocumentDataSource >& _rxDocume
{
ODatabaseSource& rModelImpl = dynamic_cast< ODatabaseSource& >( *_rxDocument.get() );
- ::osl::MutexGuard aGuard( rModelImpl.m_xMutex->getMutex() );
+ ::osl::MutexGuard aGuard( rModelImpl.m_aMutex );
if ( rModelImpl.m_pImpl.is() )
rModelImpl.m_pImpl->m_sName = _rNewName;
}
@@ -1201,7 +1201,7 @@ Reference< XConnection > SAL_CALL ODatabaseSource::connectWithCompletion( const
::rtl::OUString sServerName( m_pImpl->m_sName );
INetURLObject aURLCheck( sServerName );
if ( aURLCheck.GetProtocol() != INET_PROT_NOT_VALID )
- sServerName = aURLCheck.getName();
+ sServerName = aURLCheck.getBase( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_UNAMBIGUOUS );
// the request
AuthenticationRequest aRequest;
diff --git a/dbaccess/source/core/dataaccess/documentcontainer.cxx b/dbaccess/source/core/dataaccess/documentcontainer.cxx
index 25ddba5e1b68..859855b0bc0c 100644
--- a/dbaccess/source/core/dataaccess/documentcontainer.cxx
+++ b/dbaccess/source/core/dataaccess/documentcontainer.cxx
@@ -148,7 +148,7 @@ ODocumentContainer::ODocumentContainer(const Reference< XMultiServiceFactory >&
, sal_Bool _bFormsContainer
)
:ODefinitionContainer(_xORB,_xParentContainer,_pImpl)
- ,OPropertyStateContainer(m_aBHelper)
+ ,OPropertyStateContainer(OContentHelper::rBHelper)
,m_bFormsContainer(_bFormsContainer)
{
DBG_CTOR(ODocumentContainer, NULL);
@@ -162,7 +162,7 @@ ODocumentContainer::ODocumentContainer(const Reference< XMultiServiceFactory >&
ODocumentContainer::~ODocumentContainer()
{
DBG_DTOR(ODocumentContainer, NULL);
- if ( !m_aBHelper.bInDispose && !m_aBHelper.bDisposed )
+ if ( !OContentHelper::rBHelper.bInDispose && !OContentHelper::rBHelper.bDisposed )
{
acquire();
dispose();
diff --git a/dbaccess/source/core/dataaccess/documentdefinition.cxx b/dbaccess/source/core/dataaccess/documentdefinition.cxx
index f8772375c3cf..db239fd11654 100644
--- a/dbaccess/source/core/dataaccess/documentdefinition.cxx
+++ b/dbaccess/source/core/dataaccess/documentdefinition.cxx
@@ -545,7 +545,7 @@ ODocumentDefinition::ODocumentDefinition(const Reference< XInterface >& _rxConta
,const Reference<XConnection>& _xConnection
)
:OContentHelper(_xORB,_rxContainer,_pImpl)
- ,OPropertyStateContainer(m_aBHelper)
+ ,OPropertyStateContainer(OContentHelper::rBHelper)
,m_pInterceptor(NULL)
,m_bForm(_bForm)
,m_bOpenInDesign(sal_False)
@@ -562,7 +562,7 @@ ODocumentDefinition::ODocumentDefinition(const Reference< XInterface >& _rxConta
ODocumentDefinition::~ODocumentDefinition()
{
DBG_DTOR(ODocumentDefinition, NULL);
- if ( !m_aBHelper.bInDispose && !m_aBHelper.bDisposed )
+ if ( !OContentHelper::rBHelper.bInDispose && !OContentHelper::rBHelper.bDisposed )
{
acquire();
dispose();
diff --git a/dbaccess/source/core/dataaccess/documenteventnotifier.cxx b/dbaccess/source/core/dataaccess/documenteventnotifier.cxx
index fb998a31716d..98976bb52ebd 100644
--- a/dbaccess/source/core/dataaccess/documenteventnotifier.cxx
+++ b/dbaccess/source/core/dataaccess/documenteventnotifier.cxx
@@ -167,8 +167,9 @@ namespace dbaccess
//--------------------------------------------------------------------
void DocumentEventNotifier_Impl::disposing()
{
+ // SYNCHRONIZED ->
// cancel any pending asynchronous events
- ::osl::MutexGuard aGuard( m_rMutex );
+ ::osl::ResettableMutexGuard aGuard( m_rMutex );
if ( m_pEventBroadcaster.is() )
{
m_pEventBroadcaster->removeEventsForProcessor( this );
@@ -177,10 +178,16 @@ namespace dbaccess
}
lang::EventObject aEvent( m_rDocument );
+ aGuard.clear();
+ // <-- SYNCHRONIZED
+
m_aLegacyEventListeners.disposeAndClear( aEvent );
m_aDocumentEventListeners.disposeAndClear( aEvent );
+ // SYNCHRONIZED ->
+ aGuard.reset();
m_bDisposed = true;
+ // <-- SYNCHRONIZED
}
//--------------------------------------------------------------------
diff --git a/dbaccess/source/core/inc/ContentHelper.hxx b/dbaccess/source/core/inc/ContentHelper.hxx
index 4f18487490ec..697ec70fcdb2 100644
--- a/dbaccess/source/core/inc/ContentHelper.hxx
+++ b/dbaccess/source/core/inc/ContentHelper.hxx
@@ -132,7 +132,7 @@ namespace dbaccess
::comphelper::UStringHash,
::comphelper::UStringEqual
> PropertyChangeListenerContainer;
- typedef ::comphelper::OMutexAndBroadcastHelper OContentHelper_MBASE;
+ typedef ::comphelper::OBaseMutex OContentHelper_MBASE;
typedef ::cppu::WeakComponentImplHelper9 < ::com::sun::star::ucb::XContent
, ::com::sun::star::ucb::XCommandProcessor
, ::com::sun::star::lang::XServiceInfo
@@ -166,7 +166,6 @@ namespace dbaccess
TContentPtr m_pImpl;
sal_uInt32 m_nCommandId;
-
// helper
virtual void SAL_CALL disposing();
diff --git a/dbaccess/source/core/misc/dsntypes.cxx b/dbaccess/source/core/misc/dsntypes.cxx
index b6a9053271c0..94f4f9fd26bc 100644
--- a/dbaccess/source/core/misc/dsntypes.cxx
+++ b/dbaccess/source/core/misc/dsntypes.cxx
@@ -36,11 +36,7 @@
#include <unotools/confignode.hxx>
#include <tools/rc.hxx>
#include <tools/debug.hxx>
-// --- needed because of the solar mutex
-#include <vos/mutex.hxx>
-#include <vcl/svapp.hxx>
#include <osl/file.hxx>
-// ---
#include "dbastrings.hrc"
#include "core_resource.hxx"
#include "core_resource.hrc"
@@ -127,7 +123,6 @@ ODsnTypeCollection::ODsnTypeCollection()
:m_nLivingIterators(0)
#endif
{
- ::vos::OGuard aGuard( Application::GetSolarMutex() );
DBG_CTOR(ODsnTypeCollection,NULL);
ODataSourceTypeStringListResource aTypes(RSC_DATASOURCE_TYPES);
aTypes.fill(m_aDsnPrefixes);
diff --git a/dbaccess/source/filter/xml/xmlExport.cxx b/dbaccess/source/filter/xml/xmlExport.cxx
index cc661fab1914..1ba0c73bf089 100644
--- a/dbaccess/source/filter/xml/xmlExport.cxx
+++ b/dbaccess/source/filter/xml/xmlExport.cxx
@@ -103,6 +103,8 @@
#ifndef _COM_SUN_STAR_AWT_FONTDESCRIPTOR_HPP_
#include <com/sun/star/awt/FontDescriptor.hpp>
#endif
+#include <svtools/filenotation.hxx>
+#include <tools/diagnose_ex.h>
namespace dbaxml
{
@@ -615,7 +617,8 @@ void ODBExport::exportConnectionData()
{
SvXMLElementExport aDatabaseDescription(*this,XML_NAMESPACE_DB, XML_DATABASE_DESCRIPTION, sal_True, sal_True);
{
- AddAttribute(XML_NAMESPACE_XLINK,XML_HREF,m_aTypeCollection.cutPrefix(sValue));
+ ::svt::OFileNotation aTransformer( m_aTypeCollection.cutPrefix(sValue) );
+ AddAttribute(XML_NAMESPACE_XLINK,XML_HREF,GetRelativeReference(aTransformer.get( ::svt::OFileNotation::N_URL )));
AddAttribute(XML_NAMESPACE_DB,XML_MEDIA_TYPE,m_aTypeCollection.getMediaType(eType));
try
{
@@ -995,60 +998,68 @@ void ODBExport::exportFilter(XPropertySet* _xProp
// -----------------------------------------------------------------------------
void ODBExport::exportColumns(const Reference<XColumnsSupplier>& _xColSup)
{
- if ( _xColSup.is() )
+ OSL_PRECOND( _xColSup.is(), "ODBExport::exportColumns: invalid columns supplier!" );
+ if ( !_xColSup.is() )
+ return;
+
+ try
{
- Reference<XNameAccess> xNameAccess = _xColSup->getColumns();
- if ( xNameAccess.is() && xNameAccess->hasElements() )
+ Reference<XNameAccess> xNameAccess( _xColSup->getColumns(), UNO_SET_THROW );
+ if ( !xNameAccess->hasElements() )
+ return;
+
+ SvXMLElementExport aColumns(*this,XML_NAMESPACE_DB, XML_COLUMNS, sal_True, sal_True);
+ Sequence< ::rtl::OUString> aSeq = xNameAccess->getElementNames();
+ const ::rtl::OUString* pIter = aSeq.getConstArray();
+ const ::rtl::OUString* pEnd = pIter + aSeq.getLength();
+ for( ; pIter != pEnd ; ++pIter)
{
- SvXMLElementExport aColumns(*this,XML_NAMESPACE_DB, XML_COLUMNS, sal_True, sal_True);
- Sequence< ::rtl::OUString> aSeq = xNameAccess->getElementNames();
- const ::rtl::OUString* pIter = aSeq.getConstArray();
- const ::rtl::OUString* pEnd = pIter + aSeq.getLength();
- for( ; pIter != pEnd ; ++pIter)
+ Reference<XPropertySet> xProp(xNameAccess->getByName(*pIter),UNO_QUERY);
+ if ( xProp.is() )
{
- Reference<XPropertySet> xProp(xNameAccess->getByName(*pIter),UNO_QUERY);
- if ( xProp.is() )
- {
- SvXMLAttributeList* pAtt = new SvXMLAttributeList;
- Reference<XAttributeList> xAtt = pAtt;
- exportStyleName(xProp.get(),*pAtt);
-
- sal_Bool bHidden = getBOOL(xProp->getPropertyValue(PROPERTY_HIDDEN));
+ SvXMLAttributeList* pAtt = new SvXMLAttributeList;
+ Reference<XAttributeList> xAtt = pAtt;
+ exportStyleName(xProp.get(),*pAtt);
- ::rtl::OUString sValue;
- xProp->getPropertyValue(PROPERTY_HELPTEXT) >>= sValue;
- Any aColumnDefault;
- aColumnDefault = xProp->getPropertyValue(PROPERTY_CONTROLDEFAULT);
+ sal_Bool bHidden = getBOOL(xProp->getPropertyValue(PROPERTY_HIDDEN));
- if ( bHidden || sValue.getLength() || aColumnDefault.hasValue() || pAtt->getLength() )
- {
- AddAttribute(XML_NAMESPACE_DB, XML_NAME,*pIter);
- if ( bHidden )
- AddAttribute(XML_NAMESPACE_DB, XML_VISIBLE,XML_FALSE);
+ ::rtl::OUString sValue;
+ xProp->getPropertyValue(PROPERTY_HELPTEXT) >>= sValue;
+ Any aColumnDefault;
+ aColumnDefault = xProp->getPropertyValue(PROPERTY_CONTROLDEFAULT);
- if ( sValue.getLength() )
- AddAttribute(XML_NAMESPACE_DB, XML_HELP_MESSAGE,sValue);
-
- if ( aColumnDefault.hasValue() )
- {
- ::rtl::OUStringBuffer sColumnDefaultString,sType;
- SvXMLUnitConverter::convertAny( sColumnDefaultString, sType, aColumnDefault );
- AddAttribute(XML_NAMESPACE_DB, XML_TYPE_NAME,sType.makeStringAndClear());
- AddAttribute(XML_NAMESPACE_DB, XML_DEFAULT_VALUE,sColumnDefaultString.makeStringAndClear());
- }
+ if ( bHidden || sValue.getLength() || aColumnDefault.hasValue() || pAtt->getLength() )
+ {
+ AddAttribute(XML_NAMESPACE_DB, XML_NAME,*pIter);
+ if ( bHidden )
+ AddAttribute(XML_NAMESPACE_DB, XML_VISIBLE,XML_FALSE);
- if ( pAtt->getLength() )
- AddAttributeList(xAtt);
- }
+ if ( sValue.getLength() )
+ AddAttribute(XML_NAMESPACE_DB, XML_HELP_MESSAGE,sValue);
- if ( GetAttrList().getLength() )
+ if ( aColumnDefault.hasValue() )
{
- SvXMLElementExport aComponents(*this,XML_NAMESPACE_DB, XML_COLUMN, sal_True, sal_True);
+ ::rtl::OUStringBuffer sColumnDefaultString,sType;
+ SvXMLUnitConverter::convertAny( sColumnDefaultString, sType, aColumnDefault );
+ AddAttribute(XML_NAMESPACE_DB, XML_TYPE_NAME,sType.makeStringAndClear());
+ AddAttribute(XML_NAMESPACE_DB, XML_DEFAULT_VALUE,sColumnDefaultString.makeStringAndClear());
}
+
+ if ( pAtt->getLength() )
+ AddAttributeList(xAtt);
+ }
+
+ if ( GetAttrList().getLength() )
+ {
+ SvXMLElementExport aComponents(*this,XML_NAMESPACE_DB, XML_COLUMN, sal_True, sal_True);
}
}
}
}
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
}
// -----------------------------------------------------------------------------
void ODBExport::exportForms()
@@ -1137,20 +1148,22 @@ void ODBExport::exportAutoStyle(XPropertySet* _xProp)
pExportHelper[i].second.first->insert( TPropertyStyleMap::value_type(_xProp,GetAutoStylePool()->Add( pExportHelper[i].second.second, aPropertyStates )));
}
- Reference< XNameAccess > xCollection = xSup->getColumns();
+ Reference< XNameAccess > xCollection;
try
{
+ xCollection.set( xSup->getColumns(), UNO_SET_THROW );
awt::FontDescriptor aFont;
_xProp->getPropertyValue(PROPERTY_FONT) >>= aFont;
GetFontAutoStylePool()->Add(aFont.Name,aFont.StyleName,aFont.Family,aFont.Pitch,aFont.CharSet );
+
+ m_aCurrentPropertyStates = m_xCellExportHelper->Filter(_xProp);
+ ::comphelper::mem_fun1_t<ODBExport,XPropertySet* > aMemFunc(&ODBExport::exportAutoStyle);
+ exportCollection(xCollection,XML_TOKEN_INVALID,XML_TOKEN_INVALID,sal_False,aMemFunc);
}
catch(Exception&)
{
- // not interested in
+ DBG_UNHANDLED_EXCEPTION();
}
- m_aCurrentPropertyStates = m_xCellExportHelper->Filter(_xProp);
- ::comphelper::mem_fun1_t<ODBExport,XPropertySet* > aMemFunc(&ODBExport::exportAutoStyle);
- exportCollection(xCollection,XML_TOKEN_INVALID,XML_TOKEN_INVALID,sal_False,aMemFunc);
m_aCurrentPropertyStates.clear();
}
else
diff --git a/dbaccess/source/filter/xml/xmlfilter.cxx b/dbaccess/source/filter/xml/xmlfilter.cxx
index 8ab5d173acf0..128ad71ffc21 100644
--- a/dbaccess/source/filter/xml/xmlfilter.cxx
+++ b/dbaccess/source/filter/xml/xmlfilter.cxx
@@ -128,6 +128,7 @@
#include <toolkit/helper/vclunohelper.hxx>
#endif
#include <tools/diagnose_ex.h>
+#include <comphelper/namedvaluecollection.hxx>
using namespace ::com::sun::star;
@@ -182,11 +183,6 @@ sal_Int32 ReadThroughComponent(
xImporter->setTargetDocument( xModelComponent );
-#ifdef TIMELOG
- // if we do profiling, we want to know the stream
- RTL_LOGFILE_TRACE_AUTHOR1( "dbaxml", "oj",
- "ReadThroughComponent : parsing \"%s\"", pStreamName );
-#endif
// finally, parser the stream
try
@@ -280,6 +276,12 @@ sal_Int32 ReadThroughComponent(
return 1; // TODO/LATER: error handling
}
+#ifdef TIMELOG
+ // if we do profiling, we want to know the stream
+ RTL_LOGFILE_TRACE_AUTHOR1( "dbaxml", "oj",
+ "ReadThroughComponent : parsing \"%s\"", pStreamName );
+#endif
+
uno::Reference< XInputStream > xInputStream = xDocStream->getInputStream();
// read from the stream
return ReadThroughComponent( xInputStream
@@ -355,18 +357,16 @@ sal_Bool SAL_CALL ODBFilter::filter( const Sequence< PropertyValue >& rDescripto
sal_Bool ODBFilter::implImport( const Sequence< PropertyValue >& rDescriptor )
throw (RuntimeException)
{
-::rtl::OUString sFileName;
-
- const PropertyValue* pIter = rDescriptor.getConstArray();
- const PropertyValue* pEnd = pIter + rDescriptor.getLength();
- for(;pIter != pEnd;++pIter)
- {
- if( pIter->Name.equalsAscii( "FileName" ) )
- pIter->Value >>= sFileName;
- }
+ ::rtl::OUString sFileName;
+ ::comphelper::NamedValueCollection aMediaDescriptor( rDescriptor );
+ if ( aMediaDescriptor.has( "URL" ) )
+ sFileName = aMediaDescriptor.getOrDefault( "URL", ::rtl::OUString() );
+ if ( !sFileName.getLength() && aMediaDescriptor.has( "FileName" ) )
+ sFileName = aMediaDescriptor.getOrDefault( "FileName", sFileName );
+ OSL_ENSURE( sFileName.getLength(), "ODBFilter::implImport: no URL given!" );
+ sal_Bool bRet = ( sFileName.getLength() != 0 );
- sal_Bool bRet = (sFileName.getLength() != 0);
if ( bRet )
{
uno::Reference<XComponent> xCom(GetModel(),UNO_QUERY);
diff --git a/dbaccess/source/ui/app/AppController.cxx b/dbaccess/source/ui/app/AppController.cxx
index 4c7c97054368..ccac5237d7dc 100644
--- a/dbaccess/source/ui/app/AppController.cxx
+++ b/dbaccess/source/ui/app/AppController.cxx
@@ -34,6 +34,7 @@
#include "AppController.hxx"
#include "dbustrings.hrc"
#include "advancedsettingsdlg.hxx"
+#include "subcomponentmanager.hxx"
/** === begin UNO includes === **/
#include <com/sun/star/beans/NamedValue.hpp>
@@ -407,7 +408,8 @@ DBG_NAME(OApplicationController)
//--------------------------------------------------------------------
OApplicationController::OApplicationController(const Reference< XMultiServiceFactory >& _rxORB)
:OApplicationController_CBASE( _rxORB )
- ,m_aContextMenuInterceptors( m_aMutex )
+ ,m_aContextMenuInterceptors( getMutex() )
+ ,m_pSubComponentManager( new SubComponentManager( getSharedMutex() ) )
,m_aTableCopyHelper(this)
,m_pClipbordNotifier(NULL)
,m_nAsyncDrop(0)
@@ -417,7 +419,7 @@ OApplicationController::OApplicationController(const Reference< XMultiServiceFac
,m_eCurrentType(E_NONE)
,m_bNeedToReconnect(sal_False)
,m_bSuspended( sal_False )
- ,m_pSelectionNotifier( new SelectionNotifier( m_aMutex, *this ) )
+ ,m_pSelectionNotifier( new SelectionNotifier( getMutex(), *this ) )
{
DBG_CTOR(OApplicationController,NULL);
@@ -472,8 +474,7 @@ void SAL_CALL OApplicationController::disposing()
::std::for_each(m_aCurrentContainers.begin(),m_aCurrentContainers.end(),XContainerFunctor(this));
m_aCurrentContainers.clear();
- m_aSpecialSubFrames.clear();
- m_aDocuments.clear();
+ m_pSubComponentManager->disposing();
m_pSelectionNotifier->disposing();
if ( getView() )
@@ -596,7 +597,7 @@ sal_Bool OApplicationController::Construct(Window* _pParent)
//--------------------------------------------------------------------
void SAL_CALL OApplicationController::disposing(const EventObject& _rSource) throw( RuntimeException )
{
- ::osl::MutexGuard aGuard(m_aMutex);
+ ::osl::MutexGuard aGuard( getMutex() );
Reference<XConnection> xCon(_rSource.Source, UNO_QUERY);
if ( xCon.is() )
{
@@ -622,22 +623,7 @@ void SAL_CALL OApplicationController::disposing(const EventObject& _rSource) thr
}
else
{
- Reference<XComponent> xComp(_rSource.Source,UNO_QUERY);
- Reference<XContainer> xContainer(_rSource.Source,UNO_QUERY);
- if ( xComp.is() )
- {
- TDocuments::iterator aFind = ::std::find_if(m_aDocuments.begin(),m_aDocuments.end(),
- ::std::compose1(::std::bind2nd(::std::equal_to<Reference<XComponent> >(),xComp),::std::select1st<TDocuments::value_type>()));
- if ( aFind != m_aDocuments.end() )
- m_aDocuments.erase(aFind);
-
- TFrames::iterator aFind2 = ::std::find_if(m_aSpecialSubFrames.begin(),m_aSpecialSubFrames.end(),
- ::std::compose1(::std::bind2nd(::std::equal_to<Reference<XComponent> >(),xComp),
- ::std::compose1(::std::select2nd<TTypeFrame>(),::std::select2nd<TFrames::value_type>())));
- if ( aFind2 != m_aSpecialSubFrames.end() )
- m_aSpecialSubFrames.erase(aFind2);
-
- }
+ Reference<XContainer> xContainer( _rSource.Source, UNO_QUERY );
if ( xContainer.is() )
{
TContainerVector::iterator aFind = ::std::find(m_aCurrentContainers.begin(),m_aCurrentContainers.end(),xContainer);
@@ -662,7 +648,7 @@ sal_Bool SAL_CALL OApplicationController::suspend(sal_Bool bSuspend) throw( Runt
}
::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
- ::osl::MutexGuard aGuard(m_aMutex);
+ ::osl::MutexGuard aGuard( getMutex() );
if ( getView() && getView()->IsInModalMode() )
return sal_False;
@@ -1150,7 +1136,7 @@ namespace
void OApplicationController::Execute(sal_uInt16 _nId, const Sequence< PropertyValue >& aArgs)
{
::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
- ::osl::MutexGuard aGuard(m_aMutex);
+ ::osl::MutexGuard aGuard( getMutex() );
if ( isUserDefinedFeature( _nId ) )
{
@@ -1329,7 +1315,6 @@ void OApplicationController::Execute(sal_uInt16 _nId, const Sequence< PropertyVa
lcl_handleException_nothrow( m_xModel, ::cppu::getCaughtException() );
}
- m_sDatabaseName = ::rtl::OUString();
/*updateTitle();*/
m_bCurrentlyModified = sal_False;
InvalidateFeature(ID_BROWSER_SAVEDOC);
@@ -1425,7 +1410,7 @@ void OApplicationController::Execute(sal_uInt16 _nId, const Sequence< PropertyVa
Reference< XDataSource > xDataSource( m_xDataSource, UNO_QUERY );
Reference< XComponent > xComponent( aDesigner.createNew( xDataSource ), UNO_QUERY );
- addDocumentListener( xComponent, NULL );
+ onDocumentOpened( ::rtl::OUString(), E_QUERY, E_OPEN_DESIGN, xComponent, NULL );
}
}
break;
@@ -1466,18 +1451,17 @@ void OApplicationController::Execute(sal_uInt16 _nId, const Sequence< PropertyVa
InvalidateAll();
break;
case SID_DB_APP_DSRELDESIGN:
- if ( !impl_activateSubFrame_throw(::rtl::OUString(),SID_DB_APP_DSRELDESIGN,E_OPEN_DESIGN) )
+ if ( !m_pSubComponentManager->activateSubFrame( ::rtl::OUString(), SID_DB_APP_DSRELDESIGN, E_OPEN_DESIGN ) )
{
SharedConnection xConnection( ensureConnection() );
if ( xConnection.is() )
{
RelationDesigner aDesigner( getORB(), this, m_aCurrentFrame.getFrame() );
+
Reference< XDataSource > xDataSource( m_xDataSource, UNO_QUERY );
Reference< XComponent > xComponent( aDesigner.createNew( xDataSource ), UNO_QUERY );
- addDocumentListener( xComponent, NULL );
- m_aSpecialSubFrames.insert(TFrames::value_type(::rtl::OUString(),
- TTypeFrame(TTypeOpenMode(SID_DB_APP_DSRELDESIGN,E_OPEN_DESIGN),xComponent)));
- } // if ( xConnection.is() )
+ onDocumentOpened( ::rtl::OUString(), SID_DB_APP_DSRELDESIGN, E_OPEN_DESIGN, xComponent, NULL );
+ }
}
break;
case SID_DB_APP_DSUSERADMIN:
@@ -1676,7 +1660,7 @@ OApplicationView* OApplicationController::getContainer() const
void SAL_CALL OApplicationController::elementInserted( const ContainerEvent& _rEvent ) throw(RuntimeException)
{
::vos::OGuard aSolarGuard(Application::GetSolarMutex());
- ::osl::MutexGuard aGuard(m_aMutex);
+ ::osl::MutexGuard aGuard( getMutex() );
Reference< XContainer > xContainer(_rEvent.Source, UNO_QUERY);
if ( ::std::find(m_aCurrentContainers.begin(),m_aCurrentContainers.end(),xContainer) != m_aCurrentContainers.end() )
@@ -1712,7 +1696,7 @@ void SAL_CALL OApplicationController::elementInserted( const ContainerEvent& _rE
void SAL_CALL OApplicationController::elementRemoved( const ContainerEvent& _rEvent ) throw(RuntimeException)
{
::vos::OGuard aSolarGuard(Application::GetSolarMutex());
- ::osl::MutexGuard aGuard(m_aMutex);
+ ::osl::MutexGuard aGuard( getMutex() );
Reference< XContainer > xContainer(_rEvent.Source, UNO_QUERY);
if ( ::std::find(m_aCurrentContainers.begin(),m_aCurrentContainers.end(),xContainer) != m_aCurrentContainers.end() )
@@ -1746,7 +1730,7 @@ void SAL_CALL OApplicationController::elementRemoved( const ContainerEvent& _rEv
void SAL_CALL OApplicationController::elementReplaced( const ContainerEvent& _rEvent ) throw(RuntimeException)
{
::vos::OGuard aSolarGuard(Application::GetSolarMutex());
- ::osl::MutexGuard aGuard(m_aMutex);
+ ::osl::MutexGuard aGuard( getMutex() );
Reference< XContainer > xContainer(_rEvent.Source, UNO_QUERY);
if ( ::std::find(m_aCurrentContainers.begin(),m_aCurrentContainers.end(),xContainer) != m_aCurrentContainers.end() )
@@ -1971,16 +1955,15 @@ Reference< XComponent > OApplicationController::openElementWithArguments( const
Reference< XComponent > xDefinition;
xRet = aHelper->open( _sName, xDefinition, _eOpenMode, _rAdditionalArguments );
- addDocumentListener(xRet,xDefinition);
+ onDocumentOpened( _sName, _eType, _eOpenMode, xRet, xDefinition );
}
break;
case E_QUERY:
case E_TABLE:
{
- if ( !impl_activateSubFrame_throw(_sName,_eType,_eOpenMode) )
+ if ( !m_pSubComponentManager->activateSubFrame( _sName, _eType, _eOpenMode ) )
{
-
SharedConnection xConnection( ensureConnection() );
if ( !xConnection.is() )
break;
@@ -2017,9 +2000,7 @@ Reference< XComponent > OApplicationController::openElementWithArguments( const
}
Reference< XComponent > xComponent( pDesigner->openExisting( aDataSource, _sName, aArguments.getPropertyValues() ), UNO_QUERY );
- addDocumentListener( xComponent, NULL );
- m_aSpecialSubFrames.insert(TFrames::value_type(_sName,
- TTypeFrame(TTypeOpenMode(_eType,_eOpenMode),xComponent)));
+ onDocumentOpened( _sName, _eType, _eOpenMode, xComponent, NULL );
}
}
break;
@@ -2066,7 +2047,7 @@ void OApplicationController::newElementWithPilot( ElementType _eType )
else
xComponent = aHelper->newFormWithPilot(xDefinition,nCommandType,sName);
- addDocumentListener(xComponent,xDefinition);
+ onDocumentOpened( ::rtl::OUString(), _eType, E_OPEN_DESIGN, xComponent, xDefinition );
}
}
break;
@@ -2076,12 +2057,13 @@ void OApplicationController::newElementWithPilot( ElementType _eType )
::std::auto_ptr<OLinkedDocumentsAccess> aHelper = getDocumentsAccess(_eType);
if ( aHelper->isConnected() )
{
- Reference< XComponent > xComponent,xDefinition;
+ Reference< XComponent > xComponent;
if ( E_QUERY == _eType )
xComponent = aHelper->newQueryWithPilot();
else
xComponent = aHelper->newTableWithPilot();
- addDocumentListener(xComponent,xDefinition);
+
+ onDocumentOpened( ::rtl::OUString(), _eType, E_OPEN_DESIGN, xComponent, NULL );
}
}
break;
@@ -2107,7 +2089,7 @@ void OApplicationController::newElement( ElementType _eType, sal_Bool _bSQLView
sal_Int32 nCommandType = -1;
const ::rtl::OUString sName(getCurrentlySelectedName(nCommandType));
xComponent = aHelper->newDocument(_eType == E_FORM ? ID_FORM_NEW_TEXT : ID_REPORT_NEW_TEXT,xDefinition,nCommandType,sName);
- addDocumentListener(xComponent,xDefinition);
+ onDocumentOpened( ::rtl::OUString(), _eType, E_OPEN_DESIGN, xComponent, xDefinition );
}
}
break;
@@ -2129,7 +2111,7 @@ void OApplicationController::newElement( ElementType _eType, sal_Bool _bSQLView
Reference< XDataSource > xDataSource( m_xDataSource, UNO_QUERY );
Reference< XComponent > xComponent( pDesigner->createNew( xDataSource ), UNO_QUERY );
- addDocumentListener(xComponent,NULL);
+ onDocumentOpened( ::rtl::OUString(), _eType, E_OPEN_DESIGN, xComponent, NULL );
}
}
break;
@@ -2163,7 +2145,7 @@ void OApplicationController::addContainerListener(const Reference<XNameAccess>&
void OApplicationController::renameEntry()
{
::vos::OGuard aSolarGuard(Application::GetSolarMutex());
- ::osl::MutexGuard aGuard(m_aMutex);
+ ::osl::MutexGuard aGuard( getMutex() );
OSL_ENSURE(getContainer(),"View is NULL! -> GPF");
::std::vector< ::rtl::OUString> aList;
@@ -2311,68 +2293,59 @@ void OApplicationController::renameEntry()
DBG_UNHANDLED_EXCEPTION();
}
}
-// -----------------------------------------------------------------------------
-void OApplicationController::onEntryDeSelect(SvTreeListBox& /*_rTree*/)
-{
- SelectionGuard aSelGuard( *m_pSelectionNotifier );
- InvalidateAll();
-}
// -----------------------------------------------------------------------------
-void OApplicationController::onEntrySelect(SvLBoxEntry* _pEntry)
+void OApplicationController::onSelectionChanged()
{
InvalidateAll();
+ SelectionGuard aSelGuard( *m_pSelectionNotifier );
+
OApplicationView* pView = getContainer();
- if ( pView )
- {
- SelectionGuard aSelGuard( *m_pSelectionNotifier );
+ if ( !pView )
+ return;
+ if ( pView->getSelectionCount() == 1 )
+ {
const ElementType eType = pView->getElementType();
- if ( _pEntry && pView->isALeafSelected() )
+ if ( pView->isALeafSelected() )
{
- const ::rtl::OUString sName = pView->getQualifiedName( _pEntry );
- selectEntry(eType,sName);
+ const ::rtl::OUString sName = pView->getQualifiedName( NULL /* means 'first selected' */ );
+ showPreviewFor( eType, sName );
}
}
}
// -----------------------------------------------------------------------------
-void OApplicationController::selectEntry(const ElementType _eType,const ::rtl::OUString& _sName)
+void OApplicationController::showPreviewFor(const ElementType _eType,const ::rtl::OUString& _sName)
{
OApplicationView* pView = getContainer();
- Reference< XContent> xContent;
+ if ( !pView )
+ return;
+
try
{
switch( _eType )
{
case E_FORM:
case E_REPORT:
- if ( _sName.getLength() )
- {
- Reference< XHierarchicalNameAccess > xContainer(getElements(_eType),UNO_QUERY);
- if ( xContainer.is() && xContainer->hasByHierarchicalName(_sName) )
- xContent.set(xContainer->getByHierarchicalName(_sName),UNO_QUERY);
- }
- break;
+ {
+ Reference< XHierarchicalNameAccess > xContainer( getElements( _eType ), UNO_QUERY_THROW );
+ Reference< XContent> xContent( xContainer->getByHierarchicalName( _sName ), UNO_QUERY_THROW );
+ pView->showPreview( xContent );
+ }
+ break;
+
+ case E_TABLE:
case E_QUERY:
- if ( pView->isPreviewEnabled() )
{
SharedConnection xConnection( ensureConnection() );
if ( xConnection.is() )
- pView->showPreview(getDatabaseName(),xConnection,_sName,sal_False);
+ pView->showPreview( getDatabaseName(), xConnection, _sName, _eType == E_TABLE );
}
return;
- case E_TABLE:
- {
- SharedConnection xConnection( ensureConnection() );
- if ( xConnection.is() )
- {
- pView->showPreview(getDatabaseName(),xConnection,_sName,_eType == E_TABLE);
- return;
- }
- }
- break;
+
default:
+ OSL_ENSURE( false, "OApplicationController::showPreviewFor: unexpected element type!" );
break;
}
}
@@ -2384,8 +2357,6 @@ void OApplicationController::selectEntry(const ElementType _eType,const ::rtl::O
{
DBG_UNHANDLED_EXCEPTION();
}
-
- pView->showPreview(xContent);
}
//------------------------------------------------------------------------------
@@ -2403,21 +2374,21 @@ IMPL_LINK(OApplicationController, OnInvalidateClipboard, void*, EMPTYARG)
return 0L;
}
// -----------------------------------------------------------------------------
-void OApplicationController::onCutEntry(SvLBoxEntry* /*_pEntry*/)
+void OApplicationController::onCutEntry()
{
}
// -----------------------------------------------------------------------------
-void OApplicationController::onCopyEntry(SvLBoxEntry* /*_pEntry*/)
+void OApplicationController::onCopyEntry()
{
Execute(ID_BROWSER_COPY,Sequence<PropertyValue>());
}
// -----------------------------------------------------------------------------
-void OApplicationController::onPasteEntry(SvLBoxEntry* /*_pEntry*/)
+void OApplicationController::onPasteEntry()
{
Execute(ID_BROWSER_PASTE,Sequence<PropertyValue>());
}
// -----------------------------------------------------------------------------
-void OApplicationController::onDeleteEntry(SvLBoxEntry* /*_pEntry*/)
+void OApplicationController::onDeleteEntry()
{
ElementType eType = getContainer()->getElementType();
sal_uInt16 nId = 0;
@@ -2796,7 +2767,7 @@ IMPL_LINK( OApplicationController, OnFirstControllerConnected, void*, /**/ )
// -----------------------------------------------------------------------------
sal_Bool SAL_CALL OApplicationController::attachModel(const Reference< XModel > & _rxModel) throw( RuntimeException )
{
- ::osl::MutexGuard aGuard( m_aMutex );
+ ::osl::MutexGuard aGuard( getMutex() );
Reference< XOfficeDatabaseDocument > xOfficeDoc( _rxModel, UNO_QUERY );
if ( !xOfficeDoc.is() && _rxModel.is() )
{
@@ -2822,14 +2793,10 @@ sal_Bool SAL_CALL OApplicationController::attachModel(const Reference< XModel >
}
m_xDataSource.set(xOfficeDoc.is() ? xOfficeDoc->getDataSource() : Reference<XDataSource>(),UNO_QUERY);
- if ( !m_xDataSource.is() )
- m_sDatabaseName = ::rtl::OUString();
- else
+ if ( m_xDataSource.is() )
{
try
{
- m_xDataSource->getPropertyValue(PROPERTY_NAME) >>= m_sDatabaseName;
-
m_xDataSource->addPropertyChangeListener(PROPERTY_INFO, this);
m_xDataSource->addPropertyChangeListener(PROPERTY_URL, this);
m_xDataSource->addPropertyChangeListener(PROPERTY_ISPASSWORDREQUIRED, this);
@@ -2920,7 +2887,7 @@ void SAL_CALL OApplicationController::removeSelectionChangeListener( const Refer
::sal_Bool SAL_CALL OApplicationController::select( const Any& _aSelection ) throw (IllegalArgumentException, RuntimeException)
{
::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
- ::osl::MutexGuard aGuard(m_aMutex);
+ ::osl::MutexGuard aGuard( getMutex() );
Sequence< ::rtl::OUString> aSelection;
if ( !_aSelection.hasValue() || !getView() )
{
@@ -3048,12 +3015,30 @@ void SAL_CALL OApplicationController::removeSelectionChangeListener( const Refer
Any SAL_CALL OApplicationController::getSelection( ) throw (RuntimeException)
{
::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
- ::osl::MutexGuard aGuard(m_aMutex);
+ ::osl::MutexGuard aGuard( getMutex() );
Sequence< NamedDatabaseObject > aCurrentSelection;
const ElementType eType( getContainer()->getElementType() );
if ( eType != E_NONE )
+ {
getContainer()->describeCurrentSelectionForType( eType, aCurrentSelection );
+ if ( aCurrentSelection.getLength() == 0 )
+ { // if no objects are selected, add an entry to the sequence which describes the overall category
+ // which is selected currently
+ aCurrentSelection.realloc(1);
+ aCurrentSelection[0].Name = getDatabaseName();
+ switch ( eType )
+ {
+ case E_TABLE: aCurrentSelection[0].Type = DatabaseObjectContainer::TABLES; break;
+ case E_QUERY: aCurrentSelection[0].Type = DatabaseObjectContainer::QUERIES; break;
+ case E_FORM: aCurrentSelection[0].Type = DatabaseObjectContainer::FORMS; break;
+ case E_REPORT: aCurrentSelection[0].Type = DatabaseObjectContainer::REPORTS; break;
+ default:
+ OSL_ENSURE( false, "OApplicationController::getSelection: unexpected current element type!" );
+ break;
+ }
+ }
+ }
return makeAny( aCurrentSelection );
}
// -----------------------------------------------------------------------------
@@ -3083,45 +3068,6 @@ void OApplicationController::impl_migrateScripts_nothrow()
}
}
-// -----------------------------------------------------------------------------
-bool OApplicationController::impl_activateSubFrame_throw(const ::rtl::OUString& _sName,const sal_Int32 _nKind,const ElementOpenMode _eOpenMode) const
-{
- bool bFound = false;
- TFrames::const_iterator aFind = m_aSpecialSubFrames.find(_sName);
- for(;aFind != m_aSpecialSubFrames.end();++aFind)
- {
- if ( aFind->second.first.first == _nKind && aFind->second.first.second == _eOpenMode )
- {
- const Reference< XFrame> xFrame(aFind->second.second,UNO_QUERY);
- if ( xFrame.is() )
- {
- Reference< awt::XTopWindow> xTopWindow(xFrame->getContainerWindow(),UNO_QUERY);
- if ( xTopWindow.is() )
- xTopWindow->toFront();
- bFound = true;
- }
- break;
- } // if ( aFind->second.first.first == _nKind && aFind->second.first.second == _eOpenMode )
- }
- return bFound;
-}
-// -----------------------------------------------------------------------------
-void OApplicationController::impl_deActivateSubFrame_throw(const ::rtl::OUString& _sName,const sal_Int32 _nKind)
-{
- TFrames aCopy = m_aSpecialSubFrames;
- TFrames::iterator aFind = aCopy.find(_sName);
- for(;aFind != aCopy.end();++aFind)
- {
- if ( aFind->second.first.first == _nKind )
- {
- Reference< XFrame> xFrame(aFind->second.second,UNO_QUERY);
- if ( xFrame.is() )
- {
- ::comphelper::disposeComponent(xFrame);
- }
- } // if ( aFind->second.first.first == _nKind && aFind->second.first.second == _eOpenMode )
- }
-}
//........................................................................
} // namespace dbaui
//........................................................................
diff --git a/dbaccess/source/ui/app/AppController.hxx b/dbaccess/source/ui/app/AppController.hxx
index 07be5b0bd4e1..96ca58d6f428 100644
--- a/dbaccess/source/ui/app/AppController.hxx
+++ b/dbaccess/source/ui/app/AppController.hxx
@@ -76,6 +76,9 @@ FORWARD_DECLARE_INTERFACE(ucb,XContent)
namespace dbaui
{
//........................................................................
+
+ class SubComponentManager;
+
//====================================================================
//= OApplicationController
//====================================================================
@@ -101,13 +104,6 @@ namespace dbaui
typedef ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainer > TContainer;
typedef ::std::vector< TContainer > TContainerVector;
- typedef ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > TComponent;
- typedef ::std::map< TComponent, TComponent > TDocuments;
-
- typedef ::std::pair< sal_Int32, ElementOpenMode > TTypeOpenMode;
- typedef ::std::pair< TTypeOpenMode , TComponent > TTypeFrame;
- typedef ::std::multimap< ::rtl::OUString, TTypeFrame > TFrames;
-
private:
OTableCopyHelper::DropDescriptor m_aAsyncDrop;
@@ -130,14 +126,13 @@ namespace dbaui
ModelControllerConnector
m_aModelConnector;
TContainerVector m_aCurrentContainers; // the containers where we are listener on
- TDocuments m_aDocuments;
- TFrames m_aSpecialSubFrames; // contains the query, table and relation frame
+ ::rtl::Reference< SubComponentManager >
+ m_pSubComponentManager;
::dbaccess::ODsnTypeCollection
m_aTypeCollection;
OTableCopyHelper m_aTableCopyHelper;
TransferableClipboardListener*
m_pClipbordNotifier; // notifier for changes in the clipboard
- mutable ::rtl::OUString m_sDatabaseName;
ULONG m_nAsyncDrop;
OAsyncronousLink m_aControllerConnectedEvent;
OAsyncronousLink m_aSelectContainerEvent;
@@ -156,23 +151,11 @@ namespace dbaui
OApplicationView* getContainer() const;
- /** activates the current table, query or relation design frame when existing
- @param _sName the name of the component
- @param _nKind the kind of the component
- */
- bool impl_activateSubFrame_throw(const ::rtl::OUString& _sName,const sal_Int32 _nKind,const ElementOpenMode _eOpenMode) const;
-
- /** deactivates the current table or query frame when existing
- @param _sName the name of the component
- @param _nKind the kind of the component
- */
- void impl_deActivateSubFrame_throw(const ::rtl::OUString& _sName,const sal_Int32 _nKind);
-
/** returns the database name
@return
the database name
*/
- inline ::rtl::OUString getDatabaseName() const { return m_sDatabaseName; }
+ ::rtl::OUString getDatabaseName() const;
/** returns the stripped database name.
@return
@@ -359,14 +342,15 @@ namespace dbaui
*/
void askToReconnect();
- /** add event listener and remember the document
- @param _xDocument
- the new document, may be <NULL/>
- @param _xDefinition
- The defintion object.
+ /** remember a newly opened sub document for later access
*/
- void addDocumentListener(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& _xDocument,
- const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& _xDefinition);
+ void onDocumentOpened(
+ const ::rtl::OUString& _rName,
+ const sal_Int32 _nType,
+ const ElementOpenMode _eMode,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& _xDocument,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& _xDefinition
+ );
/** Inserts a new object into the hierachy given be the type.
@param _eType
@@ -408,9 +392,9 @@ namespace dbaui
*/
::rtl::OUString getCurrentlySelectedName(sal_Int32& _rnCommandType) const;
- /** select the give entry
+ /** shows the preview for the given entry
*/
- void selectEntry(const ElementType _eType,const ::rtl::OUString& _sName);
+ void showPreviewFor( const ElementType _eType,const ::rtl::OUString& _sName );
/** called when we just connected to a new, non-NULL model
@@ -489,7 +473,7 @@ namespace dbaui
virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > SAL_CALL getActiveConnection() throw (::com::sun::star::uno::RuntimeException);
virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > > SAL_CALL getSubComponents() throw (::com::sun::star::uno::RuntimeException);
virtual ::sal_Bool SAL_CALL isConnected( ) throw (::com::sun::star::uno::RuntimeException);
- virtual ::sal_Bool SAL_CALL connect( ) throw (::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL connect( ) throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
virtual ::sal_Bool SAL_CALL closeSubComponents( ) throw (::com::sun::star::uno::RuntimeException);
virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > SAL_CALL loadComponent( ::sal_Int32 ObjectType, const ::rtl::OUString& ObjectName, ::sal_Bool ForEditing ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > SAL_CALL loadComponentWithArguments( ::sal_Int32 ObjectType, const ::rtl::OUString& ObjectName, ::sal_Bool ForEditing, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& Arguments ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
@@ -505,8 +489,11 @@ namespace dbaui
virtual void SAL_CALL removeSelectionChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::view::XSelectionChangeListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
/** retrieves the current connection, creates it if necessary
+
+ If an error occurs, then this is either stored in the location pointed to by <arg>_pErrorInfo</arg>,
+ or, if <code>_pErrorInfo</code> is <NULL/>, then the error is displayed to the user.
*/
- const SharedConnection& ensureConnection();
+ const SharedConnection& ensureConnection( ::dbtools::SQLExceptionInfo* _pErrorInfo = NULL );
/** retrieves the current connection
*/
@@ -525,12 +512,11 @@ namespace dbaui
// IApplicationController
virtual bool onEntryDoubleClick(SvTreeListBox& _rTree);
virtual sal_Bool onContainerSelect(ElementType _eType);
- virtual void onEntrySelect(SvLBoxEntry* _pEntry);
- virtual void onEntryDeSelect(SvTreeListBox& _rTree);
- virtual void onCutEntry(SvLBoxEntry* _pEntry);
- virtual void onCopyEntry(SvLBoxEntry* _pEntry);
- virtual void onPasteEntry(SvLBoxEntry* _pEntry);
- virtual void onDeleteEntry(SvLBoxEntry* _pEntry);
+ virtual void onSelectionChanged();
+ virtual void onCutEntry();
+ virtual void onCopyEntry();
+ virtual void onPasteEntry();
+ virtual void onDeleteEntry();
virtual void previewChanged( sal_Int32 _nMode);
virtual void containerFound( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainer >& _xContainer);
diff --git a/dbaccess/source/ui/app/AppControllerDnD.cxx b/dbaccess/source/ui/app/AppControllerDnD.cxx
index e063e45c824a..989ceacdc1f0 100644
--- a/dbaccess/source/ui/app/AppControllerDnD.cxx
+++ b/dbaccess/source/ui/app/AppControllerDnD.cxx
@@ -221,6 +221,7 @@
#ifndef _VOS_MUTEX_HXX_
#include <vos/mutex.hxx>
#endif
+#include "subcomponentmanager.hxx"
//........................................................................
namespace dbaui
@@ -263,7 +264,11 @@ void OApplicationController::deleteTables(const ::std::vector< ::rtl::OUString>&
sal_Int32 nResult = RET_YES;
if ( bConfirm )
nResult = ::dbaui::askForUserAction(getView(),STR_TITLE_CONFIRM_DELETION ,STR_QUERY_DELETE_TABLE,_rList.size() > 1 && (aIter+1) != _rList.end(),sTableName);
- if ( (RET_YES == nResult) || (RET_ALL == nResult) )
+
+ bool bUserConfirmedDelete =
+ ( RET_YES == nResult )
+ || ( RET_ALL == nResult );
+ if ( bUserConfirmedDelete && m_pSubComponentManager->closeSubFrames( sTableName, E_TABLE ) )
{
SQLExceptionInfo aErrorInfo;
try
@@ -286,7 +291,6 @@ void OApplicationController::deleteTables(const ::std::vector< ::rtl::OUString>&
}
}
}
- impl_deActivateSubFrame_throw(sTableName,E_TABLE);
}
catch(SQLContext& e) { aErrorInfo = e; }
catch(SQLWarning& e) { aErrorInfo = e; }
@@ -370,8 +374,13 @@ void OApplicationController::deleteObjects( ElementType _eType, const ::std::vec
bool bSuccess = false;
- if ( ( eResult == svtools::QUERYDELETE_ALL ) ||
- ( eResult == svtools::QUERYDELETE_YES ) )
+ bool bUserConfirmedDelete =
+ ( eResult == svtools::QUERYDELETE_ALL )
+ || ( eResult == svtools::QUERYDELETE_YES );
+
+ if ( bUserConfirmedDelete
+ && ( ( _eType == E_QUERY ) ? m_pSubComponentManager->closeSubFrames( *aThisRound, _eType ) : true )
+ )
{
try
{
@@ -380,9 +389,6 @@ void OApplicationController::deleteObjects( ElementType _eType, const ::std::vec
else
xNames->removeByName( *aThisRound );
- if ( _eType == E_QUERY )
- impl_deActivateSubFrame_throw(*aThisRound,_eType);
-
bSuccess = true;
// now that we removed the element, care for all it's child elements
@@ -438,7 +444,7 @@ void OApplicationController::deleteObjects( ElementType _eType, const ::std::vec
void OApplicationController::deleteEntries()
{
::vos::OGuard aSolarGuard(Application::GetSolarMutex());
- ::osl::MutexGuard aGuard(m_aMutex);
+ ::osl::MutexGuard aGuard( getMutex() );
if ( getContainer() )
{
@@ -465,10 +471,10 @@ void OApplicationController::deleteEntries()
}
}
// -----------------------------------------------------------------------------
-const SharedConnection& OApplicationController::ensureConnection()
+const SharedConnection& OApplicationController::ensureConnection( ::dbtools::SQLExceptionInfo* _pErrorInfo )
{
::vos::OGuard aSolarGuard(Application::GetSolarMutex());
- ::osl::MutexGuard aGuard(m_aMutex);
+ ::osl::MutexGuard aGuard( getMutex() );
if ( !m_xDataSourceConnection.is() )
{
@@ -476,13 +482,34 @@ const SharedConnection& OApplicationController::ensureConnection()
String sConnectingContext( ModuleRes( STR_COULDNOTCONNECT_DATASOURCE ) );
sConnectingContext.SearchAndReplaceAscii("$name$", getStrippedDatabaseName());
- m_xDataSourceConnection.reset( connect( getDatabaseName(), sConnectingContext, sal_True ) );
+ m_xDataSourceConnection.reset( connect( getDatabaseName(), sConnectingContext, _pErrorInfo ) );
if ( m_xDataSourceConnection.is() )
- m_xMetaData = m_xDataSourceConnection->getMetaData();
-
- // otherwise we got a loop when connecting to db throws an error
-// if ( !m_xDataSourceConnection.is() )
-// getContainer()->clearSelection();
+ {
+ SQLExceptionInfo aError;
+ try
+ {
+ m_xMetaData = m_xDataSourceConnection->getMetaData();
+ }
+ catch( const SQLException& )
+ {
+ aError = ::cppu::getCaughtException();
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+ if ( aError.isValid() )
+ {
+ if ( _pErrorInfo )
+ {
+ *_pErrorInfo = aError;
+ }
+ else
+ {
+ showError( aError );
+ }
+ }
+ }
}
return m_xDataSourceConnection;
}
@@ -502,8 +529,9 @@ sal_Bool OApplicationController::isConnectionReadOnly() const
{
bIsConnectionReadOnly = m_xMetaData->isReadOnly();
}
- catch(SQLException&)
+ catch(const SQLException&)
{
+ DBG_UNHANDLED_EXCEPTION();
}
}
// TODO check configuration
@@ -562,7 +590,7 @@ Reference< XNameAccess > OApplicationController::getElements( ElementType _eType
void OApplicationController::getSelectionElementNames(::std::vector< ::rtl::OUString>& _rNames) const
{
::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
- ::osl::MutexGuard aGuard(m_aMutex);
+ ::osl::MutexGuard aGuard( getMutex() );
OSL_ENSURE(getContainer(),"View isn't valid! -> GPF");
@@ -595,7 +623,7 @@ TransferableHelper* OApplicationController::copyObject()
try
{
::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
- ::osl::MutexGuard aGuard(m_aMutex);
+ ::osl::MutexGuard aGuard( getMutex() );
ElementType eType = getContainer()->getElementType();
TransferableHelper* pData = NULL;
@@ -634,7 +662,7 @@ TransferableHelper* OApplicationController::copyObject()
if ( xElements.is() && !aList.empty() )
{
Reference< XContent> xContent(xElements->getByHierarchicalName(*aList.begin()),UNO_QUERY);
- pData = new OComponentTransferable(m_sDatabaseName,xContent);
+ pData = new OComponentTransferable( getDatabaseName(), xContent );
}
}
break;
@@ -714,7 +742,8 @@ sal_Bool OApplicationController::paste( ElementType _eType,const ::svx::ODataAcc
try
{
// the concrete query
- Reference<XQueryDefinitionsSupplier> xSourceQuerySup(getDataSourceByName_displayError( sDataSourceName, getView(), getORB(), true ),UNO_QUERY);
+ Reference< XDataSource > xDataSource( getDataSourceByName( sDataSourceName, getView(), getORB(), NULL ) );
+ Reference< XQueryDefinitionsSupplier > xSourceQuerySup( xDataSource, UNO_QUERY );
if ( xSourceQuerySup.is() )
xQueries.set(xSourceQuerySup->getQueryDefinitions(),UNO_QUERY);
@@ -865,7 +894,7 @@ sal_Bool OApplicationController::isTableFormat() const
sal_Bool OApplicationController::copyTagTable(OTableCopyHelper::DropDescriptor& _rDesc, sal_Bool _bCheck)
{
// first get the dest connection
- ::osl::MutexGuard aGuard(m_aMutex);
+ ::osl::MutexGuard aGuard( getMutex() );
SharedConnection xConnection( ensureConnection() );
if ( !xConnection.is() )
@@ -878,7 +907,7 @@ IMPL_LINK( OApplicationController, OnAsyncDrop, void*, /*NOTINTERESTEDIN*/ )
{
m_nAsyncDrop = 0;
::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
- ::osl::MutexGuard aGuard(m_aMutex);
+ ::osl::MutexGuard aGuard( getMutex() );
if ( m_aAsyncDrop.nType == E_TABLE )
diff --git a/dbaccess/source/ui/app/AppControllerGen.cxx b/dbaccess/source/ui/app/AppControllerGen.cxx
index 59c5bcf8334b..2570822ca6e2 100644
--- a/dbaccess/source/ui/app/AppControllerGen.cxx
+++ b/dbaccess/source/ui/app/AppControllerGen.cxx
@@ -40,6 +40,7 @@
#include "defaultobjectnamecheck.hxx"
#include "dlgsave.hxx"
#include "UITools.hxx"
+#include "subcomponentmanager.hxx"
/** === begin UNO includes === **/
#include <com/sun/star/container/XChild.hpp>
@@ -216,7 +217,7 @@ void OApplicationController::openDialog( const ::rtl::OUString& _sServiceName )
try
{
::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
- ::osl::MutexGuard aGuard(m_aMutex);
+ ::osl::MutexGuard aGuard( getMutex() );
WaitObject aWO(getView());
Sequence< Any > aArgs(3);
@@ -306,7 +307,7 @@ void OApplicationController::openDirectSQLDialog()
void SAL_CALL OApplicationController::propertyChange( const PropertyChangeEvent& evt ) throw (RuntimeException)
{
::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
- ::osl::MutexGuard aGuard(m_aMutex);
+ ::osl::MutexGuard aGuard( getMutex() );
if ( evt.PropertyName == PROPERTY_USER )
{
m_bNeedToReconnect = sal_True;
@@ -347,7 +348,7 @@ void SAL_CALL OApplicationController::propertyChange( const PropertyChangeEvent&
// -----------------------------------------------------------------------------
Reference< XDataSource > SAL_CALL OApplicationController::getDataSource() throw (RuntimeException)
{
- ::osl::MutexGuard aGuard(m_aMutex);
+ ::osl::MutexGuard aGuard( getMutex() );
Reference< XDataSource > xDataSource( m_xDataSource, UNO_QUERY );
return xDataSource;
}
@@ -355,7 +356,7 @@ Reference< XDataSource > SAL_CALL OApplicationController::getDataSource() throw
// -----------------------------------------------------------------------------
Reference< XWindow > SAL_CALL OApplicationController::getApplicationMainWindow() throw (RuntimeException)
{
- ::osl::MutexGuard aGuard(m_aMutex);
+ ::osl::MutexGuard aGuard( getMutex() );
Reference< XFrame > xFrame( getFrame(), UNO_QUERY_THROW );
Reference< XWindow > xWindow( xFrame->getContainerWindow(), UNO_QUERY_THROW );
return xWindow;
@@ -364,134 +365,47 @@ Reference< XWindow > SAL_CALL OApplicationController::getApplicationMainWindow()
// -----------------------------------------------------------------------------
Sequence< Reference< XComponent > > SAL_CALL OApplicationController::getSubComponents() throw (RuntimeException)
{
- ::osl::MutexGuard aGuard(m_aMutex);
- Sequence< Reference< XComponent > > aComponents( m_aDocuments.size() );
- ::std::transform( m_aDocuments.begin(), m_aDocuments.end(), aComponents.getArray(), ::std::select1st< TDocuments::value_type >() );
- return aComponents;
+ return m_pSubComponentManager->getSubComponents();
}
// -----------------------------------------------------------------------------
Reference< XConnection > SAL_CALL OApplicationController::getActiveConnection() throw (RuntimeException)
{
- ::osl::MutexGuard aGuard(m_aMutex);
+ ::osl::MutexGuard aGuard( getMutex() );
return m_xDataSourceConnection.getTyped();
}
// -----------------------------------------------------------------------------
::sal_Bool SAL_CALL OApplicationController::isConnected( ) throw (RuntimeException)
{
- ::osl::MutexGuard aGuard(m_aMutex);
+ ::osl::MutexGuard aGuard( getMutex() );
return m_xDataSourceConnection.is();
}
// -----------------------------------------------------------------------------
-::sal_Bool SAL_CALL OApplicationController::connect( ) throw (RuntimeException)
+void SAL_CALL OApplicationController::connect( ) throw (SQLException, RuntimeException)
{
- ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
- ::osl::MutexGuard aGuard(m_aMutex);
-
- ensureConnection();
- return isConnected();
-}
-
-// -----------------------------------------------------------------------------
-namespace
-{
- static Reference< XController > lcl_getController( const OApplicationController::TDocuments::iterator& _docPos )
+ SQLExceptionInfo aError;
+ SharedConnection xConnection = ensureConnection( &aError );
+ if ( !xConnection.is() )
{
- Reference< XController > xController;
+ if ( aError.isValid() )
+ aError.doThrow();
- Reference< XComponent > xComponent( _docPos->first );
- Reference< XModel > xModel( xComponent, UNO_QUERY );
- if ( xModel.is() )
- xController = xModel->getCurrentController();
- else
- {
- xController.set( xComponent, UNO_QUERY );
- if ( !xController.is() )
- {
- Reference<XFrame> xFrame( xComponent, UNO_QUERY );
- if ( xFrame.is() )
- xController = xFrame->getController();
- }
- }
- return xController;
+ // no particular error, but nonetheless could not connect -> throw a generic exception
+ String sConnectingContext( ModuleRes( STR_COULDNOTCONNECT_DATASOURCE ) );
+ sConnectingContext.SearchAndReplaceAscii( "$name$", getStrippedDatabaseName() );
+ ::dbtools::throwGenericSQLException( sConnectingContext, *this );
}
}
// -----------------------------------------------------------------------------
::sal_Bool SAL_CALL OApplicationController::closeSubComponents( ) throw (RuntimeException)
{
- ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
- ::osl::MutexGuard aGuard( m_aMutex );
-
- try
- {
- typedef ::std::vector< Reference< XComponent > > ComponentArray;
- ComponentArray aClosedComponents;
-
- TDocuments aDocuments( m_aDocuments );
- for ( TDocuments::iterator doc = aDocuments.begin();
- doc != aDocuments.end();
- ++doc
- )
- {
- Reference< XController > xController( lcl_getController( doc ) );
- OSL_ENSURE( xController.is(), "OApplicationController::closeSubComponents: did not find the sub controller!" );
-
- // suspend the controller in the document
- if ( !xController.is()
- || !xController->suspend( sal_True )
- )
- // break complete operation, no sense in continueing
- break;
-
- // revoke event listener
- Reference< XComponent > xDocument = doc->first;
- if ( xDocument.is() )
- xDocument->removeEventListener( static_cast< XFrameActionListener* >( this ) );
-
- bool bClosedSubDoc = false;
- try
- {
- Reference< XCloseable > xCloseable( xController->getFrame(), UNO_QUERY_THROW );
- xCloseable->close( sal_True );
- bClosedSubDoc = true;
- }
- catch( const Exception& )
- {
- DBG_UNHANDLED_EXCEPTION();
- }
-
- if ( !bClosedSubDoc )
- // no sense in continueing with the other docs
- break;
-
- aClosedComponents.push_back( doc->first );
- }
-
- // now remove all the components which we could successfully close
- // (this might be none, or all, or something inbetween) from m_aDocuments
- for ( ComponentArray::const_iterator comp = aClosedComponents.begin();
- comp != aClosedComponents.end();
- ++comp
- )
- {
- TDocuments::iterator pos = m_aDocuments.find( *comp );
- OSL_ENSURE( pos != m_aDocuments.end(),
- "OApplicationController::closeSubComponents: closed a component which doesn't exist anymore!" );
- if ( pos !=m_aDocuments.end() )
- m_aDocuments.erase( pos );
- }
- }
- catch ( const Exception& )
- {
- DBG_UNHANDLED_EXCEPTION();
- }
-
- return m_aDocuments.empty();
+ return m_pSubComponentManager->closeSubComponents();
}
+
// -----------------------------------------------------------------------------
namespace
{
@@ -569,7 +483,7 @@ Reference< XComponent > SAL_CALL OApplicationController::loadComponentWithArgume
const ::rtl::OUString& _ObjectName, ::sal_Bool _ForEditing, const Sequence< PropertyValue >& _Arguments ) throw (IllegalArgumentException, NoSuchElementException, SQLException, RuntimeException)
{
::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
- ::osl::MutexGuard aGuard( m_aMutex );
+ ::osl::MutexGuard aGuard( getMutex() );
impl_validateObjectTypeAndName_throw( _ObjectType, _ObjectName );
@@ -601,7 +515,7 @@ void SAL_CALL OApplicationController::releaseContextMenuInterceptor( const Refer
void OApplicationController::previewChanged( sal_Int32 _nMode )
{
::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
- ::osl::MutexGuard aGuard(m_aMutex);
+ ::osl::MutexGuard aGuard( getMutex() );
if ( m_xDataSource.is() && !isDataSourceReadOnly() )
{
@@ -645,7 +559,7 @@ void OApplicationController::askToReconnect()
{
m_bNeedToReconnect = sal_False;
sal_Bool bClear = sal_True;
- if ( !m_aDocuments.empty() )
+ if ( !m_pSubComponentManager->empty() )
{
QueryBox aQry(getView(), ModuleRes(APP_CLOSEDOCUMENTS));
switch (aQry.Execute())
@@ -671,28 +585,53 @@ void OApplicationController::askToReconnect()
}
// -----------------------------------------------------------------------------
+::rtl::OUString OApplicationController::getDatabaseName() const
+{
+ ::rtl::OUString sDatabaseName;
+ try
+ {
+ if ( m_xDataSource.is() )
+ {
+ OSL_VERIFY( m_xDataSource->getPropertyValue( PROPERTY_NAME ) >>= sDatabaseName );
+ }
+ }
+ catch ( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+ return sDatabaseName;
+}
+
+// -----------------------------------------------------------------------------
::rtl::OUString OApplicationController::getStrippedDatabaseName() const
{
- return ::dbaui::getStrippedDatabaseName(m_xDataSource,m_sDatabaseName);
+ ::rtl::OUString sDatabaseName;
+ return ::dbaui::getStrippedDatabaseName( m_xDataSource, sDatabaseName );
}
// -----------------------------------------------------------------------------
-void OApplicationController::addDocumentListener(const Reference< XComponent >& _xDocument,const Reference< XComponent >& _xDefintion)
+void OApplicationController::onDocumentOpened( const ::rtl::OUString& _rName, const sal_Int32 _nType,
+ const ElementOpenMode _eMode, const Reference< XComponent >& _xDocument, const Reference< XComponent >& _rxDefinition )
{
- if ( _xDocument.is() )
+ OSL_PRECOND( _xDocument.is(), "OApplicationController::onDocumentOpened: illegal document!" );
+ if ( !_xDocument.is() )
+ return;
+
+ try
{
- try
- {
- m_aDocuments[_xDocument] = _xDefintion;
- _xDocument->addEventListener(static_cast<XFrameActionListener*>(this));
- Reference<XPropertySet> xProp(_xDefintion,UNO_QUERY_THROW);
- if ( xProp->getPropertySetInfo()->hasPropertyByName(PROPERTY_NAME) )
- xProp->addPropertyChangeListener(PROPERTY_NAME,static_cast<XPropertyChangeListener*>(this));
- }
- catch(Exception&)
+ m_pSubComponentManager->onSubComponentOpened( _rName, _nType, _eMode, _xDocument );
+
+ if ( _rxDefinition.is() )
{
+ Reference< XPropertySet > xProp( _rxDefinition, UNO_QUERY_THROW );
+ Reference< XPropertySetInfo > xPSI( xProp->getPropertySetInfo(), UNO_SET_THROW );
+ xProp->addPropertyChangeListener( PROPERTY_NAME, static_cast< XPropertyChangeListener* >( this ) );
}
}
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
}
// -----------------------------------------------------------------------------
sal_Bool OApplicationController::insertHierachyElement(ElementType _eType,const String& _sParentFolder,sal_Bool _bCollection,const Reference<XContent>& _xContent,sal_Bool _bMove)
diff --git a/dbaccess/source/ui/app/AppDetailPageHelper.cxx b/dbaccess/source/ui/app/AppDetailPageHelper.cxx
index 2f0bd0b55877..f4c7a4eca31d 100644
--- a/dbaccess/source/ui/app/AppDetailPageHelper.cxx
+++ b/dbaccess/source/ui/app/AppDetailPageHelper.cxx
@@ -351,10 +351,10 @@ OAppDetailPageHelper::~OAppDetailPageHelper()
{
if ( m_pLists[i] )
{
- m_pLists[i]->clearCurrentSelectionEntry();
+ m_pLists[i]->clearCurrentSelection();
m_pLists[i]->Hide();
::std::auto_ptr<DBTreeListBox> aTemp(m_pLists[i]);
- m_pLists[i]->clearCurrentSelectionEntry();
+ m_pLists[i]->clearCurrentSelection(); // why a second time?
m_pLists[i] = NULL;
}
@@ -379,9 +379,7 @@ void OAppDetailPageHelper::selectAll()
int nPos = getVisibleControlIndex();
if ( nPos < E_ELEMENT_TYPE_COUNT )
{
- m_pLists[nPos]->lockAutoSelect();
m_pLists[nPos]->SelectAll(TRUE);
- m_pLists[nPos]->unlockAutoSelect();
}
}
// -----------------------------------------------------------------------------
@@ -907,8 +905,7 @@ DBTreeListBox* OAppDetailPageHelper::createTree( DBTreeListBox* _pTreeView, cons
_pTreeView->SetDoubleClickHdl(LINK(this, OAppDetailPageHelper, OnEntryDoubleClick));
_pTreeView->SetEnterKeyHdl(LINK(this, OAppDetailPageHelper, OnEntryDoubleClick));
- _pTreeView->SetSelectHdl(LINK(this, OAppDetailPageHelper, OnEntrySelectHdl));
- _pTreeView->SetDeselectHdl(LINK(this, OAppDetailPageHelper, OnDeSelectHdl));
+ _pTreeView->SetSelChangeHdl(LINK(this, OAppDetailPageHelper, OnEntrySelChange));
_pTreeView->setCutHandler(LINK(this, OAppDetailPageHelper, OnCutEntry));
_pTreeView->setCopyHandler(LINK(this, OAppDetailPageHelper, OnCopyEntry));
@@ -1066,48 +1063,33 @@ IMPL_LINK(OAppDetailPageHelper, OnEntryDoubleClick, SvTreeListBox*, _pTree)
return bHandled ? 1L : 0L;
}
// -----------------------------------------------------------------------------
-IMPL_LINK(OAppDetailPageHelper, OnDeSelectHdl, SvTreeListBox*, _pTree)
+IMPL_LINK(OAppDetailPageHelper, OnEntrySelChange, void*, /*NOINTERESTEDIN*/)
{
- OSL_ENSURE( _pTree, "OAppDetailPageHelper, OnDeSelectHdl: invalid callback!" );
- if ( _pTree != NULL )
- getBorderWin().getView()->getAppController().onEntryDeSelect( *_pTree );
+ getBorderWin().getView()->getAppController().onSelectionChanged();
return 1L;
}
// -----------------------------------------------------------------------------
-IMPL_LINK(OAppDetailPageHelper, OnEntrySelectHdl, SvLBoxEntry*, _pEntry)
+IMPL_LINK( OAppDetailPageHelper, OnCutEntry, void*, /*NOINTERESTEDIN*/ )
{
- if ( 1 == getSelectionCount() )
- {
- getBorderWin().getView()->getAppController().onEntrySelect(_pEntry);
- }
- else
- {
- showPreview(NULL);
- }
+ getBorderWin().getView()->getAppController().onCutEntry();
return 1L;
}
// -----------------------------------------------------------------------------
-IMPL_LINK( OAppDetailPageHelper, OnCutEntry, SvLBoxEntry*, _pEntry )
+IMPL_LINK( OAppDetailPageHelper, OnCopyEntry, void*, /*NOINTERESTEDIN*/ )
{
- getBorderWin().getView()->getAppController().onCutEntry(_pEntry);
+ getBorderWin().getView()->getAppController().onCopyEntry();
return 1L;
}
// -----------------------------------------------------------------------------
-IMPL_LINK( OAppDetailPageHelper, OnCopyEntry, SvLBoxEntry*, _pEntry )
+IMPL_LINK( OAppDetailPageHelper, OnPasteEntry, void*, /*NOINTERESTEDIN*/ )
{
- getBorderWin().getView()->getAppController().onCopyEntry(_pEntry);
+ getBorderWin().getView()->getAppController().onPasteEntry();
return 1L;
}
// -----------------------------------------------------------------------------
-IMPL_LINK( OAppDetailPageHelper, OnPasteEntry, SvLBoxEntry*, _pEntry )
+IMPL_LINK( OAppDetailPageHelper, OnDeleteEntry, void*, /*NOINTERESTEDIN*/ )
{
- getBorderWin().getView()->getAppController().onPasteEntry(_pEntry);
- return 1L;
-}
-// -----------------------------------------------------------------------------
-IMPL_LINK( OAppDetailPageHelper, OnDeleteEntry, SvLBoxEntry*, _pEntry )
-{
- getBorderWin().getView()->getAppController().onDeleteEntry(_pEntry);
+ getBorderWin().getView()->getAppController().onDeleteEntry();
return 1L;
}
// -----------------------------------------------------------------------------
@@ -1182,16 +1164,12 @@ void OAppDetailPageHelper::switchPreview(PreviewMode _eMode,BOOL _bForce)
m_aTBPreview.SetItemText(SID_DB_APP_DISABLE_PREVIEW, m_aMenu->GetItemText(nSelectedAction));
Resize();
+ // simulate a selectionChanged event at the controller, to force the preview to be updated
if ( isPreviewEnabled() )
{
- DBTreeListBox* pTree = getCurrentView();
- if ( pTree )
+ if ( getCurrentView() && getCurrentView()->FirstSelected() )
{
- SvLBoxEntry* pEntry = pTree->GetSelectedEntry();
- if ( pEntry )
- {
- getBorderWin().getView()->getAppController().onEntrySelect(pEntry);
- }
+ getBorderWin().getView()->getAppController().onSelectionChanged();
}
}
else
@@ -1255,9 +1233,12 @@ void OAppDetailPageHelper::showPreview(const Reference< XContent >& _xContent)
{
m_aPreview.Hide();
m_aDocumentInfo.Hide();
- DBTreeListBox* pTreeView = getCurrentView();
- if ( pTreeView )
- pTreeView->clearCurrentSelectionEntry();
+
+ // Why the below code? It might have side effects, as the tree view needs to know
+ // its current selection for other purposes than the preview, too.
+// DBTreeListBox* pTreeView = getCurrentView();
+// if ( pTreeView )
+// pTreeView->clearCurrentSelection();
}
}
catch( const Exception& )
diff --git a/dbaccess/source/ui/app/AppDetailPageHelper.hxx b/dbaccess/source/ui/app/AppDetailPageHelper.hxx
index 51f094bbbe25..2481c8744913 100644
--- a/dbaccess/source/ui/app/AppDetailPageHelper.hxx
+++ b/dbaccess/source/ui/app/AppDetailPageHelper.hxx
@@ -196,14 +196,12 @@ namespace dbaui
DBTreeListBox* createSimpleTree( ULONG _nHelpId, const Image& _rImage, const Image& _rImageHC );
DECL_LINK( OnEntryDoubleClick, SvTreeListBox* );
- DECL_LINK( OnDeSelectHdl, SvTreeListBox* );
+ DECL_LINK( OnEntrySelChange, void* );
- DECL_LINK( OnEntrySelectHdl, SvLBoxEntry* );
-
- DECL_LINK( OnCutEntry, SvLBoxEntry* );
- DECL_LINK( OnCopyEntry, SvLBoxEntry* );
- DECL_LINK( OnPasteEntry, SvLBoxEntry* );
- DECL_LINK( OnDeleteEntry, SvLBoxEntry* );
+ DECL_LINK( OnCutEntry, void* );
+ DECL_LINK( OnCopyEntry, void* );
+ DECL_LINK( OnPasteEntry, void* );
+ DECL_LINK( OnDeleteEntry, void* );
DECL_LINK(PreviewChangeHdl, void*);
// click a TB slot
diff --git a/dbaccess/source/ui/app/IApplicationController.hxx b/dbaccess/source/ui/app/IApplicationController.hxx
index 89ff2381e9dd..321eb3aafd75 100644
--- a/dbaccess/source/ui/app/IApplicationController.hxx
+++ b/dbaccess/source/ui/app/IApplicationController.hxx
@@ -71,37 +71,23 @@ namespace dbaui
@param _pEntry
the selected entry
*/
- virtual void onEntrySelect(SvLBoxEntry* _pEntry) = 0;
+ virtual void onSelectionChanged() = 0;
- /** called when an entry in a tree view has been de-selected
- @param _pTree
- The tree list box.
- */
- virtual void onEntryDeSelect(SvTreeListBox& _rTree) = 0;
-
- /** called when a "Cut" command is executed for a tree view entry
- @param _pEntry
- The entry which was cutted.
+ /** called when a "Cut" command is executed in a tree view
*/
- virtual void onCutEntry(SvLBoxEntry* _pEntry) = 0;
+ virtual void onCutEntry() = 0;
- /** called when a "Copy" command is executed for a tree view entry
- @param _pEntry
- The entry which was cutted.
+ /** called when a "Copy" command is executed in a tree view
*/
- virtual void onCopyEntry(SvLBoxEntry* _pEntry) = 0;
+ virtual void onCopyEntry() = 0;
- /** called when a "Paste" command is executed for a tree view entry
- @param _pEntry
- The entry which was cutted.
+ /** called when a "Paste" command is executed in a tree view
*/
- virtual void onPasteEntry(SvLBoxEntry* _pEntry) = 0;
+ virtual void onPasteEntry() = 0;
- /** called when a "Delete" command is executed for a tree view entry
- @param _pEntry
- The entry which was cutted.
+ /** called when a "Delete" command is executed in a tree view
*/
- virtual void onDeleteEntry(SvLBoxEntry* _pEntry) = 0;
+ virtual void onDeleteEntry() = 0;
/// called when the preview mode was changed
virtual void previewChanged( sal_Int32 _nMode ) = 0;
diff --git a/dbaccess/source/ui/app/makefile.mk b/dbaccess/source/ui/app/makefile.mk
index bef4e64f6426..b132816a3981 100644
--- a/dbaccess/source/ui/app/makefile.mk
+++ b/dbaccess/source/ui/app/makefile.mk
@@ -8,7 +8,7 @@
#
# $RCSfile: makefile.mk,v $
#
-# $Revision: 1.5 $
+# $Revision: 1.5.80.1 $
#
# This file is part of OpenOffice.org.
#
@@ -51,7 +51,8 @@ EXCEPTIONSFILES=\
$(SLO)$/AppDetailPageHelper.obj \
$(SLO)$/AppSwapWindow.obj \
$(SLO)$/AppTitleWindow.obj \
- $(SLO)$/AppView.obj
+ $(SLO)$/AppView.obj \
+ $(SLO)$/subcomponentmanager.obj
SLOFILES =\
diff --git a/dbaccess/source/ui/app/subcomponentmanager.cxx b/dbaccess/source/ui/app/subcomponentmanager.cxx
new file mode 100644
index 000000000000..c3ce4923b9c2
--- /dev/null
+++ b/dbaccess/source/ui/app/subcomponentmanager.cxx
@@ -0,0 +1,432 @@
+/*************************************************************************
+* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+*
+* Copyright 2008 by Sun Microsystems, Inc.
+*
+* OpenOffice.org - a multi-platform office productivity suite
+*
+* $RCSfile: subcomponentmanager.cxx,v $
+*
+* $Revision: 1.1.2.2 $
+*
+* This file is part of OpenOffice.org.
+*
+* OpenOffice.org is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License version 3
+* only, as published by the Free Software Foundation.
+*
+* OpenOffice.org is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Lesser General Public License version 3 for more details
+* (a copy is included in the LICENSE file that accompanied this code).
+*
+* You should have received a copy of the GNU Lesser General Public License
+* version 3 along with OpenOffice.org. If not, see
+* <http://www.openoffice.org/license.html>
+* for a copy of the LGPLv3 License.
+************************************************************************/
+
+#include "subcomponentmanager.hxx"
+
+/** === begin UNO includes === **/
+#include <com/sun/star/frame/XFrame.hpp>
+#include <com/sun/star/frame/XModel.hpp>
+#include <com/sun/star/frame/XModel2.hpp>
+#include <com/sun/star/util/XCloseable.hpp>
+#include <com/sun/star/awt/XTopWindow.hpp>
+/** === end UNO includes === **/
+
+#include <tools/diagnose_ex.h>
+#include <vcl/svapp.hxx>
+#include <vos/mutex.hxx>
+
+#include <hash_map>
+#include <algorithm>
+#include <functional>
+
+//........................................................................
+namespace dbaui
+{
+//........................................................................
+
+ /** === begin UNO using === **/
+ using ::com::sun::star::uno::Reference;
+ using ::com::sun::star::uno::XInterface;
+ using ::com::sun::star::uno::UNO_QUERY;
+ using ::com::sun::star::uno::UNO_QUERY_THROW;
+ using ::com::sun::star::uno::UNO_SET_THROW;
+ using ::com::sun::star::uno::Exception;
+ using ::com::sun::star::uno::RuntimeException;
+ using ::com::sun::star::uno::Any;
+ using ::com::sun::star::uno::makeAny;
+ using ::com::sun::star::uno::Sequence;
+ using ::com::sun::star::uno::Type;
+ using ::com::sun::star::frame::XFrame;
+ using ::com::sun::star::frame::XController;
+ using ::com::sun::star::frame::XModel;
+ using ::com::sun::star::lang::EventObject;
+ using ::com::sun::star::lang::XComponent;
+ using ::com::sun::star::frame::XModel2;
+ using ::com::sun::star::container::XEnumeration;
+ using ::com::sun::star::util::XCloseable;
+ using ::com::sun::star::awt::XTopWindow;
+ /** === end UNO using === **/
+
+ //==============================================================================
+ //= helper structs
+ //==============================================================================
+ namespace
+ {
+ struct SubComponentDescriptor
+ {
+ /// the frame which the component resides in. Must not be <NULL/>
+ Reference< XFrame > xFrame;
+ /// the controller of the sub component. Must not be <NULL/>
+ Reference< XController > xController;
+ /// the model of the sub component. Might be <NULL/>
+ Reference< XModel > xModel;
+
+ SubComponentDescriptor()
+ :xFrame()
+ ,xController()
+ ,xModel()
+ {
+ }
+
+ SubComponentDescriptor( const Reference< XComponent >& _rxComponent )
+ {
+ xModel.set( _rxComponent, UNO_QUERY );
+
+ if ( xModel.is() )
+ xController.set( xModel->getCurrentController(), UNO_SET_THROW );
+ else
+ xController.set( _rxComponent, UNO_QUERY );
+
+ if ( xController.is() )
+ xFrame.set( xController->getFrame(), UNO_SET_THROW );
+ else
+ xFrame.set( _rxComponent, UNO_QUERY_THROW );
+
+ // if the given component was a frame, then ensure we have a controller
+ if ( xFrame.is() && !xController.is() )
+ xController.set( xFrame->getController(), UNO_SET_THROW );
+
+ // if the component was a frame or a controller, then check wether there is a model (not required)
+ if ( !xModel.is() )
+ xModel.set( xController->getModel() );
+ }
+ };
+
+ struct SelectSubComponent : public ::std::unary_function< SubComponentDescriptor, Reference< XComponent > >
+ {
+ Reference< XComponent > operator()( const SubComponentDescriptor _desc ) const
+ {
+ if ( _desc.xModel.is() )
+ return _desc.xModel.get();
+ OSL_ENSURE( _desc.xController.is(), "SelectSubComponent::operator(): illegal component!" );
+ return _desc.xController.get();
+ }
+ };
+
+ struct SubComponentAccessor
+ {
+ /// the name of the sub component
+ ::rtl::OUString sName;
+ /// type of the component - usually an ElementType value
+ sal_Int32 nComponentType;
+ /// the mode in which the sub component has been opened
+ ElementOpenMode eOpenMode;
+
+ SubComponentAccessor()
+ :sName()
+ ,nComponentType( sal_Int32( E_NONE ) )
+ ,eOpenMode( E_OPEN_NORMAL )
+ {
+ }
+
+ SubComponentAccessor( const ::rtl::OUString& _rName, const sal_Int32 _nCompType, const ElementOpenMode _eMode )
+ :sName( _rName )
+ ,nComponentType( _nCompType )
+ ,eOpenMode( _eMode )
+ {
+ }
+ };
+
+ struct SubComponentAccessorHash : public ::std::unary_function< SubComponentAccessor, size_t >
+ {
+ size_t operator()( const SubComponentAccessor& _lhs ) const
+ {
+ return _lhs.sName.hashCode() + _lhs.nComponentType + size_t( _lhs.eOpenMode );
+ }
+ };
+ struct SubComponentAccessorEqual : public ::std::binary_function< SubComponentAccessor, SubComponentAccessor, bool >
+ {
+ bool operator()( const SubComponentAccessor& _lhs, const SubComponentAccessor& _rhs ) const
+ {
+ return ( _lhs.sName == _rhs.sName )
+ && ( _lhs.nComponentType == _rhs.nComponentType )
+ && ( _lhs.eOpenMode == _rhs.eOpenMode );
+ }
+ };
+
+ typedef ::std::hash_map< SubComponentAccessor, SubComponentDescriptor, SubComponentAccessorHash, SubComponentAccessorEqual >
+ SubComponentMap;
+
+ }
+
+ //==============================================================================
+ //= SubComponentManager_Data
+ //==============================================================================
+ struct SubComponentManager_Data
+ {
+ SubComponentManager_Data( const ::comphelper::SharedMutex& _rMutex )
+ :m_aMutex( _rMutex )
+ {
+ }
+
+ mutable ::comphelper::SharedMutex m_aMutex;
+ SubComponentMap m_aComponents;
+
+ ::osl::Mutex& getMutex() const { return m_aMutex; }
+ };
+
+ //====================================================================
+ //= SubComponentManager
+ //====================================================================
+ //--------------------------------------------------------------------
+ SubComponentManager::SubComponentManager( const ::comphelper::SharedMutex& _rMutex )
+ :m_pData( new SubComponentManager_Data( _rMutex ) )
+ {
+ }
+
+ //--------------------------------------------------------------------
+ SubComponentManager::~SubComponentManager()
+ {
+ }
+
+ //--------------------------------------------------------------------
+ void SubComponentManager::disposing()
+ {
+ ::osl::MutexGuard aGuard( m_pData->getMutex() );
+ m_pData->m_aComponents.clear();
+ }
+
+ //--------------------------------------------------------------------
+ namespace
+ {
+ bool lcl_fallbackToAnotherController( SubComponentDescriptor& _rCompDesc )
+ {
+ Reference< XController > xFallback;
+ OSL_PRECOND( _rCompDesc.xModel.is(), "lcl_fallbackToAnotherController: illegal call!" );
+ if ( !_rCompDesc.xModel.is() )
+ return false;
+
+ xFallback.set( _rCompDesc.xModel->getCurrentController() );
+ if ( xFallback == _rCompDesc.xController )
+ // don't accept the very same controller as fallback
+ xFallback.clear();
+
+ if ( !xFallback.is() )
+ {
+ // perhaps XModel2 can be of help here
+ Reference< XModel2 > xModel2( _rCompDesc.xModel, UNO_QUERY );
+ Reference< XEnumeration > xControllerEnum;
+ if ( xModel2.is() )
+ xControllerEnum = xModel2->getControllers();
+ while ( xControllerEnum.is() && xControllerEnum->hasMoreElements() )
+ {
+ xFallback.set( xControllerEnum->nextElement(), UNO_QUERY );
+ if ( xFallback == _rCompDesc.xController )
+ xFallback.clear();
+ }
+ }
+
+ if ( xFallback.is() )
+ {
+ _rCompDesc.xController = xFallback;
+ _rCompDesc.xFrame.set( xFallback->getFrame(), UNO_SET_THROW );
+ return true;
+ }
+
+ return false;
+ }
+
+ //----------------------------------------------------------------
+ bool lcl_closeComponent( const SubComponentDescriptor& _rComponent )
+ {
+ Reference< XController > xController( _rComponent.xController );
+ OSL_ENSURE( xController.is(), "lcl_closeComponent: invalid controller!" );
+
+ // suspend the controller in the document
+ if ( xController.is() )
+ if ( !xController->suspend( sal_True ) )
+ return false;
+
+ bool bSuccess = false;
+ try
+ {
+ Reference< XCloseable > xCloseable( _rComponent.xFrame, UNO_QUERY_THROW );
+ xCloseable->close( sal_True );
+ bSuccess = true;
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+ return bSuccess;
+ }
+ }
+
+ //--------------------------------------------------------------------
+ void SAL_CALL SubComponentManager::disposing( const EventObject& _rSource ) throw (RuntimeException)
+ {
+ ::osl::MutexGuard aGuard( m_pData->getMutex() );
+
+ for ( SubComponentMap::iterator comp = m_pData->m_aComponents.begin();
+ comp != m_pData->m_aComponents.end();
+ ++comp
+ )
+ {
+ bool bRemove = false;
+
+ if ( comp->second.xController == _rSource.Source )
+ {
+ if ( !comp->second.xModel.is() )
+ {
+ bRemove = true;
+ }
+ else
+ {
+ // maybe this is just one view to the sub document, and only this view is closed
+ if ( !lcl_fallbackToAnotherController( comp->second ) )
+ {
+ bRemove = true;
+ }
+ }
+ }
+ else if ( comp->second.xModel == _rSource.Source )
+ {
+ bRemove = true;
+ }
+
+ if ( bRemove )
+ {
+ m_pData->m_aComponents.erase( comp );
+ break;
+ }
+ }
+ }
+
+ //--------------------------------------------------------------------
+ Sequence< Reference< XComponent> > SubComponentManager::getSubComponents() const
+ {
+ ::osl::MutexGuard aGuard( m_pData->getMutex() );
+
+ Sequence< Reference< XComponent > > aComponents( m_pData->m_aComponents.size() );
+ ::std::transform(
+ m_pData->m_aComponents.begin(),
+ m_pData->m_aComponents.end(),
+ aComponents.getArray(),
+ ::std::compose1( SelectSubComponent(), ::std::select2nd< SubComponentMap::value_type >() )
+ );
+ return aComponents;
+ }
+
+ // -----------------------------------------------------------------------------
+ sal_Bool SubComponentManager::closeSubComponents()
+ {
+ ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
+ ::osl::MutexGuard aGuard( m_pData->getMutex() );
+
+ try
+ {
+ typedef ::std::vector< SubComponentAccessor > ComponentAccessors;
+ ComponentAccessors aClosedComponents;
+
+ SubComponentMap aComponents( m_pData->m_aComponents );
+ for ( SubComponentMap::const_iterator comp = aComponents.begin();
+ comp != aComponents.end();
+ ++comp
+ )
+ {
+ lcl_closeComponent( comp->second );
+ }
+ }
+ catch ( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+
+ return empty();
+ }
+
+ // -----------------------------------------------------------------------------
+ bool SubComponentManager::empty() const
+ {
+ ::osl::MutexGuard aGuard( m_pData->getMutex() );
+ return m_pData->m_aComponents.empty();
+ }
+
+ // -----------------------------------------------------------------------------
+ void SubComponentManager::onSubComponentOpened( const ::rtl::OUString& _rName, const sal_Int32 _nComponentType,
+ const ElementOpenMode _eOpenMode, const Reference< XComponent >& _rxComponent )
+ {
+ ::osl::MutexGuard aGuard( m_pData->getMutex() );
+
+ // put into map
+ SubComponentAccessor aKey( _rName, _nComponentType, _eOpenMode );
+ SubComponentDescriptor aElement( _rxComponent );
+
+ m_pData->m_aComponents.insert( SubComponentMap::value_type(
+ aKey, aElement
+ ) ) ;
+
+ // add as listener
+ aElement.xController->addEventListener( this );
+ if ( aElement.xModel.is() )
+ aElement.xModel->addEventListener( this );
+ }
+
+ // -----------------------------------------------------------------------------
+ bool SubComponentManager::activateSubFrame( const ::rtl::OUString& _rName, const sal_Int32 _nComponentType, const ElementOpenMode _eOpenMode ) const
+ {
+ ::osl::MutexGuard aGuard( m_pData->getMutex() );
+
+ SubComponentAccessor aKey( _rName, _nComponentType, _eOpenMode );
+ SubComponentMap::const_iterator pos = m_pData->m_aComponents.find( aKey );
+ if ( pos == m_pData->m_aComponents.end() )
+ // no component with this name/type/open mode
+ return false;
+
+ const Reference< XFrame > xFrame( pos->second.xFrame, UNO_SET_THROW );
+ const Reference< XTopWindow > xTopWindow( xFrame->getContainerWindow(), UNO_QUERY_THROW );
+ xTopWindow->toFront();
+
+ return true;
+ }
+
+ // -----------------------------------------------------------------------------
+ bool SubComponentManager::closeSubFrames( const ::rtl::OUString& _rName, const sal_Int32 _nComponentType )
+ {
+ ::osl::MutexGuard aGuard( m_pData->getMutex() );
+
+ SubComponentMap aWorkingCopy( m_pData->m_aComponents );
+ for ( SubComponentMap::const_iterator comp = aWorkingCopy.begin();
+ comp != aWorkingCopy.end();
+ ++comp
+ )
+ {
+ if ( ( comp->first.sName != _rName ) || ( comp->first.nComponentType != _nComponentType ) )
+ continue;
+
+ if ( !lcl_closeComponent( comp->second ) )
+ return false;
+ }
+
+ return true;
+ }
+
+//........................................................................
+} // namespace dbaui
+//........................................................................
diff --git a/dbaccess/source/ui/app/subcomponentmanager.hxx b/dbaccess/source/ui/app/subcomponentmanager.hxx
new file mode 100644
index 000000000000..e2f882052d28
--- /dev/null
+++ b/dbaccess/source/ui/app/subcomponentmanager.hxx
@@ -0,0 +1,115 @@
+/*************************************************************************
+* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+*
+* Copyright 2008 by Sun Microsystems, Inc.
+*
+* OpenOffice.org - a multi-platform office productivity suite
+*
+* $RCSfile: subcomponentmanager.hxx,v $
+*
+* $Revision: 1.1.2.2 $
+*
+* This file is part of OpenOffice.org.
+*
+* OpenOffice.org is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License version 3
+* only, as published by the Free Software Foundation.
+*
+* OpenOffice.org is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Lesser General Public License version 3 for more details
+* (a copy is included in the LICENSE file that accompanied this code).
+*
+* You should have received a copy of the GNU Lesser General Public License
+* version 3 along with OpenOffice.org. If not, see
+* <http://www.openoffice.org/license.html>
+* for a copy of the LGPLv3 License.
+************************************************************************/
+
+#ifndef DBACCESS_SUBCOMPONENTMANAGER_HXX
+#define DBACCESS_SUBCOMPONENTMANAGER_HXX
+
+#include "AppElementType.hxx"
+
+/** === begin UNO includes === **/
+#include <com/sun/star/lang/XEventListener.hpp>
+#include <com/sun/star/frame/XController.hpp>
+/** === end UNO includes === **/
+
+#include <comphelper/sharedmutex.hxx>
+#include <cppuhelper/implbase1.hxx>
+
+#include <memory>
+
+//........................................................................
+namespace dbaui
+{
+//........................................................................
+
+ struct SubComponentManager_Data;
+ //====================================================================
+ //= SubComponentManager
+ //====================================================================
+ typedef ::cppu::WeakImplHelper1 < ::com::sun::star::lang::XEventListener
+ > SubComponentManager_Base;
+ class SubComponentManager : public SubComponentManager_Base
+ {
+ public:
+ SubComponentManager( const ::comphelper::SharedMutex& _rMutex );
+ virtual ~SubComponentManager();
+
+ void disposing();
+
+ // XEventListener
+ virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
+
+ // XDatabaseDocumentUI helpers
+ ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent> >
+ getSubComponents() const;
+ sal_Bool closeSubComponents();
+
+ // container access
+ void onSubComponentOpened(
+ const ::rtl::OUString& _rName,
+ const sal_Int32 _nComponentType,
+ const ElementOpenMode _eOpenMode,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >&
+ _rxComponent
+ );
+ bool empty() const;
+
+ /** activates (i.e. brings to top) the frame in which the given component is loaded, if any
+
+ @return
+ <TRUE/> if any only of such a frame was found, i.e. the component had already been loaded
+ previously
+ */
+ bool activateSubFrame(
+ const ::rtl::OUString& _rName,
+ const sal_Int32 _nComponentType,
+ const ElementOpenMode _eOpenMode
+ ) const;
+
+ /** closes all frames of the given component
+
+ If a view for the component (given by name and type) has been loaded into one or more
+ frames (with potentially different OpenModes), then those frames are gracefully closed.
+
+ @return
+ <TRUE/> if and only if closing those frames was successful, or frames for the given sub component
+ exist.
+ */
+ bool closeSubFrames(
+ const ::rtl::OUString& _rName,
+ const sal_Int32 _nComponentType
+ );
+ private:
+ ::std::auto_ptr< SubComponentManager_Data > m_pData;
+ };
+
+//........................................................................
+} // namespace dbaui
+//........................................................................
+
+#endif // DBACCESS_SUBCOMPONENTMANAGER_HXX
diff --git a/dbaccess/source/ui/browser/brwctrlr.cxx b/dbaccess/source/ui/browser/brwctrlr.cxx
index 6352df1c8e4d..6443b06201c7 100644
--- a/dbaccess/source/ui/browser/brwctrlr.cxx
+++ b/dbaccess/source/ui/browser/brwctrlr.cxx
@@ -945,14 +945,14 @@ void SbaXDataBrowserController::disposing(const EventObject& Source) throw( Runt
// -----------------------------------------------------------------------
void SAL_CALL SbaXDataBrowserController::setIdentifier( const ::rtl::OUString& _Identifier ) throw (RuntimeException)
{
- ::osl::MutexGuard aGuard( m_aMutex );
+ ::osl::MutexGuard aGuard( getMutex() );
m_sModuleIdentifier = _Identifier;
}
// -----------------------------------------------------------------------
::rtl::OUString SAL_CALL SbaXDataBrowserController::getIdentifier( ) throw (RuntimeException)
{
- ::osl::MutexGuard aGuard( m_aMutex );
+ ::osl::MutexGuard aGuard( getMutex() );
return m_sModuleIdentifier;
}
@@ -1219,7 +1219,7 @@ void SbaXDataBrowserController::disposing()
//------------------------------------------------------------------------------
void SbaXDataBrowserController::frameAction(const ::com::sun::star::frame::FrameActionEvent& aEvent) throw( RuntimeException )
{
- ::osl::MutexGuard aGuard( m_aMutex );
+ ::osl::MutexGuard aGuard( getMutex() );
SbaXDataBrowserController_Base::frameAction( aEvent );
diff --git a/dbaccess/source/ui/browser/dbloader.cxx b/dbaccess/source/ui/browser/dbloader.cxx
index fddf41331548..87f924129c16 100644
--- a/dbaccess/source/ui/browser/dbloader.cxx
+++ b/dbaccess/source/ui/browser/dbloader.cxx
@@ -288,7 +288,9 @@ void SAL_CALL DBContentLoader::load(const Reference< XFrame > & rFrame, const ::
}
else if ( sDataSourceName.getLength() )
{
- xDatabaseDocument.set( getDataSourceOrModel( getDataSourceByName_displayError( sDataSourceName, NULL, m_xServiceFactory, sal_False ) ), UNO_QUERY );
+ ::dbtools::SQLExceptionInfo aError;
+ xDataSource.set( getDataSourceByName( sDataSourceName, NULL, m_xServiceFactory, &aError ) );
+ xDatabaseDocument.set( getDataSourceOrModel( xDataSource ), UNO_QUERY );
}
else if ( xConnection.is() )
{
diff --git a/dbaccess/source/ui/browser/dbtreeview.cxx b/dbaccess/source/ui/browser/dbtreeview.cxx
index 93d53335bc59..2f7f745460e3 100644
--- a/dbaccess/source/ui/browser/dbtreeview.cxx
+++ b/dbaccess/source/ui/browser/dbtreeview.cxx
@@ -114,9 +114,9 @@ void DBTreeView::setModel(SvLBoxTreeList* _pTreeModel)
}
// -------------------------------------------------------------------------
-void DBTreeView::setSelectHdl(const Link& _rHdl)
+void DBTreeView::setSelChangeHdl( const Link& _rHdl )
{
- m_pTreeListBox->SetSelectHdl(_rHdl);
+ m_pTreeListBox->SetSelChangeHdl( _rHdl );
}
// -----------------------------------------------------------------------------
void DBTreeView::GetFocus()
diff --git a/dbaccess/source/ui/browser/dbtreeview.hxx b/dbaccess/source/ui/browser/dbtreeview.hxx
index 5a53f6ffab71..534d51542495 100644
--- a/dbaccess/source/ui/browser/dbtreeview.hxx
+++ b/dbaccess/source/ui/browser/dbtreeview.hxx
@@ -73,7 +73,7 @@ namespace dbaui
void setModel(SvLBoxTreeList* _pTreeModel);
- void setSelectHdl(const Link& _rHdl);
+ void setSelChangeHdl(const Link& _rHdl);
DBTreeListBox& getListBox() const { return *m_pTreeListBox; }
diff --git a/dbaccess/source/ui/browser/dsbrowserDnD.cxx b/dbaccess/source/ui/browser/dsbrowserDnD.cxx
index 9dc6e028bfd2..e528427ac008 100644
--- a/dbaccess/source/ui/browser/dsbrowserDnD.cxx
+++ b/dbaccess/source/ui/browser/dsbrowserDnD.cxx
@@ -82,8 +82,6 @@ namespace dbaui
{
try
{
- ::osl::MutexGuard aGuard(m_aEntryMutex);
-
::rtl::OUString aName = GetEntryText( _pApplyTo );
::rtl::OUString aDSName = getDataSourceAcessor( m_pTreeView->getListBox().GetRootLevelParent( _pApplyTo ) );
@@ -218,10 +216,11 @@ namespace dbaui
return NULL != pTransfer;
}
// -----------------------------------------------------------------------------
- IMPL_LINK(SbaTableQueryBrowser, OnCopyEntry, SvLBoxEntry*, _pEntry)
+ IMPL_LINK(SbaTableQueryBrowser, OnCopyEntry, void*, /*NOTINTERESIN*/)
{
- if( isEntryCopyAllowed(_pEntry) )
- copyEntry(_pEntry);
+ SvLBoxEntry* pSelected = m_pTreeView->getListBox().FirstSelected();
+ if( isEntryCopyAllowed( pSelected ) )
+ copyEntry( pSelected );
return 0;
}
// -----------------------------------------------------------------------------
@@ -246,8 +245,7 @@ namespace dbaui
{
m_nAsyncDrop = 0;
::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
- ::osl::MutexGuard aGuard(m_aMutex);
-
+ ::osl::MutexGuard aGuard( getMutex() );
if ( m_aAsyncDrop.nType == E_TABLE )
{
diff --git a/dbaccess/source/ui/browser/genericcontroller.cxx b/dbaccess/source/ui/browser/genericcontroller.cxx
index 108a8b258b6e..a24c2d4e30dc 100644
--- a/dbaccess/source/ui/browser/genericcontroller.cxx
+++ b/dbaccess/source/ui/browser/genericcontroller.cxx
@@ -250,7 +250,7 @@ struct OGenericUnoController_Data
DBG_NAME(OGenericUnoController)
// -------------------------------------------------------------------------
OGenericUnoController::OGenericUnoController(const Reference< XMultiServiceFactory >& _rM)
- :OGenericUnoController_Base(m_aMutex)
+ :OGenericUnoController_Base( getMutex() )
#ifdef DBG_UTIL
,m_bDescribingSupportedFeatures( false )
#endif
@@ -266,7 +266,7 @@ OGenericUnoController::OGenericUnoController(const Reference< XMultiServiceFacto
{
osl_incrementInterlockedCount( &m_refCount );
{
- m_pData.reset( new OGenericUnoController_Data( *this, m_aMutex ) );
+ m_pData.reset( new OGenericUnoController_Data( *this, getMutex() ) );
}
osl_decrementInterlockedCount( &m_refCount );
@@ -284,7 +284,7 @@ OGenericUnoController::OGenericUnoController(const Reference< XMultiServiceFacto
// -----------------------------------------------------------------------------
OGenericUnoController::OGenericUnoController()
- :OGenericUnoController_Base(m_aMutex)
+ :OGenericUnoController_Base( getMutex() )
#ifdef DBG_UTIL
,m_bDescribingSupportedFeatures( false )
#endif
@@ -356,7 +356,7 @@ void OGenericUnoController::impl_initialize()
void SAL_CALL OGenericUnoController::initialize( const Sequence< Any >& aArguments ) throw(Exception, RuntimeException)
{
vos::OGuard aSolarGuard( Application::GetSolarMutex() );
- ::osl::MutexGuard aGuard(m_aMutex);
+ ::osl::MutexGuard aGuard( getMutex() );
Reference< XWindow > xParent;
Reference< XFrame > xFrame;
@@ -453,7 +453,7 @@ void OGenericUnoController::disposing(const EventObject& Source) throw( RuntimeE
//------------------------------------------------------------------------
void OGenericUnoController::modified(const EventObject& aEvent) throw( RuntimeException )
{
- ::osl::MutexGuard aGuard(m_aMutex);
+ ::osl::MutexGuard aGuard( getMutex() );
if ( !isDataSourceReadOnly() )
{
Reference<XModifiable> xModi(aEvent.Source,UNO_QUERY);
@@ -481,7 +481,7 @@ Reference< XWindow > SAL_CALL OGenericUnoController::getComponentWindow() throw
void OGenericUnoController::attachFrame( const Reference< XFrame >& _rxFrame ) throw( RuntimeException )
{
vos::OGuard aSolarGuard( Application::GetSolarMutex() );
- ::osl::MutexGuard aGuard(m_aMutex);
+ ::osl::MutexGuard aGuard( getMutex() );
stopFrameListening( m_aCurrentFrame.getFrame() );
Reference< XFrame > xFrame = m_aCurrentFrame.attachFrame( _rxFrame );
@@ -965,7 +965,7 @@ void SAL_CALL OGenericUnoController::removeEventListener( const Reference< XEven
//------------------------------------------------------------------------------
void OGenericUnoController::frameAction(const FrameActionEvent& aEvent) throw( RuntimeException )
{
- ::osl::MutexGuard aGuard( m_aMutex );
+ ::osl::MutexGuard aGuard( getMutex() );
if ( aEvent.Frame == m_aCurrentFrame.getFrame() )
m_aCurrentFrame.frameAction( aEvent.Action );
}
@@ -1101,35 +1101,26 @@ void OGenericUnoController::stopConnectionListening(const Reference< XConnection
xComponent->removeEventListener(static_cast<XFrameActionListener*>(this));
}
// -----------------------------------------------------------------------------
-Reference< XConnection > OGenericUnoController::connect(
- const Reference< XDataSource>& _xDataSource
- ,sal_Bool _bStartListening
- )
+Reference< XConnection > OGenericUnoController::connect( const Reference< XDataSource>& _xDataSource,
+ ::dbtools::SQLExceptionInfo* _pErrorInfo )
{
- WaitObject aWaitCursor(getView());
+ WaitObject aWaitCursor( getView() );
ODatasourceConnector aConnector( getORB(), getView(), ::rtl::OUString() );
- Reference<XConnection> xConnection = aConnector.connect(_xDataSource);
-
- // be notified when connection is in disposing
- if (_bStartListening)
- startConnectionListening(xConnection);
+ Reference< XConnection > xConnection = aConnector.connect( _xDataSource, _pErrorInfo );
+ startConnectionListening( xConnection );
return xConnection;
}
// -----------------------------------------------------------------------------
-Reference< XConnection > OGenericUnoController::connect(
- const ::rtl::OUString& _rDataSourceName, const ::rtl::OUString& _rContextInformation,
- sal_Bool _bStartListening )
+Reference< XConnection > OGenericUnoController::connect( const ::rtl::OUString& _rDataSourceName,
+ const ::rtl::OUString& _rContextInformation, ::dbtools::SQLExceptionInfo* _pErrorInfo )
{
- WaitObject aWaitCursor(getView());
+ WaitObject aWaitCursor( getView() );
ODatasourceConnector aConnector( getORB(), getView(), _rContextInformation );
- Reference<XConnection> xConnection = aConnector.connect(_rDataSourceName);
-
- // be notified when connection is in disposing
- if (_bStartListening)
- startConnectionListening(xConnection);
+ Reference<XConnection> xConnection = aConnector.connect( _rDataSourceName, _pErrorInfo );
+ startConnectionListening( xConnection );
return xConnection;
}
@@ -1219,7 +1210,7 @@ Reference< XModel > SAL_CALL OGenericUnoController::getModel(void) throw( Runtim
// -----------------------------------------------------------------------------
Reference< XFrame > SAL_CALL OGenericUnoController::getFrame(void) throw( RuntimeException )
{
- ::osl::MutexGuard aGuard( m_aMutex );
+ ::osl::MutexGuard aGuard( getMutex() );
return m_aCurrentFrame.getFrame();
}
@@ -1442,7 +1433,7 @@ Reference< awt::XWindow> OGenericUnoController::getTopMostContainerWindow() cons
Reference< XTitle > OGenericUnoController::impl_getTitleHelper_throw()
{
::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
- ::osl::MutexGuard aGuard(m_aMutex);
+ ::osl::MutexGuard aGuard( getMutex() );
if ( ! m_xTitleHelper.is ())
{
@@ -1464,7 +1455,7 @@ Reference< XTitle > OGenericUnoController::impl_getTitleHelper_throw()
::rtl::OUString SAL_CALL OGenericUnoController::getTitle()
throw (RuntimeException)
{
- ::osl::MutexGuard aGuard(m_aMutex);
+ ::osl::MutexGuard aGuard( getMutex() );
if ( m_bExternalTitle )
return impl_getTitleHelper_throw()->getTitle ();
return getPrivateTitle() + impl_getTitleHelper_throw()->getTitle ();
@@ -1476,7 +1467,7 @@ void SAL_CALL OGenericUnoController::setTitle(const ::rtl::OUString& sTitle)
throw (RuntimeException)
{
vos::OGuard aSolarGuard( Application::GetSolarMutex() );
- ::osl::MutexGuard aGuard(m_aMutex);
+ ::osl::MutexGuard aGuard( getMutex() );
m_bExternalTitle = sal_True;
impl_getTitleHelper_throw()->setTitle (sTitle);
}
diff --git a/dbaccess/source/ui/browser/unodatbr.cxx b/dbaccess/source/ui/browser/unodatbr.cxx
index 8e2f1cbce337..86dc62eda2de 100644
--- a/dbaccess/source/ui/browser/unodatbr.cxx
+++ b/dbaccess/source/ui/browser/unodatbr.cxx
@@ -82,6 +82,7 @@
#include <com/sun/star/sdb/XResultSetAccess.hpp>
#include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
#include <com/sun/star/sdb/application/NamedDatabaseObject.hpp>
+#include <com/sun/star/sdbc/ColumnValue.hpp>
#include <com/sun/star/sdbc/DataType.hpp>
#include <com/sun/star/sdbc/FetchDirection.hpp>
#include <com/sun/star/sdbc/SQLWarning.hpp>
@@ -223,8 +224,8 @@ DBG_NAME(SbaTableQueryBrowser);
//------------------------------------------------------------------------------
SbaTableQueryBrowser::SbaTableQueryBrowser(const Reference< XMultiServiceFactory >& _rM)
:SbaXDataBrowserController(_rM)
- ,m_aSelectionListeners(m_aMutex)
- ,m_aContextMenuInterceptors(m_aMutex)
+ ,m_aSelectionListeners( getMutex() )
+ ,m_aContextMenuInterceptors( getMutex() )
,m_aTableCopyHelper(this)
,m_pTreeView(NULL)
,m_pSplitter(NULL)
@@ -402,7 +403,7 @@ sal_Bool SbaTableQueryBrowser::Construct(Window* pParent)
m_pTreeModel->SetSortMode(SortAscending);
m_pTreeModel->SetCompareHdl(LINK(this, SbaTableQueryBrowser, OnTreeEntryCompare));
m_pTreeView->setModel(m_pTreeModel);
- m_pTreeView->setSelectHdl(LINK(this, SbaTableQueryBrowser, OnSelectEntry));
+ m_pTreeView->setSelChangeHdl( LINK( this, SbaTableQueryBrowser, OnSelectionChange ) );
// TODO
getBrowserView()->getVclControl()->GetDataWindow().SetUniqueId(UID_DATABROWSE_DATAWINDOW);
@@ -600,10 +601,19 @@ sal_Bool SbaTableQueryBrowser::InitializeGridModel(const Reference< ::com::sun::
{
case DataType::BIT:
case DataType::BOOLEAN:
+ {
aCurrentModelType = ::rtl::OUString::createFromAscii("CheckBox");
aInitialValues.push_back( NamedValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "VisualEffect" ) ), makeAny( VisualEffect::FLAT ) ) );
sDefaultProperty = PROPERTY_DEFAULTSTATE;
- break;
+
+ sal_Int32 nNullable = ColumnValue::NULLABLE_UNKNOWN;
+ OSL_VERIFY( xColumn->getPropertyValue( PROPERTY_ISNULLABLE ) >>= nNullable );
+ aInitialValues.push_back( NamedValue(
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "TriState" ) ),
+ makeAny( sal_Bool( ColumnValue::NO_NULLS != nNullable ) )
+ ) );
+ }
+ break;
case DataType::LONGVARCHAR:
aInitialValues.push_back( NamedValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MultiLine" ) ), makeAny( (sal_Bool)sal_True ) ) );
@@ -835,7 +845,7 @@ void SbaTableQueryBrowser::propertyChange(const PropertyChangeEvent& evt) throw(
sal_Bool SbaTableQueryBrowser::suspend(sal_Bool bSuspend) throw( RuntimeException )
{
vos::OGuard aSolarGuard( Application::GetSolarMutex() );
- ::osl::MutexGuard aGuard(m_aMutex);
+ ::osl::MutexGuard aGuard( getMutex() );
if ( getView() && getView()->IsInModalMode() )
return sal_False;
sal_Bool bRet = sal_False;
@@ -1773,8 +1783,10 @@ void SbaTableQueryBrowser::Execute(sal_uInt16 nId, const Sequence< PropertyValue
unloadAndCleanup( sal_False );
// reselect the entry
- if(pSelected)
- OnSelectEntry( pSelected );
+ if ( pSelected )
+ {
+ implSelect( pSelected );
+ }
else
{
Reference<XPropertySet> xProp(getRowSet(),UNO_QUERY);
@@ -2022,8 +2034,6 @@ IMPL_LINK(SbaTableQueryBrowser, OnExpandEntry, SvLBoxEntry*, _pParent)
// nothing to to ...
return 1L;
- ::osl::MutexGuard aGuard(m_aEntryMutex);
-
SvLBoxEntry* pFirstParent = m_pTreeView->getListBox().GetRootLevelParent(_pParent);
OSL_ENSURE(pFirstParent,"SbaTableQueryBrowser::OnExpandEntry: No rootlevelparent!");
@@ -2289,7 +2299,7 @@ sal_Bool SbaTableQueryBrowser::implSelect(const ::rtl::OUString& _rDataSourceNam
{
if ( _bSelectDirect )
{
- OnSelectEntry(pCommand);
+ implSelect( pCommand );
}
else
m_pTreeView->getListBox().Select(pCommand);
@@ -2314,11 +2324,18 @@ sal_Bool SbaTableQueryBrowser::implSelect(const ::rtl::OUString& _rDataSourceNam
}
//------------------------------------------------------------------------------
-IMPL_LINK(SbaTableQueryBrowser, OnSelectEntry, SvLBoxEntry*, _pEntry)
+IMPL_LINK(SbaTableQueryBrowser, OnSelectionChange, void*, /*NOINTERESTEDIN*/)
{
- ::osl::MutexGuard aGuard(m_aEntryMutex);
+ return implSelect( m_pTreeView->getListBox().FirstSelected() ) ? 1L : 0L;
+}
- DBTreeListUserData* pEntryData = static_cast<DBTreeListUserData*>(_pEntry->GetUserData());
+//------------------------------------------------------------------------------
+bool SbaTableQueryBrowser::implSelect( SvLBoxEntry* _pEntry )
+{
+ if ( !_pEntry )
+ return false;
+
+ DBTreeListUserData* pEntryData = static_cast< DBTreeListUserData* >( _pEntry->GetUserData() );
switch (pEntryData->eType)
{
case etTableOrView:
@@ -2326,11 +2343,11 @@ IMPL_LINK(SbaTableQueryBrowser, OnSelectEntry, SvLBoxEntry*, _pEntry)
break;
default:
// nothing to do
- return 0L;
+ return false;
}
- OSL_ENSURE(m_pTreeModel->HasParent(_pEntry), "SbaTableQueryBrowser::OnSelectEntry: invalid entry (1)!");
- OSL_ENSURE(m_pTreeModel->HasParent(m_pTreeModel->GetParent(_pEntry)), "SbaTableQueryBrowser::OnSelectEntry: invalid entry (2)!");
+ OSL_ENSURE(m_pTreeModel->HasParent(_pEntry), "SbaTableQueryBrowser::implSelect: invalid entry (1)!");
+ OSL_ENSURE(m_pTreeModel->HasParent(m_pTreeModel->GetParent(_pEntry)), "SbaTableQueryBrowser::implSelect: invalid entry (2)!");
// get the entry for the tables or queries
SvLBoxEntry* pContainer = m_pTreeModel->GetParent(_pEntry);
@@ -2490,7 +2507,7 @@ IMPL_LINK(SbaTableQueryBrowser, OnSelectEntry, SvLBoxEntry*, _pEntry)
if(e.TargetException >>= aSql)
showError(SQLExceptionInfo(aSql));
else
- OSL_ENSURE(sal_False, "SbaTableQueryBrowser::OnSelectEntry: something strange happended!");
+ OSL_ENSURE(sal_False, "SbaTableQueryBrowser::implSelect: something strange happended!");
// reset the values
xRowSetProps->setPropertyValue(PROPERTY_DATASOURCENAME,Any());
xRowSetProps->setPropertyValue(PROPERTY_ACTIVE_CONNECTION,Any());
@@ -2502,7 +2519,7 @@ IMPL_LINK(SbaTableQueryBrowser, OnSelectEntry, SvLBoxEntry*, _pEntry)
xRowSetProps->setPropertyValue(PROPERTY_ACTIVE_CONNECTION,Any());
}
}
- return 0L;
+ return true;
}
// -----------------------------------------------------------------------------
@@ -2533,7 +2550,6 @@ SvLBoxEntry* SbaTableQueryBrowser::getEntryFromContainer(const Reference<XNameAc
void SAL_CALL SbaTableQueryBrowser::elementInserted( const ContainerEvent& _rEvent ) throw(RuntimeException)
{
vos::OGuard aSolarGuard( Application::GetSolarMutex() );
- ::osl::MutexGuard aGuard(m_aEntryMutex);
Reference< XNameAccess > xNames(_rEvent.Source, UNO_QUERY);
// first search for a definition container where we can insert this element
@@ -2590,8 +2606,6 @@ sal_Bool SbaTableQueryBrowser::isCurrentlyDisplayedChanged(const String& _sName,
void SAL_CALL SbaTableQueryBrowser::elementRemoved( const ContainerEvent& _rEvent ) throw(RuntimeException)
{
::vos::OGuard aSolarGuard(Application::GetSolarMutex());
- ::osl::MutexGuard aGuard(m_aEntryMutex);
-
Reference< XNameAccess > xNames(_rEvent.Source, UNO_QUERY);
// get the top-level representing the removed data source
@@ -2700,7 +2714,7 @@ void SAL_CALL SbaTableQueryBrowser::elementRemoved( const ContainerEvent& _rEven
// -------------------------------------------------------------------------
void SAL_CALL SbaTableQueryBrowser::elementReplaced( const ContainerEvent& _rEvent ) throw(RuntimeException)
{
- ::osl::MutexGuard aGuard(m_aEntryMutex);
+ ::vos::OGuard aSolarGuard(Application::GetSolarMutex());
Reference< XNameAccess > xNames(_rEvent.Source, UNO_QUERY);
SvLBoxEntry* pContainer = getEntryFromContainer(xNames);
@@ -3218,7 +3232,7 @@ sal_Bool SbaTableQueryBrowser::ensureConnection( SvLBoxEntry* _pDSEntry, void* p
// connect
_rConnection.reset(
- connect( getDataSourceAcessor( _pDSEntry ), sConnectingContext, sal_True ),
+ connect( getDataSourceAcessor( _pDSEntry ), sConnectingContext, NULL ),
SharedConnection::TakeOwnership
);
@@ -3318,8 +3332,8 @@ void SbaTableQueryBrowser::implAdministrate( SvLBoxEntry* _pApplyTo )
if (pTopLevelSelected)
sInitialSelection = getDataSourceAcessor( pTopLevelSelected );
- Reference< XModel > xDocumentModel(
- getDataSourceOrModel(getDataSourceByName_displayError( sInitialSelection, getView(), getORB(), true )),UNO_QUERY);
+ Reference< XDataSource > xDataSource( getDataSourceByName( sInitialSelection, getView(), getORB(), NULL ) );
+ Reference< XModel > xDocumentModel( getDataSourceOrModel( xDataSource ), UNO_QUERY );
if ( xDocumentModel.is() )
{
diff --git a/dbaccess/source/ui/control/dbtreelistbox.cxx b/dbaccess/source/ui/control/dbtreelistbox.cxx
index 89b0d790909d..af2f7e0939bf 100644
--- a/dbaccess/source/ui/control/dbtreelistbox.cxx
+++ b/dbaccess/source/ui/control/dbtreelistbox.cxx
@@ -104,11 +104,9 @@ DBG_NAME(DBTreeListBox)
//------------------------------------------------------------------------
DBTreeListBox::DBTreeListBox( Window* pParent, const Reference< XMultiServiceFactory >& _rxORB, WinBits nWinStyle ,sal_Bool _bHandleEnterKey)
:SvTreeListBox(pParent,nWinStyle)
- ,m_pSelectedEntry(NULL)
,m_pDragedEntry(NULL)
,m_pActionListener(NULL)
,m_pContextMenuProvider( NULL )
- ,m_nSelectLock(0)
,m_bHandleEnterKey(_bHandleEnterKey)
,m_xORB(_rxORB)
{
@@ -118,11 +116,9 @@ DBTreeListBox::DBTreeListBox( Window* pParent, const Reference< XMultiServiceFac
// -----------------------------------------------------------------------------
DBTreeListBox::DBTreeListBox( Window* pParent, const Reference< XMultiServiceFactory >& _rxORB, const ResId& rResId,sal_Bool _bHandleEnterKey)
:SvTreeListBox(pParent,rResId)
- ,m_pSelectedEntry(NULL)
,m_pDragedEntry(NULL)
,m_pActionListener(NULL)
,m_pContextMenuProvider( NULL )
- ,m_nSelectLock(0)
,m_bHandleEnterKey(_bHandleEnterKey)
,m_xORB(_rxORB)
{
@@ -149,8 +145,7 @@ void DBTreeListBox::init()
DBTreeListBox::~DBTreeListBox()
{
DBG_DTOR(DBTreeListBox,NULL);
- if(m_aTimer.IsActive())
- m_aTimer.Stop();
+ implStopSelectionTimer();
}
//------------------------------------------------------------------------
SvLBoxEntry* DBTreeListBox::GetEntryPosByName( const String& aName, SvLBoxEntry* pStart, const IEntryFilter* _pFilter ) const
@@ -200,20 +195,6 @@ void DBTreeListBox::RequestingChilds( SvLBoxEntry* pParent )
}
// -------------------------------------------------------------------------
-void DBTreeListBox::SelectEntry(SvLBoxEntry* _pEntry)
-{
- OSL_ENSURE(_pEntry,"Who called me with NULL!");
- if ( _pEntry )
- {
- if ( GetCurEntry() )
- Select(GetCurEntry(), sal_False);
- Select(_pEntry, sal_True);
- SetCurEntry(_pEntry);
- implSelected(_pEntry);
- }
-}
-
-// -------------------------------------------------------------------------
void DBTreeListBox::InitEntry( SvLBoxEntry* _pEntry, const XubString& aStr, const Image& _rCollEntryBmp, const Image& _rExpEntryBmp, SvLBoxButtonKind eButtonKind)
{
SvTreeListBox::InitEntry( _pEntry, aStr, _rCollEntryBmp,_rExpEntryBmp, eButtonKind);
@@ -223,40 +204,33 @@ void DBTreeListBox::InitEntry( SvLBoxEntry* _pEntry, const XubString& aStr, cons
}
// -------------------------------------------------------------------------
-void DBTreeListBox::implSelected(SvLBoxEntry* _pSelected)
+void DBTreeListBox::implStopSelectionTimer()
{
- if(!m_nSelectLock && _pSelected && m_pSelectedEntry != _pSelected)
- {
- // re-start the timer
- if(m_aTimer.IsActive())
- m_aTimer.Stop();
- m_pSelectedEntry = _pSelected;
- m_aTimer.Start();
- }
+ if ( m_aTimer.IsActive() )
+ m_aTimer.Stop();
}
// -------------------------------------------------------------------------
-sal_Int32 DBTreeListBox::lockAutoSelect()
+void DBTreeListBox::implStartSelectionTimer()
{
- return ++m_nSelectLock;
+ implStopSelectionTimer();
+ m_aTimer.Start();
}
-// -------------------------------------------------------------------------
-sal_Int32 DBTreeListBox::unlockAutoSelect()
-{
- DBG_ASSERT(m_nSelectLock, "DBTreeListBox::unlockAutoSelect: not locked!");
- return --m_nSelectLock;
-}
// -----------------------------------------------------------------------------
void DBTreeListBox::DeselectHdl()
{
+ m_aSelectedEntries.erase( GetHdlEntry() );
SvTreeListBox::DeselectHdl();
+ implStartSelectionTimer();
}
// -------------------------------------------------------------------------
void DBTreeListBox::SelectHdl()
{
- implSelected(GetHdlEntry());
+ m_aSelectedEntries.insert( GetHdlEntry() );
+ SvTreeListBox::SelectHdl();
+ implStartSelectionTimer();
}
// -------------------------------------------------------------------------
@@ -281,15 +255,16 @@ IMPL_LINK(DBTreeListBox, OnResetEntry, SvLBoxEntry*, pEntry)
// -----------------------------------------------------------------------------
void DBTreeListBox::ModelHasEntryInvalidated( SvListEntry* _pEntry )
{
- SvTreeListBox::ModelHasEntryInvalidated(_pEntry);
- if ( _pEntry == m_pSelectedEntry && m_pSelectedEntry )
+ SvTreeListBox::ModelHasEntryInvalidated( _pEntry );
+
+ if ( m_aSelectedEntries.find( _pEntry ) != m_aSelectedEntries.end() )
{
- SvLBoxItem* pTextItem = m_pSelectedEntry->GetFirstItem(SV_ITEM_ID_BOLDLBSTRING);
- if ( pTextItem && !static_cast<OBoldListboxString*>(pTextItem)->isEmphasized() )
+ SvLBoxItem* pTextItem = static_cast< SvLBoxEntry* >( _pEntry )->GetFirstItem( SV_ITEM_ID_BOLDLBSTRING );
+ if ( pTextItem && !static_cast< OBoldListboxString* >( pTextItem )->isEmphasized() )
{
- if(m_aTimer.IsActive())
- m_aTimer.Stop();
- m_pSelectedEntry = NULL;
+ implStopSelectionTimer();
+ m_aSelectedEntries.erase( _pEntry );
+ // ehm - why?
}
}
}
@@ -297,11 +272,10 @@ void DBTreeListBox::ModelHasEntryInvalidated( SvListEntry* _pEntry )
void DBTreeListBox::ModelHasRemoved( SvListEntry* _pEntry )
{
SvTreeListBox::ModelHasRemoved(_pEntry);
- if (_pEntry == m_pSelectedEntry)
+ if ( m_aSelectedEntries.find( _pEntry ) != m_aSelectedEntries.end() )
{
- if(m_aTimer.IsActive())
- m_aTimer.Stop();
- m_pSelectedEntry = NULL;
+ implStopSelectionTimer();
+ m_aSelectedEntries.erase( _pEntry );
}
}
@@ -364,7 +338,7 @@ void DBTreeListBox::StartDrag( sal_Int8 _nAction, const Point& _rPosPixel )
if ( m_pDragedEntry && m_pActionListener->requestDrag( _nAction, _rPosPixel ) )
{
// if the (asynchronous) drag started, stop the selection timer
- m_aTimer.Stop();
+ implStopSelectionTimer();
// and stop selecting entries by simply moving the mouse
EndSelection();
}
@@ -414,24 +388,24 @@ void DBTreeListBox::KeyInput( const KeyEvent& rKEvt )
switch(eFunc)
{
case KEYFUNC_CUT:
- bHandled = (m_aCutHandler.IsSet() && m_pSelectedEntry);
+ bHandled = ( m_aCutHandler.IsSet() && !m_aSelectedEntries.empty() );
if ( bHandled )
- m_aCutHandler.Call(m_pSelectedEntry);
+ m_aCutHandler.Call( NULL );
break;
case KEYFUNC_COPY:
- bHandled = (m_aCopyHandler.IsSet() && m_pSelectedEntry);
+ bHandled = ( m_aCopyHandler.IsSet() && !m_aSelectedEntries.empty() );
if ( bHandled )
- m_aCopyHandler.Call(m_pSelectedEntry);
+ m_aCopyHandler.Call( NULL );
break;
case KEYFUNC_PASTE:
- bHandled = (m_aPasteHandler.IsSet() && m_pSelectedEntry);
+ bHandled = ( m_aPasteHandler.IsSet() && !m_aSelectedEntries.empty() );
if ( bHandled )
- m_aPasteHandler.Call(m_pSelectedEntry);
+ m_aPasteHandler.Call( NULL );
break;
case KEYFUNC_DELETE:
- bHandled = (m_aDeleteHandler.IsSet() && m_pSelectedEntry);
+ bHandled = ( m_aDeleteHandler.IsSet() && !m_aSelectedEntries.empty() );
if ( bHandled )
- m_aDeleteHandler.Call(m_pSelectedEntry);
+ m_aDeleteHandler.Call( NULL );
break;
default:
break;
@@ -480,9 +454,8 @@ BOOL DBTreeListBox::EditedEntry( SvLBoxEntry* pEntry, const XubString& rNewText
aEntry.aNewText =rNewText;
if(m_aEditedHandler.Call(&aEntry) != 0)
{
- if(m_aTimer.IsActive())
- m_aTimer.Stop();
- m_pSelectedEntry = NULL; // to force that the renamed selection will be reselected
+ implStopSelectionTimer();
+ m_aSelectedEntries.erase( pEntry );
}
SetEntryText(pEntry,aEntry.aNewText);
@@ -730,24 +703,23 @@ PopupMenu* DBTreeListBox::CreateContextMenu( void )
// -----------------------------------------------------------------------------
void DBTreeListBox::ExcecuteContextMenuAction( USHORT _nSelectedPopupEntry )
{
- if ( m_pContextMenuProvider )
+ if ( m_pContextMenuProvider && _nSelectedPopupEntry )
m_pContextMenuProvider->getCommandController().executeChecked( _nSelectedPopupEntry, Sequence< PropertyValue >() );
}
// -----------------------------------------------------------------------------
IMPL_LINK(DBTreeListBox, OnTimeOut, void*, /*EMPTY_ARG*/)
{
- if(m_aTimer.IsActive())
- m_aTimer.Stop();
- if (m_pSelectedEntry)
- aSelectHdl.Call( m_pSelectedEntry );
+ implStopSelectionTimer();
+
+ m_aSelChangeHdl.Call( NULL );
return 0L;
}
// -----------------------------------------------------------------------------
void DBTreeListBox::StateChanged( StateChangedType nStateChange )
{
- if ( nStateChange == STATE_CHANGE_VISIBLE && m_aTimer.IsActive() )
- m_aTimer.Stop();
+ if ( nStateChange == STATE_CHANGE_VISIBLE )
+ implStopSelectionTimer();
}
// .........................................................................
} // namespace dbaui
diff --git a/dbaccess/source/ui/dlg/dbadmin.src b/dbaccess/source/ui/dlg/dbadmin.src
index dbdb441b0c08..3ccb261bad48 100644
--- a/dbaccess/source/ui/dlg/dbadmin.src
+++ b/dbaccess/source/ui/dlg/dbadmin.src
@@ -537,13 +537,15 @@ TabPage PAGE_MYSQL_JDBC
FixedText FT_JDBCDRIVERCLASS
{
- Pos = MAP_APPFONT ( 6 , 4*UNRELATED_CONTROLS + RELATED_CONTROLS + 4*FIXEDTEXT_HEIGHT + EDIT_HEIGHT) ;
+ Pos = MAP_APPFONT ( 6,
+ 4*UNRELATED_CONTROLS + RELATED_CONTROLS + 3*FIXEDTEXT_HEIGHT + EDIT_HEIGHT) ;
Size = MAP_APPFONT ( EDIT_X - 7 , FIXEDTEXT_HEIGHT ) ;
Text[ en-US ] = "MySQL JDBC d~river class";
};
Edit ET_JDBCDRIVERCLASS
{
- Pos = MAP_APPFONT ( EDIT_X , 4*UNRELATED_CONTROLS + RELATED_CONTROLS + 3*FIXEDTEXT_HEIGHT -1 + EDIT_HEIGHT) ;
+ Pos = MAP_APPFONT ( EDIT_X,
+ 4*UNRELATED_CONTROLS + RELATED_CONTROLS + 3*FIXEDTEXT_HEIGHT -1 + EDIT_HEIGHT) ;
Size = MAP_APPFONT ( 97 , EDIT_HEIGHT ) ;
TabStop = TRUE ;
Border = TRUE ;
@@ -572,13 +574,15 @@ TabPage PAGE_ORACLE_JDBC
FixedText FT_JDBCDRIVERCLASS
{
- Pos = MAP_APPFONT ( 6 , 4*UNRELATED_CONTROLS + RELATED_CONTROLS + 4*FIXEDTEXT_HEIGHT + EDIT_HEIGHT) ;
+ Pos = MAP_APPFONT ( 6,
+ 4*UNRELATED_CONTROLS + RELATED_CONTROLS + 3*FIXEDTEXT_HEIGHT + EDIT_HEIGHT) ;
Size = MAP_APPFONT ( EDIT_X - 7 , FIXEDTEXT_HEIGHT ) ;
Text[ en-US ] = "Oracle JDBC d~river class";
};
Edit ET_JDBCDRIVERCLASS
{
- Pos = MAP_APPFONT ( EDIT_X , 4*UNRELATED_CONTROLS + RELATED_CONTROLS + 3*FIXEDTEXT_HEIGHT -1 + EDIT_HEIGHT) ;
+ Pos = MAP_APPFONT ( EDIT_X,
+ 4*UNRELATED_CONTROLS + RELATED_CONTROLS + 3*FIXEDTEXT_HEIGHT + EDIT_HEIGHT + ( FIXEDTEXT_HEIGHT - EDIT_HEIGHT ) / 2 ) ;
Size = MAP_APPFONT ( 97 , EDIT_HEIGHT ) ;
TabStop = TRUE ;
Border = TRUE ;
@@ -586,7 +590,8 @@ TabPage PAGE_ORACLE_JDBC
PushButton PB_TESTDRIVERCLASS
{
TabStop = TRUE ;
- Pos = MAP_APPFONT ( PAGE_X - BUTTON_WIDTH - UNRELATED_CONTROLS , 4*UNRELATED_CONTROLS + RELATED_CONTROLS + 3*FIXEDTEXT_HEIGHT -2 + EDIT_HEIGHT) ;
+ Pos = MAP_APPFONT ( PAGE_X - BUTTON_WIDTH - UNRELATED_CONTROLS,
+ 4*UNRELATED_CONTROLS + RELATED_CONTROLS + 3*FIXEDTEXT_HEIGHT + EDIT_HEIGHT + ( FIXEDTEXT_HEIGHT - BUTTON_HEIGHT ) / 2 ) ;
Size = MAP_APPFONT ( BUTTON_WIDTH , BUTTON_HEIGHT ) ;
Text [ en-US ] = "Test class" ;
};
diff --git a/dbaccess/source/ui/dlg/paramdialog.cxx b/dbaccess/source/ui/dlg/paramdialog.cxx
index 094b4ca727c1..9ebdb683e4a4 100644
--- a/dbaccess/source/ui/dlg/paramdialog.cxx
+++ b/dbaccess/source/ui/dlg/paramdialog.cxx
@@ -67,6 +67,7 @@
#ifndef _TOOLS_DEBUG_HXX
#include <tools/debug.hxx>
#endif
+#include <tools/diagnose_ex.h>
#ifndef _DBAUI_LOCALRESACCESS_HXX_
#include "localresaccess.hxx"
#endif
@@ -163,7 +164,7 @@ DBG_NAME(OParameterDialog)
}
catch(Exception&)
{
- DBG_ERROR("OParameterDialog::OParameterDialog : soemthing went wrong while retrieving the parameters !");
+ DBG_UNHANDLED_EXCEPTION();
}
@@ -254,6 +255,7 @@ DBG_NAME(OParameterDialog)
}
catch(Exception&)
{
+ DBG_UNHANDLED_EXCEPTION();
}
String sMessage;
@@ -314,6 +316,7 @@ DBG_NAME(OParameterDialog)
}
catch(Exception&)
{
+ DBG_UNHANDLED_EXCEPTION();
}
}
diff --git a/dbaccess/source/ui/inc/QueryDesignView.hxx b/dbaccess/source/ui/inc/QueryDesignView.hxx
index d45087709e8d..1078946a5dc5 100644
--- a/dbaccess/source/ui/inc/QueryDesignView.hxx
+++ b/dbaccess/source/ui/inc/QueryDesignView.hxx
@@ -153,7 +153,18 @@ namespace dbaui
void stopTimer();
void startTimer();
void reset();
- sal_Bool InitFromParseNode();
+
+ /** initializes the view from the current parser / parse iterator of the controller
+
+ @param _pErrorInfo
+ When not <NULL/>, the instance pointed to by this parameter takes the error
+ which happened during the initialization.
+ If it is not <NULL/>, then any such error will be displayed, using the controller's
+ showError method.
+
+ @return <TRUE/> if and only if the initialization was successful
+ */
+ bool initByParseIterator( ::dbtools::SQLExceptionInfo* _pErrorInfo );
::connectivity::OSQLParseNode* getPredicateTreeFromEntry( OTableFieldDescRef pEntry,
const String& _sCriteria,
diff --git a/dbaccess/source/ui/inc/QueryViewSwitch.hxx b/dbaccess/source/ui/inc/QueryViewSwitch.hxx
index 122dd2f24b41..c0692ba48af0 100644
--- a/dbaccess/source/ui/inc/QueryViewSwitch.hxx
+++ b/dbaccess/source/ui/inc/QueryViewSwitch.hxx
@@ -30,9 +30,12 @@
#ifndef DBAUI_QUERYVIEWSWITCH_HXX
#define DBAUI_QUERYVIEWSWITCH_HXX
-#ifndef DBAUI_QUERYVIEW_HXX
#include "queryview.hxx"
-#endif
+
+namespace dbtools
+{
+ class SQLExceptionInfo;
+}
namespace dbaui
{
@@ -70,18 +73,20 @@ namespace dbaui
virtual void initialize();
/** show the text or the design view
@return
- <TRUE/> when all went right otherwise <FALSE/> which implies an aditional
- call of switchView from the controller to restore the old state
+ <TRUE/> if and only if the view could be successfully, switched, <FALSE/> otherwise
+ (In the latter case, the controller will issue another switchView call to restore the
+ old state)
*/
- sal_Bool switchView();
+ bool switchView( ::dbtools::SQLExceptionInfo* _pErrorInfo );
sal_Bool isSlotEnabled(sal_Int32 _nSlotId);
void setSlotEnabled(sal_Int32 _nSlotId,sal_Bool _bEnable);
void setNoneVisbleRow(sal_Int32 _nRows);
+ void SaveUIConfig();
+ bool reset( ::dbtools::SQLExceptionInfo* _pErrorInfo );
+ void GrabFocus();
+
// returs the add table dialog from the design view
OAddTableDlg* getAddTableDialog();
- void SaveUIConfig();
- void reset();
- void GrabFocus();
OQueryDesignView* getDesignView() const { return m_pDesignView; }
OQueryContainerWindow* getContainer() const;
diff --git a/dbaccess/source/ui/inc/RTableConnectionData.hxx b/dbaccess/source/ui/inc/RTableConnectionData.hxx
index d5215e503734..1cb3c75540bd 100644
--- a/dbaccess/source/ui/inc/RTableConnectionData.hxx
+++ b/dbaccess/source/ui/inc/RTableConnectionData.hxx
@@ -58,7 +58,6 @@ namespace dbaui
friend bool operator!=(const ORelationTableConnectionData& lhs, const ORelationTableConnectionData& rhs) { return !(lhs == rhs); }
::osl::Mutex m_aMutex;
- ::rtl::OUString m_sDatabaseName;
// @see com.sun.star.sdbc.KeyRule
sal_Int32 m_nUpdateRules;
@@ -85,8 +84,6 @@ namespace dbaui
virtual void CopyFrom(const OTableConnectionData& rSource);
virtual OTableConnectionData* NewInstance() const { return new ORelationTableConnectionData(); }
- inline ::rtl::OUString GetDatabaseName() const { return m_sDatabaseName; }
-
/** Update create a new relation
@return true if successful
diff --git a/dbaccess/source/ui/inc/UITools.hxx b/dbaccess/source/ui/inc/UITools.hxx
index 297cdceb9b36..51722ee431cb 100644
--- a/dbaccess/source/ui/inc/UITools.hxx
+++ b/dbaccess/source/ui/inc/UITools.hxx
@@ -200,15 +200,15 @@ namespace dbaui
the window to use as parent for error messages
@param _rxORB
a service factory to use for components to be created
- @param _bDisplayError
- determines whether the method should display an error, when it happens, or simply absorb it
+ @param _pErrorInfo
+ takes the error info in case of failure. If <NULL/>, the error is displayed to the user.
*/
::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDataSource >
- getDataSourceByName_displayError(
+ getDataSourceByName(
const ::rtl::OUString& _rDataSourceName,
Window* _pErrorMessageParent,
::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > _rxORB,
- bool _bDisplayError
+ ::dbtools::SQLExceptionInfo* _pErrorInfo
);
/** returns either the model when data source is given as parameter,
diff --git a/dbaccess/source/ui/inc/WNameMatch.hxx b/dbaccess/source/ui/inc/WNameMatch.hxx
index 3b6653494ac7..c8f7daa83394 100644
--- a/dbaccess/source/ui/inc/WNameMatch.hxx
+++ b/dbaccess/source/ui/inc/WNameMatch.hxx
@@ -95,8 +95,8 @@ namespace dbaui
DECL_LINK( ButtonClickHdl, Button * );
DECL_LINK( RightButtonClickHdl, Button * );
DECL_LINK( AllNoneClickHdl, Button * );
- DECL_LINK( TableListClickHdl, SvTreeListBox* );
- DECL_LINK( TableListRightSelectHdl, SvTreeListBox* );
+ DECL_LINK( TableListClickHdl, void* );
+ DECL_LINK( TableListRightSelectHdl, void* );
public:
virtual void Reset ( );
diff --git a/dbaccess/source/ui/inc/datasourceconnector.hxx b/dbaccess/source/ui/inc/datasourceconnector.hxx
index 4a6b31dedb8b..382e59b10e7f 100644
--- a/dbaccess/source/ui/inc/datasourceconnector.hxx
+++ b/dbaccess/source/ui/inc/datasourceconnector.hxx
@@ -44,6 +44,11 @@
#include <com/sun/star/sdbc/XDataSource.hpp>
#endif
+namespace dbtools
+{
+ class SQLExceptionInfo;
+}
+
class Window;
//.........................................................................
namespace dbaui
@@ -75,14 +80,21 @@ namespace dbaui
/// returns <TRUE/> if the object is able to create data source connections
sal_Bool isValid() const { return m_xORB.is(); }
- /// create a data source connection
+ /** creates a connection to the data source, displays the possible error to the user, or returns it
+ */
::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >
- connect(const ::rtl::OUString& _rDataSourceName, sal_Bool _bShowError = sal_True) const;
+ connect(
+ const ::rtl::OUString& _rDataSourceName,
+ ::dbtools::SQLExceptionInfo* _pErrorInfo
+ ) const;
- /// create a data source connection
+ /** creates a connection to the data source, displays the possible error to the user, or returns it
+ */
::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >
- connect(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDataSource>& _xDataSource
- , sal_Bool _bShowError = sal_True) const;
+ connect(
+ const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDataSource>& _xDataSource,
+ ::dbtools::SQLExceptionInfo* _pErrorInfo
+ ) const;
};
//.........................................................................
diff --git a/dbaccess/source/ui/inc/dbtreelistbox.hxx b/dbaccess/source/ui/inc/dbtreelistbox.hxx
index b28729b29eb8..2877e2650323 100644
--- a/dbaccess/source/ui/inc/dbtreelistbox.hxx
+++ b/dbaccess/source/ui/inc/dbtreelistbox.hxx
@@ -30,21 +30,15 @@
#ifndef DBAUI_DBTREELISTBOX_HXX
#define DBAUI_DBTREELISTBOX_HXX
-#ifndef _SVTREEBOX_HXX
-#include <svtools/svtreebx.hxx>
-#endif
-#ifndef _SV_TIMER_HXX
-#include <vcl/timer.hxx>
-#endif
-#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
-#include <com/sun/star/lang/XMultiServiceFactory.hpp>
-#endif
-#ifndef DBAUI_SCROLLHELPER_HXX
#include "ScrollHelper.hxx"
-#endif
-#ifndef _DBAUI_MODULE_DBU_HXX_
#include "moduledbu.hxx"
-#endif
+
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+
+#include <svtools/svtreebx.hxx>
+#include <vcl/timer.hxx>
+
+#include <set>
namespace dbaui
@@ -70,13 +64,14 @@ namespace dbaui
OScrollHelper m_aScrollHelper;
Timer m_aTimer; // is needed for table updates
Point m_aMousePos;
- SvLBoxEntry* m_pSelectedEntry;
+ ::std::set< SvListEntry* > m_aSelectedEntries;
SvLBoxEntry* m_pDragedEntry;
IControlActionListener* m_pActionListener;
IContextMenuProvider*
m_pContextMenuProvider;
Link m_aPreExpandHandler; // handler to be called before a node is expanded
+ Link m_aSelChangeHdl; // handlet to be called (asynchronously) when the selection changes in any way
Link m_aCutHandler; // called when someone press CTRL+X
Link m_aCopyHandler; // called when someone press CTRL+C
Link m_aPasteHandler; // called when someone press CTRL+V
@@ -86,7 +81,6 @@ namespace dbaui
Link m_aEnterKeyHdl;
- sal_Int32 m_nSelectLock;
sal_Bool m_bHandleEnterKey;
protected:
@@ -116,28 +110,15 @@ namespace dbaui
inline void setORB(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _xORB) { m_xORB = _xORB; }
- void SetPreExpandHandler(const Link& _rHdl) { m_aPreExpandHandler = _rHdl; }
- Link GetPreExpandHandler() const { return m_aPreExpandHandler; }
-
- void setCutHandler(const Link& _rHdl) { m_aCutHandler = _rHdl; }
- Link getCutHandler() const { return m_aCutHandler; }
-
- void setCopyHandler(const Link& _rHdl) { m_aCopyHandler = _rHdl; }
- Link getCopyHandler() const { return m_aCopyHandler; }
-
- void setPasteHandler(const Link& _rHdl) { m_aPasteHandler = _rHdl; }
- Link getPasteHandler() const { return m_aPasteHandler; }
+ void SetPreExpandHandler(const Link& _rHdl) { m_aPreExpandHandler = _rHdl; }
+ void SetSelChangeHdl( const Link& _rHdl ) { m_aSelChangeHdl = _rHdl; }
+ void setCutHandler(const Link& _rHdl) { m_aCutHandler = _rHdl; }
+ void setCopyHandler(const Link& _rHdl) { m_aCopyHandler = _rHdl; }
+ void setPasteHandler(const Link& _rHdl) { m_aPasteHandler = _rHdl; }
+ void setDeleteHandler(const Link& _rHdl) { m_aDeleteHandler = _rHdl; }
+ void setEditingHandler(const Link& _rHdl) { m_aEditingHandler = _rHdl; }
+ void setEditedHandler(const Link& _rHdl) { m_aEditedHandler = _rHdl; }
- void setDeleteHandler(const Link& _rHdl) { m_aDeleteHandler = _rHdl; }
- Link getDeleteHandler() const { return m_aDeleteHandler; }
-
- void setEditingHandler(const Link& _rHdl){ m_aEditingHandler = _rHdl; }
- Link getEditingHandler() const { return m_aEditingHandler; }
-
- void setEditedHandler(const Link& _rHdl) { m_aEditedHandler = _rHdl; }
- Link getEditedHandler() const { return m_aEditedHandler; }
-
- inline SvLBoxEntry* GetSelectedEntry() const { return m_pSelectedEntry; }
// modified the given entry so that the expand handler is called whenever the entry is expanded
// (normally, the expand handler is called only once)
void EnableExpandHandler(SvLBoxEntry* _pEntry);
@@ -152,7 +133,6 @@ namespace dbaui
virtual void StateChanged( StateChangedType nStateChange );
virtual void InitEntry( SvLBoxEntry* pEntry, const XubString& aStr, const Image& aCollEntryBmp, const Image& aExpEntryBmp, SvLBoxButtonKind eButtonKind);
- virtual void SelectEntry(SvLBoxEntry* _pEntry);
// enable editing for tables/views and queries
virtual BOOL EditingEntry( SvLBoxEntry* pEntry, Selection& );
virtual BOOL EditedEntry( SvLBoxEntry* pEntry, const XubString& rNewText );
@@ -162,13 +142,9 @@ namespace dbaui
virtual PopupMenu* CreateContextMenu( void );
virtual void ExcecuteContextMenuAction( USHORT nSelectedPopupEntry );
- sal_Int32 lockAutoSelect();
- sal_Int32 unlockAutoSelect();
- sal_Int32 locked() const { return m_nSelectLock; }
-
void SetEnterKeyHdl(const Link& rNewHdl) {m_aEnterKeyHdl = rNewHdl;}
- inline void clearCurrentSelectionEntry() { m_pSelectedEntry = NULL; }
+ void clearCurrentSelection() { m_aSelectedEntries.clear(); }
protected:
virtual void MouseButtonDown( const MouseEvent& rMEvt );
@@ -183,7 +159,8 @@ namespace dbaui
virtual void ModelHasRemoved( SvListEntry* pEntry );
virtual void ModelHasEntryInvalidated( SvListEntry* pEntry );
- void implSelected(SvLBoxEntry* _pSelected);
+ void implStopSelectionTimer();
+ void implStartSelectionTimer();
protected:
using SvTreeListBox::ExecuteDrop;
diff --git a/dbaccess/source/ui/inc/querycontainerwindow.hxx b/dbaccess/source/ui/inc/querycontainerwindow.hxx
index 831af124969b..44af65ed2b2a 100644
--- a/dbaccess/source/ui/inc/querycontainerwindow.hxx
+++ b/dbaccess/source/ui/inc/querycontainerwindow.hxx
@@ -113,11 +113,12 @@ namespace dbaui
::rtl::OUString getStatement() { return m_pViewSwitch->getStatement( ); }
void setStatement( const ::rtl::OUString& _rsStatement ) { m_pViewSwitch->setStatement( _rsStatement ); }
- void initialize() { m_pViewSwitch->initialize(); }
- void SaveUIConfig() { m_pViewSwitch->SaveUIConfig(); }
- void reset() { m_pViewSwitch->reset(); }
+ void initialize() { m_pViewSwitch->initialize(); }
+ void SaveUIConfig() { m_pViewSwitch->SaveUIConfig(); }
+ bool reset( ::dbtools::SQLExceptionInfo* _pErrorInfo ) { return m_pViewSwitch->reset( _pErrorInfo ); }
+
+ bool switchView( ::dbtools::SQLExceptionInfo* _pErrorInfo );
- sal_Bool switchView();
virtual void GetFocus();
protected:
diff --git a/dbaccess/source/ui/inc/querycontroller.hxx b/dbaccess/source/ui/inc/querycontroller.hxx
index c3a50673a76b..b79e6ea6dfc5 100644
--- a/dbaccess/source/ui/inc/querycontroller.hxx
+++ b/dbaccess/source/ui/inc/querycontroller.hxx
@@ -196,7 +196,7 @@ namespace dbaui
static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
SAL_CALL Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&);
- protected:
+ private:
virtual void onLoadedMenu(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XLayoutManager >& _xLayoutManager);
// OPropertyArrayUsageHelper
virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const;
@@ -207,7 +207,13 @@ namespace dbaui
virtual void reset();
virtual void impl_initialize();
- void resetImpl();
+ void impl_reset();
+ /// tells the user that we needed to switch to SQL view automatically
+ void impl_showAutoSQLViewError( const ::com::sun::star::uno::Any& _rErrorDetails );
+
+ /** switches to the graphical or SQL view mode, as determined by m_bGraphicalDesign
+ */
+ bool impl_setViewMode( ::dbtools::SQLExceptionInfo* _pErrorInfo );
/// sets m_sStatement, and notifies our respective property change listeners
void setStatement_fireEvent( const ::rtl::OUString& _rNewStatement, bool _bFireStatementChange = true );
@@ -217,6 +223,7 @@ namespace dbaui
// OJoinController overridables
virtual bool allowViews() const;
virtual bool allowQueries() const;
+
private:
DECL_LINK( OnExecuteAddTable, void* );
};
diff --git a/dbaccess/source/ui/inc/unodatbr.hxx b/dbaccess/source/ui/inc/unodatbr.hxx
index 556c381bc063..9354aa943a93 100644
--- a/dbaccess/source/ui/inc/unodatbr.hxx
+++ b/dbaccess/source/ui/inc/unodatbr.hxx
@@ -132,8 +132,6 @@ namespace dbaui
::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > m_xMainToolbar;
::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > m_xCurrentDatabaseDocument;
- ::osl::Mutex m_aEntryMutex;
-
// ---------------------------
struct ExternalFeature
{
@@ -398,10 +396,10 @@ namespace dbaui
String GetEntryText( SvLBoxEntry* _pEntry ) const;
// is called when a table or a query was selected
- DECL_LINK( OnSelectEntry, SvLBoxEntry* );
+ DECL_LINK( OnSelectionChange, void* );
DECL_LINK( OnExpandEntry, SvLBoxEntry* );
- DECL_LINK( OnCopyEntry, SvLBoxEntry* );
+ DECL_LINK( OnCopyEntry, void* );
DECL_LINK( OnTreeEntryCompare, const SvSortData* );
@@ -410,6 +408,7 @@ namespace dbaui
void implRemoveStatusListeners();
sal_Bool implSelect(const ::svx::ODataAccessDescriptor& _rDescriptor,sal_Bool _bSelectDirect = sal_False);
+ bool implSelect( SvLBoxEntry* _pEntry );
/// selects the entry given and loads the grid control with the object's data
sal_Bool implSelect(
diff --git a/dbaccess/source/ui/misc/UITools.cxx b/dbaccess/source/ui/misc/UITools.cxx
index 3e026d4e5116..9f0f9bd2c85e 100644
--- a/dbaccess/source/ui/misc/UITools.cxx
+++ b/dbaccess/source/ui/misc/UITools.cxx
@@ -408,8 +408,8 @@ SQLExceptionInfo createConnection( const Reference< ::com::sun::star::beans::XP
return aInfo;
}
// -----------------------------------------------------------------------------
-Reference< XDataSource > getDataSourceByName_displayError( const ::rtl::OUString& _rDataSourceName,
- Window* _pErrorMessageParent, Reference< XMultiServiceFactory > _rxORB, bool _bDisplayError)
+Reference< XDataSource > getDataSourceByName( const ::rtl::OUString& _rDataSourceName,
+ Window* _pErrorMessageParent, Reference< XMultiServiceFactory > _rxORB, ::dbtools::SQLExceptionInfo* _pErrorInfo )
{
::comphelper::ComponentContext aContext( _rxORB );
Reference< XNameAccess > xDatabaseContext( aContext.createComponent( "com.sun.star.sdb.DatabaseContext" ), UNO_QUERY_THROW );
@@ -450,16 +450,18 @@ Reference< XDataSource > getDataSourceByName_displayError( const ::rtl::OUString
if ( xDatasource.is() )
return xDatasource;
- if ( _bDisplayError )
+ if ( aSQLError.isValid() )
{
- if ( aSQLError.isValid() )
- showError( aSQLError, _pErrorMessageParent, _rxORB );
+ if ( _pErrorInfo )
+ {
+ *_pErrorInfo = aSQLError;
+ }
else
{
- DBG_ERROR( "getDataSourceByName_displayError: not yet implemented!" );
- // by spec, we must pass this to an interaction handler ...
+ showError( aSQLError, _pErrorMessageParent, _rxORB );
}
}
+
return Reference<XDataSource>();
}
// -----------------------------------------------------------------------------
@@ -1414,14 +1416,15 @@ void fillAutoIncrementValue(const Reference<XConnection>& _xConnection,
{
_xDataSource->getPropertyValue(PROPERTY_NAME) >>= _rsDatabaseName;
}
- catch(Exception)
+ catch(const Exception& )
{
+ DBG_UNHANDLED_EXCEPTION();
}
}
::rtl::OUString sName = _rsDatabaseName;
INetURLObject aURL(sName);
if ( aURL.GetProtocol() != INET_PROT_NOT_VALID )
- sName = aURL.getBase(INetURLObject::LAST_SEGMENT,true,INetURLObject::DECODE_WITH_CHARSET);
+ sName = aURL.getBase(INetURLObject::LAST_SEGMENT,true,INetURLObject::DECODE_UNAMBIGUOUS);
return sName;
}
// -----------------------------------------------------------------------------
diff --git a/dbaccess/source/ui/misc/WNameMatch.cxx b/dbaccess/source/ui/misc/WNameMatch.cxx
index 98adbb8953c5..93feb3aa49b1 100644
--- a/dbaccess/source/ui/misc/WNameMatch.cxx
+++ b/dbaccess/source/ui/misc/WNameMatch.cxx
@@ -282,7 +282,7 @@ IMPL_LINK( OWizNameMatching, RightButtonClickHdl, Button *, pButton )
return 0;
}
//------------------------------------------------------------------------------
-IMPL_LINK( OWizNameMatching, TableListClickHdl, SvTreeListBox *, /*pListBox*/ )
+IMPL_LINK( OWizNameMatching, TableListClickHdl, void*, /*NOTINTERESTEDIN*/ )
{
SvLBoxEntry* pEntry = m_CTRL_LEFT.FirstSelected();
if(pEntry)
@@ -316,7 +316,7 @@ IMPL_LINK( OWizNameMatching, TableListClickHdl, SvTreeListBox *, /*pListBox*/ )
return 0;
}
//------------------------------------------------------------------------------
-IMPL_LINK( OWizNameMatching, TableListRightSelectHdl, SvTreeListBox *, /*pListBox*/ )
+IMPL_LINK( OWizNameMatching, TableListRightSelectHdl, void*, /*NOTINTERESTEDIN*/ )
{
SvLBoxEntry* pEntry = m_CTRL_RIGHT.FirstSelected();
if(pEntry)
diff --git a/dbaccess/source/ui/misc/databaseobjectview.cxx b/dbaccess/source/ui/misc/databaseobjectview.cxx
index 724e9f0f4285..21a247c73c9f 100644
--- a/dbaccess/source/ui/misc/databaseobjectview.cxx
+++ b/dbaccess/source/ui/misc/databaseobjectview.cxx
@@ -250,10 +250,17 @@ namespace dbaui
{
DatabaseObjectView::fillDispatchArgs( _rDispatchArguments, _aDataSource, _rObjectName );
- sal_Bool bIncludeQueryName = 0 != _rObjectName.getLength();
+ bool bIncludeQueryName = 0 != _rObjectName.getLength();
+ bool bEditViewAsSQLCommand = ( m_nCommandType == CommandType::TABLE ) && m_bPreferSQLView;
sal_Int32 nPos = _rDispatchArguments.getLength();
- _rDispatchArguments.realloc(_rDispatchArguments.getLength() + 2 + ( bIncludeQueryName ? 1 : 0 ) );
+
+ sal_Int32 nNewLen = _rDispatchArguments.getLength() + 2;
+ if ( bIncludeQueryName )
+ ++nNewLen;
+ if ( bEditViewAsSQLCommand )
+ ++nNewLen;
+ _rDispatchArguments.realloc( nNewLen );
_rDispatchArguments[nPos ].Name = PROPERTY_GRAPHICAL_DESIGN;
_rDispatchArguments[nPos++].Value <<= ::cppu::bool2any( !m_bPreferSQLView );
@@ -266,6 +273,12 @@ namespace dbaui
_rDispatchArguments[nPos ].Name = PROPERTY_COMMAND;
_rDispatchArguments[nPos++].Value <<= _rObjectName;
}
+
+ if ( bEditViewAsSQLCommand )
+ {
+ _rDispatchArguments[nPos ].Name = PROPERTY_ESCAPE_PROCESSING;
+ _rDispatchArguments[nPos++].Value <<= sal_Bool( sal_False );
+ }
}
//======================================================================
diff --git a/dbaccess/source/ui/misc/datasourceconnector.cxx b/dbaccess/source/ui/misc/datasourceconnector.cxx
index 40c073b521ac..470ab5f08ba3 100644
--- a/dbaccess/source/ui/misc/datasourceconnector.cxx
+++ b/dbaccess/source/ui/misc/datasourceconnector.cxx
@@ -91,6 +91,9 @@
#ifndef TOOLS_DIAGNOSE_EX_H
#include <tools/diagnose_ex.h>
#endif
+#ifndef _CPPUHELPER_EXC_HLP_HXX_
+#include <cppuhelper/exc_hlp.hxx>
+#endif
#ifndef _DBU_MISC_HRC_
#include "dbu_misc.hrc"
#endif
@@ -132,7 +135,8 @@ namespace dbaui
}
//---------------------------------------------------------------------
- Reference< XConnection > ODatasourceConnector::connect(const ::rtl::OUString& _rDataSourceName, sal_Bool _bShowError) const
+ Reference< XConnection > ODatasourceConnector::connect( const ::rtl::OUString& _rDataSourceName,
+ ::dbtools::SQLExceptionInfo* _pErrorInfo ) const
{
Reference< XConnection > xConnection;
@@ -142,28 +146,24 @@ namespace dbaui
// get the data source
Reference< XDataSource > xDatasource(
- getDataSourceByName_displayError( _rDataSourceName, m_pErrorMessageParent, m_xORB, _bShowError ),
+ getDataSourceByName( _rDataSourceName, m_pErrorMessageParent, m_xORB, _pErrorInfo ),
UNO_QUERY
);
+
if ( xDatasource.is() )
- xConnection = connect( xDatasource, _bShowError );
+ xConnection = connect( xDatasource, _pErrorInfo );
return xConnection;
}
//---------------------------------------------------------------------
- Reference< XConnection > ODatasourceConnector::connect(const Reference< XDataSource>& _xDataSource, sal_Bool _bShowError) const
+ Reference< XConnection > ODatasourceConnector::connect(const Reference< XDataSource>& _xDataSource,
+ ::dbtools::SQLExceptionInfo* _pErrorInfo ) const
{
Reference< XConnection > xConnection;
- OSL_ENSURE(isValid(), "ODatasourceConnector::connect: invalid object!");
- if (!isValid())
- return xConnection;
-
- if (!_xDataSource.is())
- {
- OSL_ENSURE(sal_False, "ODatasourceConnector::connect: could not retrieve the data source!");
+ OSL_ENSURE( isValid() && _xDataSource.is(), "ODatasourceConnector::connect: invalid object or argument!" );
+ if ( !isValid() || !_xDataSource.is() )
return xConnection;
- }
// get user/password
::rtl::OUString sPassword, sUser;
@@ -177,7 +177,7 @@ namespace dbaui
}
catch(Exception&)
{
- OSL_ENSURE(sal_False, "ODatasourceConnector::connect: error while retrieving data source properties!");
+ DBG_UNHANDLED_EXCEPTION();
}
// try to connect
@@ -210,19 +210,44 @@ namespace dbaui
xConnection = _xDataSource->getConnection(sUser, sPassword);
}
}
- catch(SQLContext& e) { aInfo = SQLExceptionInfo(e); }
- catch(SQLWarning& e) { aInfo = SQLExceptionInfo(e); }
- catch(SQLException& e) { aInfo = SQLExceptionInfo(e); }
+ catch( const SQLException& )
+ {
+ aInfo = ::cppu::getCaughtException();
+ }
catch(const Exception&)
{
DBG_UNHANDLED_EXCEPTION();
}
- if ( !_bShowError )
- return xConnection;
+ if ( !aInfo.isValid() )
+ {
+ // there was no error during connecting, but perhaps a warning?
+ Reference< XWarningsSupplier > xConnectionWarnings( xConnection, UNO_QUERY );
+ if ( xConnectionWarnings.is() )
+ {
+ try
+ {
+ Any aWarnings( xConnectionWarnings->getWarnings() );
+ if ( aWarnings.hasValue() )
+ {
+ String sMessage( ModuleRes( STR_WARNINGS_DURING_CONNECT ) );
+ sMessage.SearchAndReplaceAscii( "$buttontext$", Button::GetStandardText( BUTTON_MORE ) );
+ sMessage = OutputDevice::GetNonMnemonicString( sMessage );
- // was there and error?
- if ( aInfo.isValid() )
+ SQLWarning aContext;
+ aContext.Message = sMessage;
+ aContext.NextException = aWarnings;
+ aInfo = aContext;
+ }
+ xConnectionWarnings->clearWarnings();
+ }
+ catch( const Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+ }
+ }
+ else
{
if ( m_sContextInformation.getLength() )
{
@@ -232,37 +257,20 @@ namespace dbaui
aInfo = aError;
}
-
- showError(aInfo, m_pErrorMessageParent, m_xORB);
- return xConnection;
}
- // was there a warning?
- Reference< XWarningsSupplier > xConnectionWarnings( xConnection, UNO_QUERY );
- if ( xConnectionWarnings.is() )
+ // was there an error?
+ if ( aInfo.isValid() )
{
- try
+ if ( _pErrorInfo )
{
- Any aWarnings( xConnectionWarnings->getWarnings() );
- if ( aWarnings.hasValue() )
- {
- String sMessage( ModuleRes( STR_WARNINGS_DURING_CONNECT ) );
- sMessage.SearchAndReplaceAscii( "$buttontext$", Button::GetStandardText( BUTTON_MORE ) );
- sMessage = OutputDevice::GetNonMnemonicString( sMessage );
-
- SQLContext aContext;
- aContext.Message = sMessage;
- aContext.NextException = aWarnings;
- showError( SQLExceptionInfo( aContext ), m_pErrorMessageParent, m_xORB );
- }
- xConnectionWarnings->clearWarnings();
+ *_pErrorInfo = aInfo;
}
- catch( const Exception& )
+ else
{
- DBG_UNHANDLED_EXCEPTION();
+ showError( aInfo, m_pErrorMessageParent, m_xORB );
}
}
-
return xConnection;
}
diff --git a/dbaccess/source/ui/misc/dsmeta.cxx b/dbaccess/source/ui/misc/dsmeta.cxx
index 4fe29a04e2a6..aa31554f861b 100644
--- a/dbaccess/source/ui/misc/dsmeta.cxx
+++ b/dbaccess/source/ui/misc/dsmeta.cxx
@@ -120,9 +120,9 @@ namespace dbaui
if ( s_aSupport.empty() )
{
s_aSupport[ ::dbaccess::DST_MSACCESS ] = InitAdvanced( 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0 );
- s_aSupport[ ::dbaccess::DST_MYSQL_ODBC ] = InitAdvanced( 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0 );
- s_aSupport[ ::dbaccess::DST_MYSQL_JDBC ] = InitAdvanced( 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0 );
- s_aSupport[ ::dbaccess::DST_MYSQL_NATIVE ] = InitAdvanced( 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0 );
+ s_aSupport[ ::dbaccess::DST_MYSQL_ODBC ] = InitAdvanced( 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0 );
+ s_aSupport[ ::dbaccess::DST_MYSQL_JDBC ] = InitAdvanced( 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0 );
+ s_aSupport[ ::dbaccess::DST_MYSQL_NATIVE ] = InitAdvanced( 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0 );
s_aSupport[ ::dbaccess::DST_ORACLE_JDBC ] = InitAdvanced( InitAdvanced::All );
s_aSupport[ ::dbaccess::DST_ADABAS ] = InitAdvanced( 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0 );
s_aSupport[ ::dbaccess::DST_CALC ] = InitAdvanced( InitAdvanced::None );
diff --git a/dbaccess/source/ui/misc/singledoccontroller.cxx b/dbaccess/source/ui/misc/singledoccontroller.cxx
index 965185288203..ecc898cbecbc 100644
--- a/dbaccess/source/ui/misc/singledoccontroller.cxx
+++ b/dbaccess/source/ui/misc/singledoccontroller.cxx
@@ -141,7 +141,7 @@ namespace dbaui
public:
OModuleClient m_aModuleClient;
- Any m_aCurrentError; // contains the current error which can be set through IEnvironment
+ ::dbtools::SQLExceptionInfo m_aCurrentError; // contains the current error which can be set through IEnvironment
// <properties>
SharedConnection m_xConnection;
@@ -337,7 +337,7 @@ namespace dbaui
// now really reconnect ...
if ( bReConnect )
{
- m_pImpl->m_xConnection.reset( connect( m_pImpl->m_aDataSource.getDataSource(), sal_True ), SharedConnection::TakeOwnership );
+ m_pImpl->m_xConnection.reset( connect( m_pImpl->m_aDataSource.getDataSource(), NULL ), SharedConnection::TakeOwnership );
m_pImpl->m_aSdbMetaData.reset( m_pImpl->m_xConnection );
}
@@ -408,61 +408,38 @@ namespace dbaui
else
OSingleDocumentController_Base::disposing( _rSource );
}
+
//--------------------------------------------------------------------
- namespace
+ void OSingleDocumentController::appendError( const ::rtl::OUString& _rErrorMessage, const ::dbtools::StandardSQLState _eSQLState,
+ const sal_Int32 _nErrorCode )
{
- void concatSQLExceptions(Any& _rChainLeft, const Any& _rChainRight)
- {
- if (!_rChainLeft.hasValue())
- _rChainLeft = _rChainRight;
- else
- {
- // to travel the chain by reference (and not by value), we need the getValue ...
- // looks like a hack, but the meaning of getValue is documented, and it's the only chance for reference-traveling ....
-
- DBG_ASSERT(::dbtools::SQLExceptionInfo(_rChainLeft).isValid(), "concatSQLExceptions: invalid warnings chain (this will crash)!");
-
- const SQLException* pChainTravel = static_cast<const SQLException*>(_rChainLeft.getValue());
- ::dbtools::SQLExceptionIteratorHelper aReferenceIterHelper(*pChainTravel);
- while (aReferenceIterHelper.hasMoreElements())
- pChainTravel = aReferenceIterHelper.next();
-
- // reached the end of the chain, and pChainTravel points to the last element
- const_cast<SQLException*>(pChainTravel)->NextException = _rChainRight;
- }
- }
-
+ m_pImpl->m_aCurrentError.append( ::dbtools::SQLExceptionInfo::SQL_EXCEPTION, _rErrorMessage, getStandardSQLStateAscii( _eSQLState ),
+ _nErrorCode );
}
//--------------------------------------------------------------------
- /** appends an error in the current environment.
- @param _aException
- contains a description of the error or the error directly
- */
- void OSingleDocumentController::appendError(const SQLException& _aException)
+ void OSingleDocumentController::clearError()
{
- concatSQLExceptions(m_pImpl->m_aCurrentError,makeAny(_aException));
+ m_pImpl->m_aCurrentError = ::dbtools::SQLExceptionInfo();
}
+
//--------------------------------------------------------------------
- /** clears the error state.
- */
- void OSingleDocumentController::clearError()
+ sal_Bool OSingleDocumentController::hasError() const
{
- m_pImpl->m_aCurrentError = Any();
+ return m_pImpl->m_aCurrentError.isValid();
}
+
//--------------------------------------------------------------------
- /** set the current error in the given parameter.
- @param _rException
- will contain the current error
- */
- void OSingleDocumentController::getError(SQLException& _rException ) const
+ const ::dbtools::SQLExceptionInfo& OSingleDocumentController::getError() const
{
- m_pImpl->m_aCurrentError >>= _rException;
+ return m_pImpl->m_aCurrentError;
}
+
//--------------------------------------------------------------------
- sal_Bool OSingleDocumentController::hasError() const
+ void OSingleDocumentController::displayError()
{
- return m_pImpl->m_aCurrentError.hasValue();
+ showError( m_pImpl->m_aCurrentError );
}
+
//--------------------------------------------------------------------
sal_Bool SAL_CALL OSingleDocumentController::suspend(sal_Bool bSuspend) throw( RuntimeException )
{
@@ -690,7 +667,7 @@ namespace dbaui
::rtl::OUString SAL_CALL OSingleDocumentController::getTitle()
throw (RuntimeException)
{
- ::osl::MutexGuard aGuard(m_aMutex);
+ ::osl::MutexGuard aGuard( getMutex() );
if ( m_bExternalTitle )
return impl_getTitleHelper_throw()->getTitle ();
@@ -721,7 +698,7 @@ namespace dbaui
// -----------------------------------------------------------------------------
Reference< XEmbeddedScripts > SAL_CALL OSingleDocumentController::getScriptContainer() throw (RuntimeException)
{
- ::osl::MutexGuard aGuard( m_aMutex );
+ ::osl::MutexGuard aGuard( getMutex() );
if ( !m_pImpl->documentHasScriptSupport() )
return NULL;
diff --git a/dbaccess/source/ui/querydesign/JoinController.cxx b/dbaccess/source/ui/querydesign/JoinController.cxx
index 541a78dad0e4..d3f81d34d1d7 100644
--- a/dbaccess/source/ui/querydesign/JoinController.cxx
+++ b/dbaccess/source/ui/querydesign/JoinController.cxx
@@ -444,7 +444,7 @@ sal_Bool SAL_CALL OJoinController::suspend(sal_Bool _bSuspend) throw( RuntimeExc
return sal_True;
vos::OGuard aSolarGuard( Application::GetSolarMutex() );
- ::osl::MutexGuard aGuard(m_aMutex);
+ ::osl::MutexGuard aGuard( getMutex() );
if ( getView() && getView()->IsInModalMode() )
return sal_False;
sal_Bool bCheck = sal_True;
diff --git a/dbaccess/source/ui/querydesign/QueryDesignView.cxx b/dbaccess/source/ui/querydesign/QueryDesignView.cxx
index 8372f6689347..87bfaffa6d7c 100644
--- a/dbaccess/source/ui/querydesign/QueryDesignView.cxx
+++ b/dbaccess/source/ui/querydesign/QueryDesignView.cxx
@@ -440,13 +440,13 @@ namespace
eErrorCode = eColumnNotFound;
String sError(ModuleRes(STR_QRY_COLUMN_NOT_FOUND));
sError.SearchAndReplaceAscii("$name$",aColumnName);
- _pView->getController().appendError(SQLException(sError,NULL,getStandardSQLState( SQL_GENERAL_ERROR ),1000,Any()));
+ _pView->getController().appendError( sError );
try
{
Reference<XDatabaseMetaData> xMeta = _pView->getController().getConnection()->getMetaData();
if ( xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers() )
- _pView->getController().appendError(SQLException(String(ModuleRes(STR_QRY_CHECK_CASESENSITIVE)),NULL,getStandardSQLState( SQL_GENERAL_ERROR ),1000,Any()));
+ _pView->getController().appendError( String( ModuleRes( STR_QRY_CHECK_CASESENSITIVE ) ) );
}
catch(Exception&)
{
@@ -715,7 +715,7 @@ namespace
pNode->getChild(1)->getNodeType() == SQL_NODE_EQUAL))
{
String sError(ModuleRes(STR_QRY_JOIN_COLUMN_COMPARE));
- _pView->getController().appendError(SQLException(sError,NULL,getStandardSQLState( SQL_GENERAL_ERROR ),1000,Any()));
+ _pView->getController().appendError( sError );
return eIllegalJoin;
}
@@ -1364,6 +1364,9 @@ namespace
pNodeTmp = pNode->getChild(1);
::connectivity::OSQLParseNode::absorptions(pNodeTmp);
pNodeTmp = pNode->getChild(1);
+ // compress sort the criteria @see http://www.openoffice.org/issues/show_bug.cgi?id=24079
+ OSQLParseNode::compress(pNodeTmp);
+ pNodeTmp = pNode->getChild(1);
// first extract the inner joins conditions
GetInnerJoinCriteria(_pView,pNodeTmp);
@@ -1533,7 +1536,7 @@ namespace
{
eErrorCode = eNoColumnInLike;
String sError(ModuleRes(STR_QRY_LIKE_LEFT_NO_COLUMN));
- _pView->getController().appendError(SQLException(sError,NULL,getStandardSQLState( SQL_GENERAL_ERROR ),1000,Any()));
+ _pView->getController().appendError( sError );
}
}
else if( SQL_ISRULEOR2(pCondition,test_for_null,in_predicate)
@@ -2546,8 +2549,9 @@ namespace
}
return eErrorCode;
}
+
//------------------------------------------------------------------------------
- void showParseError(IEnvironment& _rEnvironment,SqlParseError _eErrorCode)
+ String getParseErrorMessage( SqlParseError _eErrorCode )
{
USHORT nResId;
switch(_eErrorCode)
@@ -2592,12 +2596,9 @@ namespace
nResId = STR_QRY_SYNTAX;
break;
}
- // ErrorBox( _pWindow, ModuleRes( nResId ) ).Execute();
- ModuleRes aRes(nResId);
- String sError(aRes);
- _rEnvironment.appendError(SQLException(sError,NULL,getStandardSQLState( SQL_GENERAL_ERROR ),1000,Any()));
+ ;
+ return String( ModuleRes( nResId ) );
}
- // -----------------------------------------------------------------------------
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
@@ -3030,12 +3031,10 @@ sal_Bool OQueryDesignView::checkStatement()
aSqlCmd += sOrder;
else
{
- if ( !m_rController.hasError() ) // fill generell error string
- showParseError(m_rController,eErrorCode);
+ if ( !m_rController.hasError() )
+ m_rController.appendError( getParseErrorMessage( eErrorCode ) );
- SQLException aError;
- m_rController.getError(aError);
- m_rController.showError(aError);
+ m_rController.displayError();
}
if ( xConnection.is() )
@@ -3228,25 +3227,33 @@ void OQueryDesignView::setNoneVisbleRow(sal_Int32 _nRows)
m_pSelectionBox->SetNoneVisbleRow(_nRows);
}
// -----------------------------------------------------------------------------
-sal_Bool OQueryDesignView::InitFromParseNode()
+bool OQueryDesignView::initByParseIterator( ::dbtools::SQLExceptionInfo* _pErrorInfo )
{
SqlParseError eErrorCode = eNativeMode;
m_rController.clearError();
+
try
{
- if ( (eErrorCode = InitFromParseNodeImpl(this,m_pSelectionBox)) != eOk )
+ eErrorCode = InitFromParseNodeImpl( this, m_pSelectionBox );
+
+ if ( eErrorCode != eOk )
{
- if ( !m_rController.hasError() ) // fill generell error string
- showParseError(m_rController,eErrorCode);
+ if ( !m_rController.hasError() )
+ m_rController.appendError( getParseErrorMessage( eErrorCode ) );
- SQLException aError;
- m_rController.getError(aError);
- m_rController.showError(aError);
+ if ( _pErrorInfo )
+ {
+ *_pErrorInfo = m_rController.getError();
+ }
+ else
+ {
+ m_rController.displayError();
+ }
}
}
- catch(Exception&)
+ catch ( const Exception& )
{
- OSL_ENSURE(0,"Can not fill query view!");
+ DBG_UNHANDLED_EXCEPTION();
}
return eErrorCode == eOk;
}
diff --git a/dbaccess/source/ui/querydesign/QueryViewSwitch.cxx b/dbaccess/source/ui/querydesign/QueryViewSwitch.cxx
index 0aedd42e4cc6..36b7afe6d727 100644
--- a/dbaccess/source/ui/querydesign/QueryViewSwitch.cxx
+++ b/dbaccess/source/ui/querydesign/QueryViewSwitch.cxx
@@ -208,40 +208,44 @@ OQueryContainerWindow* OQueryViewSwitch::getContainer() const
}
// -----------------------------------------------------------------------------
-sal_Bool OQueryViewSwitch::switchView()
+bool OQueryViewSwitch::switchView( ::dbtools::SQLExceptionInfo* _pErrorInfo )
{
sal_Bool bRet = sal_True;
sal_Bool bGraphicalDesign = static_cast<OQueryController&>(m_pDesignView->getController()).isGraphicalDesign();
OAddTableDlg* pAddTabDialog( getAddTableDialog() );
- if ( !bGraphicalDesign ) // we have to hide the add table dialog
+ OQueryContainerWindow* pContainer = getContainer();
+ if ( !bGraphicalDesign )
{
+ // hide the "Add Table" dialog
m_bAddTableDialogWasVisible = pAddTabDialog ? pAddTabDialog->IsVisible() : false;
if ( m_bAddTableDialogWasVisible )
pAddTabDialog->Hide();
- }
- OQueryContainerWindow* pContainer = getContainer();
- if ( !bGraphicalDesign )
- {
+ // tell the views they're in/active
m_pDesignView->stopTimer();
m_pTextView->getSqlEdit()->startTimer();
+ // set the most recent statement at the text view
m_pTextView->clear();
m_pTextView->setStatement(static_cast<OQueryController&>(m_pDesignView->getController()).getStatement());
}
else
{
- ::rtl::OUString sOldStatement = static_cast<OQueryController&>(m_pDesignView->getController()).getStatement();
- // we have to stop the sqledit from our textview
+ // tell the text view it's inactive now
m_pTextView->getSqlEdit()->stopTimer();
+ ::rtl::OUString sOldStatement = static_cast<OQueryController&>(m_pDesignView->getController()).getStatement();
+
+ // update the "Add Table" dialog
if ( pAddTabDialog )
pAddTabDialog->Update();
- bRet = m_pDesignView->InitFromParseNode();
- // only show the view when the data is inserted
+ // initialize the design view
+ bRet = m_pDesignView->initByParseIterator( _pErrorInfo );
+
+ // tell the design view it's active now
m_pDesignView->startTimer();
}
@@ -299,11 +303,16 @@ Reference< XMultiServiceFactory > OQueryViewSwitch::getORB() const
return m_pDesignView->getORB();
}
// -----------------------------------------------------------------------------
-void OQueryViewSwitch::reset()
+bool OQueryViewSwitch::reset( ::dbtools::SQLExceptionInfo* _pErrorInfo )
{
m_pDesignView->reset();
- if ( m_pDesignView->InitFromParseNode() )
- switchView();
+ if ( !m_pDesignView->initByParseIterator( _pErrorInfo ) )
+ return false;
+
+ if ( switchView( _pErrorInfo ) )
+ return false;
+
+ return true;
}
// -----------------------------------------------------------------------------
void OQueryViewSwitch::setNoneVisbleRow(sal_Int32 _nRows)
diff --git a/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx b/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx
index 94fe8550d759..241e5f439909 100644
--- a/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx
+++ b/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx
@@ -1649,6 +1649,13 @@ void OSelectionBrowseBox::InsertColumn(OTableFieldDescRef pEntry, USHORT& _nColu
getFields()[nOldPosition - 1] = pEntry;
ColumnMoved(pEntry->GetColumnId(),FALSE);
+ } // if ( pEntry->GetColumnId() != nColumnId )
+
+ if ( pEntry->GetFunctionType() & (FKT_AGGREGATE) )
+ {
+ String sFunctionName = pEntry->GetFunction();
+ if ( GetFunctionName(sal_uInt32(-1),sFunctionName) )
+ pEntry->SetFunction(sFunctionName);
}
// Neuzeichnen
@@ -2294,6 +2301,36 @@ sal_Bool OSelectionBrowseBox::GetFunctionName(sal_uInt32 _nFunctionTokenId,Strin
case SQL_TOKEN_SUM:
rFkt = m_pFunctionCell->GetEntry(5);
break;
+ case SQL_TOKEN_EVERY:
+ rFkt = m_pFunctionCell->GetEntry(6);
+ break;
+ case SQL_TOKEN_ANY:
+ rFkt = m_pFunctionCell->GetEntry(7);
+ break;
+ case SQL_TOKEN_SOME:
+ rFkt = m_pFunctionCell->GetEntry(8);
+ break;
+ case SQL_TOKEN_STDDEV_POP:
+ rFkt = m_pFunctionCell->GetEntry(9);
+ break;
+ case SQL_TOKEN_STDDEV_SAMP:
+ rFkt = m_pFunctionCell->GetEntry(10);
+ break;
+ case SQL_TOKEN_VAR_SAMP:
+ rFkt = m_pFunctionCell->GetEntry(11);
+ break;
+ case SQL_TOKEN_VAR_POP:
+ rFkt = m_pFunctionCell->GetEntry(12);
+ break;
+ case SQL_TOKEN_COLLECT:
+ rFkt = m_pFunctionCell->GetEntry(13);
+ break;
+ case SQL_TOKEN_FUSION:
+ rFkt = m_pFunctionCell->GetEntry(14);
+ break;
+ case SQL_TOKEN_INTERSECTION:
+ rFkt = m_pFunctionCell->GetEntry(15);
+ break;
default:
{
xub_StrLen nCount = m_aFunctionStrings.GetTokenCount();
diff --git a/dbaccess/source/ui/querydesign/querycontainerwindow.cxx b/dbaccess/source/ui/querydesign/querycontainerwindow.cxx
index 20040666e4e1..2f3a70890e92 100644
--- a/dbaccess/source/ui/querydesign/querycontainerwindow.cxx
+++ b/dbaccess/source/ui/querydesign/querycontainerwindow.cxx
@@ -120,9 +120,9 @@ namespace dbaui
}
}
// -----------------------------------------------------------------------------
- sal_Bool OQueryContainerWindow::switchView()
+ bool OQueryContainerWindow::switchView( ::dbtools::SQLExceptionInfo* _pErrorInfo )
{
- return m_pViewSwitch->switchView();
+ return m_pViewSwitch->switchView( _pErrorInfo );
}
// -----------------------------------------------------------------------------
diff --git a/dbaccess/source/ui/querydesign/querycontroller.cxx b/dbaccess/source/ui/querydesign/querycontroller.cxx
index e4709f2ea3a3..4bbd4e1dd419 100644
--- a/dbaccess/source/ui/querydesign/querycontroller.cxx
+++ b/dbaccess/source/ui/querydesign/querycontroller.cxx
@@ -271,9 +271,9 @@ using namespace ::comphelper;
namespace
{
- void ensureToolbars( OQueryController* _pController, sal_Bool _bDesign )
+ void ensureToolbars( OQueryController& _rController, sal_Bool _bDesign )
{
- Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager = _pController->getLayoutManager(_pController->getFrame());
+ Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager = _rController.getLayoutManager( _rController.getFrame() );
if ( xLayoutManager.is() )
{
xLayoutManager->lock();
@@ -293,23 +293,6 @@ namespace
xLayoutManager->doLayout();
}
}
-
- void switchDesignModeImpl(OQueryController* _pController,OQueryContainerWindow* _pWindow,sal_Bool& _rbDesign)
- {
- bool isModified = _pController->isModified();
-
- if ( !_pWindow->switchView() )
- {
- _rbDesign = !_rbDesign;
- _pWindow->switchView();
- }
- else
- {
- ensureToolbars( _pController, _rbDesign );
- }
-
- _pController->setModified( isModified );
- }
}
//------------------------------------------------------------------------------
@@ -555,8 +538,10 @@ void OQueryController::Execute(sal_uInt16 _nId, const Sequence< PropertyValue >&
getContainer()->paste();
break;
case ID_BROWSER_SQL:
+ {
if ( !getContainer()->checkStatement() )
break;
+ SQLExceptionInfo aError;
try
{
::rtl::OUString aErrorMsg;
@@ -567,30 +552,33 @@ void OQueryController::Execute(sal_uInt16 _nId, const Sequence< PropertyValue >&
delete m_pSqlIterator->getParseTree();
m_pSqlIterator->setParseTree(NULL);
m_bGraphicalDesign = !m_bGraphicalDesign;
- switchDesignModeImpl(this,getContainer(),m_bGraphicalDesign);
+ impl_setViewMode( &aError );
}
else
{
::connectivity::OSQLParseNode* pNode = m_aSqlParser.parseTree(aErrorMsg,m_sStatement,m_bGraphicalDesign);
- // m_pParseNode = pNode;
- if(pNode)
+ if ( pNode )
{
delete m_pSqlIterator->getParseTree();
m_pSqlIterator->setParseTree(pNode);
m_pSqlIterator->traverseAll();
+
if ( m_pSqlIterator->hasErrors() )
{
- showError( SQLExceptionInfo( m_pSqlIterator->getErrors() ) );
+ aError = m_pSqlIterator->getErrors();
}
else
{
const OSQLTables& xTabs = m_pSqlIterator->getTables();
- if( m_pSqlIterator->getStatementType() != SQL_STATEMENT_SELECT || xTabs.begin() == xTabs.end())
+ if ( m_pSqlIterator->getStatementType() != SQL_STATEMENT_SELECT || xTabs.begin() == xTabs.end() )
{
- ModuleRes aModuleRes(STR_QRY_NOSELECT);
- String sTmpStr(aModuleRes);
- ::rtl::OUString sError(sTmpStr);
- showError(SQLException(sError,NULL,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("S1000")),1000,Any()));
+ aError = SQLException(
+ String( ModuleRes( STR_QRY_NOSELECT ) ),
+ NULL,
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "S1000" ) ),
+ 1000,
+ Any()
+ );
}
else
{
@@ -601,33 +589,41 @@ void OQueryController::Execute(sal_uInt16 _nId, const Sequence< PropertyValue >&
setStatement_fireEvent( sNewStatement );
getContainer()->SaveUIConfig();
m_vTableConnectionData.clear();
- switchDesignModeImpl(this,getContainer(),m_bGraphicalDesign);
+ impl_setViewMode( &aError );
}
}
}
else
{
- ModuleRes aModuleRes(STR_QRY_SYNTAX);
- String sTmpStr(aModuleRes);
- ::rtl::OUString sError(sTmpStr);
- showError(SQLException(sError,NULL,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("S1000") ),1000,Any()));
+ aError = SQLException(
+ String( ModuleRes( STR_QRY_SYNTAX ) ),
+ NULL,
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "S1000" ) ),
+ 1000,
+ Any()
+ );
}
}
}
- catch(SQLException& e)
+ catch(const SQLException& e)
{
- ::dbtools::SQLExceptionInfo aInfo(e);
- showError(aInfo);
+ aError = ::cppu::getCaughtException();
}
- catch(Exception&)
+ catch(const Exception&)
{
+ DBG_UNHANDLED_EXCEPTION();
}
+
+ if ( aError.isValid() )
+ showError( aError );
+
if(m_bGraphicalDesign)
{
InvalidateFeature(ID_BROWSER_ADDTABLE);
InvalidateFeature(SID_RELATION_ADD_RELATION);
}
- break;
+ }
+ break;
case SID_BROWSER_CLEAR_QUERY:
{
getUndoMgr()->EnterListAction( String( ModuleRes(STR_QUERY_UNDO_TABWINDELETE) ), String() );
@@ -721,7 +717,11 @@ void OQueryController::Execute(sal_uInt16 _nId, const Sequence< PropertyValue >&
pNodeTmp = pTemp->getChild(1);
::connectivity::OSQLParseNode::absorptions(pNodeTmp);
pNodeTmp = pTemp->getChild(1);
- }
+ } // if ( pCondition ) // no where clause
+ ::rtl::OUString sTemp;
+ pNode->parseNodeToStr(sTemp,getConnection());
+ getContainer()->setStatement(sTemp);
+
}
}
@@ -743,6 +743,48 @@ void OQueryController::Execute(sal_uInt16 _nId, const Sequence< PropertyValue >&
}
InvalidateFeature(_nId);
}
+
+// -----------------------------------------------------------------------------
+void OQueryController::impl_showAutoSQLViewError( const ::com::sun::star::uno::Any& _rErrorDetails )
+{
+ SQLContext aErrorContext;
+ aErrorContext.Message = lcl_getObjectResourceString( STR_ERROR_PARSING_STATEMENT, m_nCommandType );
+ aErrorContext.Context = *this;
+ aErrorContext.Details = lcl_getObjectResourceString( STR_INFO_OPENING_IN_SQL_VIEW, m_nCommandType );
+ aErrorContext.NextException = _rErrorDetails;
+ showError( aErrorContext );
+}
+
+// -----------------------------------------------------------------------------
+bool OQueryController::impl_setViewMode( ::dbtools::SQLExceptionInfo* _pErrorInfo )
+{
+ OSL_PRECOND( getContainer(), "OQueryController::impl_setViewMode: illegal call!" );
+
+ bool wasModified = isModified();
+
+ SQLExceptionInfo aError;
+ bool bSuccess = getContainer()->switchView( &aError );
+ if ( !bSuccess )
+ {
+ m_bGraphicalDesign = !m_bGraphicalDesign;
+ // restore old state
+ getContainer()->switchView( NULL );
+ // don't pass &aError here, this would overwrite the error which the first switchView call
+ // returned in this location.
+ if ( _pErrorInfo )
+ *_pErrorInfo = aError;
+ else
+ showError( aError );
+ }
+ else
+ {
+ ensureToolbars( *this, m_bGraphicalDesign );
+ }
+
+ setModified( wasModified );
+ return bSuccess;
+}
+
// -----------------------------------------------------------------------------
void OQueryController::impl_initialize()
{
@@ -876,8 +918,19 @@ void OQueryController::impl_initialize()
try
{
getContainer()->initialize();
- resetImpl();
- switchDesignModeImpl(this,getContainer(),m_bGraphicalDesign);
+ impl_reset();
+
+ bool bAttemptedGraphicalDesign = m_bGraphicalDesign;
+ SQLExceptionInfo aError;
+ impl_setViewMode( &aError );
+ if ( aError.isValid() && bAttemptedGraphicalDesign && !m_bGraphicalDesign )
+ {
+ if ( !editingView() )
+ {
+ impl_showAutoSQLViewError( aError.get() );
+ }
+ }
+
getUndoMgr()->Clear();
if ( ( m_bGraphicalDesign )
@@ -908,7 +961,7 @@ void OQueryController::impl_initialize()
// -----------------------------------------------------------------------------
void OQueryController::onLoadedMenu(const Reference< ::com::sun::star::frame::XLayoutManager >& /*_xLayoutManager*/)
{
- ensureToolbars( this, m_bGraphicalDesign );
+ ensureToolbars( *this, m_bGraphicalDesign );
}
// -----------------------------------------------------------------------------
@@ -920,7 +973,7 @@ void OQueryController::onLoadedMenu(const Reference< ::com::sun::star::frame::XL
if ( !editingCommand() )
{
::vos::OGuard aSolarGuard(Application::GetSolarMutex());
- ::osl::MutexGuard aGuard(m_aMutex);
+ ::osl::MutexGuard aGuard( getMutex() );
String aDefaultName = String( ModuleRes( editingView() ? STR_VIEW_TITLE : STR_QRY_TITLE ) );
sName = aDefaultName.GetToken(0,' ');
sName += ::rtl::OUString::valueOf(getCurrentStartNumber());
@@ -1035,7 +1088,7 @@ void OQueryController::reconnect(sal_Bool _bUI)
{
m_bGraphicalDesign = sal_False;
// don't call Execute(SQL) because this changes the sql statement
- switchDesignModeImpl(this,getContainer(),m_bGraphicalDesign);
+ impl_setViewMode( NULL );
}
InvalidateAll();
}
@@ -1514,7 +1567,7 @@ bool OQueryController::doSaveAsDoc(sal_Bool _bSaveAs)
short OQueryController::saveModified()
{
vos::OGuard aSolarGuard( Application::GetSolarMutex() );
- ::osl::MutexGuard aGuard(m_aMutex);
+ ::osl::MutexGuard aGuard( getMutex() );
short nRet = RET_YES;
if ( !isConnected() || !isModified() )
return nRet;
@@ -1539,7 +1592,7 @@ short OQueryController::saveModified()
return nRet;
}
// -----------------------------------------------------------------------------
-void OQueryController::resetImpl()
+void OQueryController::impl_reset()
{
bool bValid = false;
Sequence< PropertyValue > aLayoutInformation;
@@ -1576,7 +1629,7 @@ void OQueryController::resetImpl()
}
catch( const Exception& )
{
- OSL_ENSURE( sal_False, "OQueryController::resetImpl: could not retrieve the layout information from the query!" );
+ OSL_ENSURE( sal_False, "OQueryController::impl_reset: could not retrieve the layout information from the query!" );
}
}
}
@@ -1630,12 +1683,7 @@ void OQueryController::resetImpl()
{
if ( !editingView() )
{
- SQLContext aErrorContext;
- aErrorContext.Message = lcl_getObjectResourceString( STR_ERROR_PARSING_STATEMENT, m_nCommandType );
- aErrorContext.Context = *this;
- aErrorContext.Details = lcl_getObjectResourceString( STR_INFO_OPENING_IN_SQL_VIEW, m_nCommandType );
- aErrorContext.NextException <<= m_pSqlIterator->getErrors();
- showError( aErrorContext );
+ impl_showAutoSQLViewError( makeAny( m_pSqlIterator->getErrors() ) );
}
bError = true;
}
@@ -1672,8 +1720,8 @@ void OQueryController::resetImpl()
// -----------------------------------------------------------------------------
void OQueryController::reset()
{
- resetImpl();
- getContainer()->reset();
+ impl_reset();
+ getContainer()->reset( NULL );
getUndoMgr()->Clear();
}
diff --git a/dbaccess/source/ui/tabledesign/TableController.cxx b/dbaccess/source/ui/tabledesign/TableController.cxx
index 632dc665ff57..72b2a0382fbf 100644
--- a/dbaccess/source/ui/tabledesign/TableController.cxx
+++ b/dbaccess/source/ui/tabledesign/TableController.cxx
@@ -674,7 +674,7 @@ sal_Bool SAL_CALL OTableController::suspend(sal_Bool /*_bSuspend*/) throw( Runti
return sal_True;
vos::OGuard aSolarGuard( Application::GetSolarMutex() );
- ::osl::MutexGuard aGuard(m_aMutex);
+ ::osl::MutexGuard aGuard( getMutex() );
if ( getView() && getView()->IsInModalMode() )
return sal_False;
sal_Bool bCheck = sal_True;
diff --git a/dbaccess/source/ui/uno/unoDirectSql.cxx b/dbaccess/source/ui/uno/unoDirectSql.cxx
index 823ba3dd2714..bf32f8943717 100644
--- a/dbaccess/source/ui/uno/unoDirectSql.cxx
+++ b/dbaccess/source/ui/uno/unoDirectSql.cxx
@@ -120,7 +120,7 @@ DBG_NAME(ODirectSQLDialog)
{
// the connection the row set is working with
ODatasourceConnector aDSConnector(m_aContext.getLegacyServiceFactory(),_pParent);
- xConnection = aDSConnector.connect(m_sInitialSelection);
+ xConnection = aDSConnector.connect( m_sInitialSelection, NULL );
}
catch( const Exception& )
{