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: TPrivilegesResultSet.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 "TPrivilegesResultSet.hxx"
35 using namespace connectivity
;
36 //------------------------------------------------------------------------------
37 using namespace ::com::sun::star::beans
;
38 using namespace ::com::sun::star::uno
;
39 using namespace ::com::sun::star::sdbcx
;
40 using namespace ::com::sun::star::sdbc
;
41 using namespace ::com::sun::star::container
;
42 using namespace ::com::sun::star::lang
;
43 //------------------------------------------------------------------------------
44 OResultSetPrivileges::OResultSetPrivileges( const Reference
< XDatabaseMetaData
>& _rxMeta
46 , const ::rtl::OUString
& schemaPattern
47 , const ::rtl::OUString
& tableNamePattern
)
48 : ODatabaseMetaDataResultSet(eTablePrivileges
)
49 , m_bResetValues(sal_True
)
51 osl_incrementInterlockedCount( &m_refCount
);
53 ::rtl::OUString sUserWorkingFor
;
54 static Sequence
< ::rtl::OUString
> sTableTypes
;
55 if ( sTableTypes
.getLength() == 0 )
57 // we want all catalogues, all schemas, all tables
58 sTableTypes
.realloc(3);
59 sTableTypes
[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("VIEW"));
60 sTableTypes
[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TABLE"));
61 sTableTypes
[2] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%")); // just to be sure to include anything else ....
65 m_xTables
= _rxMeta
->getTables(catalog
,schemaPattern
,tableNamePattern
,sTableTypes
);
66 m_xRow
= Reference
< XRow
>(m_xTables
,UNO_QUERY
);
68 sUserWorkingFor
= _rxMeta
->getUserName();
74 ODatabaseMetaDataResultSet::ORows aRows
;
75 static ODatabaseMetaDataResultSet::ORow
aRow(8);
76 aRow
[5] = new ORowSetValueDecorator(sUserWorkingFor
);
77 aRow
[6] = ODatabaseMetaDataResultSet::getSelectValue();
78 aRow
[7] = new ORowSetValueDecorator(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("YES")));
79 aRows
.push_back(aRow
);
80 aRow
[6] = ODatabaseMetaDataResultSet::getInsertValue();
81 aRows
.push_back(aRow
);
82 aRow
[6] = ODatabaseMetaDataResultSet::getDeleteValue();
83 aRows
.push_back(aRow
);
84 aRow
[6] = ODatabaseMetaDataResultSet::getUpdateValue();
85 aRows
.push_back(aRow
);
86 aRow
[6] = ODatabaseMetaDataResultSet::getCreateValue();
87 aRows
.push_back(aRow
);
88 aRow
[6] = ODatabaseMetaDataResultSet::getReadValue();
89 aRows
.push_back(aRow
);
90 aRow
[6] = ODatabaseMetaDataResultSet::getAlterValue();
91 aRows
.push_back(aRow
);
92 aRow
[6] = ODatabaseMetaDataResultSet::getDropValue();
93 aRows
.push_back(aRow
);
94 aRow
[6] = new ORowSetValueDecorator(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("REFERENCE")));
95 aRows
.push_back(aRow
);
99 osl_decrementInterlockedCount( &m_refCount
);
101 //------------------------------------------------------------------------------
102 const ORowSetValue
& OResultSetPrivileges::getValue(sal_Int32 columnIndex
)
109 if ( m_xRow
.is() && m_bResetValues
)
111 (*m_aRowsIter
)[1] = new ORowSetValueDecorator(m_xRow
->getString(1));
112 if ( m_xRow
->wasNull() )
113 (*m_aRowsIter
)[1]->setNull();
114 (*m_aRowsIter
)[2] = new ORowSetValueDecorator(m_xRow
->getString(2));
115 if ( m_xRow
->wasNull() )
116 (*m_aRowsIter
)[2]->setNull();
117 (*m_aRowsIter
)[3] = new ORowSetValueDecorator(m_xRow
->getString(3));
118 if ( m_xRow
->wasNull() )
119 (*m_aRowsIter
)[3]->setNull();
121 m_bResetValues
= sal_False
;
124 return ODatabaseMetaDataResultSet::getValue(columnIndex
);
126 // -----------------------------------------------------------------------------
127 void SAL_CALL
OResultSetPrivileges::disposing(void)
129 ODatabaseMetaDataResultSet::disposing();
133 // -----------------------------------------------------------------------------
134 sal_Bool SAL_CALL
OResultSetPrivileges::next( ) throw(SQLException
, RuntimeException
)
136 ::osl::MutexGuard
aGuard( m_aMutex
);
137 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper
.bDisposed
);
139 sal_Bool bReturn
= sal_False
;
140 if ( m_xTables
.is() )
144 m_bResetValues
= sal_True
;
145 if ( !m_xTables
->next() )
149 bReturn
= ODatabaseMetaDataResultSet::next();
153 m_bResetValues
= bReturn
= m_xTables
->next();
158 // -----------------------------------------------------------------------------