Skip to content
This repository has been archived by the owner on Jun 18, 2021. It is now read-only.

marcust/TroyORM

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TroyORM - An OR Mapper for MongoDB from hell.

It is work in progress :).

Annotation based immutable bean mapping (that explains the "from hell" part):

// Optional name for collection to be used, otherwise the class name will be used
@TroyCollectionName("book")
public class Book {
	
	@TroyId
	private final String _isbn;
	
	// optional mapping of field to different key in mongo
	@TroyKey("titleOfBook")
	private final String _title;
	
	// will be stored as author
	private final String _author;
	
	@TroyTransient
	private final String _dontWantToStoreThis = "foo";
	

	private Book(String isbn, String title, String author) {
		super();
		_isbn = isbn;
		_title = title;
		_author = author;
	}

	public static Book create( final String isbn, final String title, final String author ) {
		return new Book( isbn, title, author );
	}
	
}

Object Based Read and Write:

		final TroyORMDAOFactory factory = TroyORMDAOFactory.create("troy-test");
		
		final TroyDAO<Book> bookDao = factory.makeDaoForClass( Book.class );
		
		final String key = "1234" + System.currentTimeMillis();
		final Book book = Book.create( key, "MongoDB & Troy", "Marcus Thiesen et al.");
		
		bookDao.insert(book);
		
		System.out.println("Created book with key " + key );
		
		final Book loadedBook = bookDao.query().byId( key );
		
		System.out.println( "Loaded " + loadedBook.toString() );
		
		final BookTitleRefresh refresh = BookTitleRefresh.create( key, "MongoDB & TroyORM" );
		
		bookDao.updaterFor( BookTitleRefresh.class ).update( refresh );
		
		System.out.println("Updated Book");
		
		final Book loadedModifiedBook = bookDao.query().byId( key );
		
		System.out.println( "Loaded Modified " + loadedModifiedBook.toString() );

See org.thiesen.troy.example.Main for more and up to date examples.

About

An OR-Mapper for MongoDB from hell

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages