2000-09-18 15:18:56 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2005-09-08 05:10:56 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2005-09-08 05:10:56 +00:00
|
|
|
* $RCSfile: JDriver.cxx,v $
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2006-12-13 15:18:59 +00:00
|
|
|
* $Revision: 1.37 $
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2006-12-13 15:18:59 +00:00
|
|
|
* last change: $Author: kz $ $Date: 2006-12-13 16:18:59 $
|
2000-09-18 15:18:56 +00:00
|
|
|
*
|
2005-09-08 05:10: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
|
|
|
*
|
|
|
|
*
|
2005-09-08 05:10: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
|
|
|
*
|
2005-09-08 05:10: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
|
|
|
*
|
2005-09-08 05:10: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
|
|
|
*
|
2005-09-08 05:10: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
|
|
|
*
|
|
|
|
************************************************************************/
|
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
|
|
|
#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
|
2002-08-01 05:30:16 +00:00
|
|
|
#ifndef _DBHELPER_DBEXCEPTION_HXX_
|
|
|
|
#include "connectivity/dbexception.hxx"
|
|
|
|
#endif
|
2005-02-17 09:15:29 +00:00
|
|
|
#ifndef INCLUDED_JVMFWK_FRAMEWORK_H
|
|
|
|
#include <jvmfwk/framework.h>
|
|
|
|
#endif
|
2006-06-20 00:34:40 +00:00
|
|
|
#ifndef CONNECTIVITY_DIAGNOSE_EX_H
|
|
|
|
#include "diagnose_ex.h"
|
|
|
|
#endif
|
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::sdbcx;
|
|
|
|
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)
|
2003-04-24 12:26:09 +00:00
|
|
|
: m_xORB(_rxFactory)
|
2000-09-18 15:18:56 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
// --------------------------------------------------------------------------------
|
|
|
|
java_sql_Driver::~java_sql_Driver()
|
|
|
|
{}
|
|
|
|
// 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)
|
|
|
|
{
|
2003-05-22 09:50:18 +00:00
|
|
|
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 doesn't throw an exception
|
|
|
|
}
|
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
|
|
|
|
,::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
|
2006-12-13 15:18:59 +00:00
|
|
|
,::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "false" ) )
|
|
|
|
,aBooleanValues)
|
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
|
|
|
);
|
|
|
|
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
|
|
|
);
|
|
|
|
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 >())
|
|
|
|
);
|
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)
|
|
|
|
);
|
2005-03-10 14:29:42 +00:00
|
|
|
return Sequence< DriverPropertyInfo >(&aDriverInfo[0],aDriverInfo.size());
|
2004-08-02 16:05:00 +00:00
|
|
|
}
|
|
|
|
::dbtools::throwGenericSQLException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Invalid URL!")) ,*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
|
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|