Skip to content

Commit 6b52954

Browse files
committed
Merge pull request #9 from Red1L/add-indexes-autobuild
Add automatically build indexes
2 parents ee03fc3 + fe71afb commit 6b52954

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Version 1.1.0 (?)
22

3+
* [new] Automatically build indexes
34
* [new] Add Bean Validation support to Morphia (at pre-persist).
45
* [new] Add `exists()` and `count()` in `BaseMorphiaRepository`.
56
* [chg] Update for SeedStack 16.4.

morphia/src/main/java/org/seedstack/mongodb/morphia/internal/DatastoreProvider.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@ public Datastore get() {
4242
MorphiaUtils.getMongoClientConfiguration(application.getConfiguration(), morphiaDatastore.clientName()),
4343
morphiaDatastore.dbName()
4444
);
45-
46-
return morphia.createDatastore(
45+
Datastore datastore = morphia.createDatastore(
4746
injector.getInstance(Key.get(MongoClient.class, Names.named(morphiaDatastore.clientName()))),
4847
resolvedDbName
4948
);
49+
datastore.ensureIndexes(true);
50+
datastore.ensureCaps();
51+
return datastore;
5052
}
5153
}

morphia/src/main/java/org/seedstack/mongodb/morphia/internal/MorphiaModule.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import com.google.inject.AbstractModule;
1414
import com.google.inject.Key;
15+
import com.google.inject.Scopes;
1516
import org.mongodb.morphia.Datastore;
1617
import org.mongodb.morphia.Morphia;
1718
import org.seedstack.mongodb.morphia.MorphiaDatastore;
@@ -37,7 +38,7 @@ protected void configure() {
3738
for (MorphiaDatastore morphiaDatastore : morphiaDatastoresAnnotation) {
3839
DatastoreProvider datastoreProvider = new DatastoreProvider(morphiaDatastore, morphia);
3940
requestInjection(datastoreProvider);
40-
bind(Key.get(Datastore.class, morphiaDatastore)).toProvider(datastoreProvider);
41+
bind(Key.get(Datastore.class, morphiaDatastore)).toProvider(datastoreProvider).in(Scopes.SINGLETON);
4142
}
4243
}
4344
}

0 commit comments

Comments
 (0)