Created
March 2, 2018 10:48
-
-
Save daschl/9d9c9536f015dcdf3d8c45edde1faf63 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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