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