1*9b5730f6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9b5730f6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9b5730f6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9b5730f6SAndrew Rist  * distributed with this work for additional information
6*9b5730f6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9b5730f6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9b5730f6SAndrew Rist  * "License"); you may not use this file except in compliance
9*9b5730f6SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*9b5730f6SAndrew Rist  *
11*9b5730f6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*9b5730f6SAndrew Rist  *
13*9b5730f6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9b5730f6SAndrew Rist  * software distributed under the License is distributed on an
15*9b5730f6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9b5730f6SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9b5730f6SAndrew Rist  * specific language governing permissions and limitations
18*9b5730f6SAndrew Rist  * under the License.
19*9b5730f6SAndrew Rist  *
20*9b5730f6SAndrew Rist  *************************************************************/
21*9b5730f6SAndrew Rist 
22*9b5730f6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_connectivity.hxx"
26cdf0e10cSrcweir #include "adabas/BCatalog.hxx"
27cdf0e10cSrcweir #include "adabas/BConnection.hxx"
28cdf0e10cSrcweir #include "adabas/BGroups.hxx"
29cdf0e10cSrcweir #include "adabas/BUsers.hxx"
30cdf0e10cSrcweir #include "adabas/BTables.hxx"
31cdf0e10cSrcweir #include "adabas/BViews.hxx"
32cdf0e10cSrcweir #include <com/sun/star/sdbc/XRow.hpp>
33cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSet.hpp>
34cdf0e10cSrcweir #include <comphelper/types.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir 
37cdf0e10cSrcweir // -------------------------------------------------------------------------
38cdf0e10cSrcweir using namespace connectivity;
39cdf0e10cSrcweir using namespace connectivity::adabas;
40cdf0e10cSrcweir using namespace ::com::sun::star::uno;
41cdf0e10cSrcweir using namespace ::com::sun::star::beans;
42cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx;
43cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
44cdf0e10cSrcweir using namespace ::com::sun::star::container;
45cdf0e10cSrcweir using namespace ::com::sun::star::lang;
46cdf0e10cSrcweir // -----------------------------------------------------------------------------
OAdabasCatalog(SQLHANDLE _aConnectionHdl,OAdabasConnection * _pCon)47cdf0e10cSrcweir OAdabasCatalog::OAdabasCatalog(SQLHANDLE _aConnectionHdl, OAdabasConnection* _pCon) : connectivity::sdbcx::OCatalog(_pCon)
48cdf0e10cSrcweir 				,m_pConnection(_pCon)
49cdf0e10cSrcweir 				,m_aConnectionHdl(_aConnectionHdl)
50cdf0e10cSrcweir {
51cdf0e10cSrcweir }
52cdf0e10cSrcweir // -----------------------------------------------------------------------------
buildName(const Reference<XRow> & _xRow)53cdf0e10cSrcweir ::rtl::OUString OAdabasCatalog::buildName(const Reference< XRow >& _xRow)
54cdf0e10cSrcweir {
55cdf0e10cSrcweir 	::rtl::OUString sName;
56cdf0e10cSrcweir 	sName = _xRow->getString(2);
57cdf0e10cSrcweir     if ( sName.getLength() )
58cdf0e10cSrcweir         sName += OAdabasCatalog::getDot();
59cdf0e10cSrcweir 	sName += _xRow->getString(3);
60cdf0e10cSrcweir 
61cdf0e10cSrcweir 
62cdf0e10cSrcweir 	return sName;
63cdf0e10cSrcweir }
64cdf0e10cSrcweir // -----------------------------------------------------------------------------
fillVector(const::rtl::OUString & _sQuery,TStringVector & _rVector)65cdf0e10cSrcweir void OAdabasCatalog::fillVector(const ::rtl::OUString& _sQuery,TStringVector& _rVector)
66cdf0e10cSrcweir {
67cdf0e10cSrcweir     Reference< XStatement > xStmt = m_pConnection->createStatement(  );
68cdf0e10cSrcweir     OSL_ENSURE(xStmt.is(),"OAdabasCatalog::fillVector: Could not create a statement!");
69cdf0e10cSrcweir 	Reference< XResultSet > xResult = xStmt->executeQuery(_sQuery);
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 	fillNames(xResult,_rVector);
72cdf0e10cSrcweir 	::comphelper::disposeComponent(xStmt);
73cdf0e10cSrcweir 
74cdf0e10cSrcweir }
75cdf0e10cSrcweir // -------------------------------------------------------------------------
refreshTables()76cdf0e10cSrcweir void OAdabasCatalog::refreshTables()
77cdf0e10cSrcweir {
78cdf0e10cSrcweir 	TStringVector aVector;
79cdf0e10cSrcweir 	{
80cdf0e10cSrcweir 		Sequence< ::rtl::OUString > aTypes(1);
81cdf0e10cSrcweir 		aTypes[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%"));
82cdf0e10cSrcweir 		Reference< XResultSet > xResult = m_xMetaData->getTables(Any(),
83cdf0e10cSrcweir 																::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%")),
84cdf0e10cSrcweir 																::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%")),
85cdf0e10cSrcweir 																aTypes);
86cdf0e10cSrcweir 		fillNames(xResult,aVector);
87cdf0e10cSrcweir 	}
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 	if(m_pTables)
90cdf0e10cSrcweir 		m_pTables->reFill(aVector);
91cdf0e10cSrcweir 	else
92cdf0e10cSrcweir 		m_pTables = new OTables(m_xMetaData,*this,m_aMutex,aVector);
93cdf0e10cSrcweir }
94cdf0e10cSrcweir // -------------------------------------------------------------------------
refreshViews()95cdf0e10cSrcweir void OAdabasCatalog::refreshViews()
96cdf0e10cSrcweir {
97cdf0e10cSrcweir 	TStringVector aVector;
98cdf0e10cSrcweir     static const ::rtl::OUString s_sView(RTL_CONSTASCII_USTRINGPARAM("SELECT DISTINCT NULL,DOMAIN.VIEWDEFS.OWNER, DOMAIN.VIEWDEFS.VIEWNAME FROM DOMAIN.VIEWDEFS"));
99cdf0e10cSrcweir 	fillVector(s_sView,aVector);
100cdf0e10cSrcweir 
101cdf0e10cSrcweir 	if(m_pViews)
102cdf0e10cSrcweir 		m_pViews->reFill(aVector);
103cdf0e10cSrcweir 	else
104cdf0e10cSrcweir 		m_pViews = new OViews(m_xMetaData,*this,m_aMutex,aVector);
105cdf0e10cSrcweir }
106cdf0e10cSrcweir // -------------------------------------------------------------------------
refreshGroups()107cdf0e10cSrcweir void OAdabasCatalog::refreshGroups()
108cdf0e10cSrcweir {
109cdf0e10cSrcweir 	TStringVector aVector;
110cdf0e10cSrcweir     static const ::rtl::OUString s_sGroup(RTL_CONSTASCII_USTRINGPARAM("SELECT DISTINCT NULL,NULL,GROUPNAME FROM DOMAIN.USERS WHERE GROUPNAME IS NOT NULL AND GROUPNAME <> ' '"));
111cdf0e10cSrcweir     fillVector(s_sGroup,aVector);
112cdf0e10cSrcweir 	if(m_pGroups)
113cdf0e10cSrcweir 		m_pGroups->reFill(aVector);
114cdf0e10cSrcweir 	else
115cdf0e10cSrcweir 		m_pGroups = new OGroups(*this,m_aMutex,aVector,m_pConnection,this);
116cdf0e10cSrcweir }
117cdf0e10cSrcweir // -------------------------------------------------------------------------
refreshUsers()118cdf0e10cSrcweir void OAdabasCatalog::refreshUsers()
119cdf0e10cSrcweir {
120cdf0e10cSrcweir 	TStringVector aVector;
121cdf0e10cSrcweir     static const ::rtl::OUString s_sUsers(RTL_CONSTASCII_USTRINGPARAM("SELECT DISTINCT NULL,NULL,USERNAME FROM DOMAIN.USERS WHERE USERNAME IS NOT NULL AND USERNAME <> ' ' AND USERNAME <> 'CONTROL'"));
122cdf0e10cSrcweir     fillVector(s_sUsers,aVector);
123cdf0e10cSrcweir 
124cdf0e10cSrcweir 	if(m_pUsers)
125cdf0e10cSrcweir 		m_pUsers->reFill(aVector);
126cdf0e10cSrcweir 	else
127cdf0e10cSrcweir 		m_pUsers = new OUsers(*this,m_aMutex,aVector,m_pConnection,this);
128cdf0e10cSrcweir }
129cdf0e10cSrcweir // -------------------------------------------------------------------------
getDot()130cdf0e10cSrcweir const ::rtl::OUString& OAdabasCatalog::getDot()
131cdf0e10cSrcweir {
132cdf0e10cSrcweir 	static const ::rtl::OUString sDot(RTL_CONSTASCII_USTRINGPARAM("."));
133cdf0e10cSrcweir 	return sDot;
134cdf0e10cSrcweir }
135cdf0e10cSrcweir // -----------------------------------------------------------------------------
correctColumnProperties(sal_Int32,sal_Int32 & _rnType,::rtl::OUString & _rsTypeName)136cdf0e10cSrcweir void OAdabasCatalog::correctColumnProperties(sal_Int32 /*_nPrec*/, sal_Int32& _rnType,::rtl::OUString& _rsTypeName)
137cdf0e10cSrcweir {
138cdf0e10cSrcweir 	switch(_rnType)
139cdf0e10cSrcweir 	{
140cdf0e10cSrcweir 	case DataType::DECIMAL:
141cdf0e10cSrcweir 		{
142cdf0e10cSrcweir             static const ::rtl::OUString sDecimal(RTL_CONSTASCII_USTRINGPARAM("DECIMAL"));
143cdf0e10cSrcweir 			if(_rnType == DataType::DECIMAL && _rsTypeName == sDecimal)
144cdf0e10cSrcweir 				_rnType = DataType::NUMERIC;
145cdf0e10cSrcweir 		}
146cdf0e10cSrcweir 		break;
147cdf0e10cSrcweir 	case DataType::FLOAT:
148cdf0e10cSrcweir 		//	if(_nPrec >= 16)
149cdf0e10cSrcweir 		{
150cdf0e10cSrcweir 			static const ::rtl::OUString sDouble(RTL_CONSTASCII_USTRINGPARAM("DOUBLE PRECISION"));
151cdf0e10cSrcweir 			_rsTypeName = sDouble;
152cdf0e10cSrcweir 			_rnType = DataType::DOUBLE;
153cdf0e10cSrcweir 		}
154cdf0e10cSrcweir //		else if(_nPrec > 15)
155cdf0e10cSrcweir //		{
156cdf0e10cSrcweir //			static const ::rtl::OUString sReal = ::rtl::OUString::createFromAscii("REAL");
157cdf0e10cSrcweir //			_rsTypeName = sReal;
158cdf0e10cSrcweir //			_rnType = DataType::REAL;
159cdf0e10cSrcweir //		}
160cdf0e10cSrcweir 		break;
161cdf0e10cSrcweir 	}
162cdf0e10cSrcweir }
163cdf0e10cSrcweir // -----------------------------------------------------------------------------
164cdf0e10cSrcweir 
165