1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_dbaccess.hxx"
30 
31 #ifndef DBACCESS_OBJECTNAMEAPPROVAL_HXX
32 #include "objectnameapproval.hxx"
33 #endif
34 
35 /** === begin UNO includes === **/
36 #ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_
37 #include <com/sun/star/lang/DisposedException.hpp>
38 #endif
39 #ifndef _COM_SUN_STAR_SDB_TOOLS_XCONNECTIONTOOLS_HPP_
40 #include <com/sun/star/sdb/tools/XConnectionTools.hpp>
41 #endif
42 #ifndef _COM_SUN_STAR_SDB_COMMANDTYPE_HPP_
43 #include <com/sun/star/sdb/CommandType.hpp>
44 #endif
45 #ifndef _COM_SUN_STAR_SDBC_SQLEXCEPTION_HPP_
46 #include <com/sun/star/sdbc/SQLException.hpp>
47 #endif
48 /** === end UNO includes === **/
49 
50 #ifndef _CPPUHELPER_WEAKREF_HXX_
51 #include <cppuhelper/weakref.hxx>
52 #endif
53 #ifndef _CPPUHELPER_EXC_HLP_HXX_
54 #include <cppuhelper/exc_hlp.hxx>
55 #endif
56 
57 //........................................................................
58 namespace dbaccess
59 {
60 //........................................................................
61 
62 	/** === begin UNO using === **/
63     using ::com::sun::star::sdbc::XConnection;
64     using ::com::sun::star::uno::WeakReference;
65     using ::com::sun::star::uno::Reference;
66     using ::com::sun::star::lang::DisposedException;
67     using ::com::sun::star::sdb::tools::XConnectionTools;
68     using ::com::sun::star::uno::UNO_QUERY_THROW;
69     using ::com::sun::star::sdb::tools::XObjectNames;
70     using ::com::sun::star::uno::XInterface;
71     using ::com::sun::star::sdbc::SQLException;
72 	/** === end UNO using === **/
73 
74     namespace CommandType = com::sun::star::sdb::CommandType;
75 
76 	//====================================================================
77 	//= ObjectNameApproval_Impl
78 	//====================================================================
79     struct ObjectNameApproval_Impl
80     {
81         WeakReference< XConnection >        aConnection;
82         sal_Int32                           nCommandType;
83     };
84 
85 	//====================================================================
86 	//= ObjectNameApproval
87 	//====================================================================
88 	//--------------------------------------------------------------------
89     ObjectNameApproval::ObjectNameApproval( const Reference< XConnection >& _rxConnection, ObjectType _eType )
90         :m_pImpl( new ObjectNameApproval_Impl )
91     {
92         m_pImpl->aConnection = _rxConnection;
93         m_pImpl->nCommandType = _eType == TypeQuery ? CommandType::QUERY : CommandType::TABLE;
94     }
95 
96 	//--------------------------------------------------------------------
97     ObjectNameApproval::~ObjectNameApproval()
98     {
99     }
100 
101     //--------------------------------------------------------------------
102     void SAL_CALL ObjectNameApproval::approveElement( const ::rtl::OUString& _rName, const Reference< XInterface >& /*_rxElement*/ )
103     {
104         Reference< XConnection > xConnection( m_pImpl->aConnection );
105         if ( !xConnection.is() )
106             throw DisposedException();
107 
108         Reference< XConnectionTools > xConnectionTools( xConnection, UNO_QUERY_THROW );
109         Reference< XObjectNames > xObjectNames( xConnectionTools->getObjectNames(), UNO_QUERY_THROW );
110         xObjectNames->checkNameForCreate( m_pImpl->nCommandType, _rName );
111     }
112 
113 //........................................................................
114 } // namespace dbaccess
115 //........................................................................
116 
117