Permalink
Browse files

Fixed, forkert antagelse om at alle numeriske felter i en recordspec …

…er Integers
  • Loading branch information...
1 parent 59ce94b commit 3ecef7f8d7134c7fbf453844a1e138108dcd5f80 Kjeld Froberg committed Dec 11, 2012
@@ -30,9 +30,6 @@
import com.trifork.stamdata.persistence.RecordSpecification.FieldSpecification;
import com.trifork.stamdata.persistence.RecordSpecification.RecordFieldType;
-/**
- * @author Thomas G. Kristensen <tgk@trifork.com>
- */
public class RecordBuilder
{
private RecordSpecification recordSpecification;
@@ -46,21 +43,21 @@ public RecordBuilder(RecordSpecification recordSpecification)
public RecordBuilder field(String fieldName, Object value)
{
- if (value instanceof Integer)
+ if (value instanceof Long)
{
- return field(fieldName, (Integer)value);
+ return field(fieldName, (Long)value);
}
else if (value instanceof String)
{
return field(fieldName, (String)value);
}
else
{
- throw new IllegalArgumentException("Values in records must be string or integer. field=" + fieldName);
+ throw new IllegalArgumentException("Values in records must be string or long. field=" + fieldName);
}
}
- public RecordBuilder field(String fieldName, int value)
+ public RecordBuilder field(String fieldName, long value)
{
return field(fieldName, value, RecordSpecification.RecordFieldType.NUMERICAL);
}
@@ -104,7 +101,7 @@ public Record addDummyFieldsAndBuild()
}
else if(fieldSpecification.type == RecordSpecification.RecordFieldType.NUMERICAL)
{
- record = record.put(fieldSpecification.name, 0);
+ record = record.put(fieldSpecification.name, 0l);
}
else
{
@@ -132,7 +132,7 @@ private Record createRecordFromResultSet(RecordSpecification recordSpecification
if (fieldSpec.type == RecordSpecification.RecordFieldType.NUMERICAL)
{
- builder.field(fieldName, resultSet.getInt(fieldName));
+ builder.field(fieldName, resultSet.getLong(fieldName));
}
else if (fieldSpec.type == RecordSpecification.RecordFieldType.ALPHANUMERICAL)
{
@@ -95,7 +95,7 @@ public void populateInsertStatement(PreparedStatement preparedStatement, Record
}
else if (fieldSpecification.type == RecordSpecification.RecordFieldType.NUMERICAL)
{
- preparedStatement.setInt(index, (Integer) record.get(fieldSpecification.name));
+ preparedStatement.setLong(index, (Long) record.get(fieldSpecification.name));
}
else
{
@@ -152,9 +152,10 @@ public boolean conformsToSpecifications(Record record)
if (fieldsSpecification.type == RecordFieldType.NUMERICAL)
{
- if (!(value instanceof Integer))
- {
- return false;
+ if ((value instanceof Long) || (value instanceof Integer)) {
+ continue;
+ } else {
+ return false;
}
}
else if (fieldsSpecification.type == RecordFieldType.ALPHANUMERICAL)
@@ -167,7 +167,7 @@ private void importFile(Iterator<String> lines, RecordPersister persister) throw
}
}
- if (!endRecord.get("AntPost").equals(numRecords)) {
+ if (!endRecord.get("AntPost").equals(new Long(numRecords))) {
throw new ParserException("The number of records that were parsed did not match the total from the end record.");
}
}
@@ -58,7 +58,16 @@ public String stringFromRecords(Record record)
}
else if(fieldSpecification.type == RecordSpecification.RecordFieldType.NUMERICAL)
{
- String value = Integer.toString((Integer) record.get(fieldSpecification.name));
+ Object o = record.get(fieldSpecification.name);
+ String value;
+ if(o instanceof Integer) {
+ value = Integer.toString((Integer) record.get(fieldSpecification.name));
+ } else if(o instanceof Long) {
+ value = Long.toString((Long) record.get(fieldSpecification.name));
+ } else {
+ throw new AssertionError("Numerical field must be Integer or Long, but was: "+o);
+
+ }
builder.append(prefixPadding('0', fieldSpecification.length - value.length()));
builder.append(value);
}
@@ -67,10 +67,10 @@ public void testSikredeLineParserParsingASimpleLine()
Record record = exampleSikredeLineParser.parseLine(exampleLine);
- assertEquals(1, record.get("PostType"));
+ assertEquals(1l, record.get("PostType"));
assertEquals("din", record.get("TruncatedString"));
assertEquals("farmor", record.get("UntruncatedString"));
- assertEquals(42, record.get("NumberWithSpacesForPadding"));
+ assertEquals(42l, record.get("NumberWithSpacesForPadding"));
}
@Test(expected=IllegalArgumentException.class)
@@ -97,7 +97,7 @@ public void testAddingTheSameRecordTwiceButWithNeverTimestamp() throws SQLExcept
connection.commit();
Record record = fetcher.fetchCurrent("Bar", recordSpecification);
- assertThat((Integer) record.get("Foo"), is(23));
+ assertThat((Long) record.get("Foo"), is(new Long(23)));
}
@Test
Oops, something went wrong.

0 comments on commit 3ecef7f

Please sign in to comment.