All Projects → dozd → mongo-mapper

dozd / mongo-mapper

Licence: Apache-2.0 license
Easy POJO codec for MongoDB in Java

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to mongo-mapper

polymorphia
A very fast POJO codec for MongoDB (used in conjunction with the Mongo Java Driver) that handles generic types as well as polymorphic class hierarchies
Stars: ✭ 21 (-8.7%)
Mutual labels:  mapper, codec
Payload
Fail-safe asynchronous profile & object caching via Redis & MongoDB in Java for Spigot
Stars: ✭ 23 (+0%)
Mutual labels:  mongodb-java-driver
Farseer.Net
Provides consistent standard use of common components of the .Net Core language
Stars: ✭ 42 (+82.61%)
Mutual labels:  mapper
PropMapper
Object mapper for .NET. Flat and basic, but FAST.
Stars: ✭ 30 (+30.43%)
Mutual labels:  mapper
style-vendorizer
Tiny CSS vendor prefixer and property alias mapper for runtime styling solutions
Stars: ✭ 56 (+143.48%)
Mutual labels:  mapper
TranscodingStreams.jl
Simple, consistent interfaces for any codec.
Stars: ✭ 71 (+208.7%)
Mutual labels:  codec
mars
Mars - ODM Framework for MongoDB (MongoDB ODM Java )
Stars: ✭ 35 (+52.17%)
Mutual labels:  codec
p mybatis
mybatis深入学习代码文档以及源码解析,包含通用mapper、分页等插件的详细介绍以及使用
Stars: ✭ 22 (-4.35%)
Mutual labels:  mapper
ffcvt
ffmpeg convert wrapper tool
Stars: ✭ 32 (+39.13%)
Mutual labels:  codec
fo-dicom.Codecs
Cross-platform Dicom native codecs for fo-dicom
Stars: ✭ 41 (+78.26%)
Mutual labels:  codec
scale.rb
Ruby SCALE Codec Library & Substrate Client
Stars: ✭ 17 (-26.09%)
Mutual labels:  codec
dynamo-node
DynamoDB mapper
Stars: ✭ 12 (-47.83%)
Mutual labels:  mapper
muxrpc
lightweight multiplexed rpc
Stars: ✭ 96 (+317.39%)
Mutual labels:  codec
hdradio
HD Radio SDR Receiver
Stars: ✭ 15 (-34.78%)
Mutual labels:  codec
meowmeow
MeowMeow - A Toy File Encoder/Decoder
Stars: ✭ 18 (-21.74%)
Mutual labels:  codec
derivejs
DeriveJS is a reactive ODM - Object Document Mapper - framework, a "wrapper" around a database, that removes all the hassle of data-persistence by handling it transparently in the background, in a DRY manner.
Stars: ✭ 54 (+134.78%)
Mutual labels:  mapper
codec
Encode keys, values and range options, with built-in or custom encodings.
Stars: ✭ 27 (+17.39%)
Mutual labels:  codec
JNQD
Learning-based Just-noticeable-quantization-distortion Model for perceptual video coding
Stars: ✭ 21 (-8.7%)
Mutual labels:  codec
arduino-audio-tools
Arduino Audio Tools (Music Player, Music Recorder supporting I2S, Microphones, DAC, ADC, A2DP, Url, MP3, AAC, AudioKit, ES8388)
Stars: ✭ 393 (+1608.7%)
Mutual labels:  codec
JSONUtilities
Easily load JSON objects and decode them into structs or classes
Stars: ✭ 57 (+147.83%)
Mutual labels:  mapper

mongo-mapper Build Status

Mapping POJO for MongoDB has not been easier. Thanks to the new codecs feature in MongoDB Java 3.0 driver. Simply mark your entities with annotation, create EntityCodec and that's it! Then use standard methods for storing and accessing data from MongoDB.

Why us it?

  • Simple and easy to use.
  • Use standard (MongoDB) way for object manipulation.
  • Works for synchronous as well as asynchronous version of MongoDB Java Driver.
  • You can extend with your own custom codecs.
  • It's fast and small - only 13kB dependency covered by unit and integration tests.

Installation

Mongo mapper is on Maven Central. Add following into your pom.xml.

Maven
<dependency>
    <groupId>eu.dozd</groupId>
    <artifactId>mongo-mapper</artifactId>
    <version>1.x.x</version>
</dependency>

Maven Central

Gradle
compile 'eu.dozd:mongo-mapper:1.x.x'

Usage

  1. Annotate your entities with Entity. Make sure every entity has exactly one String annotated with Id. All properties must have correct getter and setter methods according Java Bean specification.

    import eu.dozd.mongo.annotation.Entity;
    import eu.dozd.mongo.annotation.Id;
    
    @Entity
    public class Person {
        @Id
        String id;
        String name;
        int age;
    
        public String getId() { return id; }
        public void setId(String id) { this.id = id; }
        
        public String getName() { return name; }
        public void setName(String name) { this.name = name; }
        
        public int getAge() { return age; }
        public void setAge(int age) { this.age = age; }
    }
  2. Create mapper CodecProvider by calling MongoMapper.getProviders.

    CodecRegistry codecRegistry = CodecRegistries.fromProviders(MongoMapper.getProviders());
    • Usage for standard driver:

          MongoClientOptions settings = MongoClientOptions.builder().codecRegistry(codecRegistry).build();
      
          MongoClient client = new MongoClient(new ServerAddress("localhost", 27017), settings);
    • Usage for asynchronous driver:

          ClusterSettings clusterSettings = ClusterSettings.builder().hosts(Arrays.asList(new ServerAddress("localhost", 27017))).build();
          MongoClientSettings settings = MongoClientSettings.builder().codecRegistry(codecRegistry)
                                              .clusterSettings(clusterSettings).build();
          
          MongoClient client = MongoClients.create(settings);
  3. Access and store data like normal POJO.

        MongoCollection<Person> collection = db.getCollection("persons", Person.class);
    
        Person person = new Person();
        person.setName("Foo Bar");
    
        // Store person normally.
        collection.insertOne(person);
    
        // Access data.
        Person person2 = collection.find.first()

Features

  • Entity reference - make sure all entities classes are annotated with Entity.
  • Embedded entities - entities annotated with Embedded does not need to have an ID.
  • @java.beans.Transient - annotated getter with it.
  • Feel free to create issue or pull request if you missing some functionality.

Custom codecs

  • You can create other Codecs for you special classes.
  • Added BigDecimalCodec and BigDecimalCodecProvider as an example.
  • Don't forget to call MongoMapper.addProvider(yourCustomCodecProvider).

Eclipse

Eclipse uses its own Java compiler which is not strictly standard compliant and requires extra configuration. In Java Compiler -> Annotation Processing -> Factory Path you need to add ClassIndex jar file. See the screenshot.

Licence

Copyright 2016 Zdenek Dolezal

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

See also

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].