Merge lp:~zorba-coders/zorba/feature-jdbc-tables into lp:zorba/jdbc-module

Proposed by Matthias Brantner
Status: Merged
Approved by: Rodolfo Ochoa
Approved revision: 48
Merged at revision: 50
Proposed branch: lp:~zorba-coders/zorba/feature-jdbc-tables
Merge into: lp:zorba/jdbc-module
Diff against target: 424 lines (+240/-5)
10 files modified
include/javaids.h (+8/-2)
include/jdbc.h (+4/-0)
include/sqltypes.h (+1/-0)
include/tables.h (+63/-0)
src/jdbc.xq (+46/-0)
src/jdbc.xq.src/connection/tables.cpp (+68/-0)
src/jdbc.xq.src/javaids.cpp (+7/-0)
src/jdbc.xq.src/jdbc.cpp (+22/-0)
src/jdbc.xq.src/jsonitemsequence.cpp (+16/-2)
src/jdbc.xq.src/sqltypes.cpp (+5/-1)
To merge this branch: bzr merge lp:~zorba-coders/zorba/feature-jdbc-tables
Reviewer Review Type Date Requested Status
Rodolfo Ochoa Approve
Matthias Brantner Approve
Review via email: mp+168811@code.launchpad.net

Commit message

- jdbc:tables function to retrieve list of tables
- implement getBoolean to be able to retrieve boolean-typed columns from the database
- slight change to tests in order to make them run independently
- allow for reading MS SQL Server timestamp columns
- optimized creation of base64Binaries avoiding encoding

To post a comment you must log in.
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~zorba-coders/zorba/feature-jdbc-tables into lp:zorba/jdbc-module failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:281 (message):
  Validation queue job feature-jdbc-tables-2013-06-11T21-05-52.162Z is
  finished. The final status was:

  1 tests did not succeed - changes not commited.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Revision history for this message
Matthias Brantner (matthias-brantner) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job feature-jdbc-tables-2013-06-11T21-47-41.751Z is finished. The final status was:

All tests succeeded!

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1, Needs Fixing < 1, Pending < 1, Needs Information < 1, Resubmit < 1. Got: 1 Approve, 1 Pending.

Revision history for this message
Rodolfo Ochoa (rodolfo-ochoa) wrote :

Looks very nice!

review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job feature-jdbc-tables-2013-06-12T02-37-45.473Z is finished. The final status was:

All tests succeeded!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/javaids.h'
2--- include/javaids.h 2013-01-29 21:33:07 +0000
3+++ include/javaids.h 2013-06-11 21:46:25 +0000
4@@ -53,7 +53,7 @@
5 jmethodID close;
6 jmethodID createStatement;
7 jmethodID prepareStatement;
8-
9+ jmethodID getMetadata;
10 };
11 class JavaStatement {
12 public:
13@@ -75,6 +75,7 @@
14 jmethodID beforeFirst;
15 jmethodID next;
16 jmethodID getInt;
17+ jmethodID getBoolean;
18 jmethodID getDouble;
19 jmethodID getString;
20 jmethodID getBLOB;
21@@ -128,7 +129,12 @@
22 jmethodID getBytes;
23 jmethodID length;
24 };
25-
26+class JavaDatabaseMetadata {
27+public:
28+ bool init();
29+ jclass classID;
30+ jmethodID getTables;
31+};
32
33 }}; // namespace zorba, jdbc
34
35
36=== modified file 'include/jdbc.h'
37--- include/jdbc.h 2013-01-29 21:33:07 +0000
38+++ include/jdbc.h 2013-06-11 21:46:25 +0000
39@@ -49,6 +49,7 @@
40 extern JavaStatement jStatement;
41 extern JavaResultSet jResultSet;
42 extern JavaResultSetMetadata jResultSetMetadata;
43+extern JavaDatabaseMetadata jDatabaseMetadata;
44 extern JavaPreparedStatement jPreparedStatement;
45 extern JavaParameterMetadata jParameterMetadata;
46 extern JavaBlob jBlob;
47@@ -107,6 +108,9 @@
48 static String
49 getStringArg(const ExternalFunction::Arguments_t& args, int index);
50
51+ static bool
52+ getOptionalStringArg(const ExternalFunction::Arguments_t& args, int index, String& aRes);
53+
54 static Item
55 getItemArg(const ExternalFunction::Arguments_t& args, int index);
56
57
58=== modified file 'include/sqltypes.h'
59--- include/sqltypes.h 2013-01-29 21:33:07 +0000
60+++ include/sqltypes.h 2013-06-11 21:46:25 +0000
61@@ -73,6 +73,7 @@
62 static bool isFloat(long lType);
63 static bool isString(long lType);
64 static bool isBLOB(long lType);
65+ static bool isBoolean(long lType);
66
67 };
68
69
70=== added file 'include/tables.h'
71--- include/tables.h 1970-01-01 00:00:00 +0000
72+++ include/tables.h 2013-06-11 21:46:25 +0000
73@@ -0,0 +1,63 @@
74+/*
75+ * Copyright 2006-2012 The FLWOR Foundation.
76+ *
77+ * Licensed under the Apache License, Version 2.0 (the "License");
78+ * you may not use this file except in compliance with the License.
79+ * You may obtain a copy of the License at
80+ *
81+ * http://www.apache.org/licenses/LICENSE-2.0
82+ *
83+ * Unless required by applicable law or agreed to in writing, software
84+ * distributed under the License is distributed on an "AS IS" BASIS,
85+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
86+ * See the License for the specific language governing permissions and
87+ * limitations under the License.
88+ */
89+
90+#include <zorba/empty_sequence.h>
91+#include <zorba/external_module.h>
92+#include <zorba/item_factory.h>
93+#include <zorba/zorba.h>
94+
95+#include "JavaVMSingleton.h"
96+
97+
98+namespace zorba
99+{
100+namespace jdbc
101+{
102+
103+class TablesFunction : public ContextualExternalFunction
104+{
105+ private:
106+ const ExternalModule* theModule;
107+ ItemFactory* theFactory;
108+ XmlDataManager* theDataManager;
109+
110+ public:
111+ TablesFunction(const ExternalModule* aModule) :
112+ theModule(aModule),
113+ theFactory(Zorba::getInstance(0)->getItemFactory()),
114+ theDataManager(Zorba::getInstance(0)->getXmlDataManager())
115+ {}
116+
117+ ~TablesFunction()
118+ {}
119+
120+ public:
121+ virtual String getURI() const
122+ { return theModule->getURI(); }
123+
124+ virtual String getLocalName() const
125+ { return "tables"; }
126+
127+ virtual ItemSequence_t
128+ evaluate(const ExternalFunction::Arguments_t& args,
129+ const zorba::StaticContext*,
130+ const zorba::DynamicContext*) const;
131+};
132+
133+
134+
135+}}; // namespace zorba, jdbc
136+
137
138=== modified file 'src/jdbc.xq'
139--- src/jdbc.xq 2013-02-02 04:36:34 +0000
140+++ src/jdbc.xq 2013-06-11 21:46:25 +0000
141@@ -543,3 +543,49 @@
142 :)
143 declare %an:sequential function jdbc:close-dataset(
144 $dataset-id as xs:anyURI) as empty-sequence() external;
145+
146+(:~
147+ : Return the list of tables from a connection
148+ :
149+ : @param $connection-id The identifier to a connection.
150+ : @param $catalog A filter of the catalog name of the tables.
151+ : Send empty-sequence for all tables.
152+ : @param $schema A filter of the schema name of the tables.
153+ : Send empty-sequence for all tables.
154+ : @param $table A filter of the name of the tables.
155+ : Send empty-sequence for all tables.
156+ :
157+ : @error SQL08000 Connection is closed.
158+ : @error SQL001 Descriptive error, see error in attached message.
159+ :
160+ : @return Return an object with the result data rows from the query provided,
161+ : the data rows are defined as follows:
162+ : { column:value* }*
163+ : Every row is represented by an object of column-value representation of the returned SQL result.
164+ :
165+ :)
166+declare %an:sequential function jdbc:tables(
167+ $connection-id as xs:anyURI,
168+ $catalog as xs:string?,
169+ $schema as xs:string?,
170+ $table as xs:string?) as object()* external;
171+
172+(:~
173+ :
174+ : Return the list of tables from a connection
175+ :
176+ : @param $connection-id The identifier to a connection.
177+ :
178+ : @error SQL08000 Connection is closed.
179+ : @error SQL001 Descriptive error, see error in attached message.
180+ :
181+ : @return Return an object with the result data rows from the query provided,
182+ : the data rows are defined as follows:
183+ : { column:value* }*
184+ : Every row is represented by an object of column-value representation of the returned SQL result.
185+ :)
186+declare %an:sequential function jdbc:tables(
187+ $connection-id as xs:anyURI) as object()*
188+{
189+ jdbc:tables($connection-id, (), (), ())
190+};
191
192=== added file 'src/jdbc.xq.src/connection/tables.cpp'
193--- src/jdbc.xq.src/connection/tables.cpp 1970-01-01 00:00:00 +0000
194+++ src/jdbc.xq.src/connection/tables.cpp 2013-06-11 21:46:25 +0000
195@@ -0,0 +1,68 @@
196+/*
197+ * Copyright 2006-2012 The FLWOR Foundation.
198+ *
199+ * Licensed under the Apache License, Version 2.0 (the "License");
200+ * you may not use this file except in compliance with the License.
201+ * You may obtain a copy of the License at
202+ *
203+ * http://www.apache.org/licenses/LICENSE-2.0
204+ *
205+ * Unless required by applicable law or agreed to in writing, software
206+ * distributed under the License is distributed on an "AS IS" BASIS,
207+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
208+ * See the License for the specific language governing permissions and
209+ * limitations under the License.
210+ */
211+
212+#include "tables.h"
213+#include "jdbc.h"
214+#include "jsonitemsequence.h"
215+
216+namespace zorba
217+{
218+namespace jdbc
219+{
220+
221+ItemSequence_t
222+TablesFunction::evaluate(const ExternalFunction::Arguments_t& args,
223+ const zorba::StaticContext* aStaticContext,
224+ const zorba::DynamicContext* aDynamincContext) const
225+{
226+ CHECK_CONNECTION
227+ jobject result=NULL;
228+
229+ JDBC_MODULE_TRY
230+
231+ String lStrUUID = JdbcModule::getStringArg(args, 0);
232+
233+ jobject oConnection = JdbcModule::getObject(aDynamincContext, lStrUUID, INSTANCE_MAP_CONNECTIONS);
234+
235+ jobject oDatabaseMetadata = env->CallObjectMethod(oConnection, jConnection.getMetadata);
236+
237+ String sTemp;
238+ jstring jCatalog = NULL;
239+ if (JdbcModule::getOptionalStringArg(args, 1, sTemp))
240+ {
241+ jCatalog = env->NewStringUTF(sTemp.c_str());
242+ }
243+ jstring jSchema = NULL;
244+ if (JdbcModule::getOptionalStringArg(args, 2, sTemp))
245+ {
246+ jSchema = env->NewStringUTF(sTemp.c_str());
247+ }
248+ jstring jTable = NULL;
249+ if (JdbcModule::getOptionalStringArg(args, 3, sTemp))
250+ {
251+ jTable = env->NewStringUTF(sTemp.c_str());
252+ }
253+ jobjectArray jTypes = env->NewObjectArray(1, env->FindClass("java/lang/String"), env->NewStringUTF("TABLE"));
254+
255+ result = env->CallObjectMethod(oDatabaseMetadata, jDatabaseMetadata.getTables, jCatalog, jSchema, jTable, jTypes);
256+ CHECK_EXCEPTION
257+
258+ JDBC_MODULE_CATCH
259+
260+ return ItemSequence_t(new JSONItemSequence(result));
261+}
262+
263+}}; // namespace zorba, jdbc
264
265=== modified file 'src/jdbc.xq.src/javaids.cpp'
266--- src/jdbc.xq.src/javaids.cpp 2013-01-29 21:33:07 +0000
267+++ src/jdbc.xq.src/javaids.cpp 2013-06-11 21:46:25 +0000
268@@ -43,6 +43,7 @@
269 close = env->GetMethodID(classID, "close", "()V");
270 createStatement = env->GetMethodID(classID, "createStatement", "()Ljava/sql/Statement;");
271 prepareStatement = env->GetMethodID(classID, "prepareStatement", "(Ljava/lang/String;)Ljava/sql/PreparedStatement;");
272+ getMetadata = env->GetMethodID(classID, "getMetaData", "()Ljava/sql/DatabaseMetaData;");
273
274 TRANSACTION_NONE = env->GetStaticIntField(classID, env->GetStaticFieldID(classID, "TRANSACTION_NONE", "I"));
275 TRANSACTION_READ_UNCOMMITTED = env->GetStaticIntField(classID, env->GetStaticFieldID(classID, "TRANSACTION_READ_UNCOMMITTED", "I"));
276@@ -68,6 +69,7 @@
277 beforeFirst = env->GetMethodID(classID, "beforeFirst", "()V");
278 next = env->GetMethodID(classID, "next", "()Z");
279 getInt = env->GetMethodID(classID, "getInt", "(I)I");
280+ getBoolean = env->GetMethodID(classID, "getBoolean", "(I)Z");
281 getDouble = env->GetMethodID(classID, "getDouble", "(I)D");
282 getString = env->GetMethodID(classID, "getString", "(I)Ljava/lang/String;");
283 getBLOB = env->GetMethodID(classID, "getBlob", "(I)Ljava/sql/Blob;");
284@@ -87,6 +89,11 @@
285 COLUMN_NULLABLE_UNKNOWN = env->GetStaticIntField(classID, env->GetStaticFieldID(classID, "columnNullableUnknown", "I"));
286 return true;
287 }
288+ bool JavaDatabaseMetadata::init() {
289+ classID = env->FindClass("java/sql/DatabaseMetaData");
290+ getTables = env->GetMethodID(classID, "getTables", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;)Ljava/sql/ResultSet;");
291+ return true;
292+ }
293 bool JavaPreparedStatement::init() {
294 classID = env->FindClass("java/sql/PreparedStatement");
295 clearParameters = env->GetMethodID(classID, "clearParameters", "()V");
296
297=== modified file 'src/jdbc.xq.src/jdbc.cpp'
298--- src/jdbc.xq.src/jdbc.cpp 2013-06-04 02:17:48 +0000
299+++ src/jdbc.xq.src/jdbc.cpp 2013-06-11 21:46:25 +0000
300@@ -53,6 +53,7 @@
301 #include "metadata.h"
302 #include "resultset.h"
303 #include "closedataset.h"
304+#include "tables.h"
305
306
307 namespace zorba
308@@ -66,6 +67,7 @@
309 JavaStatement jStatement;
310 JavaResultSet jResultSet;
311 JavaResultSetMetadata jResultSetMetadata;
312+JavaDatabaseMetadata jDatabaseMetadata;
313 JavaPreparedStatement jPreparedStatement;
314 JavaParameterMetadata jParameterMetadata;
315 JavaBlob jBlob;
316@@ -181,6 +183,10 @@
317 {
318 lFunc = new CloseDataSetFunction(this);
319 }
320+ else if (localName == "tables")
321+ {
322+ lFunc = new TablesFunction(this);
323+ }
324 }
325 return lFunc;
326 }
327@@ -263,6 +269,21 @@
328 return result;
329 }
330
331+bool
332+JdbcModule::getOptionalStringArg(const ExternalFunction::Arguments_t& args, int index, String& aRes) {
333+ Iterator_t lIter = args[index]->getIterator();
334+ lIter->open();
335+ Item item;
336+ if( lIter->next(item) )
337+ {
338+ aRes = item.getStringValue();
339+ lIter->close();
340+ return true;
341+ }
342+ lIter->close();
343+ return false;
344+}
345+
346 Item
347 JdbcModule::getItemArg(const ExternalFunction::Arguments_t& args, int index) {
348 Item item;
349@@ -331,6 +352,7 @@
350 jStatement.init();
351 jResultSet.init();
352 jResultSetMetadata.init();
353+ jDatabaseMetadata.init();
354 jPreparedStatement.init();
355 jParameterMetadata.init();
356 jBlob.init();
357
358=== modified file 'src/jdbc.xq.src/jsonitemsequence.cpp'
359--- src/jdbc.xq.src/jsonitemsequence.cpp 2013-04-12 22:41:45 +0000
360+++ src/jdbc.xq.src/jsonitemsequence.cpp 2013-06-11 21:46:25 +0000
361@@ -47,6 +47,16 @@
362 env->ReleaseStringUTFChars(oName, cName);
363 CHECK_EXCEPTION
364 columnTypes[i] = env->CallIntMethod(oMetadata, jResultSetMetadata.getColumnType, i+1);
365+
366+ if (columnTypes[i] == SQLTypes::BINARY)
367+ {
368+ jstring oType = (jstring) env->CallObjectMethod(oMetadata, jResultSetMetadata.getColumnTypeName, i+1);
369+ CHECK_EXCEPTION
370+ const char * cType = env->GetStringUTFChars(oType, 0);
371+ CHECK_EXCEPTION
372+ if (strcmp(cType, "timestamp") == 0) columnTypes[i] = SQLTypes::TIMESTAMP;
373+ }
374+
375 CHECK_EXCEPTION
376 }
377 JDBC_MODULE_CATCH
378@@ -71,11 +81,15 @@
379 if (SQLTypes::isInt(columnTypes[i])) {
380 int value = env->CallIntMethod(oResultSet, jResultSet.getInt, i+1);
381 CHECK_EXCEPTION
382- aValue = itemFactory->createInt(value);
383+ aValue = itemFactory->createInteger(value);
384 } else if (SQLTypes::isFloat(columnTypes[i])) {
385 double value = env->CallDoubleMethod(oResultSet, jResultSet.getDouble, i+1);
386 CHECK_EXCEPTION
387 aValue = itemFactory->createDouble(value);
388+ } else if (SQLTypes::isBoolean(columnTypes[i])) {
389+ bool value = env->CallBooleanMethod(oResultSet, jResultSet.getBoolean, i+1);
390+ CHECK_EXCEPTION
391+ aValue = itemFactory->createBoolean(value);
392 } else if (SQLTypes::isString(columnTypes[i])) {
393 jstring sValue = (jstring) env->CallObjectMethod(oResultSet, jResultSet.getString, i+1);
394 CHECK_EXCEPTION
395@@ -95,7 +109,7 @@
396 CHECK_EXCEPTION
397 jbyteArray bytes = (jbyteArray) env->CallObjectMethod(oBlob, jBlob.getBytes, 1, length);
398 CHECK_EXCEPTION
399- const char* byteString = (const char*)(env->GetByteArrayElements(bytes, 0));
400+ const unsigned char* byteString = reinterpret_cast<const unsigned char*>(env->GetByteArrayElements(bytes, 0));
401 aValue = itemFactory->createBase64Binary(byteString, length);
402 } else {
403 aValue = itemFactory->createJSONNull();
404
405=== modified file 'src/jdbc.xq.src/sqltypes.cpp'
406--- src/jdbc.xq.src/sqltypes.cpp 2013-02-02 04:36:34 +0000
407+++ src/jdbc.xq.src/sqltypes.cpp 2013-06-11 21:46:25 +0000
408@@ -118,11 +118,15 @@
409 }
410
411 bool SQLTypes::isInt(long lType){
412- return ( (lType == INTEGER) || (lType==BIGINT) || (lType==TINYINT) || (lType==SMALLINT) || (lType==BIT) );
413+ return ( (lType == INTEGER) || (lType==BIGINT) || (lType==TINYINT) || (lType==SMALLINT) );
414 }
415
416 bool SQLTypes::isFloat(long lType){
417 return ((lType == DECIMAL) || (lType==DOUBLE) || (lType==FLOAT) || (lType==NUMERIC) || (lType==REAL) );
418 }
419
420+bool SQLTypes::isBoolean(long lType){
421+ return ((lType == BOOLEAN) || (lType==BIT) );
422+}
423+
424 }}; // namespace zorba, jdbc

Subscribers

People subscribed via source and target branches

to all changes: