List of usage examples for com.mongodb BasicDBObject getInt
public int getInt(final String key)
From source file:no.nlf.avvik.melwinSOAPconnection.MongoOperations.java
public int getParachutistCounter() { DBCollection counterDbCollection = db.getCollection("counters"); BasicDBObject query = new BasicDBObject("_id", "jumpers"); BasicDBObject increment = new BasicDBObject().append("$inc", new BasicDBObject().append("seq", 1)); BasicDBObject counterDBObject = (BasicDBObject) counterDbCollection.findAndModify(query, increment); int seq = (int) counterDBObject.getInt("seq"); return seq;// w ww .j a v a2 s . co m }
From source file:org.apache.gora.mongodb.utils.BSONDecorator.java
License:Apache License
/** * Access field as a int.// www. j a va2 s. c om * * @param fieldName * fully qualified name of the field to be accessed * @return value of the field as a double */ public Integer getInt(String fieldName) { BasicDBObject parent = getFieldParent(fieldName); return parent.getInt(getLeafName(fieldName)); }
From source file:org.canedata.provider.mongodb.entity.MongoEntity.java
License:Apache License
private void prepareOptions(BasicDBObject options) { for (String o : options.keySet()) { if (Options.MONGO_OPTION.equals(o)) { getCollection().addOption(options.getInt(o)); continue; }/* w ww . j av a 2 s . c o m*/ if (Options.RESET_MONGO_OPTIONS.equals(o)) { getCollection().resetOptions(); continue; } if (Options.READ_PREFERENCE.equals(o)) { if (!(options.get(o) instanceof ReadPreference)) throw new MalformedParameterizedTypeException(); getCollection().setReadPreference((ReadPreference) options.get(o)); break; } if (Options.WRITE_CONCERN.equals(o)) { if (!(options.get(o) instanceof WriteConcern)) throw new MalformedParameterizedTypeException(); getCollection().setWriteConcern((WriteConcern) options.get(o)); break; } } }
From source file:org.elasticsearch.river.mongodb.RiverMongoDBTestAbstract.java
License:Apache License
private boolean isReplicaSetStarted(BasicDBObject setting) { if (setting.get("members") == null) { return false; }/*from ww w.j a v a 2 s.co m*/ BasicDBList members = (BasicDBList) setting.get("members"); int numPrimaries = 0; for (Object m : members.toArray()) { BasicDBObject member = (BasicDBObject) m; logger.trace("Member: {}", member); int state = member.getInt("state"); logger.info("Member state: " + state); // 1 - PRIMARY, 2 - SECONDARY, 7 - ARBITER if (state != 1 && state != 2 && state != 7) { return false; } if (state == 1) { ++numPrimaries; } } if (numPrimaries != 1) { logger.warn("Expected 1 primary, instead found " + numPrimaries); return false; } return true; }
From source file:org.graylog2.system.stats.mongo.MongoProbe.java
License:Open Source License
private HostInfo createHostInfo() { final HostInfo hostInfo; final CommandResult hostInfoResult = adminDb.command("hostInfo"); if (hostInfoResult.ok()) { final BasicDBObject systemMap = (BasicDBObject) hostInfoResult.get("system"); final HostInfo.System system = HostInfo.System.create(new DateTime(systemMap.getDate("currentTime")), systemMap.getString("hostname"), systemMap.getInt("cpuAddrSize"), systemMap.getLong("memSizeMB"), systemMap.getInt("numCores"), systemMap.getString("cpuArch"), systemMap.getBoolean("numaEnabled")); final BasicDBObject osMap = (BasicDBObject) hostInfoResult.get("os"); final HostInfo.Os os = HostInfo.Os.create(osMap.getString("type"), osMap.getString("name"), osMap.getString("version")); final BasicDBObject extraMap = (BasicDBObject) hostInfoResult.get("extra"); final HostInfo.Extra extra = HostInfo.Extra.create(extraMap.getString("versionString"), extraMap.getString("libcVersion"), extraMap.getString("kernelVersion"), extraMap.getString("cpuFrequencyMHz"), extraMap.getString("cpuFeatures"), extraMap.getString("scheduler"), extraMap.getLong("pageSize", -1l), extraMap.getLong("numPages", -1l), extraMap.getLong("maxOpenFiles", -1l)); hostInfo = HostInfo.create(system, os, extra); } else {//from w w w .j a va 2 s . c o m hostInfo = null; } return hostInfo; }
From source file:org.graylog2.system.stats.mongo.MongoProbe.java
License:Open Source License
public MongoStats mongoStats() { final List<ServerAddress> serverAddresses = mongoClient.getServerAddressList(); final List<HostAndPort> servers = Lists.newArrayListWithCapacity(serverAddresses.size()); for (ServerAddress serverAddress : serverAddresses) { servers.add(HostAndPort.fromParts(serverAddress.getHost(), serverAddress.getPort())); }//www . java2s . co m final DatabaseStats dbStats; final CommandResult dbStatsResult = db.command("dbStats"); if (dbStatsResult.ok()) { final BasicDBObject extentFreeListMap = (BasicDBObject) dbStatsResult.get("extentFreeList"); final DatabaseStats.ExtentFreeList extentFreeList = DatabaseStats.ExtentFreeList .create(extentFreeListMap.getInt("num"), extentFreeListMap.getInt("totalSize")); final BasicDBObject dataFileVersionMap = (BasicDBObject) dbStatsResult.get("dataFileVersion"); final DatabaseStats.DataFileVersion dataFileVersion = DatabaseStats.DataFileVersion .create(dataFileVersionMap.getInt("major"), dataFileVersionMap.getInt("minor")); dbStats = DatabaseStats.create(dbStatsResult.getString("db"), dbStatsResult.getLong("collections"), dbStatsResult.getLong("objects"), dbStatsResult.getDouble("avgObjSize"), dbStatsResult.getLong("dataSize"), dbStatsResult.getLong("storageSize"), dbStatsResult.getLong("numExtents"), dbStatsResult.getLong("indexes"), dbStatsResult.getLong("indexSize"), dbStatsResult.getLong("fileSize"), dbStatsResult.getLong("nsSizeMB"), extentFreeList, dataFileVersion); } else { dbStats = null; } final ServerStatus serverStatus; final CommandResult serverStatusResult = adminDb.command("serverStatus"); if (serverStatusResult.ok()) { final BasicDBObject connectionsMap = (BasicDBObject) serverStatusResult.get("connections"); final ServerStatus.Connections connections = ServerStatus.Connections.create( connectionsMap.getInt("current"), connectionsMap.getInt("available"), connectionsMap.getLong("totalCreated")); final BasicDBObject networkMap = (BasicDBObject) serverStatusResult.get("network"); final ServerStatus.Network network = ServerStatus.Network.create(networkMap.getInt("bytesIn"), networkMap.getInt("bytesOut"), networkMap.getInt("numRequests")); final BasicDBObject memoryMap = (BasicDBObject) serverStatusResult.get("mem"); final ServerStatus.Memory memory = ServerStatus.Memory.create(memoryMap.getInt("bits"), memoryMap.getInt("resident"), memoryMap.getInt("virtual"), memoryMap.getBoolean("supported"), memoryMap.getInt("mapped"), memoryMap.getInt("mappedWithJournal")); serverStatus = ServerStatus.create(serverStatusResult.getString("host"), serverStatusResult.getString("version"), serverStatusResult.getString("process"), serverStatusResult.getLong("pid"), serverStatusResult.getInt("uptime"), serverStatusResult.getLong("uptimeMillis"), serverStatusResult.getInt("uptimeEstimate"), new DateTime(serverStatusResult.getDate("localTime")), connections, network, memory); } else { serverStatus = null; } // TODO Collection stats? http://docs.mongodb.org/manual/reference/command/collStats/ return MongoStats.create(servers, buildInfo, hostInfo, serverStatus, dbStats); }
From source file:org.jivesoftware.openfire.roster.DefaultRosterItemProvider.java
License:Open Source License
public Iterator<RosterItem> getItems(String username) { LinkedList<RosterItem> itemList = new LinkedList<RosterItem>(); try {/*from w w w . j a v a 2s .c o m*/ init(); DBCollection coll = db.getCollection("gUser"); BasicDBObject doc = new BasicDBObject("friends", 1); BasicDBObject q = new BasicDBObject("himId", username); DBCursor res = coll.find(q, doc); Iterator<DBObject> iter = res.iterator(); while (iter.hasNext()) { BasicDBList o = (BasicDBList) iter.next().get("friends"); for (int i = 0; i < o.size(); i++) { BasicDBObject dbo = (BasicDBObject) o.get(i); // information // SELECT jid, rosterID, sub, ask, recv, nick,version FROM // ofRoster WHERE username=? RosterItem item = new RosterItem(i + 1, new JID(dbo.getString("jid")), RosterItem.SubType.getTypeFromInt(dbo.getInt("sub")), RosterItem.AskType.getTypeFromInt(dbo.getInt("ask")), RosterItem.RecvType.getTypeFromInt(dbo.getInt("recv")), dbo.getString("name"), null); item.setCurrVersion(dbo.getLong("ver")); // Add the loaded RosterItem (ie. user contact) to the // result itemList.add(item); } System.out.println("sdsd"); } } catch (Exception e) { Log.warn("Error trying to get rows in ofRoster", e); } return itemList.iterator(); }
From source file:org.keycloak.connections.mongo.updater.impl.updates.AbstractMigrateUserFedToComponent.java
License:Apache License
public void portUserFedToComponent(String providerId) { DBCollection realms = db.getCollection("realms"); DBCursor cursor = realms.find();//from w w w.j a v a2 s . co m while (cursor.hasNext()) { BasicDBObject realm = (BasicDBObject) cursor.next(); String realmId = realm.getString("_id"); Set<String> removedProviders = new HashSet<>(); BasicDBList componentEntities = (BasicDBList) realm.get("componentEntities"); BasicDBList federationProviders = (BasicDBList) realm.get("userFederationProviders"); for (Object obj : federationProviders) { BasicDBObject fedProvider = (BasicDBObject) obj; if (fedProvider.getString("providerName").equals(providerId)) { String id = fedProvider.getString("id"); removedProviders.add(id); int priority = fedProvider.getInt("priority"); String displayName = fedProvider.getString("displayName"); int fullSyncPeriod = fedProvider.getInt("fullSyncPeriod"); int changedSyncPeriod = fedProvider.getInt("changedSyncPeriod"); int lastSync = fedProvider.getInt("lastSync"); BasicDBObject component = new BasicDBObject(); component.put("id", id); component.put("name", displayName); component.put("providerType", UserStorageProvider.class.getName()); component.put("providerId", providerId); component.put("parentId", realmId); BasicDBObject config = new BasicDBObject(); config.put("priority", Collections.singletonList(Integer.toString(priority))); config.put("fullSyncPeriod", Collections.singletonList(Integer.toString(fullSyncPeriod))); config.put("changedSyncPeriod", Collections.singletonList(Integer.toString(changedSyncPeriod))); config.put("lastSync", Collections.singletonList(Integer.toString(lastSync))); BasicDBObject fedConfig = (BasicDBObject) fedProvider.get("config"); if (fedConfig != null) { for (Map.Entry<String, Object> attr : new HashSet<>(fedConfig.entrySet())) { String attrName = attr.getKey(); String attrValue = attr.getValue().toString(); config.put(attrName, Collections.singletonList(attrValue)); } } component.put("config", config); componentEntities.add(component); } } Iterator<Object> it = federationProviders.iterator(); while (it.hasNext()) { BasicDBObject fedProvider = (BasicDBObject) it.next(); String id = fedProvider.getString("id"); if (removedProviders.contains(id)) { it.remove(); } } realms.update(new BasicDBObject().append("_id", realmId), realm); } }
From source file:org.mybatis.jpetstore.domain.Item.java
License:Apache License
public static Item fromDBObject(@Nonnull final DBObject dbObj) { checkNotNull(dbObj, "Argument[dbObj] must not be null"); BasicDBObject itemObj = (BasicDBObject) dbObj; DBObject productObj = (DBObject) itemObj.get("product"); ItemBuilder builder = new ItemBuilder(itemObj.getString("item_id"), Product.fromDBObject(productObj)); if (itemObj.get("supplier_id") != null) { builder.supplierId(itemObj.getInt("supplier_id")); }//from ww w .jav a 2s . c om String listPrice = itemObj.getString("list_price"); if (!isNullOrEmpty(listPrice)) { builder.listPrice(decodeRealNumber(listPrice)); } String unitCost = itemObj.getString("unit_cost"); if (!isNullOrEmpty(unitCost)) { builder.unitCost(decodeRealNumber(unitCost)); } builder.status(itemObj.getString("status")).quantity(itemObj.getInt("quantity")) .attribute1(itemObj.getString("attribute_1")).attribute2(itemObj.getString("attribute_2")) .attribute3(itemObj.getString("attribute_3")).attribute4(itemObj.getString("attribute_4")) .attribute5(itemObj.getString("attribute_5")); return builder.build(); }
From source file:org.mybatis.jpetstore.domain.LineItem.java
License:Apache License
public static LineItem fromDBObject(@Nonnull final DBObject dbObj) { checkNotNull(dbObj, "Argument[dbObj] must not be null"); BasicDBObject lineItemObj = (BasicDBObject) dbObj; LineItem lineItem = new LineItem(); lineItem.setLineNumber(lineItemObj.getInt("line_number")); lineItem.setItemId(lineItemObj.getString("item_id")); String unitPrice = lineItemObj.getString("unit_price"); if (!isNullOrEmpty(unitPrice)) { lineItem.setUnitPrice(new BigDecimal(unitPrice)); }//from w w w . j a v a 2 s .c om lineItem.setQuantity(lineItemObj.getInt("quantity")); return lineItem; }