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


Java DBObject.get方法代碼示例

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


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

示例1: getNextId

import com.mongodb.DBObject; //導入方法依賴的package包/類
public int getNextId(GridFS destDatabase) {
	DBCollection countersCollection = destDatabase.getDB().getCollection("counters");

	DBObject record = countersCollection.findOne(new BasicDBObject("_id", "package"));
	if (record == null) {
		BasicDBObject dbObject = new BasicDBObject("_id", "package");
		dbObject.append("seq", 0);
		countersCollection.insert(dbObject);
		record = dbObject;
	}
	int oldID = (int) record.get("seq");
	int newID = oldID + 1;
	record.put("seq", newID);
	countersCollection.update(new BasicDBObject("_id", "package"), record);
	
	return newID;
}
 
開發者ID:roscisz,項目名稱:KernelHive,代碼行數:18,代碼來源:DataManager.java

示例2: updateUserChangeNameAndSurnametoName

import com.mongodb.DBObject; //導入方法依賴的package包/類
/**
 * update 6: {@link UserDocument} has changed; 'name' and 'surname' will be concat to 'name'.
 * for each every user document get 'name' and 'surname', concat them, update 'name', remove field surname and update document.
 *
 * @since V7
 */
@ChangeSet(order = "008", id = "updateUserChangeNameAndSurnameToName", author = "admin")
public void updateUserChangeNameAndSurnametoName(final MongoTemplate template) {
  final DBCollection userCollection = template.getCollection("user");

  final Iterator<DBObject> cursor = userCollection.find();
  while (cursor.hasNext()) {
    final DBObject current = cursor.next();

    final Object nameObj = current.get("name");
    final Object surnameObj = current.get("surname");
    final String updateName = (nameObj != null ? nameObj.toString() : "") + " " + (surnameObj != null ? surnameObj.toString() : "");

    final BasicDBObject updateQuery = new BasicDBObject();
    updateQuery.append("$set", new BasicDBObject("name", updateName));
    updateQuery.append("$unset", new BasicDBObject("surname", ""));

    final BasicDBObject searchQuery = new BasicDBObject();
    searchQuery.put("_id", current.get("_id"));

    userCollection.update(searchQuery, updateQuery);
  }
}
 
開發者ID:nkolytschew,項目名稱:mongobee_migration_example,代碼行數:29,代碼來源:DatabaseChangeLog.java

示例3: checkNonEncryptedSubdocument

import com.mongodb.DBObject; //導入方法依賴的package包/類
@Test
public void checkNonEncryptedSubdocument() {
    MyBean bean = new MyBean();
    MySubBean subBean = new MySubBean("sky is blue", "   earth is round");
    bean.nonSensitiveSubBean = subBean;
    mongoTemplate.save(bean);

    MyBean fromDb = mongoTemplate.findOne(query(where("_id").is(bean.id)), MyBean.class);

    assertThat(fromDb.nonSensitiveSubBean.nonSensitiveData, is(bean.nonSensitiveSubBean.nonSensitiveData));
    assertThat(fromDb.nonSensitiveSubBean.secretString, is(bean.nonSensitiveSubBean.secretString));

    DBObject fromMongo = mongoTemplate.getCollection(MyBean.MONGO_MYBEAN).find(new BasicDBObject("_id", new ObjectId(bean.id))).next();
    DBObject subMongo = (DBObject) fromMongo.get(MyBean.MONGO_NONSENSITIVESUBBEAN);

    assertThat(subMongo.get(MySubBean.MONGO_NONSENSITIVEDATA), is(subBean.nonSensitiveData));
    assertCryptLength(subMongo.get(MySubBean.MONGO_SECRETSTRING), subBean.secretString.length() + 12);
}
 
開發者ID:bolcom,項目名稱:spring-data-mongodb-encrypt,代碼行數:19,代碼來源:EncryptSystemTest.java

示例4: cryptFields

import com.mongodb.DBObject; //導入方法依賴的package包/類
void cryptFields(DBObject dbObject, Node node, Function<Object, Object> crypt) {
    if (node.type == Node.Type.MAP) {
        Node mapChildren = node.children.get(0);
        for (Map.Entry<String, Object> entry : ((BasicDBObject) dbObject).entrySet()) {
            cryptFields((DBObject) entry.getValue(), mapChildren, crypt);
        }
        return;
    }

    for (Node childNode : node.children) {
        Object value = dbObject.get(childNode.fieldName);
        if (value == null) continue;

        if (!childNode.children.isEmpty()) {
            if (value instanceof BasicDBList) {
                for (Object o : (BasicDBList) value)
                    cryptFields((DBObject) o, childNode, crypt);
            } else {
                cryptFields((BasicDBObject) value, childNode, crypt);
            }
            return;
        }

        dbObject.put(childNode.fieldName, crypt.apply(value));
    }
}
 
開發者ID:bolcom,項目名稱:spring-data-mongodb-encrypt,代碼行數:27,代碼來源:EncryptionEventListener.java

示例5: insert

import com.mongodb.DBObject; //導入方法依賴的package包/類
public Object insert(DBCollection collection, WriteConcern writeConcern) {
	DBObject document = new BasicDBObject();
	// 匹配_id
	for (int i = 0, n = columns.size(); i < n; i++) {
		// document.put(columns.get(i), values.get(i).getValue());

		String tempColumn = columns.get(i);
		if (3 == tempColumn.length() && tempColumn.equals("_id")) {
			document.put(tempColumn, new ObjectId(values.get(i).getValue().toString()));
		} else {
			document.put(tempColumn, values.get(i).getValue());
		}
	}
	log(document);
	// TODO: WriteConcern.ACKNOWLEDGED需要可以配置
	// WriteResult result = collection.insert(document, WriteConcern.ACKNOWLEDGED);
	// collection.insert(document, MongoComponent.getInstance().getDefaultWriteConcern());
	collection.insert(document, writeConcern);
	Object oid = document.get("_id");
	if (null != oid) {
		return oid.toString();
	}
	return null;
}
 
開發者ID:xsonorg,項目名稱:tangyuan2,代碼行數:25,代碼來源:InsertVo.java

示例6: User

import com.mongodb.DBObject; //導入方法依賴的package包/類
/**
 * Deserialize a User from a {@link DBObject}.
 *
 * @param dbObject The serialized object.
 */
@SuppressWarnings("unchecked")
public User(DBObject dbObject) {
    uuid = dbObject.get("_id").toString();
    username = (String) dbObject.get("username");
    password = (String) dbObject.get("password");
    ((BasicDBList) dbObject.get("roles")).forEach(o -> roles.add((String) o));
}
 
開發者ID:BakkerTom,項目名稱:happy-news,代碼行數:13,代碼來源:User.java

示例7: convert

import com.mongodb.DBObject; //導入方法依賴的package包/類
@Override
public OAuth2Authentication convert(DBObject source) {
    DBObject storedRequest = (DBObject) source.get("storedRequest");
    OAuth2Request request = new OAuth2Request((Map<String, String>) storedRequest.get("requestParameters"),
        (String) storedRequest.get("clientId"), null, true, new HashSet((List) storedRequest.get("scope")),
        null, null, null, null);
    DBObject userAuthorization = (DBObject) source.get("userAuthentication");
    Object principal = getPrincipalObject(userAuthorization.get("principal"));
    Authentication userAuthentication = new UsernamePasswordAuthenticationToken(principal,
        userAuthorization.get("credentials"), getAuthorities((List) userAuthorization.get("authorities")));
    return new OAuth2Authentication(request, userAuthentication);
}
 
開發者ID:BakkerTom,項目名稱:happy-news,代碼行數:13,代碼來源:AuthenticationReadConverter.java

示例8: toAgentCfgDbObject

import com.mongodb.DBObject; //導入方法依賴的package包/類
private AgentConfigurationDatabase toAgentCfgDbObject(DBObject dbObject) {
	AgentConfigurationDatabase agentCfgDb = new AgentConfigurationDatabase();
	agentCfgDb.setAgentId((String) dbObject.get("agentId"));
	
	DBObject agentCfgDbObj = (DBObject) dbObject.get("agentConfiguration");
	AgentConfiguration ac = new AgentConfiguration();
	
	ac.setExec((String) agentCfgDbObj.get("exec"));
   	ac.setComponent((String) agentCfgDbObj.get("component"));
   	
   	AgentConfigurationPacketbeat packetbeat = new AgentConfigurationPacketbeat();
   	packetbeat.setStream((String) ((DBObject)agentCfgDbObj.get("packetbeat")).get("stream"));
   	ac.setPacketbeat(packetbeat);
   	
   	AgentConfigurationTopbeat topbeat = new AgentConfigurationTopbeat();
   	topbeat.setStream((String) ((DBObject)agentCfgDbObj.get("topbeat")).get("stream"));
   	ac.setTopbeat(topbeat);
   	
   	AgentConfigurationFilebeat filebeat = new AgentConfigurationFilebeat();
   	filebeat.setStream((String) ((DBObject)agentCfgDbObj.get("filebeat")).get("stream"));
   	BasicDBList paths = (BasicDBList) ((DBObject)agentCfgDbObj.get("filebeat")).get("paths");
   	String[] pathsArr = paths.toArray(new String[0]);
   	List<String> pathsList = new ArrayList<String>();
   	for(String path : pathsArr) {
   		// add to the list
   		pathsList.add(path);
   	}
   	filebeat.setPaths(pathsList);
   	ac.setFilebeat(filebeat);

   	agentCfgDb.setAgentConfiguration(ac);		
	return agentCfgDb;
	
}
 
開發者ID:elastest,項目名稱:elastest-instrumentation-manager,代碼行數:35,代碼來源:AgentConfigurationRepository.java

示例9: deserialize

import com.mongodb.DBObject; //導入方法依賴的package包/類
public static Memory deserialize(DBObject obj) {

        Memory memory = new Memory(0);

        String zipBytesStr = (String) obj.get("zipBytes");

        if (zipBytesStr != null) {
            byte[] compressedBytes = Base64.getDecoder().decode((String) obj.get("zipBytes"));

            try {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                Inflater decompressor = new Inflater(true);
                InflaterOutputStream inflaterOutputStream = new InflaterOutputStream(baos, decompressor);
                inflaterOutputStream.write(compressedBytes);
                inflaterOutputStream.close();

                memory.setBytes(baos.toByteArray());

            } catch (IOException e) {
                e.printStackTrace();
            }
        } else {
            LogManager.LOGGER.severe("Memory was manually deleted");
            memory = new Memory(GameServer.INSTANCE.getConfig().getInt("memory_size"));
        }

        return memory;
    }
 
開發者ID:simon987,項目名稱:Much-Assembly-Required,代碼行數:29,代碼來源:Memory.java

示例10: Group

import com.mongodb.DBObject; //導入方法依賴的package包/類
/**
 * Create a group based on a Mongo DB Object
 *
 * @param group The existing Mongo DB Object
 */
public Group(DBObject group) {
  this.id = ((ObjectId) group.get(DB_ID)).toString();
  this.name = (String) group.get(JSON_KEY_GROUP_NAME);

  BasicDBList dbMembers = ((BasicDBList) group.get(JSON_KEY_MEMBERS_LIST));
  this.members = new String[dbMembers.size()];
  for (int i = 0; i < dbMembers.size(); i++) {
    members[i] = (String) dbMembers.get(i);
  }
}
 
開發者ID:OpenLiberty,項目名稱:sample-acmegifts,代碼行數:16,代碼來源:Group.java

示例11: deserializeHardware

import com.mongodb.DBObject; //導入方法依賴的package包/類
@Override
public CpuHardware deserializeHardware(DBObject hwJson) {
    int hwid = (int) hwJson.get("hwid");

    switch (hwid) {
        case RandomNumberGenerator.HWID:
            return RandomNumberGenerator.deserialize();
        case Clock.HWID:
            return Clock.deserialize();
    }

    return null;
}
 
開發者ID:simon987,項目名稱:Much-Assembly-Required,代碼行數:14,代碼來源:MiscHWPlugin.java

示例12: deserializeObject

import com.mongodb.DBObject; //導入方法依賴的package包/類
@Override
public GameObject deserializeObject(DBObject obj) {

    int objType = (int) obj.get("t");

    if (objType == HarvesterNPC.ID) {
        return HarvesterNPC.deserialize(obj);
    } else if (objType == Factory.ID) {
        return Factory.deserialise(obj);
    } else if (objType == RadioTower.ID) {
        return RadioTower.deserialize(obj);
    }

    return null;
}
 
開發者ID:simon987,項目名稱:Much-Assembly-Required,代碼行數:16,代碼來源:NpcPlugin.java

示例13: deserialize

import com.mongodb.DBObject; //導入方法依賴的package包/類
public static Cubot deserialize(DBObject obj) {

        Cubot cubot = new Cubot();
        cubot.setObjectId((long) obj.get("i"));
        cubot.setX((int) obj.get("x"));
        cubot.setY((int) obj.get("y"));
        cubot.hp = (int) obj.get("hp");
        cubot.setDirection(Direction.getDirection((int) obj.get("direction")));
        cubot.heldItem = (int) obj.get("heldItem");
        cubot.energy = (int) obj.get("energy");
        cubot.maxEnergy = GameServer.INSTANCE.getConfig().getInt("battery_max_energy");

        return cubot;

    }
 
開發者ID:simon987,項目名稱:Much-Assembly-Required,代碼行數:16,代碼來源:Cubot.java

示例14: deserialize

import com.mongodb.DBObject; //導入方法依賴的package包/類
public static RegisterSet deserialize(DBObject obj) {

        RegisterSet registerSet = new RegisterSet();

        BasicDBList registers = (BasicDBList) obj.get("registers");

        for (Object sRegister : registers) {

            Register register = new Register((String) ((DBObject) sRegister).get("name"));
            register.setValue((int) ((DBObject) sRegister).get("value"));

            registerSet.registers.put((int) ((DBObject) sRegister).get("index"), register);

        }

        return registerSet;
    }
 
開發者ID:simon987,項目名稱:Much-Assembly-Required,代碼行數:18,代碼來源:RegisterSet.java

示例15: deserialize

import com.mongodb.DBObject; //導入方法依賴的package包/類
public static CPU deserialize(DBObject obj, User user) throws CancelledException {

        CPU cpu = new CPU(GameServer.INSTANCE.getConfig(), user);

        cpu.codeSectionOffset = (int) obj.get("codeSegmentOffset");

        BasicDBList hardwareList = (BasicDBList) obj.get("hardware");

        for (Object serialisedHw : hardwareList) {
            CpuHardware hardware = CpuHardware.deserialize((DBObject) serialisedHw);
            hardware.setCpu(cpu);
            cpu.attachHardware(hardware, (int) ((BasicDBObject) serialisedHw).get("address"));
        }

        cpu.memory = Memory.deserialize((DBObject) obj.get("memory"));
        cpu.registerSet = RegisterSet.deserialize((DBObject) obj.get("registerSet"));

        return cpu;

    }
 
開發者ID:simon987,項目名稱:Much-Assembly-Required,代碼行數:21,代碼來源:CPU.java


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