本文整理匯總了Java中org.mongodb.morphia.Morphia.mapPackage方法的典型用法代碼示例。如果您正苦於以下問題:Java Morphia.mapPackage方法的具體用法?Java Morphia.mapPackage怎麽用?Java Morphia.mapPackage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.mongodb.morphia.Morphia
的用法示例。
在下文中一共展示了Morphia.mapPackage方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getDatastore
import org.mongodb.morphia.Morphia; //導入方法依賴的package包/類
public static synchronized Datastore getDatastore() {
if (Objects.isNull(datastore)) {
Morphia morphia = new Morphia();
morphia.mapPackage("com.ftt.elastic.match.beans");
MongoClient mongoClient = new MongoClient(PropertiesRepo.get(Constants.Settings.MONGODB_HOST), PropertiesRepo.getInt(Constants.Settings.MONGODB_PORT));
datastore = morphia.createDatastore(mongoClient, PropertiesRepo.get(Constants.Settings.MONGODB_SCHEMANAME));
}
return datastore;
}
示例2: MongoDbDao
import org.mongodb.morphia.Morphia; //導入方法依賴的package包/類
private MongoDbDao() {
Morphia morphia = new Morphia();
morphia.mapPackage("models");
datastore = morphia.createDatastore(new MongoClient(MongoDbSetting.MONGODB_HOST,
MongoDbSetting.MONGODB_PORT), MongoDbSetting.MONGODB_DB_NAME_SESSION);
datastore.ensureIndexes();
}
示例3: build
import org.mongodb.morphia.Morphia; //導入方法依賴的package包/類
public MongoDatastore build() {
if(mongoClient == null)
throw new IllegalArgumentException("Mongo client must not be null.");
final Morphia morphia = new Morphia();
morphia.mapPackage("com.crtomirmajer.wiki2mongo");
datastore = (AdvancedDatastore) morphia.createDatastore(mongoClient, database);
return new MongoDatastore(this);
}
示例4: shouldCreateNewObjectInEmbeddedMongoDb
import org.mongodb.morphia.Morphia; //導入方法依賴的package包/類
public void shouldCreateNewObjectInEmbeddedMongoDb() throws IOException {
Morphia morphia = new Morphia();
morphia.mapPackage("com.ftt.elastic.match.beans");
MongoClient mongoClient = new MongoClient(host, port);
Datastore datastore = morphia.createDatastore(mongoClient, DATABASE_NAME);
EntityDAO<ARecord> entityDAO = new EntityDAO(datastore, ARecord.class);
ARecord record = new ARecord();
record.setDisplayId("myrecord");
String id = (String) entityDAO.create(record);
ARecord recordActual = entityDAO.getOne(id);
Assert.assertEquals(recordActual.getDisplayId(), record.getDisplayId());
}
示例5: setUp
import org.mongodb.morphia.Morphia; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception
{
Morphia morphia = new Morphia();
morphia = morphia.mapPackage("es.um.nosql.schemainference.test2");
new ValidationExtension(morphia);
dbName = "test2";
client = MongoDbAdapter.getMongoDbClient("localhost");
datastore = morphia.createDatastore(client, dbName);
datastore.ensureIndexes();
validator = Validation.buildDefaultValidatorFactory().getValidator();
//client.cleanDb(dbName);
}
示例6: setUp
import org.mongodb.morphia.Morphia; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception
{
Morphia morphia = new Morphia();
morphia = morphia.mapPackage("es.um.nosql.schemainference.everypolitician");
new ValidationExtension(morphia);
dbName = "everypolitician";
client = MongoDbAdapter.getMongoDbClient("localhost");
datastore = morphia.createDatastore(client, dbName);
validator = Validation.buildDefaultValidatorFactory().getValidator();
newDbName = "neweverypolitician";
newDatastore = morphia.createDatastore(client, newDbName);
}
示例7: setUp
import org.mongodb.morphia.Morphia; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception
{
Morphia morphia = new Morphia();
morphia = morphia.mapPackage("es.um.nosql.schemainference.mongoMovies3");
new ValidationExtension(morphia);
dbName = "mongoMovies3";
client = MongoDbAdapter.getMongoDbClient("localhost");
datastore = morphia.createDatastore(client, dbName);
validator = Validation.buildDefaultValidatorFactory().getValidator();
}
示例8: setUp
import org.mongodb.morphia.Morphia; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception
{
Morphia morphia = new Morphia();
morphia = morphia.mapPackage("es.um.nosql.schemainference.opensanctions");
new ValidationExtension(morphia);
dbName = "opensanctions";
client = MongoDbAdapter.getMongoDbClient("localhost");
datastore = morphia.createDatastore(client, dbName);
validator = Validation.buildDefaultValidatorFactory().getValidator();
newDbName = "newopensanctions";
newDatastore = morphia.createDatastore(client, newDbName);
}
示例9: setUp
import org.mongodb.morphia.Morphia; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception
{
Morphia morphia = new Morphia();
morphia = morphia.mapPackage("es.um.nosql.schemainference.everypolitician");
new ValidationExtension(morphia);
dbName = "everypolitician";
client = MongoDbAdapter.getMongoDbClient("localhost");
datastore = morphia.createDatastore(client, dbName);
validator = Validation.buildDefaultValidatorFactory().getValidator();
}
示例10: setUp
import org.mongodb.morphia.Morphia; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception
{
Morphia morphia = new Morphia();
morphia = morphia.mapPackage("es.um.nosql.schemainference.opensanctions");
new ValidationExtension(morphia);
dbName = "opensanctions";
client = MongoDbAdapter.getMongoDbClient("localhost");
datastore = morphia.createDatastore(client, dbName);
validator = Validation.buildDefaultValidatorFactory().getValidator();
}
開發者ID:catedrasaes-umu,項目名稱:NoSQLDataEngineering,代碼行數:12,代碼來源:MorphiaOpenSanctionsValidationTest.java
示例11: MongoDBUtil
import org.mongodb.morphia.Morphia; //導入方法依賴的package包/類
private MongoDBUtil() {
try {
mongo = new Mongo("rank.litpo.com", 27017);
} catch (UnknownHostException e) {
e.printStackTrace();
}
morphia = new Morphia();
morphia.mapPackage("com.find1x.gpms.pojos");
ds = morphia.createDatastore(mongo, DATABASE);
}
示例12: getMorphia
import org.mongodb.morphia.Morphia; //導入方法依賴的package包/類
/**
* Produces and returns a {@code Morphia} instance.
*
* @return a {@code Morphia} instance.
*/
@Produces @Singleton
public Morphia getMorphia() {
Morphia morphia = new Morphia();
// Mappings
morphia.mapPackage("com.prodyna.pmu.cpa.domain.ejb.entity");
// Extensions
new ValidationExtension(morphia);
// Done
return morphia;
}
示例13: createInstance
import org.mongodb.morphia.Morphia; //導入方法依賴的package包/類
@Override
protected Morphia createInstance() throws Exception {
Morphia m = new Morphia();
if (mapPackages != null) {
for (String packageName : mapPackages) {
m.mapPackage(packageName, ignoreInvalidClasses);
}
}
if (mapClasses != null) {
for (String entityClass : mapClasses) {
m.map(Class.forName(entityClass));
}
}
return m;
}
示例14: main
import org.mongodb.morphia.Morphia; //導入方法依賴的package包/類
public static void main(String[] args) {
try {
final Morphia morphia = new Morphia();
morphia.mapPackage("com.boaglio.mongodb.dto");
final Datastore datastore = morphia.createDatastore(new MongoClient(), "test");
System.out.println("-------- MongoDB JUG List from REGION 4 (Morphia) ------------");
final Query<Region> query = datastore.createQuery(Region.class).filter("region","Sudeste");
final List<Region> regionList = query.asList();
System.out.println("JSON = "+regionList);
System.out.println("-------- List<JUG> ------------");
regionList.get(0).getJugs().stream().forEach(System.out::println);
} catch (Exception e) {
e.printStackTrace();
}
}
示例15: buildCrudService
import org.mongodb.morphia.Morphia; //導入方法依賴的package包/類
private void buildCrudService(Dictionary<String, ?> properties, String id) {
try {
if (!PropertiesUtil.toString(properties.get(UNITNAME_PROP), "").equals("")) {
//Aboard in case of nothing provided in dbname.
//Avoiding db connection creation with blank db name.
if (PropertiesUtil.toString(properties.get("dbName"), "").equals("")) {
throw new InvalidMongoDatabaseException("Invalid mongo database name. Provide a valid database name.");
}
MongoCredential credential = null;
if (!PropertiesUtil.toString(properties.get("username"), "").equals("")) {
credential = MongoCredential.createCredential(
PropertiesUtil.toString(properties.get("username"), ""),
PropertiesUtil.toString(properties.get("dbName"), ""),
PropertiesUtil.toString(properties.get("password"), "").toCharArray()
);
}
Morphia morphia = new Morphia();
if (!PropertiesUtil.toString(properties.get("mappablePackage"), "").equals("")) {
morphia.mapPackage(properties.get("mappablePackage").toString());
}
//Adding bundle class loader to load entity classes from fragment bundle.
morphia.getMapper().getOptions().setObjectFactory(new DefaultCreator() {
@Override
protected ClassLoader getClassLoaderForClass() {
return MongoConnectionProvider.class.getClassLoader();
}
});
ServerAddress serverAddress = new ServerAddress(
PropertiesUtil.toString(properties.get("hostName"), ""),
PropertiesUtil.toInteger(properties.get("port"), 0)
);
MongoClient mongoClient = null;
if (credential != null) {
mongoClient = new MongoClient(
serverAddress,
Arrays.asList(credential),
this.buildMongoOptions(properties)
);
} else {
mongoClient = new MongoClient(
serverAddress,
this.buildMongoOptions(properties)
);
}
if (this.unitMapping.containsKey(id)) {
this.destroy(id);
}
this.serviceContainer.put(
PropertiesUtil.toString(properties.get(UNITNAME_PROP), ""),
new MongoCrudRepositoryImpl(
morphia.createDatastore(
mongoClient,
PropertiesUtil.toString(properties.get("dbName"), "")
)
)
);
this.unitMapping.put(id,
PropertiesUtil.toString(properties.get(UNITNAME_PROP), ""));
} else {
throw new InvalidMongoUnitException("Invalid Unit name provided for mongo db configuration. Provide Valid and unique name for unit");
}
} catch (Exception ex) {
LOGGER.error("Unable to create mongo crud service for config id {} full exception ", id, ex);
}
}