public EntityCodec(Class<T> clazz, EntityInfo info) { this.clazz = clazz; this.info = info; idGenerator = Assertions.notNull("idGenerator", new ObjectIdGenerator()); registry = CodecRegistries.fromProviders(MongoMapper.getProviders()); documentCodec = new DocumentCodec(registry, new BsonTypeClassMap()); bsonTypeClassMap = new BsonTypeClassMap(); }
/** * Construct a new instance with the given registry * * @param registry {@link org.bson.codecs.configuration.CodecRegistry} to be used * @param idGenerator {@link org.bson.codecs.IdGenerator} to be used */ public BaseBsoneerCodec(final CodecRegistry registry, final IdGenerator generator) { this.registry = Assertions.notNull("registry", registry); this.idGenerator = Assertions.notNull("idGenerator", generator); defaultReader = DefaultReader.get(registry); setupSetters(); }
private void addConstructor(Builder classBuilder) { if (this.instanceFields.isEmpty()) { return; } MethodSpec.Builder constructor = MethodSpec.constructorBuilder() .addModifiers(Modifier.PUBLIC); if (this.instanceFields.stream() .filter(i -> i.isRegistryCodec() || i.isRegistry()).findAny() .isPresent()) { constructor.addParameter(ClassName.get(CodecRegistry.class), "registry", Modifier.FINAL); } for (InstanceField instanceField : this.instanceFields) { if (instanceField.isRegistryCodec()) { constructor.addStatement( "this.$N = $T.notNull($S, registry.get($T.class))", instanceField.name(), Assertions.class, instanceField.name(), instanceField.codecForClass()); } else { if (!instanceField.isRegistry()) { constructor.addParameter(instanceField.type(), instanceField.name(), Modifier.FINAL); } constructor.addStatement("this.$N = $T.notNull($S, $N)", instanceField.name(), Assertions.class, instanceField.name(), instanceField.name()); } } classBuilder.addMethod(constructor.build()); }
public SimpleCodec(final ObjectIdGenerator objectIdGenerator) { this.objectIdGenerator = Assertions.notNull("objectIdGenerator", objectIdGenerator); }