Bump for 3.6-28
[LibreOffice.git] / connectivity / source / commontools / TKey.cxx
blob606a8bfec1a309e3d62841980c02d29e667aa6c4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
31 #include "connectivity/TKey.hxx"
32 #include "connectivity/TKeyColumns.hxx"
33 #include <com/sun/star/sdbc/XRow.hpp>
34 #include <com/sun/star/sdbc/XResultSet.hpp>
35 #include "TConnection.hxx"
36 #include "connectivity/TTableHelper.hxx"
38 using namespace connectivity;
39 using namespace ::com::sun::star::uno;
40 using namespace ::com::sun::star::beans;
41 using namespace ::com::sun::star::sdbc;
42 using namespace ::com::sun::star::container;
43 using namespace ::com::sun::star::lang;
44 // -------------------------------------------------------------------------
45 OTableKeyHelper::OTableKeyHelper(OTableHelper* _pTable) : connectivity::sdbcx::OKey(sal_True)
46 ,m_pTable(_pTable)
48 construct();
50 // -------------------------------------------------------------------------
51 OTableKeyHelper::OTableKeyHelper( OTableHelper* _pTable
52 ,const ::rtl::OUString& _Name
53 ,const sdbcx::TKeyProperties& _rProps
54 ) : connectivity::sdbcx::OKey(_Name,_rProps,sal_True)
55 ,m_pTable(_pTable)
57 construct();
58 refreshColumns();
60 // -------------------------------------------------------------------------
61 void OTableKeyHelper::refreshColumns()
63 if ( !m_pTable )
64 return;
66 ::std::vector< ::rtl::OUString> aVector;
67 if ( !isNew() )
69 aVector = m_aProps->m_aKeyColumnNames;
70 if ( aVector.empty() )
72 ::dbtools::OPropertyMap& rPropMap = OMetaConnection::getPropMap();
73 ::rtl::OUString aSchema,aTable;
74 m_pTable->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_SCHEMANAME)) >>= aSchema;
75 m_pTable->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_NAME)) >>= aTable;
77 if ( !m_Name.isEmpty() ) // foreign key
80 Reference< XResultSet > xResult = m_pTable->getMetaData()->getImportedKeys(m_pTable->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_CATALOGNAME)),
81 aSchema,aTable);
83 if ( xResult.is() )
85 Reference< XRow > xRow(xResult,UNO_QUERY);
86 while( xResult->next() )
88 ::rtl::OUString aForeignKeyColumn = xRow->getString(8);
89 if(xRow->getString(12) == m_Name)
90 aVector.push_back(aForeignKeyColumn);
95 if ( aVector.empty() )
97 const Reference< XResultSet > xResult = m_pTable->getMetaData()->getPrimaryKeys(m_pTable->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_CATALOGNAME)),
98 aSchema,aTable);
100 if ( xResult.is() )
102 const Reference< XRow > xRow(xResult,UNO_QUERY);
103 while( xResult->next() )
104 aVector.push_back(xRow->getString(4));
105 } // if ( xResult.is() )
111 if ( m_pColumns )
112 m_pColumns ->reFill(aVector);
113 else
114 m_pColumns = new OKeyColumnsHelper(this,m_aMutex,aVector);
116 // -----------------------------------------------------------------------------
118 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */