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