1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_connectivity.hxx"
26 #include "ado/AKey.hxx"
27 #include <com/sun/star/sdbc/XRow.hpp>
28 #include <com/sun/star/sdbc/XResultSet.hpp>
29 #include <cppuhelper/typeprovider.hxx>
30 #include <comphelper/sequence.hxx>
31 #include "ado/AColumns.hxx"
32 #include "ado/AConnection.hxx"
33 
34 using namespace connectivity::ado;
35 using namespace com::sun::star::uno;
36 using namespace com::sun::star::lang;
37 using namespace com::sun::star::beans;
38 using namespace com::sun::star::sdbc;
39 using namespace com::sun::star::sdbcx;
40 
41 // -------------------------------------------------------------------------
OAdoKey(sal_Bool _bCase,OConnection * _pConnection,ADOKey * _pKey)42 OAdoKey::OAdoKey(sal_Bool _bCase,OConnection* _pConnection, ADOKey* _pKey)
43 	: OKey_ADO(_bCase)
44 	,m_pConnection(_pConnection)
45 {
46 	construct();
47 	m_aKey = WpADOKey(_pKey);
48 	fillPropertyValues();
49 }
50 // -------------------------------------------------------------------------
OAdoKey(sal_Bool _bCase,OConnection * _pConnection)51 OAdoKey::OAdoKey(sal_Bool _bCase,OConnection* _pConnection)
52 	: OKey_ADO(_bCase)
53 	,m_pConnection(_pConnection)
54 {
55 	construct();
56 	m_aKey.Create();
57 }
58 // -------------------------------------------------------------------------
refreshColumns()59 void OAdoKey::refreshColumns()
60 {
61 	TStringVector aVector;
62 
63 	WpADOColumns aColumns;
64 	if ( m_aKey.IsValid() )
65 	{
66 		aColumns = m_aKey.get_Columns();
67 		aColumns.fillElementNames(aVector);
68 	}
69 
70 	if(m_pColumns)
71 		m_pColumns->reFill(aVector);
72 	else
73 		m_pColumns = new OColumns(*this,m_aMutex,aVector,aColumns,isCaseSensitive(),m_pConnection);
74 }
75 // -------------------------------------------------------------------------
getUnoTunnelImplementationId()76 Sequence< sal_Int8 > OAdoKey::getUnoTunnelImplementationId()
77 {
78 	static ::cppu::OImplementationId * pId = 0;
79 	if (! pId)
80 	{
81 		::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
82 		if (! pId)
83 		{
84 			static ::cppu::OImplementationId aId;
85 			pId = &aId;
86 		}
87 	}
88 	return pId->getImplementationId();
89 }
90 
91 // com::sun::star::lang::XUnoTunnel
92 //------------------------------------------------------------------
getSomething(const Sequence<sal_Int8> & rId)93 sal_Int64 OAdoKey::getSomething( const Sequence< sal_Int8 > & rId ) throw (RuntimeException)
94 {
95 	return (rId.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(),  rId.getConstArray(), 16 ) )
96 				? reinterpret_cast< sal_Int64 >( this )
97 				: OKey_ADO::getSomething(rId);
98 }
99 // -------------------------------------------------------------------------
setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any & rValue)100 void OAdoKey::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue)throw (Exception)
101 {
102 	if(m_aKey.IsValid())
103 	{
104 		switch(nHandle)
105 		{
106 			case PROPERTY_ID_NAME:
107 				{
108 					::rtl::OUString aVal;
109 					rValue >>= aVal;
110 					m_aKey.put_Name(aVal);
111 					ADOS::ThrowException(*m_pConnection->getConnection(),*this);
112 				}
113 				break;
114 			case PROPERTY_ID_TYPE:
115 				{
116 					sal_Int32 nVal=0;
117 					rValue >>= nVal;
118 					m_aKey.put_Type(Map2KeyRule(nVal));
119 					ADOS::ThrowException(*m_pConnection->getConnection(),*this);
120 				}
121 				break;
122 			case PROPERTY_ID_REFERENCEDTABLE:
123 				{
124 					::rtl::OUString aVal;
125 					rValue >>= aVal;
126 					m_aKey.put_RelatedTable(aVal);
127 					ADOS::ThrowException(*m_pConnection->getConnection(),*this);
128 				}
129 				break;
130 			case PROPERTY_ID_UPDATERULE:
131 				{
132 					sal_Int32 nVal=0;
133 					rValue >>= nVal;
134 					m_aKey.put_UpdateRule(Map2Rule(nVal));
135 					ADOS::ThrowException(*m_pConnection->getConnection(),*this);
136 				}
137 				break;
138 			case PROPERTY_ID_DELETERULE:
139 				{
140 					sal_Int32 nVal=0;
141 					rValue >>= nVal;
142 					m_aKey.put_DeleteRule(Map2Rule(nVal));
143 					ADOS::ThrowException(*m_pConnection->getConnection(),*this);
144 				}
145 				break;
146 		}
147 	}
148 	OKey_ADO::setFastPropertyValue_NoBroadcast(nHandle,rValue);
149 }
150 // -------------------------------------------------------------------------
151 // -----------------------------------------------------------------------------
acquire()152 void SAL_CALL OAdoKey::acquire() throw()
153 {
154 	OKey_ADO::acquire();
155 }
156 // -----------------------------------------------------------------------------
release()157 void SAL_CALL OAdoKey::release() throw()
158 {
159 	OKey_ADO::release();
160 }
161 // -----------------------------------------------------------------------------
162 
163 
164