本文整理匯總了Java中org.mongodb.morphia.Morphia.createDatastore方法的典型用法代碼示例。如果您正苦於以下問題:Java Morphia.createDatastore方法的具體用法?Java Morphia.createDatastore怎麽用?Java Morphia.createDatastore使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.mongodb.morphia.Morphia
的用法示例。
在下文中一共展示了Morphia.createDatastore方法的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: 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 );
}
示例4: 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);
}
}
示例5: MongoWrapper
import org.mongodb.morphia.Morphia; //導入方法依賴的package包/類
public MongoWrapper(@Nonnull MongoDatabaseCredentials credentials) {
MongoCredential mongoCredential = MongoCredential.createCredential(
credentials.getUsername(),
credentials.getDatabase(),
credentials.getPassword().toCharArray()
);
client = new MongoClient(
new ServerAddress(credentials.getAddress(), credentials.getPort()),
Collections.singletonList(mongoCredential)
);
database = client.getDatabase(credentials.getDatabase());
morphia = new Morphia();
morphiaDatastore = morphia.createDatastore(client, credentials.getDatabase());
}
示例6: MongoDBClientBase
import org.mongodb.morphia.Morphia; //導入方法依賴的package包/類
/**
* Constructs a MongoDB client instance.
*
* This is private so it can only be instantiated via DI (using Guice).
*
* @param server server hostname or ip
* @param port port number for mongodb service
* @param dbName name of db to use
*/
@Inject
public MongoDBClientBase(@Assisted("server") String server, @Assisted("port") int port, @Assisted("dbName") String dbName) {
this.server = server;
this.port = port;
this.dbName = dbName;
mongoClient = new MongoClient(server, port);
morphia = new Morphia();
//morphia.mapPackageFromClass(Service.class);
morphiaDatastore = morphia.createDatastore(mongoClient, dbName);
morphiaDatastore.ensureIndexes();
}
示例7: 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();
}
示例8: get
import org.mongodb.morphia.Morphia; //導入方法依賴的package包/類
public static synchronized Datastore get() {
if (dataStore == null) {
morphia = new Morphia();
new ValidationExtension(morphia);
Config config = ConfigFactory.defaultApplication();
MongoClient client = new MongoClient(new MongoClientURI(config.getString("morphia.db.uri")));;
dataStore = morphia.createDatastore(client, config.getString("morphia.db.name"));
}
return dataStore;
}
示例9: dataStore
import org.mongodb.morphia.Morphia; //導入方法依賴的package包/類
@Bean
public Datastore dataStore(final Morphia morphia,
final MongoClient mongoClient,
final MongoSettings mongoSettings) {
final Datastore datastore = morphia.createDatastore(mongoClient, mongoSettings.getDatabase());
datastore.ensureIndexes();
return datastore;
}
示例10: 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);
}
示例11: getDataStore
import org.mongodb.morphia.Morphia; //導入方法依賴的package包/類
public static Datastore getDataStore(Config config) {
String[] addresses = config.getParameter(ADDRESSES_KEY, new String[]{DEFAULT_ADDRESSES});
String database = config.getParameter(DATABASE_KEY, DEFAULT_DATABASE);
String username = config.getParameter(USERNAME);
String pwd = config.getParameter(PASSWORD);
String cachedKey = StringUtils.concat(StringUtils.concat(addresses), database, username, pwd);
Datastore datastore = DATA_STORE_MAP.get(cachedKey);
if (datastore == null) {
try {
synchronized (lock) {
datastore = DATA_STORE_MAP.get(cachedKey);
if (datastore != null) {
return datastore;
}
Morphia morphia = new Morphia();
MongoFactoryBean mongoFactoryBean = new MongoFactoryBean(addresses, username, database, pwd);
MongoClient mongo = mongoFactoryBean.createInstance();
datastore = morphia.createDatastore(mongo, database);
DATA_STORE_MAP.put(cachedKey, datastore);
}
} catch (Exception e) {
throw new IllegalStateException(
StringUtils.format("connect mongo failed! addresses: {}, database: {}",
addresses, database), e);
}
}
return datastore;
}
示例12: 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());
}
示例13: 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);
}
示例14: 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);
}
示例15: 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();
}