xref: /trunk/main/connectivity/source/sdbcx/VKey.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_connectivity.hxx"
30 
31 
32 #include "connectivity/sdbcx/VKey.hxx"
33 #include <com/sun/star/lang/DisposedException.hpp>
34 #include <com/sun/star/sdbc/KeyRule.hpp>
35 #include <comphelper/sequence.hxx>
36 #include "connectivity/sdbcx/VColumn.hxx"
37 #include "connectivity/sdbcx/VCollection.hxx"
38 #include "TConnection.hxx"
39 // -------------------------------------------------------------------------
40 using namespace connectivity;
41 using namespace connectivity::sdbcx;
42 using namespace ::com::sun::star::beans;
43 using namespace ::com::sun::star::uno;
44 using namespace ::com::sun::star::sdbc;
45 using namespace ::com::sun::star::sdbcx;
46 using namespace ::com::sun::star::container;
47 using namespace ::com::sun::star::lang;
48 
49 // -----------------------------------------------------------------------------
50 ::rtl::OUString SAL_CALL OKey::getImplementationName(  ) throw (::com::sun::star::uno::RuntimeException)
51 {
52     if(isNew())
53         return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.VKeyDescription");
54     return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.VKey");
55 }
56 // -----------------------------------------------------------------------------
57 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL OKey::getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException)
58 {
59     ::com::sun::star::uno::Sequence< ::rtl::OUString > aSupported(1);
60     if(isNew())
61         aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.KeyDescription");
62     else
63         aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.Key");
64 
65     return aSupported;
66 }
67 // -----------------------------------------------------------------------------
68 sal_Bool SAL_CALL OKey::supportsService( const ::rtl::OUString& _rServiceName ) throw(::com::sun::star::uno::RuntimeException)
69 {
70     Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames());
71     const ::rtl::OUString* pSupported = aSupported.getConstArray();
72     const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
73     for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
74         ;
75 
76     return pSupported != pEnd;
77 }
78 // -------------------------------------------------------------------------
79 OKey::OKey(sal_Bool _bCase) :   ODescriptor_BASE(m_aMutex)
80             ,   ODescriptor(ODescriptor_BASE::rBHelper,_bCase,sal_True)
81             ,   m_aProps(new KeyProperties())
82             ,   m_pColumns(NULL)
83 {
84 }
85 // -------------------------------------------------------------------------
86 OKey::OKey(const ::rtl::OUString& _Name,const TKeyProperties& _rProps,sal_Bool _bCase)
87 : ODescriptor_BASE(m_aMutex)
88  ,ODescriptor(ODescriptor_BASE::rBHelper,_bCase)
89  ,m_aProps(_rProps)
90  ,m_pColumns(NULL)
91 {
92     m_Name = _Name;
93 }
94 //OKey::OKey(   const ::rtl::OUString& _Name,
95 //          const ::rtl::OUString& _ReferencedTable,
96 //          sal_Int32       _Type,
97 //          sal_Int32       _UpdateRule,
98 //          sal_Int32       _DeleteRule,
99 //          sal_Bool _bCase) :  ODescriptor_BASE(m_aMutex)
100 //                      ,ODescriptor(ODescriptor_BASE::rBHelper,_bCase)
101 //                      ,m_ReferencedTable(_ReferencedTable)
102 //                      ,m_Type(_Type)
103 //                      ,m_UpdateRule(_UpdateRule)
104 //                      ,m_DeleteRule(_DeleteRule)
105 //                        ,m_pColumns(NULL)
106 //{
107 //  m_Name = _Name;
108 //}
109 // -------------------------------------------------------------------------
110 OKey::~OKey( )
111 {
112     delete m_pColumns;
113 }
114 // -------------------------------------------------------------------------
115 Any SAL_CALL OKey::queryInterface( const Type & rType ) throw(RuntimeException)
116 {
117     Any aRet = ODescriptor::queryInterface( rType);
118     if(!aRet.hasValue())
119     {
120         if(!isNew())
121             aRet = OKey_BASE::queryInterface(rType);
122         if(!aRet.hasValue())
123             aRet = ODescriptor_BASE::queryInterface( rType);
124     }
125 
126     return aRet;
127 }
128 // -------------------------------------------------------------------------
129 Sequence< Type > SAL_CALL OKey::getTypes(  ) throw(RuntimeException)
130 {
131     if(isNew())
132         return ::comphelper::concatSequences(ODescriptor::getTypes(),ODescriptor_BASE::getTypes());
133 
134     return ::comphelper::concatSequences(ODescriptor::getTypes(),ODescriptor_BASE::getTypes(),OKey_BASE::getTypes());
135 }
136 // -------------------------------------------------------------------------
137 void OKey::construct()
138 {
139     ODescriptor::construct();
140 
141     sal_Int32 nAttrib = isNew() ? 0 : PropertyAttribute::READONLY;
142 
143     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REFERENCEDTABLE), PROPERTY_ID_REFERENCEDTABLE,    nAttrib,&m_aProps->m_ReferencedTable,   ::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL)));
144     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE),            PROPERTY_ID_TYPE,               nAttrib,&m_aProps->m_Type,          ::getCppuType(reinterpret_cast<sal_Int32*>(NULL)));
145     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_UPDATERULE),      PROPERTY_ID_UPDATERULE,         nAttrib,&m_aProps->m_UpdateRule,        ::getCppuType(reinterpret_cast<sal_Int32*>(NULL)));
146     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DELETERULE),      PROPERTY_ID_DELETERULE,         nAttrib,&m_aProps->m_DeleteRule,        ::getCppuType(reinterpret_cast<sal_Int32*>(NULL)));
147 }
148 // -------------------------------------------------------------------------
149 void SAL_CALL OKey::disposing()
150 {
151     OPropertySetHelper::disposing();
152 
153     ::osl::MutexGuard aGuard(m_aMutex);
154 
155     if(m_pColumns)
156         m_pColumns->disposing();
157 
158     ODescriptor_BASE::disposing();
159 }
160 // -------------------------------------------------------------------------
161 ::cppu::IPropertyArrayHelper* OKey::createArrayHelper( sal_Int32 /*_nId*/ ) const
162 {
163     return doCreateArrayHelper();
164 }
165 // -------------------------------------------------------------------------
166 ::cppu::IPropertyArrayHelper & OKey::getInfoHelper()
167 {
168     return *const_cast<OKey*>(this)->getArrayHelper(isNew() ? 1 : 0);
169 }
170 // -------------------------------------------------------------------------
171 Reference< ::com::sun::star::container::XNameAccess > SAL_CALL OKey::getColumns(  ) throw(RuntimeException)
172 {
173     ::osl::MutexGuard aGuard(m_aMutex);
174     checkDisposed(ODescriptor_BASE::rBHelper.bDisposed);
175 
176     try
177     {
178         if ( !m_pColumns )
179             refreshColumns();
180     }
181     catch( const RuntimeException& )
182     {
183         // allowed to leave this method
184         throw;
185     }
186     catch( const Exception& )
187     {
188         // allowed
189     }
190 
191     return const_cast<OKey*>(this)->m_pColumns;
192 }
193 // -------------------------------------------------------------------------
194 Reference< XPropertySet > SAL_CALL OKey::createDataDescriptor(  ) throw(RuntimeException)
195 {
196     ::osl::MutexGuard aGuard(m_aMutex);
197     checkDisposed(ODescriptor_BASE::rBHelper.bDisposed);
198 
199 
200     return this;
201 }
202 // -----------------------------------------------------------------------------
203 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OKey::getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException)
204 {
205     return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
206 }
207 // -----------------------------------------------------------------------------
208 ::rtl::OUString SAL_CALL OKey::getName(  ) throw(::com::sun::star::uno::RuntimeException)
209 {
210     return m_Name;
211 }
212 // -----------------------------------------------------------------------------
213 void SAL_CALL OKey::setName( const ::rtl::OUString& /*aName*/ ) throw(::com::sun::star::uno::RuntimeException)
214 {
215 }
216 // -----------------------------------------------------------------------------
217 // XInterface
218 void SAL_CALL OKey::acquire() throw()
219 {
220     ODescriptor_BASE::acquire();
221 }
222 // -----------------------------------------------------------------------------
223 void SAL_CALL OKey::release() throw()
224 {
225     ODescriptor_BASE::release();
226 }
227 // -----------------------------------------------------------------------------
228 
229