Browse Source
- Update Javadoc comments and reference documentation. - Introduce Adapter for blocking IndexOperations. - Remove transaction synchronization. - Remove unused types. - Remove dropDupos options from indexes. - Prevent usage of Querydsl along with reactive repository. - Use ReactiveQueryMethod in ReactiveMongoQuery.pull/411/merge
58 changed files with 493 additions and 771 deletions
@ -0,0 +1,66 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2016. the original author or authors. |
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
* you may not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
package org.springframework.data.mongodb.core; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
import org.springframework.data.mongodb.core.index.IndexDefinition; |
||||||
|
import org.springframework.data.mongodb.core.index.IndexInfo; |
||||||
|
import org.springframework.util.Assert; |
||||||
|
|
||||||
|
/** |
||||||
|
* Adapter for creating synchronous {@link IndexOperations}. |
||||||
|
* |
||||||
|
* @author Christoph Strobl |
||||||
|
* @since 2.0 |
||||||
|
*/ |
||||||
|
public interface IndexOperationsAdapter extends IndexOperations { |
||||||
|
|
||||||
|
/** |
||||||
|
* Obtain a blocking variant of {@link IndexOperations} wrapping {@link ReactiveIndexOperations}. |
||||||
|
* |
||||||
|
* @param reactiveIndexOperations must not be {@literal null}. |
||||||
|
* @return never {@literal null} |
||||||
|
*/ |
||||||
|
static IndexOperationsAdapter blocking(ReactiveIndexOperations reactiveIndexOperations) { |
||||||
|
|
||||||
|
Assert.notNull(reactiveIndexOperations, "ReactiveIndexOperations must not be null!"); |
||||||
|
|
||||||
|
return new IndexOperationsAdapter() { |
||||||
|
|
||||||
|
@Override |
||||||
|
public String ensureIndex(IndexDefinition indexDefinition) { |
||||||
|
return reactiveIndexOperations.ensureIndex(indexDefinition).block(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void dropIndex(String name) { |
||||||
|
reactiveIndexOperations.dropIndex(name).block(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void dropAllIndexes() { |
||||||
|
reactiveIndexOperations.dropAllIndexes().block(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public List<IndexInfo> getIndexInfo() { |
||||||
|
return reactiveIndexOperations.getIndexInfo().collectList().block(); |
||||||
|
} |
||||||
|
}; |
||||||
|
} |
||||||
|
} |
||||||
@ -1,88 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright 2016 the original author or authors. |
|
||||||
* |
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
||||||
* you may not use this file except in compliance with the License. |
|
||||||
* You may obtain a copy of the License at |
|
||||||
* |
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* |
|
||||||
* Unless required by applicable law or agreed to in writing, software |
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, |
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
||||||
* See the License for the specific language governing permissions and |
|
||||||
* limitations under the License. |
|
||||||
*/ |
|
||||||
|
|
||||||
package org.springframework.data.mongodb.core; |
|
||||||
|
|
||||||
|
|
||||||
import com.mongodb.reactivestreams.client.MongoDatabase; |
|
||||||
|
|
||||||
import java.util.Map; |
|
||||||
import java.util.concurrent.ConcurrentHashMap; |
|
||||||
|
|
||||||
import org.springframework.transaction.support.ResourceHolderSupport; |
|
||||||
import org.springframework.util.Assert; |
|
||||||
|
|
||||||
|
|
||||||
/** |
|
||||||
* @author Mark Paluch |
|
||||||
*/ |
|
||||||
class ReactiveMongoDatabaseHolder extends ResourceHolderSupport { |
|
||||||
private static final Object DEFAULT_KEY = new Object(); |
|
||||||
|
|
||||||
private final Map<Object, MongoDatabase> dbMap = new ConcurrentHashMap<Object, MongoDatabase>(); |
|
||||||
|
|
||||||
public ReactiveMongoDatabaseHolder(MongoDatabase db) { |
|
||||||
addMongoDatabase(db); |
|
||||||
} |
|
||||||
|
|
||||||
public ReactiveMongoDatabaseHolder(Object key, MongoDatabase db) { |
|
||||||
addMongoDatabase(key, db); |
|
||||||
} |
|
||||||
|
|
||||||
public MongoDatabase getMongoDatabase() { |
|
||||||
return getMongoDatabase(DEFAULT_KEY); |
|
||||||
} |
|
||||||
|
|
||||||
public MongoDatabase getMongoDatabase(Object key) { |
|
||||||
return this.dbMap.get(key); |
|
||||||
} |
|
||||||
|
|
||||||
public MongoDatabase getAnyMongoDatabase() { |
|
||||||
if (!this.dbMap.isEmpty()) { |
|
||||||
return this.dbMap.values().iterator().next(); |
|
||||||
} |
|
||||||
return null; |
|
||||||
} |
|
||||||
|
|
||||||
public void addMongoDatabase(MongoDatabase session) { |
|
||||||
addMongoDatabase(DEFAULT_KEY, session); |
|
||||||
} |
|
||||||
|
|
||||||
public void addMongoDatabase(Object key, MongoDatabase session) { |
|
||||||
Assert.notNull(key, "Key must not be null"); |
|
||||||
Assert.notNull(session, "DB must not be null"); |
|
||||||
this.dbMap.put(key, session); |
|
||||||
} |
|
||||||
|
|
||||||
public MongoDatabase removeMongoDatabase(Object key) { |
|
||||||
return this.dbMap.remove(key); |
|
||||||
} |
|
||||||
|
|
||||||
public boolean containsMongoDatabase(MongoDatabase session) { |
|
||||||
return this.dbMap.containsValue(session); |
|
||||||
} |
|
||||||
|
|
||||||
public boolean isEmpty() { |
|
||||||
return this.dbMap.isEmpty(); |
|
||||||
} |
|
||||||
|
|
||||||
public boolean doesNotHoldNonDefaultMongoDatabase() { |
|
||||||
synchronized (this.dbMap) { |
|
||||||
return this.dbMap.isEmpty() || (this.dbMap.size() == 1 && this.dbMap.containsKey(DEFAULT_KEY)); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
Loading…
Reference in new issue