tdf#150789 - FILEOPEN PPTX: fix text in SmartArt vertically off
[LibreOffice.git] / connectivity / source / drivers / jdbc / Timestamp.cxx
blobeb76247198127cd5e2a13e83fe66ab1a39ae8eb5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <java/sql/Timestamp.hxx>
21 #include <java/tools.hxx>
22 #include <connectivity/dbconversion.hxx>
23 #include <osl/diagnose.h>
25 using namespace ::comphelper;
26 using namespace connectivity;
28 //************ Class: java.sql.Date
31 jclass java_sql_Date::theClass = nullptr;
32 java_sql_Date::java_sql_Date( const css::util::Date& _rOut ) : java_util_Date( nullptr, nullptr )
34 SDBThreadAttach t;
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);
42 // Turn of Java-Call for the constructor
43 // initialise temporary variables
44 jobject tempObj;
45 static jmethodID mID(nullptr);
46 if ( !mID )
48 static const char * const cSignature = "(Ljava/lang/String;)Ljava/sql/Date;";
49 mID = t.pEnv->GetStaticMethodID( getMyClass(), "valueOf", cSignature );
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
58 java_sql_Date::~java_sql_Date()
61 jclass java_sql_Date::getMyClass() const
63 return st_getMyClass();
65 jclass java_sql_Date::st_getMyClass()
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;
74 java_sql_Date::operator css::util::Date()
76 return ::dbtools::DBTypeConversion::toDate(toString());
80 //************ Class: java.sql.Time
83 jclass java_sql_Time::theClass = nullptr;
85 java_sql_Time::~java_sql_Time()
88 jclass java_sql_Time::getMyClass() const
90 return st_getMyClass();
92 jclass java_sql_Time::st_getMyClass()
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;
99 java_sql_Time::java_sql_Time( const css::util::Time& _rOut ): java_util_Date( nullptr, nullptr )
101 SDBThreadAttach t;
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);
110 // Turn off Java-Call for the constructor
111 // initialise temporary variables
112 jobject tempObj;
113 static jmethodID mID(nullptr);
114 if ( !mID )
116 static const char * const cSignature = "(Ljava/lang/String;)Ljava/sql/Time;";
117 mID = t.pEnv->GetStaticMethodID( getMyClass(), "valueOf", cSignature );
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
127 java_sql_Time::operator css::util::Time()
129 return ::dbtools::DBTypeConversion::toTime(toString());
132 //************ Class: java.sql.Timestamp
135 jclass java_sql_Timestamp::theClass = nullptr;
137 java_sql_Timestamp::~java_sql_Timestamp()
140 jclass java_sql_Timestamp::getMyClass() const
142 return st_getMyClass();
145 jclass java_sql_Timestamp::st_getMyClass()
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;
153 java_sql_Timestamp::java_sql_Timestamp(const css::util::DateTime& _rOut)
154 :java_util_Date( nullptr, nullptr )
156 SDBThreadAttach t;
157 if( !t.pEnv )
158 return;
159 jvalue args[1];
160 // Convert parameters
161 OUString sDateStr = ::dbtools::DBTypeConversion::toDateTimeString(_rOut);
163 args[0].l = convertwchar_tToJavaString(t.pEnv,sDateStr);
165 // Turn off Java-Call for the constructor
166 // initialise temporary variables
167 jobject tempObj;
168 static jmethodID mID(nullptr);
169 if ( !mID )
171 static const char * const cSignature = "(Ljava/lang/String;)Ljava/sql/Timestamp;";
172 mID = t.pEnv->GetStaticMethodID( getMyClass(), "valueOf", cSignature );
174 OSL_ENSURE(mID,"Unknown method id!");
175 tempObj = t.pEnv->CallStaticObjectMethod( getMyClass(), mID, args[0].l );
177 saveRef( t.pEnv, tempObj );
178 t.pEnv->DeleteLocalRef( tempObj );
179 // and clean
183 java_sql_Timestamp::operator css::util::DateTime()
185 return ::dbtools::DBTypeConversion::toDateTime(toString());
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */