1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AKeys.cxx,v $
10 * $Revision: 1.20.56.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
33 #include "ado/AKeys.hxx"
34 #ifndef _CONNECTIVITY_ADO_INDEX_HXX_
35 #include "ado/AKey.hxx"
37 #include <com/sun/star/sdbc/XRow.hpp>
38 #include <com/sun/star/sdbc/XResultSet.hpp>
39 #include <com/sun/star/sdbcx/KeyType.hpp>
40 #include <com/sun/star/sdbc/KeyRule.hpp>
41 #include "ado/AConnection.hxx"
42 #include <comphelper/types.hxx>
43 #include "ado/Awrapado.hxx"
44 #include <comphelper/property.hxx>
45 #include <connectivity/dbexception.hxx>
46 #include "resource/ado_res.hrc"
48 using namespace ::comphelper
;
49 using namespace connectivity
;
50 using namespace connectivity::ado
;
51 using namespace com::sun::star::uno
;
52 using namespace com::sun::star::lang
;
53 using namespace com::sun::star::beans
;
54 using namespace com::sun::star::sdbc
;
55 using namespace com::sun::star::sdbcx
;
56 using namespace com::sun::star::container
;
58 sdbcx::ObjectType
OKeys::createObject(const ::rtl::OUString
& _rName
)
60 return new OAdoKey(isCaseSensitive(),m_pConnection
,m_aCollection
.GetItem(_rName
));
62 // -------------------------------------------------------------------------
63 void OKeys::impl_refresh() throw(RuntimeException
)
65 m_aCollection
.Refresh();
67 // -------------------------------------------------------------------------
68 Reference
< XPropertySet
> OKeys::createDescriptor()
70 return new OAdoKey(isCaseSensitive(),m_pConnection
);
72 // -------------------------------------------------------------------------
74 sdbcx::ObjectType
OKeys::appendObject( const ::rtl::OUString
&, const Reference
< XPropertySet
>& descriptor
)
77 if ( !getImplementation( pKey
, descriptor
) || pKey
== NULL
)
78 m_pConnection
->throwGenericSQLException( STR_INVALID_KEY_DESCRIPTOR_ERROR
,static_cast<XTypeProvider
*>(this) );
80 // To pass as column parameter to Key's Apppend method
84 #if OSL_DEBUG_LEVEL > 0
87 OAdoKey::Map2KeyRule(getINT32(descriptor
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE
))));
88 #if OSL_DEBUG_LEVEL > 0
92 WpADOKey aKey
= pKey
->getImpl();
93 ::rtl::OUString sName
= aKey
.get_Name();
94 if(!sName
.getLength())
95 aKey
.put_Name(::rtl::OUString::createFromAscii("PrimaryKey") );
97 ADOKeys
* pKeys
= m_aCollection
;
98 if ( FAILED(pKeys
->Append(OLEVariant((ADOKey
*)aKey
),
99 adKeyPrimary
, // must be every time adKeyPrimary
102 ADOS::ThrowException(*m_pConnection
->getConnection(),static_cast<XTypeProvider
*>(this));
103 // just make sure that an SQLExceptionis thrown here
104 m_pConnection
->throwGenericSQLException( STR_INVALID_KEY_DESCRIPTOR_ERROR
,static_cast<XTypeProvider
*>(this) );
107 return new OAdoKey(isCaseSensitive(),m_pConnection
,pKey
->getImpl());
109 // -------------------------------------------------------------------------
111 void OKeys::dropObject(sal_Int32
/*_nPos*/,const ::rtl::OUString _sElementName
)
113 if(!m_aCollection
.Delete(OLEVariant(_sElementName
)))
114 ADOS::ThrowException(*m_pConnection
->getConnection(),static_cast<XTypeProvider
*>(this));
116 // -----------------------------------------------------------------------------