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
)
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;";
56 static jmethodID
mID(NULL
);
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
);
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
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 return st_getMyClass();
99 jclass
java_sql_Time::st_getMyClass()
101 // the class needs only be fetched once, that is why it is static
103 theClass
= findMyClass("java/sql/Time");
106 java_sql_Time::java_sql_Time( const ::com::sun::star::util::Time
& _rOut
): java_util_Date( NULL
, (jobject
)NULL
)
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;";
121 static jmethodID
mID(NULL
);
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
);
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
153 theClass
= findMyClass("java/sql/Timestamp");
157 java_sql_Timestamp::java_sql_Timestamp(const ::com::sun::star::util::DateTime
& _rOut
)
158 :java_util_Date( NULL
, (jobject
)NULL
)
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;";
174 static jmethodID
mID(NULL
);
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
);
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: */