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 "sdbt_services.hxx"
22 : #include "tablename.hxx"
23 : #include "objectnames.hxx"
24 : #include "datasourcemetadata.hxx"
25 :
26 : #include <comphelper/namedvaluecollection.hxx>
27 : #include <cppuhelper/supportsservice.hxx>
28 : #include <connectivity/dbtools.hxx>
29 : #include <connectivity/statementcomposer.hxx>
30 :
31 : #include <algorithm>
32 :
33 1 : extern "C" void SAL_CALL createRegistryInfo_ConnectionTools()
34 : {
35 1 : ::sdbtools::OAutoRegistration< ::sdbtools::ConnectionTools > aRegistration;
36 1 : }
37 :
38 : namespace sdbtools
39 : {
40 :
41 : using namespace ::com::sun::star;
42 : using namespace ::com::sun::star::uno;
43 : using ::com::sun::star::uno::Reference;
44 : using ::com::sun::star::uno::RuntimeException;
45 : using ::com::sun::star::sdb::tools::XTableName;
46 : using ::com::sun::star::sdb::tools::XObjectNames;
47 : using ::com::sun::star::sdb::tools::XDataSourceMetaData;
48 : using ::com::sun::star::uno::Sequence;
49 : using ::com::sun::star::uno::XInterface;
50 : using ::com::sun::star::uno::Any;
51 : using ::com::sun::star::uno::Exception;
52 : using ::com::sun::star::sdbc::XConnection;
53 : using ::com::sun::star::lang::IllegalArgumentException;
54 : using ::com::sun::star::uno::XComponentContext;
55 :
56 : // ConnectionTools
57 25 : ConnectionTools::ConnectionTools( const Reference<XComponentContext>& _rContext )
58 25 : :ConnectionDependentComponent( _rContext )
59 : {
60 25 : }
61 :
62 50 : ConnectionTools::~ConnectionTools()
63 : {
64 50 : }
65 :
66 0 : Reference< XTableName > SAL_CALL ConnectionTools::createTableName() throw (RuntimeException, std::exception)
67 : {
68 0 : EntryGuard aGuard( *this );
69 0 : return new TableName( getContext(), getConnection() );
70 : }
71 :
72 25 : Reference< XObjectNames > SAL_CALL ConnectionTools::getObjectNames() throw (RuntimeException, std::exception)
73 : {
74 25 : EntryGuard aGuard( *this );
75 25 : return new ObjectNames( getContext(), getConnection() );
76 : }
77 :
78 0 : Reference< XDataSourceMetaData > SAL_CALL ConnectionTools::getDataSourceMetaData() throw (RuntimeException, std::exception)
79 : {
80 0 : EntryGuard aGuard( *this );
81 0 : return new DataSourceMetaData( getContext(), getConnection() );
82 : }
83 0 : Reference< container::XNameAccess > SAL_CALL ConnectionTools::getFieldsByCommandDescriptor( ::sal_Int32 commandType, const OUString& command, Reference< lang::XComponent >& keepFieldsAlive ) throw (sdbc::SQLException, RuntimeException, std::exception)
84 : {
85 0 : EntryGuard aGuard( *this );
86 0 : ::dbtools::SQLExceptionInfo aErrorInfo;
87 0 : Reference< container::XNameAccess > xRet = ::dbtools::getFieldsByCommandDescriptor(getConnection(),commandType,command,keepFieldsAlive,&aErrorInfo);
88 0 : if ( aErrorInfo.isValid() )
89 0 : aErrorInfo.doThrow();
90 0 : return xRet;
91 : }
92 0 : Reference< sdb::XSingleSelectQueryComposer > SAL_CALL ConnectionTools::getComposer( ::sal_Int32 commandType, const OUString& command ) throw (::com::sun::star::uno::RuntimeException, std::exception)
93 : {
94 0 : EntryGuard aGuard( *this );
95 0 : dbtools::StatementComposer aComposer(getConnection(), command, commandType, true );
96 0 : aComposer.setDisposeComposer(false);
97 0 : return aComposer.getComposer();
98 : }
99 :
100 0 : OUString SAL_CALL ConnectionTools::getImplementationName() throw (RuntimeException, std::exception)
101 : {
102 0 : return getImplementationName_static();
103 : }
104 :
105 0 : sal_Bool SAL_CALL ConnectionTools::supportsService(const OUString & _ServiceName) throw (RuntimeException, std::exception)
106 : {
107 0 : return cppu::supportsService(this, _ServiceName);
108 : }
109 :
110 0 : Sequence< OUString > SAL_CALL ConnectionTools::getSupportedServiceNames() throw (RuntimeException, std::exception)
111 : {
112 0 : return getSupportedServiceNames_static();
113 : }
114 :
115 1 : OUString SAL_CALL ConnectionTools::getImplementationName_static()
116 : {
117 1 : return OUString( "com.sun.star.comp.dbaccess.ConnectionTools" );
118 : }
119 :
120 1 : Sequence< OUString > SAL_CALL ConnectionTools::getSupportedServiceNames_static()
121 : {
122 1 : Sequence< OUString > aSupported( 1 );
123 1 : aSupported[0] = "com.sun.star.sdb.tools.ConnectionTools";
124 1 : return aSupported;
125 : }
126 :
127 25 : Reference< XInterface > SAL_CALL ConnectionTools::Create(const Reference< XComponentContext >& _rxContext )
128 : {
129 25 : return *( new ConnectionTools( Reference<XComponentContext>( _rxContext ) ) );
130 : }
131 :
132 25 : void SAL_CALL ConnectionTools::initialize(const Sequence< Any > & _rArguments) throw (RuntimeException, Exception, std::exception)
133 : {
134 25 : ::osl::MutexGuard aGuard( getMutex() );
135 :
136 50 : Reference< XConnection > xConnection;
137 25 : if (_rArguments.getLength()==1 && (_rArguments[0] >>= xConnection))
138 : {
139 : }
140 : else
141 : {
142 0 : ::comphelper::NamedValueCollection aArguments( _rArguments );
143 0 : aArguments.get( "Connection" ) >>= xConnection;
144 : }
145 25 : if ( !xConnection.is() )
146 0 : throw IllegalArgumentException();
147 :
148 50 : setWeakConnection( xConnection );
149 25 : }
150 :
151 : } // namespace sdbtools
152 :
153 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|