Files
libreoffice/connectivity/source/drivers/jdbc/JDriver.cxx

235 lines
10 KiB
C++
Raw Normal View History

2000-09-18 15:18:56 +00:00
/*************************************************************************
*
* OpenOffice.org - a multi-platform office productivity suite
2000-09-18 15:18:56 +00:00
*
* $RCSfile: JDriver.cxx,v $
2000-09-18 15:18:56 +00:00
*
* $Revision: 1.38 $
2000-09-18 15:18:56 +00:00
*
* last change: $Author: hr $ $Date: 2007-06-27 14:36:14 $
2000-09-18 15:18:56 +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 15:18:56 +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 15:18:56 +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 15:18:56 +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 15:18:56 +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 15:18:56 +00:00
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_connectivity.hxx"
2000-09-18 15:18:56 +00:00
#ifndef _CONNECTIVITY_JAVA_SQL_DRIVER_HXX_
#include "java/sql/Driver.hxx"
#endif
#ifndef _CONNECTIVITY_JAVA_LANG_OBJECT_HXX_
#include "java/lang/Object.hxx"
#endif
2000-11-22 13:44:26 +00:00
#ifndef _CONNECTIVITY_JAVA_LANG_CLASS_HXX_
#include "java/lang/Class.hxx"
#endif
2000-09-18 15:18:56 +00:00
#ifndef _CONNECTIVITY_JAVA_SQL_DRIVERMANAGER_HXX_
#include "java/sql/DriverManager.hxx"
#endif
#ifndef _CONNECTIVITY_JAVA_SQL_DRIVERPOPERTYINFO_HXX_
#include "java/sql/DriverPropertyInfo.hxx"
#endif
#ifndef _CONNECTIVITY_JAVA_SQL_CONNECTION_HXX_
#include "java/sql/Connection.hxx"
#endif
2001-05-09 11:59:06 +00:00
#include "java/util/Property.hxx"
2000-09-18 15:18:56 +00:00
#ifndef _CONNECTIVITY_JAVA_TOOLS_HXX_
#include "java/tools.hxx"
#endif
#ifndef _DBHELPER_DBEXCEPTION_HXX_
#include "connectivity/dbexception.hxx"
#endif
#ifndef INCLUDED_JVMFWK_FRAMEWORK_H
#include <jvmfwk/framework.h>
#endif
#ifndef CONNECTIVITY_DIAGNOSE_EX_H
#include "diagnose_ex.h"
#endif
#include "resource/jdbc_log.hrc"
#include <comphelper/componentcontext.hxx>
2000-09-18 15:18:56 +00:00
using namespace connectivity;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::sdbc;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::lang;
// -------------------------------------------------------------------------
java_sql_Driver::java_sql_Driver(const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory)
:m_aContext( _rxFactory )
,m_aLogger( m_aContext.getUNOContext(), "sdbcl", "org.openoffice.sdbc.jdbcBridge" )
2000-09-18 15:18:56 +00:00
{
}
// --------------------------------------------------------------------------------
java_sql_Driver::~java_sql_Driver()
{
}
2000-09-18 15:18:56 +00:00
// static ServiceInfo
//------------------------------------------------------------------------------
rtl::OUString java_sql_Driver::getImplementationName_Static( ) throw(RuntimeException)
{
return ::rtl::OUString::createFromAscii("com.sun.star.comp.sdbc.JDBCDriver");
// this name is referenced in the configuration and in the jdbc.xml
// Please take care when changing it.
2000-09-18 15:18:56 +00:00
}
//------------------------------------------------------------------------------
Sequence< ::rtl::OUString > java_sql_Driver::getSupportedServiceNames_Static( ) throw (RuntimeException)
{
Sequence< ::rtl::OUString > aSNS( 1 );
aSNS[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbc.Driver");
return aSNS;
}
//------------------------------------------------------------------
::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL connectivity::java_sql_Driver_CreateInstance(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory) throw( ::com::sun::star::uno::Exception )
{
return *(new java_sql_Driver(_rxFactory));
}
// --------------------------------------------------------------------------------
::rtl::OUString SAL_CALL java_sql_Driver::getImplementationName( ) throw(RuntimeException)
{
return getImplementationName_Static();
}
// --------------------------------------------------------------------------------
sal_Bool SAL_CALL java_sql_Driver::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException)
{
Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames());
const ::rtl::OUString* pSupported = aSupported.getConstArray();
2001-05-17 06:30:42 +00:00
const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
;
2000-09-18 15:18:56 +00:00
2001-05-17 06:30:42 +00:00
return pSupported != pEnd;
2000-09-18 15:18:56 +00:00
}
// --------------------------------------------------------------------------------
Sequence< ::rtl::OUString > SAL_CALL java_sql_Driver::getSupportedServiceNames( ) throw(RuntimeException)
{
return getSupportedServiceNames_Static();
}
// -------------------------------------------------------------------------
Reference< XConnection > SAL_CALL java_sql_Driver::connect( const ::rtl::OUString& url, const
Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException)
{
m_aLogger.log( LogLevel::INFO, STR_LOG_DRIVER_CONNECTING_URL, url );
Reference< XConnection > xOut;
if ( acceptsURL(url ) )
{
java_sql_Connection* pConnection = new java_sql_Connection( *this );
xOut = pConnection;
if ( !pConnection->construct(url,info) )
xOut = NULL; // an error occured and the java driver didn't throw an exception
else
m_aLogger.log( LogLevel::INFO, STR_LOG_DRIVER_SUCCESS );
}
return xOut;
2000-09-18 15:18:56 +00:00
}
// -------------------------------------------------------------------------
2000-10-24 15:34:43 +00:00
sal_Bool SAL_CALL java_sql_Driver::acceptsURL( const ::rtl::OUString& url ) throw(SQLException, RuntimeException)
2000-09-18 15:18:56 +00:00
{
2000-11-22 13:44:26 +00:00
// don't ask the real driver for the url
// I feel responsible for all jdbc url's
sal_Bool bEnabled = sal_False;
OSL_VERIFY_EQUALS( jfw_getEnabled( &bEnabled ), JFW_E_NONE, "error in jfw_getEnabled" );
static const ::rtl::OUString s_sJdbcPrefix = ::rtl::OUString::createFromAscii("jdbc:");
return bEnabled && 0 == url.compareTo(s_sJdbcPrefix, 5);
2000-09-18 15:18:56 +00:00
}
// -------------------------------------------------------------------------
2000-11-22 13:44:26 +00:00
Sequence< DriverPropertyInfo > SAL_CALL java_sql_Driver::getPropertyInfo( const ::rtl::OUString& url,
const Sequence< PropertyValue >& /*info*/ ) throw(SQLException, RuntimeException)
2000-09-18 15:18:56 +00:00
{
if ( acceptsURL(url) )
{
::std::vector< DriverPropertyInfo > aDriverInfo;
Sequence< ::rtl::OUString > aBooleanValues(2);
aBooleanValues[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) );
aBooleanValues[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "true" ) );
aDriverInfo.push_back(DriverPropertyInfo(
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JavaDriverClass"))
,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("The JDBC driver class name."))
,sal_True
,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.mysql.jdbc.Driver"))
,Sequence< ::rtl::OUString >())
);
aDriverInfo.push_back(DriverPropertyInfo(
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParameterNameSubstitution"))
,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Change named parameters with '?'."))
,sal_False
,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) )
,aBooleanValues)
);
aDriverInfo.push_back(DriverPropertyInfo(
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IgnoreDriverPrivileges"))
,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Ignore the privileges from the database driver."))
,sal_False
,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) )
,aBooleanValues)
);
aDriverInfo.push_back(DriverPropertyInfo(
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsAutoRetrievingEnabled"))
,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Retrieve generated values."))
,sal_False
,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) )
,aBooleanValues)
);
aDriverInfo.push_back(DriverPropertyInfo(
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AutoRetrievingStatement"))
,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Auto-increment statement."))
,sal_False
,::rtl::OUString()
,Sequence< ::rtl::OUString >())
);
aDriverInfo.push_back(DriverPropertyInfo(
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("GenerateASBeforeCorrelationName"))
,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Generate AS before table correlation names."))
,sal_False
,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "true" ) )
,aBooleanValues)
);
return Sequence< DriverPropertyInfo >(&aDriverInfo[0],aDriverInfo.size());
}
::dbtools::throwGenericSQLException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Invalid URL!")) ,*this);
return Sequence< DriverPropertyInfo >();
2000-09-18 15:18:56 +00:00
}
// -------------------------------------------------------------------------
sal_Int32 SAL_CALL java_sql_Driver::getMajorVersion( ) throw(RuntimeException)
{
return 1;
2000-09-18 15:18:56 +00:00
}
// -------------------------------------------------------------------------
sal_Int32 SAL_CALL java_sql_Driver::getMinorVersion( ) throw(RuntimeException)
{
return 0;
2000-09-18 15:18:56 +00:00
}
// -------------------------------------------------------------------------