1*9b5730f6SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*9b5730f6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*9b5730f6SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*9b5730f6SAndrew Rist * distributed with this work for additional information 6*9b5730f6SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*9b5730f6SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*9b5730f6SAndrew Rist * "License"); you may not use this file except in compliance 9*9b5730f6SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*9b5730f6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*9b5730f6SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*9b5730f6SAndrew Rist * software distributed under the License is distributed on an 15*9b5730f6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*9b5730f6SAndrew Rist * KIND, either express or implied. See the License for the 17*9b5730f6SAndrew Rist * specific language governing permissions and limitations 18*9b5730f6SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*9b5730f6SAndrew Rist *************************************************************/ 21*9b5730f6SAndrew Rist 22*9b5730f6SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_connectivity.hxx" 26cdf0e10cSrcweir #include "java/sql/Timestamp.hxx" 27cdf0e10cSrcweir #include "java/tools.hxx" 28cdf0e10cSrcweir #include <comphelper/types.hxx> 29cdf0e10cSrcweir #include "connectivity/dbconversion.hxx" 30cdf0e10cSrcweir 31cdf0e10cSrcweir using namespace ::comphelper; 32cdf0e10cSrcweir using namespace connectivity; 33cdf0e10cSrcweir //************************************************************** 34cdf0e10cSrcweir //************ Class: java.sql.Date 35cdf0e10cSrcweir //************************************************************** 36cdf0e10cSrcweir const double fMilliSecondsPerDay = 86400000.0; 37cdf0e10cSrcweir jclass java_sql_Date::theClass = 0; 38cdf0e10cSrcweir java_sql_Date::java_sql_Date( const ::com::sun::star::util::Date& _rOut ) : java_util_Date( NULL, (jobject)NULL ) 39cdf0e10cSrcweir { 40cdf0e10cSrcweir SDBThreadAttach t; 41cdf0e10cSrcweir if( !t.pEnv ) 42cdf0e10cSrcweir return; 43cdf0e10cSrcweir jvalue args[1]; 44cdf0e10cSrcweir // Parameter konvertieren 45cdf0e10cSrcweir ::rtl::OUString sDateStr; 46cdf0e10cSrcweir sDateStr = ::dbtools::DBTypeConversion::toDateString(_rOut); 47cdf0e10cSrcweir args[0].l = convertwchar_tToJavaString(t.pEnv,sDateStr); 48cdf0e10cSrcweir 49cdf0e10cSrcweir // Java-Call fuer den Konstruktor absetzen 50cdf0e10cSrcweir // temporaere Variable initialisieren 51cdf0e10cSrcweir static const char * cSignature = "(Ljava/lang/String;)Ljava/sql/Date;"; 52cdf0e10cSrcweir jobject tempObj; 53cdf0e10cSrcweir static jmethodID mID(NULL); 54cdf0e10cSrcweir if ( !mID ) 55cdf0e10cSrcweir mID = t.pEnv->GetStaticMethodID( getMyClass(), "valueOf", cSignature );OSL_ENSURE(mID,"Unknown method id!"); 56cdf0e10cSrcweir tempObj = t.pEnv->CallStaticObjectMethod( getMyClass(), mID, args[0].l ); 57cdf0e10cSrcweir saveRef( t.pEnv, tempObj ); 58cdf0e10cSrcweir t.pEnv->DeleteLocalRef( tempObj ); 59cdf0e10cSrcweir // und aufraeumen 60cdf0e10cSrcweir } 61cdf0e10cSrcweir 62cdf0e10cSrcweir java_sql_Date::~java_sql_Date() 63cdf0e10cSrcweir {} 64cdf0e10cSrcweir 65cdf0e10cSrcweir jclass java_sql_Date::getMyClass() const 66cdf0e10cSrcweir { 67cdf0e10cSrcweir return st_getMyClass(); 68cdf0e10cSrcweir } 69cdf0e10cSrcweir jclass java_sql_Date::st_getMyClass() 70cdf0e10cSrcweir { 71cdf0e10cSrcweir // die Klasse muss nur einmal geholt werden, daher statisch 72cdf0e10cSrcweir if( !theClass ) 73cdf0e10cSrcweir theClass = findMyClass("java/sql/Date"); 74cdf0e10cSrcweir return theClass; 75cdf0e10cSrcweir } 76cdf0e10cSrcweir // ----------------------------------------------------------------------------- 77cdf0e10cSrcweir 78cdf0e10cSrcweir java_sql_Date::operator ::com::sun::star::util::Date() 79cdf0e10cSrcweir { 80cdf0e10cSrcweir return ::dbtools::DBTypeConversion::toDate(toString()); 81cdf0e10cSrcweir } 82cdf0e10cSrcweir 83cdf0e10cSrcweir //************************************************************** 84cdf0e10cSrcweir //************ Class: java.sql.Time 85cdf0e10cSrcweir //************************************************************** 86cdf0e10cSrcweir 87cdf0e10cSrcweir jclass java_sql_Time::theClass = 0; 88cdf0e10cSrcweir 89cdf0e10cSrcweir java_sql_Time::~java_sql_Time() 90cdf0e10cSrcweir {} 91cdf0e10cSrcweir 92cdf0e10cSrcweir jclass java_sql_Time::getMyClass() const 93cdf0e10cSrcweir { 94cdf0e10cSrcweir return st_getMyClass(); 95cdf0e10cSrcweir } 96cdf0e10cSrcweir jclass java_sql_Time::st_getMyClass() 97cdf0e10cSrcweir { 98cdf0e10cSrcweir // die Klasse muss nur einmal geholt werden, daher statisch 99cdf0e10cSrcweir if( !theClass ) 100cdf0e10cSrcweir theClass = findMyClass("java/sql/Time"); 101cdf0e10cSrcweir return theClass; 102cdf0e10cSrcweir } 103cdf0e10cSrcweir java_sql_Time::java_sql_Time( const ::com::sun::star::util::Time& _rOut ): java_util_Date( NULL, (jobject)NULL ) 104cdf0e10cSrcweir { 105cdf0e10cSrcweir SDBThreadAttach t; 106cdf0e10cSrcweir if( !t.pEnv ) 107cdf0e10cSrcweir return; 108cdf0e10cSrcweir jvalue args[1]; 109cdf0e10cSrcweir // Parameter konvertieren 110cdf0e10cSrcweir ::rtl::OUString sDateStr; 111cdf0e10cSrcweir sDateStr = ::dbtools::DBTypeConversion::toTimeString(_rOut); 112cdf0e10cSrcweir args[0].l = convertwchar_tToJavaString(t.pEnv,sDateStr); 113cdf0e10cSrcweir 114cdf0e10cSrcweir // Java-Call fuer den Konstruktor absetzen 115cdf0e10cSrcweir // temporaere Variable initialisieren 116cdf0e10cSrcweir static const char * cSignature = "(Ljava/lang/String;)Ljava/sql/Time;"; 117cdf0e10cSrcweir jobject tempObj; 118cdf0e10cSrcweir static jmethodID mID(NULL); 119cdf0e10cSrcweir if ( !mID ) 120cdf0e10cSrcweir mID = t.pEnv->GetStaticMethodID( getMyClass(), "valueOf", cSignature );OSL_ENSURE(mID,"Unknown method id!"); 121cdf0e10cSrcweir tempObj = t.pEnv->CallStaticObjectMethod( getMyClass(), mID, args[0].l ); 122cdf0e10cSrcweir t.pEnv->DeleteLocalRef((jstring)args[0].l); 123cdf0e10cSrcweir saveRef( t.pEnv, tempObj ); 124cdf0e10cSrcweir t.pEnv->DeleteLocalRef( tempObj ); 125cdf0e10cSrcweir // und aufraeumen 126cdf0e10cSrcweir } 127cdf0e10cSrcweir // ----------------------------------------------------------------------------- 128cdf0e10cSrcweir java_sql_Time::operator ::com::sun::star::util::Time() 129cdf0e10cSrcweir { 130cdf0e10cSrcweir return ::dbtools::DBTypeConversion::toTime(toString()); 131cdf0e10cSrcweir } 132cdf0e10cSrcweir //************************************************************** 133cdf0e10cSrcweir //************ Class: java.sql.Timestamp 134cdf0e10cSrcweir //************************************************************** 135cdf0e10cSrcweir 136cdf0e10cSrcweir jclass java_sql_Timestamp::theClass = 0; 137cdf0e10cSrcweir 138cdf0e10cSrcweir java_sql_Timestamp::~java_sql_Timestamp() 139cdf0e10cSrcweir {} 140cdf0e10cSrcweir 141cdf0e10cSrcweir jclass java_sql_Timestamp::getMyClass() const 142cdf0e10cSrcweir { 143cdf0e10cSrcweir return st_getMyClass(); 144cdf0e10cSrcweir } 145cdf0e10cSrcweir jclass java_sql_Timestamp::st_getMyClass() 146cdf0e10cSrcweir { 147cdf0e10cSrcweir // die Klasse muss nur einmal geholt werden, daher statisch 148cdf0e10cSrcweir if( !theClass ) 149cdf0e10cSrcweir theClass = findMyClass("java/sql/Timestamp"); 150cdf0e10cSrcweir return theClass; 151cdf0e10cSrcweir } 152cdf0e10cSrcweir java_sql_Timestamp::java_sql_Timestamp(const ::com::sun::star::util::DateTime& _rOut) 153cdf0e10cSrcweir :java_util_Date( NULL, (jobject)NULL ) 154cdf0e10cSrcweir { 155cdf0e10cSrcweir SDBThreadAttach t; 156cdf0e10cSrcweir if( !t.pEnv ) 157cdf0e10cSrcweir return; 158cdf0e10cSrcweir jvalue args[1]; 159cdf0e10cSrcweir // Parameter konvertieren 160cdf0e10cSrcweir ::rtl::OUString sDateStr; 161cdf0e10cSrcweir sDateStr = ::dbtools::DBTypeConversion::toDateTimeString(_rOut); 162cdf0e10cSrcweir 163cdf0e10cSrcweir args[0].l = convertwchar_tToJavaString(t.pEnv,sDateStr); 164cdf0e10cSrcweir 165cdf0e10cSrcweir // Java-Call fuer den Konstruktor absetzen 166cdf0e10cSrcweir // temporaere Variable initialisieren 167cdf0e10cSrcweir static const char * cSignature = "(Ljava/lang/String;)Ljava/sql/Timestamp;"; 168cdf0e10cSrcweir jobject tempObj; 169cdf0e10cSrcweir static jmethodID mID(NULL); 170cdf0e10cSrcweir if ( !mID ) 171cdf0e10cSrcweir mID = t.pEnv->GetStaticMethodID( getMyClass(), "valueOf", cSignature );OSL_ENSURE(mID,"Unknown method id!"); 172cdf0e10cSrcweir tempObj = t.pEnv->CallStaticObjectMethod( getMyClass(), mID, args[0].l ); 173cdf0e10cSrcweir 174cdf0e10cSrcweir saveRef( t.pEnv, tempObj ); 175cdf0e10cSrcweir t.pEnv->DeleteLocalRef( tempObj ); 176cdf0e10cSrcweir // und aufraeumen 177cdf0e10cSrcweir } 178cdf0e10cSrcweir 179cdf0e10cSrcweir sal_Int32 java_sql_Timestamp::getNanos() 180cdf0e10cSrcweir { 181cdf0e10cSrcweir static jmethodID mID(NULL); 182cdf0e10cSrcweir return callIntMethod("getNanos",mID); 183cdf0e10cSrcweir } 184cdf0e10cSrcweir 185cdf0e10cSrcweir void java_sql_Timestamp::setNanos( sal_Int32 _par0 ) 186cdf0e10cSrcweir { 187cdf0e10cSrcweir static jmethodID mID(NULL); 188cdf0e10cSrcweir callVoidMethodWithIntArg("setNanos",mID,_par0); 189cdf0e10cSrcweir } 190cdf0e10cSrcweir // ----------------------------------------------------------------------------- 191cdf0e10cSrcweir java_sql_Timestamp::operator ::com::sun::star::util::DateTime() 192cdf0e10cSrcweir { 193cdf0e10cSrcweir return ::dbtools::DBTypeConversion::toDateTime(toString()); 194cdf0e10cSrcweir } 195cdf0e10cSrcweir // ----------------------------------------------------------------------------- 196cdf0e10cSrcweir 197cdf0e10cSrcweir 198