List of usage examples for org.springframework.batch.item.file.transform FieldSet getFieldCount
int getFieldCount();
FieldSet'. From source file:fr.acxio.tools.agia.item.database.AbstractFieldSetSqlParameterSourceProvider.java
protected MapSqlParameterSource mapFieldSet(MapSqlParameterSource sMapSqlParameterSource, FieldSet sFieldSet, int sRecIdx) { if (sFieldSet != null) { boolean aHasNames = sFieldSet.hasNames(); int aFieldCount = sFieldSet.getFieldCount(); String[] aNames = aHasNames ? sFieldSet.getNames() : null; String[] aValues = sFieldSet.getValues(); for (int i = 0; i < aFieldCount; i++) { sMapSqlParameterSource.addValue(String.format(fieldsetNameFormat, sRecIdx, (aHasNames && (aNames[i] != null) && !aNames[i].isEmpty()) ? aNames[i] : String.format(unnamedColumnFormat, i)), aValues[i]);/*from w w w. j a v a 2s .c o m*/ } } return sMapSqlParameterSource; }
From source file:de.langmi.spring.batch.examples.readers.file.tokenizers.DelimitedLineTokenizerTests.java
/** * Use a standard configured tokenizer./*from w ww .j av a 2s . c o m*/ * * @throws Exception */ @Test public void testStandardConfiguration() throws Exception { // set names only, standard configuration tokenizer.setNames(new String[] { "id", "value" }); // fire FieldSet fieldSet = tokenizer.tokenize("1,foo"); // assertions assertNotNull(fieldSet); assertTrue(fieldSet.getFieldCount() == 2); assertEquals("1", fieldSet.readString("id")); assertEquals("foo", fieldSet.readString("value")); }
From source file:de.langmi.spring.batch.examples.readers.file.tokenizers.DelimitedLineTokenizerTests.java
/** * Standard tokenizer test with quoted values. * * @throws Exception //from w ww. j a va2 s . co m */ @Test public void testWithQuotes() throws Exception { // set names only, standard configuration tokenizer.setNames(new String[] { "id", "value" }); // fire FieldSet fieldSet = tokenizer.tokenize("1,\"foo,bar\""); // assertions assertNotNull(fieldSet); assertTrue(fieldSet.getFieldCount() == 2); assertEquals("1", fieldSet.readString("id")); assertEquals("foo,bar", fieldSet.readString("value")); }
From source file:de.langmi.spring.batch.examples.readers.file.tokenizers.DelimitedLineTokenizerTests.java
/** * Standard tokenizer test with white space values. * Shows the differences for readString and readRawString, first one * trims whitespace.//from w ww. j ava2 s .c o m * * @throws Exception * @see http://forum.springsource.org/showthread.php?114765-Issue-FlatFileItemReader-automatically-Trimming-the-leading-and-trailing-spaces */ @Test public void testWithSpaces() throws Exception { // set names only, standard configuration tokenizer.setNames(new String[] { "id", "value1", "value2" }); // fire FieldSet fieldSet = tokenizer.tokenize("1, foo , bar"); // assertions assertNotNull(fieldSet); assertTrue("field count", fieldSet.getFieldCount() == 3); assertEquals("1", fieldSet.readString("id")); // readString trims assertEquals("foo", fieldSet.readString("value1")); assertEquals("bar", fieldSet.readString("value2")); // readRawString does not trim assertEquals(" foo ", fieldSet.readRawString("value1")); assertEquals(" bar", fieldSet.readRawString("value2")); // assertions with properties Properties props = fieldSet.getProperties(); // the used fieldSet impl. trims whitespace in its getProperties method // see http://forum.springsource.org/showthread.php?114765-Issue-FlatFileItemReader-automatically-Trimming-the-leading-and-trailing-spaces // for follow up problems e.g. with BeanWrapperFieldSetMapper assertEquals("foo", props.getProperty("value1")); assertEquals("bar", props.getProperty("value2")); }
From source file:fr.acxio.tools.agia.transform.ListFieldSetToMapProcessor.java
protected Map<String, Object> mapFieldSet(FieldSet sFieldSet, int sRecIdx) { Map<String, Object> aResult = new HashMap<String, Object>(); if (sFieldSet != null) { boolean aHasNames = sFieldSet.hasNames(); int aFieldCount = sFieldSet.getFieldCount(); String[] aNames = aHasNames ? sFieldSet.getNames() : null; String[] aValues = sFieldSet.getValues(); for (int i = 0; i < aFieldCount; i++) { aResult.put(String.format(fieldsetNameFormat, sRecIdx, (aHasNames && (aNames[i] != null) && !aNames[i].isEmpty()) ? aNames[i] : String.format(unnamedColumnFormat, i)), aValues[i]);//w w w .j av a 2 s .co m } } return aResult; }