當前位置: 首頁>>代碼示例>>Java>>正文


Java BSONObject.get方法代碼示例

本文整理匯總了Java中org.bson.BSONObject.get方法的典型用法代碼示例。如果您正苦於以下問題:Java BSONObject.get方法的具體用法?Java BSONObject.get怎麽用?Java BSONObject.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.bson.BSONObject的用法示例。


在下文中一共展示了BSONObject.get方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: checkElements

import org.bson.BSONObject; //導入方法依賴的package包/類
public boolean checkElements(BSONObject index, BSONObject feature) {

        if (srcIpMask == 0 && dstIpMask == 0) {
            //marking according to featureConstraint
            return featureDatabaseMgmtManager.isSatisfyOnlineEvent(
                    (Document) index,
                    (Document) feature,
                    featureConstraint);
        }

        if (srcIpMask != 0 && index.get(AthenaIndexField.MATCH_IPV4_SRC) != null ) {
            int ipsrc = (Integer) index.get(AthenaIndexField.MATCH_IPV4_SRC);
            if ((ipsrc & this.srcIpMask) == srcComparator) {
                return true;
            }
        }

        if (dstIpMask != 0 && index.get(AthenaIndexField.MATCH_IPV4_DST) != null) {
            int ipdst = (Integer) index.get(AthenaIndexField.MATCH_IPV4_DST);
            if ((ipdst & this.dstIpMask) == dstComparator) {
                return true;
            }
        }
        return false;
    }
 
開發者ID:shlee89,項目名稱:athena,代碼行數:26,代碼來源:Marking.java

示例2: hasIndexedFieldChanged

import org.bson.BSONObject; //導入方法依賴的package包/類
/**
 * Determines if an indexed field has changed as part of an update. This
 * would be private but keeping public for ease of testing.
 *
 * @param oldObject the old BSON object.
 * @param index Index containing the getFields to check for changes.
 * @param entity New version of a document.
 * @return True if an indexed field has changed. False if there is no change
 * of indexed getFields.
 */
public static boolean hasIndexedFieldChanged(BSONObject oldObject, Index index, Document entity)
{
    //DocumentRepository docRepo = new DocumentRepositoryImpl(session);
    BSONObject newObject = entity.getObject();
    //BSONObject oldObject = (BSONObject) JSON.parse(docRepo.read(entity.getId()).object());
    for (IndexField indexField : index.getFields())
    {
        String field = indexField.getField();
        if (newObject.get(field) == null && oldObject.get(field) == null)//this shouldn't happen?
        {//if there is not a field in either index
            return false;//if it's not in ether doc, it couldn't have changed
        } else if (newObject.get(field) == null || oldObject.get(field) == null)
        {//there is a field in one of the indexes, but not the other.
            return true;//the index field must have changed, it either went from missing to present or present to missing.
        }
        if (!newObject.get(field).equals(oldObject.get(field)))
        {
            return true;//fail early
        }
    }
    return false;
}
 
開發者ID:PearsonEducation,項目名稱:Docussandra,代碼行數:33,代碼來源:IndexMaintainerHelper.java

示例3: createRowKey

import org.bson.BSONObject; //導入方法依賴的package包/類
@Override
public byte[] createRowKey(BSONObject object) {
  Object id = object.get("_id");

  byte[] raw;
  if (id instanceof ObjectId) {
    raw = ((ObjectId) id).toByteArray();
  } else if (id instanceof String) {
    raw = ((String) id).getBytes();
  } else if (id instanceof BSONObject) {
    raw = bsonEncoder.encode(((BSONObject) id));
  } else {
    throw new RuntimeException("Don't know how to serialize _id: " + id.toString());
  }

  return DigestUtils.md5(raw);
}
 
開發者ID:colinmarc,項目名稱:zerowing,代碼行數:18,代碼來源:BasicTranslator.java

示例4: testToBSON

import org.bson.BSONObject; //導入方法依賴的package包/類
@Test
public void testToBSON() {
    TenantAndIdEmittableKey key =
        new TenantAndIdEmittableKey("meta.data.tenantId", "test.id.key.field");
    key.setTenantId(new Text("Midgar"));
    key.setId(new Text("1234"));

    BSONObject bson = key.toBSON();
    assertNotNull(bson);
    assertTrue(bson.containsField("meta.data.tenantId"));

    Object obj = bson.get("meta.data.tenantId");
    assertNotNull(obj);
    assertTrue(obj instanceof String);
    String val = (String) obj;
    assertEquals(val, "Midgar");

    assertTrue(bson.containsField("test.id.key.field"));
    obj = bson.get("test.id.key.field");
    assertNotNull(obj);
    assertTrue(obj instanceof String);
    val = (String) obj;
    assertEquals(val, "1234");
}
 
開發者ID:inbloom,項目名稱:secure-data-service,代碼行數:25,代碼來源:TenantAndIdEmittableKeyTest.java

示例5: getBean

import org.bson.BSONObject; //導入方法依賴的package包/類
@Override
public DataBean getBean(String key, String value) throws BeanException {
	DataBean bean;
	BSONObject datas = sqlHelper.findByKey(key, value);
	if(datas!=null && datas.containsField("id")){
		bean = new User(
				(String) datas.get("id"), 
				(String) datas.get("email"),
				(String) datas.get("pass"), 
				(String) datas.get("prenom"), 
				(String) datas.get("nom"),
				(String) datas.get("tag"));
		TransactionsUtils.applyTransactionsOnUser(bean);
		if(datas.containsField("token")){
			((User) bean).setToken((String) datas.get("token"));
		}
	}
	else
		bean = null;
	return bean;
}
 
開發者ID:steven89,項目名稱:if26_projet,代碼行數:22,代碼來源:SQLDatabase.java

示例6: findAttributeByPk

import org.bson.BSONObject; //導入方法依賴的package包/類
/**
 * @param primaryKeyValue
 * @param key
 * @return
 */
public String findAttributeByPk(String primaryKeyValue, String key) {
	BSONObject query = new BasicBSONObject();
	query.put(this.primaryKey, primaryKeyValue);
	BSONObject selector = new BasicBSONObject();
	selector.put(key, key);
	BSONObject bsonObejct = queryOne(query, selector, null);
	if (bsonObejct != null) {
		return (String) bsonObejct.get(key);
	}
	return null;
}
 
開發者ID:slowlizard,項目名稱:SequoiaDB-ORM,代碼行數:17,代碼來源:GenericDao.java

示例7: postDocumentTest

import org.bson.BSONObject; //導入方法依賴的package包/類
/**
 * Tests that the POST /databases/{databases}/tables/{table}/documents
 * endpoint properly creates a document.
 */
@Test
public void postDocumentTest()
{
    Document testDocument = Fixtures.createTestDocument();
    String documentStr = testDocument.getObjectAsString();

    //act
    Response r = given().body(documentStr).expect().statusCode(201)
            .body("id", notNullValue())
            .body("object", notNullValue())
            .body("object.greeting", containsString("hello"))
            .body("createdAt", notNullValue())
            .body("updatedAt", notNullValue())
            .when().post().andReturn();

    BSONObject bson = (BSONObject) JSON.parse(r.getBody().asString());
    String id = (String) bson.get("id");
    //check
    expect().statusCode(200)
            .body("id", equalTo(id))
            .body("object", notNullValue())
            .body("object.greeting", containsString("hello"))
            .body("createdAt", notNullValue())
            .body("updatedAt", notNullValue())
            .get(id);
    testDocument.setUuid(UUID.fromString(id));
    //cleanup the random uuid'ed doc
    f.deleteDocument(testDocument);
}
 
開發者ID:PearsonEducation,項目名稱:Docussandra,代碼行數:34,代碼來源:AbstractDocumentControllerTest.java

示例8: postDocumentWithAllDataTypesTest

import org.bson.BSONObject; //導入方法依賴的package包/類
/**
 * Tests that the POST /databases/{databases}/tables/{table}/documents
 * endpoint properly creates a document.
 */
@Test
public void postDocumentWithAllDataTypesTest()
{
    //create the index first so we are sure it will get parsed
    f.insertIndex(Fixtures.createTestIndexAllFieldTypes());
    Document testDocument = Fixtures.createTestDocument3();
    String documentStr = testDocument.getObjectAsString();

    //act
    Response r = given().body(documentStr).expect().statusCode(201)
            .body("id", notNullValue())
            .body("object", notNullValue())
            .body("object.thisisastring", containsString("hello"))
            .body("createdAt", notNullValue())
            .body("updatedAt", notNullValue())
            .when().post().andReturn();

    BSONObject bson = (BSONObject) JSON.parse(r.getBody().asString());
    String id = (String) bson.get("id");
    //check
    expect().statusCode(200)
            .body("id", equalTo(id))
            .body("object", notNullValue())
            .body("object.thisisastring", containsString("hello"))
            .body("createdAt", notNullValue())
            .body("updatedAt", notNullValue())
            .get(id);
    testDocument.setUuid(UUID.fromString(id));
    //cleanup the random uuid'ed doc
    f.deleteDocument(testDocument);
}
 
開發者ID:PearsonEducation,項目名稱:Docussandra,代碼行數:36,代碼來源:AbstractDocumentControllerTest.java

示例9: BSONToKettle

import org.bson.BSONObject; //導入方法依賴的package包/類
public Object[] BSONToKettle( BSONObject input, List<SequoiaDBInputField> fields ) throws KettleException{
   Object[] result = null;
   if ( null == fields || fields.size() == 0 ){
      return result;
   }
   result = RowDataUtil.allocateRowData( outputRowMeta.size() );
   for ( SequoiaDBInputField f : fields ){
      Object fieldObj = input.get( f.m_fieldName );
      Object valObj = f.getKettleValue( fieldObj,
                            ValueMeta.getType( f.m_kettleType ));
      result[f.m_outputIndex] = valObj;
   }
   return result;
}
 
開發者ID:SequoiaDB,項目名稱:pentaho-sequoiadb-plugin,代碼行數:15,代碼來源:SequoiaDBInputData.java

示例10: getMsg

import org.bson.BSONObject; //導入方法依賴的package包/類
static String getMsg(final BSONObject o, final String def) {
    Object e = o.get("$err");
    if (e == null) {
        e = o.get("err");
    }
    if (e == null) {
        e = o.get("errmsg");
    }
    if (e == null) {
        return def;
    }
    return e.toString();
}
 
開發者ID:dbuschman7,項目名稱:mongoFS,代碼行數:14,代碼來源:ServerError.java

示例11: getCode

import org.bson.BSONObject; //導入方法依賴的package包/類
static int getCode(final BSONObject o) {
    Object c = o.get("code");
    if (c == null) {
        c = o.get("$code");
    }
    if (c == null) {
        c = o.get("assertionCode");
    }
    if (c == null) {
        return -5;
    }
    return ((Number) c).intValue();
}
 
開發者ID:dbuschman7,項目名稱:mongoFS,代碼行數:14,代碼來源:ServerError.java

示例12: getMsg

import org.bson.BSONObject; //導入方法依賴的package包/類
static String getMsg( BSONObject o , String def ){
    Object e = o.get( "$err" );
    if ( e == null )
        e = o.get( "err" );
    if ( e == null )
        e = o.get( "errmsg" );
    if ( e == null )
        return def;
    return e.toString();
}
 
開發者ID:MaOrKsSi,項目名稱:HZS.Durian,代碼行數:11,代碼來源:ServerError.java

示例13: getCode

import org.bson.BSONObject; //導入方法依賴的package包/類
static int getCode( BSONObject o ){
    Object c = o.get( "code" );
    if ( c == null )
        c = o.get( "$code" );
    if ( c == null )
        c = o.get( "assertionCode" );
    
    if ( c == null )
        return -5;
    
    return ((Number)c).intValue();
}
 
開發者ID:MaOrKsSi,項目名稱:HZS.Durian,代碼行數:13,代碼來源:ServerError.java

示例14: getCommandReadPreference

import org.bson.BSONObject; //導入方法依賴的package包/類
/**
 * Determines the read preference that should be used for the given command.
 *
 * @param command             the {@link DBObject} representing the command
 * @param requestedPreference the preference requested by the client.
 * @return the read preference to use for the given command.  It will never return {@code null}.
 * @see com.mongodb.ReadPreference
 */
ReadPreference getCommandReadPreference(DBObject command, ReadPreference requestedPreference){
    if (_mongo.getReplicaSetStatus() == null) {
        return requestedPreference;
    }

    String comString = command.keySet().iterator().next();

    if (comString.equals("getnonce") || comString.equals("authenticate")) {
        return ReadPreference.primaryPreferred();
    }

    boolean primaryRequired;

    // explicitly check mapreduce commands are inline
    if(comString.equals("mapreduce")) {
        Object out = command.get("out");
        if (out instanceof BSONObject ){
            BSONObject outMap = (BSONObject) out;
            primaryRequired = outMap.get("inline") == null;
        } else {
            primaryRequired = true;
        }
    } else if(comString.equals("aggregate")) {
        @SuppressWarnings("unchecked")
        List<DBObject> pipeline = (List<DBObject>) command.get("pipeline");
        primaryRequired = pipeline.get(pipeline.size()-1).get("$out") != null;
    } else {
       primaryRequired =  !_obedientCommands.contains(comString.toLowerCase());
    }

    if (primaryRequired) {
        return ReadPreference.primary();
    } else if (requestedPreference == null) {
        return ReadPreference.primary();
    } else {
        return requestedPreference;
    }
}
 
開發者ID:MaOrKsSi,項目名稱:HZS.Durian,代碼行數:47,代碼來源:DB.java

示例15: map

import org.bson.BSONObject; //導入方法依賴的package包/類
@Override
public void map(final Object key, final BSONObject doc, final Context context)
  throws IOException, InterruptedException {
    final int movieId = (Integer)doc.get("movieid");
    final Number movieRating = (Number)doc.get("rating");

    context.write(new IntWritable(movieId), new DoubleWritable(movieRating.doubleValue()));
}
 
開發者ID:crcsmnky,項目名稱:mongodb-hadoop-workshop,代碼行數:9,代碼來源:MapReduceExercise.java


注:本文中的org.bson.BSONObject.get方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。