xref: /AOO41X/main/dbaccess/source/ui/inc/defaultobjectnamecheck.hxx (revision 2e2212a7c22e96cf6f6fab0dd042c34a45a64bd6)
1*2e2212a7SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2e2212a7SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2e2212a7SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2e2212a7SAndrew Rist  * distributed with this work for additional information
6*2e2212a7SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2e2212a7SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2e2212a7SAndrew Rist  * "License"); you may not use this file except in compliance
9*2e2212a7SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*2e2212a7SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*2e2212a7SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2e2212a7SAndrew Rist  * software distributed under the License is distributed on an
15*2e2212a7SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2e2212a7SAndrew Rist  * KIND, either express or implied.  See the License for the
17*2e2212a7SAndrew Rist  * specific language governing permissions and limitations
18*2e2212a7SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*2e2212a7SAndrew Rist  *************************************************************/
21*2e2212a7SAndrew Rist 
22*2e2212a7SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef DBACCESS_SOURCE_UI_INC_DEFAULTOBJECTNAMECHECK_HXX
25cdf0e10cSrcweir #define DBACCESS_SOURCE_UI_INC_DEFAULTOBJECTNAMECHECK_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #ifndef DBACCESS_SOURCE_UI_INC_OBJECTNAMECHECK_HXX
28cdf0e10cSrcweir #include "objectnamecheck.hxx"
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir 
31cdf0e10cSrcweir /** === begin UNO includes === **/
32cdf0e10cSrcweir #ifndef _COM_SUN_STAR_CONTAINER_XHIERARCHICALNAMEACCESS_HPP_
33cdf0e10cSrcweir #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
34cdf0e10cSrcweir #endif
35cdf0e10cSrcweir #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
36cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
37cdf0e10cSrcweir #endif
38cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_
39cdf0e10cSrcweir #include <com/sun/star/sdbc/XConnection.hpp>
40cdf0e10cSrcweir #endif
41cdf0e10cSrcweir /** === end UNO includes === **/
42cdf0e10cSrcweir 
43cdf0e10cSrcweir #include <memory>
44cdf0e10cSrcweir #include <boost/noncopyable.hpp>
45cdf0e10cSrcweir 
46cdf0e10cSrcweir //........................................................................
47cdf0e10cSrcweir namespace dbaui
48cdf0e10cSrcweir {
49cdf0e10cSrcweir //........................................................................
50cdf0e10cSrcweir 
51cdf0e10cSrcweir     //====================================================================
52cdf0e10cSrcweir     //= HierarchicalNameCheck
53cdf0e10cSrcweir     //====================================================================
54cdf0e10cSrcweir     struct HierarchicalNameCheck_Impl;
55cdf0e10cSrcweir     /** class implementing the IObjectNameCheck interface, and checking given object names
56cdf0e10cSrcweir         against a hierarchical name container
57cdf0e10cSrcweir     */
58cdf0e10cSrcweir     class HierarchicalNameCheck :public ::boost::noncopyable
59cdf0e10cSrcweir                                 ,public IObjectNameCheck
60cdf0e10cSrcweir     {
61cdf0e10cSrcweir     private:
62cdf0e10cSrcweir         std::auto_ptr< HierarchicalNameCheck_Impl > m_pImpl;
63cdf0e10cSrcweir 
64cdf0e10cSrcweir     public:
65cdf0e10cSrcweir         /** constructs a HierarchicalNameCheck instance
66cdf0e10cSrcweir         @param _rxNames
67cdf0e10cSrcweir             the hierarchic container of named objects, against which given names should be
68cdf0e10cSrcweir             checked
69cdf0e10cSrcweir         @param _rRelativeRoot
70cdf0e10cSrcweir             the root in the hierarchy against which given names should be checked
71cdf0e10cSrcweir         @throws ::com::sun::star::lang::IllegalArgumentException
72cdf0e10cSrcweir             if the given container is <NULL/>
73cdf0e10cSrcweir         */
74cdf0e10cSrcweir         HierarchicalNameCheck(
75cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< ::com::sun::star::container::XHierarchicalNameAccess >& _rxNames,
76cdf0e10cSrcweir             const ::rtl::OUString& _rRelativeRoot
77cdf0e10cSrcweir         );
78cdf0e10cSrcweir 
79cdf0e10cSrcweir         ~HierarchicalNameCheck();
80cdf0e10cSrcweir 
81cdf0e10cSrcweir         // IObjectNameCheck overridables
82cdf0e10cSrcweir         virtual bool    isNameValid(
83cdf0e10cSrcweir             const ::rtl::OUString& _rObjectName,
84cdf0e10cSrcweir             ::dbtools::SQLExceptionInfo& _out_rErrorToDisplay
85cdf0e10cSrcweir         ) const;
86cdf0e10cSrcweir 
87cdf0e10cSrcweir     private:
88cdf0e10cSrcweir         HierarchicalNameCheck();                                            // never implemented
89cdf0e10cSrcweir     };
90cdf0e10cSrcweir 
91cdf0e10cSrcweir     //====================================================================
92cdf0e10cSrcweir     //= DynamicTableOrQueryNameCheck
93cdf0e10cSrcweir     //====================================================================
94cdf0e10cSrcweir     struct DynamicTableOrQueryNameCheck_Impl;
95cdf0e10cSrcweir     /** class implementing the IObjectNameCheck interface, and checking a given name
96cdf0e10cSrcweir         for being valid as either a query or a table name.
97cdf0e10cSrcweir 
98cdf0e10cSrcweir         The class can be parametrized to act as either table name or query name validator.
99cdf0e10cSrcweir 
100cdf0e10cSrcweir         For databases which support queries in queries, the name check is implicitly extended
101cdf0e10cSrcweir         to both queries and tables, no matter which category is checked. This prevents, for
102cdf0e10cSrcweir         such databases, that users can create a query with the name of an existing table,
103cdf0e10cSrcweir         or vice versa.
104cdf0e10cSrcweir 
105cdf0e10cSrcweir         @seealso dbtools::DatabaseMetaData::supportsSubqueriesInFrom
106cdf0e10cSrcweir         @seealso com::sun::star::sdb::tools::XObjectNames::checkNameForCreate
107cdf0e10cSrcweir     */
108cdf0e10cSrcweir     class DynamicTableOrQueryNameCheck  :public ::boost::noncopyable
109cdf0e10cSrcweir                                         ,public IObjectNameCheck
110cdf0e10cSrcweir     {
111cdf0e10cSrcweir     private:
112cdf0e10cSrcweir         std::auto_ptr< DynamicTableOrQueryNameCheck_Impl > m_pImpl;
113cdf0e10cSrcweir 
114cdf0e10cSrcweir     public:
115cdf0e10cSrcweir         /** constructs a DynamicTableOrQueryNameCheck instance
116cdf0e10cSrcweir         @param _rxSdbLevelConnection
117cdf0e10cSrcweir             a connection supporting the css.sdb.Connection service, in other word, it
118cdf0e10cSrcweir             does expose the XTablesSupplier and XQueriesSupplier interfaces.
119cdf0e10cSrcweir         @param _nCommandType
120cdf0e10cSrcweir             specifies whether table names or query names should be checked. Only valid values
121cdf0e10cSrcweir             are CommandType::TABLE and CommandType::QUERY.
122cdf0e10cSrcweir         @throws ::com::sun::star::lang::IllegalArgumentException
123cdf0e10cSrcweir             if the given connection is <NULL/>, or the given command type is neither
124cdf0e10cSrcweir             CommandType::TABLE nor CommandType::QUERY.
125cdf0e10cSrcweir         */
126cdf0e10cSrcweir         DynamicTableOrQueryNameCheck(
127cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxSdbLevelConnection,
128cdf0e10cSrcweir             sal_Int32 _nCommandType
129cdf0e10cSrcweir         );
130cdf0e10cSrcweir 
131cdf0e10cSrcweir         ~DynamicTableOrQueryNameCheck();
132cdf0e10cSrcweir 
133cdf0e10cSrcweir         // IObjectNameCheck overridables
134cdf0e10cSrcweir         virtual bool    isNameValid(
135cdf0e10cSrcweir             const ::rtl::OUString& _rObjectName,
136cdf0e10cSrcweir             ::dbtools::SQLExceptionInfo& _out_rErrorToDisplay
137cdf0e10cSrcweir         ) const;
138cdf0e10cSrcweir 
139cdf0e10cSrcweir     private:
140cdf0e10cSrcweir         DynamicTableOrQueryNameCheck();                                                // never implemented
141cdf0e10cSrcweir     };
142cdf0e10cSrcweir 
143cdf0e10cSrcweir //........................................................................
144cdf0e10cSrcweir } // namespace dbaui
145cdf0e10cSrcweir //........................................................................
146cdf0e10cSrcweir 
147cdf0e10cSrcweir #endif // DBACCESS_SOURCE_UI_INC_DEFAULTOBJECTNAMECHECK_HXX
148cdf0e10cSrcweir 
149