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 |
0 |
public class USDAWeight { |
14 |
|
|
15 |
|
|
16 |
|
|
17 |
0 |
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 |
0 |
public USDAWeight(String str) { |
26 |
0 |
String[] parts = str.split("\\^"); |
27 |
0 |
for (int i = 0; i < parts.length; i++) { |
28 |
0 |
parts[i] = parts[i].replaceAll("^~", ""); |
29 |
0 |
parts[i] = parts[i].replaceAll("~$", ""); |
30 |
|
} |
31 |
0 |
ndb_id = parts[0]; |
32 |
0 |
amount = Double.parseDouble(parts[2]); |
33 |
0 |
description = parts[3]; |
34 |
0 |
grams = Double.parseDouble(parts[4]); |
35 |
0 |
} |
36 |
|
|
37 |
|
public void addToDB(Connection c, HashMap foods) { |
38 |
|
try { |
39 |
0 |
USDAFood food = (USDAFood)foods.get(ndb_id); |
40 |
0 |
assert(food != null); |
41 |
0 |
SQLInsert s = new SQLInsert("Measure"); |
42 |
0 |
s.getColumns().add("FID", food.ID); |
43 |
0 |
s.getColumns().add("description", description); |
44 |
0 |
s.getColumns().add("grams", grams); |
45 |
0 |
s.getColumns().add("amount", amount); |
46 |
0 |
s.execute(c); |
47 |
0 |
} catch (SQLException e) { |
48 |
0 |
logger.error("parseFood(String)", e); |
49 |
0 |
} |
50 |
0 |
} |
51 |
|
|
52 |
|
} |