LibreOffice Module connectivity (master) 1
Timestamp.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
21#include <java/tools.hxx>
23#include <osl/diagnose.h>
24
25using namespace ::comphelper;
26using namespace connectivity;
27
28//************ Class: java.sql.Date
29
30
31jclass java_sql_Date::theClass = nullptr;
32java_sql_Date::java_sql_Date( const css::util::Date& _rOut ) : java_util_Date( nullptr, nullptr )
33{
35 if( !t.pEnv )
36 return;
37 jvalue args[1];
38 // Convert parameters
39 OUString sDateStr = ::dbtools::DBTypeConversion::toDateString(_rOut);
40 args[0].l = convertwchar_tToJavaString(t.pEnv,sDateStr);
41
42 // Turn of Java-Call for the constructor
43 // initialise temporary variables
44 jobject tempObj;
45 static jmethodID mID(nullptr);
46 if ( !mID )
47 {
48 static const char * const cSignature = "(Ljava/lang/String;)Ljava/sql/Date;";
49 mID = t.pEnv->GetStaticMethodID( getMyClass(), "valueOf", cSignature );
50 }
51 OSL_ENSURE(mID,"Unknown method id!");
52 tempObj = t.pEnv->CallStaticObjectMethod( getMyClass(), mID, args[0].l );
53 saveRef( t.pEnv, tempObj );
54 t.pEnv->DeleteLocalRef( tempObj );
55 // and clean
56}
57
59{}
60
62{
63 return st_getMyClass();
64}
66{
67 // the class needs only be fetched once, that is why it is static
68 if( !theClass )
69 theClass = findMyClass("java/sql/Date");
70 return theClass;
71}
72
73
74java_sql_Date::operator css::util::Date()
75{
77}
78
79
80//************ Class: java.sql.Time
81
82
83jclass java_sql_Time::theClass = nullptr;
84
86{}
87
89{
90 return st_getMyClass();
91}
93{
94 // the class needs only be fetched once, that is why it is static
95 if( !theClass )
96 theClass = findMyClass("java/sql/Time");
97 return theClass;
98}
99java_sql_Time::java_sql_Time( const css::util::Time& _rOut ): java_util_Date( nullptr, nullptr )
100{
102 if( !t.pEnv )
103 return;
104 jvalue args[1];
105 // Convert parameters
106 // java.sql.Time supports only whole seconds...
107 OUString sDateStr = ::dbtools::DBTypeConversion::toTimeStringS(_rOut);
108 args[0].l = convertwchar_tToJavaString(t.pEnv,sDateStr);
109
110 // Turn off Java-Call for the constructor
111 // initialise temporary variables
112 jobject tempObj;
113 static jmethodID mID(nullptr);
114 if ( !mID )
115 {
116 static const char * const cSignature = "(Ljava/lang/String;)Ljava/sql/Time;";
117 mID = t.pEnv->GetStaticMethodID( getMyClass(), "valueOf", cSignature );
118 }
119 OSL_ENSURE(mID,"Unknown method id!");
120 tempObj = t.pEnv->CallStaticObjectMethod( getMyClass(), mID, args[0].l );
121 t.pEnv->DeleteLocalRef(static_cast<jstring>(args[0].l));
122 saveRef( t.pEnv, tempObj );
123 t.pEnv->DeleteLocalRef( tempObj );
124 // and clean
125}
126
127java_sql_Time::operator css::util::Time()
128{
130}
131
132//************ Class: java.sql.Timestamp
133
134
135jclass java_sql_Timestamp::theClass = nullptr;
136
138{}
139
141{
142 return st_getMyClass();
143}
144
146{
147 // the class needs only be fetched once, that is why it is static
148 if( !theClass )
149 theClass = findMyClass("java/sql/Timestamp");
150 return theClass;
151}
152
153java_sql_Timestamp::java_sql_Timestamp(const css::util::DateTime& _rOut)
154 :java_util_Date( nullptr, nullptr )
155{
157 if( !t.pEnv )
158 return;
159 jvalue args[1];
160 // Convert parameters
161 OUString sDateStr = ::dbtools::DBTypeConversion::toDateTimeString(_rOut);
162
163 args[0].l = convertwchar_tToJavaString(t.pEnv,sDateStr);
164
165 // Turn off Java-Call for the constructor
166 // initialise temporary variables
167 jobject tempObj;
168 static jmethodID mID(nullptr);
169 if ( !mID )
170 {
171 static const char * const cSignature = "(Ljava/lang/String;)Ljava/sql/Timestamp;";
172 mID = t.pEnv->GetStaticMethodID( getMyClass(), "valueOf", cSignature );
173 }
174 OSL_ENSURE(mID,"Unknown method id!");
175 tempObj = t.pEnv->CallStaticObjectMethod( getMyClass(), mID, args[0].l );
176
177 saveRef( t.pEnv, tempObj );
178 t.pEnv->DeleteLocalRef( tempObj );
179 // and clean
180}
181
182
183java_sql_Timestamp::operator css::util::DateTime()
184{
186}
187
188
189/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XPropertyListType t
void saveRef(JNIEnv *pEnv, jobject myObj)
Definition: Object.cxx:142
static jclass findMyClass(const char *_pClassName)
Definition: Object.cxx:466
virtual jclass getMyClass() const override
Definition: Timestamp.cxx:61
virtual ~java_sql_Date() override
Definition: Timestamp.cxx:58
static jclass st_getMyClass()
Definition: Timestamp.cxx:65
static jclass st_getMyClass()
Definition: Timestamp.cxx:92
virtual ~java_sql_Time() override
Definition: Timestamp.cxx:85
virtual jclass getMyClass() const override
Definition: Timestamp.cxx:88
java_sql_Time(JNIEnv *pEnv, jobject myObj)
Definition: Timestamp.hxx:62
java_sql_Timestamp(JNIEnv *pEnv, jobject myObj)
Definition: Timestamp.hxx:80
virtual ~java_sql_Timestamp() override
Definition: Timestamp.cxx:137
virtual jclass getMyClass() const override
Definition: Timestamp.cxx:140
jstring convertwchar_tToJavaString(JNIEnv *pEnv, const OUString &Temp)
Definition: tools.cxx:93
OOO_DLLPUBLIC_DBTOOLS OUString toTimeStringS(const css::util::Time &rTime)
OOO_DLLPUBLIC_DBTOOLS OUString toDateString(const css::util::Date &rDate)
OOO_DLLPUBLIC_DBTOOLS css::util::Date toDate(double dVal, const css::util::Date &_rNullDate=getStandardDate())
OOO_DLLPUBLIC_DBTOOLS OUString toDateTimeString(const css::util::DateTime &_rDateTime)
OOO_DLLPUBLIC_DBTOOLS css::util::Time toTime(double dVal, short nDigits=9)
OOO_DLLPUBLIC_DBTOOLS css::util::DateTime toDateTime(double dVal, const css::util::Date &_rNullDate=getStandardDate())
args
OUString toString(OptionInfo const *info)