xref: /trunk/main/connectivity/source/commontools/TPrivilegesResultSet.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 "TPrivilegesResultSet.hxx"
31 
32 using namespace connectivity;
33 //------------------------------------------------------------------------------
34 using namespace ::com::sun::star::beans;
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::sdbcx;
37 using namespace ::com::sun::star::sdbc;
38 using namespace ::com::sun::star::container;
39 using namespace ::com::sun::star::lang;
40 //------------------------------------------------------------------------------
41 OResultSetPrivileges::OResultSetPrivileges( const Reference< XDatabaseMetaData>& _rxMeta
42                                            , const Any& catalog
43                                            , const ::rtl::OUString& schemaPattern
44                                            , const ::rtl::OUString& tableNamePattern)
45                                            : ODatabaseMetaDataResultSet(eTablePrivileges)
46                                            , m_bResetValues(sal_True)
47 {
48     osl_incrementInterlockedCount( &m_refCount );
49     {
50         ::rtl::OUString sUserWorkingFor;
51         static Sequence< ::rtl::OUString > sTableTypes;
52         if ( sTableTypes.getLength() == 0 )
53         {
54             // we want all catalogues, all schemas, all tables
55             sTableTypes.realloc(3);
56             sTableTypes[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("VIEW"));
57             sTableTypes[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TABLE"));
58             sTableTypes[2] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%")); // just to be sure to include anything else ....
59         }
60         try
61         {
62             m_xTables = _rxMeta->getTables(catalog,schemaPattern,tableNamePattern,sTableTypes);
63             m_xRow = Reference< XRow>(m_xTables,UNO_QUERY);
64 
65             sUserWorkingFor = _rxMeta->getUserName();
66         }
67         catch(Exception&)
68         {
69         }
70 
71         ODatabaseMetaDataResultSet::ORows aRows;
72         static ODatabaseMetaDataResultSet::ORow aRow(8);
73         aRow[5] = new ORowSetValueDecorator(sUserWorkingFor);
74         aRow[6] = ODatabaseMetaDataResultSet::getSelectValue();
75         aRow[7] = new ORowSetValueDecorator(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("YES")));
76         aRows.push_back(aRow);
77         aRow[6] = ODatabaseMetaDataResultSet::getInsertValue();
78         aRows.push_back(aRow);
79         aRow[6] = ODatabaseMetaDataResultSet::getDeleteValue();
80         aRows.push_back(aRow);
81         aRow[6] = ODatabaseMetaDataResultSet::getUpdateValue();
82         aRows.push_back(aRow);
83         aRow[6] = ODatabaseMetaDataResultSet::getCreateValue();
84         aRows.push_back(aRow);
85         aRow[6] = ODatabaseMetaDataResultSet::getReadValue();
86         aRows.push_back(aRow);
87         aRow[6] = ODatabaseMetaDataResultSet::getAlterValue();
88         aRows.push_back(aRow);
89         aRow[6] = ODatabaseMetaDataResultSet::getDropValue();
90         aRows.push_back(aRow);
91         aRow[6] = new ORowSetValueDecorator(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("REFERENCE")));
92         aRows.push_back(aRow);
93 
94         setRows(aRows);
95     }
96     osl_decrementInterlockedCount( &m_refCount );
97 }
98 //------------------------------------------------------------------------------
99 const ORowSetValue& OResultSetPrivileges::getValue(sal_Int32 columnIndex)
100 {
101     switch(columnIndex)
102     {
103         case 1:
104         case 2:
105         case 3:
106             if ( m_xRow.is() && m_bResetValues )
107             {
108                 (*m_aRowsIter)[1] = new ORowSetValueDecorator(m_xRow->getString(1));
109                 if ( m_xRow->wasNull() )
110                     (*m_aRowsIter)[1]->setNull();
111                 (*m_aRowsIter)[2] = new ORowSetValueDecorator(m_xRow->getString(2));
112                 if ( m_xRow->wasNull() )
113                     (*m_aRowsIter)[2]->setNull();
114                 (*m_aRowsIter)[3] = new ORowSetValueDecorator(m_xRow->getString(3));
115                 if ( m_xRow->wasNull() )
116                     (*m_aRowsIter)[3]->setNull();
117 
118                 m_bResetValues = sal_False;
119             }
120     }
121     return ODatabaseMetaDataResultSet::getValue(columnIndex);
122 }
123 // -----------------------------------------------------------------------------
124 void SAL_CALL OResultSetPrivileges::disposing(void)
125 {
126     ODatabaseMetaDataResultSet::disposing();
127 m_xTables.clear();
128 m_xRow.clear();
129 }
130 // -----------------------------------------------------------------------------
131 sal_Bool SAL_CALL OResultSetPrivileges::next(  ) throw(SQLException, RuntimeException)
132 {
133     ::osl::MutexGuard aGuard( m_aMutex );
134     checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed );
135 
136     sal_Bool bReturn = sal_False;
137     if ( m_xTables.is() )
138     {
139         if ( m_bBOF )
140         {
141             m_bResetValues = sal_True;
142             if ( !m_xTables->next() )
143                 return sal_False;
144         }
145 
146         bReturn = ODatabaseMetaDataResultSet::next();
147         if ( !bReturn )
148         {
149             m_bBOF = sal_False;
150             m_bResetValues = bReturn = m_xTables->next();
151         }
152     }
153     return bReturn;
154 }
155 // -----------------------------------------------------------------------------
156