File tree Expand file tree Collapse file tree 4 files changed +99
-0
lines changed
config-layers/common/io/vertx/ext/mongo
src/main/java/io/vertx/reactivex/ext/mongo Expand file tree Collapse file tree 4 files changed +99
-0
lines changed Original file line number Diff line number Diff line change 1+ # /io/vertx/ext/mongo/LoadMongoDataService
2+ $class =io.vertx.reactivex.ext.mongo.LoadMongoDataService
3+
4+ # Example Data JSON
5+ # {
6+ # "test": [
7+ # {
8+ # "name": "data1"
9+ # },
10+ # {
11+ # "name": "data2"
12+ # }
13+ # ],
14+ # "test2": [
15+ # {
16+ # "name": "data1"
17+ # },
18+ # {
19+ # "name": "data2"
20+ # }
21+ # ]
22+ # }
23+
24+ enable =false
25+ mongoClient^ =/io/vertx/ext/mongo/MongoClientInstance.mongoClient
26+ data =data.json
27+
Original file line number Diff line number Diff line change 1+ {}
Original file line number Diff line number Diff line change 1+ {
2+ "db_name" : " " ,
3+ "connection_string" : " mongodb://localhost:27017"
4+ }
Original file line number Diff line number Diff line change 1+ package io .vertx .reactivex .ext .mongo ;
2+
3+ import in .erail .glue .annotation .StartService ;
4+ import io .reactivex .Observable ;
5+ import io .vertx .core .json .JsonArray ;
6+ import io .vertx .core .json .JsonObject ;
7+ import java .util .Set ;
8+
9+ /**
10+ *
11+ * @author vinay
12+ */
13+ public class LoadMongoDataService {
14+
15+ private MongoClient mMongoClient ;
16+ private JsonObject mData ;
17+ private boolean mEnable ;
18+
19+ @ StartService
20+ public void start () {
21+
22+ if (!isEnable ()) {
23+ return ;
24+ }
25+
26+ Set <String > collections = mData .fieldNames ();
27+ for (String collection : collections ) {
28+ mMongoClient
29+ .rxDropCollection (collection )
30+ .andThen (mMongoClient .rxCreateCollection (collection ))
31+ .blockingAwait ();
32+
33+ JsonArray data = mData .getJsonArray (collection );
34+
35+ Observable
36+ .fromIterable (data )
37+ .map (m -> (JsonObject ) m )
38+ .doOnNext ((t ) -> {
39+ mMongoClient .rxSave (collection , t ).blockingGet ();
40+ }).blockingSubscribe ();
41+ }
42+ }
43+
44+ public MongoClient getMongoClient () {
45+ return mMongoClient ;
46+ }
47+
48+ public void setMongoClient (MongoClient pMongoClient ) {
49+ this .mMongoClient = pMongoClient ;
50+ }
51+
52+ public JsonObject getData () {
53+ return mData ;
54+ }
55+
56+ public void setData (JsonObject pData ) {
57+ this .mData = pData ;
58+ }
59+
60+ public boolean isEnable () {
61+ return mEnable ;
62+ }
63+
64+ public void setEnable (boolean pEnable ) {
65+ this .mEnable = pEnable ;
66+ }
67+ }
You can’t perform that action at this time.
0 commit comments