DATACOUCH-159 - Improved performance of decoding of longs.
Original pull requests: #67.
This commit is contained in:
committed by
Oliver Gierke
parent
b4e14f61e7
commit
e5bed8e292
@@ -18,7 +18,6 @@ package org.springframework.data.couchbase.core.convert.translation;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonFactory;
|
import com.fasterxml.jackson.core.JsonFactory;
|
||||||
import com.fasterxml.jackson.core.JsonGenerator;
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
import com.fasterxml.jackson.core.JsonParseException;
|
|
||||||
import com.fasterxml.jackson.core.JsonParser;
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
import com.fasterxml.jackson.core.JsonToken;
|
import com.fasterxml.jackson.core.JsonToken;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
@@ -29,7 +28,9 @@ import org.springframework.data.couchbase.core.mapping.CouchbaseStorable;
|
|||||||
import org.springframework.data.mapping.model.MappingException;
|
import org.springframework.data.mapping.model.MappingException;
|
||||||
import org.springframework.data.mapping.model.SimpleTypeHolder;
|
import org.springframework.data.mapping.model.SimpleTypeHolder;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.IOException;
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import java.io.Writer;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -215,21 +216,17 @@ public class JacksonTranslationService implements TranslationService, Initializi
|
|||||||
switch (token) {
|
switch (token) {
|
||||||
case VALUE_TRUE:
|
case VALUE_TRUE:
|
||||||
case VALUE_FALSE:
|
case VALUE_FALSE:
|
||||||
return parser.getValueAsBoolean();
|
return parser.getBooleanValue();
|
||||||
case VALUE_STRING:
|
case VALUE_STRING:
|
||||||
return parser.getValueAsString();
|
return parser.getValueAsString();
|
||||||
case VALUE_NUMBER_INT:
|
case VALUE_NUMBER_INT:
|
||||||
try {
|
return parser.getNumberValue();
|
||||||
return parser.getValueAsInt();
|
|
||||||
} catch (final JsonParseException e) {
|
|
||||||
return parser.getValueAsLong();
|
|
||||||
}
|
|
||||||
case VALUE_NUMBER_FLOAT:
|
case VALUE_NUMBER_FLOAT:
|
||||||
return parser.getValueAsDouble();
|
return parser.getDoubleValue();
|
||||||
case VALUE_NULL:
|
case VALUE_NULL:
|
||||||
return null;
|
return null;
|
||||||
default:
|
default:
|
||||||
throw new MappingException("Could not decode primitve value " + token);
|
throw new MappingException("Could not decode primitive value " + token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,20 +35,11 @@ import org.springframework.test.context.ContextConfiguration;
|
|||||||
import org.springframework.test.context.TestExecutionListeners;
|
import org.springframework.test.context.TestExecutionListeners;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.core.IsEqual.equalTo;
|
import static org.hamcrest.core.IsEqual.equalTo;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.*;
|
||||||
import static org.junit.Assert.assertNotEquals;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
import static org.junit.Assert.assertNull;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Michael Nitschinger
|
* @author Michael Nitschinger
|
||||||
@@ -198,13 +189,21 @@ public class CouchbaseTemplateTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldDeserialiseLongs() {
|
public void shouldDeserialiseLongsAndInts() {
|
||||||
final long time = new Date().getTime();
|
final long longValue = new Date().getTime();
|
||||||
SimpleWithLong simpleWithLong = new SimpleWithLong("simpleWithLong:simple", time);
|
final int intValue = new Random().nextInt();
|
||||||
template.save(simpleWithLong);
|
|
||||||
simpleWithLong = template.findById("simpleWithLong:simple", SimpleWithLong.class);
|
template.save(new SimpleWithLongAndInt("simpleWithLong:simple", longValue, intValue));
|
||||||
assertNotNull(simpleWithLong);
|
SimpleWithLongAndInt document = template.findById("simpleWithLong:simple", SimpleWithLongAndInt.class);
|
||||||
assertEquals(time, simpleWithLong.getValue());
|
assertNotNull(document);
|
||||||
|
assertEquals(longValue, document.getLongValue());
|
||||||
|
assertEquals(intValue, document.getIntValue());
|
||||||
|
|
||||||
|
template.save(new SimpleWithLongAndInt("simpleWithLong:simple:other", intValue, intValue));
|
||||||
|
document = template.findById("simpleWithLong:simple:other", SimpleWithLongAndInt.class);
|
||||||
|
assertNotNull(document);
|
||||||
|
assertEquals(intValue, document.getLongValue());
|
||||||
|
assertEquals(intValue, document.getIntValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -406,28 +405,38 @@ public class CouchbaseTemplateTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Document
|
@Document
|
||||||
static class SimpleWithLong {
|
static class SimpleWithLongAndInt {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
private long value;
|
private long longValue;
|
||||||
|
private int intValue;
|
||||||
|
|
||||||
SimpleWithLong(final String id, final long value) {
|
SimpleWithLongAndInt(final String id, final long longValue, int intValue) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.value = value;
|
this.longValue = longValue;
|
||||||
|
this.intValue = intValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getId() {
|
String getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
long getValue() {
|
long getLongValue() {
|
||||||
return value;
|
return longValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setValue(final long value) {
|
void setLongValue(final long value) {
|
||||||
this.value = value;
|
this.longValue = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIntValue() {
|
||||||
|
return intValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIntValue(int intValue) {
|
||||||
|
this.intValue = intValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user