MCPcopy Index your code
hub / github.com/alexanderjarvis/play-jongo

github.com/alexanderjarvis/play-jongo @0.7.1-jongo1.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release 0.7.1-jongo1.0 ↗ · + Follow
42 symbols 107 edges 7 files 6 documented · 14%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

PlayJongo Play 2.3.x Module

This is a Play 2.3.x Module for Jongo (a MongoDB Java driver wrapper).

If you're using Play! 2.2.x or 2.1.x you can use an older version of play-jongo, for 2.2.x use 0.6.0-jongo1.0, for 2.1.x use 0.5.0-jongo0.4.

Build Status

Installation

Add the following to your projects Build.scala

val appDependencies = Seq(
  "uk.co.panaxiom" %% "play-jongo" % "0.7.1-jongo1.0"
)

Note related to play-jongo with Play 2.2: because there were issues reported due to incompatibilities of Play 2.2!, bson4jackson and the current version of jackson, you might actually want to use the following dependencies:

val appDependencies = Seq(
  "de.undercouch" % "bson4jackson" % "2.1.0" force(),
  "com.fasterxml.jackson.core" % "jackson-databind" % "2.1.0" force(),
  "com.fasterxml.jackson.core" % "jackson-annotations" % "2.1.0" force(),
  "com.fasterxml.jackson.core" % "jackson-core" % "2.1.0" force(),
  "org.mongodb" % "mongo-java-driver" % "2.11.3",
  "org.jongo" % "jongo" % "1.0",
  "uk.co.panaxiom" %% "play-jongo" % "0.7.0-jongo1.0"
)

You will need to override the application.conf configuration to specify your MongoDB configuration.

# Play Jongo
# ~~~~~
playjongo.uri="mongodb://127.0.0.1:27017/play"
playjongo.gridfs.enabled=false

Optional configuration

The default write concern for the mongodb driver can be changed via the following configuration:

playjongo.defaultWriteConcern="SAFE"

Valid values are the names of the WriteConcern enumeration fields.

By default in test mode the "test" mongo database will be used. To change this, you can specify playjongo.test-uri in your configuration.

MongoClient Factory

Not all MongoClient options are supported by the MongoClientURI. For full customization of the generated MongoClient, you can specify your own MongoClientFactory class like this:

playjongo.mongoClientFactory="com.example.MyMongoClientFactory"

The value should be the name of a class that extends from uk.co.panaxiom.MongoClientFactory and provide at least an empty constructor or a constructor that takes a play Configuration. For example:

package com.example;

import com.mongodb.*;
import java.util.Arrays;
import play.Configuration;
import uk.co.panaxiom.MongoClientFactory;

public class MyMongoClientFactory extends MongoClientFactory {
    private Configuration config = config;
    public MyMongoClientFactory(Configuration config) {
        this.config = config;
    }

    public MongoClient createClient() throws Exception {
        MongoClientOptions options = MongoClientOptions.builder()
            .connectionsPerHost(100)
            .maxConnectionIdleTime(60000)
            .build() 

        return new MongoClient(Arrays.asList(
            new ServerAddress("localhost", 27017),
            new ServerAddress("localhost", 27018),
            new ServerAddress("localhost", 27019)),
            options);
    }

    public String getDBName() {
        config.getString("myappconfig.dbname");
    }

}

Jongo Mapper

To customize the jongo mapper (see also "Configuring Jongo Mapper" in the Jongo documentation) you can provide a factory that will be used to obtain the mapper passed to jongo. Your factory class must implement uk.co.panaxiom.playjongo.JongoMapperFactory and provide a default (public no-args) constructor. You can configure your mapper factory like this:

playjongo.mapperfactory="com.example.MyJongoMapperFactory"

For scala users this project already provides a factory that uses the jackson scala module and configures the jongo/jackson mapper with the DefaultScalaModule. To use this factory you need add the jackson scala module to your appDependencies (e.g. add "com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.4.1") in project/Build.scala and configure the factory in conf/application.conf like this:

playjongo.mapperfactory="uk.co.panaxiom.playjongo.JongoScalaMapperFactory"

Usage

To use this module you just use the PlayJongo class which manages your Mongo and Jongo instances for you. It provides the same method calls as the Jongo object as detailed in the Jongo documentation: http://jongo.org/ .

A simple example:

public class User {

    public static MongoCollection users() {
        return PlayJongo.getCollection("users");
    }

    @JsonProperty("_id")
    public ObjectId id;

    public String name;

    public User insert() {
        users().save(this);
    }

    public void remove() {
        users().remove(this.id);
    }

    public static User findByName(String name) {
        return users().findOne("{name: #}", name).as(User.class);
    }

}

Contact

If you have a question or need some help you can just open an issue.

License

The license is Apache 2.0, see LICENSE.txt.

Extension points exported contracts — how you extend this code

JongoMapperFactory (Interface)
Allows applications to provide a customized Mapper. [4 implementers]
app/uk/co/panaxiom/playjongo/JongoMapperFactory.java

Core symbols most depended-on inside this repo

getInstance
called by 6
app/uk/co/panaxiom/playjongo/PlayJongo.java
getDatabase
called by 6
app/uk/co/panaxiom/playjongo/PlayJongo.java
getClientURI
called by 2
app/uk/co/panaxiom/playjongo/MongoClientFactory.java
createClient
called by 1
app/uk/co/panaxiom/playjongo/MongoClientFactory.java
getDBName
called by 1
app/uk/co/panaxiom/playjongo/MongoClientFactory.java
create
called by 1
app/uk/co/panaxiom/playjongo/JongoMapperFactory.java
getMongoClientFactory
called by 1
app/uk/co/panaxiom/playjongo/PlayJongo.java
createMapper
called by 1
app/uk/co/panaxiom/playjongo/PlayJongo.java

Shape

Method 33
Class 8
Interface 1

Languages

Java100%

Modules by API surface

test/uk/co/panaxiom/playjongo/PlayJongoTest.java13 symbols
app/uk/co/panaxiom/playjongo/PlayJongo.java11 symbols
app/uk/co/panaxiom/playjongo/MongoClientFactory.java5 symbols
app/uk/co/panaxiom/playjongo/JongoPlugin.java4 symbols
app/uk/co/panaxiom/playjongo/JongoMapperFactory.java4 symbols
test/uk/co/panaxiom/playjongo/TestMongoClientFactory.java3 symbols
app/uk/co/panaxiom/playjongo/JongoScalaMapperFactory.java2 symbols

Datastores touched

(mongodb)Database · 1 repos
playDatabase · 1 repos
barDatabase · 1 repos
fooDatabase · 1 repos

For agents

$ claude mcp add play-jongo \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page