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


Java MongoOperations類代碼示例

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


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

示例1: init

import org.springframework.data.mongodb.core.MongoOperations; //導入依賴的package包/類
@Bean
CommandLineRunner init(MongoOperations operations) {
	return args -> {
		// tag::log[]
		operations.dropCollection(Image.class);

		operations.insert(new Image("1",
			"learning-spring-boot-cover.jpg"));
		operations.insert(new Image("2",
			"learning-spring-boot-2nd-edition-cover.jpg"));
		operations.insert(new Image("3",
			"bazinga.png"));

		operations.findAll(Image.class).forEach(image -> {
			System.out.println(image.toString());
		});
		// end::log[]
	};
}
 
開發者ID:PacktPublishing,項目名稱:Learning-Spring-Boot-2.0-Second-Edition,代碼行數:20,代碼來源:InitDatabase.java

示例2: init

import org.springframework.data.mongodb.core.MongoOperations; //導入依賴的package包/類
@Bean
CommandLineRunner init(MongoOperations operations) {
	return args -> {
		// tag::log[]
		operations.dropCollection(Image.class);

		operations.insert(new Image("1",
			"learning-spring-boot-cover.jpg", "greg"));
		operations.insert(new Image("2",
			"learning-spring-boot-2nd-edition-cover.jpg", "greg"));
		operations.insert(new Image("3",
			"bazinga.png", "phil"));

		operations.findAll(Image.class).forEach(image -> {
			System.out.println(image.toString());
		});
		// end::log[]
	};
}
 
開發者ID:PacktPublishing,項目名稱:Learning-Spring-Boot-2.0-Second-Edition,代碼行數:20,代碼來源:InitDatabase.java

示例3: initializeUsers

import org.springframework.data.mongodb.core.MongoOperations; //導入依賴的package包/類
@Bean
CommandLineRunner initializeUsers(MongoOperations operations) {
	return args -> {
		operations.dropCollection(User.class);

		operations.insert(
			new User(
				null,
				"greg", "turnquist",
				new String[]{"ROLE_USER", "ROLE_ADMIN"}));
		operations.insert(
			new User(
				null,
				"phil", "webb",
				new String[]{"ROLE_USER"}));

		operations.findAll(User.class).forEach(user -> {
			System.out.println("Loaded " + user);
		});
	};
}
 
開發者ID:PacktPublishing,項目名稱:Learning-Spring-Boot-2.0-Second-Edition,代碼行數:22,代碼來源:InitUsers.java

示例4: init

import org.springframework.data.mongodb.core.MongoOperations; //導入依賴的package包/類
@Bean
CommandLineRunner init(MongoOperations operations) {
	return args -> {
		// tag::log[]
		operations.dropCollection(Image.class);

		operations.insert(new Image("1",
			"learning-spring-boot-cover.jpg", "greg"));
		operations.insert(new Image("2",
			"learning-spring-boot-2nd-edition-cover.jpg", "greg"));
		operations.insert(new Image("3",
			"bazinga.png", "greg"));

		operations.findAll(Image.class).forEach(image -> {
			System.out.println(image.toString());
		});
		// end::log[]
	};
}
 
開發者ID:PacktPublishing,項目名稱:Learning-Spring-Boot-2.0-Second-Edition,代碼行數:20,代碼來源:InitDatabase.java

示例5: init

import org.springframework.data.mongodb.core.MongoOperations; //導入依賴的package包/類
@Bean
CommandLineRunner init(MongoOperations operations) {
	return args -> {
		operations.dropCollection(Image.class);

		operations.insert(new Image("1",
			"learning-spring-boot-cover.jpg"));
		operations.insert(new Image("2",
			"learning-spring-boot-2nd-edition-cover.jpg"));
		operations.insert(new Image("3",
			"bazinga.png"));

		operations.findAll(Image.class).forEach(image -> {
			System.out.println(image.toString());
		});
	};
}
 
開發者ID:PacktPublishing,項目名稱:Learning-Spring-Boot-2.0-Second-Edition,代碼行數:18,代碼來源:InitDatabase.java

示例6: MongoDbGoogleAuthenticatorTokenCredentialRepository

import org.springframework.data.mongodb.core.MongoOperations; //導入依賴的package包/類
public MongoDbGoogleAuthenticatorTokenCredentialRepository(final IGoogleAuthenticator googleAuthenticator,
                                                           final MongoOperations mongoTemplate,
                                                           final String collectionName,
                                                           final boolean dropCollection) {
    this.mongoTemplate = mongoTemplate;
    this.collectionName = collectionName;
    this.googleAuthenticator = googleAuthenticator;
    Assert.notNull(this.mongoTemplate);

    if (dropCollection) {
        LOGGER.debug("Dropping database collection: [{}]", this.collectionName);
        this.mongoTemplate.dropCollection(this.collectionName);
    }

    if (!this.mongoTemplate.collectionExists(this.collectionName)) {
        LOGGER.debug("Creating database collection: [{}]", this.collectionName);
        this.mongoTemplate.createCollection(this.collectionName);
    }
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:20,代碼來源:MongoDbGoogleAuthenticatorTokenCredentialRepository.java

示例7: MongoDbGoogleAuthenticatorTokenRepository

import org.springframework.data.mongodb.core.MongoOperations; //導入依賴的package包/類
public MongoDbGoogleAuthenticatorTokenRepository(final MongoOperations mongoTemplate,
                                                 final String collectionName,
                                                 final boolean dropCollection,
                                                 final long expireTokensInSeconds) {
    this.mongoTemplate = mongoTemplate;
    this.collectionName = collectionName;
    this.expireTokensInSeconds = expireTokensInSeconds;

    Assert.notNull(this.mongoTemplate);
    Assert.notNull(this.collectionName);

    if (dropCollection) {
        LOGGER.debug("Dropping database collection: [{}]", this.collectionName);
        this.mongoTemplate.dropCollection(this.collectionName);
    }

    if (!this.mongoTemplate.collectionExists(this.collectionName)) {
        LOGGER.debug("Creating database collection: [{}]", this.collectionName);
        this.mongoTemplate.createCollection(this.collectionName);
    }
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:22,代碼來源:MongoDbGoogleAuthenticatorTokenRepository.java

示例8: MongoDbCasEventRepository

import org.springframework.data.mongodb.core.MongoOperations; //導入依賴的package包/類
public MongoDbCasEventRepository(final MongoOperations mongoTemplate, final String collectionName, final boolean dropCollection) {
    this.mongoTemplate = mongoTemplate;
    this.collectionName = collectionName;

    Assert.notNull(this.mongoTemplate);

    if (dropCollection) {
        LOGGER.debug("Dropping database collection: [{}]", this.collectionName);
        this.mongoTemplate.dropCollection(this.collectionName);
    }

    if (!this.mongoTemplate.collectionExists(this.collectionName)) {
        LOGGER.debug("Creating database collection: [{}]", this.collectionName);
        this.mongoTemplate.createCollection(this.collectionName);
    }
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:17,代碼來源:MongoDbCasEventRepository.java

示例9: MongoServiceRegistryDao

import org.springframework.data.mongodb.core.MongoOperations; //導入依賴的package包/類
/**
 * Ctor.
 *
 * @param mongoTemplate  mongoTemplate
 * @param collectionName collectionName
 * @param dropCollection dropCollection
 */
public MongoServiceRegistryDao(final MongoOperations mongoTemplate, final String collectionName, final boolean dropCollection) {
    this.mongoTemplate = mongoTemplate;
    this.collectionName = collectionName;
    this.dropCollection = dropCollection;

    Assert.notNull(this.mongoTemplate);

    if (this.dropCollection) {
        LOGGER.debug("Dropping database collection: [{}]", this.collectionName);
        this.mongoTemplate.dropCollection(this.collectionName);
    }

    if (!this.mongoTemplate.collectionExists(this.collectionName)) {
        LOGGER.debug("Creating database collection: [{}]", this.collectionName);
        this.mongoTemplate.createCollection(this.collectionName);
    }
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:25,代碼來源:MongoServiceRegistryDao.java

示例10: MongoDbMultifactorAuthenticationTrustStorage

import org.springframework.data.mongodb.core.MongoOperations; //導入依賴的package包/類
/**
 * Instantiates a new Mongo db multifactor authentication trust storage.
 *
 * @param collectionName the collection name
 * @param dropCollection id the configured collection should be dropped or recreated
 * @param mongoTemplate  the mongo template
 */
public MongoDbMultifactorAuthenticationTrustStorage(final String collectionName, final boolean dropCollection, final MongoOperations mongoTemplate) {
    this.collectionName = collectionName;
    this.mongoTemplate = mongoTemplate;

    Assert.notNull(this.mongoTemplate);

    if (dropCollection) {
        LOGGER.debug("Dropping database collection: [{}]", this.collectionName);
        this.mongoTemplate.dropCollection(this.collectionName);
    }

    if (!this.mongoTemplate.collectionExists(this.collectionName)) {
        LOGGER.debug("Creating database collection: [{}]", this.collectionName);
        this.mongoTemplate.createCollection(this.collectionName);
    }
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:24,代碼來源:MongoDbMultifactorAuthenticationTrustStorage.java

示例11: onStart

import org.springframework.data.mongodb.core.MongoOperations; //導入依賴的package包/類
/**
 * Application runner to initialize a capped collection for {@link Event}s and insert a new {@link Event} every two
 * seconds.
 * 
 * @param operations
 * @param reactiveOperations
 * @return
 */
@Bean
ApplicationRunner onStart(MongoOperations operations, ReactiveMongoOperations reactiveOperations) {

	return args -> {

		CollectionOptions options = CollectionOptions.empty() //
				.capped() //
				.size(2048) //
				.maxDocuments(1000);

		operations.dropCollection(Event.class);
		operations.createCollection(Event.class, options);

		Flux.interval(Duration.ofSeconds(2)) //
				.map(counter -> new Event(LocalDateTime.now())) //
				.flatMap(reactiveOperations::save) //
				.log() //
				.subscribe();
	};
}
 
開發者ID:olivergierke,項目名稱:spring-five-functional-reactive,代碼行數:29,代碼來源:WebfluxDemo.java

示例12: mongoSessionRepository

import org.springframework.data.mongodb.core.MongoOperations; //導入依賴的package包/類
@Bean
public MongoOperationsSessionRepository mongoSessionRepository(MongoOperations mongoOperations) {

	MongoOperationsSessionRepository repository = new MongoOperationsSessionRepository(mongoOperations);
	repository.setMaxInactiveIntervalInSeconds(this.maxInactiveIntervalInSeconds);

	if (this.mongoSessionConverter != null) {
		repository.setMongoSessionConverter(this.mongoSessionConverter);
	}

	if (StringUtils.hasText(this.collectionName)) {
		repository.setCollectionName(this.collectionName);
	}

	return repository;
}
 
開發者ID:spring-projects,項目名稱:spring-session-data-mongodb,代碼行數:17,代碼來源:MongoHttpSessionConfiguration.java

示例13: setup

import org.springframework.data.mongodb.core.MongoOperations; //導入依賴的package包/類
/** The mongodb ops. */

	/* (non-Javadoc)
	 * @see co.aurasphere.botmill.core.datastore.adapter.DataAdapter#setup()
	 */
	public void setup() {
		
		MongoCredential credential = MongoCredential.createCredential(
				ConfigurationUtils.getEncryptedConfiguration().getProperty("mongodb.username"), 
				ConfigurationUtils.getEncryptedConfiguration().getProperty("mongodb.database"), 
				ConfigurationUtils.getEncryptedConfiguration().getProperty("mongodb.password").toCharArray());
		ServerAddress serverAddress = new ServerAddress(
				ConfigurationUtils.getEncryptedConfiguration().getProperty("mongodb.server"), 
				Integer.valueOf(ConfigurationUtils.getEncryptedConfiguration().getProperty("mongodb.port")));
		MongoClient mongoClient = new MongoClient(serverAddress, Arrays.asList(credential));
		SimpleMongoDbFactory simpleMongoDbFactory = new SimpleMongoDbFactory(mongoClient, ConfigurationUtils.getEncryptedConfiguration().getProperty("mongodb.database"));

		MongoTemplate mongoTemplate = new MongoTemplate(simpleMongoDbFactory);
		this.source = (MongoOperations) mongoTemplate;
	}
 
開發者ID:BotMill,項目名稱:botmill-core,代碼行數:21,代碼來源:MongoDBAdapter.java

示例14: prepare

import org.springframework.data.mongodb.core.MongoOperations; //導入依賴的package包/類
@Override
public void prepare(Description description) {
	super.prepare(description);

	Veiculo veiculo = VeiculoResourceCondition.OBJECT.get();

	MongoOperations mongoOperation = (MongoOperations) ApplicationContextProvider.getApplicationContext().getBean("mongoTemplate");

	Logradouro logradouro = new Logradouro();
	logradouro.setId("1");
	logradouro.setLogradouro("Rua das Acacias");
	logradouro.setCep("88030000");
	logradouro.setTp_logradouro("Rua");

	Infracao infracao1 = createInfracao("1", veiculo, logradouro);
	Infracao infracao2 = createInfracao("2", veiculo, logradouro);
	
	mongoOperation.save(infracao1);
	mongoOperation.save(infracao2);
}
 
開發者ID:UNGPublic,項目名稱:sampleng-backend,代碼行數:21,代碼來源:InfracaoResourceCondition.java

示例15: unsubscribe

import org.springframework.data.mongodb.core.MongoOperations; //導入依賴的package包/類
public void unsubscribe(String subscriptionID) {
	ApplicationContext ctx = new GenericXmlApplicationContext(
			"classpath:MongoConfig.xml");
	MongoOperations mongoOperation = (MongoOperations) ctx
			.getBean("mongoTemplate");

	// Its size should be 0 or 1
	List<SubscriptionType> subscriptions = mongoOperation.find(new Query(
			Criteria.where("subscriptionID").is(subscriptionID)),
			SubscriptionType.class);

	for (int i = 0; i < subscriptions.size(); i++) {
		SubscriptionType subscription = subscriptions.get(i);
		// Remove from current Quartz
		removeScheduleFromQuartz(subscription);
		// Remove from DB list
		removeScheduleFromDB(mongoOperation, subscription);
	}
	((AbstractApplicationContext) ctx).close();
}
 
開發者ID:JaewookByun,項目名稱:epcis,代碼行數:21,代碼來源:MysqlQueryServiceSpring.java


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