LibreOffice Module connectivity (master) 1
TKey.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 <TKey.hxx>
21#include <TKeyColumns.hxx>
22#include <com/sun/star/sdbc/XRow.hpp>
23#include <com/sun/star/sdbc/XResultSet.hpp>
24#include <TConnection.hxx>
26
27using namespace connectivity;
28using namespace ::com::sun::star::uno;
29using namespace ::com::sun::star::beans;
30using namespace ::com::sun::star::sdbc;
31using namespace ::com::sun::star::container;
32using namespace ::com::sun::star::lang;
33
34OTableKeyHelper::OTableKeyHelper(OTableHelper* _pTable) : connectivity::sdbcx::OKey(true)
35 ,m_pTable(_pTable)
36{
37 construct();
38}
39
41 ,const OUString& Name
42 ,const std::shared_ptr<sdbcx::KeyProperties>& _rProps
43 ) : connectivity::sdbcx::OKey(Name,_rProps,true)
44 ,m_pTable(_pTable)
45{
46 construct();
48}
49
51{
52 if ( !m_pTable )
53 return;
54
55 std::vector< OUString> aVector;
56 if ( !isNew() )
57 {
58 aVector = m_aProps->m_aKeyColumnNames;
59 if ( aVector.empty() )
60 {
62 OUString aSchema,aTable;
63 m_pTable->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_SCHEMANAME)) >>= aSchema;
64 m_pTable->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_NAME)) >>= aTable;
65
66 if ( !m_Name.isEmpty() ) // foreign key
67 {
68
69 Reference< XResultSet > xResult = m_pTable->getMetaData()->getImportedKeys(m_pTable->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_CATALOGNAME)),
70 aSchema,aTable);
71
72 if ( xResult.is() )
73 {
74 Reference< XRow > xRow(xResult,UNO_QUERY);
75 while( xResult->next() )
76 {
77 OUString aForeignKeyColumn = xRow->getString(8);
78 if(xRow->getString(12) == m_Name)
79 aVector.push_back(aForeignKeyColumn);
80 }
81 }
82 }
83
84 if ( aVector.empty() )
85 {
86 const Reference< XResultSet > xResult = m_pTable->getMetaData()->getPrimaryKeys(m_pTable->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_CATALOGNAME)),
87 aSchema,aTable);
88
89 if ( xResult.is() )
90 {
91 const Reference< XRow > xRow(xResult,UNO_QUERY);
92 while( xResult->next() )
93 aVector.push_back(xRow->getString(4));
94 } // if ( xResult.is() )
95 }
96 }
97 }
98
99
100 if ( m_pColumns )
101 m_pColumns->reFill(aVector);
102 else
103 m_pColumns.reset(new OKeyColumnsHelper(this,m_aMutex,aVector));
104}
105
106
107/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::dbtools::OPropertyMap & getPropMap()
Definition: TConnection.cxx:68
virtual css::uno::Reference< css::sdbc::XDatabaseMetaData > getMetaData() const override
OTableHelper * m_pTable
Definition: TKey.hxx:29
OTableKeyHelper(OTableHelper *_pTable)
Definition: TKey.cxx:34
virtual void refreshColumns() override
Definition: TKey.cxx:50
std::shared_ptr< KeyProperties > m_aProps
Definition: VKey.hxx:68
virtual void construct() override
Definition: VKey.cxx:111
std::unique_ptr< OCollection > m_pColumns
Definition: VKey.hxx:70
mutable::osl::Mutex m_aMutex
const OUString & getNameByIndex(sal_Int32 _nIndex) const
Definition: propertyids.cxx:95
#define PROPERTY_ID_NAME
Definition: propertyids.hxx:50
#define PROPERTY_ID_CATALOGNAME
Definition: propertyids.hxx:70
#define PROPERTY_ID_SCHEMANAME
Definition: propertyids.hxx:69
OUString Name