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