Update ooo320-m1
[ooovba.git] / connectivity / source / drivers / jdbc / Timestamp.cxx
blob5a014d12a55c8fbcaa61f7f295f5e2f69a019d5a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: Timestamp.cxx,v $
10 * $Revision: 1.17 $
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_connectivity.hxx"
33 #include "java/sql/Timestamp.hxx"
34 #include "java/tools.hxx"
35 #include <comphelper/types.hxx>
36 #include "connectivity/dbconversion.hxx"
38 using namespace ::comphelper;
39 using namespace connectivity;
40 //**************************************************************
41 //************ Class: java.sql.Date
42 //**************************************************************
43 const double fMilliSecondsPerDay = 86400000.0;
44 jclass java_sql_Date::theClass = 0;
45 java_sql_Date::java_sql_Date( const ::com::sun::star::util::Date& _rOut ) : java_util_Date( NULL, (jobject)NULL )
47 SDBThreadAttach t;
48 if( !t.pEnv )
49 return;
50 jvalue args[1];
51 // Parameter konvertieren
52 ::rtl::OUString sDateStr;
53 sDateStr = ::dbtools::DBTypeConversion::toDateString(_rOut);
54 args[0].l = convertwchar_tToJavaString(t.pEnv,sDateStr);
56 // Java-Call fuer den Konstruktor absetzen
57 // temporaere Variable initialisieren
58 static const char * cSignature = "(Ljava/lang/String;)Ljava/sql/Date;";
59 jobject tempObj;
60 static jmethodID mID(NULL);
61 if ( !mID )
62 mID = t.pEnv->GetStaticMethodID( getMyClass(), "valueOf", cSignature );OSL_ENSURE(mID,"Unknown method id!");
63 tempObj = t.pEnv->CallStaticObjectMethod( getMyClass(), mID, args[0].l );
64 saveRef( t.pEnv, tempObj );
65 t.pEnv->DeleteLocalRef( tempObj );
66 // und aufraeumen
69 java_sql_Date::~java_sql_Date()
72 jclass java_sql_Date::getMyClass() const
74 // die Klasse muss nur einmal geholt werden, daher statisch
75 if( !theClass )
76 theClass = findMyClass("java/sql/Date");
77 return theClass;
79 // -----------------------------------------------------------------------------
81 java_sql_Date::operator ::com::sun::star::util::Date()
83 return ::dbtools::DBTypeConversion::toDate(toString());
86 //**************************************************************
87 //************ Class: java.sql.Time
88 //**************************************************************
90 jclass java_sql_Time::theClass = 0;
92 java_sql_Time::~java_sql_Time()
95 jclass java_sql_Time::getMyClass() const
97 // die Klasse muss nur einmal geholt werden, daher statisch
98 if( !theClass )
99 theClass = findMyClass("java/sql/Time");
100 return theClass;
103 java_sql_Time::java_sql_Time( const ::com::sun::star::util::Time& _rOut ): java_util_Date( NULL, (jobject)NULL )
105 SDBThreadAttach t;
106 if( !t.pEnv )
107 return;
108 jvalue args[1];
109 // Parameter konvertieren
110 ::rtl::OUString sDateStr;
111 sDateStr = ::dbtools::DBTypeConversion::toTimeString(_rOut);
112 args[0].l = convertwchar_tToJavaString(t.pEnv,sDateStr);
114 // Java-Call fuer den Konstruktor absetzen
115 // temporaere Variable initialisieren
116 static const char * cSignature = "(Ljava/lang/String;)Ljava/sql/Time;";
117 jobject tempObj;
118 static jmethodID mID(NULL);
119 if ( !mID )
120 mID = t.pEnv->GetStaticMethodID( getMyClass(), "valueOf", cSignature );OSL_ENSURE(mID,"Unknown method id!");
121 tempObj = t.pEnv->CallStaticObjectMethod( getMyClass(), mID, args[0].l );
122 t.pEnv->DeleteLocalRef((jstring)args[0].l);
123 saveRef( t.pEnv, tempObj );
124 t.pEnv->DeleteLocalRef( tempObj );
125 // und aufraeumen
127 // -----------------------------------------------------------------------------
128 java_sql_Time::operator ::com::sun::star::util::Time()
130 return ::dbtools::DBTypeConversion::toTime(toString());
132 //**************************************************************
133 //************ Class: java.sql.Timestamp
134 //**************************************************************
136 jclass java_sql_Timestamp::theClass = 0;
138 java_sql_Timestamp::~java_sql_Timestamp()
141 jclass java_sql_Timestamp::getMyClass() const
143 // die Klasse muss nur einmal geholt werden, daher statisch
144 if( !theClass )
145 theClass = findMyClass("java/sql/Timestamp");
146 return theClass;
149 java_sql_Timestamp::java_sql_Timestamp(const ::com::sun::star::util::DateTime& _rOut)
150 :java_util_Date( NULL, (jobject)NULL )
152 SDBThreadAttach t;
153 if( !t.pEnv )
154 return;
155 jvalue args[1];
156 // Parameter konvertieren
157 ::rtl::OUString sDateStr;
158 sDateStr = ::dbtools::DBTypeConversion::toDateTimeString(_rOut);
160 args[0].l = convertwchar_tToJavaString(t.pEnv,sDateStr);
162 // Java-Call fuer den Konstruktor absetzen
163 // temporaere Variable initialisieren
164 static const char * cSignature = "(Ljava/lang/String;)Ljava/sql/Timestamp;";
165 jobject tempObj;
166 static jmethodID mID(NULL);
167 if ( !mID )
168 mID = t.pEnv->GetStaticMethodID( getMyClass(), "valueOf", cSignature );OSL_ENSURE(mID,"Unknown method id!");
169 tempObj = t.pEnv->CallStaticObjectMethod( getMyClass(), mID, args[0].l );
171 saveRef( t.pEnv, tempObj );
172 t.pEnv->DeleteLocalRef( tempObj );
173 // und aufraeumen
176 sal_Int32 java_sql_Timestamp::getNanos()
178 static jmethodID mID(NULL);
179 return callIntMethod("getNanos",mID);
182 void java_sql_Timestamp::setNanos( sal_Int32 _par0 )
184 static jmethodID mID(NULL);
185 callVoidMethodWithIntArg("setNanos",mID,_par0);
187 // -----------------------------------------------------------------------------
188 java_sql_Timestamp::operator ::com::sun::star::util::DateTime()
190 return ::dbtools::DBTypeConversion::toDateTime(toString());
192 // -----------------------------------------------------------------------------