当前位置: 首页>>代码示例>>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;未经允许,请勿转载。