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 #include "ado/AIndex.hxx"
31 #include <com/sun/star/sdbc/XRow.hpp>
32 #include <com/sun/star/sdbc/XResultSet.hpp>
33 #include <cppuhelper/typeprovider.hxx>
34 #include <comphelper/sequence.hxx>
35 #include "ado/AColumns.hxx"
36 #include <comphelper/extract.hxx>
37 #include "TConnection.hxx"
38 #include <comphelper/types.hxx>
39 
40 using namespace ::comphelper;
41 
42 using namespace connectivity::ado;
43 using namespace com::sun::star::uno;
44 using namespace com::sun::star::lang;
45 using namespace com::sun::star::beans;
46 using namespace com::sun::star::sdbc;
47 
48 // -------------------------------------------------------------------------
49 OAdoIndex::OAdoIndex(sal_Bool _bCase,OConnection* _pConnection,ADOIndex* _pIndex)
50 	: OIndex_ADO(::rtl::OUString(),::rtl::OUString(),sal_False,sal_False,sal_False,_bCase)
51 	,m_pConnection(_pConnection)
52 {
53 	construct();
54 	m_aIndex = WpADOIndex(_pIndex);
55 	fillPropertyValues();
56 }
57 // -------------------------------------------------------------------------
58 OAdoIndex::OAdoIndex(sal_Bool _bCase,OConnection* _pConnection)
59 	: OIndex_ADO(_bCase)
60 	,m_pConnection(_pConnection)
61 {
62 	construct();
63 	m_aIndex.Create();
64 }
65 
66 // -------------------------------------------------------------------------
67 
68 void OAdoIndex::refreshColumns()
69 {
70 	TStringVector aVector;
71 
72 	WpADOColumns aColumns;
73 	if ( m_aIndex.IsValid() )
74 	{
75 		aColumns = m_aIndex.get_Columns();
76 		aColumns.fillElementNames(aVector);
77 	}
78 
79 	if ( m_pColumns )
80 		m_pColumns->reFill(aVector);
81 	else
82 		m_pColumns = new OColumns(*this,m_aMutex,aVector,aColumns,isCaseSensitive(),m_pConnection);
83 }
84 
85 // -------------------------------------------------------------------------
86 Sequence< sal_Int8 > OAdoIndex::getUnoTunnelImplementationId()
87 {
88 	static ::cppu::OImplementationId * pId = 0;
89 	if (! pId)
90 	{
91 		::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
92 		if (! pId)
93 		{
94 			static ::cppu::OImplementationId aId;
95 			pId = &aId;
96 		}
97 	}
98 	return pId->getImplementationId();
99 }
100 
101 // com::sun::star::lang::XUnoTunnel
102 //------------------------------------------------------------------
103 sal_Int64 OAdoIndex::getSomething( const Sequence< sal_Int8 > & rId ) throw (RuntimeException)
104 {
105 	return (rId.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(),  rId.getConstArray(), 16 ) )
106 				? reinterpret_cast< sal_Int64 >( this )
107 				: OIndex_ADO::getSomething(rId);
108 }
109 // -------------------------------------------------------------------------
110 void SAL_CALL OAdoIndex::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue)throw (Exception)
111 {
112 	if(m_aIndex.IsValid())
113 	{
114 		switch(nHandle)
115 		{
116 			case PROPERTY_ID_NAME:
117 				{
118 					::rtl::OUString aVal;
119 					rValue >>= aVal;
120 					m_aIndex.put_Name(aVal);
121 				}
122 				break;
123 			case PROPERTY_ID_CATALOG:
124 				{
125 					::rtl::OUString aVal;
126 					rValue >>= aVal;
127 					m_aIndex.put_Name(aVal);
128 				}
129 				break;
130 			case PROPERTY_ID_ISUNIQUE:
131 				m_aIndex.put_Unique(getBOOL(rValue));
132 				break;
133 			case PROPERTY_ID_ISPRIMARYKEYINDEX:
134 				m_aIndex.put_PrimaryKey(getBOOL(rValue));
135 				break;
136 			case PROPERTY_ID_ISCLUSTERED:
137 				m_aIndex.put_Clustered(getBOOL(rValue));
138 				break;
139 		}
140 	}
141 	OIndex_ADO::setFastPropertyValue_NoBroadcast(nHandle,rValue);
142 }
143 // -----------------------------------------------------------------------------
144 void SAL_CALL OAdoIndex::acquire() throw()
145 {
146 	OIndex_ADO::acquire();
147 }
148 // -----------------------------------------------------------------------------
149 void SAL_CALL OAdoIndex::release() throw()
150 {
151 	OIndex_ADO::release();
152 }
153 // -----------------------------------------------------------------------------
154 
155 
156 
157 
158