xref: /trunk/main/dbaccess/source/core/api/BookmarkSet.cxx (revision 0a407c2a85aa3a829e52a449aa13b6528fbe055e)
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 #include "BookmarkSet.hxx"
27 #include "core_resource.hxx"
28 #include "core_resource.hrc"
29 #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
30 #include <connectivity/dbexception.hxx>
31 #include <rtl/logfile.hxx>
32 
33 #include <limits>
34 
35 using namespace dbaccess;
36 using namespace ::connectivity;
37 using namespace ::dbtools;
38 using namespace ::com::sun::star::uno;
39 using namespace ::com::sun::star::beans;
40 using namespace ::com::sun::star::sdbc;
41 //  using namespace ::com::sun::star::sdb;
42 using namespace ::com::sun::star::sdbcx;
43 using namespace ::com::sun::star::container;
44 using namespace ::com::sun::star::lang;
45 //  using namespace ::cppu;
46 using namespace ::osl;
47 
48 void OBookmarkSet::construct(const Reference< XResultSet>& _xDriverSet,const ::rtl::OUString& i_sRowSetFilter)
49 {
50     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::construct" );
51     OCacheSet::construct(_xDriverSet,i_sRowSetFilter);
52     m_xRowLocate.set(_xDriverSet,UNO_QUERY);
53 }
54 // -----------------------------------------------------------------------------
55 Any SAL_CALL OBookmarkSet::getBookmark() throw(SQLException, RuntimeException)
56 {
57     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::getBookmark" );
58     return m_xRowLocate->getBookmark();
59 }
60 // -------------------------------------------------------------------------
61 sal_Bool SAL_CALL OBookmarkSet::moveToBookmark( const Any& bookmark ) throw(SQLException, RuntimeException)
62 {
63     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::moveToBookmark" );
64     return m_xRowLocate->moveToBookmark(bookmark);
65 }
66 // -------------------------------------------------------------------------
67 sal_Bool SAL_CALL OBookmarkSet::moveRelativeToBookmark( const Any& bookmark, sal_Int32 rows ) throw(SQLException, RuntimeException)
68 {
69     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::moveRelativeToBookmark" );
70     return m_xRowLocate->moveRelativeToBookmark(bookmark,rows);
71 }
72 // -------------------------------------------------------------------------
73 sal_Int32 SAL_CALL OBookmarkSet::compareBookmarks( const Any& _first, const Any& _second ) throw(SQLException, RuntimeException)
74 {
75     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::compareBookmarks" );
76     return m_xRowLocate->compareBookmarks(_first,_second);
77 }
78 // -------------------------------------------------------------------------
79 sal_Bool SAL_CALL OBookmarkSet::hasOrderedBookmarks(  ) throw(SQLException, RuntimeException)
80 {
81     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::hasOrderedBookmarks" );
82     return m_xRowLocate->hasOrderedBookmarks();
83 }
84 // -------------------------------------------------------------------------
85 sal_Int32 SAL_CALL OBookmarkSet::hashBookmark( const Any& bookmark ) throw(SQLException, RuntimeException)
86 {
87     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::hashBookmark" );
88     return m_xRowLocate->hashBookmark(bookmark);
89 }
90 // -------------------------------------------------------------------------
91 // ::com::sun::star::sdbcx::XDeleteRows
92 Sequence< sal_Int32 > SAL_CALL OBookmarkSet::deleteRows( const Sequence< Any >& rows ,const connectivity::OSQLTable& /*_xTable*/) throw(SQLException, RuntimeException)
93 {
94     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::deleteRows" );
95     Reference< ::com::sun::star::sdbcx::XDeleteRows> xDeleteRow(m_xRowLocate,UNO_QUERY);
96     if(xDeleteRow.is())
97     {
98         return xDeleteRow->deleteRows(rows);
99     }
100     return Sequence< sal_Int32 >();
101 }
102 // -------------------------------------------------------------------------
103 void SAL_CALL OBookmarkSet::insertRow( const ORowSetRow& _rInsertRow,const connectivity::OSQLTable& /*_xTable*/ ) throw(SQLException, RuntimeException)
104 {
105     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::insertRow" );
106     Reference<XRowUpdate> xUpdRow(m_xRowLocate,UNO_QUERY);
107     if(!xUpdRow.is())
108         ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_XROWUPDATE ), SQL_GENERAL_ERROR, *this );
109 
110     Reference<XResultSetUpdate> xUpd(m_xRowLocate,UNO_QUERY);
111     if(xUpd.is())
112     {
113         xUpd->moveToInsertRow();
114         sal_Int32 i = 1;
115         connectivity::ORowVector< ORowSetValue > ::Vector::iterator aEnd = _rInsertRow->get().end();
116         for(connectivity::ORowVector< ORowSetValue > ::Vector::iterator aIter = _rInsertRow->get().begin()+1;aIter != aEnd;++aIter,++i)
117         {
118             aIter->setSigned(m_aSignedFlags[i-1]);
119             updateColumn(i,xUpdRow,*aIter);
120         }
121         xUpd->insertRow();
122         (*_rInsertRow->get().begin()) = m_xRowLocate->getBookmark();
123     }
124     else
125         ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_XRESULTSETUPDATE ), SQL_GENERAL_ERROR, *this );
126 }
127 // -------------------------------------------------------------------------
128 void SAL_CALL OBookmarkSet::updateRow(const ORowSetRow& _rInsertRow ,const ORowSetRow& _rOrginalRow,const connectivity::OSQLTable& /*_xTable*/  ) throw(SQLException, RuntimeException)
129 {
130     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::updateRow" );
131     //  OCacheSet::updateRow( _rInsertRow,_rOrginalRow,_xTable);
132     Reference<XRowUpdate> xUpdRow(m_xRowLocate,UNO_QUERY);
133     if(!xUpdRow.is())
134         ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_XROWUPDATE ), SQL_GENERAL_ERROR, *this );
135 
136     sal_Int32 i = 1;
137     connectivity::ORowVector< ORowSetValue > ::Vector::const_iterator aOrgIter = _rOrginalRow->get().begin()+1;
138     connectivity::ORowVector< ORowSetValue > ::Vector::iterator aEnd = _rInsertRow->get().end();
139     for(connectivity::ORowVector< ORowSetValue > ::Vector::iterator aIter = _rInsertRow->get().begin()+1;aIter != aEnd;++aIter,++i,++aOrgIter)
140     {
141         aIter->setSigned(aOrgIter->isSigned());
142         updateColumn(i,xUpdRow,*aIter);
143     }
144 
145 
146     Reference<XResultSetUpdate> xUpd(m_xRowLocate,UNO_QUERY);
147     if(xUpd.is())
148         xUpd->updateRow();
149     else
150         ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_XRESULTSETUPDATE ), SQL_GENERAL_ERROR, *this );
151 }
152 // -------------------------------------------------------------------------
153 void SAL_CALL OBookmarkSet::deleteRow(const ORowSetRow& /*_rDeleteRow*/ ,const connectivity::OSQLTable& /*_xTable*/  ) throw(SQLException, RuntimeException)
154 {
155     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::deleteRow" );
156     Reference<XResultSetUpdate> xUpd(m_xRowLocate,UNO_QUERY);
157 
158     xUpd->deleteRow();
159 }
160 // -------------------------------------------------------------------------
161 void SAL_CALL OBookmarkSet::cancelRowUpdates(  ) throw(SQLException, RuntimeException)
162 {
163     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::cancelRowUpdates" );
164 }
165 // -------------------------------------------------------------------------
166 void SAL_CALL OBookmarkSet::moveToInsertRow(  ) throw(SQLException, RuntimeException)
167 {
168     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::moveToInsertRow" );
169     Reference<XResultSetUpdate> xUpd(m_xRowLocate,UNO_QUERY);
170     if(xUpd.is())
171         xUpd->moveToInsertRow();
172 }
173 // -------------------------------------------------------------------------
174 void SAL_CALL OBookmarkSet::moveToCurrentRow(  ) throw(SQLException, RuntimeException)
175 {
176     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::moveToCurrentRow" );
177 }
178 // -------------------------------------------------------------------------
179 void OBookmarkSet::fillValueRow(ORowSetRow& _rRow,sal_Int32 _nPosition)
180 {
181     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::fillValueRow" );
182     OCacheSet::fillValueRow(_rRow,_nPosition);
183 }
184 // -------------------------------------------------------------------------
185 void OBookmarkSet::updateColumn(sal_Int32 nPos,Reference< XRowUpdate > _xParameter,const ORowSetValue& _rValue)
186 {
187     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::updateColumn" );
188     if(_rValue.isBound() && _rValue.isModified())
189     {
190         if(_rValue.isNull())
191             _xParameter->updateNull(nPos);
192         else
193         {
194 
195             switch(_rValue.getTypeKind())
196             {
197                 case DataType::DECIMAL:
198                 case DataType::NUMERIC:
199                     _xParameter->updateNumericObject(nPos,_rValue.makeAny(),m_xSetMetaData->getScale(nPos));
200                     break;
201                 case DataType::CHAR:
202                 case DataType::VARCHAR:
203                 //case DataType::DECIMAL:
204                 //case DataType::NUMERIC:
205                     _xParameter->updateString(nPos,_rValue);
206                     break;
207                 case DataType::BIGINT:
208                     if ( _rValue.isSigned() )
209                         _xParameter->updateLong(nPos,_rValue);
210                     else
211                         _xParameter->updateString(nPos,_rValue);
212                     break;
213                 case DataType::BIT:
214                 case DataType::BOOLEAN:
215                     _xParameter->updateBoolean(nPos,_rValue);
216                     break;
217                 case DataType::TINYINT:
218                     if ( _rValue.isSigned() )
219                         _xParameter->updateByte(nPos,_rValue);
220                     else
221                         _xParameter->updateShort(nPos,_rValue);
222                     break;
223                 case DataType::SMALLINT:
224                     if ( _rValue.isSigned() )
225                         _xParameter->updateShort(nPos,_rValue);
226                     else
227                         _xParameter->updateInt(nPos,_rValue);
228                     break;
229                 case DataType::INTEGER:
230                     if ( _rValue.isSigned() )
231                         _xParameter->updateInt(nPos,_rValue);
232                     else
233                         _xParameter->updateLong(nPos,_rValue);
234                     break;
235                 case DataType::FLOAT:
236                     _xParameter->updateFloat(nPos,_rValue);
237                     break;
238                 case DataType::DOUBLE:
239                 case DataType::REAL:
240                     _xParameter->updateDouble(nPos,_rValue);
241                     break;
242                 case DataType::DATE:
243                     _xParameter->updateDate(nPos,_rValue);
244                     break;
245                 case DataType::TIME:
246                     _xParameter->updateTime(nPos,_rValue);
247                     break;
248                 case DataType::TIMESTAMP:
249                     _xParameter->updateTimestamp(nPos,_rValue);
250                     break;
251                 case DataType::BINARY:
252                 case DataType::VARBINARY:
253                 case DataType::LONGVARBINARY:
254                     _xParameter->updateBytes(nPos,_rValue);
255                     break;
256                 case DataType::BLOB:
257                 case DataType::CLOB:
258                     _xParameter->updateObject(nPos,_rValue.getAny());
259                     break;
260             }
261         }
262     }
263 }
264