当前位置: 首页>>代码示例>>Java>>正文


Java WriteModel类代码示例

本文整理汇总了Java中com.mongodb.client.model.WriteModel的典型用法代码示例。如果您正苦于以下问题:Java WriteModel类的具体用法?Java WriteModel怎么用?Java WriteModel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


WriteModel类属于com.mongodb.client.model包,在下文中一共展示了WriteModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: write

import com.mongodb.client.model.WriteModel; //导入依赖的package包/类
@Override
public StorageWriteResult write(List<DataContainer> containers) throws Exception {
    MongoCollection<Document> collection = MongoStorageAdapter.getCollection(MongoStorageAdapter.collectionEventRecordsName);

    // Build an array of documents
    List<WriteModel<Document>> documents = new ArrayList<>();
    for (DataContainer container : containers) {
        Document document = documentFromView(container);

        //Prism.getLogger().debug(DataUtil.jsonFromDataView(container).toString());

        // TTL
        document.append("Expires", DateUtil.parseTimeStringToDate(expiration, true));

        // Insert
        documents.add(new InsertOneModel<>(document));
    }

    // Write
    collection.bulkWrite(documents, bulkWriteOptions);

    // @todo implement real results, BulkWriteResult

    return new StorageWriteResult();
}
 
开发者ID:prism,项目名称:Prism,代码行数:26,代码来源:MongoRecords.java

示例2: bulkWrite

import com.mongodb.client.model.WriteModel; //导入依赖的package包/类
public CompletableFuture<BulkWriteResult> bulkWrite(final String collectionName, final List<? extends WriteModel<? extends Document>> requests) {
    return asyncExecutor.execute(new Callable<BulkWriteResult>() {
        @Override
        public BulkWriteResult call() throws Exception {
            return dbExecutor.bulkWrite(collectionName, requests);
        }
    });
}
 
开发者ID:landawn,项目名称:AbacusUtil,代码行数:9,代码来源:AsyncMongoDBExecutor.java

示例3: updateAll

import com.mongodb.client.model.WriteModel; //导入依赖的package包/类
@Override
public <P extends ParaObject> void updateAll(String appid, List<P> objects) {
	if (StringUtils.isBlank(appid) || objects == null) {
		return;
	}
	try {
		ArrayList<WriteModel<Document>> updates = new ArrayList<WriteModel<Document>>();
		List<String> ids = new ArrayList<String>(objects.size());
		for (P object : objects) {
			if (object != null) {
				object.setUpdated(Utils.timestamp());
				Document id = new Document(ID, object.getId());
				Document data = new Document("$set", toRow(object, Locked.class, true));
				UpdateOneModel<Document> um = new UpdateOneModel<Document>(id, data);
				updates.add(um);
				ids.add(object.getId());
			}
		}
		BulkWriteResult res = getTable(appid).bulkWrite(updates, new BulkWriteOptions().ordered(true));
		logger.debug("Updated: " + res.getModifiedCount() + ", keys: " + ids);
	} catch (Exception e) {
		logger.error(null, e);
	}
	logger.debug("DAO.updateAll() {}", objects.size());
}
 
开发者ID:Erudika,项目名称:para-dao-mongodb,代码行数:26,代码来源:MongoDBDAO.java

示例4: fsync

import com.mongodb.client.model.WriteModel; //导入依赖的package包/类
@Override
public void fsync() {
    super.fsync();

    val count = new MutableInt();

    Stream.of( data.values()
        .stream()
        .filter( m -> m.modified >= lastFsync ) )
        .grouped( bulkSize )
        .forEach( list -> {
            count.add( list.size() );

            final List<? extends WriteModel<Metadata<T>>> bulk = Lists.map( list,
                metadata -> {
                    val id = identifier.get( metadata.object );
                    return new ReplaceOneModel<>( eq( "_id", new ObjectId( id ) ), metadata, UPDATE_OPTIONS_UPSERT );
                } );
            collection.bulkWrite( bulk );

        } );

    log.info( "[{}] fsync total: {}, modified: {}", collection.getNamespace(), size(), count.intValue() );
    lastFsync = System.currentTimeMillis();
}
 
开发者ID:oaplatform,项目名称:oap,代码行数:26,代码来源:MongoStorage.java

示例5: bulkDeleteDocuments

import com.mongodb.client.model.WriteModel; //导入依赖的package包/类
@Override
public BulkOperationResult bulkDeleteDocuments(
        String dbName,
        String collName,
        BsonDocument filter,
        BsonDocument shardedKeys) {
    MongoDatabase mdb = client.getDatabase(dbName);
    MongoCollection<BsonDocument> mcoll
            = mdb.getCollection(collName, BsonDocument.class);

    List<WriteModel<BsonDocument>> deletes = new ArrayList<>();

    Bson _filter;

    if (shardedKeys != null) {
        _filter = and(filter, shardedKeys);
    } else {
        _filter = filter;
    }

    deletes.add(new DeleteManyModel<>(_filter));

    BulkWriteResult result = mcoll.bulkWrite(deletes);

    return new BulkOperationResult(HttpStatus.SC_OK, null, result);
}
 
开发者ID:SoftInstigate,项目名称:restheart,代码行数:27,代码来源:DocumentDAO.java

示例6: bulkUpsertDocuments

import com.mongodb.client.model.WriteModel; //导入依赖的package包/类
public static BulkOperationResult bulkUpsertDocuments(
        final MongoCollection<BsonDocument> coll,
        final BsonArray documents,
        final BsonDocument filter,
        final BsonDocument shardKeys) {
    Objects.requireNonNull(coll);
    Objects.requireNonNull(documents);

    ObjectId newEtag = new ObjectId();

    List<WriteModel<BsonDocument>> wm = getBulkWriteModel(
            coll,
            documents,
            filter,
            shardKeys,
            newEtag);

    BulkWriteResult result = coll.bulkWrite(wm);

    return new BulkOperationResult(HttpStatus.SC_OK, newEtag, result);
}
 
开发者ID:SoftInstigate,项目名称:restheart,代码行数:22,代码来源:DAOUtils.java

示例7: MongoBulkWriter

import com.mongodb.client.model.WriteModel; //导入依赖的package包/类
public MongoBulkWriter(String URI, String namespace)
{
	logger = LoggerFactory.getLogger(MongoBulkWriter.class);
	logger.info("Connecting to " + URI );
	mongoClient = new MongoClient(new MongoClientURI(URI));
	String[] parts = namespace.split("\\.");
	db = mongoClient.getDatabase(parts[0]);
	collection = db.getCollection(parts[1]);
	
	ops = new ArrayList<WriteModel<Document>>();
}
 
开发者ID:johnlpage,项目名称:MongoSyphon,代码行数:12,代码来源:MongoBulkWriter.java

示例8: bulkWrite

import com.mongodb.client.model.WriteModel; //导入依赖的package包/类
@Test
public void bulkWrite()
{
    List<WriteModel<Document>> list = insertOneWithBulk();

    coll.deleteOne(Filters.eq("name", "DELETEME"));

    coll.bulkWrite(list, new BulkWriteOptions());

    coll.deleteMany(Filters.eq("name", "DELETEME"));
}
 
开发者ID:dd00f,项目名称:ibm-performance-monitor,代码行数:12,代码来源:ProfiledMongoClientTest.java

示例9: insertOneWithBulk

import com.mongodb.client.model.WriteModel; //导入依赖的package包/类
private List<WriteModel<Document>> insertOneWithBulk()
{
    List<WriteModel<Document>> list = new ArrayList<WriteModel<Document>>();
    list.add(new InsertOneModel<Document>(createDeleteDocument()));
    coll.bulkWrite(list);
    return list;
}
 
开发者ID:dd00f,项目名称:ibm-performance-monitor,代码行数:8,代码来源:ProfiledMongoClientTest.java

示例10: put

import com.mongodb.client.model.WriteModel; //导入依赖的package包/类
/**
 * Put the records in the sink.
 *
 * @param collection the set of records to send.
 */
@Override
public void put(Collection<SinkRecord> collection) {
    List<SinkRecord> records = new ArrayList<>(collection);
    for (int i = 0; i < records.size(); i++) {
        Map<String, List<WriteModel<Document>>> bulks = new HashMap<>();

        for (int j = 0; j < bulkSize && i < records.size(); j++, i++) {
            SinkRecord record = records.get(i);
            Map<String, Object> jsonMap = SchemaUtils.toJsonMap((Struct) record.value());
            String topic = record.topic();

            if (bulks.get(topic) == null) {
                bulks.put(topic, new ArrayList<WriteModel<Document>>());
            }

            Document newDocument = new Document(jsonMap)
                    .append("_id", record.kafkaOffset());

            log.trace("Adding to bulk: {}", newDocument.toString());
            bulks.get(topic).add(new UpdateOneModel<Document>(
                    Filters.eq("_id", record.kafkaOffset()),
                    new Document("$set", newDocument),
                    new UpdateOptions().upsert(true)));
        }
        i--;
        log.trace("Executing bulk");
        for (String key : bulks.keySet()) {
            try {
                com.mongodb.bulk.BulkWriteResult result = mapping.get(key).bulkWrite(bulks.get(key));
            } catch (Exception e) {
                log.error(e.getMessage());
            }
        }
    }
}
 
开发者ID:DataReply,项目名称:kafka-connect-mongodb,代码行数:41,代码来源:MongodbSinkTask.java

示例11: bulkWrite

import com.mongodb.client.model.WriteModel; //导入依赖的package包/类
public BulkWriteResult bulkWrite(final List<? extends WriteModel<? extends Document>> requests, final BulkWriteOptions options) {
    if (options == null) {
        return coll.bulkWrite(requests);
    } else {
        return coll.bulkWrite(requests, options);
    }
}
 
开发者ID:landawn,项目名称:AbacusUtil,代码行数:8,代码来源:MongoCollectionExecutor.java

示例12: bulkWrite

import com.mongodb.client.model.WriteModel; //导入依赖的package包/类
public CompletableFuture<BulkWriteResult> bulkWrite(final List<? extends WriteModel<? extends Document>> requests) {
    return asyncExecutor.execute(new Callable<BulkWriteResult>() {
        @Override
        public BulkWriteResult call() throws Exception {
            return collExecutor.bulkWrite(requests);
        }
    });
}
 
开发者ID:landawn,项目名称:AbacusUtil,代码行数:9,代码来源:AsyncMongoCollectionExecutor.java

示例13: bulkWrite

import com.mongodb.client.model.WriteModel; //导入依赖的package包/类
@Override
public Observable<BulkWriteResult> bulkWrite(final List<? extends WriteModel<? extends TDocument>> requests,
                                            final BulkWriteOptions options) {
    return RxObservables.create(Observables.observe(new Block<SingleResultCallback<BulkWriteResult>>() {
        @Override
        public void apply(final SingleResultCallback<BulkWriteResult> callback) {
            wrapped.bulkWrite(requests, options, callback);
        }
    }), observableAdapter);
}
 
开发者ID:mongodb,项目名称:mongo-java-driver-rx,代码行数:11,代码来源:MongoCollectionImpl.java

示例14: updateSingleRecord

import com.mongodb.client.model.WriteModel; //导入依赖的package包/类
private void updateSingleRecord(List<WriteModel<Document>>  bulkWriter,
		Document key) {
	// Key Query
	rotateCollection();
	Document query = new Document();
	Document change;

	if (key == null) {
		int range = sequence * testOpts.workingset / 100;
		int rest = sequence - range;

		int recordno = rest + getNextVal(range);

		query.append("_id",
				new Document("w", workerID).append("i", recordno));
	} else {
		query.append("_id", key);
	}

	int updateFields = (testOpts.updateFields <= testOpts.numFields) ? testOpts.updateFields : testOpts.numFields;

	if (updateFields == 1) {
		long changedfield = (long) getNextVal((int) testOpts.NUMBER_SIZE);
		Document fields = new Document("fld0", changedfield);
		change = new Document("$set", fields);
	} else {
		TestRecord tr = createNewRecord();
		tr.internalDoc.remove("_id");
		change = new Document("$set", tr.internalDoc);
	}
		
	if (testOpts.findandmodify == false) {
		bulkWriter.add(new UpdateManyModel<Document>(query, change));
	} else {
		this.coll.findOneAndUpdate(query, change); //These are immediate not batches
	}
	testResults.RecordOpsDone("updates", 1);
}
 
开发者ID:johnlpage,项目名称:POCDriver,代码行数:39,代码来源:MongoWorker.java

示例15: insertNewRecord

import com.mongodb.client.model.WriteModel; //导入依赖的package包/类
private TestRecord insertNewRecord(List<WriteModel<Document>>  bulkWriter) {
	int[] arr = new int[2];
	arr[0] = testOpts.arraytop;
	arr[1] = testOpts.arraynext;
	TestRecord tr = createNewRecord();

	bulkWriter.add(new InsertOneModel<Document>(tr.internalDoc));
	return tr;
}
 
开发者ID:johnlpage,项目名称:POCDriver,代码行数:10,代码来源:MongoWorker.java


注:本文中的com.mongodb.client.model.WriteModel类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。