Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "connectiontools.hxx"
21 : #include "tablename.hxx"
22 : #include "objectnames.hxx"
23 : #include "datasourcemetadata.hxx"
24 :
25 : #include <comphelper/namedvaluecollection.hxx>
26 : #include <connectivity/dbtools.hxx>
27 : #include <connectivity/statementcomposer.hxx>
28 :
29 : #include <algorithm>
30 :
31 0 : extern "C" void SAL_CALL createRegistryInfo_ConnectionTools()
32 : {
33 0 : ::sdbtools::OAutoRegistration< ::sdbtools::ConnectionTools > aRegistration;
34 0 : }
35 :
36 : //........................................................................
37 : namespace sdbtools
38 : {
39 : //........................................................................
40 :
41 : /** === begin UNO using === **/
42 : using namespace ::com::sun::star;
43 : using namespace ::com::sun::star::uno;
44 : using ::com::sun::star::uno::Reference;
45 : using ::com::sun::star::uno::RuntimeException;
46 : using ::com::sun::star::sdb::tools::XTableName;
47 : using ::com::sun::star::sdb::tools::XObjectNames;
48 : using ::com::sun::star::sdb::tools::XDataSourceMetaData;
49 : using ::com::sun::star::uno::Sequence;
50 : using ::com::sun::star::uno::XInterface;
51 : using ::com::sun::star::uno::Any;
52 : using ::com::sun::star::uno::Exception;
53 : using ::com::sun::star::sdbc::XConnection;
54 : using ::com::sun::star::lang::IllegalArgumentException;
55 : using ::com::sun::star::uno::XComponentContext;
56 : /** === end UNO using === **/
57 :
58 : //====================================================================
59 : //= ConnectionTools
60 : //====================================================================
61 : //--------------------------------------------------------------------
62 0 : ConnectionTools::ConnectionTools( const ::comphelper::ComponentContext& _rContext )
63 0 : :ConnectionDependentComponent( _rContext )
64 : {
65 0 : }
66 :
67 : //--------------------------------------------------------------------
68 0 : ConnectionTools::~ConnectionTools()
69 : {
70 0 : }
71 :
72 : //--------------------------------------------------------------------
73 0 : Reference< XTableName > SAL_CALL ConnectionTools::createTableName() throw (RuntimeException)
74 : {
75 0 : EntryGuard aGuard( *this );
76 0 : return new TableName( getContext(), getConnection() );
77 : }
78 :
79 : //--------------------------------------------------------------------
80 0 : Reference< XObjectNames > SAL_CALL ConnectionTools::getObjectNames() throw (RuntimeException)
81 : {
82 0 : EntryGuard aGuard( *this );
83 0 : return new ObjectNames( getContext(), getConnection() );
84 : }
85 :
86 : //--------------------------------------------------------------------
87 0 : Reference< XDataSourceMetaData > SAL_CALL ConnectionTools::getDataSourceMetaData() throw (RuntimeException)
88 : {
89 0 : EntryGuard aGuard( *this );
90 0 : return new DataSourceMetaData( getContext(), getConnection() );
91 : }
92 : //--------------------------------------------------------------------
93 0 : Reference< container::XNameAccess > SAL_CALL ConnectionTools::getFieldsByCommandDescriptor( ::sal_Int32 commandType, const ::rtl::OUString& command, Reference< lang::XComponent >& keepFieldsAlive ) throw (sdbc::SQLException, RuntimeException)
94 : {
95 0 : EntryGuard aGuard( *this );
96 0 : ::dbtools::SQLExceptionInfo aErrorInfo;
97 0 : Reference< container::XNameAccess > xRet = ::dbtools::getFieldsByCommandDescriptor(getConnection(),commandType,command,keepFieldsAlive,&aErrorInfo);
98 0 : if ( aErrorInfo.isValid() )
99 0 : aErrorInfo.doThrow();
100 0 : return xRet;
101 : }
102 : //--------------------------------------------------------------------
103 0 : Reference< sdb::XSingleSelectQueryComposer > SAL_CALL ConnectionTools::getComposer( ::sal_Int32 commandType, const ::rtl::OUString& command ) throw (::com::sun::star::uno::RuntimeException)
104 : {
105 0 : EntryGuard aGuard( *this );
106 0 : dbtools::StatementComposer aComposer(getConnection(), command, commandType, sal_True );
107 0 : aComposer.setDisposeComposer(sal_False);
108 0 : return aComposer.getComposer();
109 : }
110 :
111 : //--------------------------------------------------------------------
112 0 : ::rtl::OUString SAL_CALL ConnectionTools::getImplementationName() throw (RuntimeException)
113 : {
114 0 : return getImplementationName_static();
115 : }
116 :
117 : //--------------------------------------------------------------------
118 0 : ::sal_Bool SAL_CALL ConnectionTools::supportsService(const ::rtl::OUString & _ServiceName) throw (RuntimeException)
119 : {
120 0 : Sequence< ::rtl::OUString > aSupported( getSupportedServiceNames() );
121 0 : const ::rtl::OUString* begin = aSupported.getConstArray();
122 0 : const ::rtl::OUString* end = aSupported.getConstArray() + aSupported.getLength();
123 0 : return ::std::find( begin, end, _ServiceName ) != end;
124 : }
125 :
126 : //--------------------------------------------------------------------
127 0 : Sequence< ::rtl::OUString > SAL_CALL ConnectionTools::getSupportedServiceNames() throw (RuntimeException)
128 : {
129 0 : return getSupportedServiceNames_static();
130 : }
131 :
132 : //--------------------------------------------------------------------
133 0 : ::rtl::OUString SAL_CALL ConnectionTools::getImplementationName_static()
134 : {
135 0 : return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.dbaccess.ConnectionTools" ) );
136 : }
137 :
138 : //--------------------------------------------------------------------
139 0 : Sequence< ::rtl::OUString > SAL_CALL ConnectionTools::getSupportedServiceNames_static()
140 : {
141 0 : Sequence< ::rtl::OUString > aSupported( 1 );
142 0 : aSupported[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.tools.ConnectionTools" ) );
143 0 : return aSupported;
144 : }
145 :
146 : //--------------------------------------------------------------------
147 0 : Reference< XInterface > SAL_CALL ConnectionTools::Create(const Reference< XComponentContext >& _rxContext )
148 : {
149 0 : return *( new ConnectionTools( ::comphelper::ComponentContext( _rxContext ) ) );
150 : }
151 :
152 : //--------------------------------------------------------------------
153 0 : void SAL_CALL ConnectionTools::initialize(const Sequence< Any > & _rArguments) throw (RuntimeException, Exception)
154 : {
155 0 : ::osl::MutexGuard aGuard( getMutex() );
156 :
157 0 : ::comphelper::NamedValueCollection aArguments( _rArguments );
158 :
159 0 : Reference< XConnection > xConnection;
160 0 : aArguments.get( "Connection" ) >>= xConnection;
161 0 : if ( !xConnection.is() )
162 0 : throw IllegalArgumentException();
163 :
164 0 : setWeakConnection( xConnection );
165 0 : }
166 :
167 :
168 : //........................................................................
169 : } // namespace sdbtools
170 : //........................................................................
171 :
172 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|