diff --git a/option/src/app/java_helidon/microprofile-config.properties.j2.tmpl b/option/src/app/java_helidon/microprofile-config.properties.j2.tmpl index f5cdd610..f1daa98e 100644 --- a/option/src/app/java_helidon/microprofile-config.properties.j2.tmpl +++ b/option/src/app/java_helidon/microprofile-config.properties.j2.tmpl @@ -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 %} diff --git a/option/src/app/java_helidon/src/main/java/me/opc/mp/database/Message.java.old b/option/src/app/java_helidon/src/main/java/me/opc/mp/database/Message.java.old deleted file mode 100644 index 84711069..00000000 --- a/option/src/app/java_helidon/src/main/java/me/opc/mp/database/Message.java.old +++ /dev/null @@ -1,31 +0,0 @@ -package me.opc.mp.database; - -public class Message { - - private String message; - - private String greeting; - - public Message() { - } - - public Message(String message) { - this.message = message; - } - - public void setMessage(String message) { - this.message = message; - } - - public String getMessage() { - return this.message; - } - - public void setGreeting(String greeting) { - this.greeting = greeting; - } - - public String getGreeting() { - return this.greeting; - } -} diff --git a/option/src/app/java_helidon4_nosql/src/main/java/me/opc/mp/database/Dept.java b/option/src/app/java_helidon4_nosql/src/main/java/me/opc/mp/database/Dept.java new file mode 100644 index 00000000..973a5450 --- /dev/null +++ b/option/src/app/java_helidon4_nosql/src/main/java/me/opc/mp/database/Dept.java @@ -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; +} \ No newline at end of file diff --git a/option/src/app/java_helidon4_nosql/src/main/java/me/opc/mp/database/DeptRepository.java b/option/src/app/java_helidon4_nosql/src/main/java/me/opc/mp/database/DeptRepository.java new file mode 100644 index 00000000..faa3c8d5 --- /dev/null +++ b/option/src/app/java_helidon4_nosql/src/main/java/me/opc/mp/database/DeptRepository.java @@ -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 { +} \ No newline at end of file diff --git a/option/src/app/java_helidon4_nosql/src/main/java/me/opc/mp/database/DeptResource.j2.java b/option/src/app/java_helidon4_nosql/src/main/java/me/opc/mp/database/DeptResource.j2.java new file mode 100644 index 00000000..e17afbba --- /dev/null +++ b/option/src/app/java_helidon4_nosql/src/main/java/me/opc/mp/database/DeptResource.j2.java @@ -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 getDept() throws Exception { + return deptRepository.findAll().toList(); + } + + @GET + @Path("info") + @Produces(MediaType.TEXT_PLAIN) + public String getInfo() { + return "Java - Helidon - {{ dbName }}"; + } +} diff --git a/option/src/app/java_helidon4_nosql/src/main/java/me/opc/mp/database/FieldAccessStrategy.java b/option/src/app/java_helidon4_nosql/src/main/java/me/opc/mp/database/FieldAccessStrategy.java new file mode 100644 index 00000000..c0d3ff33 --- /dev/null +++ b/option/src/app/java_helidon4_nosql/src/main/java/me/opc/mp/database/FieldAccessStrategy.java @@ -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; + } +} \ No newline at end of file diff --git a/option/src/app/java_helidon4_nosql/src/main/resources/application.yaml b/option/src/app/java_helidon4_nosql/src/main/resources/application.yaml new file mode 100644 index 00000000..5852e277 --- /dev/null +++ b/option/src/app/java_helidon4_nosql/src/main/resources/application.yaml @@ -0,0 +1,9 @@ +# Oracle NoSQL Configuration +jnosql: + keyvalue: + database: beers + document: + database: beers + oracle: + nosql: + host: http://localhost:8080 \ No newline at end of file diff --git a/option/src/j2_macro/java.j2_macro b/option/src/j2_macro/java.j2_macro index a4ee8a57..18d07823 100644 --- a/option/src/j2_macro/java.j2_macro +++ b/option/src/j2_macro/java.j2_macro @@ -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 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 -%}