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 <connectivity/TIndexColumns.hxx>
21 : #include <connectivity/sdbcx/VIndexColumn.hxx>
22 : #include <com/sun/star/sdbc/XRow.hpp>
23 : #include <com/sun/star/sdbc/XResultSet.hpp>
24 : #include <com/sun/star/sdbc/DataType.hpp>
25 : #include <com/sun/star/sdbc/ColumnValue.hpp>
26 : #include <comphelper/property.hxx>
27 : #include <connectivity/TIndex.hxx>
28 : #include <connectivity/TTableHelper.hxx>
29 : #include "TConnection.hxx"
30 :
31 : using namespace connectivity;
32 : using namespace connectivity::sdbcx;
33 : using namespace ::com::sun::star::uno;
34 : using namespace ::com::sun::star::beans;
35 : using namespace ::com::sun::star::sdbc;
36 : using namespace ::com::sun::star::container;
37 : using namespace ::com::sun::star::lang;
38 :
39 0 : OIndexColumns::OIndexColumns( OIndexHelper* _pIndex,
40 : ::osl::Mutex& _rMutex,
41 : const ::std::vector< OUString> &_rVector)
42 : : connectivity::sdbcx::OCollection(*_pIndex,true,_rMutex,_rVector)
43 0 : ,m_pIndex(_pIndex)
44 : {
45 0 : }
46 :
47 0 : sdbcx::ObjectType OIndexColumns::createObject(const OUString& _rName)
48 : {
49 0 : ::dbtools::OPropertyMap& rPropMap = OMetaConnection::getPropMap();
50 0 : OUString aCatalog, aSchema, aTable;
51 0 : ::com::sun::star::uno::Any Catalog(m_pIndex->getTable()->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_CATALOGNAME)));
52 0 : Catalog >>= aCatalog;
53 0 : m_pIndex->getTable()->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_SCHEMANAME)) >>= aSchema;
54 0 : m_pIndex->getTable()->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_NAME)) >>= aTable;
55 :
56 0 : Reference< XResultSet > xResult = m_pIndex->getTable()->getConnection()->getMetaData()->getIndexInfo(
57 0 : Catalog, aSchema, aTable, sal_False, sal_False);
58 :
59 0 : bool bAsc = true;
60 0 : if ( xResult.is() )
61 : {
62 0 : Reference< XRow > xRow(xResult,UNO_QUERY);
63 0 : OUString aD("D");
64 0 : while( xResult->next() )
65 : {
66 0 : if(xRow->getString(9) == _rName)
67 0 : bAsc = xRow->getString(10) != aD;
68 0 : }
69 : }
70 :
71 0 : xResult = m_pIndex->getTable()->getConnection()->getMetaData()->getColumns(
72 0 : Catalog, aSchema, aTable, _rName);
73 :
74 0 : sdbcx::ObjectType xRet;
75 0 : if ( xResult.is() )
76 : {
77 0 : Reference< XRow > xRow(xResult,UNO_QUERY);
78 0 : while( xResult->next() )
79 : {
80 0 : if ( xRow->getString(4) == _rName )
81 : {
82 0 : sal_Int32 nDataType = xRow->getInt(5);
83 0 : OUString aTypeName(xRow->getString(6));
84 0 : sal_Int32 nSize = xRow->getInt(7);
85 0 : sal_Int32 nDec = xRow->getInt(9);
86 0 : sal_Int32 nNull = xRow->getInt(11);
87 0 : OUString aColumnDef(xRow->getString(13));
88 :
89 : OIndexColumn* pRet = new OIndexColumn(bAsc,
90 : _rName,
91 : aTypeName,
92 : aColumnDef,
93 : nNull,
94 : nSize,
95 : nDec,
96 : nDataType,
97 : false,false,false,true,
98 0 : aCatalog, aSchema, aTable);
99 0 : xRet = pRet;
100 0 : break;
101 : }
102 0 : }
103 : }
104 :
105 0 : return xRet;
106 : }
107 :
108 0 : Reference< XPropertySet > OIndexColumns::createDescriptor()
109 : {
110 0 : return new OIndexColumn(true);
111 : }
112 :
113 0 : void OIndexColumns::impl_refresh() throw(RuntimeException)
114 : {
115 0 : m_pIndex->refreshColumns();
116 0 : }
117 :
118 :
119 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|