bump product version to 4.1.6.2
[LibreOffice.git] / connectivity / source / sdbcx / VKey.cxx
blob0f1ed7294c53b2548c66ab8f376795a6a0adc7e1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "connectivity/sdbcx/VKey.hxx"
21 #include <com/sun/star/lang/DisposedException.hpp>
22 #include <com/sun/star/sdbc/KeyRule.hpp>
23 #include <comphelper/sequence.hxx>
24 #include "connectivity/sdbcx/VColumn.hxx"
25 #include "connectivity/sdbcx/VCollection.hxx"
26 #include "TConnection.hxx"
27 // -------------------------------------------------------------------------
28 using namespace connectivity;
29 using namespace connectivity::sdbcx;
30 using namespace ::com::sun::star::beans;
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star::sdbc;
33 using namespace ::com::sun::star::sdbcx;
34 using namespace ::com::sun::star::container;
35 using namespace ::com::sun::star::lang;
37 // -----------------------------------------------------------------------------
38 OUString SAL_CALL OKey::getImplementationName( ) throw (::com::sun::star::uno::RuntimeException)
40 if(isNew())
41 return OUString("com.sun.star.sdbcx.VKeyDescription");
42 return OUString("com.sun.star.sdbcx.VKey");
44 // -----------------------------------------------------------------------------
45 ::com::sun::star::uno::Sequence< OUString > SAL_CALL OKey::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException)
47 ::com::sun::star::uno::Sequence< OUString > aSupported(1);
48 if(isNew())
49 aSupported[0] = OUString("com.sun.star.sdbcx.KeyDescription");
50 else
51 aSupported[0] = OUString("com.sun.star.sdbcx.Key");
53 return aSupported;
55 // -----------------------------------------------------------------------------
56 sal_Bool SAL_CALL OKey::supportsService( const OUString& _rServiceName ) throw(::com::sun::star::uno::RuntimeException)
58 Sequence< OUString > aSupported(getSupportedServiceNames());
59 const OUString* pSupported = aSupported.getConstArray();
60 const OUString* pEnd = pSupported + aSupported.getLength();
61 for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
64 return pSupported != pEnd;
66 // -------------------------------------------------------------------------
67 OKey::OKey(sal_Bool _bCase) : ODescriptor_BASE(m_aMutex)
68 , ODescriptor(ODescriptor_BASE::rBHelper,_bCase,sal_True)
69 , m_aProps(new KeyProperties())
70 , m_pColumns(NULL)
73 // -------------------------------------------------------------------------
74 OKey::OKey(const OUString& _Name,const TKeyProperties& _rProps,sal_Bool _bCase)
75 : ODescriptor_BASE(m_aMutex)
76 ,ODescriptor(ODescriptor_BASE::rBHelper,_bCase)
77 ,m_aProps(_rProps)
78 ,m_pColumns(NULL)
80 m_Name = _Name;
82 //OKey::OKey( const OUString& _Name,
83 // const OUString& _ReferencedTable,
84 // sal_Int32 _Type,
85 // sal_Int32 _UpdateRule,
86 // sal_Int32 _DeleteRule,
87 // sal_Bool _bCase) : ODescriptor_BASE(m_aMutex)
88 // ,ODescriptor(ODescriptor_BASE::rBHelper,_bCase)
89 // ,m_ReferencedTable(_ReferencedTable)
90 // ,m_Type(_Type)
91 // ,m_UpdateRule(_UpdateRule)
92 // ,m_DeleteRule(_DeleteRule)
93 // ,m_pColumns(NULL)
94 //{
95 // m_Name = _Name;
96 //}
97 // -------------------------------------------------------------------------
98 OKey::~OKey( )
100 delete m_pColumns;
102 // -------------------------------------------------------------------------
103 Any SAL_CALL OKey::queryInterface( const Type & rType ) throw(RuntimeException)
105 Any aRet = ODescriptor::queryInterface( rType);
106 if(!aRet.hasValue())
108 if(!isNew())
109 aRet = OKey_BASE::queryInterface(rType);
110 if(!aRet.hasValue())
111 aRet = ODescriptor_BASE::queryInterface( rType);
114 return aRet;
116 // -------------------------------------------------------------------------
117 Sequence< Type > SAL_CALL OKey::getTypes( ) throw(RuntimeException)
119 if(isNew())
120 return ::comphelper::concatSequences(ODescriptor::getTypes(),ODescriptor_BASE::getTypes());
122 return ::comphelper::concatSequences(ODescriptor::getTypes(),ODescriptor_BASE::getTypes(),OKey_BASE::getTypes());
124 // -------------------------------------------------------------------------
125 void OKey::construct()
127 ODescriptor::construct();
129 sal_Int32 nAttrib = isNew() ? 0 : PropertyAttribute::READONLY;
131 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REFERENCEDTABLE), PROPERTY_ID_REFERENCEDTABLE, nAttrib,&m_aProps->m_ReferencedTable, ::getCppuType(static_cast< OUString*>(0)));
132 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE), PROPERTY_ID_TYPE, nAttrib,&m_aProps->m_Type, ::getCppuType(static_cast<sal_Int32*>(0)));
133 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_UPDATERULE), PROPERTY_ID_UPDATERULE, nAttrib,&m_aProps->m_UpdateRule, ::getCppuType(static_cast<sal_Int32*>(0)));
134 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DELETERULE), PROPERTY_ID_DELETERULE, nAttrib,&m_aProps->m_DeleteRule, ::getCppuType(static_cast<sal_Int32*>(0)));
136 // -------------------------------------------------------------------------
137 void SAL_CALL OKey::disposing()
139 OPropertySetHelper::disposing();
141 ::osl::MutexGuard aGuard(m_aMutex);
143 if(m_pColumns)
144 m_pColumns->disposing();
146 ODescriptor_BASE::disposing();
148 // -------------------------------------------------------------------------
149 ::cppu::IPropertyArrayHelper* OKey::createArrayHelper( sal_Int32 /*_nId*/ ) const
151 return doCreateArrayHelper();
153 // -------------------------------------------------------------------------
154 ::cppu::IPropertyArrayHelper & OKey::getInfoHelper()
156 return *const_cast<OKey*>(this)->getArrayHelper(isNew() ? 1 : 0);
158 // -------------------------------------------------------------------------
159 Reference< ::com::sun::star::container::XNameAccess > SAL_CALL OKey::getColumns( ) throw(RuntimeException)
161 ::osl::MutexGuard aGuard(m_aMutex);
162 checkDisposed(ODescriptor_BASE::rBHelper.bDisposed);
166 if ( !m_pColumns )
167 refreshColumns();
169 catch( const RuntimeException& )
171 // allowed to leave this method
172 throw;
174 catch( const Exception& )
176 // allowed
179 return const_cast<OKey*>(this)->m_pColumns;
181 // -------------------------------------------------------------------------
182 Reference< XPropertySet > SAL_CALL OKey::createDataDescriptor( ) throw(RuntimeException)
184 ::osl::MutexGuard aGuard(m_aMutex);
185 checkDisposed(ODescriptor_BASE::rBHelper.bDisposed);
188 return this;
190 // -----------------------------------------------------------------------------
191 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OKey::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException)
193 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
195 // -----------------------------------------------------------------------------
196 OUString SAL_CALL OKey::getName( ) throw(::com::sun::star::uno::RuntimeException)
198 return m_Name;
200 // -----------------------------------------------------------------------------
201 void SAL_CALL OKey::setName( const OUString& /*aName*/ ) throw(::com::sun::star::uno::RuntimeException)
204 // -----------------------------------------------------------------------------
205 // XInterface
206 void SAL_CALL OKey::acquire() throw()
208 ODescriptor_BASE::acquire();
210 // -----------------------------------------------------------------------------
211 void SAL_CALL OKey::release() throw()
213 ODescriptor_BASE::release();
215 // -----------------------------------------------------------------------------
217 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */