1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_dbaccess.hxx"
26 
27 #ifndef DBACCESS_OBJECTNAMEAPPROVAL_HXX
28 #include "objectnameapproval.hxx"
29 #endif
30 
31 /** === begin UNO includes === **/
32 #ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_
33 #include <com/sun/star/lang/DisposedException.hpp>
34 #endif
35 #ifndef _COM_SUN_STAR_SDB_TOOLS_XCONNECTIONTOOLS_HPP_
36 #include <com/sun/star/sdb/tools/XConnectionTools.hpp>
37 #endif
38 #ifndef _COM_SUN_STAR_SDB_COMMANDTYPE_HPP_
39 #include <com/sun/star/sdb/CommandType.hpp>
40 #endif
41 #ifndef _COM_SUN_STAR_SDBC_SQLEXCEPTION_HPP_
42 #include <com/sun/star/sdbc/SQLException.hpp>
43 #endif
44 /** === end UNO includes === **/
45 
46 #ifndef _CPPUHELPER_WEAKREF_HXX_
47 #include <cppuhelper/weakref.hxx>
48 #endif
49 #ifndef _CPPUHELPER_EXC_HLP_HXX_
50 #include <cppuhelper/exc_hlp.hxx>
51 #endif
52 
53 //........................................................................
54 namespace dbaccess
55 {
56 //........................................................................
57 
58 	/** === begin UNO using === **/
59     using ::com::sun::star::sdbc::XConnection;
60     using ::com::sun::star::uno::WeakReference;
61     using ::com::sun::star::uno::Reference;
62     using ::com::sun::star::lang::DisposedException;
63     using ::com::sun::star::sdb::tools::XConnectionTools;
64     using ::com::sun::star::uno::UNO_QUERY_THROW;
65     using ::com::sun::star::sdb::tools::XObjectNames;
66     using ::com::sun::star::uno::XInterface;
67     using ::com::sun::star::sdbc::SQLException;
68 	/** === end UNO using === **/
69 
70     namespace CommandType = com::sun::star::sdb::CommandType;
71 
72 	//====================================================================
73 	//= ObjectNameApproval_Impl
74 	//====================================================================
75     struct ObjectNameApproval_Impl
76     {
77         WeakReference< XConnection >        aConnection;
78         sal_Int32                           nCommandType;
79     };
80 
81 	//====================================================================
82 	//= ObjectNameApproval
83 	//====================================================================
84 	//--------------------------------------------------------------------
ObjectNameApproval(const Reference<XConnection> & _rxConnection,ObjectType _eType)85     ObjectNameApproval::ObjectNameApproval( const Reference< XConnection >& _rxConnection, ObjectType _eType )
86         :m_pImpl( new ObjectNameApproval_Impl )
87     {
88         m_pImpl->aConnection = _rxConnection;
89         m_pImpl->nCommandType = _eType == TypeQuery ? CommandType::QUERY : CommandType::TABLE;
90     }
91 
92 	//--------------------------------------------------------------------
~ObjectNameApproval()93     ObjectNameApproval::~ObjectNameApproval()
94     {
95     }
96 
97     //--------------------------------------------------------------------
approveElement(const::rtl::OUString & _rName,const Reference<XInterface> &)98     void SAL_CALL ObjectNameApproval::approveElement( const ::rtl::OUString& _rName, const Reference< XInterface >& /*_rxElement*/ )
99     {
100         Reference< XConnection > xConnection( m_pImpl->aConnection );
101         if ( !xConnection.is() )
102             throw DisposedException();
103 
104         Reference< XConnectionTools > xConnectionTools( xConnection, UNO_QUERY_THROW );
105         Reference< XObjectNames > xObjectNames( xConnectionTools->getObjectNames(), UNO_QUERY_THROW );
106         xObjectNames->checkNameForCreate( m_pImpl->nCommandType, _rName );
107     }
108 
109 //........................................................................
110 } // namespace dbaccess
111 //........................................................................
112 
113