xref: /trunk/main/dbaccess/source/core/api/BookmarkSet.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_dbaccess.hxx"
30 #ifndef DBACCESS_CORE_API_BOOKMARKSET_HXX
31 #include "BookmarkSet.hxx"
32 #endif
33 #ifndef _DBA_CORE_RESOURCE_HXX_
34 #include "core_resource.hxx"
35 #endif
36 #ifndef _DBA_CORE_RESOURCE_HRC_
37 #include "core_resource.hrc"
38 #endif
39 #ifndef _COM_SUN_STAR_SDBC_XRESULTSETUPDATE_HPP_
40 #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
41 #endif
42 #ifndef _DBHELPER_DBEXCEPTION_HXX_
43 #include <connectivity/dbexception.hxx>
44 #endif
45 #include <rtl/logfile.hxx>
46 
47 #include <limits>
48 
49 using namespace dbaccess;
50 using namespace ::connectivity;
51 using namespace ::dbtools;
52 using namespace ::com::sun::star::uno;
53 using namespace ::com::sun::star::beans;
54 using namespace ::com::sun::star::sdbc;
55 //  using namespace ::com::sun::star::sdb;
56 using namespace ::com::sun::star::sdbcx;
57 using namespace ::com::sun::star::container;
58 using namespace ::com::sun::star::lang;
59 //  using namespace ::cppu;
60 using namespace ::osl;
61 
62 void OBookmarkSet::construct(const Reference< XResultSet>& _xDriverSet,const ::rtl::OUString& i_sRowSetFilter)
63 {
64     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::construct" );
65     OCacheSet::construct(_xDriverSet,i_sRowSetFilter);
66     m_xRowLocate.set(_xDriverSet,UNO_QUERY);
67 }
68 // -----------------------------------------------------------------------------
69 Any SAL_CALL OBookmarkSet::getBookmark() throw(SQLException, RuntimeException)
70 {
71     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::getBookmark" );
72     return m_xRowLocate->getBookmark();
73 }
74 // -------------------------------------------------------------------------
75 sal_Bool SAL_CALL OBookmarkSet::moveToBookmark( const Any& bookmark ) throw(SQLException, RuntimeException)
76 {
77     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::moveToBookmark" );
78     return m_xRowLocate->moveToBookmark(bookmark);
79 }
80 // -------------------------------------------------------------------------
81 sal_Bool SAL_CALL OBookmarkSet::moveRelativeToBookmark( const Any& bookmark, sal_Int32 rows ) throw(SQLException, RuntimeException)
82 {
83     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::moveRelativeToBookmark" );
84     return m_xRowLocate->moveRelativeToBookmark(bookmark,rows);
85 }
86 // -------------------------------------------------------------------------
87 sal_Int32 SAL_CALL OBookmarkSet::compareBookmarks( const Any& _first, const Any& _second ) throw(SQLException, RuntimeException)
88 {
89     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::compareBookmarks" );
90     return m_xRowLocate->compareBookmarks(_first,_second);
91 }
92 // -------------------------------------------------------------------------
93 sal_Bool SAL_CALL OBookmarkSet::hasOrderedBookmarks(  ) throw(SQLException, RuntimeException)
94 {
95     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::hasOrderedBookmarks" );
96     return m_xRowLocate->hasOrderedBookmarks();
97 }
98 // -------------------------------------------------------------------------
99 sal_Int32 SAL_CALL OBookmarkSet::hashBookmark( const Any& bookmark ) throw(SQLException, RuntimeException)
100 {
101     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::hashBookmark" );
102     return m_xRowLocate->hashBookmark(bookmark);
103 }
104 // -------------------------------------------------------------------------
105 // ::com::sun::star::sdbcx::XDeleteRows
106 Sequence< sal_Int32 > SAL_CALL OBookmarkSet::deleteRows( const Sequence< Any >& rows ,const connectivity::OSQLTable& /*_xTable*/) throw(SQLException, RuntimeException)
107 {
108     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::deleteRows" );
109     Reference< ::com::sun::star::sdbcx::XDeleteRows> xDeleteRow(m_xRowLocate,UNO_QUERY);
110     if(xDeleteRow.is())
111     {
112         return xDeleteRow->deleteRows(rows);
113     }
114     return Sequence< sal_Int32 >();
115 }
116 // -------------------------------------------------------------------------
117 void SAL_CALL OBookmarkSet::insertRow( const ORowSetRow& _rInsertRow,const connectivity::OSQLTable& /*_xTable*/ ) throw(SQLException, RuntimeException)
118 {
119     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::insertRow" );
120     Reference<XRowUpdate> xUpdRow(m_xRowLocate,UNO_QUERY);
121     if(!xUpdRow.is())
122         ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_XROWUPDATE ), SQL_GENERAL_ERROR, *this );
123 
124     Reference<XResultSetUpdate> xUpd(m_xRowLocate,UNO_QUERY);
125     if(xUpd.is())
126     {
127         xUpd->moveToInsertRow();
128         sal_Int32 i = 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)
131         {
132             aIter->setSigned(m_aSignedFlags[i-1]);
133             updateColumn(i,xUpdRow,*aIter);
134         }
135         xUpd->insertRow();
136         (*_rInsertRow->get().begin()) = m_xRowLocate->getBookmark();
137     }
138     else
139         ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_XRESULTSETUPDATE ), SQL_GENERAL_ERROR, *this );
140 }
141 // -------------------------------------------------------------------------
142 void SAL_CALL OBookmarkSet::updateRow(const ORowSetRow& _rInsertRow ,const ORowSetRow& _rOrginalRow,const connectivity::OSQLTable& /*_xTable*/  ) throw(SQLException, RuntimeException)
143 {
144     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::updateRow" );
145     //  OCacheSet::updateRow( _rInsertRow,_rOrginalRow,_xTable);
146     Reference<XRowUpdate> xUpdRow(m_xRowLocate,UNO_QUERY);
147     if(!xUpdRow.is())
148         ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_XROWUPDATE ), SQL_GENERAL_ERROR, *this );
149 
150     sal_Int32 i = 1;
151     connectivity::ORowVector< ORowSetValue > ::Vector::const_iterator aOrgIter = _rOrginalRow->get().begin()+1;
152     connectivity::ORowVector< ORowSetValue > ::Vector::iterator aEnd = _rInsertRow->get().end();
153     for(connectivity::ORowVector< ORowSetValue > ::Vector::iterator aIter = _rInsertRow->get().begin()+1;aIter != aEnd;++aIter,++i,++aOrgIter)
154     {
155         aIter->setSigned(aOrgIter->isSigned());
156         updateColumn(i,xUpdRow,*aIter);
157     }
158 
159 
160     Reference<XResultSetUpdate> xUpd(m_xRowLocate,UNO_QUERY);
161     if(xUpd.is())
162         xUpd->updateRow();
163     else
164         ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_XRESULTSETUPDATE ), SQL_GENERAL_ERROR, *this );
165 }
166 // -------------------------------------------------------------------------
167 void SAL_CALL OBookmarkSet::deleteRow(const ORowSetRow& /*_rDeleteRow*/ ,const connectivity::OSQLTable& /*_xTable*/  ) throw(SQLException, RuntimeException)
168 {
169     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::deleteRow" );
170     Reference<XResultSetUpdate> xUpd(m_xRowLocate,UNO_QUERY);
171 
172     xUpd->deleteRow();
173 }
174 // -------------------------------------------------------------------------
175 void SAL_CALL OBookmarkSet::cancelRowUpdates(  ) throw(SQLException, RuntimeException)
176 {
177     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::cancelRowUpdates" );
178 }
179 // -------------------------------------------------------------------------
180 void SAL_CALL OBookmarkSet::moveToInsertRow(  ) throw(SQLException, RuntimeException)
181 {
182     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::moveToInsertRow" );
183     Reference<XResultSetUpdate> xUpd(m_xRowLocate,UNO_QUERY);
184     if(xUpd.is())
185         xUpd->moveToInsertRow();
186 }
187 // -------------------------------------------------------------------------
188 void SAL_CALL OBookmarkSet::moveToCurrentRow(  ) throw(SQLException, RuntimeException)
189 {
190     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::moveToCurrentRow" );
191 }
192 // -------------------------------------------------------------------------
193 void OBookmarkSet::fillValueRow(ORowSetRow& _rRow,sal_Int32 _nPosition)
194 {
195     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::fillValueRow" );
196     OCacheSet::fillValueRow(_rRow,_nPosition);
197 }
198 // -------------------------------------------------------------------------
199 void OBookmarkSet::updateColumn(sal_Int32 nPos,Reference< XRowUpdate > _xParameter,const ORowSetValue& _rValue)
200 {
201     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::updateColumn" );
202     if(_rValue.isBound() && _rValue.isModified())
203     {
204         if(_rValue.isNull())
205             _xParameter->updateNull(nPos);
206         else
207         {
208 
209             switch(_rValue.getTypeKind())
210             {
211                 case DataType::DECIMAL:
212                 case DataType::NUMERIC:
213                     _xParameter->updateNumericObject(nPos,_rValue.makeAny(),m_xSetMetaData->getScale(nPos));
214                     break;
215                 case DataType::CHAR:
216                 case DataType::VARCHAR:
217                 //case DataType::DECIMAL:
218                 //case DataType::NUMERIC:
219                     _xParameter->updateString(nPos,_rValue);
220                     break;
221                 case DataType::BIGINT:
222                     if ( _rValue.isSigned() )
223                         _xParameter->updateLong(nPos,_rValue);
224                     else
225                         _xParameter->updateString(nPos,_rValue);
226                     break;
227                 case DataType::BIT:
228                 case DataType::BOOLEAN:
229                     _xParameter->updateBoolean(nPos,_rValue);
230                     break;
231                 case DataType::TINYINT:
232                     if ( _rValue.isSigned() )
233                         _xParameter->updateByte(nPos,_rValue);
234                     else
235                         _xParameter->updateShort(nPos,_rValue);
236                     break;
237                 case DataType::SMALLINT:
238                     if ( _rValue.isSigned() )
239                         _xParameter->updateShort(nPos,_rValue);
240                     else
241                         _xParameter->updateInt(nPos,_rValue);
242                     break;
243                 case DataType::INTEGER:
244                     if ( _rValue.isSigned() )
245                         _xParameter->updateInt(nPos,_rValue);
246                     else
247                         _xParameter->updateLong(nPos,_rValue);
248                     break;
249                 case DataType::FLOAT:
250                     _xParameter->updateFloat(nPos,_rValue);
251                     break;
252                 case DataType::DOUBLE:
253                 case DataType::REAL:
254                     _xParameter->updateDouble(nPos,_rValue);
255                     break;
256                 case DataType::DATE:
257                     _xParameter->updateDate(nPos,_rValue);
258                     break;
259                 case DataType::TIME:
260                     _xParameter->updateTime(nPos,_rValue);
261                     break;
262                 case DataType::TIMESTAMP:
263                     _xParameter->updateTimestamp(nPos,_rValue);
264                     break;
265                 case DataType::BINARY:
266                 case DataType::VARBINARY:
267                 case DataType::LONGVARBINARY:
268                     _xParameter->updateBytes(nPos,_rValue);
269                     break;
270                 case DataType::BLOB:
271                 case DataType::CLOB:
272                     _xParameter->updateObject(nPos,_rValue.getAny());
273                     break;
274             }
275         }
276     }
277 }
278 
279