xref: /trunk/main/connectivity/source/sdbcx/VKey.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
19b5730f6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
39b5730f6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
49b5730f6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
59b5730f6SAndrew Rist  * distributed with this work for additional information
69b5730f6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
79b5730f6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
89b5730f6SAndrew Rist  * "License"); you may not use this file except in compliance
99b5730f6SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
119b5730f6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
139b5730f6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
149b5730f6SAndrew Rist  * software distributed under the License is distributed on an
159b5730f6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
169b5730f6SAndrew Rist  * KIND, either express or implied.  See the License for the
179b5730f6SAndrew Rist  * specific language governing permissions and limitations
189b5730f6SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
209b5730f6SAndrew Rist  *************************************************************/
219b5730f6SAndrew Rist 
229b5730f6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_connectivity.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include "connectivity/sdbcx/VKey.hxx"
29cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
30cdf0e10cSrcweir #include <com/sun/star/sdbc/KeyRule.hpp>
31cdf0e10cSrcweir #include <comphelper/sequence.hxx>
32cdf0e10cSrcweir #include "connectivity/sdbcx/VColumn.hxx"
33cdf0e10cSrcweir #include "connectivity/sdbcx/VCollection.hxx"
34cdf0e10cSrcweir #include "TConnection.hxx"
35cdf0e10cSrcweir // -------------------------------------------------------------------------
36cdf0e10cSrcweir using namespace connectivity;
37cdf0e10cSrcweir using namespace connectivity::sdbcx;
38cdf0e10cSrcweir using namespace ::com::sun::star::beans;
39cdf0e10cSrcweir using namespace ::com::sun::star::uno;
40cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
41cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx;
42cdf0e10cSrcweir using namespace ::com::sun::star::container;
43cdf0e10cSrcweir using namespace ::com::sun::star::lang;
44cdf0e10cSrcweir 
45cdf0e10cSrcweir // -----------------------------------------------------------------------------
getImplementationName()46cdf0e10cSrcweir ::rtl::OUString SAL_CALL OKey::getImplementationName(  ) throw (::com::sun::star::uno::RuntimeException)
47cdf0e10cSrcweir {
48cdf0e10cSrcweir     if(isNew())
49ac472dbcSDamjan Jovanovic         return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.VKeyDescriptor");
50cdf0e10cSrcweir     return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.VKey");
51cdf0e10cSrcweir }
52cdf0e10cSrcweir // -----------------------------------------------------------------------------
getSupportedServiceNames()53cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL OKey::getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException)
54cdf0e10cSrcweir {
55cdf0e10cSrcweir     ::com::sun::star::uno::Sequence< ::rtl::OUString > aSupported(1);
56cdf0e10cSrcweir     if(isNew())
57ac472dbcSDamjan Jovanovic         aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.KeyDescriptor");
58cdf0e10cSrcweir     else
59cdf0e10cSrcweir         aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.Key");
60cdf0e10cSrcweir 
61cdf0e10cSrcweir     return aSupported;
62cdf0e10cSrcweir }
63cdf0e10cSrcweir // -----------------------------------------------------------------------------
supportsService(const::rtl::OUString & _rServiceName)64cdf0e10cSrcweir sal_Bool SAL_CALL OKey::supportsService( const ::rtl::OUString& _rServiceName ) throw(::com::sun::star::uno::RuntimeException)
65cdf0e10cSrcweir {
66cdf0e10cSrcweir     Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames());
67cdf0e10cSrcweir     const ::rtl::OUString* pSupported = aSupported.getConstArray();
68cdf0e10cSrcweir     const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
69cdf0e10cSrcweir     for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
70cdf0e10cSrcweir         ;
71cdf0e10cSrcweir 
72cdf0e10cSrcweir     return pSupported != pEnd;
73cdf0e10cSrcweir }
74cdf0e10cSrcweir // -------------------------------------------------------------------------
OKey(sal_Bool _bCase)75cdf0e10cSrcweir OKey::OKey(sal_Bool _bCase) :   ODescriptor_BASE(m_aMutex)
76cdf0e10cSrcweir             ,   ODescriptor(ODescriptor_BASE::rBHelper,_bCase,sal_True)
77cdf0e10cSrcweir             ,   m_aProps(new KeyProperties())
78cdf0e10cSrcweir             ,   m_pColumns(NULL)
79cdf0e10cSrcweir {
80cdf0e10cSrcweir }
81cdf0e10cSrcweir // -------------------------------------------------------------------------
OKey(const::rtl::OUString & _Name,const TKeyProperties & _rProps,sal_Bool _bCase)82cdf0e10cSrcweir OKey::OKey(const ::rtl::OUString& _Name,const TKeyProperties& _rProps,sal_Bool _bCase)
83cdf0e10cSrcweir : ODescriptor_BASE(m_aMutex)
84cdf0e10cSrcweir  ,ODescriptor(ODescriptor_BASE::rBHelper,_bCase)
85cdf0e10cSrcweir  ,m_aProps(_rProps)
86cdf0e10cSrcweir  ,m_pColumns(NULL)
87cdf0e10cSrcweir {
88cdf0e10cSrcweir     m_Name = _Name;
89cdf0e10cSrcweir }
90cdf0e10cSrcweir //OKey::OKey(   const ::rtl::OUString& _Name,
91cdf0e10cSrcweir //          const ::rtl::OUString& _ReferencedTable,
92cdf0e10cSrcweir //          sal_Int32       _Type,
93cdf0e10cSrcweir //          sal_Int32       _UpdateRule,
94cdf0e10cSrcweir //          sal_Int32       _DeleteRule,
95cdf0e10cSrcweir //          sal_Bool _bCase) :  ODescriptor_BASE(m_aMutex)
96cdf0e10cSrcweir //                      ,ODescriptor(ODescriptor_BASE::rBHelper,_bCase)
97cdf0e10cSrcweir //                      ,m_ReferencedTable(_ReferencedTable)
98cdf0e10cSrcweir //                      ,m_Type(_Type)
99cdf0e10cSrcweir //                      ,m_UpdateRule(_UpdateRule)
100cdf0e10cSrcweir //                      ,m_DeleteRule(_DeleteRule)
101cdf0e10cSrcweir //                        ,m_pColumns(NULL)
102cdf0e10cSrcweir //{
103cdf0e10cSrcweir //  m_Name = _Name;
104cdf0e10cSrcweir //}
105cdf0e10cSrcweir // -------------------------------------------------------------------------
~OKey()106cdf0e10cSrcweir OKey::~OKey( )
107cdf0e10cSrcweir {
108cdf0e10cSrcweir     delete m_pColumns;
109cdf0e10cSrcweir }
110cdf0e10cSrcweir // -------------------------------------------------------------------------
queryInterface(const Type & rType)111cdf0e10cSrcweir Any SAL_CALL OKey::queryInterface( const Type & rType ) throw(RuntimeException)
112cdf0e10cSrcweir {
113cdf0e10cSrcweir     Any aRet = ODescriptor::queryInterface( rType);
114cdf0e10cSrcweir     if(!aRet.hasValue())
115cdf0e10cSrcweir     {
116cdf0e10cSrcweir         if(!isNew())
117cdf0e10cSrcweir             aRet = OKey_BASE::queryInterface(rType);
118cdf0e10cSrcweir         if(!aRet.hasValue())
119cdf0e10cSrcweir             aRet = ODescriptor_BASE::queryInterface( rType);
120cdf0e10cSrcweir     }
121cdf0e10cSrcweir 
122cdf0e10cSrcweir     return aRet;
123cdf0e10cSrcweir }
124cdf0e10cSrcweir // -------------------------------------------------------------------------
getTypes()125cdf0e10cSrcweir Sequence< Type > SAL_CALL OKey::getTypes(  ) throw(RuntimeException)
126cdf0e10cSrcweir {
127cdf0e10cSrcweir     if(isNew())
128cdf0e10cSrcweir         return ::comphelper::concatSequences(ODescriptor::getTypes(),ODescriptor_BASE::getTypes());
129cdf0e10cSrcweir 
130cdf0e10cSrcweir     return ::comphelper::concatSequences(ODescriptor::getTypes(),ODescriptor_BASE::getTypes(),OKey_BASE::getTypes());
131cdf0e10cSrcweir }
132cdf0e10cSrcweir // -------------------------------------------------------------------------
construct()133cdf0e10cSrcweir void OKey::construct()
134cdf0e10cSrcweir {
135cdf0e10cSrcweir     ODescriptor::construct();
136cdf0e10cSrcweir 
137cdf0e10cSrcweir     sal_Int32 nAttrib = isNew() ? 0 : PropertyAttribute::READONLY;
138cdf0e10cSrcweir 
139*bccc1572SDon Lewis     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REFERENCEDTABLE), PROPERTY_ID_REFERENCEDTABLE,    nAttrib,&m_aProps->m_ReferencedTable,   ::getCppuType(static_cast< ::rtl::OUString*>(NULL)));
140*bccc1572SDon Lewis     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE),            PROPERTY_ID_TYPE,               nAttrib,&m_aProps->m_Type,          ::getCppuType(static_cast<sal_Int32*>(NULL)));
141*bccc1572SDon Lewis     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_UPDATERULE),      PROPERTY_ID_UPDATERULE,         nAttrib,&m_aProps->m_UpdateRule,        ::getCppuType(static_cast<sal_Int32*>(NULL)));
142*bccc1572SDon Lewis     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DELETERULE),      PROPERTY_ID_DELETERULE,         nAttrib,&m_aProps->m_DeleteRule,        ::getCppuType(static_cast<sal_Int32*>(NULL)));
143cdf0e10cSrcweir }
144cdf0e10cSrcweir // -------------------------------------------------------------------------
disposing()145cdf0e10cSrcweir void SAL_CALL OKey::disposing()
146cdf0e10cSrcweir {
147cdf0e10cSrcweir     OPropertySetHelper::disposing();
148cdf0e10cSrcweir 
149cdf0e10cSrcweir     ::osl::MutexGuard aGuard(m_aMutex);
150cdf0e10cSrcweir 
151cdf0e10cSrcweir     if(m_pColumns)
152cdf0e10cSrcweir         m_pColumns->disposing();
153cdf0e10cSrcweir 
154cdf0e10cSrcweir     ODescriptor_BASE::disposing();
155cdf0e10cSrcweir }
156cdf0e10cSrcweir // -------------------------------------------------------------------------
createArrayHelper(sal_Int32) const157cdf0e10cSrcweir ::cppu::IPropertyArrayHelper* OKey::createArrayHelper( sal_Int32 /*_nId*/ ) const
158cdf0e10cSrcweir {
159cdf0e10cSrcweir     return doCreateArrayHelper();
160cdf0e10cSrcweir }
161cdf0e10cSrcweir // -------------------------------------------------------------------------
getInfoHelper()162cdf0e10cSrcweir ::cppu::IPropertyArrayHelper & OKey::getInfoHelper()
163cdf0e10cSrcweir {
164cdf0e10cSrcweir     return *const_cast<OKey*>(this)->getArrayHelper(isNew() ? 1 : 0);
165cdf0e10cSrcweir }
166cdf0e10cSrcweir // -------------------------------------------------------------------------
getColumns()167cdf0e10cSrcweir Reference< ::com::sun::star::container::XNameAccess > SAL_CALL OKey::getColumns(  ) throw(RuntimeException)
168cdf0e10cSrcweir {
169cdf0e10cSrcweir     ::osl::MutexGuard aGuard(m_aMutex);
170cdf0e10cSrcweir     checkDisposed(ODescriptor_BASE::rBHelper.bDisposed);
171cdf0e10cSrcweir 
172cdf0e10cSrcweir     try
173cdf0e10cSrcweir     {
174cdf0e10cSrcweir         if ( !m_pColumns )
175cdf0e10cSrcweir             refreshColumns();
176cdf0e10cSrcweir     }
177cdf0e10cSrcweir     catch( const RuntimeException& )
178cdf0e10cSrcweir     {
179cdf0e10cSrcweir         // allowed to leave this method
180cdf0e10cSrcweir         throw;
181cdf0e10cSrcweir     }
182cdf0e10cSrcweir     catch( const Exception& )
183cdf0e10cSrcweir     {
184cdf0e10cSrcweir         // allowed
185cdf0e10cSrcweir     }
186cdf0e10cSrcweir 
187cdf0e10cSrcweir     return const_cast<OKey*>(this)->m_pColumns;
188cdf0e10cSrcweir }
189cdf0e10cSrcweir // -------------------------------------------------------------------------
createDataDescriptor()190cdf0e10cSrcweir Reference< XPropertySet > SAL_CALL OKey::createDataDescriptor(  ) throw(RuntimeException)
191cdf0e10cSrcweir {
192cdf0e10cSrcweir     ::osl::MutexGuard aGuard(m_aMutex);
193cdf0e10cSrcweir     checkDisposed(ODescriptor_BASE::rBHelper.bDisposed);
194cdf0e10cSrcweir 
195cdf0e10cSrcweir 
196cdf0e10cSrcweir     return this;
197cdf0e10cSrcweir }
198cdf0e10cSrcweir // -----------------------------------------------------------------------------
getPropertySetInfo()199cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OKey::getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException)
200cdf0e10cSrcweir {
201cdf0e10cSrcweir     return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
202cdf0e10cSrcweir }
203cdf0e10cSrcweir // -----------------------------------------------------------------------------
getName()204cdf0e10cSrcweir ::rtl::OUString SAL_CALL OKey::getName(  ) throw(::com::sun::star::uno::RuntimeException)
205cdf0e10cSrcweir {
206cdf0e10cSrcweir     return m_Name;
207cdf0e10cSrcweir }
208cdf0e10cSrcweir // -----------------------------------------------------------------------------
setName(const::rtl::OUString &)209cdf0e10cSrcweir void SAL_CALL OKey::setName( const ::rtl::OUString& /*aName*/ ) throw(::com::sun::star::uno::RuntimeException)
210cdf0e10cSrcweir {
211cdf0e10cSrcweir }
212cdf0e10cSrcweir // -----------------------------------------------------------------------------
213cdf0e10cSrcweir // XInterface
acquire()214cdf0e10cSrcweir void SAL_CALL OKey::acquire() throw()
215cdf0e10cSrcweir {
216cdf0e10cSrcweir     ODescriptor_BASE::acquire();
217cdf0e10cSrcweir }
218cdf0e10cSrcweir // -----------------------------------------------------------------------------
release()219cdf0e10cSrcweir void SAL_CALL OKey::release() throw()
220cdf0e10cSrcweir {
221cdf0e10cSrcweir     ODescriptor_BASE::release();
222cdf0e10cSrcweir }
223cdf0e10cSrcweir // -----------------------------------------------------------------------------
224