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 #ifndef DBACCESS_SOURCE_UI_INC_DEFAULTOBJECTNAMECHECK_HXX
25 #define DBACCESS_SOURCE_UI_INC_DEFAULTOBJECTNAMECHECK_HXX
26 
27 #ifndef DBACCESS_SOURCE_UI_INC_OBJECTNAMECHECK_HXX
28 #include "objectnamecheck.hxx"
29 #endif
30 
31 /** === begin UNO includes === **/
32 #ifndef _COM_SUN_STAR_CONTAINER_XHIERARCHICALNAMEACCESS_HPP_
33 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
34 #endif
35 #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
36 #include <com/sun/star/container/XNameAccess.hpp>
37 #endif
38 #ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_
39 #include <com/sun/star/sdbc/XConnection.hpp>
40 #endif
41 /** === end UNO includes === **/
42 
43 #include <memory>
44 #include <boost/noncopyable.hpp>
45 
46 //........................................................................
47 namespace dbaui
48 {
49 //........................................................................
50 
51     //====================================================================
52     //= HierarchicalNameCheck
53     //====================================================================
54     struct HierarchicalNameCheck_Impl;
55     /** class implementing the IObjectNameCheck interface, and checking given object names
56         against a hierarchical name container
57     */
58     class HierarchicalNameCheck :public ::boost::noncopyable
59                                 ,public IObjectNameCheck
60     {
61     private:
62         std::auto_ptr< HierarchicalNameCheck_Impl > m_pImpl;
63 
64     public:
65         /** constructs a HierarchicalNameCheck instance
66         @param _rxNames
67             the hierarchic container of named objects, against which given names should be
68             checked
69         @param _rRelativeRoot
70             the root in the hierarchy against which given names should be checked
71         @throws ::com::sun::star::lang::IllegalArgumentException
72             if the given container is <NULL/>
73         */
74         HierarchicalNameCheck(
75             const ::com::sun::star::uno::Reference< ::com::sun::star::container::XHierarchicalNameAccess >& _rxNames,
76             const ::rtl::OUString& _rRelativeRoot
77         );
78 
79         ~HierarchicalNameCheck();
80 
81         // IObjectNameCheck overridables
82         virtual bool    isNameValid(
83             const ::rtl::OUString& _rObjectName,
84             ::dbtools::SQLExceptionInfo& _out_rErrorToDisplay
85         ) const;
86 
87     private:
88         HierarchicalNameCheck();                                            // never implemented
89     };
90 
91     //====================================================================
92     //= DynamicTableOrQueryNameCheck
93     //====================================================================
94     struct DynamicTableOrQueryNameCheck_Impl;
95     /** class implementing the IObjectNameCheck interface, and checking a given name
96         for being valid as either a query or a table name.
97 
98         The class can be parametrized to act as either table name or query name validator.
99 
100         For databases which support queries in queries, the name check is implicitly extended
101         to both queries and tables, no matter which category is checked. This prevents, for
102         such databases, that users can create a query with the name of an existing table,
103         or vice versa.
104 
105         @seealso dbtools::DatabaseMetaData::supportsSubqueriesInFrom
106         @seealso com::sun::star::sdb::tools::XObjectNames::checkNameForCreate
107     */
108     class DynamicTableOrQueryNameCheck  :public ::boost::noncopyable
109                                         ,public IObjectNameCheck
110     {
111     private:
112         std::auto_ptr< DynamicTableOrQueryNameCheck_Impl > m_pImpl;
113 
114     public:
115         /** constructs a DynamicTableOrQueryNameCheck instance
116         @param _rxSdbLevelConnection
117             a connection supporting the css.sdb.Connection service, in other word, it
118             does expose the XTablesSupplier and XQueriesSupplier interfaces.
119         @param _nCommandType
120             specifies whether table names or query names should be checked. Only valid values
121             are CommandType::TABLE and CommandType::QUERY.
122         @throws ::com::sun::star::lang::IllegalArgumentException
123             if the given connection is <NULL/>, or the given command type is neither
124             CommandType::TABLE nor CommandType::QUERY.
125         */
126         DynamicTableOrQueryNameCheck(
127             const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxSdbLevelConnection,
128             sal_Int32 _nCommandType
129         );
130 
131         ~DynamicTableOrQueryNameCheck();
132 
133         // IObjectNameCheck overridables
134         virtual bool    isNameValid(
135             const ::rtl::OUString& _rObjectName,
136             ::dbtools::SQLExceptionInfo& _out_rErrorToDisplay
137         ) const;
138 
139     private:
140         DynamicTableOrQueryNameCheck();                                                // never implemented
141     };
142 
143 //........................................................................
144 } // namespace dbaui
145 //........................................................................
146 
147 #endif // DBACCESS_SOURCE_UI_INC_DEFAULTOBJECTNAMECHECK_HXX
148 
149