1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "java/sql/Driver.hxx"
30 #include <cppuhelper/factory.hxx>
32 using namespace connectivity
;
33 using ::rtl::OUString
;
34 using ::com::sun::star::uno::Reference
;
35 using ::com::sun::star::uno::Sequence
;
36 using ::com::sun::star::lang::XSingleServiceFactory
;
37 using ::com::sun::star::lang::XMultiServiceFactory
;
39 typedef Reference
< XSingleServiceFactory
> (SAL_CALL
*createFactoryFunc
)
41 const Reference
< XMultiServiceFactory
> & rServiceManager
,
42 const OUString
& rComponentName
,
43 ::cppu::ComponentInstantiation pCreateFunction
,
44 const Sequence
< OUString
> & rServiceNames
,
45 rtl_ModuleCount
* _pModCount
48 //---------------------------------------------------------------------------------------
49 struct ProviderRequest
51 Reference
< XSingleServiceFactory
> xRet
;
52 Reference
< XMultiServiceFactory
> const xServiceManager
;
53 OUString
const sImplementationName
;
56 void* pServiceManager
,
57 sal_Char
const* pImplementationName
59 : xServiceManager(reinterpret_cast<XMultiServiceFactory
*>(pServiceManager
))
60 , sImplementationName(OUString::createFromAscii(pImplementationName
))
65 sal_Bool
CREATE_PROVIDER(
66 const OUString
& Implname
,
67 const Sequence
< OUString
> & Services
,
68 ::cppu::ComponentInstantiation Factory
,
69 createFactoryFunc creator
72 if (!xRet
.is() && (Implname
== sImplementationName
))
75 xRet
= creator( xServiceManager
, sImplementationName
,Factory
, Services
,0);
83 void* getProvider() const { return xRet
.get(); }
86 extern "C" SAL_DLLPUBLIC_EXPORT
void SAL_CALL
87 component_getImplementationEnvironment(
88 char const ** ppEnvTypeName
, uno_Environment
**)
90 // Recent Java 6 VMs make calls to JNI Attach/DetachCurrentThread (which
91 // this code does extensively) very expensive. A follow-up JVM fix reduced
92 // the overhead significantly again for all threads but the main thread. So
93 // a quick hack to improve performance of this component again is to confine
94 // it in the affine apartment (where all code will run on a single,
95 // dedicated thread that is guaranteed no to be the main thread). However,
96 // a better fix would still be to redesign the code so that it does not call
97 // Attach/DetachCurrentThread so frequently:
98 *ppEnvTypeName
= CPPU_CURRENT_LANGUAGE_BINDING_NAME
":affine";
101 extern "C" SAL_DLLPUBLIC_EXPORT
void* SAL_CALL
component_getFactory(
102 const sal_Char
* pImplementationName
,
103 void* pServiceManager
,
104 void* /*pRegistryKey*/)
109 ProviderRequest
aReq(pServiceManager
,pImplementationName
);
111 aReq
.CREATE_PROVIDER(
112 java_sql_Driver::getImplementationName_Static(),
113 java_sql_Driver::getSupportedServiceNames_Static(),
114 java_sql_Driver_CreateInstance
,
115 ::cppu::createSingleFactory
);
118 aReq
.xRet
->acquire();
119 pRet
= aReq
.getProvider();
129 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */