-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Composite Sharding implementation (#10)
- Loading branch information
1 parent
a1d7e0a
commit 77b6665
Showing
19 changed files
with
299 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...ing-core/src/main/java/com/alpha/mongodb/sharding/core/CompositeShardedMongoTemplate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.alpha.mongodb.sharding.core; | ||
|
||
import com.alpha.mongodb.sharding.core.configuration.CompositeShardingOptions; | ||
import com.mongodb.client.MongoClient; | ||
import org.springframework.data.mongodb.MongoDatabaseFactory; | ||
import org.springframework.data.mongodb.core.convert.MongoConverter; | ||
import org.springframework.data.mongodb.core.query.Query; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Composite Sharded Mongo Template to be used with collections that are | ||
* sharded both by Database and Collection | ||
* | ||
* @author Shashank Sharma | ||
*/ | ||
public class CompositeShardedMongoTemplate extends DatabaseShardedMongoTemplate { | ||
|
||
public CompositeShardedMongoTemplate(MongoClient mongoClient, String databaseName, CompositeShardingOptions shardingOptions) { | ||
super(mongoClient, databaseName, shardingOptions); | ||
} | ||
|
||
public CompositeShardedMongoTemplate(Map<String, MongoDatabaseFactory> delegatedDatabaseFactory, CompositeShardingOptions shardingOptions) { | ||
super(delegatedDatabaseFactory, shardingOptions); | ||
} | ||
|
||
public CompositeShardedMongoTemplate(Map<String, MongoDatabaseFactory> delegatedDatabaseFactory, MongoConverter mongoConverter, CompositeShardingOptions shardingOptions) { | ||
super(delegatedDatabaseFactory, mongoConverter, shardingOptions); | ||
} | ||
|
||
@Override | ||
public long countFromAll(Query query, Class<?> entityClass) { | ||
return this.getDelegatedShardedMongoTemplateMap().values().stream().mapToLong(mongoTemplate -> ((CollectionShardedMongoTemplate) mongoTemplate).countFromAll(query, entityClass)).sum(); | ||
} | ||
|
||
@Override | ||
public long countFromAll(Query query, String collectionName) { | ||
return this.getDelegatedShardedMongoTemplateMap().values().stream().mapToLong(mongoTemplate -> ((CollectionShardedMongoTemplate) mongoTemplate).countFromAll(query, collectionName)).sum(); | ||
} | ||
|
||
@Override | ||
public long countFromAll(Query query, Class<?> entityClass, String collectionName) { | ||
return this.getDelegatedShardedMongoTemplateMap().values().stream().mapToLong(mongoTemplate -> ((CollectionShardedMongoTemplate) mongoTemplate).countFromAll(query, entityClass, collectionName)).sum(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.