xref: /AOO41X/main/connectivity/source/drivers/ado/AKeys.cxx (revision 9b5730f6ddef7eb82608ca4d31dc0d7678e652cf)
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/AKeys.hxx"
27 #ifndef _CONNECTIVITY_ADO_INDEX_HXX_
28 #include "ado/AKey.hxx"
29 #endif
30 #include <com/sun/star/sdbc/XRow.hpp>
31 #include <com/sun/star/sdbc/XResultSet.hpp>
32 #include <com/sun/star/sdbcx/KeyType.hpp>
33 #include <com/sun/star/sdbc/KeyRule.hpp>
34 #include "ado/AConnection.hxx"
35 #include <comphelper/types.hxx>
36 #include "ado/Awrapado.hxx"
37 #include <comphelper/property.hxx>
38 #include <connectivity/dbexception.hxx>
39 #include "resource/ado_res.hrc"
40 
41 using namespace ::comphelper;
42 using namespace connectivity;
43 using namespace connectivity::ado;
44 using namespace com::sun::star::uno;
45 using namespace com::sun::star::lang;
46 using namespace com::sun::star::beans;
47 using namespace com::sun::star::sdbc;
48 using namespace com::sun::star::sdbcx;
49 using namespace com::sun::star::container;
50 
createObject(const::rtl::OUString & _rName)51 sdbcx::ObjectType OKeys::createObject(const ::rtl::OUString& _rName)
52 {
53     return new OAdoKey(isCaseSensitive(),m_pConnection,m_aCollection.GetItem(_rName));
54 }
55 // -------------------------------------------------------------------------
impl_refresh()56 void OKeys::impl_refresh() throw(RuntimeException)
57 {
58     m_aCollection.Refresh();
59 }
60 // -------------------------------------------------------------------------
createDescriptor()61 Reference< XPropertySet > OKeys::createDescriptor()
62 {
63     return new OAdoKey(isCaseSensitive(),m_pConnection);
64 }
65 // -------------------------------------------------------------------------
66 // XAppend
appendObject(const::rtl::OUString &,const Reference<XPropertySet> & descriptor)67 sdbcx::ObjectType OKeys::appendObject( const ::rtl::OUString&, const Reference< XPropertySet >& descriptor )
68 {
69     OAdoKey* pKey = NULL;
70     if ( !getImplementation( pKey, descriptor ) || pKey == NULL)
71         m_pConnection->throwGenericSQLException( STR_INVALID_KEY_DESCRIPTOR_ERROR,static_cast<XTypeProvider*>(this) );
72 
73     // To pass as column parameter to Key's Apppend method
74     OLEVariant vOptional;
75     vOptional.setNoArg();
76 
77 #if OSL_DEBUG_LEVEL > 0
78     KeyTypeEnum eKey =
79 #endif
80         OAdoKey::Map2KeyRule(getINT32(descriptor->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))));
81 #if OSL_DEBUG_LEVEL > 0
82     (void)eKey;
83 #endif
84 
85     WpADOKey aKey = pKey->getImpl();
86     ::rtl::OUString sName = aKey.get_Name();
87     if(!sName.getLength())
88         aKey.put_Name(::rtl::OUString::createFromAscii("PrimaryKey") );
89 
90     ADOKeys* pKeys = m_aCollection;
91     if ( FAILED(pKeys->Append(OLEVariant((ADOKey*)aKey),
92                             adKeyPrimary, // must be every time adKeyPrimary
93                             vOptional)) )
94     {
95         ADOS::ThrowException(*m_pConnection->getConnection(),static_cast<XTypeProvider*>(this));
96         // just make sure that an SQLExceptionis thrown here
97         m_pConnection->throwGenericSQLException( STR_INVALID_KEY_DESCRIPTOR_ERROR,static_cast<XTypeProvider*>(this) );
98     }
99 
100     return new OAdoKey(isCaseSensitive(),m_pConnection,pKey->getImpl());
101 }
102 // -------------------------------------------------------------------------
103 // XDrop
dropObject(sal_Int32,const::rtl::OUString _sElementName)104 void OKeys::dropObject(sal_Int32 /*_nPos*/,const ::rtl::OUString _sElementName)
105 {
106     if(!m_aCollection.Delete(OLEVariant(_sElementName)))
107         ADOS::ThrowException(*m_pConnection->getConnection(),static_cast<XTypeProvider*>(this));
108 }
109 // -----------------------------------------------------------------------------
110 
111 
112