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 <com/sun/star/sdbcx/CompareBookmark.hpp>
31 #include <com/sun/star/sdbcx/XDeleteRows.hpp>
32 #include "flat/EResultSet.hxx"
33 #include <com/sun/star/lang/DisposedException.hpp>
34 #include <comphelper/sequence.hxx>
35 #include <comphelper/types.hxx>
36 
37 using namespace ::comphelper;
38 
39 using namespace connectivity::flat;
40 using namespace connectivity::file;
41 using namespace ::cppu;
42 using namespace com::sun::star::uno;
43 using namespace com::sun::star::lang;
44 using namespace com::sun::star::beans;
45 using namespace com::sun::star::sdbc;
46 using namespace com::sun::star::sdbcx;
47 //	using namespace com::sun::star::container;
48 //	using namespace com::sun::star::util;
49 //------------------------------------------------------------------------------
50 OFlatResultSet::OFlatResultSet( OStatement_Base* pStmt,connectivity::OSQLParseTreeIterator&	_aSQLIterator)
51 				: file::OResultSet(pStmt,_aSQLIterator)
52 				,m_bBookmarkable(sal_True)
53 {
54 	registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISBOOKMARKABLE),         PROPERTY_ID_ISBOOKMARKABLE,       PropertyAttribute::READONLY,&m_bBookmarkable,                ::getBooleanCppuType());
55 }
56 // -------------------------------------------------------------------------
57 ::rtl::OUString SAL_CALL OFlatResultSet::getImplementationName(  ) throw ( RuntimeException)
58 {
59 	return ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.flat.ResultSet");
60 }
61 // -------------------------------------------------------------------------
62 Sequence< ::rtl::OUString > SAL_CALL OFlatResultSet::getSupportedServiceNames(  ) throw( RuntimeException)
63 {
64 	 Sequence< ::rtl::OUString > aSupported(2);
65 	aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbc.ResultSet");
66 	aSupported[1] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.ResultSet");
67 	return aSupported;
68 }
69 // -------------------------------------------------------------------------
70 sal_Bool SAL_CALL OFlatResultSet::supportsService( const ::rtl::OUString& _rServiceName ) throw( RuntimeException)
71 {
72 	Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames());
73 	const ::rtl::OUString* pSupported = aSupported.getConstArray();
74 	const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
75 	for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
76 		;
77 
78 	return pSupported != pEnd;
79 }
80 // -------------------------------------------------------------------------
81 Any SAL_CALL OFlatResultSet::queryInterface( const Type & rType ) throw(RuntimeException)
82 {
83 	if(rType == ::getCppuType((const Reference<XDeleteRows>*)0) || rType == ::getCppuType((const Reference<XResultSetUpdate>*)0)
84 		|| rType == ::getCppuType((const Reference<XRowUpdate>*)0))
85 		return Any();
86 
87 	const Any aRet = OResultSet::queryInterface(rType);
88 	return aRet.hasValue() ? aRet : OFlatResultSet_BASE::queryInterface(rType);
89 }
90 // -------------------------------------------------------------------------
91 Sequence<  Type > SAL_CALL OFlatResultSet::getTypes(  ) throw( RuntimeException)
92 {
93 	Sequence< Type > aTypes = OResultSet::getTypes();
94 	::std::vector<Type> aOwnTypes;
95 	aOwnTypes.reserve(aTypes.getLength());
96 	const Type* pBegin = aTypes.getConstArray();
97 	const Type* pEnd = pBegin + aTypes.getLength();
98 	for(;pBegin != pEnd;++pBegin)
99 	{
100 		if(!(*pBegin == ::getCppuType((const Reference<XDeleteRows>*)0) ||
101 			*pBegin == ::getCppuType((const Reference<XResultSetUpdate>*)0) ||
102 			*pBegin == ::getCppuType((const Reference<XRowUpdate>*)0)))
103 		{
104 			aOwnTypes.push_back(*pBegin);
105 		}
106 	}
107 	Type* pTypes = aOwnTypes.empty() ? 0 : &aOwnTypes[0];
108 	Sequence< Type > aRet(pTypes, aOwnTypes.size());
109 	return ::comphelper::concatSequences(aRet,OFlatResultSet_BASE::getTypes());
110 }
111 
112 // -------------------------------------------------------------------------
113 // XRowLocate
114 Any SAL_CALL OFlatResultSet::getBookmark(  ) throw( SQLException,  RuntimeException)
115 {
116 	 ::osl::MutexGuard aGuard( m_aMutex );
117     checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
118 
119     return makeAny((sal_Int32)(m_aRow->get())[0]->getValue());
120 }
121 // -------------------------------------------------------------------------
122 sal_Bool SAL_CALL OFlatResultSet::moveToBookmark( const  Any& bookmark ) throw( SQLException,  RuntimeException)
123 {
124 	::osl::MutexGuard aGuard( m_aMutex );
125         checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
126 
127 
128 	m_bRowDeleted = m_bRowInserted = m_bRowUpdated = sal_False;
129 
130 	return Move(IResultSetHelper::BOOKMARK,comphelper::getINT32(bookmark),sal_True);
131 }
132 // -------------------------------------------------------------------------
133 sal_Bool SAL_CALL OFlatResultSet::moveRelativeToBookmark( const  Any& bookmark, sal_Int32 rows ) throw( SQLException,  RuntimeException)
134 {
135 	::osl::MutexGuard aGuard( m_aMutex );
136         checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
137 
138 
139 	m_bRowDeleted = m_bRowInserted = m_bRowUpdated = sal_False;
140 
141 	Move(IResultSetHelper::BOOKMARK,comphelper::getINT32(bookmark),sal_False);
142 
143 	return relative(rows);
144 }
145 
146 // -------------------------------------------------------------------------
147 sal_Int32 SAL_CALL OFlatResultSet::compareBookmarks( const Any& lhs, const  Any& rhs ) throw( SQLException,  RuntimeException)
148 {
149 	return (lhs == rhs) ? 0 : 2;
150 }
151 // -------------------------------------------------------------------------
152 sal_Bool SAL_CALL OFlatResultSet::hasOrderedBookmarks(  ) throw( SQLException,  RuntimeException)
153 {
154 	return sal_True;
155 }
156 // -------------------------------------------------------------------------
157 sal_Int32 SAL_CALL OFlatResultSet::hashBookmark( const  Any& bookmark ) throw( SQLException,  RuntimeException)
158 {
159 	return comphelper::getINT32(bookmark);
160 }
161 // -------------------------------------------------------------------------
162 IPropertyArrayHelper* OFlatResultSet::createArrayHelper( ) const
163 {
164 	Sequence< Property > aProps;
165 	describeProperties(aProps);
166 	return new ::cppu::OPropertyArrayHelper(aProps);
167 }
168 // -------------------------------------------------------------------------
169 IPropertyArrayHelper & OFlatResultSet::getInfoHelper()
170 {
171 	return *OFlatResultSet_BASE3::getArrayHelper();
172 }
173 // -----------------------------------------------------------------------------
174 void SAL_CALL OFlatResultSet::acquire() throw()
175 {
176 	OFlatResultSet_BASE2::acquire();
177 }
178 // -----------------------------------------------------------------------------
179 void SAL_CALL OFlatResultSet::release() throw()
180 {
181 	OFlatResultSet_BASE2::release();
182 }
183 // -----------------------------------------------------------------------------
184 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OFlatResultSet::getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException)
185 {
186 	return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
187 }
188 // -----------------------------------------------------------------------------
189 
190