Cleanup Connection and rename from OConnection. (firebird-sdbc)

Change-Id: I06cfdc29d7613638d3cea080e7b39c67c74d4de0
This commit is contained in:
Andrzej J.R. Hunt
2013-09-09 17:28:08 +01:00
parent 732e8c62ac
commit 5b74c6563c
13 changed files with 241 additions and 203 deletions

View File

@@ -71,47 +71,44 @@ using namespace ::com::sun::star::sdbc;
using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::sdbcx;
using namespace ::com::sun::star::uno; using namespace ::com::sun::star::uno;
const OUString OConnection::sDBLocation( "firebird.fdb" ); const OUString Connection::our_sDBLocation( "firebird.fdb" );
OConnection::OConnection(FirebirdDriver* _pDriver) Connection::Connection(FirebirdDriver* _pDriver)
:OConnection_BASE(m_aMutex), : Connection_BASE(m_aMutex)
OSubComponent<OConnection, OConnection_BASE>((::cppu::OWeakObject*)_pDriver, this), , OSubComponent<Connection, Connection_BASE>((::cppu::OWeakObject*)_pDriver, this)
m_xMetaData(NULL), , m_pDriver(_pDriver)
m_bIsEmbedded(sal_False), , m_sConnectionURL()
m_sConnectionURL(), , m_sFirebirdURL()
m_sURL(), , m_bIsEmbedded(sal_False)
m_sUser(), , m_xEmbeddedStorage(0)
m_pDriver(_pDriver), , m_sUser()
m_bClosed(sal_False), , m_bIsAutoCommit(sal_False)
m_bUseOldDateFormat(sal_False), , m_bIsReadOnly(sal_False)
m_bAutoCommit(sal_False), , m_aTransactionIsolation(TransactionIsolation::REPEATABLE_READ)
m_bReadOnly(sal_False), , m_aDBHandle(0)
m_aTransactionIsolation(TransactionIsolation::REPEATABLE_READ), , m_aTransactionHandle(0)
m_DBHandler(0), , m_xCatalog(0)
m_transactionHandle(0), , m_xMetaData(0)
m_xCatalog(0) , m_aStatements()
{ {
SAL_INFO("connectivity.firebird", "OConnection().");
m_pDriver->acquire(); m_pDriver->acquire();
} }
OConnection::~OConnection() Connection::~Connection()
{ {
SAL_INFO("connectivity.firebird", "~OConnection().");
if(!isClosed()) if(!isClosed())
close(); close();
m_pDriver->release(); m_pDriver->release();
m_pDriver = NULL; m_pDriver = 0;
} }
void SAL_CALL OConnection::release() throw() void SAL_CALL Connection::release() throw()
{ {
relase_ChildImpl(); relase_ChildImpl();
} }
void OConnection::construct(const ::rtl::OUString& url, const Sequence< PropertyValue >& info) void Connection::construct(const ::rtl::OUString& url, const Sequence< PropertyValue >& info)
throw(SQLException, RuntimeException) throw(SQLException, RuntimeException)
{ {
SAL_INFO("connectivity.firebird", "construct()."); SAL_INFO("connectivity.firebird", "construct().");
@@ -151,21 +148,21 @@ void OConnection::construct(const ::rtl::OUString& url, const Sequence< Property
m_pExtractedFDBFile.reset(new ::utl::TempFile(NULL, true)); m_pExtractedFDBFile.reset(new ::utl::TempFile(NULL, true));
m_pExtractedFDBFile->EnableKillingFile(); m_pExtractedFDBFile->EnableKillingFile();
m_sURL = m_pExtractedFDBFile->GetFileName() + "/firebird.fdb"; m_sFirebirdURL = m_pExtractedFDBFile->GetFileName() + "/firebird.fdb";
SAL_INFO("connectivity.firebird", "Temporary .fdb location: " << m_sURL); SAL_INFO("connectivity.firebird", "Temporary .fdb location: " << m_sFirebirdURL);
if (!bIsNewDatabase) if (!bIsNewDatabase)
{ {
SAL_INFO("connectivity.firebird", "Extracting .fdb from .odb" ); SAL_INFO("connectivity.firebird", "Extracting .fdb from .odb" );
if (!m_xEmbeddedStorage->isStreamElement(sDBLocation)) if (!m_xEmbeddedStorage->isStreamElement(our_sDBLocation))
{ {
::connectivity::SharedResources aResources; ::connectivity::SharedResources aResources;
const OUString sMessage = aResources.getResourceString(STR_ERROR_NEW_VERSION); const OUString sMessage = aResources.getResourceString(STR_ERROR_NEW_VERSION);
::dbtools::throwGenericSQLException(sMessage ,*this); ::dbtools::throwGenericSQLException(sMessage ,*this);
} }
Reference< XStream > xDBStream(m_xEmbeddedStorage->openStreamElement(sDBLocation, Reference< XStream > xDBStream(m_xEmbeddedStorage->openStreamElement(our_sDBLocation,
ElementModes::READ)); ElementModes::READ));
uno::Reference< ucb::XSimpleFileAccess2 > xFileAccess( uno::Reference< ucb::XSimpleFileAccess2 > xFileAccess(
@@ -178,7 +175,7 @@ void OConnection::construct(const ::rtl::OUString& url, const Sequence< Property
::dbtools::throwGenericSQLException(sMessage ,*this); ::dbtools::throwGenericSQLException(sMessage ,*this);
} }
xFileAccess->writeFile(m_sURL,xDBStream->getInputStream()); xFileAccess->writeFile(m_sFirebirdURL,xDBStream->getInputStream());
} }
// TOOO: Get DB properties from XML // TOOO: Get DB properties from XML
@@ -186,13 +183,13 @@ void OConnection::construct(const ::rtl::OUString& url, const Sequence< Property
// External file AND/OR remote connection // External file AND/OR remote connection
else if (url.startsWith("sdbc:firebird:")) else if (url.startsWith("sdbc:firebird:"))
{ {
m_sURL = url.copy(OUString("sdbc:firebird:").getLength()); m_sFirebirdURL = url.copy(OUString("sdbc:firebird:").getLength());
if (m_sURL.startsWith("file://")) // TODO: are file urls really like this? if (m_sFirebirdURL.startsWith("file://")) // TODO: are file urls really like this?
{ {
uno::Reference< ucb::XSimpleFileAccess > xFileAccess( uno::Reference< ucb::XSimpleFileAccess > xFileAccess(
ucb::SimpleFileAccess::create(comphelper::getProcessComponentContext()), ucb::SimpleFileAccess::create(comphelper::getProcessComponentContext()),
uno::UNO_QUERY); uno::UNO_QUERY);
if (!xFileAccess->exists(m_sURL)) if (!xFileAccess->exists(m_sFirebirdURL))
bIsNewDatabase = true; bIsNewDatabase = true;
} }
} }
@@ -249,9 +246,9 @@ void OConnection::construct(const ::rtl::OUString& url, const Sequence< Property
if (bIsNewDatabase) if (bIsNewDatabase)
{ {
aErr = isc_create_database(status, aErr = isc_create_database(status,
m_sURL.getLength(), m_sFirebirdURL.getLength(),
OUStringToOString(m_sURL,RTL_TEXTENCODING_UTF8).getStr(), OUStringToOString(m_sFirebirdURL,RTL_TEXTENCODING_UTF8).getStr(),
&m_DBHandler, &m_aDBHandle,
dpbLength, dpbLength,
dpbBuffer, dpbBuffer,
0); 0);
@@ -263,9 +260,9 @@ void OConnection::construct(const ::rtl::OUString& url, const Sequence< Property
else else
{ {
aErr = isc_attach_database(status, aErr = isc_attach_database(status,
m_sURL.getLength(), m_sFirebirdURL.getLength(),
OUStringToOString(m_sURL, RTL_TEXTENCODING_UTF8).getStr(), OUStringToOString(m_sFirebirdURL, RTL_TEXTENCODING_UTF8).getStr(),
&m_DBHandler, &m_aDBHandle,
dpbLength, dpbLength,
dpbBuffer); dpbBuffer);
if (aErr) if (aErr)
@@ -282,16 +279,30 @@ void OConnection::construct(const ::rtl::OUString& url, const Sequence< Property
// it in the .odb. // it in the .odb.
rebuildIndexes(); rebuildIndexes();
attachAsDocumentListener(aStorageURL);
}
osl_atomic_decrement( &m_refCount );
}
void Connection::attachAsDocumentListener(const OUString& rStorageURL)
{
// We can't directly access the Document that is using this connection
// (since a Connection can in fact be used independently of a DB document)
// hence we need to iterate through all Frames to find our Document.
uno::Reference< frame::XDesktop2 > xFramesSupplier = uno::Reference< frame::XDesktop2 > xFramesSupplier =
frame::Desktop::create(::comphelper::getProcessComponentContext()); frame::Desktop::create(::comphelper::getProcessComponentContext());
uno::Reference< frame::XFrames > xFrames(xFramesSupplier->getFrames(), uno::Reference< frame::XFrames > xFrames(xFramesSupplier->getFrames(),
uno::UNO_QUERY); uno::UNO_QUERY);
if (!xFrames.is())
return;
uno::Sequence< uno::Reference<frame::XFrame> > xFrameList = uno::Sequence< uno::Reference<frame::XFrame> > xFrameList =
xFrames->queryFrames( frame::FrameSearchFlag::ALL ); xFrames->queryFrames( frame::FrameSearchFlag::ALL );
for (sal_Int32 i = 0; i < xFrameList.getLength(); i++) for (sal_Int32 i = 0; i < xFrameList.getLength(); i++)
{ {
uno::Reference< frame::XFrame > xf = xFrameList[i]; uno::Reference< frame::XFrame > xf = xFrameList[i];
uno::Reference< XController > xc; uno::Reference< XController > xc;
if (xf.is()) if (xf.is())
xc = xf->getController(); xc = xf->getController();
@@ -300,36 +311,33 @@ void OConnection::construct(const ::rtl::OUString& url, const Sequence< Property
if (xc.is()) if (xc.is())
xm = xc->getModel(); xm = xc->getModel();
OUString aURL; if (xm.is() && xm->getURL() == rStorageURL)
if (xm.is())
aURL = xm->getURL();
if (aURL == aStorageURL)
{ {
uno::Reference<XDocumentEventBroadcaster> xBroadcaster( xm, UNO_QUERY); uno::Reference<XDocumentEventBroadcaster> xBroadcaster( xm, UNO_QUERY);
if (xBroadcaster.is()) if (xBroadcaster.is())
{
xBroadcaster->addDocumentEventListener(this); xBroadcaster->addDocumentEventListener(this);
return;
}
//TODO: remove in the disposing? //TODO: remove in the disposing?
} }
} }
} assert(false); // If we have an embedded DB we must have a document
osl_atomic_decrement( &m_refCount );
} }
//----- XServiceInfo --------------------------------------------------------- //----- XServiceInfo ---------------------------------------------------------
IMPLEMENT_SERVICE_INFO(OConnection, "com.sun.star.sdbc.drivers.firebird.OConnection", IMPLEMENT_SERVICE_INFO(Connection, "com.sun.star.sdbc.drivers.firebird.Connection",
"com.sun.star.sdbc.Connection") "com.sun.star.sdbc.Connection")
Reference< XBlob> OConnection::createBlob(ISC_QUAD* pBlobId) Reference< XBlob> Connection::createBlob(ISC_QUAD* pBlobId)
throw(SQLException, RuntimeException) throw(SQLException, RuntimeException)
{ {
SAL_INFO("connectivity.firebird", "createBlob()"); SAL_INFO("connectivity.firebird", "createBlob()");
MutexGuard aGuard(m_aMutex); MutexGuard aGuard(m_aMutex);
checkDisposed(OConnection_BASE::rBHelper.bDisposed); checkDisposed(Connection_BASE::rBHelper.bDisposed);
Reference< XBlob > xReturn = new Blob(&m_DBHandler, Reference< XBlob > xReturn = new Blob(&m_aDBHandle,
&m_transactionHandle, &m_aTransactionHandle,
*pBlobId); *pBlobId);
m_aStatements.push_back(WeakReferenceHelper(xReturn)); m_aStatements.push_back(WeakReferenceHelper(xReturn));
@@ -338,13 +346,13 @@ Reference< XBlob> OConnection::createBlob(ISC_QUAD* pBlobId)
//----- XConnection ---------------------------------------------------------- //----- XConnection ----------------------------------------------------------
Reference< XStatement > SAL_CALL OConnection::createStatement( ) Reference< XStatement > SAL_CALL Connection::createStatement( )
throw(SQLException, RuntimeException) throw(SQLException, RuntimeException)
{ {
SAL_INFO("connectivity.firebird", "createStatement()."); SAL_INFO("connectivity.firebird", "createStatement().");
MutexGuard aGuard( m_aMutex ); MutexGuard aGuard( m_aMutex );
checkDisposed(OConnection_BASE::rBHelper.bDisposed); checkDisposed(Connection_BASE::rBHelper.bDisposed);
// the pre // the pre
if(m_aTypeInfo.empty()) if(m_aTypeInfo.empty())
@@ -360,14 +368,14 @@ Reference< XStatement > SAL_CALL OConnection::createStatement( )
return xReturn; return xReturn;
} }
Reference< XPreparedStatement > SAL_CALL OConnection::prepareStatement( Reference< XPreparedStatement > SAL_CALL Connection::prepareStatement(
const OUString& _sSql) const OUString& _sSql)
throw(SQLException, RuntimeException) throw(SQLException, RuntimeException)
{ {
SAL_INFO("connectivity.firebird", "prepareStatement() " SAL_INFO("connectivity.firebird", "prepareStatement() "
"called with sql: " << _sSql); "called with sql: " << _sSql);
MutexGuard aGuard(m_aMutex); MutexGuard aGuard(m_aMutex);
checkDisposed(OConnection_BASE::rBHelper.bDisposed); checkDisposed(Connection_BASE::rBHelper.bDisposed);
if(m_aTypeInfo.empty()) if(m_aTypeInfo.empty())
buildTypeInfo(); buildTypeInfo();
@@ -380,20 +388,20 @@ Reference< XPreparedStatement > SAL_CALL OConnection::prepareStatement(
return xReturn; return xReturn;
} }
Reference< XPreparedStatement > SAL_CALL OConnection::prepareCall( Reference< XPreparedStatement > SAL_CALL Connection::prepareCall(
const OUString& _sSql ) throw(SQLException, RuntimeException) const OUString& _sSql ) throw(SQLException, RuntimeException)
{ {
SAL_INFO("connectivity.firebird", "prepareCall(). " SAL_INFO("connectivity.firebird", "prepareCall(). "
"_sSql: " << _sSql); "_sSql: " << _sSql);
MutexGuard aGuard( m_aMutex ); MutexGuard aGuard( m_aMutex );
checkDisposed(OConnection_BASE::rBHelper.bDisposed); checkDisposed(Connection_BASE::rBHelper.bDisposed);
// not implemented yet :-) a task to do // not implemented yet :-) a task to do
return NULL; return NULL;
} }
OUString SAL_CALL OConnection::nativeSQL( const OUString& _sSql ) OUString SAL_CALL Connection::nativeSQL( const OUString& _sSql )
throw(SQLException, RuntimeException) throw(SQLException, RuntimeException)
{ {
MutexGuard aGuard( m_aMutex ); MutexGuard aGuard( m_aMutex );
@@ -401,29 +409,29 @@ OUString SAL_CALL OConnection::nativeSQL( const OUString& _sSql )
return _sSql; return _sSql;
} }
void SAL_CALL OConnection::setAutoCommit( sal_Bool autoCommit ) void SAL_CALL Connection::setAutoCommit( sal_Bool autoCommit )
throw(SQLException, RuntimeException) throw(SQLException, RuntimeException)
{ {
MutexGuard aGuard( m_aMutex ); MutexGuard aGuard( m_aMutex );
checkDisposed(OConnection_BASE::rBHelper.bDisposed); checkDisposed(Connection_BASE::rBHelper.bDisposed);
m_bAutoCommit = autoCommit; m_bIsAutoCommit = autoCommit;
if (m_transactionHandle) if (m_aTransactionHandle)
{ {
setupTransaction(); setupTransaction();
} }
} }
sal_Bool SAL_CALL OConnection::getAutoCommit() throw(SQLException, RuntimeException) sal_Bool SAL_CALL Connection::getAutoCommit() throw(SQLException, RuntimeException)
{ {
MutexGuard aGuard( m_aMutex ); MutexGuard aGuard( m_aMutex );
checkDisposed(OConnection_BASE::rBHelper.bDisposed); checkDisposed(Connection_BASE::rBHelper.bDisposed);
return m_bAutoCommit; return m_bIsAutoCommit;
} }
void OConnection::setupTransaction() void Connection::setupTransaction()
throw (SQLException) throw (SQLException)
{ {
MutexGuard aGuard( m_aMutex ); MutexGuard aGuard( m_aMutex );
@@ -431,10 +439,10 @@ void OConnection::setupTransaction()
// TODO: is this sensible? If we have changed parameters then transaction // TODO: is this sensible? If we have changed parameters then transaction
// is lost... // is lost...
if (m_transactionHandle) if (m_aTransactionHandle)
{ {
clearStatements(); disposeStatements();
isc_rollback_transaction(status_vector, &m_transactionHandle); isc_rollback_transaction(status_vector, &m_aTransactionHandle);
} }
char aTransactionIsolation = 0; char aTransactionIsolation = 0;
@@ -463,16 +471,16 @@ void OConnection::setupTransaction()
char* pTPB = aTPB; char* pTPB = aTPB;
*pTPB++ = isc_tpb_version3; *pTPB++ = isc_tpb_version3;
if (m_bAutoCommit) if (m_bIsAutoCommit)
*pTPB++ = isc_tpb_autocommit; *pTPB++ = isc_tpb_autocommit;
*pTPB++ = (!m_bReadOnly ? isc_tpb_write : isc_tpb_read); *pTPB++ = (!m_bIsReadOnly ? isc_tpb_write : isc_tpb_read);
*pTPB++ = aTransactionIsolation; *pTPB++ = aTransactionIsolation;
*pTPB++ = isc_tpb_wait; *pTPB++ = isc_tpb_wait;
isc_start_transaction(status_vector, isc_start_transaction(status_vector,
&m_transactionHandle, &m_aTransactionHandle,
1, 1,
&m_DBHandler, &m_aDBHandle,
pTPB - aTPB, // bytes used in TPB pTPB - aTPB, // bytes used in TPB
aTPB); aTPB);
@@ -481,59 +489,59 @@ void OConnection::setupTransaction()
*this); *this);
} }
isc_tr_handle& OConnection::getTransaction() isc_tr_handle& Connection::getTransaction()
throw (SQLException) throw (SQLException)
{ {
MutexGuard aGuard( m_aMutex ); MutexGuard aGuard( m_aMutex );
if (!m_transactionHandle) if (!m_aTransactionHandle)
{ {
setupTransaction(); setupTransaction();
} }
return m_transactionHandle; return m_aTransactionHandle;
} }
void SAL_CALL OConnection::commit() throw(SQLException, RuntimeException) void SAL_CALL Connection::commit() throw(SQLException, RuntimeException)
{ {
MutexGuard aGuard( m_aMutex ); MutexGuard aGuard( m_aMutex );
checkDisposed(OConnection_BASE::rBHelper.bDisposed); checkDisposed(Connection_BASE::rBHelper.bDisposed);
ISC_STATUS status_vector[20]; ISC_STATUS status_vector[20];
if (!m_bAutoCommit && m_transactionHandle) if (!m_bIsAutoCommit && m_aTransactionHandle)
{ {
clearStatements(); disposeStatements();
isc_commit_transaction(status_vector, &m_transactionHandle); isc_commit_transaction(status_vector, &m_aTransactionHandle);
evaluateStatusVector(status_vector, evaluateStatusVector(status_vector,
"isc_commit_transaction", "isc_commit_transaction",
*this); *this);
} }
} }
void SAL_CALL OConnection::rollback() throw(SQLException, RuntimeException) void SAL_CALL Connection::rollback() throw(SQLException, RuntimeException)
{ {
MutexGuard aGuard( m_aMutex ); MutexGuard aGuard( m_aMutex );
checkDisposed(OConnection_BASE::rBHelper.bDisposed); checkDisposed(Connection_BASE::rBHelper.bDisposed);
ISC_STATUS status_vector[20]; ISC_STATUS status_vector[20];
if (!m_bAutoCommit && m_transactionHandle) if (!m_bIsAutoCommit && m_aTransactionHandle)
{ {
isc_rollback_transaction(status_vector, &m_transactionHandle); isc_rollback_transaction(status_vector, &m_aTransactionHandle);
} }
} }
sal_Bool SAL_CALL OConnection::isClosed( ) throw(SQLException, RuntimeException) sal_Bool SAL_CALL Connection::isClosed( ) throw(SQLException, RuntimeException)
{ {
MutexGuard aGuard( m_aMutex ); MutexGuard aGuard( m_aMutex );
// just simple -> we are close when we are disposed taht means someone called dispose(); (XComponent) // just simple -> we are close when we are disposed taht means someone called dispose(); (XComponent)
return OConnection_BASE::rBHelper.bDisposed; return Connection_BASE::rBHelper.bDisposed;
} }
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
Reference< XDatabaseMetaData > SAL_CALL OConnection::getMetaData( ) throw(SQLException, RuntimeException) Reference< XDatabaseMetaData > SAL_CALL Connection::getMetaData( ) throw(SQLException, RuntimeException)
{ {
MutexGuard aGuard( m_aMutex ); MutexGuard aGuard( m_aMutex );
checkDisposed(OConnection_BASE::rBHelper.bDisposed); checkDisposed(Connection_BASE::rBHelper.bDisposed);
// here we have to create the class with biggest interface // here we have to create the class with biggest interface
// The answer is 42 :-) // The answer is 42 :-)
@@ -547,61 +555,61 @@ Reference< XDatabaseMetaData > SAL_CALL OConnection::getMetaData( ) throw(SQLEx
return xMetaData; return xMetaData;
} }
void SAL_CALL OConnection::setReadOnly(sal_Bool readOnly) void SAL_CALL Connection::setReadOnly(sal_Bool readOnly)
throw(SQLException, RuntimeException) throw(SQLException, RuntimeException)
{ {
MutexGuard aGuard( m_aMutex ); MutexGuard aGuard( m_aMutex );
checkDisposed(OConnection_BASE::rBHelper.bDisposed); checkDisposed(Connection_BASE::rBHelper.bDisposed);
m_bReadOnly = readOnly; m_bIsReadOnly = readOnly;
setupTransaction(); setupTransaction();
} }
sal_Bool SAL_CALL OConnection::isReadOnly() throw(SQLException, RuntimeException) sal_Bool SAL_CALL Connection::isReadOnly() throw(SQLException, RuntimeException)
{ {
MutexGuard aGuard( m_aMutex ); MutexGuard aGuard( m_aMutex );
checkDisposed(OConnection_BASE::rBHelper.bDisposed); checkDisposed(Connection_BASE::rBHelper.bDisposed);
return m_bReadOnly; return m_bIsReadOnly;
} }
void SAL_CALL OConnection::setCatalog(const OUString& /*catalog*/) void SAL_CALL Connection::setCatalog(const OUString& /*catalog*/)
throw(SQLException, RuntimeException) throw(SQLException, RuntimeException)
{ {
::dbtools::throwFunctionNotSupportedException("setCatalog", *this); ::dbtools::throwFunctionNotSupportedException("setCatalog", *this);
} }
OUString SAL_CALL OConnection::getCatalog() OUString SAL_CALL Connection::getCatalog()
throw(SQLException, RuntimeException) throw(SQLException, RuntimeException)
{ {
::dbtools::throwFunctionNotSupportedException("getCatalog", *this); ::dbtools::throwFunctionNotSupportedException("getCatalog", *this);
return OUString(); return OUString();
} }
void SAL_CALL OConnection::setTransactionIsolation( sal_Int32 level ) throw(SQLException, RuntimeException) void SAL_CALL Connection::setTransactionIsolation( sal_Int32 level ) throw(SQLException, RuntimeException)
{ {
MutexGuard aGuard( m_aMutex ); MutexGuard aGuard( m_aMutex );
checkDisposed(OConnection_BASE::rBHelper.bDisposed); checkDisposed(Connection_BASE::rBHelper.bDisposed);
m_aTransactionIsolation = level; m_aTransactionIsolation = level;
setupTransaction(); setupTransaction();
} }
sal_Int32 SAL_CALL OConnection::getTransactionIsolation( ) throw(SQLException, RuntimeException) sal_Int32 SAL_CALL Connection::getTransactionIsolation( ) throw(SQLException, RuntimeException)
{ {
MutexGuard aGuard( m_aMutex ); MutexGuard aGuard( m_aMutex );
checkDisposed(OConnection_BASE::rBHelper.bDisposed); checkDisposed(Connection_BASE::rBHelper.bDisposed);
return m_aTransactionIsolation; return m_aTransactionIsolation;
} }
Reference< XNameAccess > SAL_CALL OConnection::getTypeMap() throw(SQLException, RuntimeException) Reference< XNameAccess > SAL_CALL Connection::getTypeMap() throw(SQLException, RuntimeException)
{ {
::dbtools::throwFeatureNotImplementedException( "XConnection::getTypeMap", *this ); ::dbtools::throwFeatureNotImplementedException( "XConnection::getTypeMap", *this );
return 0; return 0;
} }
void SAL_CALL OConnection::setTypeMap(const Reference< XNameAccess >& typeMap) void SAL_CALL Connection::setTypeMap(const Reference< XNameAccess >& typeMap)
throw(SQLException, RuntimeException) throw(SQLException, RuntimeException)
{ {
::dbtools::throwFeatureNotImplementedException( "XConnection::setTypeMap", *this ); ::dbtools::throwFeatureNotImplementedException( "XConnection::setTypeMap", *this );
@@ -609,33 +617,33 @@ void SAL_CALL OConnection::setTypeMap(const Reference< XNameAccess >& typeMap)
} }
//----- XCloseable ----------------------------------------------------------- //----- XCloseable -----------------------------------------------------------
void SAL_CALL OConnection::close( ) throw(SQLException, RuntimeException) void SAL_CALL Connection::close( ) throw(SQLException, RuntimeException)
{ {
SAL_INFO("connectivity.firebird", "close()."); SAL_INFO("connectivity.firebird", "close().");
// we just dispose us // we just dispose us
{ {
MutexGuard aGuard( m_aMutex ); MutexGuard aGuard( m_aMutex );
checkDisposed(OConnection_BASE::rBHelper.bDisposed); checkDisposed(Connection_BASE::rBHelper.bDisposed);
} }
dispose(); dispose();
} }
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
// XWarningsSupplier // XWarningsSupplier
Any SAL_CALL OConnection::getWarnings( ) throw(SQLException, RuntimeException) Any SAL_CALL Connection::getWarnings( ) throw(SQLException, RuntimeException)
{ {
// when you collected some warnings -> return it // when you collected some warnings -> return it
return Any(); return Any();
} }
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
void SAL_CALL OConnection::clearWarnings( ) throw(SQLException, RuntimeException) void SAL_CALL Connection::clearWarnings( ) throw(SQLException, RuntimeException)
{ {
// you should clear your collected warnings here // you should clear your collected warnings here
} }
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
// XDocumentEventListener // XDocumentEventListener
void SAL_CALL OConnection::documentEventOccured( const DocumentEvent& _Event ) void SAL_CALL Connection::documentEventOccured( const DocumentEvent& _Event )
throw(RuntimeException) throw(RuntimeException)
{ {
MutexGuard aGuard(m_aMutex); MutexGuard aGuard(m_aMutex);
@@ -650,7 +658,7 @@ void SAL_CALL OConnection::documentEventOccured( const DocumentEvent& _Event )
{ {
SAL_INFO("connectivity.firebird", "Writing .fdb into .odb" ); SAL_INFO("connectivity.firebird", "Writing .fdb into .odb" );
Reference< XStream > xDBStream(m_xEmbeddedStorage->openStreamElement(sDBLocation, Reference< XStream > xDBStream(m_xEmbeddedStorage->openStreamElement(our_sDBLocation,
ElementModes::WRITE)); ElementModes::WRITE));
using namespace ::comphelper; using namespace ::comphelper;
@@ -658,7 +666,7 @@ void SAL_CALL OConnection::documentEventOccured( const DocumentEvent& _Event )
Reference< XInputStream > xInputStream; Reference< XInputStream > xInputStream;
if (xContext.is()) if (xContext.is())
xInputStream = xInputStream =
OStorageHelper::GetInputStreamFromURL(m_sURL, xContext); OStorageHelper::GetInputStreamFromURL(m_sFirebirdURL, xContext);
if (xInputStream.is()) if (xInputStream.is())
OStorageHelper::CopyInputToOutput( xInputStream, OStorageHelper::CopyInputToOutput( xInputStream,
xDBStream->getOutputStream()); xDBStream->getOutputStream());
@@ -667,12 +675,12 @@ void SAL_CALL OConnection::documentEventOccured( const DocumentEvent& _Event )
} }
} }
// XEventListener // XEventListener
void SAL_CALL OConnection::disposing(const EventObject& /*rSource*/) void SAL_CALL Connection::disposing(const EventObject& /*rSource*/)
throw (RuntimeException) throw (RuntimeException)
{ {
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
void OConnection::buildTypeInfo() throw( SQLException) void Connection::buildTypeInfo() throw( SQLException)
{ {
SAL_INFO("connectivity.firebird", "buildTypeInfo()."); SAL_INFO("connectivity.firebird", "buildTypeInfo().");
@@ -725,25 +733,24 @@ void OConnection::buildTypeInfo() throw( SQLException)
"Closed."); "Closed.");
} }
void OConnection::disposing() void Connection::disposing()
{ {
SAL_INFO("connectivity.firebird", "disposing()."); SAL_INFO("connectivity.firebird", "disposing().");
MutexGuard aGuard(m_aMutex); MutexGuard aGuard(m_aMutex);
clearStatements(); disposeStatements();
m_bClosed = sal_True;
m_xMetaData = ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XDatabaseMetaData>(); m_xMetaData = ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XDatabaseMetaData>();
ISC_STATUS_ARRAY status; /* status vector */ ISC_STATUS_ARRAY status; /* status vector */
if (m_transactionHandle) if (m_aTransactionHandle)
{ {
// TODO: confirm whether we need to ask the user here. // TODO: confirm whether we need to ask the user here.
isc_rollback_transaction(status, &m_transactionHandle); isc_rollback_transaction(status, &m_aTransactionHandle);
} }
if (isc_detach_database(status, &m_DBHandler)) if (isc_detach_database(status, &m_aDBHandle))
{ {
evaluateStatusVector(status, "isc_detach_database", *this); evaluateStatusVector(status, "isc_detach_database", *this);
} }
@@ -753,7 +760,7 @@ void OConnection::disposing()
cppu::WeakComponentImplHelperBase::disposing(); cppu::WeakComponentImplHelperBase::disposing();
} }
void OConnection::clearStatements() void Connection::disposeStatements()
{ {
MutexGuard aGuard(m_aMutex); MutexGuard aGuard(m_aMutex);
for (OWeakRefArray::iterator i = m_aStatements.begin(); m_aStatements.end() != i; ++i) for (OWeakRefArray::iterator i = m_aStatements.begin(); m_aStatements.end() != i; ++i)
@@ -765,7 +772,7 @@ void OConnection::clearStatements()
m_aStatements.clear(); m_aStatements.clear();
} }
uno::Reference< XTablesSupplier > OConnection::createCatalog() uno::Reference< XTablesSupplier > Connection::createCatalog()
{ {
MutexGuard aGuard(m_aMutex); MutexGuard aGuard(m_aMutex);
@@ -784,7 +791,7 @@ uno::Reference< XTablesSupplier > OConnection::createCatalog()
} }
void OConnection::rebuildIndexes() throw(SQLException) void Connection::rebuildIndexes() throw(SQLException)
{ {
SAL_INFO("connectivity.firebird", "rebuildIndexes()"); SAL_INFO("connectivity.firebird", "rebuildIndexes()");
MutexGuard aGuard(m_aMutex); MutexGuard aGuard(m_aMutex);

View File

@@ -55,7 +55,7 @@ namespace connectivity
::com::sun::star::lang::XServiceInfo, ::com::sun::star::lang::XServiceInfo,
::com::sun::star::sdbc::XConnection, ::com::sun::star::sdbc::XConnection,
::com::sun::star::sdbc::XWarningsSupplier ::com::sun::star::sdbc::XWarningsSupplier
> OConnection_BASE; > Connection_BASE;
class OStatementCommonBase; class OStatementCommonBase;
class FirebirdDriver; class FirebirdDriver;
@@ -65,57 +65,80 @@ namespace connectivity
typedef ::std::vector< ::connectivity::OTypeInfo> TTypeInfoVector; typedef ::std::vector< ::connectivity::OTypeInfo> TTypeInfoVector;
typedef std::vector< ::com::sun::star::uno::WeakReferenceHelper > OWeakRefArray; typedef std::vector< ::com::sun::star::uno::WeakReferenceHelper > OWeakRefArray;
class OConnection : public OConnection_BASE, class Connection : public Connection_BASE,
public connectivity::OSubComponent<OConnection, OConnection_BASE> public connectivity::OSubComponent<Connection, Connection_BASE>
{ {
friend class connectivity::OSubComponent<OConnection, OConnection_BASE>; friend class connectivity::OSubComponent<Connection, Connection_BASE>;
/**
* Location within the .odb that an embedded .fdb will be stored.
* Only relevant for embedded dbs.
*/
static const OUString our_sDBLocation;
protected: protected:
::osl::Mutex m_aMutex; ::osl::Mutex m_aMutex;
public: public:
::osl::Mutex& getMutex() ::osl::Mutex& getMutex()
{ return m_aMutex; } { return m_aMutex; }
protected: protected:
::boost::scoped_ptr< ::utl::TempFile > m_pExtractedFDBFile;
static const OUString sDBLocation; // Location within .odb container
//====================================================================
// Data attributes
//====================================================================
TTypeInfoVector m_aTypeInfo; // vector containing an entry TTypeInfoVector m_aTypeInfo; // vector containing an entry
// for each row returned by // for each row returned by
// DatabaseMetaData.getTypeInfo. // DatabaseMetaData.getTypeInfo.
::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XDatabaseMetaData > m_xMetaData; /** The parent driver that created this connection. */
FirebirdDriver* m_pDriver;
OWeakRefArray m_aStatements; // vector containing a list /** The URL passed to us when opening, i.e. of the form sdbc:* */
// of all the Statement objects
// for this Connection
::com::sun::star::sdbc::SQLWarning m_aLastWarning; // Last SQLWarning generated by
// an operation
sal_Bool m_bIsEmbedded;
::rtl::OUString m_sConnectionURL; ::rtl::OUString m_sConnectionURL;
::rtl::OUString m_sURL; // URL of connection /**
// or file path * The URL passed to firebird, i.e. either a local file (for a
::rtl::OUString m_sUser; // the user name * temporary .fdb extracted from a .odb or a normal local file) or
FirebirdDriver* m_pDriver; // Pointer to the owning * a remote url.
// driver object */
::rtl::OUString m_sFirebirdURL;
sal_Bool m_bClosed;
sal_Bool m_bUseOldDateFormat;
sal_Bool m_bAutoCommit;
sal_Bool m_bReadOnly;
sal_Int32 m_aTransactionIsolation;
isc_db_handle m_DBHandler;
isc_tr_handle m_transactionHandle;
/* EMBEDDED MODE DATA */
/** Denotes that we have a .fdb stored within a .odb file. */
sal_Bool m_bIsEmbedded;
/**
* Handle for the folder within the .odb where we store our .fdb
* (Only used if m_bIsEmbedded is true).
*/
::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >
m_xEmbeddedStorage; m_xEmbeddedStorage;
/**
* The temporary folder where we extract the .fdb from a .odb.
* It is only valid if m_bIsEmbedded is true.
*/
::boost::scoped_ptr< ::utl::TempFile > m_pExtractedFDBFile;
/* REMOTE CONNECTION DATA */
::rtl::OUString m_sUser;
/* CONNECTION PROPERTIES */
sal_Bool m_bIsAutoCommit;
sal_Bool m_bIsReadOnly;
sal_Int32 m_aTransactionIsolation;
isc_db_handle m_aDBHandle;
isc_tr_handle m_aTransactionHandle;
::com::sun::star::uno::WeakReference< ::com::sun::star::sdbcx::XTablesSupplier> ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbcx::XTablesSupplier>
m_xCatalog; m_xCatalog;
::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XDatabaseMetaData >
m_xMetaData;
/** Statements owned by this connection. */
OWeakRefArray m_aStatements;
/**
* If we are embedded in a .odb we need to listen to Document events
* in order to save the .fdb back into the .odb.
*/
void attachAsDocumentListener(const ::rtl::OUString& rStorageURL);
/** /**
* Firebird stores binary collations for indexes on Character based * Firebird stores binary collations for indexes on Character based
@@ -123,19 +146,27 @@ namespace connectivity
* version, hence we need to rebuild the indexes when switching icu * version, hence we need to rebuild the indexes when switching icu
* versions. * versions.
*/ */
void rebuildIndexes() throw( ::com::sun::star::sdbc::SQLException); void rebuildIndexes()
void buildTypeInfo() throw( ::com::sun::star::sdbc::SQLException); throw(::com::sun::star::sdbc::SQLException);
void buildTypeInfo()
throw(::com::sun::star::sdbc::SQLException);
void setupTransaction() throw(::com::sun::star::sdbc::SQLException); /**
void clearStatements(); * Creates a new transaction with the desired parameters, if
* necessary discarding an existing transaction. This has to be done
* anytime we change the transaction isolation, or autocommiting.
*/
void setupTransaction()
throw(::com::sun::star::sdbc::SQLException);
void disposeStatements();
public: public:
virtual void construct( const ::rtl::OUString& url, virtual void construct( const ::rtl::OUString& url,
const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& info) const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& info)
throw(::com::sun::star::sdbc::SQLException, throw(::com::sun::star::sdbc::SQLException,
::com::sun::star::uno::RuntimeException); ::com::sun::star::uno::RuntimeException);
OConnection(FirebirdDriver* _pDriver); Connection(FirebirdDriver* _pDriver);
virtual ~OConnection(); virtual ~Connection();
void closeAllStatements () throw( ::com::sun::star::sdbc::SQLException); void closeAllStatements () throw( ::com::sun::star::sdbc::SQLException);
@@ -176,7 +207,7 @@ namespace connectivity
virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException); virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
inline ::rtl::OUString getUserName() const { return m_sUser; } inline ::rtl::OUString getUserName() const { return m_sUser; }
inline isc_db_handle& getDBHandle() { return m_DBHandler; } inline isc_db_handle& getDBHandle() { return m_aDBHandle; }
inline FirebirdDriver* getDriver() const { return m_pDriver;} inline FirebirdDriver* getDriver() const { return m_pDriver;}
::rtl::OUString getConnectionURL() const { return m_sConnectionURL; } ::rtl::OUString getConnectionURL() const { return m_sConnectionURL; }

View File

@@ -54,7 +54,7 @@ namespace connectivity
} }
} }
ODatabaseMetaData::ODatabaseMetaData(OConnection* _pCon) ODatabaseMetaData::ODatabaseMetaData(Connection* _pCon)
: m_pConnection(_pCon) : m_pConnection(_pCon)
{ {
OSL_ENSURE(m_pConnection,"ODatabaseMetaData::ODatabaseMetaData: No connection set!"); OSL_ENSURE(m_pConnection,"ODatabaseMetaData::ODatabaseMetaData: No connection set!");

View File

@@ -37,12 +37,12 @@ namespace connectivity
class ODatabaseMetaData : public ODatabaseMetaData_BASE class ODatabaseMetaData : public ODatabaseMetaData_BASE
{ {
OConnection* m_pConnection; Connection* m_pConnection;
public: public:
inline OConnection* getOwnConnection() const { return m_pConnection; } inline Connection* getOwnConnection() const { return m_pConnection; }
ODatabaseMetaData(OConnection* _pCon); ODatabaseMetaData(Connection* _pCon);
virtual ~ODatabaseMetaData(); virtual ~ODatabaseMetaData();
// as I mentioned before this interface is really BIG // as I mentioned before this interface is really BIG

View File

@@ -147,7 +147,7 @@ Reference< XConnection > SAL_CALL FirebirdDriver::connect(
if ( ! acceptsURL(url) ) if ( ! acceptsURL(url) )
return NULL; return NULL;
OConnection* pCon = new OConnection(this); Connection* pCon = new Connection(this);
Reference< XConnection > xCon = pCon; Reference< XConnection > xCon = pCon;
pCon->construct(url, info); pCon->construct(url, info);
m_xConnections.push_back(WeakReferenceHelper(*pCon)); m_xConnections.push_back(WeakReferenceHelper(*pCon));
@@ -193,7 +193,7 @@ uno::Reference< XTablesSupplier > SAL_CALL FirebirdDriver::getDataDefinitionByCo
const uno::Reference< XConnection >& rConnection) const uno::Reference< XConnection >& rConnection)
throw(SQLException, RuntimeException) throw(SQLException, RuntimeException)
{ {
OConnection* pConnection = static_cast< OConnection* >(rConnection.get()); Connection* pConnection = static_cast< Connection* >(rConnection.get());
return uno::Reference< XTablesSupplier >(pConnection->createCatalog(), UNO_QUERY); return uno::Reference< XTablesSupplier >(pConnection->createCatalog(), UNO_QUERY);
} }

View File

@@ -50,7 +50,7 @@ using namespace com::sun::star::util;
IMPLEMENT_SERVICE_INFO(OPreparedStatement,"com.sun.star.sdbcx.firebird.PreparedStatement","com.sun.star.sdbc.PreparedStatement"); IMPLEMENT_SERVICE_INFO(OPreparedStatement,"com.sun.star.sdbcx.firebird.PreparedStatement","com.sun.star.sdbc.PreparedStatement");
OPreparedStatement::OPreparedStatement( OConnection* _pConnection, OPreparedStatement::OPreparedStatement( Connection* _pConnection,
const TTypeInfoVector& _TypeInfo, const TTypeInfoVector& _TypeInfo,
const OUString& sql) const OUString& sql)
:OStatementCommonBase(_pConnection) :OStatementCommonBase(_pConnection)

View File

@@ -96,7 +96,7 @@ namespace connectivity
public: public:
DECLARE_SERVICE_INFO(); DECLARE_SERVICE_INFO();
// a constructor, which is required for returning objects: // a constructor, which is required for returning objects:
OPreparedStatement( OConnection* _pConnection, OPreparedStatement( Connection* _pConnection,
const TTypeInfoVector& _TypeInfo, const TTypeInfoVector& _TypeInfo,
const ::rtl::OUString& sql); const ::rtl::OUString& sql);

View File

@@ -53,7 +53,7 @@ using namespace ::com::sun::star::container;
using namespace ::com::sun::star::io; using namespace ::com::sun::star::io;
using namespace ::com::sun::star::util; using namespace ::com::sun::star::util;
OResultSet::OResultSet(OConnection* pConnection, OResultSet::OResultSet(Connection* pConnection,
const uno::Reference< XInterface >& xStatement, const uno::Reference< XInterface >& xStatement,
isc_stmt_handle& aStatementHandle, isc_stmt_handle& aStatementHandle,
XSQLDA* pSqlda) XSQLDA* pSqlda)

View File

@@ -74,7 +74,7 @@ namespace connectivity
sal_Int32 m_nResultSetConcurrency; sal_Int32 m_nResultSetConcurrency;
protected: protected:
OConnection* m_pConnection; Connection* m_pConnection;
const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& m_xStatement; const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& m_xStatement;
::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSetMetaData> m_xMetaData; ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSetMetaData> m_xMetaData;
@@ -113,7 +113,7 @@ namespace connectivity
public: public:
DECLARE_SERVICE_INFO(); DECLARE_SERVICE_INFO();
OResultSet(OConnection* pConnection, OResultSet(Connection* pConnection,
const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xStatement, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xStatement,
isc_stmt_handle& aStatementHandle, isc_stmt_handle& aStatementHandle,
XSQLDA* aSqlda); XSQLDA* aSqlda);

View File

@@ -38,7 +38,7 @@ namespace connectivity
class OResultSetMetaData : public OResultSetMetaData_BASE class OResultSetMetaData : public OResultSetMetaData_BASE
{ {
protected: protected:
OConnection* m_pConnection; Connection* m_pConnection;
XSQLDA* m_pSqlda; XSQLDA* m_pSqlda;
virtual ~OResultSetMetaData(); virtual ~OResultSetMetaData();
@@ -46,7 +46,7 @@ namespace connectivity
void verifyValidColumn(sal_Int32 column) throw(::com::sun::star::sdbc::SQLException); void verifyValidColumn(sal_Int32 column) throw(::com::sun::star::sdbc::SQLException);
public: public:
// a constructor, which is required for returning objects: // a constructor, which is required for returning objects:
OResultSetMetaData(OConnection* pConnection, OResultSetMetaData(Connection* pConnection,
XSQLDA* pSqlda) XSQLDA* pSqlda)
: m_pConnection(pConnection) : m_pConnection(pConnection)
, m_pSqlda(pSqlda) , m_pSqlda(pSqlda)

View File

@@ -44,7 +44,7 @@ namespace connectivity
public: public:
// a constructor, which is required for returning objects: // a constructor, which is required for returning objects:
OStatement( OConnection* _pConnection) OStatement( Connection* _pConnection)
: OStatementCommonBase( _pConnection), : OStatementCommonBase( _pConnection),
m_pSqlda(0) m_pSqlda(0)
{} {}

View File

@@ -44,7 +44,7 @@ using namespace ::osl;
using namespace ::rtl; using namespace ::rtl;
using namespace ::std; using namespace ::std;
OStatementCommonBase::OStatementCommonBase(OConnection* _pConnection) OStatementCommonBase::OStatementCommonBase(Connection* _pConnection)
: OStatementCommonBase_Base(_pConnection->getMutex()), : OStatementCommonBase_Base(_pConnection->getMutex()),
OPropertySetHelper(OStatementCommonBase_Base::rBHelper), OPropertySetHelper(OStatementCommonBase_Base::rBHelper),
m_pConnection(_pConnection), m_pConnection(_pConnection),

View File

@@ -58,7 +58,7 @@ namespace connectivity
::std::list< ::rtl::OUString> m_aBatchList; ::std::list< ::rtl::OUString> m_aBatchList;
OConnection* m_pConnection; Connection* m_pConnection;
ISC_STATUS_ARRAY m_statusVector; ISC_STATUS_ARRAY m_statusVector;
isc_stmt_handle m_aStatementHandle; isc_stmt_handle m_aStatementHandle;
@@ -102,7 +102,7 @@ namespace connectivity
public: public:
::cppu::OBroadcastHelper& rBHelper; ::cppu::OBroadcastHelper& rBHelper;
OStatementCommonBase(OConnection* _pConnection); OStatementCommonBase(Connection* _pConnection);
using OStatementCommonBase_Base::operator ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >; using OStatementCommonBase_Base::operator ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >;
// OComponentHelper // OComponentHelper
@@ -135,7 +135,7 @@ namespace connectivity
virtual void SAL_CALL close( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); virtual void SAL_CALL close( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
// other methods // other methods
OConnection* getOwnConnection() const { return m_pConnection;} Connection* getOwnConnection() const { return m_pConnection;}
}; };
} }