Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
579 changes: 293 additions & 286 deletions src/cspro2sql/Main.java

Large diffs are not rendered by default.

39 changes: 28 additions & 11 deletions src/cspro2sql/MonitorEngine.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cspro2sql;

import cspro2sql.bean.AreaNameFile;
import cspro2sql.bean.Dictionary;
import cspro2sql.reader.AreaNameFileReader;
import cspro2sql.reader.DictionaryReader;
import cspro2sql.sql.TemplateManager;
import cspro2sql.writer.MonitorWriter;
Expand Down Expand Up @@ -44,24 +46,39 @@ public static void main(String[] args) throws Exception {
prop.getProperty("db.dest.schema"),
prop.getProperty("dictionary"),
prop.getProperty("dictionary.prefix"));
execute(dictionaries, System.out);

final AreaNameFile areaNames = prop.getProperty("geography") != null
? AreaNameFileReader.parseAreaNamesFile(prop.getProperty("geography"))
: null;
execute(dictionaries, areaNames, prop, System.out);
} catch (Exception ex) {
System.exit(1);
}
}

static boolean execute(List<Dictionary> dictionaries, PrintStream out) {
TemplateManager tmFieldwork = null, tmListing = null, tmExpected = null;
for (Dictionary dictionary : dictionaries) {
if (dictionary.hasTag(Dictionary.TAG_FIELDWORK)) {
tmFieldwork = new TemplateManager(dictionary);
} else if (dictionary.hasTag(Dictionary.TAG_LISTING)) {
tmListing = new TemplateManager(dictionary);
} else if (dictionary.hasTag(Dictionary.TAG_EXPECTED)) {
tmExpected = new TemplateManager(dictionary);
static boolean execute(List<Dictionary> dictionaries, AreaNameFile areaNames, Properties prop, PrintStream out) {

try {
TemplateManager tmFieldwork = null, tmListing = null,
tmExpected = null, tmEaStatus = null;
for (Dictionary dictionary : dictionaries) {
if (dictionary.hasTag(Dictionary.TAG_FIELDWORK)) {
tmFieldwork = new TemplateManager(dictionary);
} else if (dictionary.hasTag(Dictionary.TAG_LISTING)) {
tmListing = new TemplateManager(dictionary);
} else if (dictionary.hasTag(Dictionary.TAG_EXPECTED)) {
tmExpected = new TemplateManager(dictionary);
} else if (dictionary.hasTag(Dictionary.TAG_EA_STATUS)) {
tmEaStatus = new TemplateManager(dictionary);
}
}

boolean gisEnabled = prop.getProperty("gis.enabled") != null && (prop.getProperty("gis.enabled").equalsIgnoreCase("true") || prop.getProperty("gis.enabled").equals("1"));
return MonitorWriter.write(tmFieldwork, tmListing, tmExpected, tmEaStatus, areaNames, gisEnabled ,out);
} catch (IOException ex) {
System.err.println(ex.getMessage());
return false;
}
return MonitorWriter.write(tmFieldwork, tmListing, tmExpected, out);
}

}
11 changes: 8 additions & 3 deletions src/cspro2sql/SchemaEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,15 @@ public static void main(String[] args) throws Exception {
}

static boolean execute(List<Dictionary> dictionaries, boolean foreignKeys, PrintStream out) {
for (Dictionary dictionary : dictionaries) {
SchemaWriter.write(dictionary, foreignKeys, out);
try {
for (Dictionary dictionary : dictionaries) {
SchemaWriter.write(dictionary, foreignKeys, out);
}
return true;
} catch (IOException ex) {
System.err.println(ex.getMessage());
return false;
}
return true;
}

}
4 changes: 2 additions & 2 deletions src/cspro2sql/UpdateEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ static boolean execute(Properties prop) {
while (rs.next()) {
String template = rs.getString(1);
System.out.print("Updating " + template + "... ");
writeDst.executeUpdate("DROP TABLE IF EXISTS " + schema + ".m" + template);
writeDst.executeUpdate("DROP TABLE IF EXISTS " + schema + ".`m" + template + "`");
writeDst.executeQuery("SELECT 0 INTO @ID");
writeDst.executeUpdate("CREATE TABLE " + schema + ".m" + template + " (PRIMARY KEY (ID)) AS SELECT @ID := @ID + 1 ID, " + template + ".* FROM " + schema + "." + template);
writeDst.executeUpdate("CREATE TABLE " + schema + ".`m" + template + "` (PRIMARY KEY (ID)) AS SELECT @ID := @ID + 1 ID, `" + template + "`.* FROM " + schema + ".`" + template + "`");
connDst.commit();
System.out.println("done");
}
Expand Down
45 changes: 45 additions & 0 deletions src/cspro2sql/bean/AreaNameFile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package cspro2sql.bean;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
*
* @author josh
*/
public class AreaNameFile {

private final String[] levels;
private final NamedArea[] areas;
private final Map<List<Integer>, NamedArea> codeToArea;

public AreaNameFile(String[] levels, NamedArea[] areas)
{
this.levels = levels;
this.areas = areas;
codeToArea = new HashMap<>();
for (NamedArea area : areas)
codeToArea.put(area.getCodes(), area);
}

public String[] getLevels()
{
return levels;
}

public NamedArea[] getAreas()
{
return areas;
}

public NamedArea lookup(List<Integer> codes)
{
return codeToArea.get(codes);
}
}
4 changes: 4 additions & 0 deletions src/cspro2sql/bean/BeanFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public static void parseDictionary(BufferedReader br, Dictionary dictionary) thr
dictionary.setName(getValue(line));
} else if (line.startsWith(Dictionary.DICT_NOTE)) {
parseNote(dictionary, getValue(line));
} else if (line.startsWith(Dictionary.HEADER_RECSTART)) {
dictionary.setRecordTypeStart(Integer.parseInt(getValue(line)));
} else if (line.startsWith(Dictionary.HEADER_RECLEN)) {
dictionary.setRecordTypeLength(Integer.parseInt(getValue(line)));
} else if (line.isEmpty()) {
break;
}
Expand Down
Loading