1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: TIndexColumns.cxx,v $
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
)
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
;
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
;
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
,
111 sal_False
,sal_False
,sal_False
,sal_True
);
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 // -----------------------------------------------------------------------------