Bump for 3.6-28
[LibreOffice.git] / connectivity / source / commontools / TIndexColumns.cxx
blobdac745c1f22a08c3d3a5a82ed4d44ea10fe57d93
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 ************************************************************************/
29 #include "connectivity/TIndexColumns.hxx"
30 #include "connectivity/sdbcx/VIndexColumn.hxx"
31 #include <com/sun/star/sdbc/XRow.hpp>
32 #include <com/sun/star/sdbc/XResultSet.hpp>
33 #include <com/sun/star/sdbc/DataType.hpp>
34 #include <com/sun/star/sdbc/ColumnValue.hpp>
35 #include <comphelper/property.hxx>
36 #include "connectivity/TIndex.hxx"
37 #include "connectivity/TTableHelper.hxx"
38 #include "TConnection.hxx"
40 using namespace connectivity;
41 using namespace connectivity::sdbcx;
42 using namespace ::com::sun::star::uno;
43 using namespace ::com::sun::star::beans;
44 using namespace ::com::sun::star::sdbc;
45 using namespace ::com::sun::star::container;
46 using namespace ::com::sun::star::lang;
47 // -------------------------------------------------------------------------
48 OIndexColumns::OIndexColumns( OIndexHelper* _pIndex,
49 ::osl::Mutex& _rMutex,
50 const ::std::vector< ::rtl::OUString> &_rVector)
51 : connectivity::sdbcx::OCollection(*_pIndex,sal_True,_rMutex,_rVector)
52 ,m_pIndex(_pIndex)
55 // -------------------------------------------------------------------------
56 sdbcx::ObjectType OIndexColumns::createObject(const ::rtl::OUString& _rName)
58 ::dbtools::OPropertyMap& rPropMap = OMetaConnection::getPropMap();
59 ::rtl::OUString aSchema,aTable;
60 m_pIndex->getTable()->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_SCHEMANAME)) >>= aSchema;
61 m_pIndex->getTable()->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_NAME)) >>= aTable;
63 Reference< XResultSet > xResult = m_pIndex->getTable()->getConnection()->getMetaData()->getIndexInfo(
64 m_pIndex->getTable()->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_CATALOGNAME)),
65 aSchema,aTable,sal_False,sal_False);
67 sal_Bool bAsc = sal_True;
68 if ( xResult.is() )
70 Reference< XRow > xRow(xResult,UNO_QUERY);
71 ::rtl::OUString aD(RTL_CONSTASCII_USTRINGPARAM("D"));
72 while( xResult->next() )
74 if(xRow->getString(9) == _rName)
75 bAsc = xRow->getString(10) != aD;
79 xResult = m_pIndex->getTable()->getConnection()->getMetaData()->getColumns(
80 m_pIndex->getTable()->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_CATALOGNAME)),
81 aSchema,aTable,_rName);
83 sdbcx::ObjectType xRet;
84 if ( xResult.is() )
86 Reference< XRow > xRow(xResult,UNO_QUERY);
87 while( xResult->next() )
89 if ( xRow->getString(4) == _rName )
91 sal_Int32 nDataType = xRow->getInt(5);
92 ::rtl::OUString aTypeName(xRow->getString(6));
93 sal_Int32 nSize = xRow->getInt(7);
94 sal_Int32 nDec = xRow->getInt(9);
95 sal_Int32 nNull = xRow->getInt(11);
96 ::rtl::OUString aColumnDef(xRow->getString(13));
98 OIndexColumn* pRet = new OIndexColumn(bAsc,
99 _rName,
100 aTypeName,
101 aColumnDef,
102 nNull,
103 nSize,
104 nDec,
105 nDataType,
106 sal_False,sal_False,sal_False,sal_True);
107 xRet = pRet;
108 break;
113 return xRet;
115 // -------------------------------------------------------------------------
116 Reference< XPropertySet > OIndexColumns::createDescriptor()
118 return new OIndexColumn(sal_True);
120 // -------------------------------------------------------------------------
121 void OIndexColumns::impl_refresh() throw(RuntimeException)
123 m_pIndex->refreshColumns();
125 // -----------------------------------------------------------------------------
127 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */