update dev300-m58
[ooovba.git] / connectivity / source / commontools / TIndexColumns.cxx
blob1f10f853e9cf8f317cf55af14711627bd9696778
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: TIndexColumns.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
33 #include "connectivity/TIndexColumns.hxx"
34 #include "connectivity/sdbcx/VIndexColumn.hxx"
35 #include <com/sun/star/sdbc/XRow.hpp>
36 #include <com/sun/star/sdbc/XResultSet.hpp>
37 #include <com/sun/star/sdbc/DataType.hpp>
38 #include <com/sun/star/sdbc/ColumnValue.hpp>
39 #include <comphelper/property.hxx>
40 #include "connectivity/TIndex.hxx"
41 #include "connectivity/TTableHelper.hxx"
42 #include "TConnection.hxx"
44 using namespace connectivity;
45 using namespace connectivity::sdbcx;
46 using namespace ::com::sun::star::uno;
47 using namespace ::com::sun::star::beans;
48 // using namespace ::com::sun::star::sdbcx;
49 using namespace ::com::sun::star::sdbc;
50 using namespace ::com::sun::star::container;
51 using namespace ::com::sun::star::lang;
52 // -------------------------------------------------------------------------
53 OIndexColumns::OIndexColumns( OIndexHelper* _pIndex,
54 ::osl::Mutex& _rMutex,
55 const ::std::vector< ::rtl::OUString> &_rVector)
56 : connectivity::sdbcx::OCollection(*_pIndex,sal_True,_rMutex,_rVector)
57 ,m_pIndex(_pIndex)
60 // -------------------------------------------------------------------------
61 sdbcx::ObjectType OIndexColumns::createObject(const ::rtl::OUString& _rName)
63 ::dbtools::OPropertyMap& rPropMap = OMetaConnection::getPropMap();
64 ::rtl::OUString aSchema,aTable;
65 m_pIndex->getTable()->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_SCHEMANAME)) >>= aSchema;
66 m_pIndex->getTable()->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_NAME)) >>= aTable;
68 Reference< XResultSet > xResult = m_pIndex->getTable()->getConnection()->getMetaData()->getIndexInfo(
69 m_pIndex->getTable()->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_CATALOGNAME)),
70 aSchema,aTable,sal_False,sal_False);
72 sal_Bool bAsc = sal_True;
73 if ( xResult.is() )
75 Reference< XRow > xRow(xResult,UNO_QUERY);
76 ::rtl::OUString aD(::rtl::OUString::createFromAscii("D"));
77 while( xResult->next() )
79 if(xRow->getString(9) == _rName)
80 bAsc = xRow->getString(10) != aD;
84 xResult = m_pIndex->getTable()->getConnection()->getMetaData()->getColumns(
85 m_pIndex->getTable()->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_CATALOGNAME)),
86 aSchema,aTable,_rName);
88 sdbcx::ObjectType xRet;
89 if ( xResult.is() )
91 Reference< XRow > xRow(xResult,UNO_QUERY);
92 while( xResult->next() )
94 if ( xRow->getString(4) == _rName )
96 sal_Int32 nDataType = xRow->getInt(5);
97 ::rtl::OUString aTypeName(xRow->getString(6));
98 sal_Int32 nSize = xRow->getInt(7);
99 sal_Int32 nDec = xRow->getInt(9);
100 sal_Int32 nNull = xRow->getInt(11);
101 ::rtl::OUString aColumnDef(xRow->getString(13));
103 OIndexColumn* pRet = new OIndexColumn(bAsc,
104 _rName,
105 aTypeName,
106 aColumnDef,
107 nNull,
108 nSize,
109 nDec,
110 nDataType,
111 sal_False,sal_False,sal_False,sal_True);
112 xRet = pRet;
113 break;
118 return xRet;
120 // -------------------------------------------------------------------------
121 Reference< XPropertySet > OIndexColumns::createDescriptor()
123 return new OIndexColumn(sal_True);
125 // -------------------------------------------------------------------------
126 void OIndexColumns::impl_refresh() throw(RuntimeException)
128 m_pIndex->refreshColumns();
130 // -----------------------------------------------------------------------------