1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <com/sun/star/sdbcx/CompareBookmark.hpp>
21 #include <component/CResultSet.hxx>
22 #include <com/sun/star/beans/PropertyAttribute.hpp>
23 #include <comphelper/sequence.hxx>
24 #include <comphelper/types.hxx>
25 #include <cppuhelper/supportsservice.hxx>
26 #include <connectivity/dbexception.hxx>
27 
28 using namespace ::comphelper;
29 using namespace connectivity::component;
30 using namespace connectivity::file;
31 using namespace ::cppu;
32 using namespace com::sun::star::uno;
33 using namespace com::sun::star::lang;
34 using namespace com::sun::star::beans;
35 using namespace com::sun::star::sdbc;
36 using namespace com::sun::star::sdbcx;
37 
38 
OComponentResultSet(OStatement_Base * pStmt,connectivity::OSQLParseTreeIterator & _aSQLIterator)39 OComponentResultSet::OComponentResultSet( OStatement_Base* pStmt,connectivity::OSQLParseTreeIterator& _aSQLIterator)
40                 : file::OResultSet(pStmt,_aSQLIterator)
41                 ,m_bBookmarkable(true)
42 {
43     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISBOOKMARKABLE),         PROPERTY_ID_ISBOOKMARKABLE,       PropertyAttribute::READONLY,&m_bBookmarkable,                cppu::UnoType<bool>::get());
44 }
45 
getImplementationName()46 OUString SAL_CALL OComponentResultSet::getImplementationName(  )
47 {
48     return "com.sun.star.sdbcx.component.ResultSet";
49 }
50 
getSupportedServiceNames()51 Sequence< OUString > SAL_CALL OComponentResultSet::getSupportedServiceNames(  )
52 {
53     return { "com.sun.star.sdbc.ResultSet", "com.sun.star.sdbcx.ResultSet" };
54 }
55 
supportsService(const OUString & _rServiceName)56 sal_Bool SAL_CALL OComponentResultSet::supportsService( const OUString& _rServiceName )
57 {
58     return cppu::supportsService(this, _rServiceName);
59 }
60 
queryInterface(const Type & rType)61 Any SAL_CALL OComponentResultSet::queryInterface( const Type & rType )
62 {
63     Any aRet = OResultSet::queryInterface(rType);
64     return aRet.hasValue() ? aRet : OComponentResultSet_BASE::queryInterface(rType);
65 }
66 
getTypes()67  Sequence<  Type > SAL_CALL OComponentResultSet::getTypes(  )
68 {
69     return ::comphelper::concatSequences(OResultSet::getTypes(),OComponentResultSet_BASE::getTypes());
70 }
71 
72 
73 // XRowLocate
getBookmark()74 Any SAL_CALL OComponentResultSet::getBookmark(  )
75 {
76     ::osl::MutexGuard aGuard( m_aMutex );
77     checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
78 
79 
80     return makeAny(static_cast<sal_Int32>((*m_aRow)[0]->getValue()));
81 }
82 
moveToBookmark(const Any & bookmark)83 sal_Bool SAL_CALL OComponentResultSet::moveToBookmark( const  Any& bookmark )
84 {
85     ::osl::MutexGuard aGuard( m_aMutex );
86     checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
87 
88 
89     m_bRowDeleted = m_bRowInserted = m_bRowUpdated = false;
90 
91     return Move(IResultSetHelper::BOOKMARK,comphelper::getINT32(bookmark),true);
92 }
93 
moveRelativeToBookmark(const Any & bookmark,sal_Int32 rows)94 sal_Bool SAL_CALL OComponentResultSet::moveRelativeToBookmark( const  Any& bookmark, sal_Int32 rows )
95 {
96     ::osl::MutexGuard aGuard( m_aMutex );
97     checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
98 
99 
100     m_bRowDeleted = m_bRowInserted = m_bRowUpdated = false;
101 
102     Move(IResultSetHelper::BOOKMARK,comphelper::getINT32(bookmark),false);
103 
104     return relative(rows);
105 }
106 
107 
compareBookmarks(const Any & lhs,const Any & rhs)108 sal_Int32 SAL_CALL OComponentResultSet::compareBookmarks( const Any& lhs, const  Any& rhs )
109 {
110     return (lhs == rhs) ? CompareBookmark::EQUAL : CompareBookmark::NOT_EQUAL;
111 }
112 
hasOrderedBookmarks()113 sal_Bool SAL_CALL OComponentResultSet::hasOrderedBookmarks(  )
114 {
115     return true;
116 }
117 
hashBookmark(const Any & bookmark)118 sal_Int32 SAL_CALL OComponentResultSet::hashBookmark( const  Any& bookmark )
119 {
120     ::osl::MutexGuard aGuard( m_aMutex );
121     checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
122 
123 
124     return comphelper::getINT32(bookmark);
125 }
126 
127 // XDeleteRows
deleteRows(const Sequence<Any> &)128 Sequence< sal_Int32 > SAL_CALL OComponentResultSet::deleteRows( const  Sequence<  Any >& /*rows*/ )
129 {
130     ::osl::MutexGuard aGuard( m_aMutex );
131     checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
132 
133     ::dbtools::throwFeatureNotImplementedSQLException( "XDeleteRows::deleteRows", *this );
134     return Sequence< sal_Int32 >();
135 }
136 
fillIndexValues(const Reference<XColumnsSupplier> &)137 bool OComponentResultSet::fillIndexValues(const Reference< XColumnsSupplier> &/*_xIndex*/)
138 {
139     //  Writer or Calc table has no index
140     return false;
141 }
142 
getInfoHelper()143 ::cppu::IPropertyArrayHelper & OComponentResultSet::getInfoHelper()
144 {
145     return *OComponentResultSet_BASE3::getArrayHelper();
146 }
147 
createArrayHelper() const148 ::cppu::IPropertyArrayHelper* OComponentResultSet::createArrayHelper() const
149 {
150     Sequence< Property > aProps;
151     describeProperties(aProps);
152     return new ::cppu::OPropertyArrayHelper(aProps);
153 }
154 
155 
acquire()156 void SAL_CALL OComponentResultSet::acquire() noexcept
157 {
158     OComponentResultSet_BASE2::acquire();
159 }
160 
release()161 void SAL_CALL OComponentResultSet::release() noexcept
162 {
163     OComponentResultSet_BASE2::release();
164 }
165 
getPropertySetInfo()166 css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL OComponentResultSet::getPropertySetInfo(  )
167 {
168     return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
169 }
170 
171 
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
173