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: Timestamp.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_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
)
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;";
60 static jmethodID
mID(NULL
);
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
);
69 java_sql_Date::~java_sql_Date()
72 jclass
java_sql_Date::getMyClass() const
74 // die Klasse muss nur einmal geholt werden, daher statisch
76 theClass
= findMyClass("java/sql/Date");
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
99 theClass
= findMyClass("java/sql/Time");
103 java_sql_Time::java_sql_Time( const ::com::sun::star::util::Time
& _rOut
): java_util_Date( NULL
, (jobject
)NULL
)
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;";
118 static jmethodID
mID(NULL
);
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
);
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
145 theClass
= findMyClass("java/sql/Timestamp");
149 java_sql_Timestamp::java_sql_Timestamp(const ::com::sun::star::util::DateTime
& _rOut
)
150 :java_util_Date( NULL
, (jobject
)NULL
)
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;";
166 static jmethodID
mID(NULL
);
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
);
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 // -----------------------------------------------------------------------------