Skip to content

Instantly share code, notes, and snippets.

@daschl
Created March 2, 2018 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daschl/9d9c9536f015dcdf3d8c45edde1faf63 to your computer and use it in GitHub Desktop.
Save daschl/9d9c9536f015dcdf3d8c45edde1faf63 to your computer and use it in GitHub Desktop.
class Config extends AbstractCouchbaseConfiguration {
protected List<String> getBootstrapHosts() {
return Arrays.asList("127.0.0.1");
}
protected String getBucketName() {
return "travel-sample";
}
protected String getBucketPassword() {
return "";
}
@Override
public MappingCouchbaseConverter mappingCouchbaseConverter() throws Exception {
return new MyMappingCouchbaseConverter(couchbaseMappingContext(), typeKey());
}
}
class MyMappingCouchbaseConverter extends MappingCouchbaseConverter {
public MyMappingCouchbaseConverter(MappingContext<? extends CouchbasePersistentEntity<?>, CouchbasePersistentProperty> mappingContext) {
super(mappingContext);
}
public MyMappingCouchbaseConverter(MappingContext<? extends CouchbasePersistentEntity<?>, CouchbasePersistentProperty> mappingContext, String typeKey) {
super(mappingContext, typeKey);
}
@Override
public void write(Object source, CouchbaseDocument target) {
if (source instanceof MyEntity) {
// todo: custom conversion from your entity into target
} else {
super.write(source, target);
}
}
@Override
public <R> R read(Class<R> clazz, CouchbaseDocument source) {
if (MyEntity.class.isAssignableFrom(clazz)) {
// todo: init clazz and assign fields from source
} else {
return super.read(clazz, source);
}
}
}
class MyEntity {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment