本文整理汇总了Java中org.bson.codecs.BsonTypeClassMap类的典型用法代码示例。如果您正苦于以下问题:Java BsonTypeClassMap类的具体用法?Java BsonTypeClassMap怎么用?Java BsonTypeClassMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BsonTypeClassMap类属于org.bson.codecs包,在下文中一共展示了BsonTypeClassMap类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getScanStats
import org.bson.codecs.BsonTypeClassMap; //导入依赖的package包/类
@Override
public ScanStats getScanStats() {
try{
MongoClient client = storagePlugin.getClient();
MongoDatabase db = client.getDatabase(scanSpec.getDbName());
MongoCollection<Document> collection = db.getCollection(scanSpec.getCollectionName());
long numDocs = collection.count();
float approxDiskCost = 0;
if (numDocs != 0) {
//toJson should use client's codec, otherwise toJson could fail on
// some types not known to DocumentCodec, e.g. DBRef.
final DocumentCodec codec =
new DocumentCodec(client.getMongoClientOptions().getCodecRegistry(), new BsonTypeClassMap());
String json = collection.find().first().toJson(codec);
approxDiskCost = json.getBytes().length * numDocs;
}
return new ScanStats(GroupScanProperty.EXACT_ROW_COUNT, numDocs, 1, approxDiskCost);
} catch (Exception e) {
throw new DrillRuntimeException(e.getMessage(), e);
}
}
示例2: addEncodeStatements
import org.bson.codecs.BsonTypeClassMap; //导入依赖的package包/类
@Override
public void addEncodeStatements(TypeMirror type, CodeGeneratorContext ctx) {
ctx.builder()
.addStatement("Codec codec = this.registry.get($L.getClass())",
ctx.getter())
.addStatement("encoderContext.encodeWithChildContext(codec, writer, $L)",
ctx.getter());
// ctx.builder()
// .addAnnotation(AnnotationSpec.builder(SuppressWarnings.class)
// .addMember("value", "$S", "unchecked")
// .addMember("value", "$S", "rawtypes").build());
ctx.instanceFields().add(ImmutableInstanceField.builder()
.type(ClassName.get(CodecRegistry.class)).name("registry").build());
ctx.instanceFields()
.add(ImmutableInstanceField.builder()
.type(ClassName.get(BsonTypeClassMap.class))
.name("bsonTypeClassMap").build());
}
示例3: getEncoder
import org.bson.codecs.BsonTypeClassMap; //导入依赖的package包/类
/**
* Customizations for the document.toJson output.
* <p>
* http://mongodb.github.io/mongo-java-driver/3.0/bson/codecs/
*
* @return the toJson encoder.
*/
private Encoder<Document> getEncoder() {
ArrayList<Codec<?>> codecs = new ArrayList<>();
if (config.getElastic().getDateFormat() != null) {
// Replace default DateCodec class to use the custom date formatter.
codecs.add(new CustomDateCodec(config.getElastic().getDateFormat()));
}
if (config.getElastic().getLongToString()) {
// Replace default LongCodec class
codecs.add(new CustomLongCodec());
}
if (codecs.size() > 0) {
BsonTypeClassMap bsonTypeClassMap = new BsonTypeClassMap();
CodecRegistry codecRegistry = CodecRegistries.fromRegistries(
CodecRegistries.fromCodecs(codecs),
MongoClient.getDefaultCodecRegistry());
return new DocumentCodec(codecRegistry, bsonTypeClassMap);
} else {
return new DocumentCodec();
}
}
示例4: get
import org.bson.codecs.BsonTypeClassMap; //导入依赖的package包/类
synchronized public static DefaultReader get(CodecRegistry registry) {
synchronized (lock) {
if (instance == null) {
instance = new DefaultReader(registry, new BsonTypeClassMap());
} else {
instance.registry.set(registry);
}
}
return instance;
}
示例5: registerCustomizedBsonTypeClassMap
import org.bson.codecs.BsonTypeClassMap; //导入依赖的package包/类
public static void registerCustomizedBsonTypeClassMap(BsonTypeClassMap bsonTypeClassMap) {
Utils.checkNotNull(bsonTypeClassMap, "bsonTypeClassMap should not be null!");
BSON_TYPE_CLASS_MAP = bsonTypeClassMap;
}
示例6: DefaultReader
import org.bson.codecs.BsonTypeClassMap; //导入依赖的package包/类
private DefaultReader(CodecRegistry registry) {
this(registry, new BsonTypeClassMap());
}
示例7: ArrayCodec
import org.bson.codecs.BsonTypeClassMap; //导入依赖的package包/类
public ArrayCodec( CodecRegistry registry, BsonTypeClassMap bsonTypeClassMap )
{
listCodec = new ListCodec( registry, bsonTypeClassMap );
}
示例8: ListCodec
import org.bson.codecs.BsonTypeClassMap; //导入依赖的package包/类
/**
* Creates a new {@code ListCodec}, which will use the given {@code CodecRegistry} and {@code BsonTypeClassMap} for
* encoding and decoding the values in the List.
*
* @param registry contains the codecs required to encode and decode {@code List} values
* @param bsonTypeClassMap will be used for decoding BSON values into the List.
*/
public ListCodec( final CodecRegistry registry, final BsonTypeClassMap bsonTypeClassMap )
{
this.registry = registry;
this.bsonTypeClassMap = bsonTypeClassMap;
}