xref: /trunk/main/dbaccess/source/ui/misc/dsmeta.cxx (revision b63233d8)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
24 #include "precompiled_dbui.hxx"
25 #include "dsmeta.hxx"
26 #include <connectivity/DriversConfig.hxx>
27 #include "dsntypes.hxx"
28 #include <comphelper/processfactory.hxx>
29 /** === begin UNO includes === **/
30 /** === end UNO includes === **/
31 
32 #include <map>
33 
34 //........................................................................
35 namespace dbaui
36 {
37 //........................................................................
38 
39 	/** === begin UNO using === **/
40     using namespace dbaccess;
41     using namespace ::com::sun::star;
42 	/** === end UNO using === **/
43 
44     struct FeatureSupport
45     {
46         // authentication mode of the data source
47         AuthenticationMode      eAuthentication;
48 
FeatureSupportdbaui::FeatureSupport49         FeatureSupport()
50             :eAuthentication( AuthUserPwd )
51         {
52         }
53 
FeatureSupportdbaui::FeatureSupport54         FeatureSupport( AuthenticationMode _Auth )
55             :eAuthentication( _Auth )
56         {
57         }
58     };
59 
60     struct FeatureMapping
61     {
62         /// one of the items from dsitems.hxx
63         ItemID          nItemID;
64         const sal_Char* pAsciiFeatureName;
65     };
66 
67 	//====================================================================
68 	//= global tables
69 	//====================================================================
70 	//--------------------------------------------------------------------
lcl_getFeatureMappings()71     static const FeatureMapping* lcl_getFeatureMappings()
72     {
73         static const FeatureMapping s_aMappings[] = {
74             { DSID_AUTORETRIEVEENABLED,     "GeneratedValues" },
75             { DSID_AUTOINCREMENTVALUE,      "GeneratedValues" },
76             { DSID_AUTORETRIEVEVALUE,       "GeneratedValues" },
77             { DSID_SQL92CHECK,              "UseSQL92NamingConstraints" },
78             { DSID_APPEND_TABLE_ALIAS,      "AppendTableAliasInSelect" },
79             { DSID_AS_BEFORE_CORRNAME,      "UseKeywordAsBeforeAlias" },
80             { DSID_ENABLEOUTERJOIN,         "UseBracketedOuterJoinSyntax" },
81             { DSID_IGNOREDRIVER_PRIV,       "IgnoreDriverPrivileges" },
82             { DSID_PARAMETERNAMESUBST,      "ParameterNameSubstitution" },
83             { DSID_SUPPRESSVERSIONCL,       "DisplayVersionColumns" },
84             { DSID_CATALOG,                 "UseCatalogInSelect" },
85             { DSID_SCHEMA,                  "UseSchemaInSelect" },
86             { DSID_INDEXAPPENDIX,           "UseIndexDirectionKeyword" },
87             { DSID_DOSLINEENDS,             "UseDOSLineEnds" },
88             { DSID_BOOLEANCOMPARISON,       "BooleanComparisonMode" },
89             { DSID_CHECK_REQUIRED_FIELDS,   "FormsCheckRequiredFields" },
90             { DSID_IGNORECURRENCY,          "IgnoreCurrency" },
91             { DSID_ESCAPE_DATETIME,         "EscapeDateTime" },
92             { DSID_PRIMARY_KEY_SUPPORT,     "PrimaryKeySupport" },
93             { DSID_RESPECTRESULTSETTYPE,    "RespectDriverResultSetType" },
94             { DSID_MAX_ROW_SCAN,            "MaxRowScan" },
95             { 0, NULL }
96         };
97         return s_aMappings;
98     }
99 
100 	//--------------------------------------------------------------------
lcl_getFeatureSet(const::rtl::OUString _rURL)101     static const FeatureSet& lcl_getFeatureSet( const ::rtl::OUString _rURL )
102     {
103         typedef ::std::map< ::rtl::OUString, FeatureSet, ::comphelper::UStringLess >    FeatureSets;
104         static FeatureSets s_aFeatureSets;
105         if ( s_aFeatureSets.empty() )
106         {
107             ::connectivity::DriversConfig aDriverConfig( ::comphelper::getProcessServiceFactory() );
108             const uno::Sequence< ::rtl::OUString > aPatterns = aDriverConfig.getURLs();
109             for (   const ::rtl::OUString* pattern = aPatterns.getConstArray();
110                     pattern != aPatterns.getConstArray() + aPatterns.getLength();
111                     ++pattern
112                 )
113             {
114                 FeatureSet aCurrentSet;
115                 const ::comphelper::NamedValueCollection aCurrentFeatures( aDriverConfig.getFeatures( *pattern ).getNamedValues() );
116 
117                 const FeatureMapping* pFeatureMapping = lcl_getFeatureMappings();
118                 while ( pFeatureMapping->pAsciiFeatureName )
119                 {
120                     if ( aCurrentFeatures.has( pFeatureMapping->pAsciiFeatureName ) )
121                         aCurrentSet.put( pFeatureMapping->nItemID );
122                     ++pFeatureMapping;
123                 }
124 
125                 s_aFeatureSets[ *pattern ] = aCurrentSet;
126             }
127         }
128 
129         OSL_ENSURE( s_aFeatureSets.find( _rURL ) != s_aFeatureSets.end(), "invalid URL/pattern!" );
130         return s_aFeatureSets[ _rURL ];
131     }
132 
133 	//--------------------------------------------------------------------
getAuthenticationMode(const::rtl::OUString & _sURL)134     static AuthenticationMode getAuthenticationMode( const ::rtl::OUString& _sURL )
135     {
136         DECLARE_STL_USTRINGACCESS_MAP( FeatureSupport, Supported);
137         static Supported s_aSupport;
138         if ( s_aSupport.empty() )
139         {
140             ::connectivity::DriversConfig aDriverConfig(::comphelper::getProcessServiceFactory());
141             const uno::Sequence< ::rtl::OUString > aURLs = aDriverConfig.getURLs();
142             const ::rtl::OUString* pIter = aURLs.getConstArray();
143             const ::rtl::OUString* pEnd = pIter + aURLs.getLength();
144             for(;pIter != pEnd;++pIter)
145             {
146                 FeatureSupport aInit( AuthNone );
147                 const ::comphelper::NamedValueCollection& aMetaData = aDriverConfig.getMetaData(*pIter);
148                 if ( aMetaData.has("Authentication") )
149                 {
150                     ::rtl::OUString sAuth;
151                     aMetaData.get("Authentication") >>= sAuth;
152                     if ( sAuth.equalsAscii("UserPassword") )
153                         aInit = AuthUserPwd;
154                     else if ( sAuth.equalsAscii("Password") )
155                         aInit = AuthPwd;
156                 }
157                 s_aSupport.insert(Supported::value_type(*pIter,aInit));
158             }
159         }
160         OSL_ENSURE(s_aSupport.find(_sURL) != s_aSupport.end(),"Illegal URL!");
161         return s_aSupport[ _sURL ].eAuthentication;
162     }
163 
164 	//====================================================================
165 	//= DataSourceMetaData_Impl
166 	//====================================================================
167     class DataSourceMetaData_Impl
168     {
169     public:
170         DataSourceMetaData_Impl( const ::rtl::OUString& _sURL );
171 
getType() const172         inline ::rtl::OUString getType() const { return m_sURL; }
173 
174     private:
175         const ::rtl::OUString m_sURL;
176     };
177 
178 	//--------------------------------------------------------------------
DataSourceMetaData_Impl(const::rtl::OUString & _sURL)179     DataSourceMetaData_Impl::DataSourceMetaData_Impl( const ::rtl::OUString& _sURL )
180         :m_sURL( _sURL )
181     {
182     }
183 
184 	//====================================================================
185 	//= DataSourceMetaData
186 	//====================================================================
187 	//--------------------------------------------------------------------
DataSourceMetaData(const::rtl::OUString & _sURL)188     DataSourceMetaData::DataSourceMetaData( const ::rtl::OUString& _sURL )
189         :m_pImpl( new DataSourceMetaData_Impl( _sURL ) )
190     {
191     }
192 
193 	//--------------------------------------------------------------------
~DataSourceMetaData()194     DataSourceMetaData::~DataSourceMetaData()
195     {
196     }
197 
198 	//--------------------------------------------------------------------
getFeatureSet() const199     const FeatureSet& DataSourceMetaData::getFeatureSet() const
200     {
201         return lcl_getFeatureSet( m_pImpl->getType() );
202     }
203 
204 	//--------------------------------------------------------------------
getAuthentication(const::rtl::OUString & _sURL)205     AuthenticationMode  DataSourceMetaData::getAuthentication( const ::rtl::OUString& _sURL )
206     {
207         return getAuthenticationMode( _sURL );
208     }
209 
210 //........................................................................
211 } // namespace dbaui
212 //........................................................................
213