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 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_connectivity.hxx"
26 
27 #include "MacabCatalog.hxx"
28 #include "MacabConnection.hxx"
29 #include "MacabTables.hxx"
30 
31 using namespace connectivity::macab;
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::beans;
34 using namespace ::com::sun::star::sdbcx;
35 using namespace ::com::sun::star::sdbc;
36 using namespace ::com::sun::star::container;
37 using namespace ::com::sun::star::lang;
38 using namespace ::cppu;
39 
40 // -------------------------------------------------------------------------
MacabCatalog(MacabConnection * _pCon)41 MacabCatalog::MacabCatalog(MacabConnection* _pCon)
42 		: connectivity::sdbcx::OCatalog(_pCon),
43 		  m_pConnection(_pCon),
44 		  m_xMetaData(m_pConnection->getMetaData())
45 {
46 }
47 // -------------------------------------------------------------------------
refreshTables()48 void MacabCatalog::refreshTables()
49 {
50 	TStringVector aVector;
51 	Sequence< ::rtl::OUString > aTypes(1);
52 	aTypes[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%"));
53 	Reference< XResultSet > xResult = m_xMetaData->getTables(
54 		Any(),
55 		::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("%")),
56 		::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("%")),
57 		aTypes);
58 
59 	if (xResult.is())
60 	{
61 		Reference< XRow > xRow(xResult,UNO_QUERY);
62 		::rtl::OUString aName;
63 		// const ::rtl::OUString& sDot = MacabCatalog::getDot();
64 
65 		while (xResult->next())
66 		{
67 			// aName = xRow->getString(2);
68 			// aName += sDot;
69 			aName = xRow->getString(3);
70 			aVector.push_back(aName);
71 		}
72 	}
73 	if (m_pTables)
74 		m_pTables->reFill(aVector);
75 	else
76 		m_pTables = new MacabTables(m_xMetaData,*this,m_aMutex,aVector);
77 }
78 // -------------------------------------------------------------------------
refreshViews()79 void MacabCatalog::refreshViews()
80 {
81 }
82 // -------------------------------------------------------------------------
refreshGroups()83 void MacabCatalog::refreshGroups()
84 {
85 }
86 // -------------------------------------------------------------------------
refreshUsers()87 void MacabCatalog::refreshUsers()
88 {
89 }
90 // -------------------------------------------------------------------------
getDot()91 const ::rtl::OUString& MacabCatalog::getDot()
92 {
93 	static const ::rtl::OUString sDot = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("."));
94 	return sDot;
95 }
96 // -----------------------------------------------------------------------------
97 
98 // XTablesSupplier
getTables()99 Reference< XNameAccess > SAL_CALL MacabCatalog::getTables(  ) throw(RuntimeException)
100 {
101 	::osl::MutexGuard aGuard(m_aMutex);
102 	checkDisposed(rBHelper.bDisposed);
103 
104 	try
105 	{
106 		if (!m_pTables)
107 			refreshTables();
108 	}
109 	catch( const RuntimeException& )
110 	{
111 		// allowed to leave this method
112 		throw;
113 	}
114 	catch( const Exception& )
115 	{
116 		// allowed
117 	}
118 
119 	return m_pTables;
120 }
121