Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / dbaccess / source / core / api / BookmarkSet.cxx
blobf7f79e28e93d6b498a98a3bdb3bb11a4ee4c4361
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 "BookmarkSet.hxx"
21 #include "core_resource.hxx"
22 #include "core_resource.hrc"
23 #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
24 #include <connectivity/dbexception.hxx>
25 #include <rtl/logfile.hxx>
27 #include <limits>
29 using namespace dbaccess;
30 using namespace ::connectivity;
31 using namespace ::dbtools;
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::beans;
34 using namespace ::com::sun::star::sdbc;
35 using namespace ::com::sun::star::sdbcx;
36 using namespace ::com::sun::star::container;
37 using namespace ::com::sun::star::lang;
38 using namespace ::osl;
40 void OBookmarkSet::construct(const Reference< XResultSet>& _xDriverSet,const ::rtl::OUString& i_sRowSetFilter)
42 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::construct" );
43 OCacheSet::construct(_xDriverSet,i_sRowSetFilter);
44 m_xRowLocate.set(_xDriverSet,UNO_QUERY);
47 Any SAL_CALL OBookmarkSet::getBookmark() throw(SQLException, RuntimeException)
49 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::getBookmark" );
50 return m_xRowLocate->getBookmark();
53 sal_Bool SAL_CALL OBookmarkSet::moveToBookmark( const Any& bookmark ) throw(SQLException, RuntimeException)
55 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::moveToBookmark" );
56 return m_xRowLocate->moveToBookmark(bookmark);
59 sal_Bool SAL_CALL OBookmarkSet::moveRelativeToBookmark( const Any& bookmark, sal_Int32 rows ) throw(SQLException, RuntimeException)
61 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::moveRelativeToBookmark" );
62 return m_xRowLocate->moveRelativeToBookmark(bookmark,rows);
65 sal_Int32 SAL_CALL OBookmarkSet::compareBookmarks( const Any& _first, const Any& _second ) throw(SQLException, RuntimeException)
67 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::compareBookmarks" );
68 return m_xRowLocate->compareBookmarks(_first,_second);
71 sal_Bool SAL_CALL OBookmarkSet::hasOrderedBookmarks( ) throw(SQLException, RuntimeException)
73 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::hasOrderedBookmarks" );
74 return m_xRowLocate->hasOrderedBookmarks();
77 sal_Int32 SAL_CALL OBookmarkSet::hashBookmark( const Any& bookmark ) throw(SQLException, RuntimeException)
79 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::hashBookmark" );
80 return m_xRowLocate->hashBookmark(bookmark);
83 // ::com::sun::star::sdbcx::XDeleteRows
84 Sequence< sal_Int32 > SAL_CALL OBookmarkSet::deleteRows( const Sequence< Any >& rows ,const connectivity::OSQLTable& /*_xTable*/) throw(SQLException, RuntimeException)
86 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::deleteRows" );
87 Reference< ::com::sun::star::sdbcx::XDeleteRows> xDeleteRow(m_xRowLocate,UNO_QUERY);
88 if(xDeleteRow.is())
90 return xDeleteRow->deleteRows(rows);
92 return Sequence< sal_Int32 >();
95 void SAL_CALL OBookmarkSet::insertRow( const ORowSetRow& _rInsertRow,const connectivity::OSQLTable& /*_xTable*/ ) throw(SQLException, RuntimeException)
97 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::insertRow" );
98 Reference<XRowUpdate> xUpdRow(m_xRowLocate,UNO_QUERY);
99 if(!xUpdRow.is())
100 ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_XROWUPDATE ), SQL_GENERAL_ERROR, *this );
102 Reference<XResultSetUpdate> xUpd(m_xRowLocate,UNO_QUERY);
103 if(xUpd.is())
105 xUpd->moveToInsertRow();
106 sal_Int32 i = 1;
107 connectivity::ORowVector< ORowSetValue > ::Vector::iterator aEnd = _rInsertRow->get().end();
108 for(connectivity::ORowVector< ORowSetValue > ::Vector::iterator aIter = _rInsertRow->get().begin()+1;aIter != aEnd;++aIter,++i)
110 aIter->setSigned(m_aSignedFlags[i-1]);
111 updateColumn(i,xUpdRow,*aIter);
113 xUpd->insertRow();
114 (*_rInsertRow->get().begin()) = m_xRowLocate->getBookmark();
116 else
117 ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_XRESULTSETUPDATE ), SQL_GENERAL_ERROR, *this );
120 void SAL_CALL OBookmarkSet::updateRow(const ORowSetRow& _rInsertRow ,const ORowSetRow& _rOrginalRow,const connectivity::OSQLTable& /*_xTable*/ ) throw(SQLException, RuntimeException)
122 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::updateRow" );
123 Reference<XRowUpdate> xUpdRow(m_xRowLocate,UNO_QUERY);
124 if(!xUpdRow.is())
125 ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_XROWUPDATE ), SQL_GENERAL_ERROR, *this );
127 sal_Int32 i = 1;
128 connectivity::ORowVector< ORowSetValue > ::Vector::const_iterator aOrgIter = _rOrginalRow->get().begin()+1;
129 connectivity::ORowVector< ORowSetValue > ::Vector::iterator aEnd = _rInsertRow->get().end();
130 for(connectivity::ORowVector< ORowSetValue > ::Vector::iterator aIter = _rInsertRow->get().begin()+1;aIter != aEnd;++aIter,++i,++aOrgIter)
132 aIter->setSigned(aOrgIter->isSigned());
133 updateColumn(i,xUpdRow,*aIter);
137 Reference<XResultSetUpdate> xUpd(m_xRowLocate,UNO_QUERY);
138 if(xUpd.is())
139 xUpd->updateRow();
140 else
141 ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_XRESULTSETUPDATE ), SQL_GENERAL_ERROR, *this );
144 void SAL_CALL OBookmarkSet::deleteRow(const ORowSetRow& /*_rDeleteRow*/ ,const connectivity::OSQLTable& /*_xTable*/ ) throw(SQLException, RuntimeException)
146 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::deleteRow" );
147 Reference<XResultSetUpdate> xUpd(m_xRowLocate,UNO_QUERY);
149 xUpd->deleteRow();
152 void SAL_CALL OBookmarkSet::cancelRowUpdates( ) throw(SQLException, RuntimeException)
154 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::cancelRowUpdates" );
157 void SAL_CALL OBookmarkSet::moveToInsertRow( ) throw(SQLException, RuntimeException)
159 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::moveToInsertRow" );
160 Reference<XResultSetUpdate> xUpd(m_xRowLocate,UNO_QUERY);
161 if(xUpd.is())
162 xUpd->moveToInsertRow();
165 void SAL_CALL OBookmarkSet::moveToCurrentRow( ) throw(SQLException, RuntimeException)
167 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::moveToCurrentRow" );
170 void OBookmarkSet::fillValueRow(ORowSetRow& _rRow,sal_Int32 _nPosition)
172 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::fillValueRow" );
173 OCacheSet::fillValueRow(_rRow,_nPosition);
176 void OBookmarkSet::updateColumn(sal_Int32 nPos,Reference< XRowUpdate > _xParameter,const ORowSetValue& _rValue)
178 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::updateColumn" );
179 if(_rValue.isBound() && _rValue.isModified())
181 if(_rValue.isNull())
182 _xParameter->updateNull(nPos);
183 else
186 switch(_rValue.getTypeKind())
188 case DataType::DECIMAL:
189 case DataType::NUMERIC:
190 _xParameter->updateNumericObject(nPos,_rValue.makeAny(),m_xSetMetaData->getScale(nPos));
191 break;
192 case DataType::CHAR:
193 case DataType::VARCHAR:
194 _xParameter->updateString(nPos,_rValue);
195 break;
196 case DataType::BIGINT:
197 if ( _rValue.isSigned() )
198 _xParameter->updateLong(nPos,_rValue);
199 else
200 _xParameter->updateString(nPos,_rValue);
201 break;
202 case DataType::BIT:
203 case DataType::BOOLEAN:
204 _xParameter->updateBoolean(nPos,_rValue);
205 break;
206 case DataType::TINYINT:
207 if ( _rValue.isSigned() )
208 _xParameter->updateByte(nPos,_rValue);
209 else
210 _xParameter->updateShort(nPos,_rValue);
211 break;
212 case DataType::SMALLINT:
213 if ( _rValue.isSigned() )
214 _xParameter->updateShort(nPos,_rValue);
215 else
216 _xParameter->updateInt(nPos,_rValue);
217 break;
218 case DataType::INTEGER:
219 if ( _rValue.isSigned() )
220 _xParameter->updateInt(nPos,_rValue);
221 else
222 _xParameter->updateLong(nPos,_rValue);
223 break;
224 case DataType::FLOAT:
225 _xParameter->updateFloat(nPos,_rValue);
226 break;
227 case DataType::DOUBLE:
228 case DataType::REAL:
229 _xParameter->updateDouble(nPos,_rValue);
230 break;
231 case DataType::DATE:
232 _xParameter->updateDate(nPos,_rValue);
233 break;
234 case DataType::TIME:
235 _xParameter->updateTime(nPos,_rValue);
236 break;
237 case DataType::TIMESTAMP:
238 _xParameter->updateTimestamp(nPos,_rValue);
239 break;
240 case DataType::BINARY:
241 case DataType::VARBINARY:
242 case DataType::LONGVARBINARY:
243 _xParameter->updateBytes(nPos,_rValue);
244 break;
245 case DataType::BLOB:
246 case DataType::CLOB:
247 _xParameter->updateObject(nPos,_rValue.getAny());
248 break;
253 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */