Latest commit adab473 Jun 27, 2018
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
README.adoc Update README.adoc Jun 27, 2018

README.adoc

WildFly NoSQL

Introduction

The goal of wildfly-nosql, is no-nonsense improvements focused on making the developer’s life easier when using NoSQL on https://github.com/wildfly/wildfly
https://github.com/wildfly-swarm/wildfly-swarm. In particular, not to hide and abstract the underlying NoSQL APIs but to give simple and natural access to them. The configuration allows NoSQL database connection profiles to be defined, to be used by applications. The CDI access simplifies application access to the defined NoSQL database connection profiles.

Connection pooling

Connections to NoSQL database servers are managed by the underlying native NoSQL drivers. Connection pooling is provided directly by the native NoSQL drivers.

Define NoSQL connection profiles

Each NoSQL connection profile uniquely names the profile id, which can be used to @Inject @Named("id") the connection into your application code.

Each NoSQL connection profile (optionally) specifies the module name that contains the native NoSQL driver classes, which is important for working with other software that may presume different NoSQL driver module names. If the module is not specified, a default name is used.

   @Inject @Named("MyMongoDB") MongoDatabase database;
   @Inject @Named("MyCassandra") Cluster cluster;
   @Inject @Named("MyOrientDBPool") OPartitionedDatabasePool pool;
   @Inject @Named("MyNeo4j") Driver database;

Each NoSQL connection profile uniquely names the JNDI lookup jndi-name, which can be easily used by application code.

   @Resource(lookup = "java:jboss/cassandra/MyDB")  Cluster cluster;
   @Resource(lookup = "java:jboss/mongodb/MyDB") MongoDatabase database;
   @Resource(lookup = "java:jboss/neo4j/MyDB") Driver database;
   @Resource(lookup = "java:jboss/orientdb/MyDB")  OPartitionedDatabasePool pool;

WildFly

Currently, WildFly 11 integration is available, as a feature pack distribution (see below feature pack artifacts).

Each defined connection profile, is shared by all applications deployed to the WildFly application server. The underlying (native) NoSQL class instance(s) that represent the connection profile, are associated with the connection profile id and jndi-name.

WildFly MongoDB feature pack

<groupId>org.wildfly.nosql</groupId>
<artifactId>wildfly-mongodb-feature-pack</artifactId>
<version>1.0.0.Beta1</version>
<name>WildFly: MongoDB Feature Pack</name>
<groupId>org.wildfly.nosql</groupId>
<artifactId>wildfly-mongodb-driver-feature-pack</artifactId>
<version>1.0.0.Beta1</version>
<name>WildFly: MongoDB driver Feature Pack</name>

WildFly Cassandra feature pack

<groupId>org.wildfly.nosql</groupId>
<artifactId>wildfly-cassandra-feature-pack</artifactId>
<version>1.0.0.Beta1</version>
<name>WildFly: Cassandra Feature Pack</name>
<groupId>org.wildfly.nosql</groupId>
<artifactId>wildfly-cassandra-driver-feature-pack</artifactId>
<version>1.0.0.Beta1</version>
<name>WildFly: Cassandra driver Feature Pack</name>

WildFly OrientDB feature pack

<groupId>org.wildfly.nosql</groupId>
<artifactId>wildfly-orientdb-feature-pack</artifactId>
<version>1.0.0.Beta1</version>
<name>WildFly: OrientDB Feature Pack</name>
<groupId>org.wildfly.nosql</groupId>
<artifactId>wildfly-orientdb-driver-feature-pack</artifactId>
<version>1.0.0.Beta1</version>
<name>WildFly: OrientDB driver Feature Pack</name>

WildFly Neo4j feature pack

<groupId>org.wildfly.nosql</groupId>
<artifactId>wildfly-neo4j-feature-pack</artifactId>
<version>1.0.0.Beta1</version>
<name>WildFly: Neo4j Feature Pack</name>
<groupId>org.wildfly.nosql</groupId>
<artifactId>wildfly-neo4j-driver-feature-pack</artifactId>
<version>1.0.0.Beta1</version>
<name>WildFly: Neo4j driver Feature Pack</name>

WildFly Swarm

WildFly Swarm has one deployment per app server instance, therefore, the defined connection profiles are only used by application deployment.

You get to bring your own NoSQL driver. In fact, you must bring your own NoSQL driver. All that’s required though is just adding it as a normal Maven dependency to your project ( check the below Java driver version table to make sure it will work).

Example pom.xml dependencies for each NoSQL fraction:

  <dependencies>
    <dependency>
      <groupId>org.wildfly.swarm</groupId>
      <artifactId>mongodb</artifactId>
    </dependency>
    <dependency>
      <groupId>org.mongodb</groupId>
      <artifactId>mongo-java-driver</artifactId>
      <version>${version.mongodb.driver}</version>
    </dependency>
  </dependencies>
 <dependencies>
    <dependency>
      <groupId>org.wildfly.swarm</groupId>
      <artifactId>cassandra</artifactId>
    </dependency>
    <dependency>
      <groupId>com.datastax.cassandra</groupId>
      <artifactId>cassandra-driver-core</artifactId>
      <version>${version.cassandra.driver}</version>
    </dependency>
  </dependencies>
 <dependencies>
    <dependency>
      <groupId>org.wildfly.swarm</groupId>
      <artifactId>neo4j</artifactId>
 </dependency>
    <dependency>
      <groupId>org.neo4j.driver</groupId>
      <artifactId>neo4j-java-driver</artifactId>
      <version>${version.neo4j.driver}</version>
    </dependency>
 </dependencies>
    <dependencies>
        <dependency>
            <groupId>org.wildfly.swarm</groupId>
            <artifactId>orientdb</artifactId>
        </dependency>

        <dependency>
            <groupId>com.orientechnologies</groupId>
            <artifactId>orientdb-core</artifactId>
        </dependency>

        <dependency>
            <groupId>com.orientechnologies</groupId>
            <artifactId>orientdb-graphdb</artifactId>
        </dependency>

        <dependency>
            <groupId>com.orientechnologies</groupId>
            <artifactId>orientdb-object</artifactId>
        </dependency>

        <dependency>
            <groupId>com.orientechnologies</groupId>
            <artifactId>orientdb-client</artifactId>
        </dependency>

        <dependency>
            <groupId>com.tinkerpop.blueprints</groupId>
            <artifactId>blueprints-core</artifactId>
        </dependency>

        <dependency>
            <groupId>com.googlecode.concurrentlinkedhashmap</groupId>
            <artifactId>concurrentlinkedhashmap-lru</artifactId>
        </dependency>

Creating the connection profiles

MongoDB Java driver versions

Table 1. MongoDB Java driver (org.mongodb:mongo-java-driver).
Version WildFly WildFly Swarm

3.0.3

NO

YES

3.2.2

YES

YES

3.3.0

NO

YES

3.4.2

NO

YES

Connecting to MongoDB from WildFly

The mongodb subsystem may define multiple MongoDB connection profiles, that are used to obtain com.mongodb.MongoClient
com.mongodb.client.MongoDatabase class instances that represent each defined profile. The MongoClient/MongoDatabase classes are thread safe and can be shared by multiple deployed applications.

<!-- example of WildFly MongoDB client subsystem defining two profiles. -->
<subsystem xmlns="urn:jboss:domain:mongodb:1.0">
    <mongo name="default" id="mongodbtestprofile" jndi-name="java:jboss/mongodb/test" database="mongotestdb" security-domain="mongoRealm" auth-type="DEFAULT" ssl="false" >
        <host name="default" outbound-socket-binding-ref="mongotesthost"/>
        <properties name="default">
            <property name="writeConcern" value="ACKNOWLEDGED"/>
            <property name="readConcern" value="LOCAL"/>
        </properties>
    </mongo>
    <mongo name="default2" id="mongodbsales" jndi-name="java:jboss/mongodb/sales" database="mongotestdb" security-domain="mongoRealm" auth-type="DEFAULT" ssl="false" >
        <host name="default2" outbound-socket-binding-ref="mongotesthost"/>
    </mongo>
</subsystem>

Connecting to MongoDB from WildFly Swarm

Refer to Wildfly Swarm documentation for org.wildfly.swarm.mongodb.MongoDBFraction

Minimal example:

// Main.java
package org.wildflynosql.demo.rest;

import java.util.HashMap;

import org.wildfly.swarm.Swarm;
import org.wildfly.swarm.config.mongodb.Mongo;
import org.wildfly.swarm.config.mongodb.mongo.Host;
import org.wildfly.swarm.config.security.Flag;
import org.wildfly.swarm.config.security.SecurityDomain;
import org.wildfly.swarm.config.security.security_domain.ClassicAuthentication;
import org.wildfly.swarm.config.security.security_domain.authentication.LoginModule;
import org.wildfly.swarm.mongodb.MongoDBFraction;
import org.wildfly.swarm.security.SecurityFraction;
import org.wildfly.swarm.spi.api.OutboundSocketBinding;

public class Main {

    public static void main(String... args) throws Exception {
        Swarm swarm = new Swarm(args)
            .outboundSocketBinding("standard-sockets",
                new OutboundSocketBinding("mongotesthost")
                    .remoteHost("localhost")
                    .remotePort(27017))
            .fraction(SecurityFraction.defaultSecurityFraction()
                .securityDomain(
                    new SecurityDomain("mongoRealm")
                        .classicAuthentication(
                            new ClassicAuthentication().loginModule(
                                new LoginModule("ConfiguredIdentity").code("ConfiguredIdentity")
                                    .flag(Flag.REQUIRED)
                                    .moduleOptions(new HashMap<Object, Object>() {
                                       {
                                           put("principal", "devuser");
                                           put("username", "devuser");
                                           put("password", "changethis");
                                       }
                                   }
                                )
                            )
                        )
                    )
                )
            .fraction(new MongoDBFraction()
                .mongo(new Mongo("mongodbtestprofile")
                    .host(new Host("mongotesthost")
                        .outboundSocketBindingRef("mongotesthost")
                        )
                    .database("mongotestdb")
                    .jndiName("java:jboss/mongodb/test")
                    .id("mongodbtestprofile")
                    .securityDomain("mongoRealm")
                        // .authType(Mongo.AuthType.GSSAPI)
                        // .authType(Mongo.AuthType.PLAIN_SASL)
                        // .authType(Mongo.AuthType.SCRAM_SHA_1)
                        // .authType(Mongo.AuthType.MONGODB_CR)
                        // .authType(Mongo.AuthType.MONGODB_X509)
                        .authType(Mongo.AuthType.DEFAULT)
                        .ssl(false)
                    )
            ).fraction(new org.wildfly.swarm.ee.EEFraction())
            .start()
            .deploy();
    }
}
// HelloWorldEndpoint.java
package org.wildflynosql.demo.rest;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.inject.Named;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;

import com.mongodb.client.MongoDatabase;

@ApplicationScoped
@Path("/hello")
public class HelloWorldEndpoint {

    @Inject @Named("mongodbtestprofile")
    MongoDatabase database;

    @GET
    @Produces("text/plain")
    public Response doGet() {
        return Response.ok("Hello from WildFly Swarm! database = " + database).build();
    }
}
<!-- pom.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.wildflynosql</groupId>
  <artifactId>demo</artifactId>
  <name>WildFly Swarm Example</name>
  <version>1.0.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <properties>
    <version.wildfly.swarm>2017.6.0-SNAPSHOT</version.wildfly.swarm>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <failOnMissingWebXml>false</failOnMissingWebXml>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <version.mongodb.driver>3.2.2</version.mongodb.driver>
    <version.org.glassfish.javax.json>1.0.3</version.org.glassfish.javax.json>
  </properties>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.wildfly.swarm</groupId>
        <artifactId>bom-all</artifactId>
        <version>${version.wildfly.swarm}</version>
        <scope>import</scope>
        <type>pom</type>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <build>
    <finalName>demo</finalName>
    <plugins>
      <plugin>
        <groupId>org.wildfly.swarm</groupId>
        <artifactId>wildfly-swarm-plugin</artifactId>
        <version>${version.wildfly.swarm}</version>
        <configuration>
          <mainClass>org.wildflynosql.demo.rest.Main</mainClass>
        </configuration>

        <executions>
          <execution>
            <goals>
              <goal>package</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <dependencies>
    <!-- Java EE 7 dependency -->
    <dependency>
      <groupId>javax</groupId>
      <artifactId>javaee-api</artifactId>
      <version>7.0</version>
      <scope>provided</scope>
    </dependency>
    <!-- WildFly Swarm Fractions -->
    <dependency>
      <groupId>org.wildfly.swarm</groupId>
      <artifactId>jaxrs-jsonp</artifactId>
    </dependency>

    <dependency>
      <groupId>org.wildfly.swarm</groupId>
      <artifactId>jsonp</artifactId>
    </dependency>

    <dependency>
      <groupId>org.glassfish</groupId>
      <artifactId>javax.json</artifactId>
      <version>${version.org.glassfish.javax.json}</version>
    </dependency>
    <dependency>
      <groupId>org.wildfly.swarm</groupId>
      <artifactId>mongodb</artifactId>
    </dependency>
    <dependency>
      <groupId>org.mongodb</groupId>
      <artifactId>mongo-java-driver</artifactId>
      <version>${version.mongodb.driver}</version>
    </dependency>

  </dependencies>
</project>
<!-- empty beans.xml -->
<beans xmlns="http://java.sun.com/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="
      http://java.sun.com/xml/ns/javaee
      http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
</beans>

Cassandra Java driver versions

Table 2. Cassandra Java driver (com.datastax.cassandra:cassandra-driver-core).
Version WildFly WildFly Swarm

3.0.0

YES

YES

Connecting to Cassandra from WildFly

The cassandradriver subsystem may define multiple Cassandra connection profiles, that are used to obtain com.datastax.driver.core.Cluster
com.datastax.driver.core.Session class instances that represent each defined profile. The Cluster/Session classes are thread safe and can be shared by multiple deployed applications.

<!-- example of WildFly Cassandra client subsystem defining profile. -->
<subsystem xmlns="urn:jboss:domain:cassandradriver:1.0">
    <cassandra name="default" id="cassandratestprofile" jndi-name="java:jboss/cassandradriver/test" ssl="true">
        <host name="default" outbound-socket-binding-ref="casstesthost"/>
    </cassandra>
</subsystem>

Connecting to Cassandra from WildFly Swarm

Refer to Wildfly Swarm documentation for org.wildfly.swarm.cassandra.CassandraFraction

Minimal example:

// Main.java
package org.wildflynosql.demo.rest;

import java.util.HashMap;

import org.wildfly.swarm.Swarm;
import org.wildfly.swarm.config.cassandradriver.Cassandra;
import org.wildfly.swarm.config.cassandradriver.cassandra.Host;
import org.wildfly.swarm.config.security.Flag;
import org.wildfly.swarm.config.security.SecurityDomain;
import org.wildfly.swarm.config.security.security_domain.ClassicAuthentication;
import org.wildfly.swarm.config.security.security_domain.authentication.LoginModule;
import org.wildfly.swarm.cassandra.CassandraFraction;
import org.wildfly.swarm.security.SecurityFraction;
import org.wildfly.swarm.spi.api.OutboundSocketBinding;

public class Main {

    public static void main(String... args) throws Exception {
        Swarm swarm = new Swarm(args)
            .outboundSocketBinding("standard-sockets",
                new OutboundSocketBinding("casstesthost")
                    .remoteHost("localhost")
                    .remotePort(9042))
            .fraction(SecurityFraction.defaultSecurityFraction()
                .securityDomain(
                    new SecurityDomain("cassandraRealm")
                        .classicAuthentication(
                            new ClassicAuthentication().loginModule(
                                new LoginModule("ConfiguredIdentity").code("ConfiguredIdentity")
                                    .flag(Flag.REQUIRED)
                                    .moduleOptions(new HashMap<Object, Object>() {
                                       {
                                           put("principal", "devuser");
                                           put("username", "devuser");
                                           put("password", "changethis");
                                       }
                                   }
                                )
                            )
                        )
                    )
                )
            .fraction(new CassandraFraction()
                .cassandra(new Cassandra("cassandratestprofile")
                    .host(new Host("casstesthost")
                        .outboundSocketBindingRef("casstesthost")
                        )
                    .jndiName("java:jboss/cassandradriver/test")
                    .id("cassandratestprofile")
                    .securityDomain("mongoRealm")
                    .ssl(false)
                    )
            ).fraction(new org.wildfly.swarm.ee.EEFraction())
            .start()
            .deploy();
    }
}
// HelloWorldEndpoint.java
package org.wildflynosql.demo.rest;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.inject.Named;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;

import com.datastax.driver.core.Cluster;

@ApplicationScoped
@Path("/hello")
public class HelloWorldEndpoint {

    @Inject @Named("cassandratestprofile")
    Cluster cluster;

    @GET
    @Produces("text/plain")
    public Response doGet() {
        return Response.ok("Hello from WildFly Swarm! cluster = " + cluster).build();
    }
}
<!-- pom.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.wildflynosql</groupId>
  <artifactId>demo</artifactId>
  <name>WildFly Swarm Example</name>
  <version>1.0.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <properties>
    <version.wildfly.swarm>2017.6.0-SNAPSHOT</version.wildfly.swarm>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <failOnMissingWebXml>false</failOnMissingWebXml>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <version.cassandra.driver>3.0.0</version.cassandra.driver>
    <version.org.glassfish.javax.json>1.0.3</version.org.glassfish.javax.json>
  </properties>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.wildfly.swarm</groupId>
        <artifactId>bom-all</artifactId>
        <version>${version.wildfly.swarm}</version>
        <scope>import</scope>
        <type>pom</type>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <build>
    <finalName>demo</finalName>
    <plugins>
      <plugin>
        <groupId>org.wildfly.swarm</groupId>
        <artifactId>wildfly-swarm-plugin</artifactId>
        <version>${version.wildfly.swarm}</version>
        <configuration>
          <mainClass>org.wildflynosql.demo.rest.Main</mainClass>
        </configuration>

        <executions>
          <execution>
            <goals>
              <goal>package</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <dependencies>
    <!-- Java EE 7 dependency -->
    <dependency>
      <groupId>javax</groupId>
      <artifactId>javaee-api</artifactId>
      <version>7.0</version>
      <scope>provided</scope>
    </dependency>
    <!-- WildFly Swarm Fractions -->
    <dependency>
      <groupId>org.wildfly.swarm</groupId>
      <artifactId>jaxrs-jsonp</artifactId>
    </dependency>

    <dependency>
      <groupId>org.wildfly.swarm</groupId>
      <artifactId>jsonp</artifactId>
    </dependency>

    <dependency>
      <groupId>org.glassfish</groupId>
      <artifactId>javax.json</artifactId>
      <version>${version.org.glassfish.javax.json}</version>
    </dependency>
    <dependency>
      <groupId>org.wildfly.swarm</groupId>
      <artifactId>cassandra</artifactId>
    </dependency>
    <dependency>
        <groupId>com.datastax.cassandra</groupId>
        <artifactId>cassandra-driver-core</artifactId>
        <version>${version.cassandra.driver}</version>
    </dependency>

  </dependencies>
</project>
<!-- empty beans.xml -->
<beans xmlns="http://java.sun.com/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="
      http://java.sun.com/xml/ns/javaee
      http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
</beans>

OrientDB Java driver versions

Table 3. OrientDB Java driver (com.orientechnologies:orientdb-core, com.orientechnologies:orientdb-graphdb, com.orientechnologies:orientdb-object, com.orientechnologies:orientdb-client).
Version WildFly WildFly Swarm

2.2.9

YES

YES

Connecting to OrientDB from WildFly

The orientdb subsystem may define multiple OrientDB connection profiles, that are used to obtain com.orientechnologies.orient.core.db.OPartitionedDatabasePool class instances that represent each defined profile. The OPartitionedDatabasePool class is thread safe and can be shared by multiple deployed applications.

Warning
The OrientDB client API, is heavily dependent on keeping one OrientDB database open per Java thread. When your application is done with the database, you must close the OrientDB database to disassociate it from the Java thread, or the open database will still be open by that Java thread, when the Java thread is returned to the Java thread pool. A max of one OrientDB database can be open per Java thread, so if you open a different database, the current one will be automatically closed first.
<!-- example of WildFly OrientDB client subsystem defining profile. -->
<subsystem xmlns="urn:jboss:domain:orientdb:1.0">
    <orient name="default" id="orientdbtestprofile" database="test" jndi-name="java:jboss/orientdb/test" security-domain="orientRealm" max-partition-size="64" max-pool-size="-1">
        <host name="default" outbound-socket-binding-ref="orienttesthost"/>
    </orient>
</subsystem>

Connecting to OrientDB from WildFly Swarm

Refer to Wildfly Swarm documentation for org.wildfly.swarm.orientdb.OrientDBFraction.

Minimal example:

// Main.java
package org.wildflynosql.demo.rest;

import java.util.HashMap;

import org.wildfly.swarm.Swarm;
import org.wildfly.swarm.config.orientdb.Orient;
import org.wildfly.swarm.config.orientdb.orient.Host;
import org.wildfly.swarm.config.security.Flag;
import org.wildfly.swarm.config.security.SecurityDomain;
import org.wildfly.swarm.config.security.security_domain.ClassicAuthentication;
import org.wildfly.swarm.config.security.security_domain.authentication.LoginModule;
import org.wildfly.swarm.orientdb.OrientDBFraction;
import org.wildfly.swarm.security.SecurityFraction;
import org.wildfly.swarm.spi.api.OutboundSocketBinding;

public class Main {

    public static void main(String... args) throws Exception {
        Swarm swarm = new Swarm(args)
            .outboundSocketBinding("standard-sockets",
                new OutboundSocketBinding("orienttesthost")
                    .remoteHost("localhost")
                    .remotePort(2424))
            .fraction(SecurityFraction.defaultSecurityFraction()
                .securityDomain(
                    new SecurityDomain("orientRealm")
                        .classicAuthentication(
                            new ClassicAuthentication().loginModule(
                                new LoginModule("ConfiguredIdentity").code("ConfiguredIdentity")
                                    .flag(Flag.REQUIRED)
                                    .moduleOptions(new HashMap<Object, Object>() {
                                       {
                                           put("principal", "admin");
                                           put("username", "admin");
                                           put("password", "changethis");
                                       }
                                   }
                                )
                            )
                        )
                    )
                )
            .fraction(new OrientDBFraction()
                .orient(new Orient("orienttesttprofile")
                    .host(new Host("orienttesthost")
                        .outboundSocketBindingRef("orienttesthost")
                        )
                    .database("test")
                    .jndiName("java:jboss/orientdb/test")
                    .id("orienttesttprofile")
                    .securityDomain("orientRealm")
                    )
            ).fraction(new org.wildfly.swarm.ee.EEFraction())
            .start()
            .deploy();
    }
}
// HelloWorldEndpoint.java
package org.wildflynosql.demo.rest;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.inject.Named;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;

import com.orientechnologies.orient.core.db.OPartitionedDatabasePool;

@ApplicationScoped
@Path("/hello")
public class HelloWorldEndpoint {

    @Inject @Named("orienttesttprofile")
    OPartitionedDatabasePool databasePool;

    @GET
    @Produces("text/plain")
    public Response doGet() {
        return Response.ok("Hello from WildFly Swarm! databasePool= " + databasePool).build();
    }
}
<!-- pom.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.wildflynosql</groupId>
  <artifactId>demo</artifactId>
  <name>WildFly Swarm Example</name>
  <version>1.0.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <properties>
    <version.wildfly.swarm>2017.6.0-SNAPSHOT</version.wildfly.swarm>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <failOnMissingWebXml>false</failOnMissingWebXml>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <version.cassandra.driver>3.0.0</version.cassandra.driver>
    <version.org.glassfish.javax.json>1.0.3</version.org.glassfish.javax.json>
  </properties>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.wildfly.swarm</groupId>
        <artifactId>bom-all</artifactId>
        <version>${version.wildfly.swarm}</version>
        <scope>import</scope>
        <type>pom</type>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <build>
    <finalName>demo</finalName>
    <plugins>
      <plugin>
        <groupId>org.wildfly.swarm</groupId>
        <artifactId>wildfly-swarm-plugin</artifactId>
        <version>${version.wildfly.swarm}</version>
        <configuration>
          <mainClass>org.wildflynosql.demo.rest.Main</mainClass>
        </configuration>

        <executions>
          <execution>
            <goals>
              <goal>package</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <dependencies>
    <!-- Java EE 7 dependency -->
    <dependency>
      <groupId>javax</groupId>
      <artifactId>javaee-api</artifactId>
      <version>7.0</version>
      <scope>provided</scope>
    </dependency>
    <!-- WildFly Swarm Fractions -->
    <dependency>
      <groupId>org.wildfly.swarm</groupId>
      <artifactId>jaxrs-jsonp</artifactId>
    </dependency>

    <dependency>
      <groupId>org.wildfly.swarm</groupId>
      <artifactId>jsonp</artifactId>
    </dependency>

    <dependency>
      <groupId>org.glassfish</groupId>
      <artifactId>javax.json</artifactId>
      <version>${version.org.glassfish.javax.json}</version>
    </dependency>
    <dependency>
        <groupId>org.wildfly.swarm</groupId>
        <artifactId>orientdb</artifactId>
    </dependency>
    <dependency>
        <groupId>com.orientechnologies</groupId>
        <artifactId>orientdb-core</artifactId>
    </dependency>

    <dependency>
        <groupId>com.orientechnologies</groupId>
        <artifactId>orientdb-graphdb</artifactId>
    </dependency>

    <dependency>
        <groupId>com.orientechnologies</groupId>
        <artifactId>orientdb-object</artifactId>
    </dependency>

    <dependency>
        <groupId>com.orientechnologies</groupId>
        <artifactId>orientdb-client</artifactId>
    </dependency>

    <dependency>
        <groupId>com.tinkerpop.blueprints</groupId>
        <artifactId>blueprints-core</artifactId>
    </dependency>

    <dependency>
        <groupId>com.googlecode.concurrentlinkedhashmap</groupId>
        <artifactId>concurrentlinkedhashmap-lru</artifactId>
    </dependency>
  </dependencies>
</project>
<!-- empty beans.xml -->
<beans xmlns="http://java.sun.com/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="
      http://java.sun.com/xml/ns/javaee
      http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
</beans>

Neo4j Java driver versions

Table 4. Neo4j Java driver (org.neo4j.driver:neo4j-java-driver).
Version WildFly WildFly Swarm

1.2.1

YES

YES

Connecting to Neo4j from WildFly

The neo4jdriver subsystem may define multiple Neo4j connection profiles, that are used to obtain org.neo4j.driver.v1.Driver class instance that represent each defined profile. The Driver class is thread safe and can be shared by multiple deployed applications.

If transaction=none is specified in connection profile, Neo4j connection will not be enlisted into JTA transactions.

If transaction=1pc is specified in connection profile, Neo4j connection will be enlisted into active JTA transactions. If there isn’t an active JTA transaction, the Ne04j TX API is in control of the Neo4j transaction. With one caveat, that the Ne04j transaction should be ended by the application code, before entering into a JTA transaction (since it won’t be joined into the JTA transaction). When the JTA transaction commits, the underlying Neo4j tx.success()
tx.close() are called. If the JTA transaction rolls back, the underlying Neo4j tx.failure() + tx.close() are called.

<!-- example of WildFly Neo4j client subsystem defining profile with JTA transaction enrollement via one phase XAResource wrapper enabled (via transaction="1pc") -->
<subsystem xmlns="urn:jboss:domain:neo4jdriver:1.0">
    <neo4j name="default" id="neo4jtesttprofile" jndi-name="java:jboss/neo4jdriver/test" transaction="1pc">
        <host name="default" outbound-socket-binding-ref="neo4jtesthost"/>
    </neo4j>
</subsystem>

Connecting to Neo4j from WildFly Swarm

Refer to Wildfly Swarm documentation for org.wildfly.swarm.neo4j.Neo4jFraction

Minimal example:

// Main.java
package org.wildflynosql.demo.rest;

import java.util.HashMap;

import org.wildfly.swarm.Swarm;
import org.wildfly.swarm.config.neo4jdriver.Neo4j;
import org.wildfly.swarm.config.neo4jdriver.neo4j.Host;
import org.wildfly.swarm.config.security.Flag;
import org.wildfly.swarm.config.security.SecurityDomain;
import org.wildfly.swarm.config.security.security_domain.ClassicAuthentication;
import org.wildfly.swarm.config.security.security_domain.authentication.LoginModule;
import org.wildfly.swarm.neo4j.Neo4jFraction;
import org.wildfly.swarm.security.SecurityFraction;
import org.wildfly.swarm.spi.api.OutboundSocketBinding;

public class Main {

    public static void main(String... args) throws Exception {
        Swarm swarm = new Swarm(args)
            .outboundSocketBinding("standard-sockets",
                new OutboundSocketBinding("neo4jtesthost")
                    .remoteHost("localhost")
                    .remotePort(7687))
            .fraction(SecurityFraction.defaultSecurityFraction()
                .securityDomain(
                    new SecurityDomain("neo4jRealm")
                        .classicAuthentication(
                            new ClassicAuthentication().loginModule(
                                new LoginModule("ConfiguredIdentity").code("ConfiguredIdentity")
                                    .flag(Flag.REQUIRED)
                                    .moduleOptions(new HashMap<Object, Object>() {
                                       {
                                           put("principal", "devuser");
                                           put("username", "devuser");
                                           put("password", "changethis");
                                       }
                                   }
                                )
                            )
                        )
                    )
                )
            .fraction(new Neo4jFraction()
                .neo4j(new Neo4j("neo4jtestprofile")
                    .host(new Host("neo4jtesthost")
                        .outboundSocketBindingRef("neo4jtesthost")
                        )
                    .jndiName("java:jboss/neo4jdriver/test")
                    .id("neo4jtestprofile")
                    .module("org.neo4j.custom")
                    .securityDomain("neo4jRealm")
                    .transaction("1pc")
                    )
            ).fraction(new org.wildfly.swarm.ee.EEFraction())
            .start()
            .deploy();
    }
}
// HelloWorldEndpoint.java
package org.wildflynosql.demo.rest;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.inject.Named;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;

import org.neo4j.driver.v1.Driver;

@ApplicationScoped
@Path("/hello")
public class HelloWorldEndpoint {

    @Inject @Named("neo4jtestprofile")
    Driver database;

    @GET
    @Produces("text/plain")
    public Response doGet() {
        return Response.ok("Hello from WildFly Swarm! database = " + database).build();
    }
}
<!-- pom.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.wildflynosql</groupId>
  <artifactId>demo</artifactId>
  <name>WildFly Swarm Example</name>
  <version>1.0.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <properties>
    <version.wildfly.swarm>2017.6.0-SNAPSHOT</version.wildfly.swarm>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <failOnMissingWebXml>false</failOnMissingWebXml>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <version.neo4j.driver>1.2.1</version.neo4j.driver>
    <version.org.glassfish.javax.json>1.0.3</version.org.glassfish.javax.json>
  </properties>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.wildfly.swarm</groupId>
        <artifactId>bom-all</artifactId>
        <version>${version.wildfly.swarm}</version>
        <scope>import</scope>
        <type>pom</type>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <build>
    <finalName>demo</finalName>
    <plugins>
      <plugin>
        <groupId>org.wildfly.swarm</groupId>
        <artifactId>wildfly-swarm-plugin</artifactId>
        <version>${version.wildfly.swarm}</version>
        <configuration>
          <mainClass>org.wildflynosql.demo.rest.Main</mainClass>
        </configuration>

        <executions>
          <execution>
            <goals>
              <goal>package</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <dependencies>
    <!-- Java EE 7 dependency -->
    <dependency>
      <groupId>javax</groupId>
      <artifactId>javaee-api</artifactId>
      <version>7.0</version>
      <scope>provided</scope>
    </dependency>
    <!-- WildFly Swarm Fractions -->
    <dependency>
      <groupId>org.wildfly.swarm</groupId>
      <artifactId>jaxrs-jsonp</artifactId>
    </dependency>

    <dependency>
      <groupId>org.wildfly.swarm</groupId>
      <artifactId>jsonp</artifactId>
    </dependency>

    <dependency>
      <groupId>org.glassfish</groupId>
      <artifactId>javax.json</artifactId>
      <version>${version.org.glassfish.javax.json}</version>
    </dependency>
      <dependency>
      <groupId>org.wildfly.swarm</groupId>
      <artifactId>neo4j</artifactId>
    </dependency>
    <dependency>
      <groupId>org.neo4j.driver</groupId>
      <artifactId>neo4j-java-driver</artifactId>
      <version>${version.neo4j.driver}</version>
    </dependency>
  </dependencies>
</project>
<!-- empty beans.xml -->
<beans xmlns="http://java.sun.com/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="
      http://java.sun.com/xml/ns/javaee
      http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
</beans>

Logging categories

org.wildfly.nosql - Enable NoSQL subsystem logging.

org.wildfly.swarm.neo4j - Enable Neo4j fraction logging.

org.wildfly.swarm.orientdb - Enable OrientDB fraction logging.

org.wildfly.swarm.cassandra - Enable Cassandra fraction logging.

org.wildfly.swarm.mongodb - Enable MongoDB fraction logging.

Common issues

  1. Incorrectly spelled profile name causes CDI injection or JNDI lookup, to fail. Correct to use correct spelling of NoSQL profile name.

  2. Missing beans.xml leads to deployment failure.

Community

Issue tracking

Dicussion forum

IRC chat

Also find us on freenode irc room #wildfly-nosql.