Skip to content

Commit

Permalink
Nitrite native support apache#1298
Browse files Browse the repository at this point in the history
  • Loading branch information
JiriOndrusek committed Feb 19, 2021
1 parent c1a7a18 commit 2e187a8
Show file tree
Hide file tree
Showing 24 changed files with 429 additions and 99 deletions.
21 changes: 17 additions & 4 deletions docs/modules/ROOT/pages/reference/extensions/nitrite.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
= Nitrite
:page-aliases: extensions/nitrite.adoc
:cq-artifact-id: camel-quarkus-nitrite
:cq-native-supported: false
:cq-status: Preview
:cq-native-supported: true
:cq-status: Stable
:cq-description: Access Nitrite databases.
:cq-deprecated: false
:cq-jvm-since: 1.0.0
:cq-native-since: n/a
:cq-native-since: 1.7.0

[.badges]
[.badge-key]##JVM since##[.badge-supported]##1.0.0## [.badge-key]##Native##[.badge-unsupported]##unsupported##
[.badge-key]##JVM since##[.badge-supported]##1.0.0## [.badge-key]##Native since##[.badge-supported]##1.7.0##

Access Nitrite databases.

Expand All @@ -32,3 +32,16 @@ Please refer to the above link for usage and configuration details.
----

Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications.

== Usage

If your persistence objects implement `java.io.Serializable`, you have to add configuration of all serializable classes.
There is a new serialization support in GraalVM 21.0. Developers can configure classes
for serialization via the serialization configuration file
`-H:SerializationConfigurationResources=/path/to-serialization-config.json` option. For more
information see https://github.com/oracle/graal/pull/2730[PR with feature].

If your persistence objects implement `org.dizitart.no2.mapper.Mappable`. All classes have to
implement also `java.io.Serializable` and have to be registered for serialization (see previous option),
even though the Java serialization won't be used.

6 changes: 3 additions & 3 deletions docs/modules/ROOT/partials/reference/components/nitrite.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page
:cq-artifact-id: camel-quarkus-nitrite
:cq-artifact-id-base: nitrite
:cq-native-supported: false
:cq-status: Preview
:cq-native-supported: true
:cq-status: Stable
:cq-deprecated: false
:cq-jvm-since: 1.0.0
:cq-native-since: n/a
:cq-native-since: 1.7.0
:cq-camel-part-name: nitrite
:cq-camel-part-title: Nitrite
:cq-camel-part-description: Access Nitrite databases.
Expand Down
1 change: 0 additions & 1 deletion extensions-jvm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@
<module>mllp</module>
<module>mvel</module>
<module>mybatis</module>
<module>nitrite</module>
<module>ognl</module>
<module>openstack</module>
<module>printer</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.camel.quarkus</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,15 @@
*/
package org.apache.camel.quarkus.component.nitrite.deployment;

import io.quarkus.deployment.annotations.BuildProducer;
import java.util.Arrays;
import java.util.List;

import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedClassBuildItem;
import io.quarkus.deployment.pkg.steps.NativeBuild;
import org.apache.camel.quarkus.core.JvmOnlyRecorder;
import org.h2.store.fs.FilePathNio;
import org.jboss.logging.Logger;

class NitriteProcessor {
private static final Logger LOG = Logger.getLogger(NitriteProcessor.class);

private static final String FEATURE = "camel-nitrite";

Expand All @@ -38,25 +33,15 @@ FeatureBuildItem feature() {
return new FeatureBuildItem(FEATURE);
}

/**
* Remove this once this extension starts supporting the native mode.
*/
@BuildStep(onlyIf = NativeBuild.class)
@Record(value = ExecutionTime.RUNTIME_INIT)
void warnJvmInNative(JvmOnlyRecorder recorder) {
JvmOnlyRecorder.warnJvmInNative(LOG, FEATURE); // warn at build time
recorder.warnJvmInNative(FEATURE); // warn at runtime
}

@BuildStep
void runtimeInitializedClasses(BuildProducer<RuntimeInitializedClassBuildItem> runtimeInitializedClasses) {
RuntimeInitializedClassBuildItem runtimeInitializedClass() {
// this class uses a SecureRandom which needs to be initialised at run time
runtimeInitializedClasses.produce(new RuntimeInitializedClassBuildItem("org.dizitart.no2.Security"));
return new RuntimeInitializedClassBuildItem("org.dizitart.no2.Security");
}

@BuildStep
void reflectiveClasses(BuildProducer<ReflectiveClassBuildItem> reflectiveClasses) {
reflectiveClasses.produce(new ReflectiveClassBuildItem(false, false, FilePathNio.class));
List<ReflectiveClassBuildItem> reflectiveClasses() {
return Arrays.asList(new ReflectiveClassBuildItem(false, false, org.h2.store.fs.FilePathNio.class),
new ReflectiveClassBuildItem(true, false, "sun.reflect.ReflectionFactory"));
}

}
5 changes: 3 additions & 2 deletions extensions-jvm/nitrite/pom.xml → extensions/nitrite/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.camel.quarkus</groupId>
Expand All @@ -33,6 +35,5 @@
<modules>
<module>deployment</module>
<module>runtime</module>
<module>integration-test</module>
</modules>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.camel.quarkus</groupId>
Expand All @@ -28,9 +30,11 @@

<artifactId>camel-quarkus-nitrite</artifactId>
<name>Camel Quarkus :: Nitrite :: Runtime</name>
<description>Access Nitrite databases.</description>

<properties>
<camel.quarkus.jvmSince>1.0.0</camel.quarkus.jvmSince>
<camel.quarkus.nativeSince>1.7.0</camel.quarkus.nativeSince>
</properties>

<dependencyManagement>
Expand Down
9 changes: 9 additions & 0 deletions extensions/nitrite/runtime/src/main/doc/usage.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
If your persistence objects implement `java.io.Serializable`, you have to add configuration of all serializable classes.
There is a new serialization support in GraalVM 21.0. Developers can configure classes
for serialization via the serialization configuration file
`-H:SerializationConfigurationResources=/path/to-serialization-config.json` option. For more
information see https://github.com/oracle/graal/pull/2730[PR with feature].

If your persistence objects implement `org.dizitart.no2.mapper.Mappable`. All classes have to
implement also `java.io.Serializable` and have to be registered for serialization (see previous option),
even though the Java serialization won't be used.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[
{
"name" : "org.dizitart.no2.NitriteId"
},
{
"name" : "java.lang.Long"
},
{
"name" : "java.lang.Number"
},
{
"name" : "org.dizitart.no2.Document"
},
{
"name" : "java.util.LinkedHashMap"
},
{
"name" : "java.util.HashMap"
},
{
"name" : "java.util.Date"
},
{
"name" : "java.lang.String"
},
{
"name" : "java.lang.Integer"
},
{
"name" : "org.dizitart.no2.meta.Attributes"
},
{
"name" : "org.dizitart.no2.internals.IndexMetaService$IndexMeta"
},
{
"name" : "java.util.concurrent.atomic.AtomicBoolean"
},
{
"name" : "org.dizitart.no2.Index"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
name: "Camel Nitrite"
description: "Access Nitrite databases"
metadata:
unlisted: true
guide: "https://camel.apache.org/camel-quarkus/latest/reference/extensions/nitrite.html"
categories:
- "integration"
status:
- "preview"
- "stable"
1 change: 1 addition & 0 deletions extensions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@
<module>nats</module>
<module>netty</module>
<module>netty-http</module>
<module>nitrite</module>
<module>nsq</module>
<module>oaipmh</module>
<module>olingo4</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,33 @@
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-build-parent-it</artifactId>
<artifactId>camel-quarkus-integration-tests</artifactId>
<version>1.7.0-SNAPSHOT</version>
<relativePath>../../../poms/build-parent-it/pom.xml</relativePath>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>camel-quarkus-nitrite-integration-test</artifactId>
<name>Camel Quarkus :: Nitrite :: Integration Test</name>
<artifactId>camel-quarkus-integration-test-nitrite</artifactId>
<name>Camel Quarkus :: Integration Tests :: Nitrite</name>
<description>Integration tests for Camel Quarkus Nitrite extension</description>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-bom-test</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
Expand All @@ -39,7 +53,6 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
Expand Down Expand Up @@ -73,4 +86,34 @@
</dependency>
</dependencies>

<profiles>
<profile>
<id>native</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<properties>
<quarkus.package.type>native</quarkus.package.type>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,7 @@
import java.io.Serializable;
import java.util.Date;

import org.dizitart.no2.IndexType;
import org.dizitart.no2.objects.Id;
import org.dizitart.no2.objects.Index;
import org.dizitart.no2.objects.Indices;

@Indices({
@Index(value = "address", type = IndexType.NonUnique),
@Index(value = "name", type = IndexType.Unique)
})
public class Employee implements Serializable, Cloneable {
@Id
private long empId;
public abstract class Employee implements Serializable, Cloneable {

private Date joinDate;

Expand All @@ -42,19 +31,15 @@ public Employee() {
}

public Employee(long empId, Date joinDate, String name, String address) {
this.empId = empId;
setEmpId(empId);
this.joinDate = joinDate;
this.name = name;
this.address = address;
}

public long getEmpId() {
return empId;
}
public abstract long getEmpId();

public void setEmpId(long empId) {
this.empId = empId;
}
public abstract void setEmpId(long empId);

public Date getJoinDate() {
return joinDate;
Expand Down Expand Up @@ -83,7 +68,7 @@ public void setAddress(String address) {
@Override
public String toString() {
return "Employee{" +
"empId=" + empId +
"empId=" + getEmpId() +
", joinDate=" + joinDate +
", name='" + name + '\'' +
", address='" + address + '\'' +
Expand Down
Loading

0 comments on commit 2e187a8

Please sign in to comment.