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 #ifndef DBAUI_UPDATEHELPERIMPL_HXX
28 #define DBAUI_UPDATEHELPERIMPL_HXX
29 
30 #include <com/sun/star/sdbc/XResultSetUpdate.hpp>
31 #include <com/sun/star/sdbc/XRowUpdate.hpp>
32 #include <com/sun/star/sdbc/XParameters.hpp>
33 #include <com/sun/star/sdbc/XPreparedStatement.hpp>
34 #include <com/sun/star/sdbc/XRowSet.hpp>
35 #include <com/sun/star/sdbc/XResultSetMetaData.hpp>
36 #include "IUpdateHelper.hxx"
37 #include <rtl/logfile.hxx>
38 
39 namespace dbaui
40 {
41     class ORowUpdateHelper : public IUpdateHelper
42     {
43         ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowUpdate >			m_xRowUpdate;
44         ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSetUpdate >	m_xResultSetUpdate;	//
45     public:
46         ORowUpdateHelper(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRowSet>& _xRowSet)
47             :m_xRowUpdate(_xRowSet,::com::sun::star::uno::UNO_QUERY)
48             ,m_xResultSetUpdate(_xRowSet,::com::sun::star::uno::UNO_QUERY)
49         {
50         }
51         virtual ~ORowUpdateHelper() {}
52         virtual void updateString(sal_Int32 _nPos, const ::rtl::OUString& _sValue)
53         {
54             m_xRowUpdate->updateString(_nPos, _sValue);
55         }
56         virtual void updateDouble(sal_Int32 _nPos,const double& _nValue)
57         {
58             m_xRowUpdate->updateDouble(_nPos, _nValue);
59         }
60         virtual void updateDate(sal_Int32 _nPos,const ::com::sun::star::util::Date& _nValue)
61         {
62             m_xRowUpdate->updateDate(_nPos, _nValue);
63         }
64         virtual void updateTime(sal_Int32 _nPos,const ::com::sun::star::util::Time& _nValue)
65         {
66             m_xRowUpdate->updateTime(_nPos, _nValue);
67         }
68         virtual void updateTimestamp(sal_Int32 _nPos,const ::com::sun::star::util::DateTime& _nValue)
69         {
70             m_xRowUpdate->updateTimestamp(_nPos, _nValue);
71         }
72         virtual void updateInt(sal_Int32 _nPos,const sal_Int32& _nValue)
73         {
74             m_xRowUpdate->updateInt(_nPos, _nValue);
75         }
76         virtual void updateNull(sal_Int32 _nPos, ::sal_Int32)
77         {
78             m_xRowUpdate->updateNull(_nPos);
79         }
80         virtual void moveToInsertRow()
81         {
82             m_xResultSetUpdate->moveToInsertRow();
83         }
84         virtual void insertRow()
85         {
86             m_xResultSetUpdate->insertRow();
87         }
88     };
89 
90     class OParameterUpdateHelper : public IUpdateHelper
91     {
92         ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPreparedStatement >  m_xPrepared;
93         ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XParameters >         m_xParameters;
94 
95     public:
96         OParameterUpdateHelper(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPreparedStatement >& _xPrepared)
97            :m_xPrepared(_xPrepared)
98            ,m_xParameters(_xPrepared,::com::sun::star::uno::UNO_QUERY)
99         {
100         }
101         virtual ~OParameterUpdateHelper() {}
102         virtual void updateString(sal_Int32 _nPos, const ::rtl::OUString& _sValue)
103         {
104             RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OParameterUpdateHelper::updateString" );
105             m_xParameters->setString(_nPos, _sValue);
106         }
107         virtual void updateDouble(sal_Int32 _nPos,const double& _nValue)
108         {
109             RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OParameterUpdateHelper::updateDouble" );
110             m_xParameters->setDouble(_nPos, _nValue);
111         }
112         virtual void updateDate(sal_Int32 _nPos,const ::com::sun::star::util::Date& _nValue)
113         {
114             RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OParameterUpdateHelper::updateDouble" );
115             m_xParameters->setDate(_nPos, _nValue);
116         }
117         virtual void updateTime(sal_Int32 _nPos,const ::com::sun::star::util::Time& _nValue)
118         {
119             RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OParameterUpdateHelper::updateDouble" );
120             m_xParameters->setTime(_nPos, _nValue);
121         }
122         virtual void updateTimestamp(sal_Int32 _nPos,const ::com::sun::star::util::DateTime& _nValue)
123         {
124             RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OParameterUpdateHelper::updateDouble" );
125             m_xParameters->setTimestamp(_nPos, _nValue);
126         }
127         virtual void updateInt(sal_Int32 _nPos,const sal_Int32& _nValue)
128         {
129             RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OParameterUpdateHelper::updateInt" );
130             m_xParameters->setInt(_nPos, _nValue);
131         }
132         virtual void updateNull(sal_Int32 _nPos, ::sal_Int32 sqlType)
133         {
134             RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OParameterUpdateHelper::updateNull" );
135             m_xParameters->setNull(_nPos,sqlType);
136         }
137         virtual void moveToInsertRow()
138         {
139         }
140         virtual void insertRow()
141         {
142             RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "misc", "Ocke.Janssen@sun.com", "OParameterUpdateHelper::insertRow" );
143             m_xPrepared->executeUpdate();
144         }
145     };
146 }
147 
148 #endif // DBAUI_UPDATEHELPERIMPL_HXX
149 
150