LibreOffice Module dbaccess (master) 1
TableWindowData.cxx
Go to the documentation of this file.
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 <com/sun/star/sdb/XQueriesSupplier.hpp>
23#include <com/sun/star/sdbcx/XTablesSupplier.hpp>
24#include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
25#include <com/sun/star/sdbcx/XKeysSupplier.hpp>
26#include <com/sun/star/container/XNameAccess.hpp>
27#include <com/sun/star/container/XIndexAccess.hpp>
28#include <com/sun/star/lang/XComponent.hpp>
29#include <utility>
30
31using namespace dbaui;
32using namespace ::com::sun::star::lang;
33using namespace ::com::sun::star::uno;
34using namespace ::com::sun::star::sdb;
35using namespace ::com::sun::star::sdbc;
36using namespace ::com::sun::star::sdbcx;
37using namespace ::com::sun::star::beans;
38using namespace ::com::sun::star::container;
39
40OTableWindowData::OTableWindowData( const Reference< XPropertySet>& _xTable
41 ,OUString _sComposedName
42 ,OUString sTableName
43 ,OUString sWinName )
44 :m_xTable(_xTable)
45 ,m_aTableName(std::move( sTableName ))
46 ,m_aWinName(std::move( sWinName ))
47 ,m_sComposedName(std::move(_sComposedName))
48 ,m_aPosition( Point(-1,-1) )
49 ,m_aSize( Size(-1,-1) )
50 ,m_bShowAll( true )
51 ,m_bIsQuery(false)
52 ,m_bIsValid(true)
53{
54 if( m_aWinName.isEmpty() )
56
57 listen();
58}
59
61{
62 Reference<XComponent> xComponent( m_xTable, UNO_QUERY );
63 if ( xComponent.is() )
64 stopComponentListening( xComponent );
65}
66
68{
69 return ( (m_aPosition.X() != -1) && (m_aPosition.Y() != -1) );
70}
71
73{
74 return ( (m_aSize.Width() != -1) && (m_aSize.Height() !=-1) );
75}
76
77void OTableWindowData::_disposing( const css::lang::EventObject& /*_rSource*/ )
78{
79 ::osl::MutexGuard aGuard( m_aMutex );
80 // it doesn't matter which one was disposed
81 m_xColumns.clear();
82 m_xKeys.clear();
83 m_xTable.clear();
84}
85
86bool OTableWindowData::init(const Reference< XConnection >& _xConnection,bool _bAllowQueries)
87{
88 OSL_ENSURE(!m_xTable.is(),"We are already connected to a table!");
89
90 ::osl::MutexGuard aGuard( m_aMutex );
91
92 Reference< XQueriesSupplier > xSupQueries( _xConnection, UNO_QUERY_THROW );
93 Reference< XNameAccess > xQueries( xSupQueries->getQueries(), UNO_SET_THROW );
94 bool bIsKnownQuery = _bAllowQueries && xQueries->hasByName( m_sComposedName );
95
96 Reference< XTablesSupplier > xSupTables( _xConnection, UNO_QUERY_THROW );
97 Reference< XNameAccess > xTables( xSupTables->getTables(), UNO_SET_THROW );
98 bool bIsKnownTable = xTables->hasByName( m_sComposedName );
99
100 if ( bIsKnownQuery )
101 m_xTable.set( xQueries->getByName( m_sComposedName ), UNO_QUERY );
102 else if ( bIsKnownTable )
103 m_xTable.set( xTables->getByName( m_sComposedName ), UNO_QUERY );
104 else
105 m_bIsValid = false;
106
107 // if we survived so far, we know whether it's a query
108 m_bIsQuery = bIsKnownQuery;
109
110 listen();
111
112 Reference< XIndexAccess > xColumnsAsIndex( m_xColumns,UNO_QUERY );
113 return xColumnsAsIndex.is() && ( xColumnsAsIndex->getCount() > 0 );
114}
115
117{
118 if ( !m_xTable.is() )
119 return;
120
121 // listen for the object being disposed
122 Reference<XComponent> xComponent( m_xTable, UNO_QUERY );
123 if ( xComponent.is() )
124 startComponentListening( xComponent );
125
126 // obtain the columns
127 Reference< XColumnsSupplier > xColumnsSups( m_xTable, UNO_QUERY);
128 if ( xColumnsSups.is() )
129 m_xColumns = xColumnsSups->getColumns();
130
131 Reference<XKeysSupplier> xKeySup(m_xTable,UNO_QUERY);
132 if ( xKeySup.is() )
133 m_xKeys = xKeySup->getKeys();
134}
135
136/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr tools::Long Y() const
constexpr tools::Long X() const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
css::uno::Reference< css::beans::XPropertySet > m_xTable
mutable::osl::Mutex m_aMutex
css::uno::Reference< css::container::XIndexAccess > m_xKeys
virtual void _disposing(const css::lang::EventObject &_rSource) override
css::uno::Reference< css::container::XNameAccess > m_xColumns
virtual ~OTableWindowData() override
bool init(const css::uno::Reference< css::sdbc::XConnection > &_xConnection, bool _bAllowQueries)
late constructor
void startComponentListening(const css::uno::Reference< css::lang::XComponent > &_rxComp)
void stopComponentListening(const css::uno::Reference< css::lang::XComponent > &_rxComp)
awt::Size m_aSize