GithubHelp home page GithubHelp logo

javaee6-extensions-mongodb's Introduction

#MongoDB Java EE 6 utils Maven Dependencies

<dependency>
    <groupId>com.github.wayis.framework</groupId>
    <artifactId>javaee6-extensions-mongodb</artifactId>
    <version>1.0.0</version>
</dependency>

Version 1.0.0

DBConnection
EJB singleton that handles the connection to MongoDB database.
All properties are searched into a mongodb.properties bundle file:

  • mongodb.host: The host of the mongodb server. (Default value: 'localhost').
  • mongodb.port: The port of the mongodb server. (Default value: '27017').
  • mongodb.dbname: The mongodb database to use. If the database does not exist, it will be created after the construction of this singleton EJB class.

Example to use it in an API REST Resource with JAX-RS:

import com.mongodb.DBCollection;
import com.mongodb.DBObject;
import com.github.wayis.framework.javaee.extensions.mongodb.DBConnection;

import javax.annotation.PostConstruct;
import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.List;

/**
 * REST API to manage users.<br/>
 * <ul>
 * <li><i>/users : GET</i> => Gets all users in JSON format.</li>
 * </ul>
 * Example of users in JSON format :<br/>
 * <pre>
 * {
 *      "lastname": "DOE",
 *      "firstname": "John"
 * }
 * </pre>
 */
@Stateless
@Path("/users")
@Produces(MediaType.APPLICATION_JSON)
public class UserResource {

    /**
     * MongoDB connection provider.
     */
    @Inject
    private DBConnection dbConnection;
    /**
     * Users collection.
     */
    private DBCollection users;

    @PostConstruct
    public void init() {
        users = dbConnection.getCollection("users");
    }

    /**
     * Finds all users.
     *
     * @return List of DBObject represents users.
     */
    @GET
    public List<DBObject> findAll() {
        return users.find().toArray();
    }
}

javaee6-extensions-mongodb's People

Watchers

James Cloos avatar Luc LABBE avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.