1d1766043SAndrew Rist/**************************************************************
2d1766043SAndrew Rist *
3d1766043SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4d1766043SAndrew Rist * or more contributor license agreements.  See the NOTICE file
5d1766043SAndrew Rist * distributed with this work for additional information
6d1766043SAndrew Rist * regarding copyright ownership.  The ASF licenses this file
7d1766043SAndrew Rist * to you under the Apache License, Version 2.0 (the
8d1766043SAndrew Rist * "License"); you may not use this file except in compliance
9d1766043SAndrew Rist * with the License.  You may obtain a copy of the License at
10d1766043SAndrew Rist *
11d1766043SAndrew Rist *   http://www.apache.org/licenses/LICENSE-2.0
12d1766043SAndrew Rist *
13d1766043SAndrew Rist * Unless required by applicable law or agreed to in writing,
14d1766043SAndrew Rist * software distributed under the License is distributed on an
15d1766043SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16d1766043SAndrew Rist * KIND, either express or implied.  See the License for the
17d1766043SAndrew Rist * specific language governing permissions and limitations
18d1766043SAndrew Rist * under the License.
19d1766043SAndrew Rist *
20d1766043SAndrew Rist *************************************************************/
21d1766043SAndrew Rist
22d1766043SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir#ifndef __com_sun_star_sdb_tools_XObjectNames_idl__
25cdf0e10cSrcweir#define __com_sun_star_sdb_tools_XObjectNames_idl__
26cdf0e10cSrcweir
27cdf0e10cSrcweir#ifndef __com_sun_star_lang_IllegalArgumentException_idl__
28cdf0e10cSrcweir#include <com/sun/star/lang/IllegalArgumentException.idl>
29cdf0e10cSrcweir#endif
30cdf0e10cSrcweir
31cdf0e10cSrcweir#ifndef __com_sun_star_sdbc_SQLException_idl__
32cdf0e10cSrcweir#include <com/sun/star/sdbc/SQLException.idl>
33cdf0e10cSrcweir#endif
34cdf0e10cSrcweir
35cdf0e10cSrcweir//=============================================================================
36cdf0e10cSrcweirmodule com {  module sun {  module star {  module sdb { module tools {
37cdf0e10cSrcweir//=============================================================================
38cdf0e10cSrcweir
39cdf0e10cSrcweir//-----------------------------------------------------------------------------
40cdf0e10cSrcweir/** encapsulates functionality which you might find useful when writing a
41cdf0e10cSrcweir    database application which deals with query and table names.
42cdf0e10cSrcweir
43cdf0e10cSrcweir    <p>The most important task fulfilled by this instance is that it hides
44cdf0e10cSrcweir    different naming restrictions from you, which are caused by server-side
45cdf0e10cSrcweir    or client side specialities.</p>
46cdf0e10cSrcweir
47cdf0e10cSrcweir    <p>For instance, it can validate names against
48cdf0e10cSrcweir    the characters allowed in the object names of a connection. Also, it
49cdf0e10cSrcweir    relieves you from caring whether a database supports queries in a <code>SELECT</code>
50cdf0e10cSrcweir    statment's <code>FROM</code> part (known as "queries in queries"). In such
51cdf0e10cSrcweir    databases, query and table names share a common namespace, thus they must be
52cdf0e10cSrcweir    unique. Using this interface, you can easily ensure this uniqueness.</p>
53cdf0e10cSrcweir
54cdf0e10cSrcweir    <p>All of the functionality present in this interface depends on a connection,
55cdf0e10cSrcweir    thus it entry point for obtaining it is a <type scope="com::sun::star::sdb">Connection</type>
56cdf0e10cSrcweir    service.</p>
57cdf0e10cSrcweir
58cdf0e10cSrcweir    <p>The component itself does not have life-time control mechanimns, i.e. you
59cdf0e10cSrcweir    cannot explicitly dispose it (<member scope="com::sun::star::lang">XComponent::dispose</member>),
60cdf0e10cSrcweir    and you cannot be notified when it dies.<br/>
61cdf0e10cSrcweir    However, if your try to access any of its methods or attributes, after the
62cdf0e10cSrcweir    connection which was used to create it was closed, a <type scope="com::sun::star::lang">DisposedException</type>
63cdf0e10cSrcweir    will be thrown.</p>
64cdf0e10cSrcweir
65cdf0e10cSrcweir    @see XConnectionTools
66cdf0e10cSrcweir
67*c4dc0a1aSJürgen Schmidt    @since OpenOffice 2.0.4
68cdf0e10cSrcweir*/
69cdf0e10cSrcweirpublished interface XObjectNames
70cdf0e10cSrcweir{
71cdf0e10cSrcweir    /** suggests a (unique) table or query name
72cdf0e10cSrcweir
73cdf0e10cSrcweir        <p>If in the database, tables and queries share a common namespace, this will be respected
74cdf0e10cSrcweir        by this function.</p>
75cdf0e10cSrcweir
76cdf0e10cSrcweir        <p>Note that in an multi-threaded environment, the name you obtain here is not absolutely
77cdf0e10cSrcweir        guaranteed to be unique. It is unique at the very moment the function returns to you.
78cdf0e10cSrcweir        But already when you evaluate the returned value, it might not be uniquey anymore, if
79cdf0e10cSrcweir        another process or thread created a query or table with this name.</p>
80cdf0e10cSrcweir
81cdf0e10cSrcweir        <p>This implies that you cannot rely on the name's uniqueness, but you can use it as
82cdf0e10cSrcweir        first guess to present to the user. In most cases, it will still be sufficient when
83cdf0e10cSrcweir        you are actually creating the table respectively query.</p>
84cdf0e10cSrcweir
85cdf0e10cSrcweir        @param CommandType
86cdf0e10cSrcweir            specifies the <type scope="com::sun::star::sdb">CommandType</type> of the object for which
87cdf0e10cSrcweir            a unique name is to be generated. Must be either <member scope="com::sun::star::sdb">CommandType::TABLE</member>
88cdf0e10cSrcweir            or <member scope="com::sun::star::sdb">CommandType::QUERY</member>.
89cdf0e10cSrcweir
90cdf0e10cSrcweir        @param BaseName
91cdf0e10cSrcweir            specifies the base of the to-be-created object name. If empty, a default
92cdf0e10cSrcweir            base name will be used.
93cdf0e10cSrcweir
94cdf0e10cSrcweir        @throws com::sun::star::lang::IllegalArgumentException
95cdf0e10cSrcweir            if <arg>CommandType</arg> specifies an invalid command type.
96cdf0e10cSrcweir    */
97cdf0e10cSrcweir    string  suggestName( [in] long CommandType, [in] string BaseName )
98cdf0e10cSrcweir        raises ( com::sun::star::lang::IllegalArgumentException );
99cdf0e10cSrcweir
100cdf0e10cSrcweir    /** converts the given object name to a name which is valid in the database.
101cdf0e10cSrcweir
102cdf0e10cSrcweir        <p>The conversion takes place by converting every character which is neither
103cdf0e10cSrcweir        allowed by the SQL-92 standard, nor part of the special characters supported
104cdf0e10cSrcweir        by the database, with an underscore character (_).</p>
105cdf0e10cSrcweir
106cdf0e10cSrcweir        @see com::sun::star::sdbc::XDatabaseMetaData::getExtraNameCharacters
107cdf0e10cSrcweir    */
108cdf0e10cSrcweir    string  convertToSQLName( [in] string Name );
109cdf0e10cSrcweir
110cdf0e10cSrcweir    /** checks whether a given name is used as table respectively query name in the database.
111cdf0e10cSrcweir
112cdf0e10cSrcweir        <p>If in the database, tables and queries share a common namespace, this will be respected
113cdf0e10cSrcweir        by this function.</p>
114cdf0e10cSrcweir
115cdf0e10cSrcweir        <p>As before, the information you obtain by calling this method might be obsolete
116cdf0e10cSrcweir        in the very moment you evaluate this, in case another process or thread interferes.
117cdf0e10cSrcweir        However, it's usually sufficiently up-to-date for purpose of using it in a database
118cdf0e10cSrcweir        application driven by user interactions.</p>
119cdf0e10cSrcweir
120cdf0e10cSrcweir        @param CommandType
121cdf0e10cSrcweir            specifies the <type scope="com::sun::star::sdb">CommandType</type> of the object whose
122cdf0e10cSrcweir            name should be checked. Must be either <member scope="com::sun::star::sdb">CommandType::TABLE</member>
123cdf0e10cSrcweir            or <member scope="com::sun::star::sdb">CommandType::QUERY</member>.
124cdf0e10cSrcweir
125cdf0e10cSrcweir        @param Name
126cdf0e10cSrcweir            specifies the to-be-checked name of the object.
127cdf0e10cSrcweir
128cdf0e10cSrcweir        @return
129cdf0e10cSrcweir            <TRUE/> if and only if the given name is legitimate as table respectively query name
130cdf0e10cSrcweir            to be used in the database.
131cdf0e10cSrcweir
132cdf0e10cSrcweir        @throws com::sun::star::lang::IllegalArgumentException
133cdf0e10cSrcweir            if <arg>CommandType</arg> specifies an invalid command type.
134cdf0e10cSrcweir
135cdf0e10cSrcweir        @see checkNameIsUsed
136cdf0e10cSrcweir    */
137cdf0e10cSrcweir    boolean isNameUsed( [in] long CommandType, [in] string Name )
138cdf0e10cSrcweir        raises ( com::sun::star::lang::IllegalArgumentException );
139cdf0e10cSrcweir
140cdf0e10cSrcweir    /** checks whether a given name is valid as table or query name
141cdf0e10cSrcweir
142cdf0e10cSrcweir        <p>For tables, the name must consist of characters allowed by the SQL-92 standard,
143cdf0e10cSrcweir        plus characters allowed by the connection as extra name characters.</p>
144cdf0e10cSrcweir
145cdf0e10cSrcweir        <p>For queries, names are nearly arbitrary, except that usual quoting characters
146cdf0e10cSrcweir        must not be part of the name.</p>
147cdf0e10cSrcweir
148cdf0e10cSrcweir        @see com::sun::star::sdbc::XDatabaseMetaData::getExtraNameCharacters
149cdf0e10cSrcweir    */
150cdf0e10cSrcweir    boolean isNameValid( [in] long CommandType, [in] string Name )
151cdf0e10cSrcweir        raises ( com::sun::star::lang::IllegalArgumentException );
152cdf0e10cSrcweir
153cdf0e10cSrcweir    /** checks whether a given name is allowed for a to-be-created table or query in the
154cdf0e10cSrcweir        database.
155cdf0e10cSrcweir
156cdf0e10cSrcweir        <p>This method basically does the same checks as <member>isNameUsed</member> and
157cdf0e10cSrcweir        <member>isNameValid</member>. In case the given name is not allowed, it throws an
158cdf0e10cSrcweir        exception. This error can be presented to the user, to give it a common experience
159cdf0e10cSrcweir        in all cases where he's required to enter an object name.</p>
160cdf0e10cSrcweir
161cdf0e10cSrcweir        @see isNameUsed
162cdf0e10cSrcweir        @see isNameValid
163cdf0e10cSrcweir        @see com::sun::star::sdb::ErrorMessageDialog
164cdf0e10cSrcweir        @see com::sun::star::sdb::InteractionHandler
165cdf0e10cSrcweir    */
166cdf0e10cSrcweir    void    checkNameForCreate( [in] long CommandType, [in] string Name )
167cdf0e10cSrcweir            raises ( com::sun::star::sdbc::SQLException );
168cdf0e10cSrcweir};
169cdf0e10cSrcweir
170cdf0e10cSrcweir//=============================================================================
171cdf0e10cSrcweir}; }; }; }; };
172cdf0e10cSrcweir//=============================================================================
173cdf0e10cSrcweir
174cdf0e10cSrcweir#endif
175cdf0e10cSrcweir
176