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 // MARKER(update_precomp.py): autogen include statement, do not remove
23 #include "precompiled_connectivity.hxx"
24 #include "dbase/DTables.hxx"
25 #include "dbase/DTable.hxx"
26 #include <com/sun/star/sdbc/XRow.hpp>
27 #include <com/sun/star/sdbc/XResultSet.hpp>
28 #include <com/sun/star/sdbc/ColumnValue.hpp>
29 #include <com/sun/star/sdbc/KeyRule.hpp>
30 #include <com/sun/star/sdbcx/KeyType.hpp>
31 #include "file/FCatalog.hxx"
32 #include "file/FConnection.hxx"
33 #include <com/sun/star/lang/XUnoTunnel.hpp>
34 #include "dbase/DCatalog.hxx"
35 #include <comphelper/types.hxx>
36 #include "resource/dbase_res.hrc"
37 #include "connectivity/dbexception.hxx"
38
39 using namespace ::comphelper;
40 using namespace connectivity;
41 using namespace connectivity::dbase;
42 using namespace connectivity::file;
43 using namespace ::com::sun::star::uno;
44 using namespace ::com::sun::star::beans;
45 using namespace ::com::sun::star::sdbcx;
46 using namespace ::com::sun::star::sdbc;
47 using namespace ::com::sun::star::lang;
48 using namespace ::com::sun::star::container;
49 namespace starutil = ::com::sun::star::util;
50
createObject(const::rtl::OUString & _rName)51 sdbcx::ObjectType ODbaseTables::createObject(const ::rtl::OUString& _rName)
52 {
53 ::rtl::OUString aName,aSchema;
54 ODbaseTable* pRet = new ODbaseTable(this,(ODbaseConnection*)static_cast<OFileCatalog&>(m_rParent).getConnection(),
55 _rName,::rtl::OUString::createFromAscii("TABLE"));
56
57 sdbcx::ObjectType xRet = pRet;
58 pRet->construct();
59 return xRet;
60 }
61 // -------------------------------------------------------------------------
impl_refresh()62 void ODbaseTables::impl_refresh( ) throw(RuntimeException)
63 {
64 static_cast<ODbaseCatalog*>(&m_rParent)->refreshTables();
65 }
66 // -------------------------------------------------------------------------
createDescriptor()67 Reference< XPropertySet > ODbaseTables::createDescriptor()
68 {
69 return new ODbaseTable(this,(ODbaseConnection*)static_cast<OFileCatalog&>(m_rParent).getConnection());
70 }
71 typedef connectivity::sdbcx::OCollection ODbaseTables_BASE_BASE;
72 // -------------------------------------------------------------------------
73 // XAppend
appendObject(const::rtl::OUString & _rForName,const Reference<XPropertySet> & descriptor)74 sdbcx::ObjectType ODbaseTables::appendObject( const ::rtl::OUString& _rForName, const Reference< XPropertySet >& descriptor )
75 {
76 Reference<XUnoTunnel> xTunnel(descriptor,UNO_QUERY);
77 if(xTunnel.is())
78 {
79 ODbaseTable* pTable = reinterpret_cast< ODbaseTable* >( xTunnel->getSomething(ODbaseTable::getUnoTunnelImplementationId()) );
80 if(pTable)
81 {
82 pTable->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME),makeAny(_rForName));
83 try
84 {
85 if(!pTable->CreateImpl())
86 throw SQLException();
87 }
88 catch(SQLException&)
89 {
90 throw;
91 }
92 catch(Exception&)
93 {
94 throw SQLException();
95 }
96 }
97 }
98 return createObject( _rForName );
99 }
100 // -------------------------------------------------------------------------
101 // XDrop
dropObject(sal_Int32 _nPos,const::rtl::OUString _sElementName)102 void ODbaseTables::dropObject(sal_Int32 _nPos,const ::rtl::OUString _sElementName)
103 {
104 Reference< XUnoTunnel> xTunnel;
105 try
106 {
107 xTunnel.set(getObject(_nPos),UNO_QUERY);
108 }
109 catch(const Exception&)
110 {
111 if(ODbaseTable::Drop_Static(ODbaseTable::getEntry(static_cast<OFileCatalog&>(m_rParent).getConnection(),_sElementName),sal_False,NULL))
112 return;
113 }
114
115 if ( xTunnel.is() )
116 {
117 ODbaseTable* pTable = reinterpret_cast< ODbaseTable* >( xTunnel->getSomething(ODbaseTable::getUnoTunnelImplementationId()) );
118 if(pTable)
119 pTable->DropImpl();
120 }
121 else
122 {
123 const ::rtl::OUString sError( static_cast<OFileCatalog&>(m_rParent).getConnection()->getResources().getResourceStringWithSubstitution(
124 STR_TABLE_NOT_DROP,
125 "$tablename$", _sElementName
126 ) );
127 ::dbtools::throwGenericSQLException( sError, NULL );
128 }
129 }
130 // -------------------------------------------------------------------------
queryInterface(const Type & rType)131 Any SAL_CALL ODbaseTables::queryInterface( const Type & rType ) throw(RuntimeException)
132 {
133 typedef sdbcx::OCollection OTables_BASE;
134 return OTables_BASE::queryInterface(rType);
135 }
136 // -----------------------------------------------------------------------------
137
138 /* vim: set noet sw=4 ts=4: */
139