1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_connectivity.hxx"
30 
31 #ifndef _CONNECTIVITY_ADABAS_INDEXCOLUMNS_HXX_
32 #include "adabas/BIndexColumns.hxx"
33 #endif
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 "adabas/BTable.hxx"
40 #include "adabas/BCatalog.hxx"
41 #include <comphelper/types.hxx>
42 #include <comphelper/property.hxx>
43 
44 using namespace connectivity::adabas;
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 ObjectType OIndexColumns::createObject(const ::rtl::OUString& _rName)
54 {
55 
56 	Reference< XResultSet > xResult = m_pIndex->getTable()->getConnection()->getMetaData()->getIndexInfo(Any(),
57 					m_pIndex->getTable()->getSchema(),m_pIndex->getTable()->getTableName(),sal_False,sal_False);
58 
59 	sal_Bool bAsc = sal_True;
60 	if(xResult.is())
61 	{
62                 Reference< XRow > xRow(xResult,UNO_QUERY);
63 		::rtl::OUString aD(::rtl::OUString::createFromAscii("D"));
64 		while(xResult->next())
65 		{
66 			if(xRow->getString(9) == _rName)
67 				bAsc = xRow->getString(10) != aD;
68 		}
69 		::comphelper::disposeComponent(xResult);
70 	}
71 
72 	xResult = m_pIndex->getTable()->getConnection()->getMetaData()->getColumns(Any(),
73 			m_pIndex->getTable()->getSchema(),m_pIndex->getTable()->getTableName(),_rName);
74 
75     ObjectType xRet = NULL;
76 	if(xResult.is())
77 	{
78                 Reference< XRow > xRow(xResult,UNO_QUERY);
79 		while(xResult->next())
80 		{
81 			if(xRow->getString(4) == _rName)
82 			{
83 				sal_Int32 nType				= xRow->getInt(5);
84 				::rtl::OUString sTypeName	= xRow->getString(6);
85 				sal_Int32 nPrec				= xRow->getInt(7);
86 				OAdabasCatalog::correctColumnProperties(nPrec,nType,sTypeName);
87 
88 				OIndexColumn* pRet = new OIndexColumn(bAsc,
89 													_rName,
90 													sTypeName,
91 													xRow->getString(13),
92 													xRow->getInt(11),
93 													nPrec,
94 													xRow->getInt(9),
95 													nType,
96 													sal_False,sal_False,sal_False,sal_True);
97 				xRet = pRet;
98 				break;
99 			}
100 		}
101 		::comphelper::disposeComponent(xResult);
102 	}
103 
104 	return xRet;
105 }
106 // -------------------------------------------------------------------------
107 Reference< XPropertySet > OIndexColumns::createDescriptor()
108 {
109 	return new OIndexColumn(sal_True);
110 }
111 // -----------------------------------------------------------------------------
112 void OIndexColumns::impl_refresh() throw(::com::sun::star::uno::RuntimeException)
113 {
114 	m_pIndex->refreshColumns();
115 }
116 // -----------------------------------------------------------------------------
117 ObjectType OIndexColumns::appendObject( const ::rtl::OUString& /*_rForName*/, const Reference< XPropertySet >& descriptor )
118 {
119     return cloneDescriptor( descriptor );
120 }
121 // -----------------------------------------------------------------------------
122 
123 
124 
125