本文整理汇总了Java中org.jongo.MongoCollection.save方法的典型用法代码示例。如果您正苦于以下问题:Java MongoCollection.save方法的具体用法?Java MongoCollection.save怎么用?Java MongoCollection.save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jongo.MongoCollection
的用法示例。
在下文中一共展示了MongoCollection.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: acquireLock
import org.jongo.MongoCollection; //导入方法依赖的package包/类
@Async
public void acquireLock(String issuer, String userAgentString,
String collection, long lockTime) {
MongoCollection syncLogCollection = jongo.getCollection(SYNC_LOG);
SyncLog syncLog = syncLogCollection.findOne("{issuer: #}", issuer).as(SyncLog.class);
boolean firstLog = false;
if (syncLog == null) {
syncLog = new SyncLog();
firstLog = true;
}
syncLog.setIssuer(issuer);
syncLog.setUserAgent(UserAgent.parse(userAgentString));
syncLog.setCollection(collection);
syncLog.setLockAcquired(lockTime);
syncLog.setLockReleased(0);
if (firstLog) {
syncLogCollection.save(syncLog);
} else {
syncLogCollection.update("{issuer: #}", issuer).with(syncLog);
}
}
示例2: remove
import org.jongo.MongoCollection; //导入方法依赖的package包/类
public void remove(String collection, List<Document> removedDocuments) {
long time = System.currentTimeMillis();
MongoCollection mongoCollection = jongo.getCollection(collection);
for (Document document : removedDocuments) {
NitriteDocument nitriteDocument = mongoCollection
.findOne("{ _id: #}", document.getId().getIdValue())
.as(NitriteDocument.class);
if (nitriteDocument != null && !nitriteDocument.isDeleted()) {
nitriteDocument.setDeleted(true);
nitriteDocument.setDeleteTime(time);
nitriteDocument.setSyncTime(time);
mongoCollection.save(nitriteDocument);
}
}
}
示例3: writeFuncParseRecord
import org.jongo.MongoCollection; //导入方法依赖的package包/类
@Override
public void writeFuncParseRecord(String moduleName, String funcName,
String version, long moduleVersion, String parseText) throws TypeStorageException {
try {
MongoCollection recs = jdb.getCollection(TABLE_MODULE_FUNC_PARSE);
recs.remove("{moduleName:#,funcName:#,version:#}", moduleName, funcName, version);
FuncRecord rec = new FuncRecord();
rec.setModuleName(moduleName);
rec.setFuncName(funcName);
rec.setVersion(version);
rec.setModuleVersion(moduleVersion);
rec.setDocument(parseText);
recs.save(rec);
} catch (Exception e) {
throw new TypeStorageException(e);
}
}
示例4: writeTypeParseRecord
import org.jongo.MongoCollection; //导入方法依赖的package包/类
@Override
public void writeTypeParseRecord(String moduleName, String typeName,
String version, long moduleVersion, String document) throws TypeStorageException {
try {
MongoCollection recs = jdb.getCollection(TABLE_MODULE_TYPE_PARSE);
recs.remove("{moduleName:#,typeName:#,version:#}", moduleName, typeName, version);
TypeRecord rec = new TypeRecord();
rec.setModuleName(moduleName);
rec.setTypeName(typeName);
rec.setVersion(version);
rec.setModuleVersion(moduleVersion);
rec.setDocument(document);
recs.save(rec);
} catch (Exception e) {
throw new TypeStorageException(e);
}
}
示例5: newLocation
import org.jongo.MongoCollection; //导入方法依赖的package包/类
@POST
@Path("new")
@Consumes (MediaType.APPLICATION_JSON)
public Response newLocation(Location location) {
Response response;
try {
LOG.info("Received POST XML/JSON Request. New Location request");
if (GoogleGeocoderApiHelper.setGeoLocation(location))
{
//Save the object using Jongo
MongoCollection collection = MongoDatabase.Get_DB_Collection(MONGO_COLLECTIONS.LOCATIONS);
collection.save(location);
response = Response.status(Response.Status.OK).entity(location).build();
} else {
response = Response.status(Response.Status.PRECONDITION_FAILED).entity("Error: Invalid Address").build();
}
} catch (Exception e) {
LOG.error(e);
e.printStackTrace();
response = Response.status(Response.Status.PRECONDITION_FAILED).entity("Error: " + e).build();
}
return response;
}
示例6: updateTotalHostedBikeRideCount
import org.jongo.MongoCollection; //导入方法依赖的package包/类
private void updateTotalHostedBikeRideCount(String rideLeaderId, int totalHostedBikeRideCount) {
try {
//Update User that created the ride.
MongoCollection auCollection = MongoDatabase.Get_DB_Collection(MONGO_COLLECTIONS.ANONYMOUS_USERS);
AnonymousUser rideLeaderAsAnonymousUser = auCollection.findOne(new ObjectId(rideLeaderId)).as(AnonymousUser.class);
if (rideLeaderAsAnonymousUser != null) {
rideLeaderAsAnonymousUser.totalHostedBikeRideCount = totalHostedBikeRideCount;
rideLeaderAsAnonymousUser.latestActiveTimeStamp = new DateTime().withZone(DateTimeZone.UTC).toInstant().getMillis();
auCollection.save(rideLeaderAsAnonymousUser);
} else {
MongoCollection userCollection = MongoDatabase.Get_DB_Collection(MONGO_COLLECTIONS.USERS);
User rideLeaderAsUser = userCollection.findOne(new ObjectId(rideLeaderId)).as(User.class);
rideLeaderAsUser.totalHostedBikeRideCount = totalHostedBikeRideCount;
rideLeaderAsUser.latestActiveTimeStamp = new DateTime().withZone(DateTimeZone.UTC).toInstant().getMillis();
userCollection.save(rideLeaderAsUser);
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例7: updateLatestActiveTimeStamp
import org.jongo.MongoCollection; //导入方法依赖的package包/类
private void updateLatestActiveTimeStamp(String userId) {
try {
//Update User that created the ride.
MongoCollection auCollection = MongoDatabase.Get_DB_Collection(MONGO_COLLECTIONS.ANONYMOUS_USERS);
AnonymousUser rideLeaderAsAnonymousUser = auCollection.findOne(new ObjectId(userId)).as(AnonymousUser.class);
if (rideLeaderAsAnonymousUser != null) {
rideLeaderAsAnonymousUser.latestActiveTimeStamp = new DateTime().withZone(DateTimeZone.UTC).toInstant().getMillis();
auCollection.save(rideLeaderAsAnonymousUser);
} else {
MongoCollection userCollection = MongoDatabase.Get_DB_Collection(MONGO_COLLECTIONS.USERS);
User rideLeaderAsUser = userCollection.findOne(new ObjectId(userId)).as(User.class);
rideLeaderAsUser.latestActiveTimeStamp = new DateTime().withZone(DateTimeZone.UTC).toInstant().getMillis();
userCollection.save(rideLeaderAsUser);
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例8: newObject
import org.jongo.MongoCollection; //导入方法依赖的package包/类
@POST
@Path("new")
public Response newObject(Tracking tracking) {
Response response;
try {
LOG.info("Received POST XML/JSON Request. New Tracking Object");
//Get the object using Jongo
MongoCollection collection = MongoDatabase.Get_DB_Collection(MONGO_COLLECTIONS.TRACKING);
collection.save(tracking);
response = Response.status(Response.Status.OK).entity(tracking).build();
} catch (Exception e) {
LOG.error(e);
e.printStackTrace();
response = Response.status(Response.Status.PRECONDITION_FAILED).entity("Error: " + e).build();
}
return response;
}
示例9: modify
import org.jongo.MongoCollection; //导入方法依赖的package包/类
public void modify(String collection, List<Document> modifiedDocuments) {
long time = System.currentTimeMillis();
MongoCollection mongoCollection = jongo.getCollection(collection);
for (Document document : modifiedDocuments) {
NitriteDocument nitriteDocument = mongoCollection
.findOne("{ _id: #}", document.getId().getIdValue())
.as(NitriteDocument.class);
if (nitriteDocument != null) {
if (nitriteDocument.isDeleted()) {
continue;
}
// update operation
Document existing = nitriteDocument.getDocument();
existing.putAll(document);
nitriteDocument.setSyncTime(time);
nitriteDocument.setDocument(existing);
mongoCollection.save(nitriteDocument);
} else {
// insert operation
nitriteDocument = new NitriteDocument();
if (document.getId() != null
&& document.getId().getIdValue() != null) {
nitriteDocument.setId(document.getId().getIdValue());
}
nitriteDocument.setSyncTime(time);
nitriteDocument.setDeleted(false);
nitriteDocument.setDocument(document);
mongoCollection.save(nitriteDocument);
}
}
}
示例10: putMessage
import org.jongo.MongoCollection; //导入方法依赖的package包/类
protected void putMessage(String jobId, String subject, String body) {
MongoCollection collection = mongoDBService.getCollection(Constants.DB.TO_SEND);
ToSend message = new ToSend();
message.setJobId(jobId);
message.setSubject(subject);
message.setBody(body);
collection.save(message);
}
示例11: doInsert
import org.jongo.MongoCollection; //导入方法依赖的package包/类
private void doInsert(MongoCollection collection, String opQuery, Object[] parameters) throws DataServiceFault {
if (opQuery != null) {
if (parameters.length > 0) {
if (opQuery.equals("#")) {
collection.save(JSON.parse(parameters[0].toString()));
} else {
collection.insert(opQuery, parameters);
}
} else {
collection.insert(opQuery);
}
} else {
throw new DataServiceFault("Mongo insert statements must contain a query");
}
}
示例12: getAnonymousUser
import org.jongo.MongoCollection; //导入方法依赖的package包/类
/**
* Client sends over the device UUID and a 4 digit random number
* @param deviceUUID
* @return
* @throws Exception
*/
@GET
@Path("/anonymous/{key}/{deviceUUID}")
public Response getAnonymousUser(@PathParam("key") String key, @PathParam("deviceUUID") String deviceUUID) throws Exception {
Response response;
try {
LOG.info("Received POST XML/JSON Request. AnonymousUser request");
AnonymousUser au = null;
//check if already an anonymousUser
MongoCollection auCollection = MongoDatabase.Get_DB_Collection(MONGO_COLLECTIONS.ANONYMOUS_USERS);
if (auCollection != null && auCollection.count() > 0) {
Iterable<AnonymousUser> found =
auCollection.find("{deviceAccount.deviceUUID:#, deviceAccount.key:#}",deviceUUID, key)
.sort("{joinedTimeStamp : -1}")
.limit(1)
.as(AnonymousUser.class);
for(AnonymousUser anonymousUser: found) {
au = anonymousUser;
}
}
//Create new if it doesn't exist.
if (au == null ) {
au = new AnonymousUser();
au.deviceAccount.deviceUUID = deviceUUID;
au.deviceAccount.key = key;
au.imagePath = getImagePath(au.imagePath);
LOG.info("AnonymousUser created");
}
//Note the use. Helps us identify active users.
au.latestActiveTimeStamp = new DateTime().withZone(DateTimeZone.UTC).toInstant().getMillis();
//Get the object using Jongo
auCollection.save(au);
response = Response.status(Response.Status.OK).entity(au).build();
} catch (Exception e) {
LOG.error(e);
e.printStackTrace();
response = Response.status(Response.Status.PRECONDITION_FAILED).entity("Error: " + e).build();
}
return response;
}
示例13: changeUser
import org.jongo.MongoCollection; //导入方法依赖的package包/类
private Response changeUser(User submittedUser, SharedStaticValues.UpdateType type) {
Response response = null;
try {
User myUser = null;
boolean validUser = false;
if (submittedUser.oAuth != null && submittedUser.deviceAccount != null) {
validUser = SecurityTools.isLoggedIn(submittedUser) && SecurityTools.isValidUser(submittedUser.id, submittedUser.deviceAccount.deviceUUID);
}
//Validate that the client has access
if (validUser) {
//Validate User exist.
MongoCollection userCollection = MongoDatabase.Get_DB_Collection(MONGO_COLLECTIONS.USERS);
if (userCollection != null && userCollection.count() > 0) {
myUser = userCollection.findOne("{foreignId:#, foreignIdType:#}",submittedUser.oAuth.foreignId, submittedUser.oAuth.foreignIdType).as(User.class);
}
if (myUser != null) {
switch (type) {
case UPDATE_TYPE:
//Update user as requested.
if (!submittedUser.email.equals(myUser.email))
myUser.email = submittedUser.email;
if (!submittedUser.userName.equals(myUser.userName)) {
//Validate that the new name is available
Iterable<User> users = userCollection
.find()
.fields("{userName: 1}")
.as(User.class);
boolean validNewUser = true;
for(User user : users) {
if (submittedUser.userName.equals(user.userName)) {
validNewUser = false;
break; //Currently not notifying the user.
}
}
if (validNewUser) {
myUser.userName = submittedUser.userName;
}
}
if (!myUser.imagePath.equals(submittedUser.imagePath)) {
//Delete Old
ImageHelper imageHelper = new ImageHelper();
imageHelper.deleteImage(myUser.imagePath);
//Update to new image path
myUser.imagePath = getImagePath(submittedUser.imagePath);
}
//Update the object using Jongo
userCollection.save(myUser);
break;
}
//Update the user with updated active timestamp
myUser.latestActiveTimeStamp = new DateTime().withZone(DateTimeZone.UTC).toInstant().getMillis();
} else {
response = Response.status(Response.Status.PRECONDITION_FAILED).entity("Error: Invalid User").build();
}
} else {
response = Response.status(Response.Status.PRECONDITION_FAILED).entity("Error: Not currently logged in.").build();
}
} catch (Exception e) {
LOG.error(e);
e.printStackTrace();
response = Response.status(Response.Status.PRECONDITION_FAILED).entity("Error: " + e).build();
}
return response;
}
示例14: newBikeRide
import org.jongo.MongoCollection; //导入方法依赖的package包/类
@POST
@Path("new/geoloc={latitude: ([-]?[0-9]+).([0-9]+)},{longitude: ([-]?[0-9]+).([0-9]+)}")
@Consumes (MediaType.APPLICATION_JSON)
public Response newBikeRide(BikeRide bikeRide, @PathParam("latitude") BigDecimal latitude, @PathParam("longitude") BigDecimal longitude) {
Response response;
LOG.info("Received POST XML/JSON Request. New BikeRide request");
try {
if (bikeRide != null &&
StringUtils.isNotBlank(bikeRide.bikeRideName) &&
StringUtils.isNotBlank(bikeRide.rideLeaderId) &&
bikeRide.rideStartTime != null &&
StringUtils.isNotBlank(bikeRide.details)) {
if (GoogleGeocoderApiHelper.isValidGeoLoc(latitude, longitude)) {
GeoLoc geoLoc = new GeoLoc();
geoLoc.latitude = latitude;
geoLoc.longitude = longitude;
//Validate real address:
if (GoogleGeocoderApiHelper.setGeoLocation(bikeRide.location) && //Call API for ride geoCodes
GoogleGeocoderApiHelper.setBikeRideLocationId(bikeRide)) {
bikeRide.imagePath = getImagePath(bikeRide.imagePath);
//save the object using Jongo
MongoCollection collectionBikeRides = MongoDatabase.Get_DB_Collection(MONGO_COLLECTIONS.BIKERIDES);
collectionBikeRides.save(bikeRide);
final int totalHostedBikeRideCount = (int) collectionBikeRides.count("{rideLeaderId:#}", bikeRide.rideLeaderId);
updateTotalHostedBikeRideCount(bikeRide.rideLeaderId, totalHostedBikeRideCount);
bikeRide = CommonBikeRideCalls.postBikeRideDBUpdates(bikeRide, geoLoc);
response = Response.status(Response.Status.OK).entity(bikeRide).build();
} else {
//Invalid address
LOG.info("Invalid address, we're not making the ride sucker!");
response = Response.status(Response.Status.PRECONDITION_FAILED).entity("Invalid Address").build();
}
} else {
response = Response.status(Response.Status.PRECONDITION_FAILED).entity("Error: Invalid GeoLocation").build();
}
} else {
response = Response.status(Response.Status.PRECONDITION_FAILED).entity("Please complete all fields.").build();
}
} catch (Exception e) {
LOG.error(e.getMessage());
e.printStackTrace();
response = Response.status(Response.Status.PRECONDITION_FAILED).entity("Error: " + e).build();
}
return response;
}
示例15: setBikeRideLocationId
import org.jongo.MongoCollection; //导入方法依赖的package包/类
public static boolean setBikeRideLocationId(BikeRide bikeRide) {
try {
Location location = new Location();
List<Location> locations = new ArrayList<Location>();
//Polish location data
if (bikeRide.location.city != null) {
bikeRide.location.city = bikeRide.location.city.trim();
}
if (bikeRide.location.state != null) {
bikeRide.location.state = bikeRide.location.state.trim();
}
if (bikeRide.location.country != null) {
bikeRide.location.country = bikeRide.location.country.trim();
}
//Build location
StringBuilder addressAsBuilder = new StringBuilder();
addressAsBuilder.append(bikeRide.location.city).append(", ").append(bikeRide.location.state);
if (StringUtils.isNotBlank(bikeRide.location.country)) {
addressAsBuilder.append(", ").append(bikeRide.location.country);
}
//Check is current city exist
MongoCollection locationCollection = MongoDatabase.Get_DB_Collection(MONGO_COLLECTIONS.LOCATIONS);
Iterable<Location> locationsIterable = locationCollection
.find("{formattedAddress: {$regex: '"+addressAsBuilder.toString()+".*', $options: 'i'} }")
.limit(1)
.as(Location.class);
locations = Lists.newArrayList(locationsIterable);
if (locations == null || locations.size() == 0) {
//Add new location to the DB
location.city = (bikeRide.location.city);
location.state = (bikeRide.location.state);
location.country = (bikeRide.location.country);
GoogleGeocoderApiHelper.setGeoLocation(location); //Call API for city center geoCode
//Recheck after pulling back google result to make sure that prior google result is not in our system.
locationsIterable = locationCollection
.find("{formattedAddress: {$regex: '"+location.formattedAddress+".*', $options: 'i'} }")
.limit(1)
.as(Location.class);
locations = Lists.newArrayList(locationsIterable);
if (locations == null || locations.size() == 0) {
locationCollection.save(location);
} else {
location = locations.get(0);
}
} else {
location = locations.get(0);
}
bikeRide.cityLocationId = location.id;
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}