Coder Social home page Coder Social logo

monganez's Introduction

Summary

monganez is MongoDB simple data mapper for Java. This library helps to convert Java Object(Map/Iterable/POJO) to the DBObject(from MongoDB Java Driver). For example, below.


public class SaveTest {

	private DBCollection collection;
	
	@Before
	public void setUp() throws UnknownHostException, MongoException{
		Mongo mongo = new Mongo("localhost");
		DB db = mongo.getDB("test");
		collection = db.getCollection("saved");
	}
	
	@Test
	public void testNestedPojoListAsAttributeToDBObject() throws IllegalAccessException, InvocationTargetException, NoSuchMethodException{
		String id = Long.toString(System.currentTimeMillis());
		Foo foo = new Foo();
		foo.setId(id);
		foo.setCount(40);
		Bar bar1 = new Bar();
		bar1.setId("bar1_" + id);
		bar1.setStringList(new ArrayList(Arrays.asList("hoge", "hogehoge")));
		Bar bar2 = new Bar();
		bar2.setId("bar2_" + id);
		bar2.setStringList(new ArrayList(Arrays.asList("foo", "bar", "hoge")));
		foo.setBarList(new ArrayList(Arrays.asList(bar1, bar2)));
		
		Map map = new HashMap();
		map.put("foo", foo);
		
		DBObjectEncoder encoder = new DBObjectEncoder();
		collection.save(encoder.encode(map));
	}
}

In MongoDB, below.


> db.saved.find();
{ "_id" : ObjectId("4dda9b15f769a51d9f924c8d"), "foo" : { "id" : "1306172181493", "count" : 40, "class" : "net.wrap_trap.monganez.Foo", "bar" : null, "barList": { "collectionValue" : [
        {
                "id" : "bar1_1306172181493",
                "stringList" : {
                        "collectionValue" : [
                                "hoge",
                                "hogehoge"
                        ],
                        "collectionClass" : "java.util.ArrayList"
                },
                "class" : "net.wrap_trap.monganez.Bar"
        },
        {
                "id" : "bar2_1306172181493",
                "stringList" : {
                        "collectionValue" : [
                                "foo",
                                "bar",
                                "hoge"
                        ],
                        "collectionClass" : "java.util.ArrayList"
                },
                "class" : "net.wrap_trap.monganez.Bar"
        }
], "collectionClass" : "java.util.ArrayList" } } }

Usage

  • encode Map/Iterable/POJO to DBObject.
  • decode DBObject to Map/Iterable/POJO.
  • show deails.

Make Jar


mvn package -Dmaven.test.skip=true

Maven Repository


<dependency>
		<groupId>net.wrap-trap</groupId>
		<artifactId>monganez</artifactId>
		<version>0.0.1-SNAPSHOT</version>
		<type>jar</type>
		<scope>compile</scope>
</dependency>
<repository>
		<id>wrap-trap.net/maven2/snapshot</id>
		<name>wrap-trap.net Maven Snapshot Repository</name>
		<url>http://wrap-trap.net/maven2/snapshot</url>
</repository>

License

ASL 2.0

monganez's People

Contributors

masayuki038 avatar

Stargazers

 avatar

Watchers

 avatar James Cloos 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.