@Override public boolean contains(String itemId) { if (coll == null) return false; BasicDBObject docsearch = new BasicDBObject(); docsearch.put("item_id", itemId); return coll.contains(docsearch); }
@Override public void remove(String itemId) { if (coll == null) return; BasicDBObject docsearch = new BasicDBObject(); docsearch.put("item_id", itemId); coll.remove(docsearch); }
@Override public void reset() { synchronized (collMonitor) { coll.drop(); coll = new MongoDBCollection(db, this.collName); } size = 0; }
@Override public DocumentCacheItem get(String itemId) { if (coll == null) return null; BasicDBObject docsearch = new BasicDBObject(); docsearch.put("item_id", itemId); BasicDBObject doc = coll.get(docsearch); return doc2DocumentCacheItem(doc); }
@Override public String put( String itemId, InputStream dataStream, long dataSize, HashMap<String, String> params, HashMap<String, String> metas, XMLConfig extra) { if (coll == null) return null; if (maxDocSize > 0 && dataSize > 0 && dataSize > maxDocSize) return null; BasicDBObject docsearch = new BasicDBObject(); docsearch.put("item_id", itemId); BasicDBObject doc = new BasicDBObject(); doc.put("item_id", itemId); doc.put("item_extra", extra.asXml()); Document xml_params = DocumentFactory.getInstance().createDocument("utf-8"); xml_params.setXMLEncoding("utf-8"); Element xml_params_items = xml_params.addElement("params"); for (Map.Entry<String, String> item : params.entrySet()) { String key = item.getKey(); if (item.getValue() != null) xml_params_items.addElement(key).addText(item.getValue()); } doc.put("item_params", xml_params.asXML()); Document xml_metas = DocumentFactory.getInstance().createDocument("utf-8"); xml_metas.setXMLEncoding("utf-8"); Element xml_metas_items = xml_metas.addElement("metas"); for (Map.Entry<String, String> item : metas.entrySet()) { String key = item.getKey(); if (item.getKey().startsWith("meta_")) { key = key.replace(':', '_').replace('-', '_').replace('.', '_').replace('/', '_'); } if (item.getValue() != null) xml_metas_items.addElement(key).addText(item.getValue()); } doc.put("item_metas", xml_metas.asXML()); if (dataStream != null) { String contentBase64 = ""; try { // dataStream.reset(); contentBase64 = Base64.inputStreamToStringBase64(dataStream); doc.put("content_base64", contentBase64); } catch (IOException e) { System.out.println(itemId); e.printStackTrace(); } } remove(itemId); return coll.add(doc); }