1
2
3
4 package ca.spaz.cron.datasource.sql.USDAsr17;
5
6 import java.sql.*;
7 import java.util.HashMap;
8
9 import org.apache.log4j.Logger;
10
11 import ca.spaz.sql.SQLInsert;
12
13 public class USDAWeight {
14 /***
15 * Logger for this class
16 */
17 private static final Logger logger = Logger.getLogger(USDAImporter.class);
18
19 String ndb_id;
20 double amount;
21 double grams;
22 String description;
23
24
25 public USDAWeight(String str) {
26 String[] parts = str.split("//^");
27 for (int i = 0; i < parts.length; i++) {
28 parts[i] = parts[i].replaceAll("^~", "");
29 parts[i] = parts[i].replaceAll("~$", "");
30 }
31 ndb_id = parts[0];
32 amount = Double.parseDouble(parts[2]);
33 description = parts[3];
34 grams = Double.parseDouble(parts[4]);
35 }
36
37 public void addToDB(Connection c, HashMap foods) {
38 try {
39 USDAFood food = (USDAFood)foods.get(ndb_id);
40 assert(food != null);
41 SQLInsert s = new SQLInsert("Measure");
42 s.getColumns().add("FID", food.ID);
43 s.getColumns().add("description", description);
44 s.getColumns().add("grams", grams);
45 s.getColumns().add("amount", amount);
46 s.execute(c);
47 } catch (SQLException e) {
48 logger.error("parseFood(String)", e);
49 }
50 }
51
52 }