/** * @deprecated Use {@link #AbstractMongoRepository(MongoProperties)} instead. */ @Deprecated public AbstractMongoRepository() { mongoProperties = new MongoProperties(); mongoProperties.setDefaultReadTimeout(2000); mongoProperties.setDefaultWriteTimeout(2000); }
/** * Find a single value with the specified key, if existing. * * @param key the key to search for * @return an Optional containing the requested value, or {@code Optional.empty()} if no value with this key exists */ public Optional<V> findOne(final K key) { return findOne(key, mongoProperties.getDefaultReadTimeout(), TimeUnit.MILLISECONDS); }
/** * Deletes the document identified by key. * * @param key the identifier of the deleted document */ public void delete(final K key) { delete(key, mongoProperties.getDefaultWriteTimeout(), TimeUnit.MILLISECONDS); }
private static String getAuthenticationDb(final MongoProperties mongoProperties) { final String authenticationDb = mongoProperties.getAuthenticationDb(); if (authenticationDb != null && !authenticationDb.isEmpty()) { return authenticationDb; } return mongoProperties.getDb(); }
private static boolean useUnauthorizedConnection(final MongoProperties mongoProperties) { return mongoProperties.getUser().isEmpty() || mongoProperties.getPassword().isEmpty(); }
@Test public void shouldReturnPassword() { final MongoProperties props = new MongoProperties(); props.setPassword("somePassword"); assertThat(props.getPassword(), is("somePassword")); }
public TestRepository(final MongoDatabase mongoDatabase) { super(new MongoProperties()); this.collection = mongoDatabase.getCollection("test"); }
@Bean @Primary @ConditionalOnMissingBean(name = "mongoClient", value = MongoClient.class) public MongoClient mongoClient(final MongoProperties mongoProperties) { LOG.info("Creating MongoClient"); return new MongoClient(mongoProperties.getServers(), getMongoCredentials(mongoProperties), mongoProperties.toMongoClientOptions(codecRegistry())); }
@Bean @ConditionalOnProperty(prefix = "edison.mongo", name = "socket-timeout-for-high-timeout-client") public MongoClient mongoClientWithHighSocketTimeout(final MongoProperties mongoProperties) { LOG.info("Creating MongoClient with high socket timeout"); return new MongoClient(mongoProperties.getServers(), getMongoCredentials(mongoProperties), mongoProperties.toMongoClientOptionsWithHighTimeout(codecRegistry())); }
@Bean @ConditionalOnProperty(prefix = "edison.mongo", name = "socket-timeout-for-high-timeout-client") public MongoDatabase mongoDatabaseWithHighSocketTimeout(final MongoClient mongoClientWithHighSocketTimeout, final MongoProperties mongoProperties) { return mongoClientWithHighSocketTimeout.getDatabase(mongoProperties.getDb()); } }
private static boolean useUnauthorizedConnection(final MongoProperties mongoProperties) { return mongoProperties.getUser().isEmpty() || mongoProperties.getPassword().isEmpty(); }
public static Collection<JobMetaRepository> data() { return asList( new MongoJobMetaRepository(EmbeddedMongoHelper.getMongoClient().getDatabase("jobmeta-" + UUID.randomUUID()), "jobmeta", new MongoProperties()), new InMemJobMetaRepository() ); }
@Bean @Primary @ConditionalOnMissingBean(name = "mongoClient", value = MongoClient.class) public MongoClient mongoClient(final MongoProperties mongoProperties) { LOG.info("Creating MongoClient"); return new MongoClient(mongoProperties.getServers(), getMongoCredentials(mongoProperties), mongoProperties.toMongoClientOptions(codecRegistry())); }
private static String getAuthenticationDb(final MongoProperties mongoProperties) { final String authenticationDb = mongoProperties.getAuthenticationDb(); if (authenticationDb != null && !authenticationDb.isEmpty()) { return authenticationDb; } return mongoProperties.getDb(); }
@Bean @Primary @ConditionalOnMissingBean(name = "mongoDatabase", value = MongoDatabase.class) public MongoDatabase mongoDatabase(final MongoClient mongoClient, final MongoProperties mongoProperties) { return mongoClient.getDatabase(mongoProperties.getDb()); }
/** * Find a single value with the specified key, if existing. * * @param key the key to search for * @return an Optional containing the requested value, or {@code Optional.empty()} if no value with this key exists */ public Optional<V> findOne(final K key) { return findOne(key, mongoProperties.getDefaultReadTimeout(), TimeUnit.MILLISECONDS); }
/** * Updates the document if it is already present in the repository. * * @param value the new value * @return true, if the document was updated, false otherwise. */ public boolean update(final V value) { return update(value, mongoProperties.getDefaultWriteTimeout(), TimeUnit.MILLISECONDS); }
private static List<MongoCredential> getMongoCredentials(final MongoProperties mongoProperties) { if (useUnauthorizedConnection(mongoProperties)) { return Collections.emptyList(); } return singletonList(createCredential(mongoProperties.getUser(), getAuthenticationDb(mongoProperties), mongoProperties.getPassword().toCharArray())); }