1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: FDatabaseMetaDataResultSet.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #include "precompiled_connectivity.hxx"
31 #include "ParameterSubstitution.hxx"
32 #include "connectivity/sqlparse.hxx"
33 #include <comphelper/sequenceashashmap.hxx>
35 namespace connectivity
37 using namespace ::com::sun::star::uno
;
38 using namespace ::com::sun::star::sdbc
;
39 using namespace ::com::sun::star::lang
;
40 using namespace ::com::sun::star
;
42 ParameterSubstitution::ParameterSubstitution(const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& _rxContext
) : m_xContext(_rxContext
)
45 void SAL_CALL
ParameterSubstitution::initialize( const uno::Sequence
< uno::Any
>& _aArguments
) throw (uno::Exception
, uno::RuntimeException
)
47 ::osl::MutexGuard
aGuard(m_aMutex
);
48 comphelper::SequenceAsHashMap
aArgs(_aArguments
);
49 uno::Reference
< sdbc::XConnection
> xConnection
;
50 xConnection
= aArgs
.getUnpackedValueOrDefault(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ActiveConnection")),xConnection
);
51 m_xConnection
= xConnection
;
53 //------------------------------------------------------------------------------
54 rtl::OUString
ParameterSubstitution::getImplementationName_Static( ) throw(RuntimeException
)
56 return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.comp.helper.ParameterSubstitution"));
58 //------------------------------------------------------------------------------
59 ::rtl::OUString SAL_CALL
ParameterSubstitution::getImplementationName( ) throw(RuntimeException
)
61 return getImplementationName_Static();
63 //------------------------------------------------------------------
64 sal_Bool SAL_CALL
ParameterSubstitution::supportsService( const ::rtl::OUString
& _rServiceName
) throw(RuntimeException
)
66 Sequence
< ::rtl::OUString
> aSupported(getSupportedServiceNames());
67 const ::rtl::OUString
* pSupported
= aSupported
.getConstArray();
68 const ::rtl::OUString
* pEnd
= pSupported
+ aSupported
.getLength();
69 for (;pSupported
!= pEnd
&& !pSupported
->equals(_rServiceName
); ++pSupported
)
72 return pSupported
!= pEnd
;
74 //------------------------------------------------------------------
75 Sequence
< ::rtl::OUString
> SAL_CALL
ParameterSubstitution::getSupportedServiceNames( ) throw(RuntimeException
)
77 return getSupportedServiceNames_Static();
79 //------------------------------------------------------------------
80 Sequence
< ::rtl::OUString
> ParameterSubstitution::getSupportedServiceNames_Static( ) throw (RuntimeException
)
82 Sequence
< ::rtl::OUString
> aSNS( 1 );
83 aSNS
[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdb.ParameterSubstitution");
87 //------------------------------------------------------------------
88 Reference
< XInterface
> ParameterSubstitution::create(const Reference
< XComponentContext
>& _xContext
)
90 return *(new ParameterSubstitution(_xContext
));
92 //------------------------------------------------------------------
93 ::rtl::OUString SAL_CALL
ParameterSubstitution::substituteVariables( const ::rtl::OUString
& _sText
, ::sal_Bool
/*bSubstRequired*/ ) throw (::com::sun::star::container::NoSuchElementException
, ::com::sun::star::uno::RuntimeException
)
95 ::rtl::OUString sRet
= _sText
;
96 uno::Reference
< sdbc::XConnection
> xConnection
= m_xConnection
;
97 if ( xConnection
.is() )
101 uno::Reference
< XMultiServiceFactory
> xFac(m_xContext
->getServiceManager(),uno::UNO_QUERY_THROW
);
102 OSQLParser
aParser( xFac
);
103 ::rtl::OUString sErrorMessage
;
104 ::rtl::OUString sNewSql
;
105 OSQLParseNode
* pNode
= aParser
.parseTree(sErrorMessage
,_sText
);
107 { // special handling for parameters
108 OSQLParseNode::substituteParameterNames(pNode
);
109 pNode
->parseNodeToStr( sNewSql
, xConnection
);
114 catch(const Exception
&)
120 //------------------------------------------------------------------
121 ::rtl::OUString SAL_CALL
ParameterSubstitution::reSubstituteVariables( const ::rtl::OUString
& _sText
) throw (::com::sun::star::uno::RuntimeException
)
125 //------------------------------------------------------------------
126 ::rtl::OUString SAL_CALL
ParameterSubstitution::getSubstituteVariableValue( const ::rtl::OUString
& /*variable*/ ) throw (::com::sun::star::container::NoSuchElementException
, ::com::sun::star::uno::RuntimeException
)
128 throw container::NoSuchElementException();
130 //------------------------------------------------------------------
133 // ==================================
135 // ==================================