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