Skip to content

Commit

Permalink
Merge pull request #83 from mgueury/main
Browse files Browse the repository at this point in the history
NoSQL - Helidon 4 - First version / Java QueryIterable
  • Loading branch information
MarcGueury committed Mar 8, 2024
2 parents 7e4f9e7 + d56096b commit 09a7db4
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 38 deletions.
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 -%}

0 comments on commit 09a7db4

Please sign in to comment.