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 #ifndef _CONNECTIVITY_DBASE_OCONNECTION_HXX_
32 #include "dbase/DConnection.hxx"
33 #endif
34 #include "dbase/DDatabaseMetaData.hxx"
35 #include "dbase/DCatalog.hxx"
36 #ifndef _CONNECTIVITY_DBASE_ODRIVER_HXX_
37 #include "dbase/DDriver.hxx"
38 #endif
39 #include <com/sun/star/lang/DisposedException.hpp>
40 #include <tools/urlobj.hxx>
41 #include "dbase/DPreparedStatement.hxx"
42 #include "dbase/DStatement.hxx"
43 #include <tools/debug.hxx>
44 #include <connectivity/dbexception.hxx>
45 
46 using namespace connectivity::dbase;
47 using namespace connectivity::file;
48 
49 typedef connectivity::file::OConnection  OConnection_BASE;
50 
51 //------------------------------------------------------------------------------
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 
58 DBG_NAME(ODbaseConnection)
59 // --------------------------------------------------------------------------------
60 ODbaseConnection::ODbaseConnection(ODriver*	_pDriver) : OConnection(_pDriver)
61 {
62 	DBG_CTOR(ODbaseConnection,NULL);
63 	m_aFilenameExtension = String::CreateFromAscii("dbf");
64 }
65 //-----------------------------------------------------------------------------
66 ODbaseConnection::~ODbaseConnection()
67 {
68 	DBG_DTOR(ODbaseConnection,NULL);
69 }
70 
71 // XServiceInfo
72 // --------------------------------------------------------------------------------
73 IMPLEMENT_SERVICE_INFO(ODbaseConnection, "com.sun.star.sdbc.drivers.dbase.Connection", "com.sun.star.sdbc.Connection")
74 
75 // --------------------------------------------------------------------------------
76 Reference< XDatabaseMetaData > SAL_CALL ODbaseConnection::getMetaData(  ) throw(SQLException, RuntimeException)
77 {
78 	::osl::MutexGuard aGuard( m_aMutex );
79 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
80 
81 
82 	Reference< XDatabaseMetaData > xMetaData = m_xMetaData;
83 	if(!xMetaData.is())
84 	{
85 		xMetaData = new ODbaseDatabaseMetaData(this);
86 		m_xMetaData = xMetaData;
87 	}
88 
89 	return xMetaData;
90 }
91 //------------------------------------------------------------------------------
92 ::com::sun::star::uno::Reference< XTablesSupplier > ODbaseConnection::createCatalog()
93 {
94 	::osl::MutexGuard aGuard( m_aMutex );
95 	Reference< XTablesSupplier > xTab = m_xCatalog;
96 	if(!xTab.is())
97 	{
98 		ODbaseCatalog *pCat = new ODbaseCatalog(this);
99 		xTab = pCat;
100 		m_xCatalog = xTab;
101 	}
102 	return xTab;
103 }
104 // --------------------------------------------------------------------------------
105 Reference< XStatement > SAL_CALL ODbaseConnection::createStatement(  ) throw(SQLException, RuntimeException)
106 {
107 	::osl::MutexGuard aGuard( m_aMutex );
108 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
109 
110 
111 	Reference< XStatement > xReturn = new ODbaseStatement(this);
112     m_aStatements.push_back(WeakReferenceHelper(xReturn));
113 	return xReturn;
114 }
115 // --------------------------------------------------------------------------------
116 Reference< XPreparedStatement > SAL_CALL ODbaseConnection::prepareStatement( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException)
117 {
118 	::osl::MutexGuard aGuard( m_aMutex );
119 	checkDisposed(OConnection_BASE::rBHelper.bDisposed);
120 
121 
122 	ODbasePreparedStatement* pStmt = new ODbasePreparedStatement(this);
123 	Reference< XPreparedStatement > xHoldAlive = pStmt;
124 	pStmt->construct(sql);
125     m_aStatements.push_back(WeakReferenceHelper(*pStmt));
126 	return pStmt;
127 }
128 // --------------------------------------------------------------------------------
129 Reference< XPreparedStatement > SAL_CALL ODbaseConnection::prepareCall( const ::rtl::OUString& /*sql*/ ) throw(SQLException, RuntimeException)
130 {
131     ::dbtools::throwFeatureNotImplementedException( "XConnection::prepareCall", *this );
132 	return NULL;
133 }
134 // -----------------------------------------------------------------------------
135 
136