Java Code Examples for org.bson.Document#getInteger()
The following examples show how to use
org.bson.Document#getInteger() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MongodbHelper.java From cassandana with Apache License 2.0 | 6 votes |
@Override public AclEntity getAcl(String topic, String username, String clientId) { FindIterable<Document> findIterable = aclCollection.find(eq("username", username)); MongoCursor<Document> cursor = findIterable.iterator(); AclEntity acl = null; if(cursor.hasNext()) { Document document = cursor.next(); acl = new AclEntity(); acl.username = username; acl.clientId = clientId; acl.topic = topic; acl.canPublish = (document.getInteger("write") == 1); acl.canSubscribe = (document.getInteger("read") == 1); } cursor.close(); return acl; }
Example 2
Source File: MongoPcjDocuments.java From rya with Apache License 2.0 | 6 votes |
/** * Gets the {@link PcjMetadata} from a provided PCJ Id. * * @param pcjId - The Id of the PCJ to get from MongoDB. (not null) * @return - The {@link PcjMetadata} of the Pcj specified. * @throws PCJStorageException The PCJ metadata document does not exist. */ public PcjMetadata getPcjMetadata(final String pcjId) throws PCJStorageException { requireNonNull(pcjId); // since query by ID, there will only be one. final Document result = pcjCollection.find(new Document(PCJ_METADATA_ID, makeMetadataID(pcjId))).first(); if(result == null) { throw new PCJStorageException("The PCJ: " + pcjId + " does not exist."); } final String sparql = result.getString(SPARQL_FIELD); final int cardinality = result.getInteger(CARDINALITY_FIELD, 0); @SuppressWarnings("unchecked") final List<List<String>> varOrders = (List<List<String>>) result.get(VAR_ORDER_FIELD); final Set<VariableOrder> varOrder = new HashSet<>(); for(final List<String> vars : varOrders) { varOrder.add(new VariableOrder(vars)); } return new PcjMetadata(sparql, cardinality, varOrder); }
Example 3
Source File: MongoWithReplicasTestBase.java From quarkus with Apache License 2.0 | 6 votes |
private static boolean isReplicaSetStarted(final Document setting) { if (!setting.containsKey("members")) { return false; } @SuppressWarnings("unchecked") final List<Document> members = setting.get("members", List.class); for (final Document member : members) { LOGGER.infof("replica set member %s", member); final int state = member.getInteger("state"); LOGGER.infof("state: %s", state); // 1 - PRIMARY, 2 - SECONDARY, 7 - ARBITER if (state != 1 && state != 2 && state != 7) { return false; } } return true; }
Example 4
Source File: Portal.java From Much-Assembly-Required with GNU General Public License v3.0 | 5 votes |
public Portal(Document document) { super(document, 1, 1); destination = new Location( document.getInteger("dstWorldX"), document.getInteger("dstWorldY"), document.getString("dstDimension"), document.getInteger("dstX"), document.getInteger("dstY")); setX(document.getInteger("x")); setY(document.getInteger("y")); }
Example 5
Source File: ScoredPattern.java From baleen with Apache License 2.0 | 5 votes |
/** * Construct the Scored pattern from the given document * * @param document (mongo) to construct from */ public ScoredPattern(Document document) { pattern = document.getString(PATTERN_FACT_FIELD); frequency = document.getInteger(FREQUENCY_KEY); coherence = document.getDouble(COHERENCE_KEY); }
Example 6
Source File: MongoDbWriter.java From MongoDb-Sink-Connector with Apache License 2.0 | 5 votes |
private void retrieveOffsets() { MongoIterable<Document> documentIterable = mongoHelper.getDocuments(OFFSETS_COLLECTION); try (MongoCursor<Document> documents = documentIterable.iterator()) { while (documents.hasNext()) { Document doc = documents.next(); Document id = (Document) doc.get("_id"); String topic = id.getString("topic"); int partition = id.getInteger("partition"); long offset = doc.getLong("offset"); latestOffsets.put(new TopicPartition(topic, partition), offset); } } }
Example 7
Source File: CubotInventory.java From Much-Assembly-Required with GNU General Public License v3.0 | 5 votes |
public CubotInventory(Document document, ControllableUnit cubot) { super(document, cubot); position = document.getInteger("position"); inventorySize = document.getInteger("size"); inventory = new HashMap<>(); for (String i : ((Map<String, Document>) document.get("inventory")).keySet()) { inventory.put(Integer.valueOf(i), GameServer.INSTANCE.getRegistry().deserializeItem(((Map<String, Document>) document.get("inventory")).get(i))); } }
Example 8
Source File: MongoBlockServiceImpl.java From nuls-v2 with MIT License | 5 votes |
@Override public int getBlockPackageTxCount(int chainId, long startHeight, long endHeight) { if (!CacheManager.isChainExist(chainId)) { return 0; } BasicDBObject fields = new BasicDBObject(); fields.append("txCount", 1); Bson filter = Filters.and(Filters.gt("_id", startHeight), Filters.lte("_id", endHeight)); List<Document> docsList = this.mongoDBService.query(BLOCK_HEADER_TABLE + chainId, filter, fields, Sorts.descending("_id")); int count = 0; for (Document document : docsList) { count += document.getInteger("txCount"); } return count; }
Example 9
Source File: MongoAccountLedgerServiceImpl.java From nuls-v2 with MIT License | 5 votes |
@Override public List<AccountLedgerInfo> getAccountCrossLedgerInfoList(int chainId, String address) { Bson filter = Filters.eq("address", address); List<Document> documentList = mongoDBService.query(DBTableConstant.ACCOUNT_LEDGER_TABLE + chainId, filter); List<AccountLedgerInfo> accountLedgerInfoList = new ArrayList<>(); for (Document document : documentList) { if (document.getInteger("chainId") == chainId) { continue; } AccountLedgerInfo ledgerInfo = DocumentTransferTool.toInfo(document, "key", AccountLedgerInfo.class); accountLedgerInfoList.add(ledgerInfo); } return accountLedgerInfoList; }
Example 10
Source File: MongoCompensableLock.java From ByteTCC with GNU Lesser General Public License v3.0 | 5 votes |
public boolean reExitTransactionInMongoDB(TransactionXid transactionXid, String identifier) { byte[] global = transactionXid.getGlobalTransactionId(); String instanceId = ByteUtils.byteArrayToString(global); try { String application = CommonUtils.getApplication(this.endpoint); String databaseName = application.replaceAll("\\W", "_"); MongoDatabase mdb = this.mongoClient.getDatabase(databaseName); MongoCollection<Document> collection = mdb.getCollection(CONSTANTS_TB_LOCKS); Bson condition = Filters.eq(CONSTANTS_FD_GLOBAL, instanceId); Document increases = new Document(); increases.append("times", -1); Document document = new Document(); document.append("$inc", increases); Document target = collection.findOneAndUpdate(condition, document, new FindOneAndUpdateOptions().upsert(true)); Integer times = target == null ? null : target.getInteger("times"); return times == null ? true : times <= 0; } catch (com.mongodb.MongoWriteException error) { logger.error("Error occurred while locking transaction(gxid= {}).", instanceId, error); return true; } catch (RuntimeException rex) { logger.error("Error occurred while locking transaction(gxid= {}).", instanceId, rex); return true; } }
Example 11
Source File: Change.java From repositoryminer with Apache License 2.0 | 5 votes |
/** * Converts documents to changes. * * @param documents * * @return a list of changes. */ public static List<Change> parseDocuments(List<Document> documents) { List<Change> changes = new ArrayList<Change>(); if (documents == null) return changes; for (Document doc : documents) { Change change = new Change(doc.getString("new_path"), doc.getString("old_path"), doc.getInteger("lines_added", 0), doc.getInteger("lines_removed", 0), ChangeType.valueOf(doc.getString("type"))); changes.add(change); } return changes; }
Example 12
Source File: MongoCompensableLogger.java From ByteTCC with GNU Lesser General Public License v3.0 | 4 votes |
@SuppressWarnings("unchecked") public TransactionArchive reconstructTransactionArchive(Document document) throws Exception { XidFactory compensableXidFactory = this.beanFactory.getCompensableXidFactory(); boolean propagated = document.getBoolean("propagated"); String propagatedBy = document.getString("propagated_by"); boolean compensable = document.getBoolean("compensable"); boolean coordinator = document.getBoolean("coordinator"); int compensableStatus = document.getInteger("status"); // boolean error = document.getBoolean("error"); Integer recoveredTimes = document.getInteger("recovered_times"); Date recoveredAt = document.getDate("recovered_at"); TransactionArchive archive = new TransactionArchive(); String global = document.getString(CONSTANTS_FD_GLOBAL); byte[] globalByteArray = ByteUtils.stringToByteArray(global); TransactionXid globalXid = compensableXidFactory.createGlobalXid(globalByteArray); archive.setXid(globalXid); String textVariables = document.getString("variables"); byte[] variablesByteArray = null; if (StringUtils.isNotBlank(textVariables) && StringUtils.equals(textVariables, "null") == false) { variablesByteArray = ByteUtils.stringToByteArray(textVariables); } if (variablesByteArray == null || variablesByteArray.length == 0) { archive.setVariables(new HashMap<String, Serializable>()); } else { Map<String, Serializable> variables = // (Map<String, Serializable>) SerializeUtils.deserializeObject(variablesByteArray); archive.setVariables(variables); } archive.setRecoveredAt(recoveredAt == null ? 0 : recoveredAt.getTime()); archive.setRecoveredTimes(recoveredTimes == null ? 0 : recoveredTimes); archive.setCompensable(compensable); archive.setCoordinator(coordinator); archive.setCompensableStatus(compensableStatus); archive.setPropagated(propagated); archive.setPropagatedBy(propagatedBy); archive.getRemoteResources().addAll(this.constructParticipantList(document)); archive.getCompensableResourceList().addAll(this.constructCompensableList(document)); return archive; }
Example 13
Source File: DocumentToStudentTransformer.java From Java-9-Spring-Webflux with Apache License 2.0 | 4 votes |
@Override public StudentDTO transform(Document source) { return new StudentDTO(source.getString(NAME), source.getInteger(AGE), source.getDouble(CREDIT), source.getString(MAJOR), ((ObjectId) source.get(ID)).toString()); }
Example 14
Source File: DocumentToStudentTransformer.java From Java-9-Spring-Webflux with Apache License 2.0 | 4 votes |
@Override public StudentDTO transform(Document source) { return new StudentDTO(source.getString(NAME), source.getInteger(AGE), source.getDouble(CREDIT), source.getString(MAJOR), ((ObjectId) source.get(ID)).toString()); }
Example 15
Source File: UpdateDataForSpecifyingLastReproduction.java From repairnator with MIT License | 4 votes |
public static void main(String[] args) { String dbConnectionUrl = args[0]; String dbName = args[1]; String collectionName = args[2]; MongoConnection mongoConnection = new MongoConnection(dbConnectionUrl, dbName); MongoDatabase database = mongoConnection.getMongoDatabase(); MongoCollection collection = database.getCollection(collectionName); Calendar limitDateMay = Calendar.getInstance(); limitDateMay.set(2017, Calendar.MAY, 10); final List<ObjectId> updatedDocs = new ArrayList<>(); Set<Integer> ids = new HashSet<>(); Block<Document> block = new Block<Document>() { @Override public void apply(Document document) { ObjectId documentId = document.getObjectId("_id"); Object pBuildId = document.get("previousBuildId"); if (pBuildId instanceof Integer) { int previousBuildId = document.getInteger("previousBuildId", -1); if (previousBuildId != -1) { boolean lastReproducedBuggyBuild = !ids.contains(previousBuildId); ids.add(previousBuildId); document.append("lastReproducedBuggyBuild", lastReproducedBuggyBuild); collection.replaceOne(eq("_id", documentId), document, new UpdateOptions().upsert( true )); updatedDocs.add(documentId); } } } }; collection.find().sort(orderBy(descending("buildReproductionDate"))).forEach( block ); System.out.println("Updated docs: "+updatedDocs.size()); }
Example 16
Source File: Obstacle.java From Much-Assembly-Required with GNU General Public License v3.0 | 4 votes |
public Obstacle(Document document) { super(document, 1, 1); hp = document.getInteger(hp); color = document.getInteger(color); }
Example 17
Source File: BiomassBlob.java From Much-Assembly-Required with GNU General Public License v3.0 | 4 votes |
public BiomassBlob(Document document) { super(document); biomassCount = document.getInteger("biomassCount"); }
Example 18
Source File: ConstructionSite.java From Much-Assembly-Required with GNU General Public License v3.0 | 4 votes |
public ConstructionSite(Document document) { super(document, 1, 1); age = document.getInteger("age"); bluePrint = BluePrintRegistry.INSTANCE.deserializeBlueprint((Document) document.get("blueprint")); }
Example 19
Source File: ElectricBox.java From Much-Assembly-Required with GNU General Public License v3.0 | 4 votes |
public ElectricBox(Document document) { super(document); hp = document.getInteger("hp"); }
Example 20
Source File: CPU.java From Much-Assembly-Required with GNU General Public License v3.0 | 3 votes |
public static CPU deserialize(Document obj, ControllableUnit unit) throws CancelledException { CPU cpu = new CPU(GameServer.INSTANCE.getConfig(), unit); cpu.codeSectionOffset = obj.getInteger("codeSegmentOffset"); cpu.memory = new Memory((Document) obj.get("memory")); cpu.registerSet = RegisterSet.deserialize((Document) obj.get("registerSet")); return cpu; }