2000-09-18 23:16:46 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2005-09-08 10:34:47 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-09-18 23:16:46 +00:00
|
|
|
*
|
2005-09-08 10:34:47 +00:00
|
|
|
* $RCSfile: connection.cxx,v $
|
2000-09-18 23:16:46 +00:00
|
|
|
*
|
2006-10-05 11:58:37 +00:00
|
|
|
* $Revision: 1.51 $
|
2000-09-18 23:16:46 +00:00
|
|
|
*
|
2006-10-05 11:58:37 +00:00
|
|
|
* last change: $Author: kz $ $Date: 2006-10-05 12:58:37 $
|
2000-09-18 23:16:46 +00:00
|
|
|
*
|
2005-09-08 10:34:47 +00:00
|
|
|
* The Contents of this file are made available subject to
|
|
|
|
* the terms of GNU Lesser General Public License Version 2.1.
|
2000-09-18 23:16:46 +00:00
|
|
|
*
|
|
|
|
*
|
2005-09-08 10:34:47 +00:00
|
|
|
* GNU Lesser General Public License Version 2.1
|
|
|
|
* =============================================
|
|
|
|
* Copyright 2005 by Sun Microsystems, Inc.
|
|
|
|
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
2000-09-18 23:16:46 +00:00
|
|
|
*
|
2005-09-08 10:34:47 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2.1, as published by the Free Software Foundation.
|
2000-09-18 23:16:46 +00:00
|
|
|
*
|
2005-09-08 10:34:47 +00:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2000-09-18 23:16:46 +00:00
|
|
|
*
|
2005-09-08 10:34:47 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
2000-09-18 23:16:46 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
2006-07-10 14:09:51 +00:00
|
|
|
|
2006-09-17 05:39:00 +00:00
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_dbaccess.hxx"
|
|
|
|
|
2000-09-18 23:16:46 +00:00
|
|
|
#ifndef _DBA_CORE_CONNECTION_HXX_
|
|
|
|
#include "connection.hxx"
|
|
|
|
#endif
|
2006-07-10 14:09:51 +00:00
|
|
|
|
2000-10-25 06:42:28 +00:00
|
|
|
#ifndef DBACCESS_SHARED_DBASTRINGS_HRC
|
|
|
|
#include "dbastrings.hrc"
|
2000-09-18 23:16:46 +00:00
|
|
|
#endif
|
|
|
|
#ifndef _DBA_COREDATAACCESS_DATASOURCE_HXX_
|
|
|
|
#include "datasource.hxx"
|
|
|
|
#endif
|
2006-07-10 14:09:51 +00:00
|
|
|
#ifndef _DBA_CORE_RESOURCE_HRC_
|
|
|
|
#include "core_resource.hrc"
|
|
|
|
#endif
|
|
|
|
#ifndef _DBA_CORE_RESOURCE_HXX_
|
|
|
|
#include "core_resource.hxx"
|
|
|
|
#endif
|
2000-09-18 23:16:46 +00:00
|
|
|
#ifndef _DBA_COREAPI_STATEMENT_HXX_
|
2006-07-10 14:09:51 +00:00
|
|
|
#include "statement.hxx"
|
2000-09-18 23:16:46 +00:00
|
|
|
#endif
|
|
|
|
#ifndef _DBA_COREAPI_PREPAREDSTATEMENT_HXX_
|
2006-07-10 14:09:51 +00:00
|
|
|
#include "preparedstatement.hxx"
|
2000-09-18 23:16:46 +00:00
|
|
|
#endif
|
|
|
|
#ifndef _DBA_COREAPI_CALLABLESTATEMENT_HXX_
|
2006-07-10 14:09:51 +00:00
|
|
|
#include "callablestatement.hxx"
|
2000-09-18 23:16:46 +00:00
|
|
|
#endif
|
2006-07-10 14:09:51 +00:00
|
|
|
#ifndef DBA_CONTAINERMEDIATOR_HXX
|
|
|
|
#include "ContainerMediator.hxx"
|
|
|
|
#endif
|
|
|
|
#ifndef DBACCESS_CORE_API_SINGLESELECTQUERYCOMPOSER_HXX
|
|
|
|
#include "SingleSelectQueryComposer.hxx"
|
2000-09-18 23:16:46 +00:00
|
|
|
#endif
|
2006-07-10 14:09:51 +00:00
|
|
|
#ifndef DBACCESS_CORE_API_QUERYCOMPOSER_HXX
|
|
|
|
#include "querycomposer.hxx"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/** === begin UNO includes === **/
|
2000-09-18 23:16:46 +00:00
|
|
|
#ifndef _COM_SUN_STAR_SDB_COMMANDTYPE_HPP_
|
|
|
|
#include <com/sun/star/sdb/CommandType.hpp>
|
|
|
|
#endif
|
|
|
|
#ifndef _COM_SUN_STAR_SDBC_XDRIVERACCESS_HPP_
|
|
|
|
#include <com/sun/star/sdbc/XDriverAccess.hpp>
|
|
|
|
#endif
|
|
|
|
#ifndef _COM_SUN_STAR_SDBCX_XDATADEFINITIONSUPPLIER_HPP_
|
|
|
|
#include <com/sun/star/sdbcx/XDataDefinitionSupplier.hpp>
|
|
|
|
#endif
|
2002-08-12 08:21:59 +00:00
|
|
|
#ifndef _COM_SUN_STAR_REFLECTION_XPROXYFACTORY_HPP_
|
|
|
|
#include <com/sun/star/reflection/XProxyFactory.hpp>
|
|
|
|
#endif
|
2006-07-10 14:09:51 +00:00
|
|
|
#ifndef _COM_SUN_STAR_BEANS_NAMEDVALUE_HPP_
|
|
|
|
#include <com/sun/star/beans/NamedValue.hpp>
|
2000-09-18 23:16:46 +00:00
|
|
|
#endif
|
2006-07-10 14:09:51 +00:00
|
|
|
/** === end UNO includes === **/
|
|
|
|
|
2000-10-11 10:21:40 +00:00
|
|
|
#ifndef _CONNECTIVITY_DBTOOLS_HXX_
|
|
|
|
#include <connectivity/dbtools.hxx>
|
2000-09-18 23:16:46 +00:00
|
|
|
#endif
|
2006-07-10 14:09:51 +00:00
|
|
|
#ifndef CONNECTIVITY_INC_CONNECTIVITY_DBMETADATA_HXX
|
|
|
|
#include <connectivity/dbmetadata.hxx>
|
2000-09-18 23:16:46 +00:00
|
|
|
#endif
|
2006-07-10 14:09:51 +00:00
|
|
|
#ifndef _DBHELPER_DBEXCEPTION_HXX_
|
|
|
|
#include <connectivity/dbexception.hxx>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _TOOLS_DEBUG_HXX
|
|
|
|
#include <tools/debug.hxx>
|
|
|
|
#endif
|
|
|
|
#ifndef TOOLS_DIAGNOSE_EX_H
|
|
|
|
#include <tools/diagnose_ex.h>
|
2001-03-02 16:01:04 +00:00
|
|
|
#endif
|
2001-03-15 07:29:16 +00:00
|
|
|
#ifndef _COMPHELPER_EXTRACT_HXX_
|
|
|
|
#include <comphelper/extract.hxx>
|
2001-02-14 14:04:16 +00:00
|
|
|
#endif
|
2002-08-12 08:21:59 +00:00
|
|
|
#ifndef _COMPHELPER_UNO3_HXX_
|
|
|
|
#include <comphelper/uno3.hxx>
|
|
|
|
#endif
|
2006-07-10 14:09:51 +00:00
|
|
|
#ifndef _COMPHELPER_SEQUENCE_HXX_
|
|
|
|
#include <comphelper/sequence.hxx>
|
2004-08-02 14:08:12 +00:00
|
|
|
#endif
|
2006-07-10 14:09:51 +00:00
|
|
|
#ifndef _CPPUHELPER_TYPEPROVIDER_HXX_
|
|
|
|
#include <cppuhelper/typeprovider.hxx>
|
2004-08-02 14:08:12 +00:00
|
|
|
#endif
|
2000-09-18 23:16:46 +00:00
|
|
|
|
|
|
|
using namespace ::com::sun::star::uno;
|
|
|
|
using namespace ::com::sun::star::lang;
|
|
|
|
using namespace ::com::sun::star::util;
|
|
|
|
using namespace ::com::sun::star::sdb;
|
2006-10-05 11:58:37 +00:00
|
|
|
using namespace ::com::sun::star::sdb::application;
|
2000-09-18 23:16:46 +00:00
|
|
|
using namespace ::com::sun::star::sdbc;
|
|
|
|
using namespace ::com::sun::star::sdbcx;
|
|
|
|
using namespace ::com::sun::star::beans;
|
2002-08-12 08:21:59 +00:00
|
|
|
using namespace ::com::sun::star::reflection;
|
2000-09-18 23:16:46 +00:00
|
|
|
using namespace ::com::sun::star::container;
|
2006-10-05 11:58:37 +00:00
|
|
|
using namespace ::com::sun::star::graphic;
|
2000-09-18 23:16:46 +00:00
|
|
|
using namespace ::osl;
|
2000-10-11 10:21:40 +00:00
|
|
|
using namespace ::comphelper;
|
2000-09-18 23:16:46 +00:00
|
|
|
using namespace ::cppu;
|
2001-03-02 16:01:04 +00:00
|
|
|
using namespace ::dbtools;
|
2000-10-18 15:16:39 +00:00
|
|
|
|
|
|
|
//........................................................................
|
|
|
|
namespace dbaccess
|
|
|
|
{
|
|
|
|
//........................................................................
|
2000-09-18 23:16:46 +00:00
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
// XServiceInfo
|
|
|
|
//------------------------------------------------------------------------------
|
2002-08-12 08:21:59 +00:00
|
|
|
rtl::OUString OConnection::getImplementationName( ) throw(RuntimeException)
|
2000-09-18 23:16:46 +00:00
|
|
|
{
|
2002-08-12 08:21:59 +00:00
|
|
|
return rtl::OUString::createFromAscii("com.sun.star.comp.dbaccess.Connection");
|
2000-09-18 23:16:46 +00:00
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
2002-08-12 08:21:59 +00:00
|
|
|
sal_Bool OConnection::supportsService( const ::rtl::OUString& _rServiceName ) throw (RuntimeException)
|
2000-09-18 23:16:46 +00:00
|
|
|
{
|
|
|
|
return findValue(getSupportedServiceNames(), _rServiceName, sal_True).getLength() != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2002-08-12 08:21:59 +00:00
|
|
|
Sequence< ::rtl::OUString > OConnection::getSupportedServiceNames( ) throw (RuntimeException)
|
2000-09-18 23:16:46 +00:00
|
|
|
{
|
2002-08-15 09:40:25 +00:00
|
|
|
Sequence< ::rtl::OUString > aSupported = OConnectionWrapper::getSupportedServiceNames();
|
|
|
|
|
|
|
|
if ( 0 == findValue( aSupported, SERVICE_SDB_CONNECTION, sal_True ).getLength() )
|
|
|
|
{
|
|
|
|
sal_Int32 nLen = aSupported.getLength();
|
|
|
|
aSupported.realloc( nLen + 1 );
|
|
|
|
aSupported[ nLen ] = SERVICE_SDB_CONNECTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
return aSupported;
|
2000-09-18 23:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// XCloseable
|
|
|
|
//------------------------------------------------------------------------------
|
2002-08-12 08:21:59 +00:00
|
|
|
void OConnection::close(void) throw( SQLException, RuntimeException )
|
2000-09-18 23:16:46 +00:00
|
|
|
{
|
2002-08-15 09:40:25 +00:00
|
|
|
// being closed is the same as being disposed
|
|
|
|
dispose();
|
2000-09-18 23:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2002-08-12 08:21:59 +00:00
|
|
|
sal_Bool OConnection::isClosed(void) throw( SQLException, RuntimeException )
|
2000-09-18 23:16:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard(m_aMutex);
|
2002-08-12 08:21:59 +00:00
|
|
|
return !m_xConnection.is();
|
2000-09-18 23:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// XConnection
|
|
|
|
//------------------------------------------------------------------------------
|
2002-08-12 08:21:59 +00:00
|
|
|
Reference< XStatement > OConnection::createStatement(void) throw( SQLException, RuntimeException )
|
2000-09-18 23:16:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard(m_aMutex);
|
|
|
|
checkDisposed();
|
|
|
|
|
2002-10-10 12:22:42 +00:00
|
|
|
Reference< XStatement > xStatement;
|
2002-08-12 08:21:59 +00:00
|
|
|
Reference< XStatement > xMasterStatement = m_xConnection->createStatement();
|
2002-10-10 12:22:42 +00:00
|
|
|
if ( xMasterStatement.is() )
|
|
|
|
{
|
|
|
|
xStatement = new OStatement(this, xMasterStatement);
|
|
|
|
m_aStatements.push_back(WeakReferenceHelper(xStatement));
|
|
|
|
}
|
2000-09-18 23:16:46 +00:00
|
|
|
return xStatement;
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
2002-08-12 08:21:59 +00:00
|
|
|
Reference< XPreparedStatement > OConnection::prepareStatement(const rtl::OUString& sql) throw( SQLException, RuntimeException )
|
2000-09-18 23:16:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard(m_aMutex);
|
|
|
|
checkDisposed();
|
|
|
|
|
|
|
|
// TODO convert the SQL to SQL the driver understands
|
2002-10-10 12:22:42 +00:00
|
|
|
Reference< XPreparedStatement > xStatement;
|
2002-08-12 08:21:59 +00:00
|
|
|
Reference< XPreparedStatement > xMasterStatement = m_xConnection->prepareStatement(sql);
|
2002-10-10 12:22:42 +00:00
|
|
|
if ( xMasterStatement.is() )
|
|
|
|
{
|
|
|
|
xStatement = new OPreparedStatement(this, xMasterStatement);
|
|
|
|
m_aStatements.push_back(WeakReferenceHelper(xStatement));
|
|
|
|
}
|
2000-09-18 23:16:46 +00:00
|
|
|
return xStatement;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2002-08-12 08:21:59 +00:00
|
|
|
Reference< XPreparedStatement > OConnection::prepareCall(const rtl::OUString& sql) throw( SQLException, RuntimeException )
|
2000-09-18 23:16:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard(m_aMutex);
|
|
|
|
checkDisposed();
|
|
|
|
|
2002-10-10 12:22:42 +00:00
|
|
|
Reference< XPreparedStatement > xStatement;
|
2005-09-23 11:04:20 +00:00
|
|
|
Reference< XPreparedStatement > xMasterStatement = m_xConnection->prepareCall(sql);
|
2002-10-10 12:22:42 +00:00
|
|
|
if ( xMasterStatement.is() )
|
|
|
|
{
|
|
|
|
xStatement = new OCallableStatement(this, xMasterStatement);
|
|
|
|
m_aStatements.push_back(WeakReferenceHelper(xStatement));
|
|
|
|
}
|
2000-09-18 23:16:46 +00:00
|
|
|
return xStatement;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2002-08-12 08:21:59 +00:00
|
|
|
rtl::OUString OConnection::nativeSQL(const rtl::OUString& sql) throw( SQLException, RuntimeException )
|
2000-09-18 23:16:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard(m_aMutex);
|
|
|
|
checkDisposed();
|
2002-08-12 08:21:59 +00:00
|
|
|
return m_xConnection->nativeSQL(sql);
|
2000-09-18 23:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2002-08-12 08:21:59 +00:00
|
|
|
void OConnection::setAutoCommit(sal_Bool autoCommit) throw( SQLException, RuntimeException )
|
2000-09-18 23:16:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard(m_aMutex);
|
|
|
|
checkDisposed();
|
2002-08-12 08:21:59 +00:00
|
|
|
m_xConnection->setAutoCommit(autoCommit);
|
2000-09-18 23:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2002-08-12 08:21:59 +00:00
|
|
|
sal_Bool OConnection::getAutoCommit(void) throw( SQLException, RuntimeException )
|
2000-09-18 23:16:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard(m_aMutex);
|
|
|
|
checkDisposed();
|
2002-08-12 08:21:59 +00:00
|
|
|
return m_xConnection->getAutoCommit();
|
2000-09-18 23:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2002-08-12 08:21:59 +00:00
|
|
|
void OConnection::commit(void) throw( SQLException, RuntimeException )
|
2000-09-18 23:16:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard(m_aMutex);
|
|
|
|
checkDisposed();
|
2002-08-12 08:21:59 +00:00
|
|
|
m_xConnection->commit();
|
2000-09-18 23:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2002-08-12 08:21:59 +00:00
|
|
|
void OConnection::rollback(void) throw( SQLException, RuntimeException )
|
2000-09-18 23:16:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard(m_aMutex);
|
|
|
|
checkDisposed();
|
2002-08-12 08:21:59 +00:00
|
|
|
m_xConnection->rollback();
|
2000-09-18 23:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2002-08-12 08:21:59 +00:00
|
|
|
Reference< XDatabaseMetaData > OConnection::getMetaData(void) throw( SQLException, RuntimeException )
|
2000-09-18 23:16:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard(m_aMutex);
|
|
|
|
checkDisposed();
|
2002-08-12 08:21:59 +00:00
|
|
|
return m_xConnection->getMetaData();
|
2000-09-18 23:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2002-08-12 08:21:59 +00:00
|
|
|
void OConnection::setReadOnly(sal_Bool readOnly) throw( SQLException, RuntimeException )
|
2000-09-18 23:16:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard(m_aMutex);
|
|
|
|
checkDisposed();
|
2002-08-12 08:21:59 +00:00
|
|
|
m_xConnection->setReadOnly(readOnly);
|
2000-09-18 23:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2002-08-12 08:21:59 +00:00
|
|
|
sal_Bool OConnection::isReadOnly(void) throw( SQLException, RuntimeException )
|
2000-09-18 23:16:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard(m_aMutex);
|
|
|
|
checkDisposed();
|
2002-08-12 08:21:59 +00:00
|
|
|
return m_xConnection->isReadOnly();
|
2000-09-18 23:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2002-08-12 08:21:59 +00:00
|
|
|
void OConnection::setCatalog(const rtl::OUString& catalog) throw( SQLException, RuntimeException )
|
2000-09-18 23:16:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard(m_aMutex);
|
|
|
|
checkDisposed();
|
2002-08-12 08:21:59 +00:00
|
|
|
m_xConnection->setCatalog(catalog);
|
2000-09-18 23:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2002-08-12 08:21:59 +00:00
|
|
|
rtl::OUString OConnection::getCatalog(void) throw( SQLException, RuntimeException )
|
2000-09-18 23:16:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard(m_aMutex);
|
|
|
|
checkDisposed();
|
2002-08-12 08:21:59 +00:00
|
|
|
return m_xConnection->getCatalog();
|
2000-09-18 23:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2002-08-12 08:21:59 +00:00
|
|
|
void OConnection::setTransactionIsolation(sal_Int32 level) throw( SQLException, RuntimeException )
|
2000-09-18 23:16:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard(m_aMutex);
|
|
|
|
checkDisposed();
|
2002-08-12 08:21:59 +00:00
|
|
|
m_xConnection->setTransactionIsolation(level);
|
2000-09-18 23:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2002-08-12 08:21:59 +00:00
|
|
|
sal_Int32 OConnection::getTransactionIsolation(void) throw( SQLException, RuntimeException )
|
2000-09-18 23:16:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard(m_aMutex);
|
|
|
|
checkDisposed();
|
2002-08-12 08:21:59 +00:00
|
|
|
return m_xConnection->getTransactionIsolation();
|
2000-09-18 23:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2002-08-12 08:21:59 +00:00
|
|
|
Reference< XNameAccess > OConnection::getTypeMap(void) throw( SQLException, RuntimeException )
|
2000-09-18 23:16:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard(m_aMutex);
|
|
|
|
checkDisposed();
|
2002-08-12 08:21:59 +00:00
|
|
|
return m_xConnection->getTypeMap();
|
2000-09-18 23:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2002-08-12 08:21:59 +00:00
|
|
|
void OConnection::setTypeMap(const Reference< XNameAccess > & typeMap) throw( SQLException, RuntimeException )
|
2000-09-18 23:16:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard(m_aMutex);
|
|
|
|
checkDisposed();
|
2002-08-12 08:21:59 +00:00
|
|
|
m_xConnection->setTypeMap(typeMap);
|
2000-09-18 23:16:46 +00:00
|
|
|
}
|
|
|
|
//==========================================================================
|
|
|
|
//= OConnection
|
|
|
|
//==========================================================================
|
|
|
|
DBG_NAME(OConnection)
|
|
|
|
//--------------------------------------------------------------------------
|
2004-08-02 14:08:12 +00:00
|
|
|
OConnection::OConnection(ODatabaseSource& _rDB
|
|
|
|
, Reference< XConnection >& _rxMaster
|
|
|
|
, const Reference< XMultiServiceFactory >& _rxORB)
|
2002-08-12 08:21:59 +00:00
|
|
|
:OSubComponent(m_aMutex, static_cast< OWeakObject* >(&_rDB))
|
2000-09-18 23:16:46 +00:00
|
|
|
// as the queries reroute their refcounting to us, this m_aMutex is okey. If the queries
|
|
|
|
// container would do it's own refcounting, it would have to aquire m_pMutex
|
|
|
|
// same for tables
|
2005-03-10 15:33:05 +00:00
|
|
|
,m_aTableFilter(_rDB.m_pImpl->m_aTableFilter)
|
|
|
|
,m_aTableTypeFilter(_rDB.m_pImpl->m_aTableTypeFilter)
|
2006-07-10 14:09:51 +00:00
|
|
|
,m_aContext( _rxORB )
|
2002-08-12 08:21:59 +00:00
|
|
|
,m_xMasterConnection(_rxMaster)
|
2001-04-11 05:46:23 +00:00
|
|
|
,m_pTables(NULL)
|
|
|
|
,m_pViews(NULL)
|
2006-06-20 01:44:04 +00:00
|
|
|
,m_aWarnings( Reference< XWarningsSupplier >( _rxMaster, UNO_QUERY ) )
|
2001-04-26 08:09:55 +00:00
|
|
|
,m_bSupportsViews(sal_False)
|
2005-03-18 09:05:31 +00:00
|
|
|
,m_bSupportsUsers(sal_False)
|
|
|
|
,m_bSupportsGroups(sal_False)
|
2000-09-18 23:16:46 +00:00
|
|
|
{
|
|
|
|
DBG_CTOR(OConnection,NULL);
|
2001-10-08 06:28:39 +00:00
|
|
|
osl_incrementInterlockedCount(&m_refCount);
|
2002-08-12 08:21:59 +00:00
|
|
|
|
2004-08-02 14:08:12 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
Reference< XProxyFactory > xProxyFactory(
|
|
|
|
_rxORB->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.reflection.ProxyFactory"))),UNO_QUERY);
|
|
|
|
Reference<XAggregation> xAgg = xProxyFactory->createProxy(_rxMaster.get());
|
|
|
|
setDelegation(xAgg,m_refCount);
|
|
|
|
DBG_ASSERT(m_xConnection.is(), "OConnection::OConnection : invalid master connection !");
|
|
|
|
}
|
|
|
|
catch(const Exception&)
|
2002-08-12 08:21:59 +00:00
|
|
|
{
|
2006-10-05 11:58:37 +00:00
|
|
|
DBG_UNHANDLED_EXCEPTION();
|
2002-08-12 08:21:59 +00:00
|
|
|
}
|
2006-05-04 07:37:14 +00:00
|
|
|
|
2006-10-05 11:58:37 +00:00
|
|
|
m_xTableUIProvider = m_xTableUIProvider.query( m_xMasterConnection );
|
|
|
|
|
2001-04-11 05:46:23 +00:00
|
|
|
try
|
|
|
|
{
|
2006-05-04 07:37:14 +00:00
|
|
|
m_xQueries = new OQueryContainer(Reference< XNameContainer >(_rDB.getQueryDefinitions( ),UNO_QUERY), this,_rxORB, &m_aWarnings);
|
2004-08-02 14:08:12 +00:00
|
|
|
|
2001-10-08 06:28:39 +00:00
|
|
|
sal_Bool bCase = sal_True;
|
2003-12-01 09:35:53 +00:00
|
|
|
Reference<XDatabaseMetaData> xMeta;
|
2001-10-08 06:28:39 +00:00
|
|
|
try
|
|
|
|
{
|
2003-12-01 09:35:53 +00:00
|
|
|
xMeta = getMetaData();
|
2006-08-15 09:44:37 +00:00
|
|
|
bCase = xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers();
|
2001-10-08 06:28:39 +00:00
|
|
|
}
|
|
|
|
catch(SQLException&)
|
|
|
|
{
|
|
|
|
}
|
2006-07-10 14:09:51 +00:00
|
|
|
Reference< XNameContainer > xTableDefinitions(_rDB.getTables(),UNO_QUERY);
|
|
|
|
m_pTables = new OTableContainer( *this, m_aMutex, this, bCase, xTableDefinitions, this, &m_aWarnings );
|
2004-08-02 14:08:12 +00:00
|
|
|
|
2001-04-26 08:09:55 +00:00
|
|
|
// check if we supports types
|
2003-12-01 09:35:53 +00:00
|
|
|
if ( xMeta.is() )
|
2001-04-26 08:09:55 +00:00
|
|
|
{
|
2003-12-01 09:35:53 +00:00
|
|
|
Reference<XResultSet> xRes = xMeta->getTableTypes();
|
|
|
|
if(xRes.is())
|
2001-04-26 08:09:55 +00:00
|
|
|
{
|
2005-01-21 16:02:45 +00:00
|
|
|
::rtl::OUString sView(RTL_CONSTASCII_USTRINGPARAM("VIEW"));
|
2003-12-01 09:35:53 +00:00
|
|
|
Reference<XRow> xRow(xRes,UNO_QUERY);
|
|
|
|
while(xRes->next())
|
2001-04-26 08:09:55 +00:00
|
|
|
{
|
2003-12-01 09:35:53 +00:00
|
|
|
::rtl::OUString sValue = xRow->getString(1);
|
|
|
|
if( !xRow->wasNull() && sValue == sView)
|
|
|
|
{
|
|
|
|
m_bSupportsViews = sal_True;
|
|
|
|
break;
|
|
|
|
}
|
2001-04-26 08:09:55 +00:00
|
|
|
}
|
|
|
|
}
|
2006-07-10 14:09:51 +00:00
|
|
|
// some dbs don't support this type so we should ask if a XViewsSupplier is supported
|
2003-12-01 09:35:53 +00:00
|
|
|
if(!m_bSupportsViews)
|
|
|
|
{
|
2005-03-18 09:05:31 +00:00
|
|
|
Reference< XViewsSupplier > xMaster(getMasterTables(),UNO_QUERY);
|
2003-12-01 09:35:53 +00:00
|
|
|
|
|
|
|
if (xMaster.is() && xMaster->getViews().is())
|
|
|
|
m_bSupportsViews = sal_True;
|
|
|
|
}
|
|
|
|
if(m_bSupportsViews)
|
|
|
|
{
|
2006-05-04 07:37:14 +00:00
|
|
|
m_pViews = new OViewContainer(*this, m_aMutex, this, bCase,this,&m_aWarnings);
|
2003-12-01 09:35:53 +00:00
|
|
|
m_pViews->addContainerListener(m_pTables);
|
|
|
|
m_pTables->addContainerListener(m_pViews);
|
|
|
|
}
|
2005-03-18 09:05:31 +00:00
|
|
|
m_bSupportsUsers = Reference< XUsersSupplier> (getMasterTables(),UNO_QUERY).is();
|
|
|
|
m_bSupportsGroups = Reference< XGroupsSupplier> (getMasterTables(),UNO_QUERY).is();
|
|
|
|
|
2006-07-10 14:09:51 +00:00
|
|
|
impl_checkTableQueryNames_nothrow();
|
2001-07-19 09:01:27 +00:00
|
|
|
}
|
2001-04-11 05:46:23 +00:00
|
|
|
}
|
2004-10-22 07:58:38 +00:00
|
|
|
catch(Exception&)
|
2001-04-11 05:46:23 +00:00
|
|
|
{
|
|
|
|
}
|
2001-10-08 06:28:39 +00:00
|
|
|
osl_decrementInterlockedCount( &m_refCount );
|
2000-09-18 23:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
OConnection::~OConnection()
|
|
|
|
{
|
2000-11-14 12:32:59 +00:00
|
|
|
delete m_pTables;
|
2001-03-29 06:07:13 +00:00
|
|
|
delete m_pViews;
|
2000-09-18 23:16:46 +00:00
|
|
|
DBG_DTOR(OConnection,NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-02 16:01:04 +00:00
|
|
|
// XWarningsSupplier
|
|
|
|
//--------------------------------------------------------------------------
|
2002-08-12 08:21:59 +00:00
|
|
|
Any SAL_CALL OConnection::getWarnings() throw(SQLException, RuntimeException)
|
2001-03-02 16:01:04 +00:00
|
|
|
{
|
2002-08-12 08:21:59 +00:00
|
|
|
MutexGuard aGuard(m_aMutex);
|
|
|
|
checkDisposed();
|
2006-05-04 07:37:14 +00:00
|
|
|
return m_aWarnings.getWarnings();
|
2001-03-02 16:01:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
void SAL_CALL OConnection::clearWarnings( ) throw(SQLException, RuntimeException)
|
|
|
|
{
|
2002-08-12 08:21:59 +00:00
|
|
|
MutexGuard aGuard(m_aMutex);
|
|
|
|
checkDisposed();
|
2006-05-04 07:37:14 +00:00
|
|
|
m_aWarnings.clearWarnings();
|
2001-03-02 16:01:04 +00:00
|
|
|
}
|
|
|
|
|
2000-09-18 23:16:46 +00:00
|
|
|
//--------------------------------------------------------------------------
|
2005-10-24 07:28:24 +00:00
|
|
|
namespace
|
2000-09-18 23:16:46 +00:00
|
|
|
{
|
2005-10-24 07:28:24 +00:00
|
|
|
struct CompareTypeByName : public ::std::binary_function< Type, Type, bool >
|
2001-04-26 08:09:55 +00:00
|
|
|
{
|
2005-10-24 07:28:24 +00:00
|
|
|
bool operator() ( const Type& _rLHS, const Type& _rRHS ) const
|
2005-03-18 09:05:31 +00:00
|
|
|
{
|
2005-10-24 07:28:24 +00:00
|
|
|
return _rLHS.getTypeName() < _rRHS.getTypeName();
|
2005-03-18 09:05:31 +00:00
|
|
|
}
|
2005-10-24 07:28:24 +00:00
|
|
|
};
|
|
|
|
typedef ::std::set< Type, CompareTypeByName > TypeBag;
|
|
|
|
|
|
|
|
void lcl_copyTypes( TypeBag& _out_rTypes, const Sequence< Type >& _rTypes )
|
|
|
|
{
|
|
|
|
::std::copy( _rTypes.getConstArray(), _rTypes.getConstArray() + _rTypes.getLength(),
|
|
|
|
::std::insert_iterator< TypeBag >( _out_rTypes, _out_rTypes.begin() ) );
|
2001-04-26 08:09:55 +00:00
|
|
|
}
|
2005-10-24 07:28:24 +00:00
|
|
|
}
|
|
|
|
// com::sun::star::lang::XTypeProvider
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
Sequence< Type > OConnection::getTypes() throw (RuntimeException)
|
|
|
|
{
|
|
|
|
TypeBag aNormalizedTypes;
|
|
|
|
|
|
|
|
lcl_copyTypes( aNormalizedTypes, OSubComponent::getTypes() );
|
|
|
|
lcl_copyTypes( aNormalizedTypes, OConnection_Base::getTypes() );
|
|
|
|
lcl_copyTypes( aNormalizedTypes, ::connectivity::OConnectionWrapper::getTypes() );
|
|
|
|
|
|
|
|
if ( !m_bSupportsViews )
|
|
|
|
aNormalizedTypes.erase( XViewsSupplier::static_type() );
|
|
|
|
if ( !m_bSupportsUsers )
|
|
|
|
aNormalizedTypes.erase( XUsersSupplier::static_type() );
|
|
|
|
if ( !m_bSupportsGroups )
|
|
|
|
aNormalizedTypes.erase( XGroupsSupplier::static_type() );
|
|
|
|
|
|
|
|
Sequence< Type > aSupportedTypes( aNormalizedTypes.size() );
|
|
|
|
::std::copy( aNormalizedTypes.begin(), aNormalizedTypes.end(), aSupportedTypes.getArray() );
|
|
|
|
return aSupportedTypes;
|
2000-09-18 23:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
Sequence< sal_Int8 > OConnection::getImplementationId() throw (RuntimeException)
|
|
|
|
{
|
2001-07-18 07:45:32 +00:00
|
|
|
return getUnoTunnelImplementationId();
|
2000-09-18 23:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// com::sun::star::uno::XInterface
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
Any OConnection::queryInterface( const Type & rType ) throw (RuntimeException)
|
|
|
|
{
|
2005-10-24 07:28:24 +00:00
|
|
|
if ( !m_bSupportsViews && rType.equals( XViewsSupplier::static_type() ) )
|
2001-04-26 08:09:55 +00:00
|
|
|
return Any();
|
2005-10-24 07:28:24 +00:00
|
|
|
else if ( !m_bSupportsUsers && rType.equals( XUsersSupplier::static_type() ) )
|
2005-03-18 09:05:31 +00:00
|
|
|
return Any();
|
2005-10-24 07:28:24 +00:00
|
|
|
else if ( !m_bSupportsGroups && rType.equals( XGroupsSupplier::static_type() ) )
|
2005-03-18 09:05:31 +00:00
|
|
|
return Any();
|
2000-09-18 23:16:46 +00:00
|
|
|
Any aReturn = OSubComponent::queryInterface( rType );
|
|
|
|
if (!aReturn.hasValue())
|
2002-08-12 08:21:59 +00:00
|
|
|
{
|
2000-09-18 23:16:46 +00:00
|
|
|
aReturn = OConnection_Base::queryInterface( rType );
|
2002-08-12 08:21:59 +00:00
|
|
|
if (!aReturn.hasValue())
|
|
|
|
aReturn = OConnectionWrapper::queryInterface( rType );
|
|
|
|
}
|
2000-09-18 23:16:46 +00:00
|
|
|
return aReturn;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------
|
2001-11-01 15:29:21 +00:00
|
|
|
void OConnection::acquire() throw ()
|
2000-09-18 23:16:46 +00:00
|
|
|
{
|
|
|
|
OSubComponent::acquire();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------
|
2001-11-01 15:29:21 +00:00
|
|
|
void OConnection::release() throw ()
|
2000-09-18 23:16:46 +00:00
|
|
|
{
|
|
|
|
OSubComponent::release();
|
|
|
|
}
|
|
|
|
|
|
|
|
// OSubComponent
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void OConnection::disposing()
|
|
|
|
{
|
|
|
|
MutexGuard aGuard(m_aMutex);
|
|
|
|
|
|
|
|
OSubComponent::disposing();
|
2004-08-02 14:08:12 +00:00
|
|
|
OConnectionWrapper::disposing();
|
|
|
|
|
|
|
|
for (OWeakRefArrayIterator i = m_aStatements.begin(); m_aStatements.end() != i; ++i)
|
2002-08-12 08:21:59 +00:00
|
|
|
{
|
2004-08-02 14:08:12 +00:00
|
|
|
Reference<XComponent> xComp(i->get(),UNO_QUERY);
|
|
|
|
::comphelper::disposeComponent(xComp);
|
2002-08-12 08:21:59 +00:00
|
|
|
}
|
|
|
|
m_aStatements.clear();
|
|
|
|
m_xMasterTables = NULL;
|
|
|
|
|
2001-02-14 14:04:16 +00:00
|
|
|
if(m_pTables)
|
2002-08-23 04:56:21 +00:00
|
|
|
m_pTables->dispose();
|
2001-03-29 06:07:13 +00:00
|
|
|
if(m_pViews)
|
2002-08-23 04:56:21 +00:00
|
|
|
m_pViews->dispose();
|
2000-09-18 23:16:46 +00:00
|
|
|
|
2004-08-02 14:08:12 +00:00
|
|
|
::comphelper::disposeComponent(m_xQueries);
|
|
|
|
|
|
|
|
for (OWeakRefArrayIterator j = m_aComposers.begin(); m_aComposers.end() != j; ++j)
|
2000-09-18 23:16:46 +00:00
|
|
|
{
|
2004-08-02 14:08:12 +00:00
|
|
|
Reference<XComponent> xComp(j->get(),UNO_QUERY);
|
|
|
|
::comphelper::disposeComponent(xComp);
|
2000-09-18 23:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_aComposers.clear();
|
|
|
|
|
2004-08-02 14:08:12 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
if (m_xMasterConnection.is())
|
|
|
|
m_xMasterConnection->close();
|
|
|
|
}
|
|
|
|
catch(Exception)
|
|
|
|
{
|
|
|
|
}
|
2000-09-18 23:16:46 +00:00
|
|
|
m_xMasterConnection = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XChild
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
Reference< XInterface > OConnection::getParent(void) throw( RuntimeException )
|
|
|
|
{
|
2002-12-12 09:43:23 +00:00
|
|
|
MutexGuard aGuard(m_aMutex);
|
2000-09-18 23:16:46 +00:00
|
|
|
checkDisposed();
|
|
|
|
return m_xParent;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2006-06-20 01:44:04 +00:00
|
|
|
void OConnection::setParent(const Reference< XInterface > & /*Parent*/) throw( NoSupportException, RuntimeException )
|
2000-09-18 23:16:46 +00:00
|
|
|
{
|
|
|
|
throw NoSupportException();
|
|
|
|
}
|
|
|
|
|
|
|
|
// XSQLQueryComposerFactory
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
Reference< XSQLQueryComposer > OConnection::createQueryComposer(void) throw( RuntimeException )
|
|
|
|
{
|
|
|
|
MutexGuard aGuard(m_aMutex);
|
|
|
|
checkDisposed();
|
|
|
|
|
|
|
|
// Reference< XNumberFormatsSupplier > xSupplier = pParent->getNumberFormatsSupplier();
|
2006-07-10 14:09:51 +00:00
|
|
|
Reference< XSQLQueryComposer > xComposer( new OQueryComposer( this ) );
|
2000-09-18 23:16:46 +00:00
|
|
|
m_aComposers.push_back(WeakReferenceHelper(xComposer));
|
|
|
|
return xComposer;
|
|
|
|
}
|
2002-08-21 09:31:33 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
void OConnection::refresh(const Reference< XNameAccess >& _rToBeRefreshed)
|
2000-09-18 23:16:46 +00:00
|
|
|
{
|
2002-08-21 09:31:33 +00:00
|
|
|
if ( _rToBeRefreshed == Reference< XNameAccess >(m_pTables) )
|
2000-09-18 23:16:46 +00:00
|
|
|
{
|
2002-08-21 09:31:33 +00:00
|
|
|
if (!m_pTables->isInitialized())
|
2001-10-05 05:47:13 +00:00
|
|
|
{
|
2005-03-18 09:05:31 +00:00
|
|
|
getMasterTables();
|
2002-08-21 09:31:33 +00:00
|
|
|
|
|
|
|
if (m_xMasterTables.is() && m_xMasterTables->getTables().is())
|
|
|
|
{ // yes -> wrap them
|
|
|
|
m_pTables->construct(m_xMasterTables->getTables(),m_aTableFilter, m_aTableTypeFilter);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // no -> use an own container
|
|
|
|
m_pTables->construct(m_aTableFilter, m_aTableTypeFilter);
|
2001-10-08 06:28:39 +00:00
|
|
|
}
|
2001-10-05 05:47:13 +00:00
|
|
|
}
|
2002-08-21 09:31:33 +00:00
|
|
|
}
|
|
|
|
else if ( _rToBeRefreshed == Reference< XNameAccess >(m_pViews) )
|
|
|
|
{
|
|
|
|
if (!m_pViews->isInitialized())
|
|
|
|
{
|
|
|
|
// check if out "master connection" can supply tables
|
2005-03-18 09:05:31 +00:00
|
|
|
Reference< XViewsSupplier > xMaster(getMasterTables(),UNO_QUERY);
|
2001-08-24 05:40:35 +00:00
|
|
|
|
2002-08-21 09:31:33 +00:00
|
|
|
if (xMaster.is() && xMaster->getViews().is())
|
|
|
|
m_pViews->construct(xMaster->getViews(),m_aTableFilter, m_aTableTypeFilter);
|
|
|
|
else
|
|
|
|
m_pViews->construct(m_aTableFilter, m_aTableTypeFilter);
|
2000-09-18 23:16:46 +00:00
|
|
|
}
|
|
|
|
}
|
2002-08-21 09:31:33 +00:00
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// XTablesSupplier
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
Reference< XNameAccess > OConnection::getTables() throw( RuntimeException )
|
|
|
|
{
|
|
|
|
MutexGuard aGuard(m_aMutex);
|
|
|
|
checkDisposed();
|
|
|
|
|
|
|
|
refresh(m_pTables);
|
2000-09-18 23:16:46 +00:00
|
|
|
|
2000-11-14 12:32:59 +00:00
|
|
|
return m_pTables;
|
2000-09-18 23:16:46 +00:00
|
|
|
}
|
2001-03-29 06:07:13 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
Reference< XNameAccess > SAL_CALL OConnection::getViews( ) throw(RuntimeException)
|
|
|
|
{
|
|
|
|
MutexGuard aGuard(m_aMutex);
|
|
|
|
checkDisposed();
|
|
|
|
|
2002-08-23 04:56:21 +00:00
|
|
|
refresh(m_pViews);
|
2001-03-29 06:07:13 +00:00
|
|
|
|
|
|
|
return m_pViews;
|
|
|
|
}
|
2000-09-18 23:16:46 +00:00
|
|
|
// XQueriesSupplier
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
Reference< XNameAccess > OConnection::getQueries(void) throw( RuntimeException )
|
|
|
|
{
|
|
|
|
MutexGuard aGuard(m_aMutex);
|
|
|
|
checkDisposed();
|
|
|
|
|
2004-08-02 14:08:12 +00:00
|
|
|
return m_xQueries;
|
2000-09-18 23:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ::com::sun::star::sdb::XCommandPreparation
|
|
|
|
//------------------------------------------------------------------------------
|
2001-03-29 06:07:13 +00:00
|
|
|
Reference< XPreparedStatement > SAL_CALL OConnection::prepareCommand( const ::rtl::OUString& command, sal_Int32 commandType ) throw(::com::sun::star::sdbc::SQLException, RuntimeException)
|
2000-09-18 23:16:46 +00:00
|
|
|
{
|
|
|
|
MutexGuard aGuard(m_aMutex);
|
|
|
|
checkDisposed();
|
|
|
|
|
|
|
|
rtl::OUString aStatement;
|
|
|
|
switch (commandType)
|
|
|
|
{
|
|
|
|
case CommandType::TABLE:
|
2004-08-02 14:08:12 +00:00
|
|
|
{
|
|
|
|
aStatement = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SELECT * FROM "));
|
2006-07-10 14:09:51 +00:00
|
|
|
|
|
|
|
::rtl::OUString sCatalog, sSchema, sTable;
|
|
|
|
::dbtools::qualifiedNameComponents( getMetaData(), command, sCatalog, sSchema, sTable, ::dbtools::eInDataManipulation );
|
|
|
|
aStatement += ::dbtools::composeTableNameForSelect( this, sCatalog, sSchema, sTable );
|
2004-08-02 14:08:12 +00:00
|
|
|
}
|
2000-09-18 23:16:46 +00:00
|
|
|
break;
|
|
|
|
case CommandType::QUERY:
|
2004-08-02 14:08:12 +00:00
|
|
|
if ( m_xQueries->hasByName(command) )
|
2000-09-18 23:16:46 +00:00
|
|
|
{
|
2004-08-02 14:08:12 +00:00
|
|
|
Reference< XPropertySet > xQuery(m_xQueries->getByName(command),UNO_QUERY);
|
2000-09-18 23:16:46 +00:00
|
|
|
xQuery->getPropertyValue(PROPERTY_COMMAND) >>= aStatement;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
aStatement = command;
|
|
|
|
}
|
|
|
|
// TODO EscapeProcessing
|
|
|
|
return prepareStatement(aStatement);
|
|
|
|
}
|
2003-12-16 11:41:07 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
Reference< XInterface > SAL_CALL OConnection::createInstance( const ::rtl::OUString& _sServiceSpecifier ) throw (Exception, RuntimeException)
|
|
|
|
{
|
|
|
|
Reference< XServiceInfo > xRet;
|
2005-01-05 11:28:08 +00:00
|
|
|
if ( ( SERVICE_NAME_SINGLESELECTQUERYCOMPOSER == _sServiceSpecifier )
|
|
|
|
|| ( _sServiceSpecifier.equalsAscii( "com.sun.star.sdb.SingleSelectQueryAnalyzer" ) )
|
|
|
|
)
|
2003-12-16 11:41:07 +00:00
|
|
|
{
|
2006-07-10 14:09:51 +00:00
|
|
|
xRet = new OSingleSelectQueryComposer( getTables(),this, m_aContext.getLegacyServiceFactory() );
|
2003-12-16 11:41:07 +00:00
|
|
|
m_aComposers.push_back(WeakReferenceHelper(xRet));
|
|
|
|
}
|
|
|
|
return Reference< XInterface >(xRet,UNO_QUERY);
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
2006-06-20 01:44:04 +00:00
|
|
|
Reference< XInterface > SAL_CALL OConnection::createInstanceWithArguments( const ::rtl::OUString& _sServiceSpecifier, const Sequence< Any >& /*Arguments*/ ) throw (Exception, RuntimeException)
|
2003-12-16 11:41:07 +00:00
|
|
|
{
|
|
|
|
return createInstance(_sServiceSpecifier);
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
Sequence< ::rtl::OUString > SAL_CALL OConnection::getAvailableServiceNames( ) throw (RuntimeException)
|
|
|
|
{
|
|
|
|
Sequence< ::rtl::OUString > aRet(1);
|
|
|
|
aRet[0] = SERVICE_NAME_SINGLESELECTQUERYCOMPOSER;
|
|
|
|
return aRet;
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
2005-03-18 09:05:31 +00:00
|
|
|
Reference< XTablesSupplier > OConnection::getMasterTables()
|
|
|
|
{
|
|
|
|
// check if out "master connection" can supply tables
|
|
|
|
if(!m_xMasterTables.is())
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Reference<XDatabaseMetaData> xMeta = getMetaData();
|
|
|
|
if ( xMeta.is() )
|
2006-07-10 14:09:51 +00:00
|
|
|
m_xMasterTables = ::dbtools::getDataDefinitionByURLAndConnection( xMeta->getURL(), m_xMasterConnection, m_aContext.getLegacyServiceFactory() );
|
2005-03-18 09:05:31 +00:00
|
|
|
}
|
|
|
|
catch(SQLException&)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return m_xMasterTables;
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// XUsersSupplier
|
|
|
|
Reference< XNameAccess > SAL_CALL OConnection::getUsers( ) throw(RuntimeException)
|
|
|
|
{
|
|
|
|
MutexGuard aGuard(m_aMutex);
|
|
|
|
checkDisposed();
|
|
|
|
|
|
|
|
Reference<XUsersSupplier> xUsr(getMasterTables(),UNO_QUERY);
|
|
|
|
return xUsr.is() ? xUsr->getUsers() : Reference< XNameAccess >();
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// XGroupsSupplier
|
|
|
|
Reference< XNameAccess > SAL_CALL OConnection::getGroups( ) throw(RuntimeException)
|
|
|
|
{
|
|
|
|
MutexGuard aGuard(m_aMutex);
|
|
|
|
checkDisposed();
|
|
|
|
Reference<XGroupsSupplier> xGrp(getMasterTables(),UNO_QUERY);
|
|
|
|
return xGrp.is() ? xGrp->getGroups() : Reference< XNameAccess >();
|
|
|
|
}
|
2006-07-10 14:09:51 +00:00
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
void OConnection::impl_loadConnectionTools_throw()
|
|
|
|
{
|
|
|
|
Sequence< Any > aArguments( 1 );
|
|
|
|
aArguments[0] <<= NamedValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Connection" ) ), makeAny( Reference< XConnection >( this ) ) );
|
|
|
|
|
|
|
|
if ( !m_aContext.createComponentWithArguments( "com.sun.star.sdb.tools.ConnectionTools", aArguments, m_xConnectionTools ) )
|
|
|
|
throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "service not registered: com.sun.star.sdb.tools.ConnectionTools" ) ), *this );
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
Reference< tools::XTableName > SAL_CALL OConnection::createTableName( ) throw (RuntimeException)
|
|
|
|
{
|
|
|
|
MutexGuard aGuard(m_aMutex);
|
|
|
|
checkDisposed();
|
|
|
|
impl_loadConnectionTools_throw();
|
|
|
|
|
|
|
|
return m_xConnectionTools->createTableName();
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
Reference< tools::XObjectNames > SAL_CALL OConnection::getObjectNames( ) throw (RuntimeException)
|
|
|
|
{
|
|
|
|
MutexGuard aGuard(m_aMutex);
|
|
|
|
checkDisposed();
|
|
|
|
impl_loadConnectionTools_throw();
|
|
|
|
|
|
|
|
return m_xConnectionTools->getObjectNames();
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
Reference< tools::XDataSourceMetaData > SAL_CALL OConnection::getDataSourceMetaData( ) throw (RuntimeException)
|
|
|
|
{
|
|
|
|
MutexGuard aGuard(m_aMutex);
|
|
|
|
checkDisposed();
|
|
|
|
impl_loadConnectionTools_throw();
|
|
|
|
|
|
|
|
return m_xConnectionTools->getDataSourceMetaData();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
void OConnection::impl_checkTableQueryNames_nothrow()
|
|
|
|
{
|
|
|
|
DatabaseMetaData aMeta( static_cast< XConnection* >( this ) );
|
|
|
|
if ( !aMeta.supportsSubqueriesInFrom() )
|
|
|
|
// nothing to do
|
|
|
|
return;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Reference< XNameAccess > xTables( getTables() );
|
|
|
|
Sequence< ::rtl::OUString > aTableNames( xTables->getElementNames() );
|
|
|
|
::std::set< ::rtl::OUString > aSortedTableNames( aTableNames.getConstArray(), aTableNames.getConstArray() + aTableNames.getLength() );
|
|
|
|
|
|
|
|
Reference< XNameAccess > xQueries( getQueries() );
|
|
|
|
Sequence< ::rtl::OUString > aQueryNames( xQueries->getElementNames() );
|
|
|
|
|
|
|
|
for ( const ::rtl::OUString* pQueryName = aQueryNames.getConstArray();
|
|
|
|
pQueryName != aQueryNames.getConstArray() + aQueryNames.getLength();
|
|
|
|
++pQueryName
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if ( aSortedTableNames.find( *pQueryName ) != aSortedTableNames.end() )
|
|
|
|
{
|
|
|
|
::rtl::OUString sConflictWarning( DBACORE_RESSTRING( RID_STR_CONFLICTING_NAMES ) );
|
|
|
|
m_aWarnings.appendWarning( sConflictWarning, "01SB0", *this );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch( const Exception& )
|
|
|
|
{
|
|
|
|
DBG_UNHANDLED_EXCEPTION();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-05 11:58:37 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
Reference< XGraphic > SAL_CALL OConnection::getTableIcon( const ::rtl::OUString& _TableName, ::sal_Int32 _ColorMode ) throw (RuntimeException)
|
|
|
|
{
|
|
|
|
Reference< XGraphic > xReturn;
|
|
|
|
|
|
|
|
// ask our aggregate
|
|
|
|
if ( m_xTableUIProvider.is() )
|
|
|
|
xReturn = m_xTableUIProvider->getTableIcon( _TableName, _ColorMode );
|
|
|
|
|
|
|
|
// ask ourself
|
|
|
|
// well, we don't have own functionality here ...
|
|
|
|
// In the future, we might decide to delegate the complete handling to this interface.
|
|
|
|
// In this case, we would need to load the icon here.
|
|
|
|
|
|
|
|
return xReturn;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
Reference< XInterface > SAL_CALL OConnection::getTableEditor( const Reference< XDatabaseDocumentUI >& _DocumentUI, const ::rtl::OUString& _TableName ) throw (IllegalArgumentException, WrappedTargetException, RuntimeException)
|
|
|
|
{
|
|
|
|
Reference< XInterface > xReturn;
|
|
|
|
|
|
|
|
// ask our aggregate
|
|
|
|
if ( m_xTableUIProvider.is() )
|
|
|
|
xReturn = m_xTableUIProvider->getTableEditor( _DocumentUI, _TableName );
|
|
|
|
|
|
|
|
// ask ourself
|
|
|
|
// well, we don't have own functionality here ...
|
|
|
|
// In the future, we might decide to delegate the complete handling to this interface.
|
|
|
|
// In this case, we would need to instantiate an css.sdb.TableDesign here.
|
|
|
|
|
|
|
|
return xReturn;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-18 15:16:39 +00:00
|
|
|
//........................................................................
|
|
|
|
} // namespace dbaccess
|
|
|
|
//........................................................................
|
2000-09-18 23:16:46 +00:00
|
|
|
|