本文整理了Java中com.mongodb.BasicDBObject.get()
方法的一些代码示例,展示了BasicDBObject.get()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BasicDBObject.get()
方法的具体详情如下:
包路径:com.mongodb.BasicDBObject
类名称:BasicDBObject
方法名:get
暂无
代码示例来源:origin: stackoverflow.com
BasicDBObject doc = new BasicDBObject( "name", "Matt" );
collection.insert( doc );
ObjectId id = (ObjectId)doc.get( "_id" );
代码示例来源:origin: spring-projects/spring-data-examples
private boolean isReplicaSetStarted(BasicDBObject setting) {
if (setting.get("members") == null) {
return false;
}
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;
}
代码示例来源:origin: MorphiaOrg/morphia
private void assertHashed(final List<DBObject> indexInfo) {
for (final DBObject dbObject : indexInfo) {
BasicDBObject index = (BasicDBObject) dbObject;
if (!index.getString("name").equals("_id_")) {
assertEquals(((DBObject) index.get("key")).get("hashedValue"), "hashed");
}
}
}
代码示例来源:origin: MorphiaOrg/morphia
dbObject.get("partialFilterExpression"));
BasicDBObject collation = (BasicDBObject) dbObject.get("collation");
assertEquals("en_US", collation.get("locale"));
assertEquals("upper", collation.get("caseFirst"));
assertEquals("shifted", collation.get("alternate"));
Assert.assertTrue(collation.getBoolean("backwards"));
assertEquals("upper", collation.get("caseFirst"));
Assert.assertTrue(collation.getBoolean("caseLevel"));
assertEquals("space", collation.get("maxVariable"));
Assert.assertTrue(collation.getBoolean("normalization"));
Assert.assertTrue(collation.getBoolean("numericOrdering"));
assertEquals(5, collation.get("strength"));
代码示例来源:origin: Graylog2/graylog2-server
public DashboardWidget fromPersisted(BasicDBObject fields) throws DashboardWidget.NoSuchWidgetTypeException, InvalidRangeParametersException, InvalidWidgetConfigurationException {
final String type = (String)fields.get(DashboardWidget.FIELD_TYPE);
final BasicDBObject config = (BasicDBObject) fields.get(DashboardWidget.FIELD_CONFIG);
final String widgetId = (String) fields.get(DashboardWidget.FIELD_ID);
// Build timerange.
final BasicDBObject timerangeConfig = (BasicDBObject) config.get("timerange");
final TimeRange timeRange = timeRangeFactory.create(timerangeConfig);
final String description = (String) fields.get(DashboardWidget.FIELD_DESCRIPTION);
final int cacheTime = (int) firstNonNull(fields.get(DashboardWidget.FIELD_CACHE_TIME), 0);
return buildDashboardWidget(type, widgetId, description, cacheTime,
config, timeRange, (String) fields.get(DashboardWidget.FIELD_CREATOR_USER_ID));
}
代码示例来源:origin: MorphiaOrg/morphia
@Test
public void shouldUseSuppliedConverterToEncodeAndDecodeObject() {
// given
getMorphia().map(CharEntity.class);
// when
getDs().save(new CharEntity());
// then check the representation in the database is a number
final BasicDBObject dbObj = (BasicDBObject) getDs().getCollection(CharEntity.class).findOne();
assertThat(dbObj.get("c"), is(instanceOf(int.class)));
assertThat(dbObj.getInt("c"), is((int) 'a'));
// then check CharEntity can be decoded from the database
final CharEntity ce = getDs().find(CharEntity.class).find(new FindOptions().limit(1)).tryNext();
assertThat(ce.c, is(notNullValue()));
assertThat(ce.c.charValue(), is('a'));
}
代码示例来源:origin: Graylog2/graylog2-server
@Override
public List<WidgetPosition> getPositions() {
final BasicDBObject positions = (BasicDBObject) fields.get(DashboardImpl.EMBEDDED_POSITIONS);
if (positions == null) {
return Collections.emptyList();
}
final List<WidgetPosition> result = new ArrayList<>(positions.size());
for ( String positionId : positions.keySet() ) {
final BasicDBObject position = (BasicDBObject) positions.get(positionId);
final int width = parseInt(position.get("width").toString());
final int height = parseInt(position.get("height").toString());
final int col = parseInt(position.get("col").toString());
final int row = parseInt(position.get("row").toString());
final WidgetPosition widgetPosition = WidgetPosition.builder()
.id(positionId)
.width(width)
.height(height)
.col(col)
.row(row)
.build();
result.add(widgetPosition);
}
return result;
}
代码示例来源:origin: Graylog2/graylog2-server
@Override
public AlertCondition getAlertCondition(Stream stream, String conditionId) throws NotFoundException {
if (stream.getFields().containsKey(StreamImpl.EMBEDDED_ALERT_CONDITIONS)) {
@SuppressWarnings("unchecked")
final List<BasicDBObject> alertConditions = (List<BasicDBObject>) stream.getFields().get(StreamImpl.EMBEDDED_ALERT_CONDITIONS);
for (BasicDBObject conditionFields : alertConditions) {
try {
if (conditionFields.get("id").equals(conditionId)) {
return alertService.fromPersisted(conditionFields, stream);
}
} catch (Exception e) {
LOG.error("Skipping alert condition.", e);
}
}
}
throw new NotFoundException("Alert condition <" + conditionId + "> for stream <" + stream.getId() + "> not found");
}
代码示例来源:origin: Graylog2/graylog2-server
private Dashboard create(ObjectId id, Map<String, Object> fields) {
final Dashboard dashboard = new DashboardImpl(id, fields);
// Add all widgets of this dashboard.
if (fields.containsKey(DashboardImpl.EMBEDDED_WIDGETS)) {
if (fields.get(DashboardImpl.EMBEDDED_WIDGETS) instanceof List) {
for (BasicDBObject widgetFields : (List<BasicDBObject>) fields.get(DashboardImpl.EMBEDDED_WIDGETS)) {
try {
final DashboardWidget widget = dashboardWidgetCreator.fromPersisted(widgetFields);
dashboard.addPersistedWidget(widget);
} catch (DashboardWidget.NoSuchWidgetTypeException e) {
LOG.error("No such widget type: [" + widgetFields.get("type") + "] - Dashboard: [" + dashboard.getId() + "]", e);
} catch (InvalidRangeParametersException e) {
LOG.error("Invalid range parameters of widget in dashboard: [" + dashboard.getId() + "]", e);
} catch (InvalidWidgetConfigurationException e) {
LOG.error("Invalid configuration of widget in dashboard: [" + dashboard.getId() + "]", e);
}
}
}
}
return dashboard;
}
代码示例来源:origin: Graylog2/graylog2-server
@Override
@SuppressWarnings("unchecked")
public SavedSearch load(String id) throws NotFoundException {
BasicDBObject o = (BasicDBObject) get(SavedSearchImpl.class, id);
if (o == null) {
throw new NotFoundException("Couldn't find saved search with ID " + id);
}
return new SavedSearchImpl((ObjectId) o.get("_id"), o.toMap());
}
代码示例来源:origin: Graylog2/graylog2-server
@Override
public Dashboard load(String id) throws NotFoundException {
final BasicDBObject o = (BasicDBObject) get(DashboardImpl.class, id);
if (o == null) {
throw new NotFoundException("Couldn't find dashboard with ID " + id);
}
return this.create((ObjectId) o.get(DashboardImpl.FIELD_ID), o.toMap());
}
代码示例来源:origin: Graylog2/graylog2-server
@Override
public StreamRule load(String id) throws NotFoundException {
BasicDBObject o = (BasicDBObject) get(StreamRuleImpl.class, new ObjectId(id));
if (o == null) {
throw new NotFoundException("Couldn't find stream rule with ID" + id);
}
return new StreamRuleImpl((ObjectId) o.get("_id"), o.toMap());
}
代码示例来源:origin: org.mongodb/mongo-java-driver
private void addOperand(@Nullable final String op, final Object value) {
Object valueToPut = value;
if (op == null) {
if (_hasNot) {
valueToPut = new BasicDBObject(QueryOperators.NOT, valueToPut);
_hasNot = false;
}
_query.put(_currentKey, valueToPut);
return;
}
Object storedValue = _query.get(_currentKey);
BasicDBObject operand;
if (!(storedValue instanceof DBObject)) {
operand = new BasicDBObject();
if (_hasNot) {
DBObject notOperand = new BasicDBObject(QueryOperators.NOT, operand);
_query.put(_currentKey, notOperand);
_hasNot = false;
} else {
_query.put(_currentKey, operand);
}
} else {
operand = (BasicDBObject) _query.get(_currentKey);
if (operand.get(QueryOperators.NOT) != null) {
operand = (BasicDBObject) operand.get(QueryOperators.NOT);
}
}
operand.put(op, valueToPut);
}
代码示例来源:origin: MorphiaOrg/morphia
@PreLoad
void preLoad(final BasicDBObject dbObj) {
//pull all the fields from value field into the parent.
dbObj.putAll((DBObject) dbObj.get("value"));
}
}
代码示例来源:origin: org.mongodb/mongo-java-driver
/**
* Creates a new instance which is a copy of this BasicDBObject.
*
* @return a BasicDBObject with exactly the same values as this instance.
*/
public Object copy() {
// copy field values into new object
BasicDBObject newCopy = new BasicDBObject(this.toMap());
// need to clone the sub obj
for (final String field : keySet()) {
Object val = get(field);
if (val instanceof BasicDBObject) {
newCopy.put(field, ((BasicDBObject) val).copy());
} else if (val instanceof BasicDBList) {
newCopy.put(field, ((BasicDBList) val).copy());
}
}
return newCopy;
}
代码示例来源:origin: MorphiaOrg/morphia
@Test
public void testEmbeddedMap() throws Exception {
getMorphia().map(ContainsMapOfEmbeddedGoos.class).map(ContainsMapOfEmbeddedInterfaces.class);
final Goo g1 = new Goo("Scott");
final ContainsMapOfEmbeddedGoos cmoeg = new ContainsMapOfEmbeddedGoos();
cmoeg.values.put("first", g1);
getDs().save(cmoeg);
//check className in the map values.
final BasicDBObject goo = (BasicDBObject) ((BasicDBObject) getDs().getCollection(ContainsMapOfEmbeddedGoos.class)
.findOne()
.get("values"))
.get("first");
assertFalse(goo.containsField(getMorphia().getMapper().getOptions().getDiscriminatorField()));
}
代码示例来源:origin: MorphiaOrg/morphia
@Test
public void testEmbeddedMapWithValueInterface() throws Exception {
getMorphia().map(ContainsMapOfEmbeddedGoos.class).map(ContainsMapOfEmbeddedInterfaces.class);
final Goo g1 = new Goo("Scott");
final ContainsMapOfEmbeddedInterfaces cmoei = new ContainsMapOfEmbeddedInterfaces();
cmoei.values.put("first", g1);
getDs().save(cmoei);
//check className in the map values.
final BasicDBObject goo = (BasicDBObject) ((BasicDBObject) getDs().getCollection(ContainsMapOfEmbeddedInterfaces.class)
.findOne()
.get("values"))
.get("first");
assertTrue(goo.containsField(getMorphia().getMapper().getOptions().getDiscriminatorField()));
}
代码示例来源:origin: MorphiaOrg/morphia
relatedDbObj.get("_id"))),
new DefaultEntityCache());
articles.findOne(
new BasicDBObject("_id",
articleDbObj.get("_id"))),
new DefaultEntityCache());
代码示例来源:origin: MorphiaOrg/morphia
@Test
public void testEmbeddedMapUpdateOperationsOnInterfaceValue() throws Exception {
getMorphia().map(ContainsMapOfEmbeddedGoos.class).map(ContainsMapOfEmbeddedInterfaces.class);
final Goo g1 = new Goo("Scott");
final Goo g2 = new Goo("Ralph");
final ContainsMapOfEmbeddedInterfaces cmoei = new ContainsMapOfEmbeddedInterfaces();
cmoei.values.put("first", g1);
getDs().save(cmoei);
getDs().update(cmoei, getDs().createUpdateOperations(ContainsMapOfEmbeddedInterfaces.class).set("values.second", g2));
//check className in the map values.
final BasicDBObject goo = (BasicDBObject) ((BasicDBObject) getDs().getCollection(ContainsMapOfEmbeddedInterfaces.class)
.findOne()
.get("values"))
.get("second");
assertTrue("className should be here.", goo.containsField(getMorphia().getMapper().getOptions().getDiscriminatorField()));
}
代码示例来源:origin: MorphiaOrg/morphia
@Test //@Ignore("waiting on issue 184")
public void testEmbeddedMapUpdateOperations() throws Exception {
getMorphia().map(ContainsMapOfEmbeddedGoos.class).map(ContainsMapOfEmbeddedInterfaces.class);
final Goo g1 = new Goo("Scott");
final Goo g2 = new Goo("Ralph");
final ContainsMapOfEmbeddedGoos cmoeg = new ContainsMapOfEmbeddedGoos();
cmoeg.values.put("first", g1);
getDs().save(cmoeg);
getDs().update(cmoeg, getDs().createUpdateOperations(ContainsMapOfEmbeddedGoos.class).set("values.second", g2));
//check className in the map values.
final BasicDBObject goo = (BasicDBObject) ((BasicDBObject) getDs().getCollection(ContainsMapOfEmbeddedGoos.class)
.findOne()
.get("values")).get(
"second");
assertFalse("className should not be here.", goo.containsField(
getMorphia().getMapper().getOptions().getDiscriminatorField()));
}
内容来源于网络,如有侵权,请联系作者删除!