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


Java Datastore類代碼示例

本文整理匯總了Java中org.mongodb.morphia.Datastore的典型用法代碼示例。如果您正苦於以下問題:Java Datastore類的具體用法?Java Datastore怎麽用?Java Datastore使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Datastore類屬於org.mongodb.morphia包,在下文中一共展示了Datastore類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testDottedNames

import org.mongodb.morphia.Datastore; //導入依賴的package包/類
@Test
public void testDottedNames() {
    ParentType parentType = new ParentType();
    EmbeddedSubtype embedded = new EmbeddedSubtype();
    embedded.setText("text");
    embedded.setNumber(42L);
    embedded.setFlag(true);
    parentType.setEmbedded(embedded);

    Datastore ds = getDs();
    ds.save(parentType);

    Query<ParentType> query = ds.find(ParentType.class)
                                .disableValidation()
                                .field("embedded.flag").equal(true);

    Assert.assertEquals(parentType, query.get());
}
 
開發者ID:mongodb,項目名稱:morphia,代碼行數:19,代碼來源:TestEmbeddedValidation.java

示例2: datastore

import org.mongodb.morphia.Datastore; //導入依賴的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

示例3: saveObjectGraph

import org.mongodb.morphia.Datastore; //導入依賴的package包/類
/**
 * Saves the whole object graph.
 * TODO: make a generic version for non circular graphs
 * @param ds
 */
public void saveObjectGraph(Datastore ds){
    long startTime = System.nanoTime();

    for (Person e : conversation.getParticipants()){
        ds.save(e.getStatistics());
        ds.save(e);
    }

    ds.save(conversation);
    ds.save(statistics);
    ds.save(this);
    long endTime = System.nanoTime();
    long duration = (endTime - startTime);  //divide by 1000000 to get milliseconds.
    logger.info("Time to save GlobalStatistics object: " + duration / 1000000 + "ms");
}
 
開發者ID:roberterdin,項目名稱:thatsapp,代碼行數:21,代碼來源:GlobalStatistics.java

示例4: getDatastore

import org.mongodb.morphia.Datastore; //導入依賴的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

示例5: buildDatastore

import org.mongodb.morphia.Datastore; //導入依賴的package包/類
@JsonIgnore
@Override
public Datastore buildDatastore() {
    MongoClient client = buildClient();

    MapperOptions options = morphia.getMapper().getOptions();
    options.setStoreNulls(getStoreNulls());
    options.setStoreEmpties(getStoreEmpties());
    options.setIgnoreFinals(getIgnoreFinals());
    options.setUseLowerCaseCollectionNames(getUseLowerCaseCollectionNames());

    if (getEnableValidationExtension()) {
        new ValidationExtension(morphia);
    }

    return morphia.createDatastore(client, checkNotNull(getDbName()));
}
 
開發者ID:serhuz,項目名稱:dropwizard-morphia,代碼行數:18,代碼來源:AbstractMongoConfiguration.java

示例6: testAuth

import org.mongodb.morphia.Datastore; //導入依賴的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

示例7: execute

import org.mongodb.morphia.Datastore; //導入依賴的package包/類
@Override
public String execute() throws Exception {
	Datastore ds = MongoDBUtil.getDatastore();
	List<User> list = UserDAO.findUserList(session.getAttribute("username")
			.toString(), oldPassword);
	if (list.size() == 0) {
		return ERROR;
	} else {
		ds.updateFirst(
				ds.find(User.class, "password", oldPassword),
				ds.createUpdateOperations(User.class).set("password",
						password));
		message = "您已成功修改密碼!";
		return SUCCESS;
	}
}
 
開發者ID:findix,項目名稱:GPMS,代碼行數:17,代碼來源:ChangePasswdAction.java

示例8: shouldSkipNullID

import org.mongodb.morphia.Datastore; //導入依賴的package包/類
@Test
public void shouldSkipNullID() throws Exception {
  Object entity = new Object();
  new MockUnit(Datastore.class, DBObject.class, Mapper.class, MappedClass.class, Field.class,
      GeneratedValue.class)
          .expect(unit -> {

            MappedClass mclass = unit.get(MappedClass.class);
            expect(mclass.getIdField()).andReturn(null);
            Mapper mapper = unit.get(Mapper.class);
            expect(mapper.getMappedClass(entity)).andReturn(mclass);
          })
          .run(unit -> {
            new AutoIncID(unit.get(Datastore.class), IdGen.LOCAL)
                .prePersist(entity, unit.get(DBObject.class), unit.get(Mapper.class));
          });
}
 
開發者ID:jooby-project,項目名稱:jooby,代碼行數:18,代碼來源:Issue569.java

示例9: defaultsWithDatastoreCallback

import org.mongodb.morphia.Datastore; //導入依賴的package包/類
@Test
public void defaultsWithDatastoreCallback() throws Exception {
  new MockUnit(Env.class, Config.class, Binder.class)
      .expect(unit -> {
        Config config = unit.get(Config.class);
        expect(config.getConfig("mongodb")).andReturn($mongodb.getConfig("mongodb"));
        expect(config.hasPath("mongodb.db")).andReturn(false);
        expect(config.getString("db")).andReturn("mongodb://127.0.0.1/mydb");
      })
      .expect(serviceKey(new ServiceKey()))
      .expect(mongodb)
      .expect(morphia)
      .expect(unit -> {
        Datastore ds = unit.get(Datastore.class);
        ds.ensureIndexes();
      })
      .expect(objectFactory)
      .run(unit -> {
        new Monphia()
            .doWith(ds -> {
              ds.ensureIndexes();
            })
            .configure(unit.get(Env.class), unit.get(Config.class), unit.get(Binder.class));
      });
}
 
開發者ID:jooby-project,項目名稱:jooby,代碼行數:26,代碼來源:MonphiaTest.java

示例10: should_save_mixed_type_lists

import org.mongodb.morphia.Datastore; //導入依賴的package包/類
@Test
@LocalData
public void should_save_mixed_type_lists() {
    MixedTypeListClass mixed = new MixedTypeListClass();
    Serializable[] mixedList = {1, "teststring", new DummySerialiazable()};
    mixed.mixedTypeList = mixedList;
    Datastore ds = SetupConfig.get().getInjector().getInstance(Datastore.class);
    ds.save(mixed);
    MixedTypeListClass restoredMixed = ds.createQuery(MixedTypeListClass.class).get();

    assertEquals(1, restoredMixed.mixedTypeList[0]);
    assertEquals("teststring", restoredMixed.mixedTypeList[1]);
    assertNotNull(restoredMixed.mixedTypeList[2]);
    assertTrue(restoredMixed.mixedTypeList[2] instanceof DummySerialiazable);
    DummySerialiazable dummy = (DummySerialiazable) restoredMixed.mixedTypeList[2];
    assertEquals("test", dummy.test);
}
 
開發者ID:groupon,項目名稱:DotCi,代碼行數:18,代碼來源:MongoRepositoryTest.java

示例11: list

import org.mongodb.morphia.Datastore; //導入依賴的package包/類
/**
* {@inheritDoc}
*/
@Override
public Iterable<Conference> list() {
	Datastore ds = getDatastore();
	if (ds.find(getEntityClass()).countAll() == 0) {
		// TODO Remove
		SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
		ds.save(Arrays.asList(
				create("Test 1", "Description 1", f.parse("2013-01-01 00:00:00"), f.parse("2013-01-03 00:00:00")),
				create("Test 2", "Description 2", f.parse("2013-02-01 00:00:00"), f.parse("2013-02-03 00:00:00")),
				create("Test 3", "Description 3", f.parse("2013-03-01 00:00:00"), f.parse("2013-03-03 00:00:00")),
				create("Test 4", "Description 4", f.parse("2013-04-01 00:00:00"), f.parse("2013-04-03 00:00:00"))
		));
		}
		catch (ParseException e) {
			// Ignore
		}
	}
	
 return super.list();
}
 
開發者ID:pd-pmueller,項目名稱:cpa,代碼行數:25,代碼來源:ConferenceServiceImpl.java

示例12: setupDatabase

import org.mongodb.morphia.Datastore; //導入依賴的package包/類
private void setupDatabase(MongoClient mongoCl, String dbName) {
	// Initialize Morphia
	Morphia morphia = new Morphia();
	morphia.map(Company.class).map(LinkedChest.class);

	// Setup datastore
	MapperOptions opts = new MapperOptions();
	opts.objectFactory = new CustomCreator(this.getClassLoader());
	Mapper mapper = new Mapper(opts);
	Datastore ds = new DatastoreImpl(mapper, mongoCl, dbName);

	// Setup DAOs
	companyDAO = new CompanyDAO(ds);
	companyDAO.ensureIndexes();
	linkedChestDAO = new LinkedChestDAO(ds);
	linkedChestDAO.ensureIndexes();
}
 
開發者ID:stephenmac7,項目名稱:Incorporate,代碼行數:18,代碼來源:Incorporate.java

示例13: doGetDatastore

import org.mongodb.morphia.Datastore; //導入依賴的package包/類
/**
 * get dataStore of the db.
 * @param dbName
 * @return
 */
private Datastore doGetDatastore(String dbName) {
    Datastore datastore = datastores.get(dbName);
    if (datastore == null) {
        synchronized (MongoDataSource.class) {
            datastore = datastores.get(dbName);
            if (datastore == null) {
                datastore = ds.createDatastore(m, dbName);
                if (StringUtils.isNotEmpty(userName) && StringUtils.isNotEmpty(password)) {
                    DB db = datastore.getDB();
                    if (db != null) {
                        db.authenticate(userName,this.password.toCharArray());
                    }
                }
                datastores.put(dbName, datastore);
            }
        }
    }
    return datastore;
}
 
開發者ID:houdejun214,項目名稱:lakeside-java,代碼行數:25,代碼來源:MongoDataSource.java

示例14: readSingle

import org.mongodb.morphia.Datastore; //導入依賴的package包/類
private void readSingle(final Datastore datastore, final Mapper mapper, final Object entity, final Class fieldType,
                        final Reference annotation, final EntityCache cache, final MappedField mf, final DBObject dbObject) {

    final Object ref = mf.getDbObjectValue(dbObject);
    if (ref != null) {
        Object resolvedObject;
        if (annotation.lazy() && LazyFeatureDependencies.assertDependencyFullFilled()) {
            resolvedObject = createOrReuseProxy(datastore, mapper, fieldType, ref, cache, annotation);
        } else {
            resolvedObject = resolveObject(datastore, mapper, cache, mf, annotation.idOnly(), ref);
        }

        if (resolvedObject != null) {
            mf.setFieldValue(entity, resolvedObject);
        }

    }
}
 
開發者ID:mongodb,項目名稱:morphia,代碼行數:19,代碼來源:ReferenceMapper.java

示例15: QueryImpl

import org.mongodb.morphia.Datastore; //導入依賴的package包/類
/**
 * Creates a Query for the given type and collection
 *
 * @param clazz the type to return
 * @param coll  the collection to query
 * @param ds    the Datastore to use
 */
public QueryImpl(final Class<T> clazz, final DBCollection coll, final Datastore ds) {
    super(CriteriaJoin.AND);

    setQuery(this);
    this.clazz = clazz;
    this.ds = ((org.mongodb.morphia.DatastoreImpl) ds);
    dbColl = coll;
    cache = this.ds.getMapper().createEntityCache();

    final MappedClass mc = this.ds.getMapper().getMappedClass(clazz);
    final Entity entAn = mc == null ? null : mc.getEntityAnnotation();
    if (entAn != null) {
        getOptions().readPreference(this.ds.getMapper().getMappedClass(clazz).getEntityAnnotation().queryNonPrimary()
                   ? ReadPreference.secondaryPreferred()
                   : null);
    }
}
 
開發者ID:mongodb,項目名稱:morphia,代碼行數:25,代碼來源:QueryImpl.java


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