LibreOffice Module dbaccess (master) 1
BookmarkSet.cxx
Go to the documentation of this file.
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 "BookmarkSet.hxx"
21#include <core_resource.hxx>
22#include <strings.hrc>
23#include <com/sun/star/sdbc/XResultSetUpdate.hpp>
25
26using namespace dbaccess;
27using namespace ::connectivity;
28using namespace ::dbtools;
29using namespace ::com::sun::star::uno;
30using namespace ::com::sun::star::beans;
31using namespace ::com::sun::star::sdbc;
32using namespace ::com::sun::star::sdbcx;
33using namespace ::com::sun::star::container;
34using namespace ::com::sun::star::lang;
35using namespace ::osl;
36
37void OBookmarkSet::construct(const Reference< XResultSet>& _xDriverSet,const OUString& i_sRowSetFilter)
38{
39 OCacheSet::construct(_xDriverSet,i_sRowSetFilter);
40 m_xRowLocate.set(_xDriverSet,UNO_QUERY);
41}
42
43void OBookmarkSet::reset(const Reference< XResultSet>& _xDriverSet)
44{
45 construct(_xDriverSet, m_sRowSetFilter);
46}
47
49{
50 return m_xRowLocate->getBookmark();
51}
52
53bool OBookmarkSet::moveToBookmark( const Any& bookmark )
54{
55 return m_xRowLocate->moveToBookmark(bookmark);
56}
57
58sal_Int32 OBookmarkSet::compareBookmarks( const Any& _first, const Any& _second )
59{
60 return m_xRowLocate->compareBookmarks(_first,_second);
61}
62
64{
65 return m_xRowLocate->hasOrderedBookmarks();
66}
67
68sal_Int32 OBookmarkSet::hashBookmark( const Any& bookmark )
69{
70 return m_xRowLocate->hashBookmark(bookmark);
71}
72
73void OBookmarkSet::insertRow( const ORowSetRow& _rInsertRow,const connectivity::OSQLTable& /*_xTable*/ )
74{
75 Reference<XRowUpdate> xUpdRow(m_xRowLocate,UNO_QUERY);
76 if(!xUpdRow.is())
77 ::dbtools::throwSQLException( DBA_RES( RID_STR_NO_XROWUPDATE ), StandardSQLState::GENERAL_ERROR, *this );
78
79 Reference<XResultSetUpdate> xUpd(m_xRowLocate,UNO_QUERY);
80 if(xUpd.is())
81 {
82 xUpd->moveToInsertRow();
83 sal_Int32 i = 1;
84 connectivity::ORowVector< ORowSetValue > ::Vector::iterator aEnd = _rInsertRow->end();
85 for(connectivity::ORowVector< ORowSetValue > ::Vector::iterator aIter = _rInsertRow->begin()+1;aIter != aEnd;++aIter,++i)
86 {
87 aIter->setSigned(m_aSignedFlags[i-1]);
88 updateColumn(i,xUpdRow,*aIter);
89 }
90 xUpd->insertRow();
91 (*_rInsertRow->begin()) = m_xRowLocate->getBookmark();
92 }
93 else
94 ::dbtools::throwSQLException( DBA_RES( RID_STR_NO_XRESULTSETUPDATE ), StandardSQLState::GENERAL_ERROR, *this );
95}
96
97void OBookmarkSet::updateRow(const ORowSetRow& _rInsertRow ,const ORowSetRow& _rOriginalRow,const connectivity::OSQLTable& /*_xTable*/ )
98{
99 Reference<XRowUpdate> xUpdRow(m_xRowLocate,UNO_QUERY);
100 if(!xUpdRow.is())
101 ::dbtools::throwSQLException( DBA_RES( RID_STR_NO_XROWUPDATE ), StandardSQLState::GENERAL_ERROR, *this );
102
103 sal_Int32 i = 1;
104 connectivity::ORowVector< ORowSetValue > ::Vector::const_iterator aOrgIter = _rOriginalRow->begin()+1;
105 connectivity::ORowVector< ORowSetValue > ::Vector::iterator aEnd = _rInsertRow->end();
106 for(connectivity::ORowVector< ORowSetValue > ::Vector::iterator aIter = _rInsertRow->begin()+1;aIter != aEnd;++aIter,++i,++aOrgIter)
107 {
108 aIter->setSigned(aOrgIter->isSigned());
109 updateColumn(i,xUpdRow,*aIter);
110 }
111
112
113 Reference<XResultSetUpdate> xUpd(m_xRowLocate,UNO_QUERY);
114 if(xUpd.is())
115 xUpd->updateRow();
116 else
117 ::dbtools::throwSQLException( DBA_RES( RID_STR_NO_XRESULTSETUPDATE ), StandardSQLState::GENERAL_ERROR, *this );
118}
119
120void OBookmarkSet::deleteRow(const ORowSetRow& /*_rDeleteRow*/ ,const connectivity::OSQLTable& /*_xTable*/ )
121{
122 Reference<XResultSetUpdate> xUpd(m_xRowLocate,UNO_QUERY);
123
124 xUpd->deleteRow();
125}
126
127void OBookmarkSet::updateColumn(sal_Int32 nPos, const Reference< XRowUpdate >& _xParameter, const ORowSetValue& _rValue)
128{
129 if(!(_rValue.isBound() && _rValue.isModified()))
130 return;
131
132 if(_rValue.isNull())
133 _xParameter->updateNull(nPos);
134 else
135 {
136
137 switch(_rValue.getTypeKind())
138 {
139 case DataType::DECIMAL:
140 case DataType::NUMERIC:
141 _xParameter->updateNumericObject(nPos,_rValue.makeAny(),m_xSetMetaData->getScale(nPos));
142 break;
143 case DataType::CHAR:
144 case DataType::VARCHAR:
145 _xParameter->updateString(nPos,_rValue.getString());
146 break;
147 case DataType::BIGINT:
148 if ( _rValue.isSigned() )
149 _xParameter->updateLong(nPos,_rValue.getLong());
150 else
151 _xParameter->updateString(nPos,_rValue.getString());
152 break;
153 case DataType::BIT:
154 case DataType::BOOLEAN:
155 _xParameter->updateBoolean(nPos,_rValue.getBool());
156 break;
157 case DataType::TINYINT:
158 if ( _rValue.isSigned() )
159 _xParameter->updateByte(nPos,_rValue.getInt8());
160 else
161 _xParameter->updateShort(nPos,_rValue.getInt16());
162 break;
163 case DataType::SMALLINT:
164 if ( _rValue.isSigned() )
165 _xParameter->updateShort(nPos,_rValue.getInt16());
166 else
167 _xParameter->updateInt(nPos,_rValue.getInt32());
168 break;
169 case DataType::INTEGER:
170 if ( _rValue.isSigned() )
171 _xParameter->updateInt(nPos,_rValue.getInt32());
172 else
173 _xParameter->updateLong(nPos,_rValue.getLong());
174 break;
175 case DataType::FLOAT:
176 _xParameter->updateFloat(nPos,_rValue.getFloat());
177 break;
178 case DataType::DOUBLE:
179 case DataType::REAL:
180 _xParameter->updateDouble(nPos,_rValue.getDouble());
181 break;
182 case DataType::DATE:
183 _xParameter->updateDate(nPos,_rValue.getDate());
184 break;
185 case DataType::TIME:
186 _xParameter->updateTime(nPos,_rValue.getTime());
187 break;
188 case DataType::TIMESTAMP:
189 _xParameter->updateTimestamp(nPos,_rValue.getDateTime());
190 break;
191 case DataType::BINARY:
192 case DataType::VARBINARY:
193 case DataType::LONGVARBINARY:
194 _xParameter->updateBytes(nPos,_rValue.getSequence());
195 break;
196 case DataType::BLOB:
197 case DataType::CLOB:
198 _xParameter->updateObject(nPos,_rValue.getAny());
199 break;
200 }
201 }
202}
203
204/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::util::Time getTime() const
sal_Int32 getInt32() const
OUString getString() const
css::uno::Any makeAny() const
sal_Int32 getTypeKind() const
sal_Int8 getInt8() const
sal_Int16 getInt16() const
css::util::Date getDate() const
css::util::DateTime getDateTime() const
sal_Int64 getLong() const
const css::uno::Any & getAny() const
css::uno::Sequence< sal_Int8 > getSequence() const
virtual css::uno::Any getBookmark() override
Definition: BookmarkSet.cxx:48
virtual bool moveToBookmark(const css::uno::Any &bookmark) override
Definition: BookmarkSet.cxx:53
css::uno::Reference< css::sdbcx::XRowLocate > m_xRowLocate
Definition: BookmarkSet.hxx:31
virtual sal_Int32 hashBookmark(const css::uno::Any &bookmark) override
Definition: BookmarkSet.cxx:68
virtual bool hasOrderedBookmarks() override
Definition: BookmarkSet.cxx:63
virtual void updateRow(const ORowSetRow &_rInsertRow, const ORowSetRow &_rOriginalRow, const connectivity::OSQLTable &_xTable) override
Definition: BookmarkSet.cxx:97
virtual void deleteRow(const ORowSetRow &_rInsertRow, const connectivity::OSQLTable &_xTable) override
virtual void insertRow(const ORowSetRow &_rInsertRow, const connectivity::OSQLTable &_xTable) override
Definition: BookmarkSet.cxx:73
void updateColumn(sal_Int32 nPos, const css::uno::Reference< css::sdbc::XRowUpdate > &_xParameter, const connectivity::ORowSetValue &_rValue)
virtual sal_Int32 compareBookmarks(const css::uno::Any &first, const css::uno::Any &second) override
Definition: BookmarkSet.cxx:58
virtual void construct(const css::uno::Reference< css::sdbc::XResultSet > &_xDriverSet, const OUString &i_sRowSetFilter) override
Definition: BookmarkSet.cxx:37
virtual void reset(const css::uno::Reference< css::sdbc::XResultSet > &_xDriverSet) override
Definition: BookmarkSet.cxx:43
css::uno::Reference< css::sdbc::XResultSetMetaData > m_xSetMetaData
Definition: CacheSet.hxx:40
std::vector< bool > m_aSignedFlags
Definition: CacheSet.hxx:44
OUString m_sRowSetFilter
Definition: CacheSet.hxx:51
virtual void construct(const css::uno::Reference< css::sdbc::XResultSet > &_xDriverSet, const OUString &i_sRowSetFilter)
Definition: CacheSet.cxx:74
#define DBA_RES(id)
sal_uInt16 nPos
css::uno::Reference< css::sdbcx::XColumnsSupplier > OSQLTable
int i