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