I'm using Tapestry 5.4beta6 now and I can see there is tapestry-mongodb module. Is there any example how can I use this in an application? I found the former module on github but there is only a note that module is part of core framework but no docs or example ...
tapestry-mongodb is just wrapping the initialization of the MongoDB Java driver. You're free to use whatever POJO-wrapper you like; there are plenty of them:
I took this example from the tapestry-mongodb tests, which uses Jongo as ORM:
Module
public class MongoDBTestModule
{
public static void contributeApplicationDefaults(MappedConfiguration<String, String> configuration)
{
configuration.add(MongoDBSymbols.DEFAULT_DB_NAME, "TapestryMongoTest");
}
public static void contributeMongoDBSource(OrderedConfiguration<ServerAddress> configuration)
{
try
{
configuration.add("test", new ServerAddress("localhost", 12345));
}
catch (UnknownHostException e)
{
throw new RuntimeException(e);
}
}
}
Person entity:
package org.apache.tapestry5.internal.mongodb;
import org.bson.types.ObjectId;
import java.util.Date;
/**
*
*/
public class People
{
private ObjectId _id;
private String name;
private String surname;
private Date birthDate;
public ObjectId get_id() {
return _id;
}
public void set_id(ObjectId _id) {
this._id = _id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
public Date getBirthDate() {
return birthDate;
}
public void setBirthDate(Date birthDate) {
this.birthDate = birthDate;
}
}
Actual test code
@Inject
MongoDB mongoDB;
void test() {
// ...
org.jongo.Jongo jongo = new Jongo(mongoDB.getDefaultMongoDb());
org.jongo.MongoCollection peoples = jongo.getCollection("peoples");
// ...
}