本文整理匯總了Java中org.mongodb.morphia.Morphia類的典型用法代碼示例。如果您正苦於以下問題:Java Morphia類的具體用法?Java Morphia怎麽用?Java Morphia使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Morphia類屬於org.mongodb.morphia包,在下文中一共展示了Morphia類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: datastore
import org.mongodb.morphia.Morphia; //導入依賴的package包/類
@Bean
public Datastore datastore(Morphia morphia) throws ClassNotFoundException, IOException {
List<String> packageNamesFromApplication = MorphiaUtils.getApplicationPackageName(applicationContext);
Set<Class<?>> classes = packageNamesFromApplication
.parallelStream()
.flatMap(packageName -> MorphiaUtils.getClasses(packageName).parallelStream())
.collect(Collectors.toSet());
classes.parallelStream()
.filter(clazz -> Objects.nonNull(clazz.getAnnotation(Entity.class)))
.forEach( clazz ->morphia.map(clazz));
Datastore dataStore = morphia.createDatastore(mongoClient, mongoTemplate.getDb().getName());
dataStore.ensureIndexes();
return dataStore;
}
示例2: 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;
}
示例3: SimpleMongoAsyncTest
import org.mongodb.morphia.Morphia; //導入依賴的package包/類
public SimpleMongoAsyncTest() throws IOException {
// Start embeded mongo
config = new MongodConfigBuilder()
.version(Version.Main.PRODUCTION)
.net(new Net(27018, Network.localhostIsIPv6()))
.build();
exe = MongodStarter.getDefaultInstance().prepare(config);
mongoProcess = exe.start();
AtomicBoolean started = new AtomicBoolean(false);
// Start mongo client
client = MongoClients.create("mongodb://localhost:27018");
database = client.getDatabase("test");
collection = database.getCollection(COLLECTION_NAME);
morphia = new Morphia().mapPackage("com.querydsl.mongodb.domain");
}
示例4: MongoApplicationStructure
import org.mongodb.morphia.Morphia; //導入依賴的package包/類
MongoApplicationStructure(final String applicationName)
{
super( applicationName );
// Turn off the really annoying MongoDB spam :/
{
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
Logger rootLogger = loggerContext.getLogger( "org.mongodb.driver" );
rootLogger.setLevel( Level.OFF );
}
this.mongoClient = new MongoClient( new MongoClientURI( CoreConfig.MongoDB.uri ) );
this.accountManager = createNewAccountManager();
xyz.kvantum.server.api.logging.Logger.info( "Initialized MongoApplicationStructure: {}", this
.applicationName );
this.morphia = new Morphia();
this.morphia.mapPackage( "com.github.intellectualsites.kvantum.implementation" );
this.morphiaDatastore = morphia.createDatastore( this.mongoClient, CoreConfig.MongoDB.dbMorphia );
}
示例5: MongoDB
import org.mongodb.morphia.Morphia; //導入依賴的package包/類
private MongoDB() {
MongoClientOptions mongoOptions = MongoClientOptions.builder()
.socketTimeout(60000) // Wait 1m for a query to finish, https://jira.mongodb.org/browse/JAVA-1076
.connectTimeout(15000) // Try the initial connection for 15s, http://blog.mongolab.com/2013/10/do-you-want-a-timeout/
.maxConnectionIdleTime(600000) // Keep idle connections for 10m, so we discard failed connections quickly
.readPreference(ReadPreference.primaryPreferred()) // Read from the primary, if not available use a secondary
.build();
MongoClient mongoClient;
mongoClient = new MongoClient(new ServerAddress(DB_HOST, DB_PORT), mongoOptions);
mongoClient.setWriteConcern(WriteConcern.SAFE);
datastore = new Morphia().mapPackage(BaseEntity.class.getPackage().getName())
.createDatastore(mongoClient, DB_NAME);
datastore.ensureIndexes();
datastore.ensureCaps();
LOG.info("Connection to database '" + DB_HOST + ":" + DB_PORT + "/" + DB_NAME + "' initialized");
}
示例6: testAuth
import org.mongodb.morphia.Morphia; //導入依賴的package包/類
@Test
public void testAuth()
throws Exception
{
//MongoDB 3.0//
MongoCredential credential = MongoCredential.createScramSha1Credential( _DATABASE_, _USER_, _PASSWORD_.toCharArray() );
MongoClient client = new MongoClient( new ServerAddress( _HOST_, _PORT_ ), Arrays.asList( credential ) );
MongoDatabase db = client.getDatabase( _DATABASE_ );
//MongoDB 2.6//
// DB db = client.getDB( "opensec" );
// db.authenticate( "opensec", "opensec".toCharArray() );
db.getName();
Morphia morphia = new Morphia();
Datastore ds = morphia.createDatastore( client, _DATABASE_ );
ds.toString();
// DefinitionDAO dao = new DefinitionDAO( ds );
// long count = dao.count();
// System.out.println( "# OVAL Definitions: " + count );
}
示例7: getEntityClass
import org.mongodb.morphia.Morphia; //導入依賴的package包/類
@Override
public Class<?> getEntityClass(String name) {
DatastoreProvider dsp = ServiceLocator.getServiceImplementation(DatastoreProvider.class);
Morphia morphia = dsp.getMorphia();
Set<String> keyset = morphia.getMapper().getMCMap().keySet();
MappedClass mappedClass = null;
for(String className : keyset){
if(name.equalsIgnoreCase(className) || name.equalsIgnoreCase(className.substring(className.lastIndexOf(".") + 1)))
mappedClass = morphia.getMapper().getMCMap().get(className);
}
if(mappedClass == null)
return null;
else{
return mappedClass.getClazz();
}
}
示例8: init
import org.mongodb.morphia.Morphia; //導入依賴的package包/類
@Override
public void init() throws ServletException {
super.init();
try {
LumongoPoolConfig lumongoPoolConfig = new LumongoPoolConfig().addMember("localhost").setDefaultRetries(2);
lumongoPoolConfig.setMemberUpdateEnabled(false);
lumongoWorkPool = new LumongoWorkPool(lumongoPoolConfig);
Properties properties = new Properties();
properties.load(UIQueryServiceImpl.class.getResourceAsStream("/version.properties"));
lumongoVersion = properties.getProperty("lumongoVersion");
luceneVersion = properties.getProperty("luceneVersion");
MongoClientOptions mongoClientOptions = MongoClientOptions.builder().connectionsPerHost(32).build();
MongoClient mongoClient = new MongoClient("localhost", mongoClientOptions);
Morphia morphia = new Morphia();
morphia.map(UIQueryObject.class);
datastore = morphia.createDatastore(mongoClient, QUERY_HISTORY);
datastore.ensureIndexes();
}
catch (Exception e) {
LOG.error("Failed to initiate lumongo work pool.", e);
}
}
示例9: createInstanceFromClazz
import org.mongodb.morphia.Morphia; //導入依賴的package包/類
@Test
public void createInstanceFromClazz() throws Exception {
Injectable injectable = new Injectable();
new MockUnit(Registry.class, Morphia.class, Mapper.class, ObjectFactory.class)
.expect(boot)
.expect(unit -> {
Registry injector = unit.get(Registry.class);
expect(injector.require(Injectable.class)).andReturn(injectable);
})
.run(unit -> {
assertEquals(injectable,
new GuiceObjectFactory(unit.get(Registry.class), unit.get(Morphia.class))
.createInstance(Injectable.class));
});
}
示例10: createInstanceFromClazzNoInjectable
import org.mongodb.morphia.Morphia; //導入依賴的package包/類
@Test
public void createInstanceFromClazzNoInjectable() throws Exception {
GuiceObjectFactoryTest expected = new GuiceObjectFactoryTest();
new MockUnit(Registry.class, Morphia.class, Mapper.class, ObjectFactory.class)
.expect(boot)
.expect(unit -> {
ObjectFactory injector = unit.get(ObjectFactory.class);
expect(injector.createInstance(GuiceObjectFactoryTest.class)).andReturn(expected);
})
.run(unit -> {
assertEquals(expected,
new GuiceObjectFactory(unit.get(Registry.class), unit.get(Morphia.class))
.createInstance(GuiceObjectFactoryTest.class));
});
}
示例11: createInstanceFromClazzWithDBObject
import org.mongodb.morphia.Morphia; //導入依賴的package包/類
@Test
public void createInstanceFromClazzWithDBObject() throws Exception {
Injectable injectable = new Injectable();
new MockUnit(Registry.class, Morphia.class, Mapper.class, ObjectFactory.class, DBObject.class)
.expect(boot)
.expect(unit -> {
Registry injector = unit.get(Registry.class);
expect(injector.require(Injectable.class)).andReturn(injectable);
})
.run(unit -> {
assertEquals(injectable,
new GuiceObjectFactory(unit.get(Registry.class), unit.get(Morphia.class))
.createInstance(Injectable.class, unit.get(DBObject.class)));
});
}
示例12: createInstanceFromClazzWithDBObjectNoInjectable
import org.mongodb.morphia.Morphia; //導入依賴的package包/類
@Test
public void createInstanceFromClazzWithDBObjectNoInjectable() throws Exception {
GuiceObjectFactoryTest expected = new GuiceObjectFactoryTest();
new MockUnit(Registry.class, Morphia.class, Mapper.class, ObjectFactory.class, DBObject.class)
.expect(boot)
.expect(unit -> {
ObjectFactory factory = unit.get(ObjectFactory.class);
expect(factory.createInstance(GuiceObjectFactoryTest.class, unit.get(DBObject.class)))
.andReturn(expected);
})
.run(unit -> {
assertEquals(expected,
new GuiceObjectFactory(unit.get(Registry.class), unit.get(Morphia.class))
.createInstance(GuiceObjectFactoryTest.class, unit.get(DBObject.class)));
});
}
示例13: createInstanceFully
import org.mongodb.morphia.Morphia; //導入依賴的package包/類
@Test
public void createInstanceFully() throws Exception {
Injectable injectable = new Injectable();
new MockUnit(Registry.class, Morphia.class, Mapper.class, ObjectFactory.class, DBObject.class,
MappedField.class)
.expect(boot)
.expect(unit -> {
MappedField mf = unit.get(MappedField.class);
expect(mf.getType()).andReturn(Injectable.class);
Registry injector = unit.get(Registry.class);
expect(injector.require(Injectable.class)).andReturn(injectable);
})
.run(
unit -> {
assertEquals(
injectable,
new GuiceObjectFactory(unit.get(Registry.class), unit.get(Morphia.class))
.createInstance(unit.get(Mapper.class), unit.get(MappedField.class),
unit.get(DBObject.class)));
});
}
示例14: createInstanceFullyNoInjectable
import org.mongodb.morphia.Morphia; //導入依賴的package包/類
@Test
public void createInstanceFullyNoInjectable() throws Exception {
GuiceObjectFactoryTest expected = new GuiceObjectFactoryTest();
new MockUnit(Registry.class, Morphia.class, Mapper.class, ObjectFactory.class, DBObject.class,
MappedField.class)
.expect(boot)
.expect(unit -> {
MappedField mf = unit.get(MappedField.class);
expect(mf.getType()).andReturn(GuiceObjectFactoryTest.class);
ObjectFactory factory = unit.get(ObjectFactory.class);
expect(factory.createInstance(unit.get(Mapper.class), mf, unit.get(DBObject.class)))
.andReturn(expected);
})
.run(unit -> {
assertEquals(
expected,
new GuiceObjectFactory(unit.get(Registry.class), unit.get(Morphia.class))
.createInstance(unit.get(Mapper.class), unit.get(MappedField.class),
unit.get(DBObject.class)));
});
}
示例15: createMap
import org.mongodb.morphia.Morphia; //導入依賴的package包/類
@Test
public void createMap() throws Exception {
Map<String, Object> expected = Collections.emptyMap();
new MockUnit(Registry.class, Morphia.class, Mapper.class, ObjectFactory.class,
MappedField.class)
.expect(boot)
.expect(unit -> {
ObjectFactory factory = unit.get(ObjectFactory.class);
expect(factory.createMap(unit.get(MappedField.class))).andReturn(expected);
})
.run(unit -> {
assertEquals(
expected,
new GuiceObjectFactory(unit.get(Registry.class), unit.get(Morphia.class))
.createMap(unit.get(MappedField.class)));
});
}