Bump for 3.6-28
[LibreOffice.git] / connectivity / source / drivers / jdbc / Timestamp.cxx
blob0af78c85744963434cac1880862983ff84b3226c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "java/sql/Timestamp.hxx"
30 #include "java/tools.hxx"
31 #include <comphelper/types.hxx>
32 #include "connectivity/dbconversion.hxx"
34 using namespace ::comphelper;
35 using namespace connectivity;
36 //**************************************************************
37 //************ Class: java.sql.Date
38 //**************************************************************
39 const double fMilliSecondsPerDay = 86400000.0;
40 jclass java_sql_Date::theClass = 0;
41 java_sql_Date::java_sql_Date( const ::com::sun::star::util::Date& _rOut ) : java_util_Date( NULL, (jobject)NULL )
43 SDBThreadAttach t;
44 if( !t.pEnv )
45 return;
46 jvalue args[1];
47 // Convert parameters
48 ::rtl::OUString sDateStr;
49 sDateStr = ::dbtools::DBTypeConversion::toDateString(_rOut);
50 args[0].l = convertwchar_tToJavaString(t.pEnv,sDateStr);
52 // Turn of Java-Call for the constructor
53 // initialise temporary variables
54 static const char * cSignature = "(Ljava/lang/String;)Ljava/sql/Date;";
55 jobject tempObj;
56 static jmethodID mID(NULL);
57 if ( !mID )
58 mID = t.pEnv->GetStaticMethodID( getMyClass(), "valueOf", cSignature );OSL_ENSURE(mID,"Unknown method id!");
59 tempObj = t.pEnv->CallStaticObjectMethod( getMyClass(), mID, args[0].l );
60 saveRef( t.pEnv, tempObj );
61 t.pEnv->DeleteLocalRef( tempObj );
62 // and clean
65 java_sql_Date::~java_sql_Date()
68 jclass java_sql_Date::getMyClass() const
70 return st_getMyClass();
72 jclass java_sql_Date::st_getMyClass()
74 // the class needs only be fetched once, that is why it is static
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 return st_getMyClass();
99 jclass java_sql_Time::st_getMyClass()
101 // the class needs only be fetched once, that is why it is static
102 if( !theClass )
103 theClass = findMyClass("java/sql/Time");
104 return theClass;
106 java_sql_Time::java_sql_Time( const ::com::sun::star::util::Time& _rOut ): java_util_Date( NULL, (jobject)NULL )
108 SDBThreadAttach t;
109 if( !t.pEnv )
110 return;
111 jvalue args[1];
112 // Convert parameters
113 ::rtl::OUString sDateStr;
114 sDateStr = ::dbtools::DBTypeConversion::toTimeString(_rOut);
115 args[0].l = convertwchar_tToJavaString(t.pEnv,sDateStr);
117 // Turn off Java-Call for the constructor
118 // intialise temporary variables
119 static const char * cSignature = "(Ljava/lang/String;)Ljava/sql/Time;";
120 jobject tempObj;
121 static jmethodID mID(NULL);
122 if ( !mID )
123 mID = t.pEnv->GetStaticMethodID( getMyClass(), "valueOf", cSignature );OSL_ENSURE(mID,"Unknown method id!");
124 tempObj = t.pEnv->CallStaticObjectMethod( getMyClass(), mID, args[0].l );
125 t.pEnv->DeleteLocalRef((jstring)args[0].l);
126 saveRef( t.pEnv, tempObj );
127 t.pEnv->DeleteLocalRef( tempObj );
128 // and clean
130 // -----------------------------------------------------------------------------
131 java_sql_Time::operator ::com::sun::star::util::Time()
133 return ::dbtools::DBTypeConversion::toTime(toString());
135 //**************************************************************
136 //************ Class: java.sql.Timestamp
137 //**************************************************************
139 jclass java_sql_Timestamp::theClass = 0;
141 java_sql_Timestamp::~java_sql_Timestamp()
144 jclass java_sql_Timestamp::getMyClass() const
146 return st_getMyClass();
149 jclass java_sql_Timestamp::st_getMyClass()
151 // the class needs only be fetched once, that is why it is static
152 if( !theClass )
153 theClass = findMyClass("java/sql/Timestamp");
154 return theClass;
157 java_sql_Timestamp::java_sql_Timestamp(const ::com::sun::star::util::DateTime& _rOut)
158 :java_util_Date( NULL, (jobject)NULL )
160 SDBThreadAttach t;
161 if( !t.pEnv )
162 return;
163 jvalue args[1];
164 // Convert parameters
165 ::rtl::OUString sDateStr;
166 sDateStr = ::dbtools::DBTypeConversion::toDateTimeString(_rOut);
168 args[0].l = convertwchar_tToJavaString(t.pEnv,sDateStr);
170 // Turn off Java-Call for the constructor
171 // initialise temporary variables
172 static const char * cSignature = "(Ljava/lang/String;)Ljava/sql/Timestamp;";
173 jobject tempObj;
174 static jmethodID mID(NULL);
175 if ( !mID )
176 mID = t.pEnv->GetStaticMethodID( getMyClass(), "valueOf", cSignature );OSL_ENSURE(mID,"Unknown method id!");
177 tempObj = t.pEnv->CallStaticObjectMethod( getMyClass(), mID, args[0].l );
179 saveRef( t.pEnv, tempObj );
180 t.pEnv->DeleteLocalRef( tempObj );
181 // and clean
184 // -----------------------------------------------------------------------------
185 java_sql_Timestamp::operator ::com::sun::star::util::DateTime()
187 return ::dbtools::DBTypeConversion::toDateTime(toString());
189 // -----------------------------------------------------------------------------
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */