Fixing internals

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-publishing/document-store-lib--mongodb@122619 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2016-01-28 17:15:13 +00:00
parent e6482a0424
commit f23fbe0070
2 changed files with 20 additions and 14 deletions

View File

@ -12,7 +12,7 @@ import org.bson.codecs.Codec;
import org.bson.codecs.DecoderContext;
import org.bson.codecs.EncoderContext;
public class GenericCodec<T extends Comparable<? extends Serializable>> implements Codec<T> {
public class GenericCodec<T extends Serializable> implements Codec<T> {
protected final Class<T> tClass;

View File

@ -167,8 +167,8 @@ public class PersistenceMongoDB extends PersistenceBackend {
@SuppressWarnings({ "unchecked", "rawtypes" })
protected static List<Codec> findMissingCodecs(CodecRegistry cr, Record record){
List<Codec> codecs = new ArrayList<>();
Collection<Comparable<? extends Serializable>> properties = record.getResourceProperties().values();
for(Comparable value : properties){
Collection<? extends Serializable> properties = record.getResourceProperties().values();
for(Serializable value : properties){
try {
try {
cr.get(value.getClass());
@ -183,13 +183,22 @@ public class PersistenceMongoDB extends PersistenceBackend {
}else{
GenericCodec genericCodec = new GenericCodec<>(value.getClass());
try {
Comparable<? extends Serializable> recreatedValue = genericCodec.getFromString(value.toString());
if(value.compareTo(recreatedValue)==0){
codecs.add(genericCodec);
logger.trace("Adding {} to manage {} : {}", genericCodec, value.getClass(), value);
Serializable recreatedValue = genericCodec.getFromString(value.toString());
if(value instanceof Comparable && recreatedValue instanceof Comparable){
Comparable valueComparable = (Comparable) value;
Comparable recreatedValueComparable = (Comparable) recreatedValue;
if(valueComparable.compareTo(recreatedValueComparable)==0){
codecs.add(genericCodec);
logger.trace("Adding {} to manage {} : {}", genericCodec, value.getClass(), value);
}
}else{
String message = String.format("%s != %s", value, recreatedValue);
throw new Exception(message);
if(value.hashCode()==recreatedValue.hashCode()){
codecs.add(genericCodec);
logger.trace("Adding {} to manage {} : {}", genericCodec, value.getClass(), value);
}else{
String message = String.format("%s != %s", value, recreatedValue);
throw new Exception(message);
}
}
}catch(Exception e){
logger.error("{} cannot be used for {} : {}", GenericCodec.class.getSimpleName(), value.getClass(), value, e);
@ -239,13 +248,10 @@ public class PersistenceMongoDB extends PersistenceBackend {
}
protected static Record documentToUsageRecord(Document document) throws Exception {
Map<String, Comparable<? extends Serializable>> map = new
HashMap<String, Comparable<? extends Serializable>>();
Map<String, Serializable> map = new HashMap<String, Serializable>();
Set<Entry<String, Object>> set = document.entrySet();
for(Entry<String, Object> entry : set){
@SuppressWarnings("unchecked")
Comparable<? extends Serializable> value =
(Comparable<? extends Serializable>) entry.getValue();
Serializable value = (Serializable) entry.getValue();
map.put(entry.getKey(), value);
}
Record record = RecordUtility.getRecord(map);