Skip to content

Commit

Permalink
[AD-545] JNI Interface to load query metadata (CPP) (#46)
Browse files Browse the repository at this point in the history
### Summary

[AD-545] JNI Interface to load query metadata (CPP)

### Description

Expose JNI Interface for the follow...

```
DocumentDbConnection.getConnectionProperties()

java.util.List
List.size()
List.get(Int)

DocumentDbMqlQueryContext
DocumentDbMqlQueryContext.getAggregateOperationsAsStrings()
DocumentDbMqlQueryContext.getColumnMetadata()
DocumentDbMqlQueryContext.getCollectionName()
DocumentDbMqlQueryContext.getPaths()

JdbcColumnMetadata
JdbcColumnMetadata.getOrdinal()
JdbcColumnMetadata.isAutoIncrement()
JdbcColumnMetadata.isCaseSensitive()
JdbcColumnMetadata.isSearchable()
JdbcColumnMetadata.isCurrency()
JdbcColumnMetadata.getNullable()
JdbcColumnMetadata.isSigned()
JdbcColumnMetadata.getColumnDisplaySize()
JdbcColumnMetadata.getColumnLabel()
JdbcColumnMetadata.getColumnName()
JdbcColumnMetadata.getSchemaName()
JdbcColumnMetadata.getPrecision()
JdbcColumnMetadata.getScale()
JdbcColumnMetadata.getTableName()
JdbcColumnMetadata.getCatalogName()
JdbcColumnMetadata.getColumnType()
JdbcColumnMetadata.getColumnTypeName()
JdbcColumnMetadata.isReadOnly()
JdbcColumnMetadata.isWritable;()
JdbcColumnMetadata.isDefinitelyWritable()
JdbcColumnMetadata.getColumnClassName()

DocumentDbQueryMappingService
DocumentDbQueryMappingService.DocumentDbQueryMappingService(DocumentDbConnection, DocumetDbDatabaseMetadata)
DocumentDbQueryMappingService.get()
```

### Related Issue

https://bitquill.atlassian.net/browse/AD-545
https://bitquill.atlassian.net/browse/AD-590

* [AD-587] JNI Interface to load query metadata (CPP)

* [AD-587] JNI Interface to load query metadata (CPP)

* [AD-545] Correct MacOS build issues. Remove unused interfaces.

* [AD-545] Comments and code clean up.

* [AD-545] Comments and code clean up.

* [AD-545] Comments and code clean up.

* [AD-545] Revert some changes not supported in C++ 11.

* [AD-545] Improve error reporting when setting up JNI context.

* [AD-545] Change JDBC driver version for MacOS.

* [AD-545] Clean-up

* [AD-545] Improvement on error handling getting connection.

* [AD-545] Corrections from code review comments.
  • Loading branch information
Bruce Irschick authored Mar 17, 2022
1 parent e6429aa commit db566bf
Show file tree
Hide file tree
Showing 27 changed files with 2,405 additions and 84 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/mac-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ env:
DOC_DB_LOCAL_PORT: 27019
DOC_DB_REMOTE_PORT: 27017
DOC_DB_PRIV_KEY_FILE: ~/certs/docdb-sshtunnel.pem
JDBC_DRIVER_VERSION: "1.1.1"
JDBC_DRIVER_VERSION: "1.2.0"

jobs:
build-mac:
Expand Down
2 changes: 1 addition & 1 deletion build_mac_debug64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ cmake ../src -DCMAKE_BUILD_TYPE="Debug" -DCODE_COVERAGE="ON" -DBUILD_SHARED_LIBS
cd ..

# Download the DocumentDB JDBC Driver
JDBC_DRIVER_VERSION="${JDBC_DRIVER_VERSION-1.1.1}"
JDBC_DRIVER_VERSION="${JDBC_DRIVER_VERSION-1.2.0}"
JDBC_DRIVER_FILENAME="documentdb-jdbc-$JDBC_DRIVER_VERSION-all.jar"
JDBC_DRIVER_FULLPATH="$DRIVER_BIN_DIR/libs/$JDBC_DRIVER_FILENAME"
export DOCUMENTDB_HOME="$DRIVER_BIN_DIR"
Expand Down
2 changes: 1 addition & 1 deletion build_mac_release64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ cmake ../src -DCMAKE_BUILD_TYPE="$BUILD_TYPE" -DCODE_COVERAGE="OFF" -DBUILD_SHAR
make -j 4

# Download the DocumentDB JDBC Driver
JDBC_DRIVER_VERSION="${JDBC_DRIVER_VERSION-1.1.1}"
JDBC_DRIVER_VERSION="${JDBC_DRIVER_VERSION-1.2.0}"
JDBC_DRIVER_FILENAME="documentdb-jdbc-$JDBC_DRIVER_VERSION-all.jar"
JDBC_DRIVER_FULLPATH="$DRIVER_BIN_DIR/libs/$JDBC_DRIVER_FILENAME"
export DOCUMENTDB_HOME="$DRIVER_BIN_DIR"
Expand Down
2 changes: 1 addition & 1 deletion scripts/build_windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ $DRIVER_BIN_DIR = "$DRIVER_BUILD_DIR\..\bin\$CONFIGURATION"
New-Item -Path $DRIVER_BIN_DIR -ItemType Directory -Force | Out-Null

# Download the JDBC driver
$JDBC_DRIVER_VERSION = if ($JDBC_DRIVER_VERSION -eq $null) { "1.1.1" } else { $JDBC_DRIVER_VERSION }
$JDBC_DRIVER_VERSION = if ($JDBC_DRIVER_VERSION -eq $null) { "1.2.0" } else { $JDBC_DRIVER_VERSION }
$JDBC_DRIVER_FILENAME = "documentdb-jdbc-$JDBC_DRIVER_VERSION-all.jar"
$JDBC_DRIVER_FULLPATH = "$DRIVER_BIN_DIR\libs\$JDBC_DRIVER_FILENAME"
if (-not (Test-Path -Path $JDBC_DRIVER_FULLPATH -PathType Leaf)) {
Expand Down
2 changes: 2 additions & 0 deletions src/odbc-test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ set(SOURCES
../odbc/src/ignite_error.cpp
../odbc/src/jni/database_metadata.cpp
../odbc/src/jni/documentdb_connection.cpp
../odbc/src/jni/documentdb_mql_query_context.cpp
../odbc/src/jni/documentdb_query_mapping_service.cpp
../odbc/src/jni/java.cpp
../odbc/src/jni/result_set.cpp
../odbc/src/log.cpp
Expand Down
3 changes: 2 additions & 1 deletion src/odbc-test/src/java_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ struct JavaTestSuiteFixture : OdbcTestSuite {
using OdbcTestSuite::OdbcTestSuite;

SharedPointer< JniContext > GetJniContext(std::vector< char* >& opts) const {
JniErrorInfo errInfo;
SharedPointer< JniContext > ctx(JniContext::Create(
&opts[0], static_cast< int >(opts.size()), JniHandlers()));
&opts[0], static_cast< int >(opts.size()), JniHandlers(), errInfo));
BOOST_CHECK(ctx.Get() != nullptr);
return ctx;
}
Expand Down
437 changes: 436 additions & 1 deletion src/odbc-test/src/jni_test.cpp

Large diffs are not rendered by default.

15 changes: 7 additions & 8 deletions src/odbc-test/src/meta_queries_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,9 @@ struct MetaQueriesTestSuiteFixture : public odbc::OdbcTestSuite {
/**
* Constructor.
*/
MetaQueriesTestSuiteFixture() : grid(0), cache1(0), cache2(0) {
}
MetaQueriesTestSuiteFixture() = default;

bool WasNull(const SQLLEN length) {
bool WasNull(const SQLLEN length) const {
return (length == SQL_NULL_DATA);
}

Expand Down Expand Up @@ -221,7 +220,7 @@ struct MetaQueriesTestSuiteFixture : public odbc::OdbcTestSuite {
const std::string &expName,
SQLSMALLINT expDataType,
SQLULEN expSize, SQLSMALLINT expScale,
SQLSMALLINT expNullability) {
SQLSMALLINT expNullability) const {
std::vector< SQLCHAR > name(ODBC_BUFFER_SIZE);
SQLSMALLINT nameLen = 0;
SQLSMALLINT dataType = 0;
Expand Down Expand Up @@ -343,7 +342,7 @@ struct MetaQueriesTestSuiteFixture : public odbc::OdbcTestSuite {
SQLLEN nullability;

SQLRETURN ret = SQLColAttribute(stmt, idx, SQL_DESC_NAME, &name[0],
(SQLSMALLINT)name.size(), &nameLen, 0);
(SQLSMALLINT)name.size(), &nameLen, nullptr);
ODBC_FAIL_ON_ERROR(ret, SQL_HANDLE_STMT, stmt);

ret = SQLColAttribute(stmt, idx, SQL_DESC_TYPE, 0, 0, 0, &dataType);
Expand Down Expand Up @@ -451,13 +450,13 @@ struct MetaQueriesTestSuiteFixture : public odbc::OdbcTestSuite {
}

/** Node started during the test. */
Ignite grid;
Ignite grid = nullptr;

/** Frist cache instance. */
Cache< int64_t, TestType > cache1;
Cache< int64_t, TestType > cache1 = nullptr;

/** Second cache instance. */
Cache< int64_t, ComplexType > cache2;
Cache< int64_t, ComplexType > cache2 = nullptr;
};

BOOST_FIXTURE_TEST_SUITE(MetaQueriesTestSuite, MetaQueriesTestSuiteFixture)
Expand Down
6 changes: 2 additions & 4 deletions src/odbc-test/src/queries_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ struct QueriesTestSuiteFixture : odbc::OdbcTestSuite {
/**
* Destructor.
*/
virtual ~QueriesTestSuiteFixture() {
// No-op.
}
~QueriesTestSuiteFixture() override = default;

template < typename T >
void CheckTwoRowsInt(SQLSMALLINT type) {
Expand All @@ -93,7 +91,7 @@ struct QueriesTestSuiteFixture : odbc::OdbcTestSuite {

// Binding columns.
for (SQLSMALLINT i = 0; i < columnsCnt; ++i) {
ret = SQLBindCol(stmt, i + 1, type, &columns[i], sizeof(columns[i]), 0);
ret = SQLBindCol(stmt, i + 1, type, &columns[i], sizeof(columns[i]), nullptr);

if (!SQL_SUCCEEDED(ret))
BOOST_FAIL(GetOdbcErrorMessage(SQL_HANDLE_STMT, stmt));
Expand Down
5 changes: 5 additions & 0 deletions src/odbc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ set(SOURCES src/app/application_data_buffer.cpp
src/diagnostic/diagnostic_record_storage.cpp
src/jni/database_metadata.cpp
src/jni/documentdb_connection.cpp
src/jni/documentdb_connection_properties.cpp
src/jni/documentdb_database_metadata.cpp
src/jni/documentdb_mql_query_context.cpp
src/jni/documentdb_query_mapping_service.cpp
src/jni/jdbc_column_metadata.cpp
src/jni/java.cpp
src/jni/result_set.cpp
src/environment.cpp
Expand Down
2 changes: 1 addition & 1 deletion src/odbc/include/ignite/odbc/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ class Connection : public diagnostic::DiagnosableAdapter {
*
* @return JNI context.
*/
SharedPointer< JniContext > GetJniContext();
SharedPointer< JniContext > GetJniContext(JniErrorInfo& errInfo);

/**
* De-initializes the JVM options
Expand Down
1 change: 1 addition & 0 deletions src/odbc/include/ignite/odbc/jni/database_metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace jni {
*/
class DatabaseMetaData {
friend class DocumentDbConnection;
friend class DocumentDbQueryMappingService;

public:
~DatabaseMetaData() = default;
Expand Down
17 changes: 17 additions & 0 deletions src/odbc/include/ignite/odbc/jni/documentdb_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include <ignite/odbc/common/concurrent.h>
#include <ignite/odbc/config/configuration.h>
#include <ignite/odbc/jni/database_metadata.h>
#include <ignite/odbc/jni/documentdb_connection_properties.h>
#include <ignite/odbc/jni/documentdb_database_metadata.h>
#include <ignite/odbc/jni/java.h>

#ifndef _IGNITE_ODBC_JNI_DOCUMENTDB_CONNECTION
Expand Down Expand Up @@ -89,6 +91,21 @@ class DocumentDbConnection {
*/
JniErrorCode GetSshLocalPort(int32_t& localPort, JniErrorInfo& errInfo);

/**
* Gets the connection properties.
*
* @return the connection properties
*/
SharedPointer< DocumentDbConnectionProperties > GetConnectionProperties(JniErrorInfo& errInfo);

/**
* Gets the DocumentDb Database Metadata (different from JDBC Database MetaData)
*
* @return the DocumentDb database metadata.
*/
SharedPointer< DocumentDbDatabaseMetadata > GetDatabaseMetadata(
JniErrorInfo& errInfo);

private:
/** The JNI context */
SharedPointer< JniContext > _jniContext;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <ignite/odbc/common/concurrent.h>
#include <ignite/odbc/jni/java.h>
#include <ignite/odbc/jni/result_set.h>

#include <string>

#ifndef _IGNITE_ODBC_JNI_DOCUMENTDB_CONNECTION_PROPERTIES
#define _IGNITE_ODBC_JNI_DOCUMENTDB_CONNECTION_PROPERTIES

using ignite::odbc::common::concurrent::SharedPointer;
using ignite::odbc::jni::ResultSet;
using ignite::odbc::jni::java::GlobalJObject;
using ignite::odbc::jni::java::JniContext;
using ignite::odbc::jni::java::JniErrorInfo;

namespace ignite {
namespace odbc {
namespace jni {
/**
* Wrapper for the the DocumentDB connection properties.
*/
class DocumentDbConnectionProperties {
friend class DocumentDbConnection;
friend class DocumentDbQueryMappingService;

public:
~DocumentDbConnectionProperties() = default;

private:
/**
* Constructs an instance of the DocumentDbConnectionProperties class.
*/
DocumentDbConnectionProperties(
SharedPointer< JniContext >& jniContext,
SharedPointer< GlobalJObject >& connectionProperties)
: _jniContext(jniContext), _connectionProperties(connectionProperties) {
}

/** The JNI context */
SharedPointer< JniContext > _jniContext;

/** The DocumentDbConnectionProperties Java object */
SharedPointer< GlobalJObject > _connectionProperties;
};
} // namespace jni
} // namespace odbc
} // namespace ignite

#endif // _IGNITE_ODBC_JNI_DOCUMENTDB_CONNECTION_PROPERTIES
69 changes: 69 additions & 0 deletions src/odbc/include/ignite/odbc/jni/documentdb_database_metadata.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <ignite/odbc/common/concurrent.h>
#include <ignite/odbc/jni/java.h>
#include <ignite/odbc/jni/result_set.h>

#include <string>

#ifndef _IGNITE_ODBC_JNI_DOCUMENTDB_DATABASE_METADATA
#define _IGNITE_ODBC_JNI_DOCUMENTDB_DATABASE_METADATA

using ignite::odbc::common::concurrent::SharedPointer;
using ignite::odbc::jni::ResultSet;
using ignite::odbc::jni::java::GlobalJObject;
using ignite::odbc::jni::java::JniContext;
using ignite::odbc::jni::java::JniErrorInfo;

namespace ignite {
namespace odbc {
namespace jni {
/**
* Wrapper for the the DocumentDB database metadata.
*/
class DocumentDbDatabaseMetadata {
friend class DocumentDbConnection;
friend class DocumentDbQueryMappingService;

public:
/**
* Destructs a DocumentDbDatabaseMetadata instance.
*/
~DocumentDbDatabaseMetadata() = default;

private:
/**
* Constructs an instance of the DocumentDbDatabaseMetadata class.
*/
DocumentDbDatabaseMetadata(
SharedPointer< JniContext >& jniContext,
SharedPointer< GlobalJObject >& databaseMetadata)
: _jniContext(jniContext), _databaseMetadata(databaseMetadata) {
}

/** The JNI context */
SharedPointer< JniContext > _jniContext;

/** The DocumentDbDatabaseMetadata Java object */
SharedPointer< GlobalJObject > _databaseMetadata;
};
} // namespace jni
} // namespace odbc
} // namespace ignite

#endif // _IGNITE_ODBC_JNI_DOCUMENTDB_DATABASE_METADATA
Loading

0 comments on commit db566bf

Please sign in to comment.