merge the formfield patch from ooo-build
[ooovba.git] / connectivity / source / drivers / dbase / DTables.cxx
blob988a98f0bdfaeaaa15cf6e42c383f17e2cc982d2
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: DTables.cxx,v $
10 * $Revision: 1.27.56.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
33 #include "dbase/DTables.hxx"
34 #include "dbase/DTable.hxx"
35 #include <com/sun/star/sdbc/XRow.hpp>
36 #include <com/sun/star/sdbc/XResultSet.hpp>
37 #include <com/sun/star/sdbc/ColumnValue.hpp>
38 #include <com/sun/star/sdbc/KeyRule.hpp>
39 #include <com/sun/star/sdbcx/KeyType.hpp>
40 #include "file/FCatalog.hxx"
41 #include "file/FConnection.hxx"
42 #include <com/sun/star/lang/XUnoTunnel.hpp>
43 #include "dbase/DCatalog.hxx"
44 #include <comphelper/types.hxx>
45 #include "resource/dbase_res.hrc"
46 #include "connectivity/dbexception.hxx"
48 using namespace ::comphelper;
49 using namespace connectivity;
50 using namespace connectivity::dbase;
51 using namespace connectivity::file;
52 using namespace ::com::sun::star::uno;
53 using namespace ::com::sun::star::beans;
54 using namespace ::com::sun::star::sdbcx;
55 using namespace ::com::sun::star::sdbc;
56 using namespace ::com::sun::star::lang;
57 using namespace ::com::sun::star::container;
58 namespace starutil = ::com::sun::star::util;
60 sdbcx::ObjectType ODbaseTables::createObject(const ::rtl::OUString& _rName)
62 ::rtl::OUString aName,aSchema;
63 ODbaseTable* pRet = new ODbaseTable(this,(ODbaseConnection*)static_cast<OFileCatalog&>(m_rParent).getConnection(),
64 _rName,::rtl::OUString::createFromAscii("TABLE"));
66 sdbcx::ObjectType xRet = pRet;
67 pRet->construct();
68 return xRet;
70 // -------------------------------------------------------------------------
71 void ODbaseTables::impl_refresh( ) throw(RuntimeException)
73 static_cast<ODbaseCatalog*>(&m_rParent)->refreshTables();
75 // -------------------------------------------------------------------------
76 Reference< XPropertySet > ODbaseTables::createDescriptor()
78 return new ODbaseTable(this,(ODbaseConnection*)static_cast<OFileCatalog&>(m_rParent).getConnection());
80 typedef connectivity::sdbcx::OCollection ODbaseTables_BASE_BASE;
81 // -------------------------------------------------------------------------
82 // XAppend
83 sdbcx::ObjectType ODbaseTables::appendObject( const ::rtl::OUString& _rForName, const Reference< XPropertySet >& descriptor )
85 Reference<XUnoTunnel> xTunnel(descriptor,UNO_QUERY);
86 if(xTunnel.is())
88 ODbaseTable* pTable = reinterpret_cast< ODbaseTable* >( xTunnel->getSomething(ODbaseTable::getUnoTunnelImplementationId()) );
89 if(pTable)
91 pTable->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME),makeAny(_rForName));
92 try
94 if(!pTable->CreateImpl())
95 throw SQLException();
97 catch(SQLException&)
99 throw;
101 catch(Exception&)
103 throw SQLException();
107 return createObject( _rForName );
109 // -------------------------------------------------------------------------
110 // XDrop
111 void ODbaseTables::dropObject(sal_Int32 _nPos,const ::rtl::OUString _sElementName)
113 Reference< XUnoTunnel> xTunnel;
116 xTunnel.set(getObject(_nPos),UNO_QUERY);
118 catch(const Exception&)
120 if(ODbaseTable::Drop_Static(ODbaseTable::getEntry(static_cast<OFileCatalog&>(m_rParent).getConnection(),_sElementName),sal_False,NULL))
121 return;
124 if ( xTunnel.is() )
126 ODbaseTable* pTable = reinterpret_cast< ODbaseTable* >( xTunnel->getSomething(ODbaseTable::getUnoTunnelImplementationId()) );
127 if(pTable)
128 pTable->DropImpl();
130 else
132 const ::rtl::OUString sError( static_cast<OFileCatalog&>(m_rParent).getConnection()->getResources().getResourceStringWithSubstitution(
133 STR_TABLE_NOT_DROP,
134 "$tablename$", _sElementName
135 ) );
136 ::dbtools::throwGenericSQLException( sError, NULL );
139 // -------------------------------------------------------------------------
140 Any SAL_CALL ODbaseTables::queryInterface( const Type & rType ) throw(RuntimeException)
142 typedef sdbcx::OCollection OTables_BASE;
143 return OTables_BASE::queryInterface(rType);
145 // -----------------------------------------------------------------------------