This code does pretty much what John said. I picked Super CSV because it
had a way to map positions in the CSV to attributes in a Pojo.

Mapping the values to attributes:
* nameMapping = new String[]{"stockOnHand","wholeSalePrice","brand","type",
"color", "size", "gender", "id"};*
* processors = new CellProcessor[] { *
*new ParseInt(),//stockOnHand*
*new ParseDouble(),//wholeSalePrice*
*new NotNull(),//brand*
*new NotNull(),//type*
*new NotNull(),//color*
*new ParseDouble(),//size*
*new NotNull(),//gender*
*new NotNull()//productId*
* };*
* loadProducts("products.csv",nameMapping,processors);*

When putting into the Region, I used the Spring Data Repository. To improve
performance I did the puts in batches:



*private void loadProducts(String file, String[] nameMapping,
CellProcessor[] processors) { System.out.println("Started loading the
products"); initalizeBeanReader(file); Product prod; List<Product>
productPuts = new ArrayList<Product>(); int prodCount = 0; try { while
((prod = beanReader.read(Product.class, nameMapping,processors)) != null) {
productPuts.add(prod); prodCount++; if (productPuts.size() % 10 == 0) {
productRepository.save(productPuts); productPuts.clear(); } } } catch
(IOException e) { errorLog.add(e.toString()); } }*

Reply via email to