/** * Can be overidden in order to customize document creation. * @param n * @param id */ protected void createDocument(JsonNode n, String id) { db.create(id, n); } }
private void insertDocuments(List<Map<String, Object>> documentsIterator) { for (Map<String, Object> map : documentsIterator) { this.connector.create(map); } }
private void insertDocuments(List<Map<String, Object>> documentsIterator) { for (Map<String, Object> map : documentsIterator) { this.connector.create(map); } }
/** * Inserts a document in the store. * * @param docId document id. * @param document document in the form of JsonNode. */ public void insertDocument(String docId, @Nonnull Object document) { dbConnector.create(docId, document); }
@Override protected void insert(final Map<String, Object> attributes) { logger.debug("Insert doc: {}", attributes); couchDbConnector.create(attributes); }
/** * Inserts a document in the store. * * @param docId document id. * @param document document in the form of JsonNode. */ public void insertDocument(String docId, @Nonnull Object document) { dbConnector.create(docId, document); }
public static void insertDocument(Object dbTuple) { connector.create(dbTuple); }
public static void insertDocument(Map<String, String> dbTuple) { connector.create(dbTuple); }
@Override protected void update(final Map<String, Object> attributes) { final String id = (String) attributes.get(COUCH_ID); try { final InputStream oldDocStream = couchDbConnector.getAsStream(id); final Map<String, Object> res = objectMapper.readValue(oldDocStream, typeRef); res.putAll(attributes); couchDbConnector.update(res); logger.debug("Updating id: {} with attributes: {}", id, attributes); } catch (DocumentNotFoundException e) { logger.debug("Insert doc (not found by update(): {}", attributes); couchDbConnector.create(attributes); } catch (IOException e) { logger.error("Unexpected IO CouchDB Exception", e); } }
/** * Update or insert a document identified by docId in the database. * * @param docId document id. * @param document document. */ public void upsertDocument(String docId, @Nonnull Object document) { if (docId != null && dbConnector.contains(docId)) { dbConnector.update(document); } else { //create a document & if docId is null then couch db will generate a random id. dbConnector.create(document); } }
/** * Update or insert a document identified by docId in the database. * * @param docId document id. * @param document document. */ public void upsertDocument(String docId, @Nonnull Object document) { if (docId != null && dbConnector.contains(docId)) { dbConnector.update(document); } else { //create a document & if docId is null then couch db will generate a random id. dbConnector.create(document); } }
/** * @throws UpdateConflictException if there was an update conflict. */ public void add(T entity) { assertEntityNotNull(entity); Assert.isTrue(Documents.isNew(entity), "entity must be new"); db.create(entity); }
public void storeTrigger(CouchDbTrigger newTrigger, boolean replaceExisting) throws JobPersistenceException { CouchDbTrigger existingTrigger = getTriggerByKey(newTrigger.getKey()); if (existingTrigger == null) { db.create(newTrigger); return; } if (replaceExisting) { if (!(existingTrigger.getJobName().equals(newTrigger.getJobKey().getName()) && existingTrigger.getJobGroup().equals(newTrigger.getJobKey().getGroup()))) { throw new JobPersistenceException("New trigger is not related to the same job as the old trigger."); } newTrigger.setName(existingTrigger.getName()); newTrigger.setGroup(existingTrigger.getGroup()); newTrigger.setRevision(existingTrigger.getRevision()); if (logger.isDebugEnabled()) { logger.debug(String.format("Document ID : %s; Revision: %s", newTrigger.getId(), newTrigger.getRevision())); } db.update(newTrigger); } else { throw new ObjectAlreadyExistsException("trigger already exists " + newTrigger.getKey()); } }
public void storeJob(CouchDbJobDetail newJob, boolean replaceExisting) throws JobPersistenceException { CouchDbJobDetail existingJob = retrieveJob(newJob.getKey()); if (existingJob == null) { db.create(newJob); return; } if (replaceExisting) { newJob.setId(existingJob.getId()); newJob.setRevision(existingJob.getRevision()); db.update(newJob); } else { throw new ObjectAlreadyExistsException("job already exists"); } }
private void createOrUpdateContent(StreamContent streamContent, StreamContent streamContentFromDB, boolean resourceDoesNotExist) { if (resourceDoesNotExist) { db.create(streamContent); createAttachment(streamContent.getId(), streamContent.getRevision(), streamContent); } else { streamContentFromDB.setChecksum(streamContent.getChecksum()); streamContentFromDB.setContentType(streamContent.getContentType()); db.update(streamContentFromDB); createAttachment(streamContentFromDB.getId(), streamContentFromDB.getRevision(), streamContent); } }
public static ViewQuery createAndFetchViewQuery() { if (!connector.contains(DESIGN_DOC_ID)) { //The design document doesn't exist in the database so we create it. JsonNode rootNode = mapper.createObjectNode(); ((ObjectNode)rootNode).put("language", "javascript"); ((ObjectNode)rootNode).putObject("views").putObject(TEST_VIEW).put("map", "function(doc) {\n emit(doc._id, doc);\n}"); connector.create(DESIGN_DOC_ID, rootNode); } return new ViewQuery().designDocId(DESIGN_DOC_ID).viewName(TEST_VIEW); }