update dev300-m58
[ooovba.git] / connectivity / source / drivers / adabas / BCatalog.cxx
blob22fbe61f4f20260644cda63fa3d3945f21cc8cfb
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: BCatalog.cxx,v $
10 * $Revision: 1.16 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
33 #include "adabas/BCatalog.hxx"
34 #include "adabas/BConnection.hxx"
35 #include "adabas/BGroups.hxx"
36 #include "adabas/BUsers.hxx"
37 #include "adabas/BTables.hxx"
38 #include "adabas/BViews.hxx"
39 #include <com/sun/star/sdbc/XRow.hpp>
40 #include <com/sun/star/sdbc/XResultSet.hpp>
41 #include <comphelper/types.hxx>
44 // -------------------------------------------------------------------------
45 using namespace connectivity;
46 using namespace connectivity::adabas;
47 using namespace ::com::sun::star::uno;
48 using namespace ::com::sun::star::beans;
49 using namespace ::com::sun::star::sdbcx;
50 using namespace ::com::sun::star::sdbc;
51 using namespace ::com::sun::star::container;
52 using namespace ::com::sun::star::lang;
53 // -----------------------------------------------------------------------------
54 OAdabasCatalog::OAdabasCatalog(SQLHANDLE _aConnectionHdl, OAdabasConnection* _pCon) : connectivity::sdbcx::OCatalog(_pCon)
55 ,m_pConnection(_pCon)
56 ,m_aConnectionHdl(_aConnectionHdl)
59 // -----------------------------------------------------------------------------
60 ::rtl::OUString OAdabasCatalog::buildName(const Reference< XRow >& _xRow)
62 ::rtl::OUString sName;
63 sName = _xRow->getString(2);
64 if ( sName.getLength() )
65 sName += OAdabasCatalog::getDot();
66 sName += _xRow->getString(3);
69 return sName;
71 // -----------------------------------------------------------------------------
72 void OAdabasCatalog::fillVector(const ::rtl::OUString& _sQuery,TStringVector& _rVector)
74 Reference< XStatement > xStmt = m_pConnection->createStatement( );
75 OSL_ENSURE(xStmt.is(),"OAdabasCatalog::fillVector: Could not create a statement!");
76 Reference< XResultSet > xResult = xStmt->executeQuery(_sQuery);
78 fillNames(xResult,_rVector);
79 ::comphelper::disposeComponent(xStmt);
82 // -------------------------------------------------------------------------
83 void OAdabasCatalog::refreshTables()
85 TStringVector aVector;
87 Sequence< ::rtl::OUString > aTypes(1);
88 aTypes[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%"));
89 Reference< XResultSet > xResult = m_xMetaData->getTables(Any(),
90 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%")),
91 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%")),
92 aTypes);
93 fillNames(xResult,aVector);
96 if(m_pTables)
97 m_pTables->reFill(aVector);
98 else
99 m_pTables = new OTables(m_xMetaData,*this,m_aMutex,aVector);
101 // -------------------------------------------------------------------------
102 void OAdabasCatalog::refreshViews()
104 TStringVector aVector;
105 static const ::rtl::OUString s_sView(RTL_CONSTASCII_USTRINGPARAM("SELECT DISTINCT NULL,DOMAIN.VIEWDEFS.OWNER, DOMAIN.VIEWDEFS.VIEWNAME FROM DOMAIN.VIEWDEFS"));
106 fillVector(s_sView,aVector);
108 if(m_pViews)
109 m_pViews->reFill(aVector);
110 else
111 m_pViews = new OViews(m_xMetaData,*this,m_aMutex,aVector);
113 // -------------------------------------------------------------------------
114 void OAdabasCatalog::refreshGroups()
116 TStringVector aVector;
117 static const ::rtl::OUString s_sGroup(RTL_CONSTASCII_USTRINGPARAM("SELECT DISTINCT NULL,NULL,GROUPNAME FROM DOMAIN.USERS WHERE GROUPNAME IS NOT NULL AND GROUPNAME <> ' '"));
118 fillVector(s_sGroup,aVector);
119 if(m_pGroups)
120 m_pGroups->reFill(aVector);
121 else
122 m_pGroups = new OGroups(*this,m_aMutex,aVector,m_pConnection,this);
124 // -------------------------------------------------------------------------
125 void OAdabasCatalog::refreshUsers()
127 TStringVector aVector;
128 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'"));
129 fillVector(s_sUsers,aVector);
131 if(m_pUsers)
132 m_pUsers->reFill(aVector);
133 else
134 m_pUsers = new OUsers(*this,m_aMutex,aVector,m_pConnection,this);
136 // -------------------------------------------------------------------------
137 const ::rtl::OUString& OAdabasCatalog::getDot()
139 static const ::rtl::OUString sDot(RTL_CONSTASCII_USTRINGPARAM("."));
140 return sDot;
142 // -----------------------------------------------------------------------------
143 void OAdabasCatalog::correctColumnProperties(sal_Int32 /*_nPrec*/, sal_Int32& _rnType,::rtl::OUString& _rsTypeName)
145 switch(_rnType)
147 case DataType::DECIMAL:
149 static const ::rtl::OUString sDecimal(RTL_CONSTASCII_USTRINGPARAM("DECIMAL"));
150 if(_rnType == DataType::DECIMAL && _rsTypeName == sDecimal)
151 _rnType = DataType::NUMERIC;
153 break;
154 case DataType::FLOAT:
155 // if(_nPrec >= 16)
157 static const ::rtl::OUString sDouble(RTL_CONSTASCII_USTRINGPARAM("DOUBLE PRECISION"));
158 _rsTypeName = sDouble;
159 _rnType = DataType::DOUBLE;
161 // else if(_nPrec > 15)
162 // {
163 // static const ::rtl::OUString sReal = ::rtl::OUString::createFromAscii("REAL");
164 // _rsTypeName = sReal;
165 // _rnType = DataType::REAL;
166 // }
167 break;
170 // -----------------------------------------------------------------------------