Add setup for MongoDB and insert (1.4.1)
This commit is contained in:
parent
d81bbb58a9
commit
4bad3fc48f
31
ass1-doc/src/main/java/dst/ass1/doc/impl/DocumentQuery.java
Normal file
31
ass1-doc/src/main/java/dst/ass1/doc/impl/DocumentQuery.java
Normal file
@ -0,0 +1,31 @@
|
||||
package dst.ass1.doc.impl;
|
||||
|
||||
import com.mongodb.MongoClient;
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
import dst.ass1.doc.IDocumentQuery;
|
||||
import org.bson.Document;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DocumentQuery implements IDocumentQuery {
|
||||
private final MongoDatabase db;
|
||||
|
||||
public DocumentQuery(MongoDatabase db) {
|
||||
this.db = db;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Document findLocationById(Long locationId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> findIdsByNameAndRadius(String name, double longitude, double latitude, double radius) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Document> getDocumentStatistics() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
package dst.ass1.doc.impl;
|
||||
|
||||
import com.mongodb.MongoClient;
|
||||
import com.mongodb.client.MongoCollection;
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
import dst.ass1.doc.IDocumentRepository;
|
||||
import dst.ass1.jpa.model.ILocation;
|
||||
import org.bson.Document;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static dst.ass1.jpa.util.Constants.*;
|
||||
|
||||
public class DocumentRepository implements IDocumentRepository {
|
||||
private final MongoClient mongoClient = new MongoClient();
|
||||
|
||||
@Override
|
||||
public void insert(ILocation location, Map<String, Object> locationProperties) {
|
||||
MongoDatabase mongoDatabase = mongoClient.getDatabase(MONGO_DB_NAME);
|
||||
MongoCollection<Document> mongoCollection = mongoDatabase.getCollection(COLL_LOCATION_DATA);
|
||||
|
||||
Document document = new Document(locationProperties)
|
||||
.append(I_LOCATION, location.getLocationId())
|
||||
.append(M_LOCATION_NAME, location.getName());
|
||||
|
||||
mongoCollection.insertOne(document);
|
||||
}
|
||||
}
|
||||
@ -9,13 +9,11 @@ public class DocumentServiceFactory implements IDocumentServiceFactory {
|
||||
|
||||
@Override
|
||||
public IDocumentQuery createDocumentQuery(MongoDatabase db) {
|
||||
// TODO
|
||||
return null;
|
||||
return new DocumentQuery(db);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IDocumentRepository createDocumentRepository() {
|
||||
// TODO
|
||||
return null;
|
||||
return new DocumentRepository();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user