1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_connectivity.hxx"
30 #include "java/sql/Timestamp.hxx"
31 #include "java/tools.hxx"
32 #include <comphelper/types.hxx>
33 #include "connectivity/dbconversion.hxx"
34 
35 using namespace ::comphelper;
36 using namespace connectivity;
37 //**************************************************************
38 //************ Class: java.sql.Date
39 //**************************************************************
40 const double fMilliSecondsPerDay = 86400000.0;
41 jclass java_sql_Date::theClass = 0;
42 java_sql_Date::java_sql_Date( const ::com::sun::star::util::Date& _rOut ) : java_util_Date( NULL, (jobject)NULL )
43 {
44 	SDBThreadAttach t;
45 	if( !t.pEnv )
46 		return;
47 	jvalue args[1];
48 	// Parameter konvertieren
49 	::rtl::OUString sDateStr;
50 	sDateStr = ::dbtools::DBTypeConversion::toDateString(_rOut);
51 	args[0].l = convertwchar_tToJavaString(t.pEnv,sDateStr);
52 
53 	// Java-Call fuer den Konstruktor absetzen
54 	// temporaere Variable initialisieren
55 	static const char * cSignature = "(Ljava/lang/String;)Ljava/sql/Date;";
56 	jobject tempObj;
57 	static jmethodID mID(NULL);
58 	if ( !mID  )
59 		mID  = t.pEnv->GetStaticMethodID( getMyClass(), "valueOf", cSignature );OSL_ENSURE(mID,"Unknown method id!");
60 	tempObj = t.pEnv->CallStaticObjectMethod( getMyClass(), mID, args[0].l );
61 	saveRef( t.pEnv, tempObj );
62 	t.pEnv->DeleteLocalRef( tempObj );
63 	// und aufraeumen
64 }
65 
66 java_sql_Date::~java_sql_Date()
67 {}
68 
69 jclass java_sql_Date::getMyClass() const
70 {
71 	return st_getMyClass();
72 }
73 jclass java_sql_Date::st_getMyClass()
74 {
75 	// die Klasse muss nur einmal geholt werden, daher statisch
76 	if( !theClass )
77         theClass = findMyClass("java/sql/Date");
78 	return theClass;
79 }
80 // -----------------------------------------------------------------------------
81 
82 java_sql_Date::operator ::com::sun::star::util::Date()
83 {
84 	return ::dbtools::DBTypeConversion::toDate(toString());
85 }
86 
87 //**************************************************************
88 //************ Class: java.sql.Time
89 //**************************************************************
90 
91 jclass java_sql_Time::theClass = 0;
92 
93 java_sql_Time::~java_sql_Time()
94 {}
95 
96 jclass java_sql_Time::getMyClass() const
97 {
98 	return st_getMyClass();
99 }
100 jclass java_sql_Time::st_getMyClass()
101 {
102 	// die Klasse muss nur einmal geholt werden, daher statisch
103 	if( !theClass )
104         theClass = findMyClass("java/sql/Time");
105 	return theClass;
106 }
107 java_sql_Time::java_sql_Time( const ::com::sun::star::util::Time& _rOut ): java_util_Date( NULL, (jobject)NULL )
108 {
109 	SDBThreadAttach t;
110 	if( !t.pEnv )
111 		return;
112 	jvalue args[1];
113 	// Parameter konvertieren
114 	::rtl::OUString sDateStr;
115 	sDateStr = ::dbtools::DBTypeConversion::toTimeString(_rOut);
116 	args[0].l = convertwchar_tToJavaString(t.pEnv,sDateStr);
117 
118 	// Java-Call fuer den Konstruktor absetzen
119 	// temporaere Variable initialisieren
120 	static const char * cSignature = "(Ljava/lang/String;)Ljava/sql/Time;";
121 	jobject tempObj;
122 	static jmethodID mID(NULL);
123 	if ( !mID  )
124 		mID  = t.pEnv->GetStaticMethodID( getMyClass(), "valueOf", cSignature );OSL_ENSURE(mID,"Unknown method id!");
125 	tempObj = t.pEnv->CallStaticObjectMethod( getMyClass(), mID, args[0].l );
126 	t.pEnv->DeleteLocalRef((jstring)args[0].l);
127 	saveRef( t.pEnv, tempObj );
128 	t.pEnv->DeleteLocalRef( tempObj );
129 	// und aufraeumen
130 }
131 // -----------------------------------------------------------------------------
132 java_sql_Time::operator ::com::sun::star::util::Time()
133 {
134 	return ::dbtools::DBTypeConversion::toTime(toString());
135 }
136 //**************************************************************
137 //************ Class: java.sql.Timestamp
138 //**************************************************************
139 
140 jclass java_sql_Timestamp::theClass = 0;
141 
142 java_sql_Timestamp::~java_sql_Timestamp()
143 {}
144 
145 jclass java_sql_Timestamp::getMyClass() const
146 {
147 	return st_getMyClass();
148 }
149 jclass java_sql_Timestamp::st_getMyClass()
150 {
151 	// die Klasse muss nur einmal geholt werden, daher statisch
152 	if( !theClass )
153         theClass = findMyClass("java/sql/Timestamp");
154 	return theClass;
155 }
156 java_sql_Timestamp::java_sql_Timestamp(const ::com::sun::star::util::DateTime& _rOut)
157 				   :java_util_Date( NULL, (jobject)NULL )
158 {
159 		SDBThreadAttach t;
160 	if( !t.pEnv )
161 		return;
162 	jvalue args[1];
163 	// Parameter konvertieren
164 	::rtl::OUString sDateStr;
165 	sDateStr = ::dbtools::DBTypeConversion::toDateTimeString(_rOut);
166 
167 	args[0].l = convertwchar_tToJavaString(t.pEnv,sDateStr);
168 
169 	// Java-Call fuer den Konstruktor absetzen
170 	// temporaere Variable initialisieren
171 	static const char * cSignature = "(Ljava/lang/String;)Ljava/sql/Timestamp;";
172 	jobject tempObj;
173 	static jmethodID mID(NULL);
174 	if ( !mID  )
175 		mID  = t.pEnv->GetStaticMethodID( getMyClass(), "valueOf", cSignature );OSL_ENSURE(mID,"Unknown method id!");
176 	tempObj = t.pEnv->CallStaticObjectMethod( getMyClass(), mID, args[0].l );
177 
178 	saveRef( t.pEnv, tempObj );
179 	t.pEnv->DeleteLocalRef( tempObj );
180 	// und aufraeumen
181 }
182 
183 sal_Int32 java_sql_Timestamp::getNanos()
184 {
185     static jmethodID mID(NULL);
186     return callIntMethod("getNanos",mID);
187 }
188 
189 void java_sql_Timestamp::setNanos( sal_Int32 _par0 )
190 {
191     static jmethodID mID(NULL);
192     callVoidMethodWithIntArg("setNanos",mID,_par0);
193 }
194 // -----------------------------------------------------------------------------
195 java_sql_Timestamp::operator ::com::sun::star::util::DateTime()
196 {
197 	return ::dbtools::DBTypeConversion::toDateTime(toString());
198 }
199 // -----------------------------------------------------------------------------
200 
201 
202