xref: /AOO41X/main/dbaccess/source/core/api/BookmarkSet.cxx (revision 96de54900b79e13b861fbc62cbf36018b54e21b7)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_dbaccess.hxx"
26 #ifndef DBACCESS_CORE_API_BOOKMARKSET_HXX
27 #include "BookmarkSet.hxx"
28 #endif
29 #ifndef _DBA_CORE_RESOURCE_HXX_
30 #include "core_resource.hxx"
31 #endif
32 #ifndef _DBA_CORE_RESOURCE_HRC_
33 #include "core_resource.hrc"
34 #endif
35 #ifndef _COM_SUN_STAR_SDBC_XRESULTSETUPDATE_HPP_
36 #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
37 #endif
38 #ifndef _DBHELPER_DBEXCEPTION_HXX_
39 #include <connectivity/dbexception.hxx>
40 #endif
41 #include <rtl/logfile.hxx>
42 
43 #include <limits>
44 
45 using namespace dbaccess;
46 using namespace ::connectivity;
47 using namespace ::dbtools;
48 using namespace ::com::sun::star::uno;
49 using namespace ::com::sun::star::beans;
50 using namespace ::com::sun::star::sdbc;
51 //  using namespace ::com::sun::star::sdb;
52 using namespace ::com::sun::star::sdbcx;
53 using namespace ::com::sun::star::container;
54 using namespace ::com::sun::star::lang;
55 //  using namespace ::cppu;
56 using namespace ::osl;
57 
construct(const Reference<XResultSet> & _xDriverSet,const::rtl::OUString & i_sRowSetFilter)58 void OBookmarkSet::construct(const Reference< XResultSet>& _xDriverSet,const ::rtl::OUString& i_sRowSetFilter)
59 {
60     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::construct" );
61     OCacheSet::construct(_xDriverSet,i_sRowSetFilter);
62     m_xRowLocate.set(_xDriverSet,UNO_QUERY);
63 }
64 // -----------------------------------------------------------------------------
getBookmark()65 Any SAL_CALL OBookmarkSet::getBookmark() throw(SQLException, RuntimeException)
66 {
67     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::getBookmark" );
68     return m_xRowLocate->getBookmark();
69 }
70 // -------------------------------------------------------------------------
moveToBookmark(const Any & bookmark)71 sal_Bool SAL_CALL OBookmarkSet::moveToBookmark( const Any& bookmark ) throw(SQLException, RuntimeException)
72 {
73     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::moveToBookmark" );
74     return m_xRowLocate->moveToBookmark(bookmark);
75 }
76 // -------------------------------------------------------------------------
moveRelativeToBookmark(const Any & bookmark,sal_Int32 rows)77 sal_Bool SAL_CALL OBookmarkSet::moveRelativeToBookmark( const Any& bookmark, sal_Int32 rows ) throw(SQLException, RuntimeException)
78 {
79     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::moveRelativeToBookmark" );
80     return m_xRowLocate->moveRelativeToBookmark(bookmark,rows);
81 }
82 // -------------------------------------------------------------------------
compareBookmarks(const Any & _first,const Any & _second)83 sal_Int32 SAL_CALL OBookmarkSet::compareBookmarks( const Any& _first, const Any& _second ) throw(SQLException, RuntimeException)
84 {
85     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::compareBookmarks" );
86     return m_xRowLocate->compareBookmarks(_first,_second);
87 }
88 // -------------------------------------------------------------------------
hasOrderedBookmarks()89 sal_Bool SAL_CALL OBookmarkSet::hasOrderedBookmarks(  ) throw(SQLException, RuntimeException)
90 {
91     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::hasOrderedBookmarks" );
92     return m_xRowLocate->hasOrderedBookmarks();
93 }
94 // -------------------------------------------------------------------------
hashBookmark(const Any & bookmark)95 sal_Int32 SAL_CALL OBookmarkSet::hashBookmark( const Any& bookmark ) throw(SQLException, RuntimeException)
96 {
97     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::hashBookmark" );
98     return m_xRowLocate->hashBookmark(bookmark);
99 }
100 // -------------------------------------------------------------------------
101 // ::com::sun::star::sdbcx::XDeleteRows
deleteRows(const Sequence<Any> & rows,const connectivity::OSQLTable &)102 Sequence< sal_Int32 > SAL_CALL OBookmarkSet::deleteRows( const Sequence< Any >& rows ,const connectivity::OSQLTable& /*_xTable*/) throw(SQLException, RuntimeException)
103 {
104     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::deleteRows" );
105     Reference< ::com::sun::star::sdbcx::XDeleteRows> xDeleteRow(m_xRowLocate,UNO_QUERY);
106     if(xDeleteRow.is())
107     {
108         return xDeleteRow->deleteRows(rows);
109     }
110     return Sequence< sal_Int32 >();
111 }
112 // -------------------------------------------------------------------------
insertRow(const ORowSetRow & _rInsertRow,const connectivity::OSQLTable &)113 void SAL_CALL OBookmarkSet::insertRow( const ORowSetRow& _rInsertRow,const connectivity::OSQLTable& /*_xTable*/ ) throw(SQLException, RuntimeException)
114 {
115     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::insertRow" );
116     Reference<XRowUpdate> xUpdRow(m_xRowLocate,UNO_QUERY);
117     if(!xUpdRow.is())
118         ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_XROWUPDATE ), SQL_GENERAL_ERROR, *this );
119 
120     Reference<XResultSetUpdate> xUpd(m_xRowLocate,UNO_QUERY);
121     if(xUpd.is())
122     {
123         xUpd->moveToInsertRow();
124         sal_Int32 i = 1;
125         connectivity::ORowVector< ORowSetValue > ::Vector::iterator aEnd = _rInsertRow->get().end();
126         for(connectivity::ORowVector< ORowSetValue > ::Vector::iterator aIter = _rInsertRow->get().begin()+1;aIter != aEnd;++aIter,++i)
127         {
128             aIter->setSigned(m_aSignedFlags[i-1]);
129             updateColumn(i,xUpdRow,*aIter);
130         }
131         xUpd->insertRow();
132         (*_rInsertRow->get().begin()) = m_xRowLocate->getBookmark();
133     }
134     else
135         ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_XRESULTSETUPDATE ), SQL_GENERAL_ERROR, *this );
136 }
137 // -------------------------------------------------------------------------
updateRow(const ORowSetRow & _rInsertRow,const ORowSetRow & _rOrginalRow,const connectivity::OSQLTable &)138 void SAL_CALL OBookmarkSet::updateRow(const ORowSetRow& _rInsertRow ,const ORowSetRow& _rOrginalRow,const connectivity::OSQLTable& /*_xTable*/  ) throw(SQLException, RuntimeException)
139 {
140     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::updateRow" );
141     //  OCacheSet::updateRow( _rInsertRow,_rOrginalRow,_xTable);
142     Reference<XRowUpdate> xUpdRow(m_xRowLocate,UNO_QUERY);
143     if(!xUpdRow.is())
144         ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_XROWUPDATE ), SQL_GENERAL_ERROR, *this );
145 
146     sal_Int32 i = 1;
147     connectivity::ORowVector< ORowSetValue > ::Vector::const_iterator aOrgIter = _rOrginalRow->get().begin()+1;
148     connectivity::ORowVector< ORowSetValue > ::Vector::iterator aEnd = _rInsertRow->get().end();
149     for(connectivity::ORowVector< ORowSetValue > ::Vector::iterator aIter = _rInsertRow->get().begin()+1;aIter != aEnd;++aIter,++i,++aOrgIter)
150     {
151         aIter->setSigned(aOrgIter->isSigned());
152         updateColumn(i,xUpdRow,*aIter);
153     }
154 
155 
156     Reference<XResultSetUpdate> xUpd(m_xRowLocate,UNO_QUERY);
157     if(xUpd.is())
158         xUpd->updateRow();
159     else
160         ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_XRESULTSETUPDATE ), SQL_GENERAL_ERROR, *this );
161 }
162 // -------------------------------------------------------------------------
deleteRow(const ORowSetRow &,const connectivity::OSQLTable &)163 void SAL_CALL OBookmarkSet::deleteRow(const ORowSetRow& /*_rDeleteRow*/ ,const connectivity::OSQLTable& /*_xTable*/  ) throw(SQLException, RuntimeException)
164 {
165     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::deleteRow" );
166     Reference<XResultSetUpdate> xUpd(m_xRowLocate,UNO_QUERY);
167 
168     xUpd->deleteRow();
169 }
170 // -------------------------------------------------------------------------
cancelRowUpdates()171 void SAL_CALL OBookmarkSet::cancelRowUpdates(  ) throw(SQLException, RuntimeException)
172 {
173     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::cancelRowUpdates" );
174 }
175 // -------------------------------------------------------------------------
moveToInsertRow()176 void SAL_CALL OBookmarkSet::moveToInsertRow(  ) throw(SQLException, RuntimeException)
177 {
178     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::moveToInsertRow" );
179     Reference<XResultSetUpdate> xUpd(m_xRowLocate,UNO_QUERY);
180     if(xUpd.is())
181         xUpd->moveToInsertRow();
182 }
183 // -------------------------------------------------------------------------
moveToCurrentRow()184 void SAL_CALL OBookmarkSet::moveToCurrentRow(  ) throw(SQLException, RuntimeException)
185 {
186     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::moveToCurrentRow" );
187 }
188 // -------------------------------------------------------------------------
fillValueRow(ORowSetRow & _rRow,sal_Int32 _nPosition)189 void OBookmarkSet::fillValueRow(ORowSetRow& _rRow,sal_Int32 _nPosition)
190 {
191     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::fillValueRow" );
192     OCacheSet::fillValueRow(_rRow,_nPosition);
193 }
194 // -------------------------------------------------------------------------
updateColumn(sal_Int32 nPos,Reference<XRowUpdate> _xParameter,const ORowSetValue & _rValue)195 void OBookmarkSet::updateColumn(sal_Int32 nPos,Reference< XRowUpdate > _xParameter,const ORowSetValue& _rValue)
196 {
197     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::updateColumn" );
198     if(_rValue.isBound() && _rValue.isModified())
199     {
200         if(_rValue.isNull())
201             _xParameter->updateNull(nPos);
202         else
203         {
204 
205             switch(_rValue.getTypeKind())
206             {
207                 case DataType::DECIMAL:
208                 case DataType::NUMERIC:
209                     _xParameter->updateNumericObject(nPos,_rValue.makeAny(),m_xSetMetaData->getScale(nPos));
210                     break;
211                 case DataType::CHAR:
212                 case DataType::VARCHAR:
213                 //case DataType::DECIMAL:
214                 //case DataType::NUMERIC:
215                     _xParameter->updateString(nPos,_rValue);
216                     break;
217                 case DataType::BIGINT:
218                     if ( _rValue.isSigned() )
219                         _xParameter->updateLong(nPos,_rValue);
220                     else
221                         _xParameter->updateString(nPos,_rValue);
222                     break;
223                 case DataType::BIT:
224                 case DataType::BOOLEAN:
225                     _xParameter->updateBoolean(nPos,_rValue);
226                     break;
227                 case DataType::TINYINT:
228                     if ( _rValue.isSigned() )
229                         _xParameter->updateByte(nPos,_rValue);
230                     else
231                         _xParameter->updateShort(nPos,_rValue);
232                     break;
233                 case DataType::SMALLINT:
234                     if ( _rValue.isSigned() )
235                         _xParameter->updateShort(nPos,_rValue);
236                     else
237                         _xParameter->updateInt(nPos,_rValue);
238                     break;
239                 case DataType::INTEGER:
240                     if ( _rValue.isSigned() )
241                         _xParameter->updateInt(nPos,_rValue);
242                     else
243                         _xParameter->updateLong(nPos,_rValue);
244                     break;
245                 case DataType::FLOAT:
246                     _xParameter->updateFloat(nPos,_rValue);
247                     break;
248                 case DataType::DOUBLE:
249                 case DataType::REAL:
250                     _xParameter->updateDouble(nPos,_rValue);
251                     break;
252                 case DataType::DATE:
253                     _xParameter->updateDate(nPos,_rValue);
254                     break;
255                 case DataType::TIME:
256                     _xParameter->updateTime(nPos,_rValue);
257                     break;
258                 case DataType::TIMESTAMP:
259                     _xParameter->updateTimestamp(nPos,_rValue);
260                     break;
261                 case DataType::BINARY:
262                 case DataType::VARBINARY:
263                 case DataType::LONGVARBINARY:
264                     _xParameter->updateBytes(nPos,_rValue);
265                     break;
266                 case DataType::BLOB:
267                 case DataType::CLOB:
268                     _xParameter->updateObject(nPos,_rValue.getAny());
269                     break;
270             }
271         }
272     }
273 }
274 
275