1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: BCatalog.cxx,v $
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
)
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);
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("%")),
93 fillNames(xResult
,aVector
);
97 m_pTables
->reFill(aVector
);
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
);
109 m_pViews
->reFill(aVector
);
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
);
120 m_pGroups
->reFill(aVector
);
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
);
132 m_pUsers
->reFill(aVector
);
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("."));
142 // -----------------------------------------------------------------------------
143 void OAdabasCatalog::correctColumnProperties(sal_Int32
/*_nPrec*/, sal_Int32
& _rnType
,::rtl::OUString
& _rsTypeName
)
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
;
154 case DataType::FLOAT
:
157 static const ::rtl::OUString
sDouble(RTL_CONSTASCII_USTRINGPARAM("DOUBLE PRECISION"));
158 _rsTypeName
= sDouble
;
159 _rnType
= DataType::DOUBLE
;
161 // else if(_nPrec > 15)
163 // static const ::rtl::OUString sReal = ::rtl::OUString::createFromAscii("REAL");
164 // _rsTypeName = sReal;
165 // _rnType = DataType::REAL;
170 // -----------------------------------------------------------------------------