xref: /AOO41X/main/connectivity/source/commontools/TPrivilegesResultSet.cxx (revision 9b5730f6ddef7eb82608ca4d31dc0d7678e652cf)
1*9b5730f6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9b5730f6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9b5730f6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9b5730f6SAndrew Rist  * distributed with this work for additional information
6*9b5730f6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9b5730f6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9b5730f6SAndrew Rist  * "License"); you may not use this file except in compliance
9*9b5730f6SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*9b5730f6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*9b5730f6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9b5730f6SAndrew Rist  * software distributed under the License is distributed on an
15*9b5730f6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9b5730f6SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9b5730f6SAndrew Rist  * specific language governing permissions and limitations
18*9b5730f6SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*9b5730f6SAndrew Rist  *************************************************************/
21*9b5730f6SAndrew Rist 
22*9b5730f6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_connectivity.hxx"
26cdf0e10cSrcweir #include "TPrivilegesResultSet.hxx"
27cdf0e10cSrcweir 
28cdf0e10cSrcweir using namespace connectivity;
29cdf0e10cSrcweir //------------------------------------------------------------------------------
30cdf0e10cSrcweir using namespace ::com::sun::star::beans;
31cdf0e10cSrcweir using namespace ::com::sun::star::uno;
32cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx;
33cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
34cdf0e10cSrcweir using namespace ::com::sun::star::container;
35cdf0e10cSrcweir using namespace ::com::sun::star::lang;
36cdf0e10cSrcweir //------------------------------------------------------------------------------
OResultSetPrivileges(const Reference<XDatabaseMetaData> & _rxMeta,const Any & catalog,const::rtl::OUString & schemaPattern,const::rtl::OUString & tableNamePattern)37cdf0e10cSrcweir OResultSetPrivileges::OResultSetPrivileges( const Reference< XDatabaseMetaData>& _rxMeta
38cdf0e10cSrcweir 										   , const Any& catalog
39cdf0e10cSrcweir 										   , const ::rtl::OUString& schemaPattern
40cdf0e10cSrcweir 										   , const ::rtl::OUString& tableNamePattern)
41cdf0e10cSrcweir 										   : ODatabaseMetaDataResultSet(eTablePrivileges)
42cdf0e10cSrcweir                                            , m_bResetValues(sal_True)
43cdf0e10cSrcweir {
44cdf0e10cSrcweir 	osl_incrementInterlockedCount( &m_refCount );
45cdf0e10cSrcweir 	{
46cdf0e10cSrcweir 		::rtl::OUString sUserWorkingFor;
47cdf0e10cSrcweir 		static Sequence< ::rtl::OUString > sTableTypes;
48cdf0e10cSrcweir 		if ( sTableTypes.getLength() == 0 )
49cdf0e10cSrcweir 		{
50cdf0e10cSrcweir 			// we want all catalogues, all schemas, all tables
51cdf0e10cSrcweir 			sTableTypes.realloc(3);
52cdf0e10cSrcweir 			sTableTypes[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("VIEW"));
53cdf0e10cSrcweir 			sTableTypes[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TABLE"));
54cdf0e10cSrcweir 			sTableTypes[2] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%"));	// just to be sure to include anything else ....
55cdf0e10cSrcweir 		}
56cdf0e10cSrcweir 		try
57cdf0e10cSrcweir 		{
58cdf0e10cSrcweir 			m_xTables = _rxMeta->getTables(catalog,schemaPattern,tableNamePattern,sTableTypes);
59cdf0e10cSrcweir 			m_xRow = Reference< XRow>(m_xTables,UNO_QUERY);
60cdf0e10cSrcweir 
61cdf0e10cSrcweir 			sUserWorkingFor = _rxMeta->getUserName();
62cdf0e10cSrcweir 		}
63cdf0e10cSrcweir 		catch(Exception&)
64cdf0e10cSrcweir 		{
65cdf0e10cSrcweir 		}
66cdf0e10cSrcweir 
67cdf0e10cSrcweir 		ODatabaseMetaDataResultSet::ORows aRows;
68cdf0e10cSrcweir 		static ODatabaseMetaDataResultSet::ORow aRow(8);
69cdf0e10cSrcweir 		aRow[5] = new ORowSetValueDecorator(sUserWorkingFor);
70cdf0e10cSrcweir 		aRow[6] = ODatabaseMetaDataResultSet::getSelectValue();
71cdf0e10cSrcweir 		aRow[7] = new ORowSetValueDecorator(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("YES")));
72cdf0e10cSrcweir 		aRows.push_back(aRow);
73cdf0e10cSrcweir 		aRow[6] = ODatabaseMetaDataResultSet::getInsertValue();
74cdf0e10cSrcweir 		aRows.push_back(aRow);
75cdf0e10cSrcweir 		aRow[6] = ODatabaseMetaDataResultSet::getDeleteValue();
76cdf0e10cSrcweir 		aRows.push_back(aRow);
77cdf0e10cSrcweir 		aRow[6] = ODatabaseMetaDataResultSet::getUpdateValue();
78cdf0e10cSrcweir 		aRows.push_back(aRow);
79cdf0e10cSrcweir 		aRow[6] = ODatabaseMetaDataResultSet::getCreateValue();
80cdf0e10cSrcweir 		aRows.push_back(aRow);
81cdf0e10cSrcweir 		aRow[6] = ODatabaseMetaDataResultSet::getReadValue();
82cdf0e10cSrcweir 		aRows.push_back(aRow);
83cdf0e10cSrcweir 		aRow[6] = ODatabaseMetaDataResultSet::getAlterValue();
84cdf0e10cSrcweir 		aRows.push_back(aRow);
85cdf0e10cSrcweir 		aRow[6] = ODatabaseMetaDataResultSet::getDropValue();
86cdf0e10cSrcweir 		aRows.push_back(aRow);
87cdf0e10cSrcweir 		aRow[6] = new ORowSetValueDecorator(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("REFERENCE")));
88cdf0e10cSrcweir 		aRows.push_back(aRow);
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 		setRows(aRows);
91cdf0e10cSrcweir 	}
92cdf0e10cSrcweir 	osl_decrementInterlockedCount( &m_refCount );
93cdf0e10cSrcweir }
94cdf0e10cSrcweir //------------------------------------------------------------------------------
getValue(sal_Int32 columnIndex)95cdf0e10cSrcweir const ORowSetValue& OResultSetPrivileges::getValue(sal_Int32 columnIndex)
96cdf0e10cSrcweir {
97cdf0e10cSrcweir 	switch(columnIndex)
98cdf0e10cSrcweir 	{
99cdf0e10cSrcweir 		case 1:
100cdf0e10cSrcweir 		case 2:
101cdf0e10cSrcweir 		case 3:
102cdf0e10cSrcweir 			if ( m_xRow.is() && m_bResetValues )
103cdf0e10cSrcweir 			{
104cdf0e10cSrcweir 				(*m_aRowsIter)[1] = new ORowSetValueDecorator(m_xRow->getString(1));
105cdf0e10cSrcweir 				if ( m_xRow->wasNull() )
106cdf0e10cSrcweir 					(*m_aRowsIter)[1]->setNull();
107cdf0e10cSrcweir 				(*m_aRowsIter)[2] = new ORowSetValueDecorator(m_xRow->getString(2));
108cdf0e10cSrcweir 				if ( m_xRow->wasNull() )
109cdf0e10cSrcweir 					(*m_aRowsIter)[2]->setNull();
110cdf0e10cSrcweir 				(*m_aRowsIter)[3] = new ORowSetValueDecorator(m_xRow->getString(3));
111cdf0e10cSrcweir 				if ( m_xRow->wasNull() )
112cdf0e10cSrcweir 					(*m_aRowsIter)[3]->setNull();
113cdf0e10cSrcweir 
114cdf0e10cSrcweir 				m_bResetValues = sal_False;
115cdf0e10cSrcweir 			}
116cdf0e10cSrcweir 	}
117cdf0e10cSrcweir 	return ODatabaseMetaDataResultSet::getValue(columnIndex);
118cdf0e10cSrcweir }
119cdf0e10cSrcweir // -----------------------------------------------------------------------------
disposing(void)120cdf0e10cSrcweir void SAL_CALL OResultSetPrivileges::disposing(void)
121cdf0e10cSrcweir {
122cdf0e10cSrcweir 	ODatabaseMetaDataResultSet::disposing();
123cdf0e10cSrcweir m_xTables.clear();
124cdf0e10cSrcweir m_xRow.clear();
125cdf0e10cSrcweir }
126cdf0e10cSrcweir // -----------------------------------------------------------------------------
next()127cdf0e10cSrcweir sal_Bool SAL_CALL OResultSetPrivileges::next(  ) throw(SQLException, RuntimeException)
128cdf0e10cSrcweir {
129cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
130cdf0e10cSrcweir 	checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed );
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 	sal_Bool bReturn = sal_False;
133cdf0e10cSrcweir 	if ( m_xTables.is() )
134cdf0e10cSrcweir 	{
135cdf0e10cSrcweir 		if ( m_bBOF )
136cdf0e10cSrcweir 		{
137cdf0e10cSrcweir 			m_bResetValues = sal_True;
138cdf0e10cSrcweir 			if ( !m_xTables->next() )
139cdf0e10cSrcweir 				return sal_False;
140cdf0e10cSrcweir 		}
141cdf0e10cSrcweir 
142cdf0e10cSrcweir         bReturn = ODatabaseMetaDataResultSet::next();
143cdf0e10cSrcweir         if ( !bReturn )
144cdf0e10cSrcweir 		{
145cdf0e10cSrcweir 			m_bBOF = sal_False;
146cdf0e10cSrcweir 			m_bResetValues = bReturn = m_xTables->next();
147cdf0e10cSrcweir 		}
148cdf0e10cSrcweir 	}
149cdf0e10cSrcweir 	return bReturn;
150cdf0e10cSrcweir }
151cdf0e10cSrcweir // -----------------------------------------------------------------------------
152