List of usage examples for com.mongodb BasicDBObject getInt
public int getInt(final String key)
From source file:ch.agent.crnickl.mongodb.ReadMethodsForChroniclesAndSeries.java
License:Apache License
/** * Find a series corresponding to a surrogate. * // w ww. j a v a2 s .c o m * @param s a surrogate * @return a series or null * @throws T2DBException */ public <T> Series<T> getSeries(Surrogate s) throws T2DBException { BasicDBObject obj = (BasicDBObject) getObject(s, false); Throwable cause = null; if (obj != null) try { ObjectId chrOid = obj.getObjectId(MongoDatabase.FLD_SER_CHRON); int serNum = obj.getInt(MongoDatabase.FLD_SER_NUM); Chronicle chronicle = new ChronicleImpl( makeSurrogate(s.getDatabase(), DBObjectType.CHRONICLE, chrOid)); check(Permission.READ, chronicle); Series<T> series = new SeriesImpl<T>(chronicle, null, serNum, s); return series; } catch (Exception e) { cause = e; } throw T2DBMsg.exception(cause, E.E40104, s.toString()); }
From source file:ch.agent.crnickl.mongodb.ReadMethodsForChroniclesAndSeries.java
License:Apache License
/** * Return array of series in the positions corresponding to the * requested numbers. These numbers are series numbers within the schema, * not the series keys in the database. When a requested number in the array is * non-positive, the corresponding series will be null in the result. A * series can also be null when the requested number is positive but the * series has no data and has not been set up in the database (and therefore * has no series database key).//from w w w. j a va 2s . c o m * <p> * Note. There is no exception if the chronicle does not exist. This behavior makes * it easier to implement the wishful transaction protocol (i.e. testing again if it * was okay to delete a chronicle after it was deleted). * * @param chronicle a chronicle * @param names an array of simple names to plug into the series * @param numbers an array of numbers * @return an array of series * @throws T2DBException */ public <T> Series<T>[] getSeries(Chronicle chronicle, String[] names, int[] numbers) throws T2DBException { if (names.length != numbers.length) throw new IllegalArgumentException("lengths of names[] and numbers[] differ"); @SuppressWarnings("unchecked") Series<T>[] result = new SeriesImpl[numbers.length]; if (result.length > 0) { Map<Integer, Integer> map = new HashMap<Integer, Integer>(); for (int i = 0; i < numbers.length; i++) { if (numbers[i] > 0) { if (map.put(numbers[i], i) != null) throw new IllegalArgumentException("duplicate number: " + numbers[i]); } } Surrogate s = chronicle.getSurrogate(); Database db = s.getDatabase(); try { check(Permission.READ, chronicle); } catch (Exception e) { throw T2DBMsg.exception(e, E.E40104, s.toString()); } try { DBCursor cursor = getMongoDB(db) .getSeries().find( mongoObject(MongoDatabase.FLD_SER_CHRON, getId(chronicle), MongoDatabase.FLD_SER_NUM, mongoObject(Operator.IN.op(), numbers)), mongoObject(MongoDatabase.FLD_SER_NUM, 1)); while (cursor.hasNext()) { BasicDBObject obj = (BasicDBObject) cursor.next(); ObjectId serOid = obj.getObjectId(MongoDatabase.FLD_ID); int serNumber = obj.getInt(MongoDatabase.FLD_SER_NUM); int i = map.get(serNumber); result[i] = new SeriesImpl<T>(chronicle, names[i], numbers[i], makeSurrogate(db, DBObjectType.SERIES, serOid)); } } catch (Exception e) { throw T2DBMsg.exception(e, E.E40121, chronicle.getName(true)); } } return result; }
From source file:ch.agent.crnickl.mongodb.ReadMethodsForSchema.java
License:Apache License
@SuppressWarnings({ "rawtypes", "unchecked" }) private AttributeDefinition<?> attributeDefinition(Surrogate schemaSurrogate, int seriesNr, Database db, BasicDBObject bo) throws T2DBException { int number = bo.getInt(MongoDatabase.FLD_ATTRIBDEF_NUM); boolean era = bo.getBoolean(MongoDatabase.FLD_ATTRIBDEF_ERASING); AttributeDefinitionImpl<?> def = null; if (era) {/*from w ww . j a v a2s .c om*/ def = new AttributeDefinitionImpl(seriesNr, number, null, null); def.edit(); def.setErasing(true); } else { ObjectId propId = bo.getObjectId(MongoDatabase.FLD_ATTRIBDEF_PROP); Surrogate propSurr = makeSurrogate(db, DBObjectType.PROPERTY, new MongoDBObjectId(propId)); Property<?> prop = ((MongoDatabase) db).getReadMethodsForProperty().getProperty(propSurr); String val = bo.getString(MongoDatabase.FLD_ATTRIBDEF_VAL); checkIntegrity(prop, propSurr, schemaSurrogate); def = new AttributeDefinitionImpl(seriesNr, number, prop, prop.getValueType().scan(val)); } return def; }
From source file:ch.agent.crnickl.mongodb.ReadMethodsForSchema.java
License:Apache License
private SeriesDefinition seriesDefinition(Surrogate schemaSurrogate, Database db, BasicDBObject bo) throws T2DBException { int number = bo.getInt(MongoDatabase.FLD_SERIESDEF_NUM); boolean era = bo.getBoolean(MongoDatabase.FLD_SERIESDEF_ERASING); SeriesDefinitionImpl def = null;//from w w w. ja v a 2 s.c o m if (era) { def = new SeriesDefinitionImpl(number, null, null); def.edit(); def.setErasing(true); } else { String desc = bo.getString(MongoDatabase.FLD_SERIESDEF_DESC); BasicDBList list = (BasicDBList) bo.get(MongoDatabase.FLD_SERIESDEF_ATTRIBS); Collection<AttributeDefinition<?>> attribs = attributeDefinitions(schemaSurrogate, number, db, list); def = new SeriesDefinitionImpl(number, desc, attribs); } return def; }
From source file:ch.windmobile.server.mongo.MongoDataSource.java
License:Open Source License
private StationInfo createStationInfo(BasicDBObject stationJson) { StationInfo stationInfo = new StationInfo(); stationInfo.setId(stationJson.getString("_id")); stationInfo.setShortName(stationJson.getString("short")); stationInfo.setName(stationJson.getString("name")); stationInfo.setDataValidity(getDataValidity(new DateTime())); stationInfo.setStationLocationType(StationLocationType.TAKEOFF); BasicDBList locationJson = (BasicDBList) stationJson.get("loc"); stationInfo.setWgs84Longitude((Double) locationJson.get(0)); stationInfo.setWgs84Latitude((Double) locationJson.get(1)); ;/* w ww.j a v a 2 s . c o m*/ stationInfo.setAltitude(stationJson.getInt("alt")); stationInfo.setMaintenanceStatus(Status.fromValue(stationJson.getString("status"))); return stationInfo; }
From source file:com.ca.apm.mongo.test.MongoReplicaSetForTestFactory.java
License:Open Source License
private boolean isReplicaSetStarted(BasicDBObject setting) { if (setting.get("members") == null) { return false; }/*from w w w . j a v a 2s. c o m*/ BasicDBList members = (BasicDBList) setting.get("members"); for (Object m : members.toArray()) { BasicDBObject member = (BasicDBObject) m; logger.info(member.toString()); int state = member.getInt("state"); logger.info("state: " + state); // 1 - PRIMARY, 2 - SECONDARY, 7 - ARBITER if (state != 1 && state != 2 && state != 7) { return false; } } return true; }
From source file:com.deftlabs.lock.mongo.impl.LockDao.java
License:Apache License
/** * Check for expired/inactive/dead locks and unlock. *//* ww w .ja v a 2 s.c om*/ static void expireInactiveLocks(final MongoClient pMongo, final DistributedLockSvcOptions pSvcOptions) { // Adjust the time buffer to make sure we do not have small time issues. final long queryServerTime = getServerTime(pMongo, pSvcOptions); final BasicDBObject query = new BasicDBObject(LockDef.STATE.field, LockState.LOCKED.code()); query.put(LockDef.LOCK_TIMEOUT_TIME.field, new BasicDBObject(LT, new Date(queryServerTime))); final DBCursor cur = getDbCollection(pMongo, pSvcOptions).find(query).batchSize(10); try { while (cur.hasNext()) { final BasicDBObject lockDoc = (BasicDBObject) cur.next(); final ObjectId lockId = (ObjectId) lockDoc.get(LockDef.LOCK_ID.field); final String lockName = lockDoc.getString(LockDef.ID.field); final long serverTime = getServerTime(pMongo, pSvcOptions); final BasicDBObject toSet = new BasicDBObject(); toSet.put(LockDef.LIBRARY_VERSION.field, null); toSet.put(LockDef.UPDATED.field, new Date(serverTime)); toSet.put(LockDef.LOCK_ACQUIRED_TIME.field, null); toSet.put(LockDef.LOCK_TIMEOUT_TIME.field, null); toSet.put(LockDef.LOCK_ID.field, null); toSet.put(LockDef.STATE.field, LockState.UNLOCKED.code()); toSet.put(LockDef.OWNER_APP_NAME.field, null); toSet.put(LockDef.OWNER_ADDRESS.field, null); toSet.put(LockDef.OWNER_HOSTNAME.field, null); toSet.put(LockDef.OWNER_THREAD_ID.field, null); toSet.put(LockDef.OWNER_THREAD_NAME.field, null); toSet.put(LockDef.OWNER_THREAD_GROUP_NAME.field, null); toSet.put(LockDef.LOCK_ATTEMPT_COUNT.field, 0); toSet.put(LockDef.INACTIVE_LOCK_TIMEOUT.field, null); final BasicDBObject timeoutQuery = new BasicDBObject(LockDef.ID.field, lockName); timeoutQuery.put(LockDef.LOCK_ID.field, lockId); timeoutQuery.put(LockDef.STATE.field, LockState.LOCKED.code()); timeoutQuery.put(LockDef.LOCK_TIMEOUT_TIME.field, new BasicDBObject(LT, new Date(serverTime))); final BasicDBObject previousLockDoc = (BasicDBObject) getDbCollection(pMongo, pSvcOptions) .findAndModify(timeoutQuery, new BasicDBObject(LockDef.INACTIVE_LOCK_TIMEOUT.field, 1), null, false, new BasicDBObject(SET, toSet), false, false); if (previousLockDoc == null) continue; if (!pSvcOptions.getEnableHistory()) continue; // Insert the history state. LockHistoryDao.insert(pMongo, lockName, pSvcOptions, previousLockDoc.getInt(LockDef.INACTIVE_LOCK_TIMEOUT.field), serverTime, LockState.LOCKED, lockId, true); } } finally { if (cur != null) cur.close(); } }
From source file:com.dentinium.doctor.Doctor.java
public Doctor(BasicDBObject obj) { doctorID = obj.getString("userid"); doctorName = obj.getString("name"); email = obj.getString("email"); if (obj.getString("phone") != null) { phone = obj.getString("phone"); } else {/* w ww . j a v a2 s . co m*/ phone = "not set"; } if (obj.getString("wage") != null) { wage = obj.getInt("wage"); } else { wage = 0; } BasicDBObject tmp = (BasicDBObject) obj.get("works"); companyName = tmp.getString("companyname"); }
From source file:com.edgytech.umongo.ReplicaDialog.java
License:Apache License
public void updateFromReplicaConfig(BasicDBObject member) { // reset/*from w w w . j ava2s . c o m*/ xmlLoadCheckpoint(); ((TextField) getBoundUnit(Item.host)).editable = false; setStringFieldValue(Item.host, member.getString("host")); setBooleanFieldValue(Item.arbiterOnly, member.getBoolean("arbiterOnly", false)); setBooleanFieldValue(Item.hidden, member.getBoolean("hidden", false)); setBooleanFieldValue(Item.ignoreIndexes, !member.getBoolean("buildIndexes", true)); if (member.containsField("priority")) { setDoubleFieldValue(Item.priority, member.getDouble("priority")); } if (member.containsField("slaveDelay")) { setIntFieldValue(Item.slaveDelay, member.getInt("slaveDelay")); } if (member.containsField("votes")) { setIntFieldValue(Item.votes, member.getInt("votes")); } if (member.containsField("tags")) { ((DocBuilderField) getBoundUnit(Item.tags)).setDBObject((DBObject) member.get("tags")); } }
From source file:com.edgytech.umongo.ServerPanel.java
License:Apache License
public void rsReconfigure(ButtonBase button) throws Exception { ReplSetNode replset = (ReplSetNode) getServerNode().getParentNode(); final DBCollection col = replset.getMongoClient().getDB("local").getCollection("system.replset"); DBObject config = col.findOne();// ww w .j a va 2 s . c o m BasicDBList members = (BasicDBList) config.get("members"); int i = 0; String myhost = getServerNode().getServerAddress().getHost() + ":" + getServerNode().getServerAddress().getPort(); for (; i < members.size(); ++i) { if (myhost.equals(((DBObject) members.get(i)).get("host"))) break; } if (i == members.size()) { throw new Exception("No such server in configuration"); } ReplicaDialog dia = UMongo.instance.getGlobalStore().getReplicaDialog(); BasicDBObject oldConf = (BasicDBObject) members.get(i); dia.updateFromReplicaConfig(oldConf); if (!dia.show()) return; BasicDBObject conf = dia.getReplicaConfig(oldConf.getInt("_id")); members.put(i, conf); ReplSetPanel.reconfigure(replset, config); }