xref: /trunk/main/connectivity/source/drivers/ado/AKey.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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/AKey.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 "ado/AConnection.hxx"
37 
38 using namespace connectivity::ado;
39 using namespace com::sun::star::uno;
40 using namespace com::sun::star::lang;
41 using namespace com::sun::star::beans;
42 using namespace com::sun::star::sdbc;
43 using namespace com::sun::star::sdbcx;
44 
45 // -------------------------------------------------------------------------
46 OAdoKey::OAdoKey(sal_Bool _bCase,OConnection* _pConnection, ADOKey* _pKey)
47     : OKey_ADO(_bCase)
48     ,m_pConnection(_pConnection)
49 {
50     construct();
51     m_aKey = WpADOKey(_pKey);
52     fillPropertyValues();
53 }
54 // -------------------------------------------------------------------------
55 OAdoKey::OAdoKey(sal_Bool _bCase,OConnection* _pConnection)
56     : OKey_ADO(_bCase)
57     ,m_pConnection(_pConnection)
58 {
59     construct();
60     m_aKey.Create();
61 }
62 // -------------------------------------------------------------------------
63 void OAdoKey::refreshColumns()
64 {
65     TStringVector aVector;
66 
67     WpADOColumns aColumns;
68     if ( m_aKey.IsValid() )
69     {
70         aColumns = m_aKey.get_Columns();
71         aColumns.fillElementNames(aVector);
72     }
73 
74     if(m_pColumns)
75         m_pColumns->reFill(aVector);
76     else
77         m_pColumns = new OColumns(*this,m_aMutex,aVector,aColumns,isCaseSensitive(),m_pConnection);
78 }
79 // -------------------------------------------------------------------------
80 Sequence< sal_Int8 > OAdoKey::getUnoTunnelImplementationId()
81 {
82     static ::cppu::OImplementationId * pId = 0;
83     if (! pId)
84     {
85         ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
86         if (! pId)
87         {
88             static ::cppu::OImplementationId aId;
89             pId = &aId;
90         }
91     }
92     return pId->getImplementationId();
93 }
94 
95 // com::sun::star::lang::XUnoTunnel
96 //------------------------------------------------------------------
97 sal_Int64 OAdoKey::getSomething( const Sequence< sal_Int8 > & rId ) throw (RuntimeException)
98 {
99     return (rId.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(),  rId.getConstArray(), 16 ) )
100                 ? reinterpret_cast< sal_Int64 >( this )
101                 : OKey_ADO::getSomething(rId);
102 }
103 // -------------------------------------------------------------------------
104 void OAdoKey::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue)throw (Exception)
105 {
106     if(m_aKey.IsValid())
107     {
108         switch(nHandle)
109         {
110             case PROPERTY_ID_NAME:
111                 {
112                     ::rtl::OUString aVal;
113                     rValue >>= aVal;
114                     m_aKey.put_Name(aVal);
115                     ADOS::ThrowException(*m_pConnection->getConnection(),*this);
116                 }
117                 break;
118             case PROPERTY_ID_TYPE:
119                 {
120                     sal_Int32 nVal=0;
121                     rValue >>= nVal;
122                     m_aKey.put_Type(Map2KeyRule(nVal));
123                     ADOS::ThrowException(*m_pConnection->getConnection(),*this);
124                 }
125                 break;
126             case PROPERTY_ID_REFERENCEDTABLE:
127                 {
128                     ::rtl::OUString aVal;
129                     rValue >>= aVal;
130                     m_aKey.put_RelatedTable(aVal);
131                     ADOS::ThrowException(*m_pConnection->getConnection(),*this);
132                 }
133                 break;
134             case PROPERTY_ID_UPDATERULE:
135                 {
136                     sal_Int32 nVal=0;
137                     rValue >>= nVal;
138                     m_aKey.put_UpdateRule(Map2Rule(nVal));
139                     ADOS::ThrowException(*m_pConnection->getConnection(),*this);
140                 }
141                 break;
142             case PROPERTY_ID_DELETERULE:
143                 {
144                     sal_Int32 nVal=0;
145                     rValue >>= nVal;
146                     m_aKey.put_DeleteRule(Map2Rule(nVal));
147                     ADOS::ThrowException(*m_pConnection->getConnection(),*this);
148                 }
149                 break;
150         }
151     }
152     OKey_ADO::setFastPropertyValue_NoBroadcast(nHandle,rValue);
153 }
154 // -------------------------------------------------------------------------
155 // -----------------------------------------------------------------------------
156 void SAL_CALL OAdoKey::acquire() throw()
157 {
158     OKey_ADO::acquire();
159 }
160 // -----------------------------------------------------------------------------
161 void SAL_CALL OAdoKey::release() throw()
162 {
163     OKey_ADO::release();
164 }
165 // -----------------------------------------------------------------------------
166 
167 
168