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
27
28 #include "connectivity/sdbcx/VKey.hxx"
29 #include <com/sun/star/lang/DisposedException.hpp>
30 #include <com/sun/star/sdbc/KeyRule.hpp>
31 #include <comphelper/sequence.hxx>
32 #include "connectivity/sdbcx/VColumn.hxx"
33 #include "connectivity/sdbcx/VCollection.hxx"
34 #include "TConnection.hxx"
35 // -------------------------------------------------------------------------
36 using namespace connectivity;
37 using namespace connectivity::sdbcx;
38 using namespace ::com::sun::star::beans;
39 using namespace ::com::sun::star::uno;
40 using namespace ::com::sun::star::sdbc;
41 using namespace ::com::sun::star::sdbcx;
42 using namespace ::com::sun::star::container;
43 using namespace ::com::sun::star::lang;
44
45 // -----------------------------------------------------------------------------
getImplementationName()46 ::rtl::OUString SAL_CALL OKey::getImplementationName( ) throw (::com::sun::star::uno::RuntimeException)
47 {
48 if(isNew())
49 return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.VKeyDescriptor");
50 return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.VKey");
51 }
52 // -----------------------------------------------------------------------------
getSupportedServiceNames()53 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL OKey::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException)
54 {
55 ::com::sun::star::uno::Sequence< ::rtl::OUString > aSupported(1);
56 if(isNew())
57 aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.KeyDescriptor");
58 else
59 aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.Key");
60
61 return aSupported;
62 }
63 // -----------------------------------------------------------------------------
supportsService(const::rtl::OUString & _rServiceName)64 sal_Bool SAL_CALL OKey::supportsService( const ::rtl::OUString& _rServiceName ) throw(::com::sun::star::uno::RuntimeException)
65 {
66 Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames());
67 const ::rtl::OUString* pSupported = aSupported.getConstArray();
68 const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
69 for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
70 ;
71
72 return pSupported != pEnd;
73 }
74 // -------------------------------------------------------------------------
OKey(sal_Bool _bCase)75 OKey::OKey(sal_Bool _bCase) : ODescriptor_BASE(m_aMutex)
76 , ODescriptor(ODescriptor_BASE::rBHelper,_bCase,sal_True)
77 , m_aProps(new KeyProperties())
78 , m_pColumns(NULL)
79 {
80 }
81 // -------------------------------------------------------------------------
OKey(const::rtl::OUString & _Name,const TKeyProperties & _rProps,sal_Bool _bCase)82 OKey::OKey(const ::rtl::OUString& _Name,const TKeyProperties& _rProps,sal_Bool _bCase)
83 : ODescriptor_BASE(m_aMutex)
84 ,ODescriptor(ODescriptor_BASE::rBHelper,_bCase)
85 ,m_aProps(_rProps)
86 ,m_pColumns(NULL)
87 {
88 m_Name = _Name;
89 }
90 //OKey::OKey( const ::rtl::OUString& _Name,
91 // const ::rtl::OUString& _ReferencedTable,
92 // sal_Int32 _Type,
93 // sal_Int32 _UpdateRule,
94 // sal_Int32 _DeleteRule,
95 // sal_Bool _bCase) : ODescriptor_BASE(m_aMutex)
96 // ,ODescriptor(ODescriptor_BASE::rBHelper,_bCase)
97 // ,m_ReferencedTable(_ReferencedTable)
98 // ,m_Type(_Type)
99 // ,m_UpdateRule(_UpdateRule)
100 // ,m_DeleteRule(_DeleteRule)
101 // ,m_pColumns(NULL)
102 //{
103 // m_Name = _Name;
104 //}
105 // -------------------------------------------------------------------------
~OKey()106 OKey::~OKey( )
107 {
108 delete m_pColumns;
109 }
110 // -------------------------------------------------------------------------
queryInterface(const Type & rType)111 Any SAL_CALL OKey::queryInterface( const Type & rType ) throw(RuntimeException)
112 {
113 Any aRet = ODescriptor::queryInterface( rType);
114 if(!aRet.hasValue())
115 {
116 if(!isNew())
117 aRet = OKey_BASE::queryInterface(rType);
118 if(!aRet.hasValue())
119 aRet = ODescriptor_BASE::queryInterface( rType);
120 }
121
122 return aRet;
123 }
124 // -------------------------------------------------------------------------
getTypes()125 Sequence< Type > SAL_CALL OKey::getTypes( ) throw(RuntimeException)
126 {
127 if(isNew())
128 return ::comphelper::concatSequences(ODescriptor::getTypes(),ODescriptor_BASE::getTypes());
129
130 return ::comphelper::concatSequences(ODescriptor::getTypes(),ODescriptor_BASE::getTypes(),OKey_BASE::getTypes());
131 }
132 // -------------------------------------------------------------------------
construct()133 void OKey::construct()
134 {
135 ODescriptor::construct();
136
137 sal_Int32 nAttrib = isNew() ? 0 : PropertyAttribute::READONLY;
138
139 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REFERENCEDTABLE), PROPERTY_ID_REFERENCEDTABLE, nAttrib,&m_aProps->m_ReferencedTable, ::getCppuType(static_cast< ::rtl::OUString*>(NULL)));
140 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE), PROPERTY_ID_TYPE, nAttrib,&m_aProps->m_Type, ::getCppuType(static_cast<sal_Int32*>(NULL)));
141 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_UPDATERULE), PROPERTY_ID_UPDATERULE, nAttrib,&m_aProps->m_UpdateRule, ::getCppuType(static_cast<sal_Int32*>(NULL)));
142 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DELETERULE), PROPERTY_ID_DELETERULE, nAttrib,&m_aProps->m_DeleteRule, ::getCppuType(static_cast<sal_Int32*>(NULL)));
143 }
144 // -------------------------------------------------------------------------
disposing()145 void SAL_CALL OKey::disposing()
146 {
147 OPropertySetHelper::disposing();
148
149 ::osl::MutexGuard aGuard(m_aMutex);
150
151 if(m_pColumns)
152 m_pColumns->disposing();
153
154 ODescriptor_BASE::disposing();
155 }
156 // -------------------------------------------------------------------------
createArrayHelper(sal_Int32) const157 ::cppu::IPropertyArrayHelper* OKey::createArrayHelper( sal_Int32 /*_nId*/ ) const
158 {
159 return doCreateArrayHelper();
160 }
161 // -------------------------------------------------------------------------
getInfoHelper()162 ::cppu::IPropertyArrayHelper & OKey::getInfoHelper()
163 {
164 return *const_cast<OKey*>(this)->getArrayHelper(isNew() ? 1 : 0);
165 }
166 // -------------------------------------------------------------------------
getColumns()167 Reference< ::com::sun::star::container::XNameAccess > SAL_CALL OKey::getColumns( ) throw(RuntimeException)
168 {
169 ::osl::MutexGuard aGuard(m_aMutex);
170 checkDisposed(ODescriptor_BASE::rBHelper.bDisposed);
171
172 try
173 {
174 if ( !m_pColumns )
175 refreshColumns();
176 }
177 catch( const RuntimeException& )
178 {
179 // allowed to leave this method
180 throw;
181 }
182 catch( const Exception& )
183 {
184 // allowed
185 }
186
187 return const_cast<OKey*>(this)->m_pColumns;
188 }
189 // -------------------------------------------------------------------------
createDataDescriptor()190 Reference< XPropertySet > SAL_CALL OKey::createDataDescriptor( ) throw(RuntimeException)
191 {
192 ::osl::MutexGuard aGuard(m_aMutex);
193 checkDisposed(ODescriptor_BASE::rBHelper.bDisposed);
194
195
196 return this;
197 }
198 // -----------------------------------------------------------------------------
getPropertySetInfo()199 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OKey::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException)
200 {
201 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
202 }
203 // -----------------------------------------------------------------------------
getName()204 ::rtl::OUString SAL_CALL OKey::getName( ) throw(::com::sun::star::uno::RuntimeException)
205 {
206 return m_Name;
207 }
208 // -----------------------------------------------------------------------------
setName(const::rtl::OUString &)209 void SAL_CALL OKey::setName( const ::rtl::OUString& /*aName*/ ) throw(::com::sun::star::uno::RuntimeException)
210 {
211 }
212 // -----------------------------------------------------------------------------
213 // XInterface
acquire()214 void SAL_CALL OKey::acquire() throw()
215 {
216 ODescriptor_BASE::acquire();
217 }
218 // -----------------------------------------------------------------------------
release()219 void SAL_CALL OKey::release() throw()
220 {
221 ODescriptor_BASE::release();
222 }
223 // -----------------------------------------------------------------------------
224
225