Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "TableWindowData.hxx"
21 : #include <osl/diagnose.h>
22 : #include <tools/debug.hxx>
23 : #include <com/sun/star/sdb/XQueriesSupplier.hpp>
24 : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
25 : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
26 : #include <com/sun/star/sdbcx/XKeysSupplier.hpp>
27 : #include <com/sun/star/container/XNameAccess.hpp>
28 : #include <com/sun/star/container/XIndexAccess.hpp>
29 :
30 : using namespace dbaui;
31 : using namespace ::com::sun::star::lang;
32 : using namespace ::com::sun::star::uno;
33 : using namespace ::com::sun::star::sdb;
34 : using namespace ::com::sun::star::sdbc;
35 : using namespace ::com::sun::star::sdbcx;
36 : using namespace ::com::sun::star::beans;
37 : using namespace ::com::sun::star::container;
38 :
39 : // class OTableWindowData
40 0 : OTableWindowData::OTableWindowData( const Reference< XPropertySet>& _xTable
41 : ,const OUString& _rComposedName
42 : ,const OUString& rTableName
43 : ,const OUString& rWinName )
44 : :m_xTable(_xTable)
45 : ,m_aTableName( rTableName )
46 : ,m_aWinName( rWinName )
47 : ,m_sComposedName(_rComposedName)
48 : ,m_aPosition( Point(-1,-1) )
49 : ,m_aSize( Size(-1,-1) )
50 : ,m_bShowAll( true )
51 : ,m_bIsQuery(false)
52 0 : ,m_bIsValid(true)
53 : {
54 0 : if( m_aWinName.isEmpty() )
55 0 : m_aWinName = m_aTableName;
56 :
57 0 : listen();
58 0 : }
59 :
60 0 : OTableWindowData::~OTableWindowData()
61 : {
62 0 : Reference<XComponent> xComponent( m_xTable, UNO_QUERY );
63 0 : if ( xComponent.is() )
64 0 : stopComponentListening( xComponent );
65 0 : }
66 :
67 0 : bool OTableWindowData::HasPosition() const
68 : {
69 0 : return ( (m_aPosition.X() != -1) && (m_aPosition.Y() != -1) );
70 : }
71 :
72 0 : bool OTableWindowData::HasSize() const
73 : {
74 0 : return ( (m_aSize.Width() != -1) && (m_aSize.Height() !=-1) );
75 : }
76 :
77 0 : void OTableWindowData::_disposing( const ::com::sun::star::lang::EventObject& /*_rSource*/ )
78 : {
79 0 : ::osl::MutexGuard aGuard( m_aMutex );
80 : // it doesn't matter which one was disposed
81 0 : m_xColumns.clear();
82 0 : m_xKeys.clear();
83 0 : m_xTable.clear();
84 0 : }
85 :
86 0 : bool OTableWindowData::init(const Reference< XConnection >& _xConnection,bool _bAllowQueries)
87 : {
88 : OSL_ENSURE(!m_xTable.is(),"We are already connected to a table!");
89 :
90 0 : ::osl::MutexGuard aGuard( m_aMutex );
91 :
92 0 : Reference< XQueriesSupplier > xSupQueries( _xConnection, UNO_QUERY_THROW );
93 0 : Reference< XNameAccess > xQueries( xSupQueries->getQueries(), UNO_QUERY_THROW );
94 0 : bool bIsKnownQuery = _bAllowQueries && xQueries->hasByName( m_sComposedName );
95 :
96 0 : Reference< XTablesSupplier > xSupTables( _xConnection, UNO_QUERY_THROW );
97 0 : Reference< XNameAccess > xTables( xSupTables->getTables(), UNO_QUERY_THROW );
98 0 : bool bIsKnownTable = xTables->hasByName( m_sComposedName );
99 :
100 0 : if ( bIsKnownQuery )
101 0 : m_xTable.set( xQueries->getByName( m_sComposedName ), UNO_QUERY );
102 0 : else if ( bIsKnownTable )
103 0 : m_xTable.set( xTables->getByName( m_sComposedName ), UNO_QUERY );
104 : else
105 0 : m_bIsValid = false;
106 :
107 : // if we survived so far, we know whether it's a query
108 0 : m_bIsQuery = bIsKnownQuery;
109 :
110 0 : listen();
111 :
112 0 : Reference< XIndexAccess > xColumnsAsIndex( m_xColumns,UNO_QUERY );
113 0 : return xColumnsAsIndex.is() && ( xColumnsAsIndex->getCount() > 0 );
114 : }
115 :
116 0 : void OTableWindowData::listen()
117 : {
118 0 : if ( m_xTable.is() )
119 : {
120 : // listen for the object being disposed
121 0 : Reference<XComponent> xComponent( m_xTable, UNO_QUERY );
122 0 : if ( xComponent.is() )
123 0 : startComponentListening( xComponent );
124 :
125 : // obtain the columns
126 0 : Reference< XColumnsSupplier > xColumnsSups( m_xTable, UNO_QUERY);
127 0 : if ( xColumnsSups.is() )
128 0 : m_xColumns = xColumnsSups->getColumns();
129 :
130 0 : Reference<XKeysSupplier> xKeySup(m_xTable,UNO_QUERY);
131 0 : if ( xKeySup.is() )
132 0 : m_xKeys = xKeySup->getKeys();
133 : }
134 0 : }
135 :
136 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|