當前位置: 首頁>>代碼示例>>Java>>正文


Java Morphia.createDatastore方法代碼示例

本文整理匯總了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;
}
 
開發者ID:ganchix,項目名稱:morphia-spring-boot-starter,代碼行數:19,代碼來源:MorphiaAutoConfiguration.java

示例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;
}
 
開發者ID:nimesh-mittal,項目名稱:elastic-match,代碼行數:10,代碼來源:ConnectionFactory.java

示例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 );
    }
 
開發者ID:nakamura5akihito,項目名稱:six-oval,代碼行數:24,代碼來源:MongoClientAuthTest.java

示例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);
	}

}
 
開發者ID:lumongo,項目名稱:lumongo,代碼行數:27,代碼來源:UIQueryServiceImpl.java

示例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());
}
 
開發者ID:lucko,項目名稱:helper,代碼行數:16,代碼來源:MongoWrapper.java

示例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();
}
 
開發者ID:sjsucohort6,項目名稱:amigo-chatbot,代碼行數:22,代碼來源:MongoDBClientBase.java

示例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();
}
 
開發者ID:shuza,項目名稱:Simple-RestFull-API,代碼行數:8,代碼來源:MongoDbDao.java

示例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;
	}
 
開發者ID:daflockinger,項目名稱:spongeblog,代碼行數:12,代碼來源:DataStoreFactory.java

示例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;
}
 
開發者ID:caelwinner,項目名稱:spring-morphia,代碼行數:9,代碼來源:MorphiaConfiguration.java

示例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);
}
 
開發者ID:crtomirmajer,項目名稱:wiki2mongo,代碼行數:12,代碼來源:MongoDatastore.java

示例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;
    }
 
開發者ID:WenZuHuai,項目名稱:light-task-scheduler,代碼行數:32,代碼來源:DataStoreProvider.java

示例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());
}
 
開發者ID:nimesh-mittal,項目名稱:elastic-match,代碼行數:15,代碼來源:EntityDaoTest.java

示例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);
}
 
開發者ID:catedrasaes-umu,項目名稱:NoSQLDataEngineering,代碼行數:14,代碼來源:MorphiaTestConfig.java

示例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);
}
 
開發者ID:catedrasaes-umu,項目名稱:NoSQLDataEngineering,代碼行數:14,代碼來源:MorphiaEveryPolCloneTest.java

示例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();
}
 
開發者ID:catedrasaes-umu,項目名稱:NoSQLDataEngineering,代碼行數:12,代碼來源:MorphiaMoviesValidationTest.java


注:本文中的org.mongodb.morphia.Morphia.createDatastore方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。