Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoSQL - Helidon 4 - First version / Java QueryIterable #83

Merged
merged 3 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions option/src/app/java_helidon/microprofile-config.properties.j2.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,18 @@ javax.sql.DataSource.ds1.dataSource.user=##DB_USER##
javax.sql.DataSource.ds1.dataSource.password=##DB_PASSWORD##
{%- endif %}

{%- if db_family == "nosql" %}
# Oracle NoSQL Connection
jnosql.keyvalue.database=dept
jnosql.document.database=dept
jnosql.oracle.nosql.table.read.limit=10
jnosql.oracle.nosql.table.write.limit=10
jnosql.oracle.nosql.table.storage.gb=1
jnosql.oracle.nosql.host=${TF_VAR_nosql_endpoint}
jnosql.oracle.nosql.compartment=${TF_VAR_compartment_ocid}
{%- if deploy_type in ["compute", "kubernetes", "instance_pool"] %}
jnosql.oracle.nosql.deployment=CLOUD_INSTANCE_PRINCIPAL
{%- else %}
jnosql.oracle.nosql.deployment=CLOUD_RESOURCE_PRINCIPAL
{%- endif %}
{%- endif %}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package me.opc.mp.database;

import jakarta.json.bind.annotation.JsonbVisibility;
import jakarta.nosql.*;

@Entity
@JsonbVisibility(FieldAccessStrategy.class)
public class Dept {
@Id
private int deptno;
@Column
private String dname;
@Column
private String loc;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package me.opc.mp.database;

import jakarta.data.repository.Query;
import jakarta.data.repository.Repository;
import org.eclipse.jnosql.databases.oracle.mapping.OracleNoSQLRepository;

@Repository
public interface DeptRepository extends OracleNoSQLRepository<Dept, Integer> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{% import "java.j2_macro" as m with context %}
package me.opc.mp.database;

import jakarta.persistence.*;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;
import jakarta.inject.*;
{{ m.import() }}

/**
* Dept Table
*/
@Path("/")
public class DeptResource {
@Inject
private DeptRepository deptRepository;

@GET
@Path("dept")
@Produces(MediaType.APPLICATION_JSON)
public List<Dept> getDept() throws Exception {
return deptRepository.findAll().toList();
}

@GET
@Path("info")
@Produces(MediaType.TEXT_PLAIN)
public String getInfo() {
return "Java - Helidon - {{ dbName }}";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package me.opc.mp.database;

import jakarta.json.bind.config.PropertyVisibilityStrategy;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class FieldAccessStrategy implements PropertyVisibilityStrategy {
@Override
public boolean isVisible(Field field) {
return true;
}

@Override
public boolean isVisible(Method method) {
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Oracle NoSQL Configuration
jnosql:
keyvalue:
database: beers
document:
database: beers
oracle:
nosql:
host: http://localhost:8080
12 changes: 5 additions & 7 deletions option/src/j2_macro/java.j2_macro
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,10 @@ import javax.json.*;
{%- endmacro -%}

{% macro nosql() -%}
// See https://github.com/oracle/nosql-examples/blob/master/examples-nosql-java-sdk/sqlexamples/QueryData.java
QueryRequest queryRequest = new QueryRequest().setStatement("SELECT deptno, dname, loc FROM dept");
QueryResult queryResult = handle.query(queryRequest);
do {
List<MapValue> results = queryResult.getResults();
for (MapValue row : results) {
rows.add( new Dept( row.get("deptno").asInteger().getValue(), row.get("dname").asString().getValue(), row.get("loc").asString().getValue() ) );
}
} while (!queryRequest.isDone());
QueryIterableResult results = handle.queryIterable(queryRequest);
for (MapValue row : results) {
rows.add( new Dept( row.get("deptno").asInteger().getValue(), row.get("dname").asString().getValue(), row.get("loc").asString().getValue() ) );
}
{%- endmacro -%}