本文整理汇总了Java中org.jongo.MongoCollection类的典型用法代码示例。如果您正苦于以下问题:Java MongoCollection类的具体用法?Java MongoCollection怎么用?Java MongoCollection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MongoCollection类属于org.jongo包,在下文中一共展示了MongoCollection类的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: removedItems
import org.jongo.MongoCollection; //导入依赖的package包/类
public List<Document> removedItems(String collection, long fromSequence, long newSequence) {
List<Document> documentList = new ArrayList<>();
MongoCollection userCollection = jongo.getCollection(collection);
MongoCursor<NitriteDocument> removeLogs = userCollection
.find("{" +
" $and: [" +
" {" + DELETED + ": { $eq: true }}," +
" {" + DELETE_TIME + ": { $gte: # }}," +
" {" + DELETE_TIME + ": { $lte: # }}" +
" ]}", fromSequence, newSequence)
.as(NitriteDocument.class);
if (removeLogs != null) {
for (NitriteDocument logEntry : removeLogs) {
Document document = new Document(logEntry.getDocument());
document.remove(DOC_SOURCE);
documentList.add(document);
}
}
return documentList;
}
示例3: modifiedItems
import org.jongo.MongoCollection; //导入依赖的package包/类
public List<Document> modifiedItems(String collection, long fromSequence, long newSequence) {
MongoCollection userCollection = jongo.getCollection(collection);
MongoCursor<NitriteDocument> documents = userCollection
.find("{" +
" $and: [" +
" {" + DELETED + ": { $eq: false }}," +
" {" + SYNC_TIME + ": { $gte: # }}," +
" {" + SYNC_TIME + ": { $lte: # }}" +
" ]}", fromSequence, newSequence)
.as(NitriteDocument.class);
List<Document> result = new ArrayList<>();
for (NitriteDocument nitriteDocument : documents) {
Document doc = new Document(nitriteDocument.getDocument());
doc.remove(DOC_SOURCE);
result.add(doc);
}
return result;
}
示例4: 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);
}
}
}
示例5: setUp
import org.jongo.MongoCollection; //导入依赖的package包/类
@Before
public void setUp() {
UserAccount clientAccount = new UserAccount();
clientAccount.setUserName("wh_client");
clientAccount.setPassword("wh_secret");
clientAccount.setAuthorities(new String[] {AUTH_CLIENT});
MongoCollection collection = jongo.getCollection(USER_REPO);
collection.insert(clientAccount);
UserAccount userAccount = new UserAccount();
userAccount.setUserName("test");
userAccount.setPassword("password");
userAccount.setAuthorities(new String[] {AUTH_USER});
userAccount.setCollections(new ArrayList<String>() {{ add("test-collection"); }});
ResponseEntity<Void> responseEntity = restTemplate
.withBasicAuth("wh_client", "wh_secret")
.postForEntity("/api/v1/user/create", userAccount, Void.class);
assertNotNull(responseEntity);
assertEquals(responseEntity.getStatusCodeValue(), 200);
}
示例6: testCreateUser
import org.jongo.MongoCollection; //导入依赖的package包/类
@Test
public void testCreateUser() {
UserAccount userAccount = new UserAccount();
userAccount.setUserName("test");
userAccount.setPassword("password");
userAccount.setAuthorities(new String[] {AUTH_USER});
userAccount.setCollections(new ArrayList<String>() {{ add("test-collection"); }});
ResponseEntity<Void> responseEntity = restTemplate
.withBasicAuth("wh_client", "wh_secret")
.postForEntity("/api/v1/user/create", userAccount, Void.class);
assertNotNull(responseEntity);
assertEquals(responseEntity.getStatusCodeValue(), 200);
MongoCollection collection = jongo.getCollection(USER_REPO);
UserAccount account = collection.findOne("{userName: 'test'}").as(UserAccount.class);
assertEquals(account, userAccount);
collection.remove("{userName: 'test'}");
}
示例7: testDeleteUser
import org.jongo.MongoCollection; //导入依赖的package包/类
@Test
public void testDeleteUser() {
UserAccount userAccount = new UserAccount();
userAccount.setUserName("test");
userAccount.setPassword("password");
userAccount.setAuthorities(new String[] {AUTH_USER});
userAccount.setCollections(new ArrayList<String>() {{ add("test-collection"); }});
ResponseEntity<Void> responseEntity = restTemplate
.withBasicAuth("wh_client", "wh_secret")
.postForEntity("/api/v1/user/create", userAccount, Void.class);
assertNotNull(responseEntity);
assertEquals(responseEntity.getStatusCodeValue(), 200);
MongoCollection collection = jongo.getCollection(USER_REPO);
UserAccount account = collection.findOne("{userName: 'test'}").as(UserAccount.class);
assertEquals(account, userAccount);
restTemplate.withBasicAuth("wh_client", "wh_secret")
.delete("/api/v1/user/delete/test");
collection = jongo.getCollection(USER_REPO);
account = collection.findOne("{userName: 'test'}").as(UserAccount.class);
assertNull(account);
}
示例8: getEventsWithinDates
import org.jongo.MongoCollection; //导入依赖的package包/类
/**
* Fetches events that occur within two dates.
*
* @param fromDate Starting date.
* @param toDate Ending date.
*
* @return A list of events.
*/
public List<Event> getEventsWithinDates(long fromDate, long toDate) {
MongoCollection collection = db.getClient().getCollection("events");
List<Event> eventList = new ArrayList<>();
List<Event> events = cursorToArray(collection.find("{ startDateTime: { " +
"$gte: #," +
"$lt: # } }", fromDate, toDate).as(Event.class));
List<Event> recurringEvents = cursorToArray(collection.find("{ recurring: true }").as(Event.class));
for (Event event : events) {
for (Event recurringEvent : recurringEvents) {
if (!recurringEvent.getId().equals(event.getId()) && recurringEvent.getRecursUntil() <= toDate) {
eventList.add(recurringEvent);
}
}
eventList.add(event);
}
return eventList;
}
示例9: saveImage
import org.jongo.MongoCollection; //导入依赖的package包/类
/**
* Saves an image in the database.
*
* @param name The filename of the image, including type.
* @param file The file to be saved.
* @param path The special path that ties an event to an image.
* @param type The mimetype of the image.
* @return A boolean that indicates whether the saving was successful.
*/
@Override
public boolean saveImage(String name, MultipartFile file, String path, String type) {
byte[] imageByteArray;
try {
imageByteArray = file.getBytes();
} catch (IOException e) {
e.printStackTrace();
return false;
}
Image image = new Image(name, imageByteArray, path, type);
MongoCollection collection = client.getClient().getCollection("images");
collection.insert(image);
return true;
}
示例10: createUser
import org.jongo.MongoCollection; //导入依赖的package包/类
public UserEntity createUser(String accountId, String username) {
JongoDBService manager = AppContext.getManager(JongoDBService.class);
Jongo jongo = manager.getJongo();
MongoCollection collection = jongo.getCollection("USER");
UserEntity userEntity = new UserEntity();
userEntity.setUserId(accountId);
userEntity.setAccountId(accountId);
userEntity.setLevel(1);
userEntity.setUserName(username);
try {
collection.insert(userEntity);
return userEntity;
} catch (com.mongodb.DuplicateKeyException e) {
}
return null;
}
示例11: migrateGeneralScriptFunctions
import org.jongo.MongoCollection; //导入依赖的package包/类
private void migrateGeneralScriptFunctions(GlobalContext context) {
logger.info("Searching for functions of type 'step.plugins.functions.types.GeneralScriptFunction' to be migrated...");
com.mongodb.client.MongoCollection<Document> functions = MongoDBAccessorHelper.getMongoCollection_(context.getMongoClient(), "functions");
AtomicInteger i = new AtomicInteger();
Document filterCallFunction = new Document("type", "step.plugins.functions.types.GeneralScriptFunction");
functions.find(filterCallFunction).forEach(new Block<Document>() {
@Override
public void apply(Document t) {
t.replace("type", "step.plugins.java.GeneralScriptFunction");
Document filter = new Document("_id", t.get("_id"));
functions.replaceOne(filter, t);
i.incrementAndGet();
}
});
logger.info("Migrated "+i.get()+" functions of type 'step.plugins.functions.types.GeneralScriptFunction'");
}
示例12: renameArtefactType
import org.jongo.MongoCollection; //导入依赖的package包/类
private void renameArtefactType(GlobalContext context, String classFrom, String classTo) {
logger.info("Searching for artefacts of type '"+classFrom+"' to be migrated...");
com.mongodb.client.MongoCollection<Document> artefacts = MongoDBAccessorHelper.getMongoCollection_(context.getMongoClient(), "artefacts");
AtomicInteger i = new AtomicInteger();
Document filterCallFunction = new Document("_class", classFrom);
artefacts.find(filterCallFunction).forEach(new Block<Document>() {
@Override
public void apply(Document t) {
try {
i.incrementAndGet();
t.put("_class", classTo);
Document filter = new Document("_id", t.get("_id"));
artefacts.replaceOne(filter, t);
logger.info("Migrating "+classFrom+ " to "+t.toJson());
} catch(ClassCastException e) {
// ignore
}
}
});
logger.info("Migrated "+i.get()+" artefacts of type '"+classFrom+"'");
}
示例13: setupDemo
import org.jongo.MongoCollection; //导入依赖的package包/类
private void setupDemo(GlobalContext context) {
MongoCollection functionCollection = MongoDBAccessorHelper.getCollection(context.getMongoClient(), "functions");
FunctionRepositoryImpl functionRepository = new FunctionRepositoryImpl(functionCollection);
JsonObject schema = null;
if(context.getConfiguration().getPropertyAsBoolean("enforceschemas", false)){
StringReader sr = new StringReader("{\"properties\":{\"label\":{\"type\":\"string\"}},\"required\":[\"label\"]}");
schema = Json.createReader(sr).readObject();
sr.close();
}
Function javaFunction = addScriptFunction(functionRepository, "Demo_Keyword_Java", "java", "../data/scripts/demo-java-keyword.jar", schema);
Function javascriptFunction = addScriptFunction(functionRepository, "Demo_Keyword_Javascript", "javascript", "../data/scripts/Demo_Keyword_Javascript.js");
Function openChrome = addSeleniumFunction(functionRepository, "Open_Chrome", "java", "../data/scripts/demo-selenium-keyword.jar" );
Function googleSearch = addSeleniumFunction(functionRepository, "Google_Search", "java", "../data/scripts/demo-selenium-keyword.jar" );
Function googleSearchMock = addSeleniumFunction(functionRepository, "Google_Search_Mock", "javascript", "../data/scripts/Google_Search_Mock.js" );
Function jmeterDemoFunction = addJMeterFunction(functionRepository, "Demo_Keyword_JMeter", "../data/scripts/Demo_JMeter.jmx");
}
示例14: from
import org.jongo.MongoCollection; //导入依赖的package包/类
public MongoCollection from(EntityType type) {
switch (type) {
case AOC:
return aocs.get();
case REGION:
return regions.get();
case DOMAIN:
return domains.get();
case CELLAR:
return cellars.get();
case RECORD:
return records.get();
case MOVEMENT:
return movements.get();
}
return null;
}
示例15: getAllRegisteredModules
import org.jongo.MongoCollection; //导入依赖的package包/类
@Override
public Set<String> getAllRegisteredModules(boolean withUnsupported) throws TypeStorageException {
try {
MongoCollection infos = jdb.getCollection(TABLE_MODULE_VERSION);
Map<String, Boolean> map = getProjection(infos, "{}", "moduleName", String.class, "supported", Boolean.class);
Set<String> ret = new TreeSet<String>();
if (withUnsupported) {
ret.addAll(map.keySet());
} else {
for (String module : map.keySet())
if (map.get(module))
ret.add(module);
}
return ret;
} catch (Exception e) {
throw new TypeStorageException(e);
}
}