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


Java DocumentCodec类代码示例

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


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

示例1: getScanStats

import org.bson.codecs.DocumentCodec; //导入依赖的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);
  }
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:22,代码来源:MongoGroupScan.java

示例2: loadResource

import org.bson.codecs.DocumentCodec; //导入依赖的package包/类
@Override
public void loadResource(Resource resource) throws IOException {
	final MongoCollection<Document> collection = handler.getCollection(uri);

	if (!resource.getContents().isEmpty()) {
		resource.getContents().clear();
	}

	final String id = uri.segment(2);
	final Document filter = new Document(MongoHandler.ID_FIELD, id);
	final Document document = collection
			.find(filter)
			.limit(1)
			.first();

	if (document == null) {
		throw new IOException("Cannot find document with " + MongoHandler.ID_FIELD + " " + id);
	}

	JsonWriter writer = new JsonWriter(new StringWriter());
	new DocumentCodec().encode(writer, document,
			EncoderContext.builder()
					.isEncodingCollectibleDocument(true)
					.build());
	readJson(resource, writer.getWriter().toString());
}
 
开发者ID:emfjson,项目名称:emfjson-mongo,代码行数:27,代码来源:MongoInputStream.java

示例3: MongoClientWrapper

import org.bson.codecs.DocumentCodec; //导入依赖的package包/类
@Inject
public MongoClientWrapper(MongoClientConfiguration configuration) throws
    UnreachableMongoServerException {
  try {
    MongoClientOptions options = toMongoClientOptions(configuration);
    ImmutableList<MongoCredential> credentials = toMongoCredentials(configuration);

    testAddress(configuration.getHostAndPort(), options);

    this.configuration = configuration;

    this.driverClient = new com.mongodb.MongoClient(
        new ServerAddress(
            configuration.getHostAndPort().getHostText(),
            configuration.getHostAndPort().getPort()),
        credentials,
        options
    );

    version = calculateVersion();
    codecRegistry = CodecRegistries.fromCodecs(new DocumentCodec());
    closed = false;
  } catch (com.mongodb.MongoException ex) {
    throw new UnreachableMongoServerException(configuration.getHostAndPort(), ex);
  }
}
 
开发者ID:torodb,项目名称:mongowp,代码行数:27,代码来源:MongoClientWrapper.java

示例4: getEncoder

import org.bson.codecs.DocumentCodec; //导入依赖的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();
    }
}
 
开发者ID:ozlerhakan,项目名称:mongolastic,代码行数:33,代码来源:ElasticBulkService.java

示例5: JsonCodec

import org.bson.codecs.DocumentCodec; //导入依赖的package包/类
public JsonCodec( TypeReference<T> tr, Class<T> clazz, Function<T, String> idFunc ) {
    this.clazz = clazz;
    this.idFunc = idFunc;
    documentCodec = new DocumentCodec();
    fileReader = Binder.json.readerFor( tr );
    fileWriter = Binder.json.writerFor( tr );
}
 
开发者ID:oaplatform,项目名称:oap,代码行数:8,代码来源:JsonCodec.java

示例6: get

import org.bson.codecs.DocumentCodec; //导入依赖的package包/类
@Override
@SuppressWarnings( "unchecked" )
public <T> Codec<T> get( Class<T> clazz, final CodecRegistry registry )
{
    if ( clazz.isPrimitive() )
    {
        clazz = Primitives.wrap( clazz );
    }
    if ( codecs.containsKey( clazz ) )
    {
        return (Codec<T>) codecs.get( clazz );
    }

    if ( Entity.class.isAssignableFrom( clazz ) )
    {
        // there are two possible class types we can get. Some are the real interfaces and the other classes are
        // proxy based
        Class<?> eclass = Proxy.isProxyClass( clazz ) ? clazz.getInterfaces()[0] : clazz;
        return (Codec<T>) new EntityCodec( db, EntityFactory.getProperties( (Class<? extends Entity>) eclass ) );
    }

    if ( Document.class.isAssignableFrom( clazz ) )
    {
        return (Codec<T>) new DocumentCodec( registry, mapping );
    }

    if ( List.class.isAssignableFrom( clazz ) )
    {
        return (Codec<T>) new ListCodec( registry, mapping );
    }

    if ( clazz.isArray() )
    {
        return (Codec<T>) new ArrayCodec( registry, mapping );
    }

    return null;
}
 
开发者ID:cherimojava,项目名称:cherimodata,代码行数:39,代码来源:EntityCodecProvider.java

示例7: readFrom

import org.bson.codecs.DocumentCodec; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public <T> T readFrom(Document document, Class<T> target) {
    BsonDocument bsonDocument = document.toBsonDocument(target, CodecRegistries.fromCodecs(new DocumentCodec()));
    return (T) TDocument.fromBsonDocument(bsonDocument, target).getEquivalentPOJO(this);
}
 
开发者ID:welkinbai,项目名称:BsonMapper,代码行数:7,代码来源:DefaultBsonMapper.java

示例8: VerseCodec

import org.bson.codecs.DocumentCodec; //导入依赖的package包/类
public VerseCodec() {
	 this.documentCodec = new DocumentCodec();
}
 
开发者ID:aureliano,项目名称:verbum-domini,代码行数:4,代码来源:VerseCodec.java

示例9: BookCodec

import org.bson.codecs.DocumentCodec; //导入依赖的package包/类
public BookCodec() {
	 this.documentCodec = new DocumentCodec();
}
 
开发者ID:aureliano,项目名称:verbum-domini,代码行数:4,代码来源:BookCodec.java

示例10: BibleCodec

import org.bson.codecs.DocumentCodec; //导入依赖的package包/类
public BibleCodec() {
	 this.documentCodec = new DocumentCodec();
}
 
开发者ID:aureliano,项目名称:verbum-domini,代码行数:4,代码来源:BibleCodec.java

示例11: UserCodec

import org.bson.codecs.DocumentCodec; //导入依赖的package包/类
public UserCodec() {
	 this.documentCodec = new DocumentCodec();
}
 
开发者ID:aureliano,项目名称:verbum-domini,代码行数:4,代码来源:UserCodec.java

示例12: ChapterCodec

import org.bson.codecs.DocumentCodec; //导入依赖的package包/类
public ChapterCodec() {
	 this.documentCodec = new DocumentCodec();
}
 
开发者ID:aureliano,项目名称:verbum-domini,代码行数:4,代码来源:ChapterCodec.java

示例13: mongoDocumentToByteArray

import org.bson.codecs.DocumentCodec; //导入依赖的package包/类
public static byte[] mongoDocumentToByteArray(Document mongoDocument) {
	BasicOutputBuffer outputBuffer = new BasicOutputBuffer();
	BsonBinaryWriter writer = new BsonBinaryWriter(outputBuffer);
	new DocumentCodec().encode(writer, mongoDocument, EncoderContext.builder().isEncodingCollectibleDocument(true).build());
	return outputBuffer.toByteArray();
}
 
开发者ID:lumongo,项目名称:lumongo,代码行数:7,代码来源:LumongoUtil.java

示例14: byteArrayToMongoDocument

import org.bson.codecs.DocumentCodec; //导入依赖的package包/类
public static Document byteArrayToMongoDocument(byte[] byteArray) {
	BsonBinaryReader bsonReader = new BsonBinaryReader(ByteBuffer.wrap(byteArray));
	return new DocumentCodec().decode(bsonReader, DecoderContext.builder().build());
}
 
开发者ID:lumongo,项目名称:lumongo,代码行数:5,代码来源:LumongoUtil.java


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