ObjectBuilder
First of all: The ObjectBuilder is a tool for developers. If you aren't a developer this is probably not interesting for you.
Features
Installation
- Saving custom objects to a MongoDB database
- Loading custom objects from a MongoDB database
- Compatible with pretty much every custom datastructure you can imagine
- Clone (git): https://bitbucket.org/Jobi/objectbuilder/overview
- Compile it using maven
- Add dependency to your maven project
API UsageCode (Text):<dependency>
<groupId>com.spleefleague</groupId>
<artifactId>ObjectBuilder</artifactId>
<version>1.1</version>
</dependency>
Saving Objects
Loading ObjectsCode (Text):ObjectBuilder.save(customPlayer, customPlayerCollection);
Creating custom objectsCode (Text)://Requires the DBObject (MongoDB) of the object you want to load
CustomPlayer cp = ObjectBuilder.load(customPlayerdbo, CustomPlayer.class);
The next part is easier to explain with an example class.
- Every custom object which is going to be loaded or saved to/from the DB needs to extend DBEntity
- Objects which are going to be loaded from the DB need to implement DBLoadable, objects which are saved to the DB need to extend DBSaveable
Code (Text):public class CustomPlayer extends DBEntity implements DBLoadable, DBSaveable {
@DBLoad(fieldName = "username", priority = 10)
private String name;
@DBLoad(fieldName = "uuid", typeConverter = TypeConverter.UUIDStringConverter.class, priority = 10)
private UUID uuid;
@DBLoad(fieldName = "friends", typeConverter = TypeConverter.UUIDStringConverter.class)
private Collection<UUID> friends;
private Rank rank;//Rank is an enu
@DBLoad(fieldName = "goals", typeConverter = TypeConverter.LocationConverter.class)
private Location[] goals;
public String getName() {
return name;
}
public UUID getUUID() {
return uuid;
}
@DBSave(fieldName = "rank")
public Rank getRank() {
return rank;
}
@DBLoad(fieldName = "rank")
public void setRank(Rank rank) {
this.rank = rank;
}
public Location[] getGoals() {
return goals;
}
}Options in the annotations
- If a value should be saved to the DB either the field or a method returning the value needs a @DBSave annotation.
- If a value should be loaded from the DB either the field or a method setting the value needs a @DBLoad annotation.
- (required) fieldName: The name of the field which holds the value in the Document
- (situational) typeConverter:
- Used to load values which are not
- primitive (int, boolean, double, ...)
- Strings
- DBLoadable
- One dimensional Array of the above
- (Possibly nested) Collection of the above
- Good to load Bukkit classes like Location directly without a Wrapper
- For detailed instructions take a look into the TypeConverter class
- (optional) priority: higher value -> loaded earlier

MongoDB Java Object Builder 1.1
Utility class to directly load and save Java Objects from/to a MongoDB Database
Recent Updates
- MongoDB 3.0 Jan 15, 2016