1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: BookmarkSet.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
33 #ifndef DBACCESS_CORE_API_BOOKMARKSET_HXX
34 #include "BookmarkSet.hxx"
36 #ifndef _DBA_CORE_RESOURCE_HXX_
37 #include "core_resource.hxx"
39 #ifndef _DBA_CORE_RESOURCE_HRC_
40 #include "core_resource.hrc"
42 #ifndef _COM_SUN_STAR_SDBC_XRESULTSETUPDATE_HPP_
43 #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
45 #ifndef _DBHELPER_DBEXCEPTION_HXX_
46 #include <connectivity/dbexception.hxx>
48 #include <rtl/logfile.hxx>
52 using namespace dbaccess
;
53 using namespace ::connectivity
;
54 using namespace ::dbtools
;
55 using namespace ::com::sun::star::uno
;
56 using namespace ::com::sun::star::beans
;
57 using namespace ::com::sun::star::sdbc
;
58 // using namespace ::com::sun::star::sdb;
59 using namespace ::com::sun::star::sdbcx
;
60 using namespace ::com::sun::star::container
;
61 using namespace ::com::sun::star::lang
;
62 // using namespace ::cppu;
63 using namespace ::osl
;
65 void OBookmarkSet::construct(const Reference
< XResultSet
>& _xDriverSet
)
67 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::construct" );
68 OCacheSet::construct(_xDriverSet
);
69 m_xRowLocate
.set(_xDriverSet
,UNO_QUERY
);
71 // -----------------------------------------------------------------------------
72 Any SAL_CALL
OBookmarkSet::getBookmark() throw(SQLException
, RuntimeException
)
74 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::getBookmark" );
75 return m_xRowLocate
->getBookmark();
77 // -------------------------------------------------------------------------
78 sal_Bool SAL_CALL
OBookmarkSet::moveToBookmark( const Any
& bookmark
) throw(SQLException
, RuntimeException
)
80 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::moveToBookmark" );
81 return m_xRowLocate
->moveToBookmark(bookmark
);
83 // -------------------------------------------------------------------------
84 sal_Bool SAL_CALL
OBookmarkSet::moveRelativeToBookmark( const Any
& bookmark
, sal_Int32 rows
) throw(SQLException
, RuntimeException
)
86 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::moveRelativeToBookmark" );
87 return m_xRowLocate
->moveRelativeToBookmark(bookmark
,rows
);
89 // -------------------------------------------------------------------------
90 sal_Int32 SAL_CALL
OBookmarkSet::compareBookmarks( const Any
& _first
, const Any
& _second
) throw(SQLException
, RuntimeException
)
92 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::compareBookmarks" );
93 return m_xRowLocate
->compareBookmarks(_first
,_second
);
95 // -------------------------------------------------------------------------
96 sal_Bool SAL_CALL
OBookmarkSet::hasOrderedBookmarks( ) throw(SQLException
, RuntimeException
)
98 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::hasOrderedBookmarks" );
99 return m_xRowLocate
->hasOrderedBookmarks();
101 // -------------------------------------------------------------------------
102 sal_Int32 SAL_CALL
OBookmarkSet::hashBookmark( const Any
& bookmark
) throw(SQLException
, RuntimeException
)
104 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::hashBookmark" );
105 return m_xRowLocate
->hashBookmark(bookmark
);
107 // -------------------------------------------------------------------------
108 // ::com::sun::star::sdbcx::XDeleteRows
109 Sequence
< sal_Int32
> SAL_CALL
OBookmarkSet::deleteRows( const Sequence
< Any
>& rows
,const connectivity::OSQLTable
& /*_xTable*/) throw(SQLException
, RuntimeException
)
111 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::deleteRows" );
112 Reference
< ::com::sun::star::sdbcx::XDeleteRows
> xDeleteRow(m_xRowLocate
,UNO_QUERY
);
115 return xDeleteRow
->deleteRows(rows
);
117 return Sequence
< sal_Int32
>();
119 // -------------------------------------------------------------------------
120 void SAL_CALL
OBookmarkSet::insertRow( const ORowSetRow
& _rInsertRow
,const connectivity::OSQLTable
& /*_xTable*/ ) throw(SQLException
, RuntimeException
)
122 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::insertRow" );
123 Reference
<XRowUpdate
> xUpdRow(m_xRowLocate
,UNO_QUERY
);
125 ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_XROWUPDATE
), SQL_GENERAL_ERROR
, *this );
127 Reference
<XResultSetUpdate
> xUpd(m_xRowLocate
,UNO_QUERY
);
130 xUpd
->moveToInsertRow();
132 connectivity::ORowVector
< ORowSetValue
> ::Vector::iterator aEnd
= _rInsertRow
->get().end();
133 for(connectivity::ORowVector
< ORowSetValue
> ::Vector::iterator aIter
= _rInsertRow
->get().begin()+1;aIter
!= aEnd
;++aIter
,++i
)
135 aIter
->setSigned(m_aSignedFlags
[i
-1]);
136 updateColumn(i
,xUpdRow
,*aIter
);
139 (*_rInsertRow
->get().begin()) = m_xRowLocate
->getBookmark();
142 ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_XRESULTSETUPDATE
), SQL_GENERAL_ERROR
, *this );
144 // -------------------------------------------------------------------------
145 void SAL_CALL
OBookmarkSet::updateRow(const ORowSetRow
& _rInsertRow
,const ORowSetRow
& _rOrginalRow
,const connectivity::OSQLTable
& /*_xTable*/ ) throw(SQLException
, RuntimeException
)
147 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::updateRow" );
148 // OCacheSet::updateRow( _rInsertRow,_rOrginalRow,_xTable);
149 Reference
<XRowUpdate
> xUpdRow(m_xRowLocate
,UNO_QUERY
);
151 ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_XROWUPDATE
), SQL_GENERAL_ERROR
, *this );
154 connectivity::ORowVector
< ORowSetValue
> ::Vector::const_iterator aOrgIter
= _rOrginalRow
->get().begin()+1;
155 connectivity::ORowVector
< ORowSetValue
> ::Vector::iterator aEnd
= _rInsertRow
->get().end();
156 for(connectivity::ORowVector
< ORowSetValue
> ::Vector::iterator aIter
= _rInsertRow
->get().begin()+1;aIter
!= aEnd
;++aIter
,++i
,++aOrgIter
)
158 aIter
->setSigned(aOrgIter
->isSigned());
159 updateColumn(i
,xUpdRow
,*aIter
);
163 Reference
<XResultSetUpdate
> xUpd(m_xRowLocate
,UNO_QUERY
);
167 ::dbtools::throwSQLException( DBACORE_RESSTRING( RID_STR_NO_XRESULTSETUPDATE
), SQL_GENERAL_ERROR
, *this );
169 // -------------------------------------------------------------------------
170 void SAL_CALL
OBookmarkSet::deleteRow(const ORowSetRow
& /*_rDeleteRow*/ ,const connectivity::OSQLTable
& /*_xTable*/ ) throw(SQLException
, RuntimeException
)
172 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::deleteRow" );
173 Reference
<XResultSetUpdate
> xUpd(m_xRowLocate
,UNO_QUERY
);
177 // -------------------------------------------------------------------------
178 void SAL_CALL
OBookmarkSet::cancelRowUpdates( ) throw(SQLException
, RuntimeException
)
180 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::cancelRowUpdates" );
182 // -------------------------------------------------------------------------
183 void SAL_CALL
OBookmarkSet::moveToInsertRow( ) throw(SQLException
, RuntimeException
)
185 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::moveToInsertRow" );
186 Reference
<XResultSetUpdate
> xUpd(m_xRowLocate
,UNO_QUERY
);
188 xUpd
->moveToInsertRow();
190 // -------------------------------------------------------------------------
191 void SAL_CALL
OBookmarkSet::moveToCurrentRow( ) throw(SQLException
, RuntimeException
)
193 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::moveToCurrentRow" );
195 // -------------------------------------------------------------------------
196 void OBookmarkSet::fillValueRow(ORowSetRow
& _rRow
,sal_Int32 _nPosition
)
198 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::fillValueRow" );
199 OCacheSet::fillValueRow(_rRow
,_nPosition
);
201 // -------------------------------------------------------------------------
202 void OBookmarkSet::updateColumn(sal_Int32 nPos
,Reference
< XRowUpdate
> _xParameter
,const ORowSetValue
& _rValue
)
204 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger
, "dbaccess", "Ocke.Janssen@sun.com", "OBookmarkSet::updateColumn" );
205 if(_rValue
.isBound() && _rValue
.isModified())
208 _xParameter
->updateNull(nPos
);
212 switch(_rValue
.getTypeKind())
214 case DataType::DECIMAL
:
215 case DataType::NUMERIC
:
216 _xParameter
->updateNumericObject(nPos
,_rValue
.makeAny(),m_xSetMetaData
->getScale(nPos
));
219 case DataType::VARCHAR
:
220 //case DataType::DECIMAL:
221 //case DataType::NUMERIC:
222 _xParameter
->updateString(nPos
,_rValue
);
224 case DataType::BIGINT
:
225 if ( _rValue
.isSigned() )
226 _xParameter
->updateLong(nPos
,_rValue
);
228 _xParameter
->updateString(nPos
,_rValue
);
231 case DataType::BOOLEAN
:
232 _xParameter
->updateBoolean(nPos
,_rValue
);
234 case DataType::TINYINT
:
235 if ( _rValue
.isSigned() )
236 _xParameter
->updateByte(nPos
,_rValue
);
238 _xParameter
->updateShort(nPos
,_rValue
);
240 case DataType::SMALLINT
:
241 if ( _rValue
.isSigned() )
242 _xParameter
->updateShort(nPos
,_rValue
);
244 _xParameter
->updateInt(nPos
,_rValue
);
246 case DataType::INTEGER
:
247 if ( _rValue
.isSigned() )
248 _xParameter
->updateInt(nPos
,_rValue
);
250 _xParameter
->updateLong(nPos
,_rValue
);
252 case DataType::FLOAT
:
253 _xParameter
->updateFloat(nPos
,_rValue
);
255 case DataType::DOUBLE
:
257 _xParameter
->updateDouble(nPos
,_rValue
);
260 _xParameter
->updateDate(nPos
,_rValue
);
263 _xParameter
->updateTime(nPos
,_rValue
);
265 case DataType::TIMESTAMP
:
266 _xParameter
->updateTimestamp(nPos
,_rValue
);
268 case DataType::BINARY
:
269 case DataType::VARBINARY
:
270 case DataType::LONGVARBINARY
:
271 _xParameter
->updateBytes(nPos
,_rValue
);