public Map<String, Object> write(Element element) { Map<String, Object> entity = new HashMap<String, Object>(); entity.put(Dictionary.FIELD_RESEND, 0); entity.put(Dictionary.FIELD_ACTIVATE, true); entity.put(Dictionary.FIELD_PID, element.getId()); entity.put(Dictionary.FIELD_TYPE, element.getType()); entity.put(Dictionary.FIELD_TIMESTAMP, System.currentTimeMillis()); entity.put(Dictionary.FIELD_DELAY, this.format.format(new Date())); entity.put(Dictionary.FIELD_CLASS, element.getClass().getSimpleName()); JID to = this.jidBuilder.build(element.getTo()); JID from = this.jidBuilder.build(element.getFrom()); entity.put(Dictionary.FIELD_TO, this.bare ? to.asStringWithBare() : to.asString()); entity.put(Dictionary.FIELD_FROM, this.bare ? from.asStringWithBare() : from.asString()); return entity; }
/** * ID,FROM,TO,TYPE * * @param storage * @param element * @return */ protected Element read(Map<String, Object> storage, Element element) { return element .setId(this.toString(storage, Dictionary.FIELD_PID)) .setFrom(this.toString(storage, Dictionary.FIELD_FROM)) .setTo(this.toString(storage, Dictionary.FIELD_TO)) .setType(this.toString(storage, Dictionary.FIELD_TYPE)); }
/* * Class比较 * * @see com.sissi.persistent.PersistentElement#isSupport(com.sissi.protocol.Element) */ public boolean isSupport(Element element) { return this.support == element.getClass(); }
/* * {"id":Xxx} * * @see com.sissi.persistent.PersistentElement#query(com.sissi.protocol.Element) */ public Map<String, Object> query(Element element) { return MongoUtils.asMap( BasicDBObjectBuilder.start(Dictionary.FIELD_PID, element.getId()).get()); }