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 #include "connectivity/sdbcx/VCatalog.hxx"
27 #include "connectivity/sdbcx/VCollection.hxx"
28 #include <com/sun/star/lang/DisposedException.hpp>
29 #include "connectivity/sdbcx/VCollection.hxx"
30 #include "connectivity/sdbcx/VDescriptor.hxx"
31 #include "TConnection.hxx"
32 #include <comphelper/uno3.hxx>
33 #include "connectivity/dbtools.hxx"
34 
35 using namespace connectivity;
36 using namespace connectivity::sdbcx;
37 using namespace ::com::sun::star::beans;
38 using namespace ::com::sun::star::uno;
39 using namespace ::com::sun::star::sdbc;
40 using namespace ::com::sun::star::sdbcx;
41 using namespace ::com::sun::star::container;
42 using namespace ::com::sun::star::lang;
43 //------------------------------------------------------------------------------
44 IMPLEMENT_SERVICE_INFO(OCatalog,"com.sun.star.comp.connectivity.OCatalog","com.sun.star.sdbcx.DatabaseDefinition")
45 //------------------------------------------------------------------------------
OCatalog(const Reference<XConnection> & _xConnection)46 OCatalog::OCatalog(const Reference< XConnection> &_xConnection) : OCatalog_BASE(m_aMutex)
47 			,connectivity::OSubComponent<OCatalog, OCatalog_BASE>(_xConnection, this)
48 			,m_pTables(NULL)
49 			,m_pViews(NULL)
50 			,m_pGroups(NULL)
51 			,m_pUsers(NULL)
52 {
53 	try
54 	{
55 		m_xMetaData = _xConnection->getMetaData();
56 	}
57 	catch(const Exception&)
58 	{
59 		OSL_ENSURE(0,"No Metadata available!");
60 	}
61 }
62 //-----------------------------------------------------------------------------
~OCatalog()63 OCatalog::~OCatalog()
64 {
65 	delete m_pTables;
66 	delete m_pViews;
67 	delete m_pGroups;
68 	delete m_pUsers;
69 }
70 //-----------------------------------------------------------------------------
acquire()71 void SAL_CALL OCatalog::acquire() throw()
72 {
73 	OCatalog_BASE::acquire();
74 }
75 //------------------------------------------------------------------------------
release()76 void SAL_CALL OCatalog::release() throw()
77 {
78 	relase_ChildImpl();
79 }
80 
81 //------------------------------------------------------------------------------
disposing()82 void SAL_CALL OCatalog::disposing()
83 {
84 	::osl::MutexGuard aGuard(m_aMutex);
85 
86 	if(m_pTables)
87 		m_pTables->disposing();
88 	if(m_pViews)
89 		m_pViews->disposing();
90 	if(m_pGroups)
91 		m_pGroups->disposing();
92 	if(m_pUsers)
93 		m_pUsers->disposing();
94 
95 	dispose_ChildImpl();
96 	OCatalog_BASE::disposing();
97 }
98 //------------------------------------------------------------------------------
99 // XTablesSupplier
getTables()100 Reference< XNameAccess > SAL_CALL OCatalog::getTables(  ) throw(RuntimeException)
101 {
102 	::osl::MutexGuard aGuard(m_aMutex);
103 	checkDisposed(OCatalog_BASE::rBHelper.bDisposed);
104 
105 	try
106 	{
107 		if(!m_pTables)
108 			refreshTables();
109 	}
110 	catch( const RuntimeException& )
111 	{
112 		// allowed to leave this method
113 		throw;
114 	}
115 	catch( const Exception& )
116 	{
117 		// allowed
118 	}
119 
120 	return const_cast<OCatalog*>(this)->m_pTables;
121 }
122 // -------------------------------------------------------------------------
123 // XViewsSupplier
getViews()124 Reference< XNameAccess > SAL_CALL OCatalog::getViews(  ) throw(RuntimeException)
125 {
126 	::osl::MutexGuard aGuard(m_aMutex);
127 	checkDisposed(OCatalog_BASE::rBHelper.bDisposed);
128 
129 	try
130 	{
131 		if(!m_pViews)
132 			refreshViews();
133 	}
134 	catch( const RuntimeException& )
135 	{
136 		// allowed to leave this method
137 		throw;
138 	}
139 	catch( const Exception& )
140 	{
141 		// allowed
142 	}
143 
144 	return const_cast<OCatalog*>(this)->m_pViews;
145 }
146 // -------------------------------------------------------------------------
147 // XUsersSupplier
getUsers()148 Reference< XNameAccess > SAL_CALL OCatalog::getUsers(  ) throw(RuntimeException)
149 {
150 	::osl::MutexGuard aGuard(m_aMutex);
151 	checkDisposed(OCatalog_BASE::rBHelper.bDisposed);
152 
153 	try
154 	{
155 		if(!m_pUsers)
156 			refreshUsers();
157 	}
158 	catch( const RuntimeException& )
159 	{
160 		// allowed to leave this method
161 		throw;
162 	}
163 	catch( const Exception& )
164 	{
165 		// allowed
166 	}
167 
168 	return const_cast<OCatalog*>(this)->m_pUsers;
169 }
170 // -------------------------------------------------------------------------
171 // XGroupsSupplier
getGroups()172 Reference< XNameAccess > SAL_CALL OCatalog::getGroups(  ) throw(RuntimeException)
173 {
174 	::osl::MutexGuard aGuard(m_aMutex);
175 	checkDisposed(OCatalog_BASE::rBHelper.bDisposed);
176 
177 	try
178 	{
179 		if(!m_pGroups)
180 			refreshGroups();
181 	}
182 	catch( const RuntimeException& )
183 	{
184 		// allowed to leave this method
185 		throw;
186 	}
187 	catch( const Exception& )
188 	{
189 		// allowed
190 	}
191 
192 	return const_cast<OCatalog*>(this)->m_pGroups;
193 }
194 // -----------------------------------------------------------------------------
buildName(const Reference<XRow> & _xRow)195 ::rtl::OUString OCatalog::buildName(const Reference< XRow >& _xRow)
196 {
197 	::rtl::OUString sCatalog = _xRow->getString(1);
198 	if ( _xRow->wasNull() )
199 		sCatalog = ::rtl::OUString();
200 	::rtl::OUString sSchema = _xRow->getString(2);
201 	if ( _xRow->wasNull() )
202 		sSchema = ::rtl::OUString();
203 	::rtl::OUString sTable = _xRow->getString(3);
204 	if ( _xRow->wasNull() )
205 		sTable = ::rtl::OUString();
206 
207 	::rtl::OUString sComposedName(
208 		::dbtools::composeTableName( m_xMetaData, sCatalog, sSchema, sTable, sal_False, ::dbtools::eInDataManipulation ) );
209 	return sComposedName;
210 }
211 // -----------------------------------------------------------------------------
fillNames(Reference<XResultSet> & _xResult,TStringVector & _rNames)212 void OCatalog::fillNames(Reference< XResultSet >& _xResult,TStringVector& _rNames)
213 {
214 	if ( _xResult.is() )
215 	{
216 		_rNames.reserve(20);
217 		Reference< XRow > xRow(_xResult,UNO_QUERY);
218 		while ( _xResult->next() )
219 		{
220 			_rNames.push_back( buildName(xRow) );
221 		}
222 		xRow.clear();
223 		::comphelper::disposeComponent(_xResult);
224 	}
225 }
226 // -------------------------------------------------------------------------
construct()227 void ODescriptor::construct()
228 {
229 	sal_Int32 nAttrib = isNew() ? 0 : ::com::sun::star::beans::PropertyAttribute::READONLY;
230 	registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME), PROPERTY_ID_NAME ,nAttrib,&m_Name,::getCppuType(static_cast< ::rtl::OUString*>(NULL)));
231 }
232 // -------------------------------------------------------------------------
~ODescriptor()233 ODescriptor::~ODescriptor()
234 {
235 }
236 // -----------------------------------------------------------------------------
237