Line data Source code
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 "dbase/DResultSet.hxx"
22 : #include <com/sun/star/lang/DisposedException.hpp>
23 : #include <comphelper/sequence.hxx>
24 : #include <cppuhelper/supportsservice.hxx>
25 : #include "dbase/DIndex.hxx"
26 : #include "dbase/DIndexIter.hxx"
27 : #include <comphelper/types.hxx>
28 : #include <connectivity/dbexception.hxx>
29 : #include "resource/dbase_res.hrc"
30 :
31 : using namespace ::comphelper;
32 :
33 : using namespace connectivity::dbase;
34 : using namespace connectivity::file;
35 : using namespace ::cppu;
36 : using namespace com::sun::star::uno;
37 : using namespace com::sun::star::lang;
38 : using namespace com::sun::star::beans;
39 : using namespace com::sun::star::sdbc;
40 : using namespace com::sun::star::sdbcx;
41 :
42 21 : ODbaseResultSet::ODbaseResultSet( OStatement_Base* pStmt,connectivity::OSQLParseTreeIterator& _aSQLIterator)
43 : : file::OResultSet(pStmt,_aSQLIterator)
44 21 : ,m_bBookmarkable(true)
45 : {
46 21 : registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISBOOKMARKABLE), PROPERTY_ID_ISBOOKMARKABLE, PropertyAttribute::READONLY,&m_bBookmarkable, cppu::UnoType<bool>::get());
47 21 : }
48 :
49 0 : OUString SAL_CALL ODbaseResultSet::getImplementationName( ) throw ( RuntimeException, std::exception)
50 : {
51 0 : return OUString("com.sun.star.sdbcx.dbase.ResultSet");
52 : }
53 :
54 0 : Sequence< OUString > SAL_CALL ODbaseResultSet::getSupportedServiceNames( ) throw( RuntimeException, std::exception)
55 : {
56 0 : Sequence< OUString > aSupported(2);
57 0 : aSupported[0] = "com.sun.star.sdbc.ResultSet";
58 0 : aSupported[1] = "com.sun.star.sdbcx.ResultSet";
59 0 : return aSupported;
60 : }
61 :
62 0 : sal_Bool SAL_CALL ODbaseResultSet::supportsService( const OUString& _rServiceName ) throw( RuntimeException, std::exception)
63 : {
64 0 : return cppu::supportsService(this, _rServiceName);
65 : }
66 :
67 587 : Any SAL_CALL ODbaseResultSet::queryInterface( const Type & rType ) throw(RuntimeException, std::exception)
68 : {
69 587 : Any aRet = ODbaseResultSet_BASE::queryInterface(rType);
70 587 : return aRet.hasValue() ? aRet : OResultSet::queryInterface(rType);
71 : }
72 :
73 0 : Sequence< Type > SAL_CALL ODbaseResultSet::getTypes( ) throw( RuntimeException, std::exception)
74 : {
75 0 : return ::comphelper::concatSequences(OResultSet::getTypes(),ODbaseResultSet_BASE::getTypes());
76 : }
77 :
78 :
79 : // XRowLocate
80 175 : Any SAL_CALL ODbaseResultSet::getBookmark( ) throw( SQLException, RuntimeException, std::exception)
81 : {
82 175 : ::osl::MutexGuard aGuard( m_aMutex );
83 175 : checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
84 : OSL_ENSURE((m_bShowDeleted || !m_aRow->isDeleted()),"getBookmark called for deleted row");
85 :
86 175 : return makeAny((sal_Int32)(m_aRow->get())[0]->getValue());
87 : }
88 :
89 12 : sal_Bool SAL_CALL ODbaseResultSet::moveToBookmark( const Any& bookmark ) throw( SQLException, RuntimeException, std::exception)
90 : {
91 12 : ::osl::MutexGuard aGuard( m_aMutex );
92 12 : checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
93 :
94 :
95 12 : m_bRowDeleted = m_bRowInserted = m_bRowUpdated = false;
96 :
97 12 : return m_pTable ? Move(IResultSetHelper::BOOKMARK,comphelper::getINT32(bookmark),true) : sal_False;
98 : }
99 :
100 0 : sal_Bool SAL_CALL ODbaseResultSet::moveRelativeToBookmark( const Any& bookmark, sal_Int32 rows ) throw( SQLException, RuntimeException, std::exception)
101 : {
102 0 : ::osl::MutexGuard aGuard( m_aMutex );
103 0 : checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
104 0 : if(!m_pTable)
105 0 : return sal_False;
106 :
107 :
108 0 : Move(IResultSetHelper::BOOKMARK,comphelper::getINT32(bookmark),false);
109 :
110 0 : return relative(rows);
111 : }
112 :
113 :
114 163 : sal_Int32 SAL_CALL ODbaseResultSet::compareBookmarks( const Any& lhs, const Any& rhs ) throw( SQLException, RuntimeException, std::exception)
115 : {
116 163 : sal_Int32 nFirst(0),nSecond(0),nResult(0);
117 163 : if ( !( lhs >>= nFirst ) || !( rhs >>= nSecond ) )
118 : {
119 0 : ::connectivity::SharedResources aResources;
120 0 : const OUString sMessage = aResources.getResourceString(STR_INVALID_BOOKMARK);
121 0 : ::dbtools::throwGenericSQLException(sMessage ,*this);
122 : } // if ( !( lhs >>= nFirst ) || !( rhs >>= nSecond ) )
123 :
124 163 : if(nFirst < nSecond)
125 1 : nResult = CompareBookmark::LESS;
126 162 : else if(nFirst > nSecond)
127 0 : nResult = CompareBookmark::GREATER;
128 : else
129 162 : nResult = CompareBookmark::EQUAL;
130 :
131 163 : return nResult;
132 : }
133 :
134 1 : sal_Bool SAL_CALL ODbaseResultSet::hasOrderedBookmarks( ) throw( SQLException, RuntimeException, std::exception)
135 : {
136 1 : return sal_True;
137 : }
138 :
139 2 : sal_Int32 SAL_CALL ODbaseResultSet::hashBookmark( const Any& bookmark ) throw( SQLException, RuntimeException, std::exception)
140 : {
141 2 : ::osl::MutexGuard aGuard( m_aMutex );
142 2 : checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
143 :
144 :
145 2 : return comphelper::getINT32(bookmark);
146 : }
147 :
148 : // XDeleteRows
149 0 : Sequence< sal_Int32 > SAL_CALL ODbaseResultSet::deleteRows( const Sequence< Any >& /*rows*/ ) throw( SQLException, RuntimeException, std::exception)
150 : {
151 0 : ::osl::MutexGuard aGuard( m_aMutex );
152 0 : checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
153 :
154 0 : ::dbtools::throwFeatureNotImplementedSQLException( "XDeleteRows::deleteRows", *this );
155 0 : return Sequence< sal_Int32 >();
156 : }
157 :
158 0 : bool ODbaseResultSet::fillIndexValues(const Reference< XColumnsSupplier> &_xIndex)
159 : {
160 0 : Reference<XUnoTunnel> xTunnel(_xIndex,UNO_QUERY);
161 0 : if(xTunnel.is())
162 : {
163 0 : dbase::ODbaseIndex* pIndex = reinterpret_cast< dbase::ODbaseIndex* >( xTunnel->getSomething(dbase::ODbaseIndex::getUnoTunnelImplementationId()) );
164 0 : if(pIndex)
165 : {
166 0 : dbase::OIndexIterator* pIter = pIndex->createIterator(NULL,NULL);
167 :
168 0 : if (pIter)
169 : {
170 0 : sal_uIntPtr nRec = pIter->First();
171 0 : while (nRec != NODE_NOTFOUND)
172 : {
173 0 : if (m_aOrderbyAscending[0])
174 0 : m_pFileSet->get().push_back(nRec);
175 : else
176 0 : m_pFileSet->get().insert(m_pFileSet->get().begin(),nRec);
177 0 : nRec = pIter->Next();
178 : }
179 0 : m_pFileSet->setFrozen();
180 0 : delete pIter;
181 0 : return true;
182 : }
183 : }
184 : }
185 0 : return false;
186 : }
187 :
188 147 : ::cppu::IPropertyArrayHelper & ODbaseResultSet::getInfoHelper()
189 : {
190 147 : return *ODbaseResultSet_BASE3::getArrayHelper();
191 : }
192 :
193 18 : ::cppu::IPropertyArrayHelper* ODbaseResultSet::createArrayHelper() const
194 : {
195 18 : Sequence< Property > aProps;
196 18 : describeProperties(aProps);
197 18 : return new ::cppu::OPropertyArrayHelper(aProps);
198 : }
199 :
200 1265 : void SAL_CALL ODbaseResultSet::acquire() throw()
201 : {
202 1265 : ODbaseResultSet_BASE2::acquire();
203 1265 : }
204 :
205 1265 : void SAL_CALL ODbaseResultSet::release() throw()
206 : {
207 1265 : ODbaseResultSet_BASE2::release();
208 1265 : }
209 :
210 21 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL ODbaseResultSet::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException, std::exception)
211 : {
212 21 : return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
213 : }
214 :
215 0 : sal_Int32 ODbaseResultSet::getCurrentFilePos() const
216 : {
217 0 : return m_pTable->getFilePos();
218 : }
219 :
220 :
221 :
222 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|