Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / connectivity / source / drivers / component / CTable.cxx
blob819ce7a970638a09546800444fe1994188594e03
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <component/CTable.hxx>
21 #include <component/CColumns.hxx>
22 #include <cppuhelper/queryinterface.hxx>
24 using namespace connectivity;
25 using namespace connectivity::component;
26 using namespace connectivity::file;
27 using namespace ::cppu;
28 using namespace ::dbtools;
29 using namespace ::com::sun::star::uno;
30 using namespace ::com::sun::star::beans;
31 using namespace ::com::sun::star::sdbcx;
32 using namespace ::com::sun::star::sdbc;
33 using namespace ::com::sun::star::container;
34 using namespace ::com::sun::star::lang;
35 using namespace ::com::sun::star::sheet;
36 using namespace ::com::sun::star::util;
39 OComponentTable::OComponentTable(sdbcx::OCollection* _pTables,file::OConnection* _pConnection,
40 const OUString& Name,
41 const OUString& Type,
42 const OUString& Description ,
43 const OUString& SchemaName,
44 const OUString& CatalogName
45 ) : OComponentTable_BASE(_pTables,_pConnection,Name,
46 Type,
47 Description,
48 SchemaName,
49 CatalogName)
50 ,m_nDataRows(0)
54 void OComponentTable::refreshColumns()
56 ::osl::MutexGuard aGuard( m_aMutex );
58 ::std::vector< OUString> aVector;
60 for(const auto& rxColumn : *m_aColumns)
61 aVector.push_back(Reference< XNamed>(rxColumn,UNO_QUERY_THROW)->getName());
63 if(m_xColumns)
64 m_xColumns->reFill(aVector);
65 else
66 m_xColumns.reset(new component::OComponentColumns(this,m_aMutex,aVector));
69 void OComponentTable::refreshIndexes()
71 // Writer or Calc table has no index
75 Sequence< Type > SAL_CALL OComponentTable::getTypes( )
77 Sequence< Type > aTypes = OTable_TYPEDEF::getTypes();
78 std::vector<Type> aOwnTypes;
79 aOwnTypes.reserve(aTypes.getLength());
81 const Type* pBegin = aTypes.getConstArray();
82 const Type* pEnd = pBegin + aTypes.getLength();
83 for(;pBegin != pEnd;++pBegin)
85 if(!( *pBegin == cppu::UnoType<XKeysSupplier>::get()||
86 *pBegin == cppu::UnoType<XIndexesSupplier>::get()||
87 *pBegin == cppu::UnoType<XRename>::get()||
88 *pBegin == cppu::UnoType<XAlterTable>::get()||
89 *pBegin == cppu::UnoType<XDataDescriptorFactory>::get()))
90 aOwnTypes.push_back(*pBegin);
92 aOwnTypes.push_back(cppu::UnoType<css::lang::XUnoTunnel>::get());
94 return Sequence< Type >(aOwnTypes.data(), aOwnTypes.size());
98 Any SAL_CALL OComponentTable::queryInterface( const Type & rType )
100 if( rType == cppu::UnoType<XKeysSupplier>::get()||
101 rType == cppu::UnoType<XIndexesSupplier>::get()||
102 rType == cppu::UnoType<XRename>::get()||
103 rType == cppu::UnoType<XAlterTable>::get()||
104 rType == cppu::UnoType<XDataDescriptorFactory>::get())
105 return Any();
107 return OTable_TYPEDEF::queryInterface(rType);
111 sal_Int32 OComponentTable::getCurrentLastPos() const
113 return m_nDataRows;
116 bool OComponentTable::seekRow(IResultSetHelper::Movement eCursorPosition, sal_Int32 nOffset, sal_Int32& nCurPos)
118 // prepare positioning:
120 sal_uInt32 nNumberOfRecords = m_nDataRows;
121 sal_uInt32 nTempPos = m_nFilePos;
122 m_nFilePos = nCurPos;
124 switch(eCursorPosition)
126 case IResultSetHelper::NEXT:
127 m_nFilePos++;
128 break;
129 case IResultSetHelper::PRIOR:
130 if (m_nFilePos > 0)
131 m_nFilePos--;
132 break;
133 case IResultSetHelper::FIRST:
134 m_nFilePos = 1;
135 break;
136 case IResultSetHelper::LAST:
137 m_nFilePos = nNumberOfRecords;
138 break;
139 case IResultSetHelper::RELATIVE1:
140 m_nFilePos = (m_nFilePos + nOffset < 0) ? 0
141 : static_cast<sal_uInt32>(m_nFilePos + nOffset);
142 break;
143 case IResultSetHelper::ABSOLUTE1:
144 case IResultSetHelper::BOOKMARK:
145 m_nFilePos = static_cast<sal_uInt32>(nOffset);
146 break;
149 if (m_nFilePos > static_cast<sal_Int32>(nNumberOfRecords))
150 m_nFilePos = static_cast<sal_Int32>(nNumberOfRecords) + 1;
152 if (m_nFilePos == 0 || m_nFilePos == static_cast<sal_Int32>(nNumberOfRecords) + 1)
154 switch(eCursorPosition)
156 case IResultSetHelper::PRIOR:
157 case IResultSetHelper::FIRST:
158 m_nFilePos = 0;
159 break;
160 case IResultSetHelper::LAST:
161 case IResultSetHelper::NEXT:
162 case IResultSetHelper::ABSOLUTE1:
163 case IResultSetHelper::RELATIVE1:
164 if (nOffset > 0)
165 m_nFilePos = nNumberOfRecords + 1;
166 else if (nOffset < 0)
167 m_nFilePos = 0;
168 break;
169 case IResultSetHelper::BOOKMARK:
170 m_nFilePos = nTempPos; // previous position
171 break;
173 return false;
176 //! read buffer / setup row object etc?
177 nCurPos = m_nFilePos;
178 return true;
181 void OComponentTable::FileClose()
183 ::osl::MutexGuard aGuard(m_aMutex);
185 OComponentTable_BASE::FileClose();
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */