xref: /AOO41X/main/dbaccess/source/ui/querydesign/TableWindowData.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
30*cdf0e10cSrcweir #ifndef DBAUI_TABLEWINDOWDATA_HXX
31*cdf0e10cSrcweir #include "TableWindowData.hxx"
32*cdf0e10cSrcweir #endif
33*cdf0e10cSrcweir #ifndef _TOOLS_DEBUG_HXX
34*cdf0e10cSrcweir #include <tools/debug.hxx>
35*cdf0e10cSrcweir #endif
36*cdf0e10cSrcweir #include <com/sun/star/sdb/XQueriesSupplier.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
39*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XKeysSupplier.hpp>
40*cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
41*cdf0e10cSrcweir #include <com/sun/star/container/XIndexAccess.hpp>
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir using namespace dbaui;
44*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
45*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
46*cdf0e10cSrcweir using namespace ::com::sun::star::sdb;
47*cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
48*cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx;
49*cdf0e10cSrcweir using namespace ::com::sun::star::beans;
50*cdf0e10cSrcweir using namespace ::com::sun::star::container;
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir //==================================================================
53*cdf0e10cSrcweir // class OTableWindowData
54*cdf0e10cSrcweir //==================================================================
55*cdf0e10cSrcweir DBG_NAME(OTableWindowData)
56*cdf0e10cSrcweir //------------------------------------------------------------------------------
57*cdf0e10cSrcweir OTableWindowData::OTableWindowData( const Reference< XPropertySet>& _xTable
58*cdf0e10cSrcweir                                    ,const ::rtl::OUString& _rComposedName
59*cdf0e10cSrcweir                                    ,const ::rtl::OUString& rTableName
60*cdf0e10cSrcweir                                    ,const ::rtl::OUString& rWinName )
61*cdf0e10cSrcweir     :m_xTable(_xTable)
62*cdf0e10cSrcweir     ,m_aTableName( rTableName )
63*cdf0e10cSrcweir 	,m_aWinName( rWinName )
64*cdf0e10cSrcweir 	,m_sComposedName(_rComposedName)
65*cdf0e10cSrcweir 	,m_aPosition( Point(-1,-1) )
66*cdf0e10cSrcweir 	,m_aSize( Size(-1,-1) )
67*cdf0e10cSrcweir 	,m_bShowAll( sal_True )
68*cdf0e10cSrcweir     ,m_bIsQuery(false)
69*cdf0e10cSrcweir     ,m_bIsValid(true)
70*cdf0e10cSrcweir {
71*cdf0e10cSrcweir 	DBG_CTOR(OTableWindowData,NULL);
72*cdf0e10cSrcweir 	if( !m_aWinName.getLength() )
73*cdf0e10cSrcweir 		m_aWinName = m_aTableName;
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir     listen();
76*cdf0e10cSrcweir }
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir //------------------------------------------------------------------------------
79*cdf0e10cSrcweir OTableWindowData::~OTableWindowData()
80*cdf0e10cSrcweir {
81*cdf0e10cSrcweir 	DBG_DTOR(OTableWindowData,NULL);
82*cdf0e10cSrcweir     Reference<XComponent> xComponent( m_xTable, UNO_QUERY );
83*cdf0e10cSrcweir 	if ( xComponent.is() )
84*cdf0e10cSrcweir 		stopComponentListening( xComponent );
85*cdf0e10cSrcweir }
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir //------------------------------------------------------------------------------
88*cdf0e10cSrcweir sal_Bool OTableWindowData::HasPosition() const
89*cdf0e10cSrcweir {
90*cdf0e10cSrcweir 	return ( (m_aPosition.X() != -1) && (m_aPosition.Y() != -1) );
91*cdf0e10cSrcweir }
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir //------------------------------------------------------------------------------
94*cdf0e10cSrcweir sal_Bool OTableWindowData::HasSize() const
95*cdf0e10cSrcweir {
96*cdf0e10cSrcweir 	return ( (m_aSize.Width() != -1) && (m_aSize.Height() !=-1) );
97*cdf0e10cSrcweir }
98*cdf0e10cSrcweir // -----------------------------------------------------------------------------
99*cdf0e10cSrcweir void OTableWindowData::_disposing( const ::com::sun::star::lang::EventObject& /*_rSource*/ )
100*cdf0e10cSrcweir {
101*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
102*cdf0e10cSrcweir 	// it doesn't matter which one was disposed
103*cdf0e10cSrcweir     m_xColumns.clear();
104*cdf0e10cSrcweir     m_xKeys.clear();
105*cdf0e10cSrcweir 	m_xTable.clear();
106*cdf0e10cSrcweir }
107*cdf0e10cSrcweir // -----------------------------------------------------------------------------
108*cdf0e10cSrcweir bool OTableWindowData::init(const Reference< XConnection  >& _xConnection,bool _bAllowQueries)
109*cdf0e10cSrcweir {
110*cdf0e10cSrcweir     OSL_ENSURE(!m_xTable.is(),"We are already connected to a table!");
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir     ::osl::MutexGuard aGuard( m_aMutex );
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir 	Reference< XQueriesSupplier > xSupQueries( _xConnection, UNO_QUERY_THROW );
115*cdf0e10cSrcweir     Reference< XNameAccess > xQueries( xSupQueries->getQueries(), UNO_QUERY_THROW );
116*cdf0e10cSrcweir     bool bIsKnownQuery = _bAllowQueries && xQueries->hasByName( m_sComposedName );
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir     Reference< XTablesSupplier > xSupTables( _xConnection, UNO_QUERY_THROW );
119*cdf0e10cSrcweir     Reference< XNameAccess > xTables( xSupTables->getTables(), UNO_QUERY_THROW );
120*cdf0e10cSrcweir     bool bIsKnownTable = xTables->hasByName( m_sComposedName );
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir     if ( bIsKnownQuery )
123*cdf0e10cSrcweir         m_xTable.set( xQueries->getByName( m_sComposedName ), UNO_QUERY );
124*cdf0e10cSrcweir     else if ( bIsKnownTable )
125*cdf0e10cSrcweir         m_xTable.set( xTables->getByName( m_sComposedName ), UNO_QUERY );
126*cdf0e10cSrcweir     else
127*cdf0e10cSrcweir         m_bIsValid = false;
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir     // if we survived so far, we know whether it's a query
130*cdf0e10cSrcweir     m_bIsQuery = bIsKnownQuery;
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir     listen();
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir     Reference< XIndexAccess > xColumnsAsIndex( m_xColumns,UNO_QUERY );
135*cdf0e10cSrcweir     return xColumnsAsIndex.is() && ( xColumnsAsIndex->getCount() > 0 );
136*cdf0e10cSrcweir }
137*cdf0e10cSrcweir // -----------------------------------------------------------------------------
138*cdf0e10cSrcweir void OTableWindowData::listen()
139*cdf0e10cSrcweir {
140*cdf0e10cSrcweir     if ( m_xTable.is() )
141*cdf0e10cSrcweir     {
142*cdf0e10cSrcweir         // listen for the object being disposed
143*cdf0e10cSrcweir 	    Reference<XComponent> xComponent( m_xTable, UNO_QUERY );
144*cdf0e10cSrcweir 	    if ( xComponent.is() )
145*cdf0e10cSrcweir 		    startComponentListening( xComponent );
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir         // obtain the columns
148*cdf0e10cSrcweir         Reference< XColumnsSupplier > xColumnsSups( m_xTable, UNO_QUERY);
149*cdf0e10cSrcweir         if ( xColumnsSups.is() )
150*cdf0e10cSrcweir 	        m_xColumns = xColumnsSups->getColumns();
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir         Reference<XKeysSupplier> xKeySup(m_xTable,UNO_QUERY);
153*cdf0e10cSrcweir 	    if ( xKeySup.is() )
154*cdf0e10cSrcweir 		    m_xKeys = xKeySup->getKeys();
155*cdf0e10cSrcweir     }
156*cdf0e10cSrcweir }
157*cdf0e10cSrcweir // -----------------------------------------------------------------------------
158