1*96de5490SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*96de5490SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*96de5490SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*96de5490SAndrew Rist * distributed with this work for additional information
6*96de5490SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*96de5490SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*96de5490SAndrew Rist * "License"); you may not use this file except in compliance
9*96de5490SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*96de5490SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*96de5490SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*96de5490SAndrew Rist * software distributed under the License is distributed on an
15*96de5490SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*96de5490SAndrew Rist * KIND, either express or implied. See the License for the
17*96de5490SAndrew Rist * specific language governing permissions and limitations
18*96de5490SAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*96de5490SAndrew Rist *************************************************************/
21*96de5490SAndrew Rist
22*96de5490SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "tablecontainer.hxx"
28cdf0e10cSrcweir #include "dbastrings.hrc"
29cdf0e10cSrcweir #include "table.hxx"
30cdf0e10cSrcweir #include <comphelper/property.hxx>
31cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
32cdf0e10cSrcweir #include <tools/debug.hxx>
33cdf0e10cSrcweir #include <comphelper/enumhelper.hxx>
34cdf0e10cSrcweir #include "core_resource.hxx"
35cdf0e10cSrcweir #include "core_resource.hrc"
36cdf0e10cSrcweir #include <com/sun/star/sdb/CommandType.hpp>
37cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
38cdf0e10cSrcweir #include <com/sun/star/beans/PropertyState.hpp>
39cdf0e10cSrcweir #include <com/sun/star/beans/XPropertyState.hpp>
40cdf0e10cSrcweir #include <com/sun/star/sdbc/XConnection.hpp>
41cdf0e10cSrcweir #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
42cdf0e10cSrcweir #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
43cdf0e10cSrcweir #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
44cdf0e10cSrcweir #include <com/sun/star/sdbc/KeyRule.hpp>
45cdf0e10cSrcweir #include <com/sun/star/sdbcx/KeyType.hpp>
46cdf0e10cSrcweir #include <com/sun/star/sdbc/ColumnValue.hpp>
47cdf0e10cSrcweir #include <com/sun/star/sdbc/XRow.hpp>
48cdf0e10cSrcweir #include <comphelper/types.hxx>
49cdf0e10cSrcweir #include <connectivity/dbtools.hxx>
50cdf0e10cSrcweir #include <comphelper/extract.hxx>
51cdf0e10cSrcweir #include <connectivity/dbexception.hxx>
52cdf0e10cSrcweir #include "TableDeco.hxx"
53cdf0e10cSrcweir #include "sdbcoretools.hxx"
54cdf0e10cSrcweir #include "ContainerMediator.hxx"
55cdf0e10cSrcweir #include "definitioncolumn.hxx"
56cdf0e10cSrcweir #include "objectnameapproval.hxx"
57cdf0e10cSrcweir #include <tools/string.hxx>
58cdf0e10cSrcweir #include <rtl/logfile.hxx>
59cdf0e10cSrcweir #ifndef TOOLS_DIAGNOSE_EX_H
60cdf0e10cSrcweir #include <tools/diagnose_ex.h>
61cdf0e10cSrcweir #endif
62cdf0e10cSrcweir #ifndef TOOLS_DIAGNOSE_EX_H
63cdf0e10cSrcweir #include <tools/diagnose_ex.h>
64cdf0e10cSrcweir #endif
65cdf0e10cSrcweir
66cdf0e10cSrcweir using namespace dbaccess;
67cdf0e10cSrcweir using namespace dbtools;
68cdf0e10cSrcweir using namespace ::com::sun::star::uno;
69cdf0e10cSrcweir using namespace ::com::sun::star::lang;
70cdf0e10cSrcweir using namespace ::com::sun::star::beans;
71cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
72cdf0e10cSrcweir using namespace ::com::sun::star::sdb;
73cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx;
74cdf0e10cSrcweir using namespace ::com::sun::star::container;
75cdf0e10cSrcweir using namespace ::com::sun::star::util;
76cdf0e10cSrcweir using namespace ::osl;
77cdf0e10cSrcweir using namespace ::comphelper;
78cdf0e10cSrcweir using namespace ::cppu;
79cdf0e10cSrcweir using namespace ::connectivity::sdbcx;
80cdf0e10cSrcweir
81cdf0e10cSrcweir namespace
82cdf0e10cSrcweir {
lcl_isPropertySetDefaulted(const Sequence<::rtl::OUString> & _aNames,const Reference<XPropertySet> & _xProp)83cdf0e10cSrcweir sal_Bool lcl_isPropertySetDefaulted(const Sequence< ::rtl::OUString>& _aNames,const Reference<XPropertySet>& _xProp)
84cdf0e10cSrcweir {
85cdf0e10cSrcweir Reference<XPropertyState> xState(_xProp,UNO_QUERY);
86cdf0e10cSrcweir if ( xState.is() )
87cdf0e10cSrcweir {
88cdf0e10cSrcweir const ::rtl::OUString* pIter = _aNames.getConstArray();
89cdf0e10cSrcweir const ::rtl::OUString* pEnd = pIter + _aNames.getLength();
90cdf0e10cSrcweir for(;pIter != pEnd;++pIter)
91cdf0e10cSrcweir {
92cdf0e10cSrcweir try
93cdf0e10cSrcweir {
94cdf0e10cSrcweir PropertyState aState = xState->getPropertyState(*pIter);
95cdf0e10cSrcweir if ( aState != PropertyState_DEFAULT_VALUE )
96cdf0e10cSrcweir break;
97cdf0e10cSrcweir }
98cdf0e10cSrcweir catch(Exception)
99cdf0e10cSrcweir {
100cdf0e10cSrcweir OSL_ENSURE( 0, "lcl_isPropertySetDefaulted: Exception caught!" );
101cdf0e10cSrcweir }
102cdf0e10cSrcweir }
103cdf0e10cSrcweir return ( pIter == pEnd );
104cdf0e10cSrcweir }
105cdf0e10cSrcweir return sal_False;
106cdf0e10cSrcweir }
107cdf0e10cSrcweir }
108cdf0e10cSrcweir //==========================================================================
109cdf0e10cSrcweir //= OTableContainer
110cdf0e10cSrcweir //==========================================================================
DBG_NAME(OTableContainer)111cdf0e10cSrcweir DBG_NAME(OTableContainer)
112cdf0e10cSrcweir //------------------------------------------------------------------------------
113cdf0e10cSrcweir OTableContainer::OTableContainer(::cppu::OWeakObject& _rParent,
114cdf0e10cSrcweir ::osl::Mutex& _rMutex,
115cdf0e10cSrcweir const Reference< XConnection >& _xCon,
116cdf0e10cSrcweir sal_Bool _bCase,
117cdf0e10cSrcweir const Reference< XNameContainer >& _xTableDefinitions,
118cdf0e10cSrcweir IRefreshListener* _pRefreshListener,
119cdf0e10cSrcweir ::dbtools::IWarningsContainer* _pWarningsContainer
120cdf0e10cSrcweir ,oslInterlockedCount& _nInAppend)
121cdf0e10cSrcweir :OFilteredContainer(_rParent,_rMutex,_xCon,_bCase,_pRefreshListener,_pWarningsContainer,_nInAppend)
122cdf0e10cSrcweir ,m_xTableDefinitions(_xTableDefinitions)
123cdf0e10cSrcweir ,m_pTableMediator( NULL )
124cdf0e10cSrcweir ,m_bInDrop(sal_False)
125cdf0e10cSrcweir {
126cdf0e10cSrcweir DBG_CTOR(OTableContainer, NULL);
127cdf0e10cSrcweir }
128cdf0e10cSrcweir
129cdf0e10cSrcweir //------------------------------------------------------------------------------
~OTableContainer()130cdf0e10cSrcweir OTableContainer::~OTableContainer()
131cdf0e10cSrcweir {
132cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "api", "Ocke.Janssen@sun.com", "OTableContainer::OTableContainer" );
133cdf0e10cSrcweir // dispose();
134cdf0e10cSrcweir DBG_DTOR(OTableContainer, NULL);
135cdf0e10cSrcweir }
136cdf0e10cSrcweir
137cdf0e10cSrcweir // -----------------------------------------------------------------------------
removeMasterContainerListener()138cdf0e10cSrcweir void OTableContainer::removeMasterContainerListener()
139cdf0e10cSrcweir {
140cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "api", "Ocke.Janssen@sun.com", "OTableContainer::removeMasterContainerListener" );
141cdf0e10cSrcweir try
142cdf0e10cSrcweir {
143cdf0e10cSrcweir Reference<XContainer> xCont( m_xMasterContainer, UNO_QUERY_THROW );
144cdf0e10cSrcweir xCont->removeContainerListener( this );
145cdf0e10cSrcweir }
146cdf0e10cSrcweir catch( const Exception& )
147cdf0e10cSrcweir {
148cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION();
149cdf0e10cSrcweir }
150cdf0e10cSrcweir }
151cdf0e10cSrcweir
152cdf0e10cSrcweir // -----------------------------------------------------------------------------
getTableTypeRestriction() const153cdf0e10cSrcweir ::rtl::OUString OTableContainer::getTableTypeRestriction() const
154cdf0e10cSrcweir {
155cdf0e10cSrcweir // no restriction at all (other than the ones provided externally)
156cdf0e10cSrcweir return ::rtl::OUString();
157cdf0e10cSrcweir }
158cdf0e10cSrcweir
159cdf0e10cSrcweir // -----------------------------------------------------------------------------
160cdf0e10cSrcweir // XServiceInfo
161cdf0e10cSrcweir //------------------------------------------------------------------------------
162cdf0e10cSrcweir IMPLEMENT_SERVICE_INFO2(OTableContainer, "com.sun.star.sdb.dbaccess.OTableContainer", SERVICE_SDBCX_CONTAINER, SERVICE_SDBCX_TABLES)
163cdf0e10cSrcweir
164cdf0e10cSrcweir // -----------------------------------------------------------------------------
165cdf0e10cSrcweir namespace
166cdf0e10cSrcweir {
lcl_createDefintionObject(const::rtl::OUString & _rName,const Reference<XNameContainer> & _xTableDefinitions,Reference<XPropertySet> & _xTableDefinition,Reference<XNameAccess> & _xColumnDefinitions,sal_Bool _bModified)167cdf0e10cSrcweir void lcl_createDefintionObject(const ::rtl::OUString& _rName
168cdf0e10cSrcweir ,const Reference< XNameContainer >& _xTableDefinitions
169cdf0e10cSrcweir ,Reference<XPropertySet>& _xTableDefinition
170cdf0e10cSrcweir ,Reference<XNameAccess>& _xColumnDefinitions
171cdf0e10cSrcweir ,sal_Bool _bModified)
172cdf0e10cSrcweir {
173cdf0e10cSrcweir if ( _xTableDefinitions.is() )
174cdf0e10cSrcweir {
175cdf0e10cSrcweir if ( _xTableDefinitions->hasByName(_rName) )
176cdf0e10cSrcweir _xTableDefinition.set(_xTableDefinitions->getByName(_rName),UNO_QUERY);
177cdf0e10cSrcweir else
178cdf0e10cSrcweir {
179cdf0e10cSrcweir Sequence< Any > aArguments(1);
180cdf0e10cSrcweir PropertyValue aValue;
181cdf0e10cSrcweir // set as folder
182cdf0e10cSrcweir aValue.Name = PROPERTY_NAME;
183cdf0e10cSrcweir aValue.Value <<= _rName;
184cdf0e10cSrcweir aArguments[0] <<= aValue;
185cdf0e10cSrcweir _xTableDefinition.set(::comphelper::getProcessServiceFactory()->createInstanceWithArguments(SERVICE_SDB_TABLEDEFINITION,aArguments),UNO_QUERY);
186cdf0e10cSrcweir _xTableDefinitions->insertByName(_rName,makeAny(_xTableDefinition));
187cdf0e10cSrcweir ::dbaccess::notifyDataSourceModified(_xTableDefinitions,_bModified);
188cdf0e10cSrcweir }
189cdf0e10cSrcweir Reference<XColumnsSupplier> xColumnsSupplier(_xTableDefinition,UNO_QUERY);
190cdf0e10cSrcweir if ( xColumnsSupplier.is() )
191cdf0e10cSrcweir _xColumnDefinitions = xColumnsSupplier->getColumns();
192cdf0e10cSrcweir }
193cdf0e10cSrcweir }
194cdf0e10cSrcweir // -------------------------------------------------------------------------
195cdf0e10cSrcweir }
196cdf0e10cSrcweir // -------------------------------------------------------------------------
createObject(const::rtl::OUString & _rName)197cdf0e10cSrcweir connectivity::sdbcx::ObjectType OTableContainer::createObject(const ::rtl::OUString& _rName)
198cdf0e10cSrcweir {
199cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "api", "Ocke.Janssen@sun.com", "OTableContainer::createObject" );
200cdf0e10cSrcweir Reference<XColumnsSupplier > xSup;
201cdf0e10cSrcweir if(m_xMasterContainer.is() && m_xMasterContainer->hasByName(_rName))
202cdf0e10cSrcweir xSup.set(m_xMasterContainer->getByName(_rName),UNO_QUERY);
203cdf0e10cSrcweir
204cdf0e10cSrcweir connectivity::sdbcx::ObjectType xRet;
205cdf0e10cSrcweir if ( m_xMetaData.is() )
206cdf0e10cSrcweir {
207cdf0e10cSrcweir Reference<XPropertySet> xTableDefinition;
208cdf0e10cSrcweir Reference<XNameAccess> xColumnDefinitions;
209cdf0e10cSrcweir lcl_createDefintionObject(_rName,m_xTableDefinitions,xTableDefinition,xColumnDefinitions,sal_False);
210cdf0e10cSrcweir
211cdf0e10cSrcweir if ( xSup.is() )
212cdf0e10cSrcweir {
213cdf0e10cSrcweir ODBTableDecorator* pTable = new ODBTableDecorator( m_xConnection, xSup, ::dbtools::getNumberFormats( m_xConnection ) ,xColumnDefinitions);
214cdf0e10cSrcweir xRet = pTable;
215cdf0e10cSrcweir pTable->construct();
216cdf0e10cSrcweir }
217cdf0e10cSrcweir else
218cdf0e10cSrcweir {
219cdf0e10cSrcweir ::rtl::OUString sCatalog,sSchema,sTable;
220cdf0e10cSrcweir ::dbtools::qualifiedNameComponents(m_xMetaData,
221cdf0e10cSrcweir _rName,
222cdf0e10cSrcweir sCatalog,
223cdf0e10cSrcweir sSchema,
224cdf0e10cSrcweir sTable,
225cdf0e10cSrcweir ::dbtools::eInDataManipulation);
226cdf0e10cSrcweir Any aCatalog;
227cdf0e10cSrcweir if(sCatalog.getLength())
228cdf0e10cSrcweir aCatalog <<= sCatalog;
229cdf0e10cSrcweir ::rtl::OUString sType,sDescription;
230cdf0e10cSrcweir Sequence< ::rtl::OUString> aTypeFilter;
231cdf0e10cSrcweir getAllTableTypeFilter( aTypeFilter );
232cdf0e10cSrcweir
233cdf0e10cSrcweir Reference< XResultSet > xRes = m_xMetaData.is() ? m_xMetaData->getTables(aCatalog,sSchema,sTable,aTypeFilter) : Reference< XResultSet >();
234cdf0e10cSrcweir if(xRes.is() && xRes->next())
235cdf0e10cSrcweir {
236cdf0e10cSrcweir Reference< XRow > xRow(xRes,UNO_QUERY);
237cdf0e10cSrcweir if(xRow.is())
238cdf0e10cSrcweir {
239cdf0e10cSrcweir sType = xRow->getString(4);
240cdf0e10cSrcweir sDescription = xRow->getString(5);
241cdf0e10cSrcweir }
242cdf0e10cSrcweir }
243cdf0e10cSrcweir ::comphelper::disposeComponent(xRes);
244cdf0e10cSrcweir ODBTable* pTable = new ODBTable(this
245cdf0e10cSrcweir ,m_xConnection
246cdf0e10cSrcweir ,sCatalog
247cdf0e10cSrcweir ,sSchema
248cdf0e10cSrcweir ,sTable
249cdf0e10cSrcweir ,sType
250cdf0e10cSrcweir ,sDescription
251cdf0e10cSrcweir ,xColumnDefinitions);
252cdf0e10cSrcweir xRet = pTable;
253cdf0e10cSrcweir pTable->construct();
254cdf0e10cSrcweir }
255cdf0e10cSrcweir Reference<XPropertySet> xDest(xRet,UNO_QUERY);
256cdf0e10cSrcweir if ( xTableDefinition.is() )
257cdf0e10cSrcweir ::comphelper::copyProperties(xTableDefinition,xDest);
258cdf0e10cSrcweir
259cdf0e10cSrcweir if ( !m_pTableMediator.is() )
260cdf0e10cSrcweir m_pTableMediator = new OContainerMediator(
261cdf0e10cSrcweir this, m_xTableDefinitions.get(), m_xConnection, OContainerMediator::eTables );
262cdf0e10cSrcweir if ( m_pTableMediator.is() )
263cdf0e10cSrcweir m_pTableMediator->notifyElementCreated(_rName,xDest);
264cdf0e10cSrcweir }
265cdf0e10cSrcweir
266cdf0e10cSrcweir return xRet;
267cdf0e10cSrcweir }
268cdf0e10cSrcweir // -----------------------------------------------------------------------------
createDescriptor()269cdf0e10cSrcweir Reference< XPropertySet > OTableContainer::createDescriptor()
270cdf0e10cSrcweir {
271cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "api", "Ocke.Janssen@sun.com", "OTableContainer::createDescriptor" );
272cdf0e10cSrcweir Reference< XPropertySet > xRet;
273cdf0e10cSrcweir
274cdf0e10cSrcweir // frist we have to look if the master tables does support this
275cdf0e10cSrcweir // and if then create a table object as well with the master tables
276cdf0e10cSrcweir Reference<XColumnsSupplier > xMasterColumnsSup;
277cdf0e10cSrcweir Reference<XDataDescriptorFactory> xDataFactory(m_xMasterContainer,UNO_QUERY);
278cdf0e10cSrcweir if ( xDataFactory.is() && m_xMetaData.is() )
279cdf0e10cSrcweir {
280cdf0e10cSrcweir xMasterColumnsSup = Reference< XColumnsSupplier >( xDataFactory->createDataDescriptor(), UNO_QUERY );
281cdf0e10cSrcweir ODBTableDecorator* pTable = new ODBTableDecorator( m_xConnection, xMasterColumnsSup, ::dbtools::getNumberFormats( m_xConnection ) ,NULL);
282cdf0e10cSrcweir xRet = pTable;
283cdf0e10cSrcweir pTable->construct();
284cdf0e10cSrcweir }
285cdf0e10cSrcweir else
286cdf0e10cSrcweir {
287cdf0e10cSrcweir ODBTable* pTable = new ODBTable(this, m_xConnection);
288cdf0e10cSrcweir xRet = pTable;
289cdf0e10cSrcweir pTable->construct();
290cdf0e10cSrcweir }
291cdf0e10cSrcweir return xRet;
292cdf0e10cSrcweir }
293cdf0e10cSrcweir // -----------------------------------------------------------------------------
294cdf0e10cSrcweir // XAppend
appendObject(const::rtl::OUString & _rForName,const Reference<XPropertySet> & descriptor)295cdf0e10cSrcweir ObjectType OTableContainer::appendObject( const ::rtl::OUString& _rForName, const Reference< XPropertySet >& descriptor )
296cdf0e10cSrcweir {
297cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "api", "Ocke.Janssen@sun.com", "OTableContainer::appendObject" );
298cdf0e10cSrcweir // append the new table with a create stmt
299cdf0e10cSrcweir ::rtl::OUString aName = getString(descriptor->getPropertyValue(PROPERTY_NAME));
300cdf0e10cSrcweir if(m_xMasterContainer.is() && m_xMasterContainer->hasByName(aName))
301cdf0e10cSrcweir {
302cdf0e10cSrcweir String sMessage(DBACORE_RESSTRING(RID_STR_TABLE_IS_FILTERED));
303cdf0e10cSrcweir sMessage.SearchAndReplaceAscii("$name$", aName);
304cdf0e10cSrcweir throw SQLException(sMessage,static_cast<XTypeProvider*>(static_cast<OFilteredContainer*>(this)),SQLSTATE_GENERAL,1000,Any());
305cdf0e10cSrcweir }
306cdf0e10cSrcweir
307cdf0e10cSrcweir Reference< XConnection > xConnection( m_xConnection.get(), UNO_QUERY );
308cdf0e10cSrcweir PContainerApprove pApprove( new ObjectNameApproval( xConnection, ObjectNameApproval::TypeTable ) );
309cdf0e10cSrcweir pApprove->approveElement( aName, descriptor );
310cdf0e10cSrcweir
311cdf0e10cSrcweir try
312cdf0e10cSrcweir {
313cdf0e10cSrcweir EnsureReset aReset(m_nInAppend);
314cdf0e10cSrcweir Reference<XAppend> xAppend(m_xMasterContainer,UNO_QUERY);
315cdf0e10cSrcweir if(xAppend.is())
316cdf0e10cSrcweir {
317cdf0e10cSrcweir xAppend->appendByDescriptor(descriptor);
318cdf0e10cSrcweir }
319cdf0e10cSrcweir else
320cdf0e10cSrcweir {
321cdf0e10cSrcweir ::rtl::OUString aSql = ::dbtools::createSqlCreateTableStatement(descriptor,m_xConnection);
322cdf0e10cSrcweir
323cdf0e10cSrcweir Reference<XConnection> xCon = m_xConnection;
324cdf0e10cSrcweir OSL_ENSURE(xCon.is(),"Connection is null!");
325cdf0e10cSrcweir if ( xCon.is() )
326cdf0e10cSrcweir {
327cdf0e10cSrcweir Reference< XStatement > xStmt = xCon->createStatement( );
328cdf0e10cSrcweir if ( xStmt.is() )
329cdf0e10cSrcweir xStmt->execute(aSql);
330cdf0e10cSrcweir ::comphelper::disposeComponent(xStmt);
331cdf0e10cSrcweir }
332cdf0e10cSrcweir }
333cdf0e10cSrcweir }
334cdf0e10cSrcweir catch(Exception&)
335cdf0e10cSrcweir {
336cdf0e10cSrcweir throw;
337cdf0e10cSrcweir }
338cdf0e10cSrcweir
339cdf0e10cSrcweir Reference<XPropertySet> xTableDefinition;
340cdf0e10cSrcweir Reference<XNameAccess> xColumnDefinitions;
341cdf0e10cSrcweir lcl_createDefintionObject(getNameForObject(descriptor),m_xTableDefinitions,xTableDefinition,xColumnDefinitions,sal_False);
342cdf0e10cSrcweir Reference<XColumnsSupplier> xSup(descriptor,UNO_QUERY);
343cdf0e10cSrcweir Reference<XDataDescriptorFactory> xFac(xColumnDefinitions,UNO_QUERY);
344cdf0e10cSrcweir Reference<XAppend> xAppend(xColumnDefinitions,UNO_QUERY);
345cdf0e10cSrcweir sal_Bool bModified = sal_False;
346cdf0e10cSrcweir if ( xSup.is() && xColumnDefinitions.is() && xFac.is() && xAppend.is() )
347cdf0e10cSrcweir {
348cdf0e10cSrcweir Reference<XNameAccess> xNames = xSup->getColumns();
349cdf0e10cSrcweir if ( xNames.is() )
350cdf0e10cSrcweir {
351cdf0e10cSrcweir Reference<XPropertySet> xProp = xFac->createDataDescriptor();
352cdf0e10cSrcweir Sequence< ::rtl::OUString> aSeq = xNames->getElementNames();
353cdf0e10cSrcweir const ::rtl::OUString* pIter = aSeq.getConstArray();
354cdf0e10cSrcweir const ::rtl::OUString* pEnd = pIter + aSeq.getLength();
355cdf0e10cSrcweir for(;pIter != pEnd;++pIter)
356cdf0e10cSrcweir {
357cdf0e10cSrcweir if ( !xColumnDefinitions->hasByName(*pIter) )
358cdf0e10cSrcweir {
359cdf0e10cSrcweir Reference<XPropertySet> xColumn(xNames->getByName(*pIter),UNO_QUERY);
360cdf0e10cSrcweir if ( !OColumnSettings::hasDefaultSettings( xColumn ) )
361cdf0e10cSrcweir {
362cdf0e10cSrcweir ::comphelper::copyProperties( xColumn, xProp );
363cdf0e10cSrcweir xAppend->appendByDescriptor( xProp );
364cdf0e10cSrcweir bModified = sal_True;
365cdf0e10cSrcweir }
366cdf0e10cSrcweir }
367cdf0e10cSrcweir }
368cdf0e10cSrcweir }
369cdf0e10cSrcweir }
370cdf0e10cSrcweir const static ::rtl::OUString s_pTableProps[] = { ::rtl::OUString(PROPERTY_FILTER), ::rtl::OUString(PROPERTY_ORDER)
371cdf0e10cSrcweir , ::rtl::OUString(PROPERTY_APPLYFILTER), ::rtl::OUString(PROPERTY_FONT)
372cdf0e10cSrcweir , ::rtl::OUString(PROPERTY_ROW_HEIGHT), ::rtl::OUString(PROPERTY_TEXTCOLOR)
373cdf0e10cSrcweir , ::rtl::OUString(PROPERTY_TEXTLINECOLOR), ::rtl::OUString(PROPERTY_TEXTEMPHASIS)
374cdf0e10cSrcweir , ::rtl::OUString(PROPERTY_TEXTRELIEF) };
375cdf0e10cSrcweir Sequence< ::rtl::OUString> aNames(s_pTableProps,sizeof(s_pTableProps)/sizeof(s_pTableProps[0]));
376cdf0e10cSrcweir if ( bModified || !lcl_isPropertySetDefaulted(aNames,xTableDefinition) )
377cdf0e10cSrcweir ::dbaccess::notifyDataSourceModified(m_xTableDefinitions,sal_True);
378cdf0e10cSrcweir
379cdf0e10cSrcweir return createObject( _rForName );
380cdf0e10cSrcweir }
381cdf0e10cSrcweir // -------------------------------------------------------------------------
382cdf0e10cSrcweir // XDrop
dropObject(sal_Int32 _nPos,const::rtl::OUString _sElementName)383cdf0e10cSrcweir void OTableContainer::dropObject(sal_Int32 _nPos,const ::rtl::OUString _sElementName)
384cdf0e10cSrcweir {
385cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "api", "Ocke.Janssen@sun.com", "OTableContainer::dropObject" );
386cdf0e10cSrcweir m_bInDrop = sal_True;
387cdf0e10cSrcweir try
388cdf0e10cSrcweir {
389cdf0e10cSrcweir Reference< XDrop > xDrop(m_xMasterContainer,UNO_QUERY);
390cdf0e10cSrcweir if(xDrop.is())
391cdf0e10cSrcweir xDrop->dropByName(_sElementName);
392cdf0e10cSrcweir else
393cdf0e10cSrcweir {
394cdf0e10cSrcweir ::rtl::OUString sCatalog,sSchema,sTable,sComposedName;
395cdf0e10cSrcweir
396cdf0e10cSrcweir sal_Bool bIsView = sal_False;
397cdf0e10cSrcweir Reference<XPropertySet> xTable(getObject(_nPos),UNO_QUERY);
398cdf0e10cSrcweir if ( xTable.is() && m_xMetaData.is() )
399cdf0e10cSrcweir {
400cdf0e10cSrcweir if( m_xMetaData.is() && m_xMetaData->supportsCatalogsInTableDefinitions() )
401cdf0e10cSrcweir xTable->getPropertyValue(PROPERTY_CATALOGNAME) >>= sCatalog;
402cdf0e10cSrcweir if( m_xMetaData.is() && m_xMetaData->supportsSchemasInTableDefinitions() )
403cdf0e10cSrcweir xTable->getPropertyValue(PROPERTY_SCHEMANAME) >>= sSchema;
404cdf0e10cSrcweir xTable->getPropertyValue(PROPERTY_NAME) >>= sTable;
405cdf0e10cSrcweir
406cdf0e10cSrcweir sComposedName = ::dbtools::composeTableName( m_xMetaData, sCatalog, sSchema, sTable, sal_True, ::dbtools::eInTableDefinitions );
407cdf0e10cSrcweir
408cdf0e10cSrcweir ::rtl::OUString sType;
409cdf0e10cSrcweir xTable->getPropertyValue(PROPERTY_TYPE) >>= sType;
410cdf0e10cSrcweir bIsView = sType.equalsIgnoreAsciiCase(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("VIEW")));
411cdf0e10cSrcweir }
412cdf0e10cSrcweir
413cdf0e10cSrcweir if(!sComposedName.getLength())
414cdf0e10cSrcweir ::dbtools::throwFunctionSequenceException(static_cast<XTypeProvider*>(static_cast<OFilteredContainer*>(this)));
415cdf0e10cSrcweir
416cdf0e10cSrcweir ::rtl::OUString aSql = ::rtl::OUString::createFromAscii("DROP ");
417cdf0e10cSrcweir
418cdf0e10cSrcweir // #104282# OJ
419cdf0e10cSrcweir if ( bIsView ) // here we have a view
420cdf0e10cSrcweir aSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("VIEW "));
421cdf0e10cSrcweir else
422cdf0e10cSrcweir aSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TABLE "));
423cdf0e10cSrcweir aSql += sComposedName;
424cdf0e10cSrcweir Reference<XConnection> xCon = m_xConnection;
425cdf0e10cSrcweir OSL_ENSURE(xCon.is(),"Connection is null!");
426cdf0e10cSrcweir if ( xCon.is() )
427cdf0e10cSrcweir {
428cdf0e10cSrcweir Reference< XStatement > xStmt = xCon->createStatement( );
429cdf0e10cSrcweir if(xStmt.is())
430cdf0e10cSrcweir xStmt->execute(aSql);
431cdf0e10cSrcweir ::comphelper::disposeComponent(xStmt);
432cdf0e10cSrcweir }
433cdf0e10cSrcweir }
434cdf0e10cSrcweir
435cdf0e10cSrcweir if ( m_xTableDefinitions.is() && m_xTableDefinitions->hasByName(_sElementName) )
436cdf0e10cSrcweir {
437cdf0e10cSrcweir m_xTableDefinitions->removeByName(_sElementName);
438cdf0e10cSrcweir }
439cdf0e10cSrcweir }
440cdf0e10cSrcweir catch(Exception&)
441cdf0e10cSrcweir {
442cdf0e10cSrcweir m_bInDrop = sal_False;
443cdf0e10cSrcweir throw;
444cdf0e10cSrcweir }
445cdf0e10cSrcweir m_bInDrop = sal_False;
446cdf0e10cSrcweir }
447cdf0e10cSrcweir // -----------------------------------------------------------------------------
elementInserted(const ContainerEvent & Event)448cdf0e10cSrcweir void SAL_CALL OTableContainer::elementInserted( const ContainerEvent& Event ) throw (RuntimeException)
449cdf0e10cSrcweir {
450cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "api", "Ocke.Janssen@sun.com", "OTableContainer::elementInserted" );
451cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_rMutex);
452cdf0e10cSrcweir ::rtl::OUString sName;
453cdf0e10cSrcweir Event.Accessor >>= sName;
454cdf0e10cSrcweir if ( !m_nInAppend && !hasByName(sName) )
455cdf0e10cSrcweir {
456cdf0e10cSrcweir if(!m_xMasterContainer.is() || m_xMasterContainer->hasByName(sName))
457cdf0e10cSrcweir {
458cdf0e10cSrcweir ObjectType xName = createObject(sName);
459cdf0e10cSrcweir insertElement(sName,xName);
460cdf0e10cSrcweir // and notify our listeners
461cdf0e10cSrcweir ContainerEvent aEvent(static_cast<XContainer*>(this), makeAny(sName), makeAny(xName), Any());
462cdf0e10cSrcweir m_aContainerListeners.notifyEach( &XContainerListener::elementInserted, aEvent );
463cdf0e10cSrcweir }
464cdf0e10cSrcweir }
465cdf0e10cSrcweir }
466cdf0e10cSrcweir // -----------------------------------------------------------------------------
elementRemoved(const ContainerEvent &)467cdf0e10cSrcweir void SAL_CALL OTableContainer::elementRemoved( const ContainerEvent& /*Event*/ ) throw (RuntimeException)
468cdf0e10cSrcweir {
469cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "api", "Ocke.Janssen@sun.com", "OTableContainer::elementRemoved" );
470cdf0e10cSrcweir }
471cdf0e10cSrcweir // -----------------------------------------------------------------------------
elementReplaced(const ContainerEvent & Event)472cdf0e10cSrcweir void SAL_CALL OTableContainer::elementReplaced( const ContainerEvent& Event ) throw (RuntimeException)
473cdf0e10cSrcweir {
474cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "api", "Ocke.Janssen@sun.com", "OTableContainer::elementReplaced" );
475cdf0e10cSrcweir // create a new config entry
476cdf0e10cSrcweir {
477cdf0e10cSrcweir ::rtl::OUString sOldComposedName,sNewComposedName;
478cdf0e10cSrcweir Event.ReplacedElement >>= sOldComposedName;
479cdf0e10cSrcweir Event.Accessor >>= sNewComposedName;
480cdf0e10cSrcweir
481cdf0e10cSrcweir renameObject(sOldComposedName,sNewComposedName);
482cdf0e10cSrcweir }
483cdf0e10cSrcweir }
484cdf0e10cSrcweir // -----------------------------------------------------------------------------
disposing()485cdf0e10cSrcweir void SAL_CALL OTableContainer::disposing()
486cdf0e10cSrcweir {
487cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "api", "Ocke.Janssen@sun.com", "OTableContainer::disposing" );
488cdf0e10cSrcweir OFilteredContainer::disposing();
489cdf0e10cSrcweir // say our listeners goobye
490cdf0e10cSrcweir m_xTableDefinitions = NULL;
491cdf0e10cSrcweir m_pTableMediator = NULL;
492cdf0e10cSrcweir }
493cdf0e10cSrcweir // -----------------------------------------------------------------------------
disposing(const::com::sun::star::lang::EventObject &)494cdf0e10cSrcweir void SAL_CALL OTableContainer::disposing( const ::com::sun::star::lang::EventObject& /*Source*/ ) throw (::com::sun::star::uno::RuntimeException)
495cdf0e10cSrcweir {
496cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "api", "Ocke.Janssen@sun.com", "OTableContainer::disposing" );
497cdf0e10cSrcweir }
498cdf0e10cSrcweir
499cdf0e10cSrcweir // -----------------------------------------------------------------------------
addMasterContainerListener()500cdf0e10cSrcweir void OTableContainer::addMasterContainerListener()
501cdf0e10cSrcweir {
502cdf0e10cSrcweir try
503cdf0e10cSrcweir {
504cdf0e10cSrcweir Reference< XContainer > xCont( m_xMasterContainer, UNO_QUERY_THROW );
505cdf0e10cSrcweir xCont->addContainerListener( this );
506cdf0e10cSrcweir }
507cdf0e10cSrcweir catch( const Exception& )
508cdf0e10cSrcweir {
509cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION();
510cdf0e10cSrcweir }
511cdf0e10cSrcweir }
512cdf0e10cSrcweir
513