2000-09-18 15:18:56 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-10 08:26:26 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2008-04-10 08:26:26 +00:00
|
|
|
* Copyright 2008 by Sun Microsystems, Inc.
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2008-04-10 08:26:26 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2008-04-10 08:26:26 +00:00
|
|
|
* $RCSfile: JDriver.cxx,v $
|
2008-10-01 12:28:29 +00:00
|
|
|
* $Revision: 1.43.56.1 $
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2008-04-10 08:26:26 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2008-04-10 08:26:26 +00:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2008-04-10 08:26:26 +00:00
|
|
|
* OpenOffice.org 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 version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2008-04-10 08:26:26 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
2006-09-17 01:47:16 +00:00
|
|
|
|
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_connectivity.hxx"
|
2000-09-18 15:18:56 +00:00
|
|
|
#include "java/sql/Driver.hxx"
|
|
|
|
#include "java/lang/Object.hxx"
|
2000-11-22 13:44:26 +00:00
|
|
|
#include "java/lang/Class.hxx"
|
2000-09-18 15:18:56 +00:00
|
|
|
#include "java/sql/DriverManager.hxx"
|
|
|
|
#include "java/sql/DriverPropertyInfo.hxx"
|
|
|
|
#include "java/sql/Connection.hxx"
|
2001-05-09 11:59:06 +00:00
|
|
|
#include "java/util/Property.hxx"
|
2000-09-18 15:18:56 +00:00
|
|
|
#include "java/tools.hxx"
|
2002-08-01 05:30:16 +00:00
|
|
|
#include "connectivity/dbexception.hxx"
|
2005-02-17 09:15:29 +00:00
|
|
|
#include <jvmfwk/framework.h>
|
2006-06-20 00:34:40 +00:00
|
|
|
#include "diagnose_ex.h"
|
2007-06-27 13:36:14 +00:00
|
|
|
#include "resource/jdbc_log.hrc"
|
2008-10-01 12:28:29 +00:00
|
|
|
#include "resource/common_res.hrc"
|
|
|
|
#include "resource/sharedresources.hxx"
|
2007-06-27 13:36:14 +00:00
|
|
|
#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)
|
2007-06-27 13:36:14 +00:00
|
|
|
: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()
|
2007-06-27 13:36:14 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2000-09-18 15:18:56 +00:00
|
|
|
// static ServiceInfo
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
rtl::OUString java_sql_Driver::getImplementationName_Static( ) throw(RuntimeException)
|
|
|
|
{
|
2001-05-30 05:38:50 +00:00
|
|
|
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();
|
|
|
|
}
|
2002-08-01 06:16:25 +00:00
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
Reference< XConnection > SAL_CALL java_sql_Driver::connect( const ::rtl::OUString& url, const
|
|
|
|
Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException)
|
|
|
|
{
|
2007-06-27 13:36:14 +00:00
|
|
|
m_aLogger.log( LogLevel::INFO, STR_LOG_DRIVER_CONNECTING_URL, url );
|
|
|
|
|
2003-05-22 09:50:18 +00:00
|
|
|
Reference< XConnection > xOut;
|
|
|
|
if ( acceptsURL(url ) )
|
|
|
|
{
|
2007-06-27 13:36:14 +00:00
|
|
|
java_sql_Connection* pConnection = new java_sql_Connection( *this );
|
2003-05-22 09:50:18 +00:00
|
|
|
xOut = pConnection;
|
|
|
|
if ( !pConnection->construct(url,info) )
|
2007-06-27 13:36:14 +00:00
|
|
|
xOut = NULL; // an error occured and the java driver didn't throw an exception
|
|
|
|
else
|
|
|
|
m_aLogger.log( LogLevel::INFO, STR_LOG_DRIVER_SUCCESS );
|
2003-05-22 09:50:18 +00:00
|
|
|
}
|
2003-04-24 12:26:09 +00:00
|
|
|
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
|
2005-02-17 09:15:29 +00:00
|
|
|
sal_Bool bEnabled = sal_False;
|
2006-06-20 00:34:40 +00:00
|
|
|
OSL_VERIFY_EQUALS( jfw_getEnabled( &bEnabled ), JFW_E_NONE, "error in jfw_getEnabled" );
|
2001-05-29 07:59:27 +00:00
|
|
|
static const ::rtl::OUString s_sJdbcPrefix = ::rtl::OUString::createFromAscii("jdbc:");
|
2005-02-17 09:15:29 +00:00
|
|
|
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,
|
2006-06-20 00:34:40 +00:00
|
|
|
const Sequence< PropertyValue >& /*info*/ ) throw(SQLException, RuntimeException)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
2004-08-02 16:05:00 +00:00
|
|
|
if ( acceptsURL(url) )
|
|
|
|
{
|
|
|
|
::std::vector< DriverPropertyInfo > aDriverInfo;
|
|
|
|
|
2006-12-13 15:18:59 +00:00
|
|
|
Sequence< ::rtl::OUString > aBooleanValues(2);
|
|
|
|
aBooleanValues[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) );
|
|
|
|
aBooleanValues[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "true" ) );
|
2004-08-02 16:05:00 +00:00
|
|
|
|
|
|
|
aDriverInfo.push_back(DriverPropertyInfo(
|
|
|
|
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JavaDriverClass"))
|
|
|
|
,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("The JDBC driver class name."))
|
|
|
|
,sal_True
|
2007-11-21 14:03:32 +00:00
|
|
|
,::rtl::OUString()
|
|
|
|
,Sequence< ::rtl::OUString >())
|
|
|
|
);
|
|
|
|
|
|
|
|
aDriverInfo.push_back(DriverPropertyInfo(
|
|
|
|
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JavaDriverClassPath"))
|
|
|
|
,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("The class path where to look for the JDBC driver."))
|
|
|
|
,sal_True
|
|
|
|
,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "" ) )
|
|
|
|
,Sequence< ::rtl::OUString >())
|
|
|
|
);
|
|
|
|
|
|
|
|
aDriverInfo.push_back(DriverPropertyInfo(
|
|
|
|
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SystemProperties"))
|
|
|
|
,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Additional properties to set at java.lang.System before loading the driver."))
|
|
|
|
,sal_True
|
|
|
|
,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "" ) )
|
2004-08-02 16:05:00 +00:00
|
|
|
,Sequence< ::rtl::OUString >())
|
|
|
|
);
|
2007-11-21 14:03:32 +00:00
|
|
|
|
2004-08-02 16:05:00 +00:00
|
|
|
aDriverInfo.push_back(DriverPropertyInfo(
|
|
|
|
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParameterNameSubstitution"))
|
|
|
|
,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Change named parameters with '?'."))
|
|
|
|
,sal_False
|
2006-12-13 15:18:59 +00:00
|
|
|
,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) )
|
|
|
|
,aBooleanValues)
|
2004-08-02 16:05:00 +00:00
|
|
|
);
|
2007-11-21 14:03:32 +00:00
|
|
|
|
2004-08-02 16:05:00 +00:00
|
|
|
aDriverInfo.push_back(DriverPropertyInfo(
|
|
|
|
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IgnoreDriverPrivileges"))
|
|
|
|
,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Ignore the privileges from the database driver."))
|
|
|
|
,sal_False
|
2006-12-13 15:18:59 +00:00
|
|
|
,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) )
|
|
|
|
,aBooleanValues)
|
2004-08-02 16:05:00 +00:00
|
|
|
);
|
2007-11-21 14:03:32 +00:00
|
|
|
|
2004-08-02 16:05:00 +00:00
|
|
|
aDriverInfo.push_back(DriverPropertyInfo(
|
|
|
|
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsAutoRetrievingEnabled"))
|
|
|
|
,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Retrieve generated values."))
|
|
|
|
,sal_False
|
2006-12-13 15:18:59 +00:00
|
|
|
,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) )
|
|
|
|
,aBooleanValues)
|
2004-08-02 16:05:00 +00:00
|
|
|
);
|
2007-11-21 14:03:32 +00:00
|
|
|
|
2004-08-02 16:05:00 +00:00
|
|
|
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 >())
|
|
|
|
);
|
2007-11-21 14:03:32 +00:00
|
|
|
|
2006-12-13 15:18:59 +00:00
|
|
|
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)
|
|
|
|
);
|
2007-11-27 11:02:08 +00:00
|
|
|
aDriverInfo.push_back(DriverPropertyInfo(
|
|
|
|
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IgnoreCurrency"))
|
|
|
|
,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Ignore the currency field from the ResultsetMetaData."))
|
|
|
|
,sal_False
|
|
|
|
,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) )
|
|
|
|
,aBooleanValues)
|
|
|
|
);
|
2008-01-29 07:38:04 +00:00
|
|
|
aDriverInfo.push_back(DriverPropertyInfo(
|
|
|
|
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("EscapeDateTime"))
|
|
|
|
,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Escape date time format."))
|
|
|
|
,sal_False
|
|
|
|
,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "true" ) )
|
|
|
|
,aBooleanValues)
|
|
|
|
);
|
2008-01-30 08:47:06 +00:00
|
|
|
aDriverInfo.push_back(DriverPropertyInfo(
|
|
|
|
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TypeInfoSettings"))
|
|
|
|
,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Defines how the type info of the database metadata should be manipulated."))
|
|
|
|
,sal_False
|
|
|
|
,::rtl::OUString( )
|
|
|
|
,Sequence< ::rtl::OUString > ())
|
|
|
|
);
|
2005-03-10 14:29:42 +00:00
|
|
|
return Sequence< DriverPropertyInfo >(&aDriverInfo[0],aDriverInfo.size());
|
2004-08-02 16:05:00 +00:00
|
|
|
}
|
2008-10-01 12:28:29 +00:00
|
|
|
::connectivity::SharedResources aResources;
|
|
|
|
const ::rtl::OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
|
|
|
|
::dbtools::throwGenericSQLException(sMessage ,*this);
|
2003-04-24 12:26:09 +00:00
|
|
|
return Sequence< DriverPropertyInfo >();
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
sal_Int32 SAL_CALL java_sql_Driver::getMajorVersion( ) throw(RuntimeException)
|
|
|
|
{
|
2003-04-24 12:26:09 +00:00
|
|
|
return 1;
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
sal_Int32 SAL_CALL java_sql_Driver::getMinorVersion( ) throw(RuntimeException)
|
|
|
|
{
|
2003-04-24 12:26:09 +00:00
|
|
|
return 0;
|
2000-09-18 15:18:56 +00:00
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|