merge the formfield patch from ooo-build
[ooovba.git] / connectivity / source / sdbcx / VKey.cxx
blob553dc9f21f3c533eac1c1118aa596c97c75deb68
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: VKey.cxx,v $
10 * $Revision: 1.18 $
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"
35 #include "connectivity/sdbcx/VKey.hxx"
36 #include <com/sun/star/lang/DisposedException.hpp>
37 #include <com/sun/star/sdbc/KeyRule.hpp>
38 #include <comphelper/sequence.hxx>
39 #include "connectivity/sdbcx/VColumn.hxx"
40 #include "connectivity/sdbcx/VCollection.hxx"
41 #include "TConnection.hxx"
42 // -------------------------------------------------------------------------
43 using namespace connectivity;
44 using namespace connectivity::sdbcx;
45 using namespace ::com::sun::star::beans;
46 using namespace ::com::sun::star::uno;
47 using namespace ::com::sun::star::sdbc;
48 using namespace ::com::sun::star::sdbcx;
49 using namespace ::com::sun::star::container;
50 using namespace ::com::sun::star::lang;
52 // -----------------------------------------------------------------------------
53 ::rtl::OUString SAL_CALL OKey::getImplementationName( ) throw (::com::sun::star::uno::RuntimeException)
55 if(isNew())
56 return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.VKeyDescription");
57 return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.VKey");
59 // -----------------------------------------------------------------------------
60 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL OKey::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException)
62 ::com::sun::star::uno::Sequence< ::rtl::OUString > aSupported(1);
63 if(isNew())
64 aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.KeyDescription");
65 else
66 aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.Key");
68 return aSupported;
70 // -----------------------------------------------------------------------------
71 sal_Bool SAL_CALL OKey::supportsService( const ::rtl::OUString& _rServiceName ) throw(::com::sun::star::uno::RuntimeException)
73 Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames());
74 const ::rtl::OUString* pSupported = aSupported.getConstArray();
75 const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
76 for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
79 return pSupported != pEnd;
81 // -------------------------------------------------------------------------
82 OKey::OKey(sal_Bool _bCase) : ODescriptor_BASE(m_aMutex)
83 , ODescriptor(ODescriptor_BASE::rBHelper,_bCase,sal_True)
84 , m_aProps(new KeyProperties())
85 , m_pColumns(NULL)
88 // -------------------------------------------------------------------------
89 OKey::OKey(const ::rtl::OUString& _Name,const TKeyProperties& _rProps,sal_Bool _bCase)
90 : ODescriptor_BASE(m_aMutex)
91 ,ODescriptor(ODescriptor_BASE::rBHelper,_bCase)
92 ,m_aProps(_rProps)
93 ,m_pColumns(NULL)
95 m_Name = _Name;
97 //OKey::OKey( const ::rtl::OUString& _Name,
98 // const ::rtl::OUString& _ReferencedTable,
99 // sal_Int32 _Type,
100 // sal_Int32 _UpdateRule,
101 // sal_Int32 _DeleteRule,
102 // sal_Bool _bCase) : ODescriptor_BASE(m_aMutex)
103 // ,ODescriptor(ODescriptor_BASE::rBHelper,_bCase)
104 // ,m_ReferencedTable(_ReferencedTable)
105 // ,m_Type(_Type)
106 // ,m_UpdateRule(_UpdateRule)
107 // ,m_DeleteRule(_DeleteRule)
108 // ,m_pColumns(NULL)
110 // m_Name = _Name;
112 // -------------------------------------------------------------------------
113 OKey::~OKey( )
115 delete m_pColumns;
117 // -------------------------------------------------------------------------
118 Any SAL_CALL OKey::queryInterface( const Type & rType ) throw(RuntimeException)
120 Any aRet = ODescriptor::queryInterface( rType);
121 if(!aRet.hasValue())
123 if(!isNew())
124 aRet = OKey_BASE::queryInterface(rType);
125 if(!aRet.hasValue())
126 aRet = ODescriptor_BASE::queryInterface( rType);
129 return aRet;
131 // -------------------------------------------------------------------------
132 Sequence< Type > SAL_CALL OKey::getTypes( ) throw(RuntimeException)
134 if(isNew())
135 return ::comphelper::concatSequences(ODescriptor::getTypes(),ODescriptor_BASE::getTypes());
137 return ::comphelper::concatSequences(ODescriptor::getTypes(),ODescriptor_BASE::getTypes(),OKey_BASE::getTypes());
139 // -------------------------------------------------------------------------
140 void OKey::construct()
142 ODescriptor::construct();
144 sal_Int32 nAttrib = isNew() ? 0 : PropertyAttribute::READONLY;
146 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REFERENCEDTABLE), PROPERTY_ID_REFERENCEDTABLE, nAttrib,&m_aProps->m_ReferencedTable, ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL)));
147 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE), PROPERTY_ID_TYPE, nAttrib,&m_aProps->m_Type, ::getCppuType(reinterpret_cast<sal_Int32*>(NULL)));
148 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_UPDATERULE), PROPERTY_ID_UPDATERULE, nAttrib,&m_aProps->m_UpdateRule, ::getCppuType(reinterpret_cast<sal_Int32*>(NULL)));
149 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DELETERULE), PROPERTY_ID_DELETERULE, nAttrib,&m_aProps->m_DeleteRule, ::getCppuType(reinterpret_cast<sal_Int32*>(NULL)));
151 // -------------------------------------------------------------------------
152 void SAL_CALL OKey::disposing()
154 OPropertySetHelper::disposing();
156 ::osl::MutexGuard aGuard(m_aMutex);
158 if(m_pColumns)
159 m_pColumns->disposing();
161 ODescriptor_BASE::disposing();
163 // -------------------------------------------------------------------------
164 ::cppu::IPropertyArrayHelper* OKey::createArrayHelper( sal_Int32 /*_nId*/ ) const
166 return doCreateArrayHelper();
168 // -------------------------------------------------------------------------
169 ::cppu::IPropertyArrayHelper & OKey::getInfoHelper()
171 return *const_cast<OKey*>(this)->getArrayHelper(isNew() ? 1 : 0);
173 // -------------------------------------------------------------------------
174 Reference< ::com::sun::star::container::XNameAccess > SAL_CALL OKey::getColumns( ) throw(RuntimeException)
176 ::osl::MutexGuard aGuard(m_aMutex);
177 checkDisposed(ODescriptor_BASE::rBHelper.bDisposed);
181 if ( !m_pColumns )
182 refreshColumns();
184 catch( const RuntimeException& )
186 // allowed to leave this method
187 throw;
189 catch( const Exception& )
191 // allowed
194 return const_cast<OKey*>(this)->m_pColumns;
196 // -------------------------------------------------------------------------
197 Reference< XPropertySet > SAL_CALL OKey::createDataDescriptor( ) throw(RuntimeException)
199 ::osl::MutexGuard aGuard(m_aMutex);
200 checkDisposed(ODescriptor_BASE::rBHelper.bDisposed);
203 return this;
205 // -----------------------------------------------------------------------------
206 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OKey::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException)
208 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
210 // -----------------------------------------------------------------------------
211 ::rtl::OUString SAL_CALL OKey::getName( ) throw(::com::sun::star::uno::RuntimeException)
213 return m_Name;
215 // -----------------------------------------------------------------------------
216 void SAL_CALL OKey::setName( const ::rtl::OUString& /*aName*/ ) throw(::com::sun::star::uno::RuntimeException)
219 // -----------------------------------------------------------------------------
220 // XInterface
221 void SAL_CALL OKey::acquire() throw()
223 ODescriptor_BASE::acquire();
225 // -----------------------------------------------------------------------------
226 void SAL_CALL OKey::release() throw()
228 ODescriptor_BASE::release();
230 // -----------------------------------------------------------------------------