Skip to content

Commit d52739c

Browse files
committed
some changes on Convertertool
1 parent 63fdf6c commit d52739c

File tree

5 files changed

+56
-31
lines changed

5 files changed

+56
-31
lines changed

src/osm/OSMClassification.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,14 +1538,15 @@ private boolean isClassName(String key) {
15381538
public void write2Table(Connection targetConnection, String classificationTableName) throws SQLException {
15391539

15401540
SQLStatementQueue sq = new SQLStatementQueue(targetConnection);
1541-
1541+
try{
15421542
// init first line: unknown classification
15431543
sq.append("INSERT INTO ");
15441544
sq.append(classificationTableName);
15451545
sq.append(" VALUES (-1, 'no_class', 'no_subclass');");
15461546

15471547
sq.forceExecute();
1548-
1548+
}
1549+
catch(Exception e){}
15491550
// now append real data
15501551
int n = 0;
15511552

@@ -1602,10 +1603,14 @@ public void setupClassificationTable(SQLStatementQueue sq, String schema) throws
16021603
sq.append("subclassname character varying);");
16031604

16041605
// init first line: unknown classification
1606+
try{
16051607
sq.append("INSERT INTO ");
16061608
sq.append(DB.getFullTableName(schema, CLASSIFICATIONTABLE));
16071609
sq.append(" VALUES (-1, 'no_class', 'no_subclass');");
1610+
}
1611+
catch(Exception e){
16081612

1613+
}
16091614
// now append real data
16101615
int id = 0;
16111616

src/shp2ohdm/Shapefile2OHDM.java

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@ public class Shapefile2OHDM {
1919
private boolean importerUserIDSet;
2020

2121
public static void main(String[] args) {
22-
String targetParameterFileName = "db_ohdm_historic_local.txt";
23-
String importParameterFileName = "db_shape_import.txt";
22+
String importParameterFileName ="db_ohdm_historic_local.txt"; // "C:\\Program Files\\Apache Software Foundation\\Tomcat 9.0\\bin\\configFiles\\db_ohdm_historic_local"; //
23+
String targetParameterFileName = "db_shape_import.txt"; // "C:\\Program Files\\Apache Software Foundation\\Tomcat 9.0\\bin\\configFiles\\db_shape_import";//
2424

25-
if(args.length > 0) {
25+
if(args.length > 0) {
2626
importParameterFileName = args[0];
27-
} else if(args.length > 1) {
27+
}
28+
if(args.length > 1) {
2829
targetParameterFileName = args[1];
29-
} if(args.length > 2) {
30+
}
31+
else{ //(args.length > 2)
3032
System.err.println("at most two parameter required: shape-import description and ohdm target description");
3133
System.exit(1);
3234
}
@@ -99,13 +101,18 @@ void importShapefile() throws IOException {
99101
if ( (validSinceString == null && columnValidSinceYear == null)
100102
|| (validUntilString == null && columnValidUntilYear == null)
101103
|| this.importParameter.getClassificationID() == -1) {
102-
throw new SQLException("validSince, validUntil (at least year) and classification must be set - fatal, give up");
104+
105+
validSinceString = java.time.LocalDate.now().toString() ;
106+
validUntilString = java.time.LocalDate.now().toString() ;
107+
108+
109+
// throw new SQLException("validSince, validUntil (at least year) and classification must be set - fatal, give up");
103110
}
104111

105112
// both schemas are in the same db - ensured, see constructor
106113
this.sqlQueue = new SQLStatementQueue(this.importParameter);
107114

108-
// find primary key column
115+
// find primary key column
109116
sqlQueue.append("SELECT kcu.COLUMN_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS tc " +
110117
"INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS kcu\n" +
111118
" ON kcu.CONSTRAINT_NAME = tc.CONSTRAINT_NAME\n" +
@@ -116,6 +123,7 @@ void importShapefile() throws IOException {
116123
sqlQueue.append("'");
117124

118125
ResultSet resultSet = sqlQueue.executeWithResult();
126+
119127
if (resultSet.next()) {
120128
// got primary key column name
121129
pkColumnName = resultSet.getString(1);
@@ -250,7 +258,8 @@ void importShapefile() throws IOException {
250258
// since
251259
if (columnValidSinceYear == null) {
252260
validSinceValue = "'" + validSinceString + "'";
253-
} else { // at least year is in the table
261+
}
262+
else { // at least year is in the table
254263
validSinceValue = "to_timestamp(concat(cast(";
255264
validSinceValue += columnValidSinceYear;
256265
validSinceValue += " as varchar(4)), '-',";
@@ -280,7 +289,8 @@ void importShapefile() throws IOException {
280289
// until
281290
if (columnValidUntilYear == null) {
282291
validUntilValue = "'" + validUntilString + "'";
283-
} else { // at least year is in the table
292+
}
293+
else { // at least year is in the table
284294
validUntilValue = "to_timestamp(concat(cast(";
285295
validUntilValue += columnValidUntilYear;
286296
validUntilValue += " as varchar(4)), '-',";
@@ -327,7 +337,7 @@ void importShapefile() throws IOException {
327337
insertedIDsTableName = Util.makeValidTableName(insertedIDsTableName);
328338
insertedIDsTableName = DB.getFullTableName(this.importParameter.getSchema(), insertedIDsTableName);
329339

330-
sqlQueue.append("CREATE TABLE ");
340+
sqlQueue.append("CREATE TABLE IF NOT EXISTS ");
331341
sqlQueue.append(insertedIDsTableName);
332342
sqlQueue.append(" (id_geoobject_geometry bigint);");
333343
sqlQueue.forceExecute();

src/util/DB.java

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@ public class DB {
2424
// ids are defined identically in each table
2525
static public String getCreateTableBegin(String schema, String tableName) {
2626
StringBuilder sb = new StringBuilder();
27-
28-
sb.append("CREATE TABLE ");
27+
28+
sb.append("DROP TABLE IF EXISTS ");
29+
sb.append(DB.getFullTableName(schema, tableName));
30+
sb.append("; ");
31+
32+
sb.append("CREATE TABLE IF NOT EXISTS ");
2933
sb.append(DB.getFullTableName(schema, tableName));
3034
sb.append(" (");
3135
sb.append(DB.getCreatePrimaryKeyDescription(schema, tableName));
@@ -35,9 +39,10 @@ static public String getCreateTableBegin(String schema, String tableName) {
3539

3640
// primary key are created identically
3741
static public String getCreatePrimaryKeyDescription(String schema, String tableName) {
38-
return "id bigint PRIMARY KEY DEFAULT nextval('"
42+
return "id bigint PRIMARY KEY DEFAULT nextval('"
3943
+ DB.getSequenceName(DB.getFullTableName(schema, tableName))
4044
+ "'::regclass)";
45+
4146
}
4247

4348
// primary key are created identically
@@ -56,7 +61,7 @@ static public void createSequence(Connection targetConnection, String schema, St
5661

5762
static public void createSequence(SQLStatementQueue targetQueue, String schema, String tableName) throws SQLException {
5863

59-
targetQueue.append("CREATE SEQUENCE ");
64+
targetQueue.append("CREATE SEQUENCE IF NOT EXISTS ");
6065
targetQueue.append(DB.getSequenceName(DB.getFullTableName(schema, tableName)));
6166
targetQueue.append(" INCREMENT 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1;");
6267
targetQueue.forceExecute();
@@ -78,7 +83,7 @@ static public void drop(SQLStatementQueue sq, String schema, String tableName) {
7883

7984
static public void drop(SQLStatementQueue sq, String fullTableName) {
8085
try {
81-
sq.append("DROP SEQUENCE ");
86+
sq.append("DROP SEQUENCE IF EXISTS ");
8287
sq.append(DB.getSequenceName(fullTableName));
8388
sq.append(" CASCADE;");
8489
sq.forceExecute();
@@ -100,15 +105,20 @@ static public void drop(SQLStatementQueue sq, String fullTableName) {
100105
////////////////////////////////////////////////////////////////////////
101106
// names //
102107
////////////////////////////////////////////////////////////////////////
103-
104-
static public String getSequenceName(String tableName) {
105-
return tableName + "_id ";
108+
109+
110+
static public String getFullTableName_(String schema, String tableName) {
111+
return schema + ".\"" + tableName ;
112+
}static public String getSequenceName(String tableName) {
113+
return tableName.substring(0, tableName.length() - 1) + "_id\" ";
106114
}
107115

108116
static public String getFullTableName(String schema, String tableName) {
109-
return schema + "." + tableName;
117+
return schema + ".\"" + tableName+"\"";
110118
}
111119

120+
121+
112122
////////////////////////////////////////////////////////////////////////
113123
// helper //
114124
////////////////////////////////////////////////////////////////////////
@@ -187,7 +197,7 @@ public static SQLStatementQueue createSQLStatementQueue(Connection target, Param
187197
public static void writeTimeStamp(SQLStatementQueue sq, String targetSchema) throws SQLException {
188198
DB.drop(sq, targetSchema, DB.TIME_STAMP_TABLE);
189199

190-
sq.append("CREATE TABLE ");
200+
sq.append("CREATE TABLE IF NOT EXISTS ");
191201
sq.append(DB.getFullTableName(targetSchema, DB.TIME_STAMP_TABLE));
192202
sq.append(" (");
193203
sq.append("timestampstring character varying");

src/util/OHDM_DB.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public static void createOHDMTables(Connection targetConnection, String schema)
101101
sq.forceExecute();
102102
sq.append("INSERT INTO ");
103103
sq.append(DB.getFullTableName(schema, TABLE_EXTERNAL_SYSTEMS));
104-
sq.append(" (name, description) VALUES ('osm', 'Open Street Map');");
104+
sq.append("(name, description) VALUES ('osm', 'Open Street Map');");
105105
sq.forceExecute();
106106

107107
// EXTERNAL_USERS

src/util/Parameter.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,17 @@ public class Parameter {
5555
private String columnNameObjectName;
5656
private String columnNameGeometry;
5757
private String tableName;
58-
private int classificationID = -1;
58+
private int classificationID =44;// -1;
5959
private String validSince;
6060
private String validUntil;
6161
private boolean dropAndRecreate = true;
6262

63-
public String columnValidSinceYear = null;
64-
public String columnValidSinceMonth = null;
65-
public String columnValidSinceDay = null;
66-
public String columnValidUntilYear = null;
67-
public String columnValidUntilMonth = null;
68-
public String columnValidUntilDay = null;
63+
public String columnValidSinceYear ;
64+
public String columnValidSinceMonth ;
65+
public String columnValidSinceDay;
66+
public String columnValidUntilYear ;
67+
public String columnValidUntilMonth;
68+
public String columnValidUntilDay ;
6969
private String sourceURL = "";
7070
private String sourceLicense = "";
7171
private String sourceComments = "";
@@ -205,7 +205,7 @@ public Parameter(String filename) throws FileNotFoundException, IOException {
205205
case "osmfilecreationdate": this.checkDateFormat(value); break;
206206
case "columnNameObjectName": this.columnNameObjectName = value; break;
207207
case "columnNameGeometry": this.columnNameGeometry = value; break;
208-
case "tableName": this.tableName = value; break;
208+
case "tableName": this.tableName = value; break;
209209
case "validSince": this.validSince = value; this.checkDateFormat(validSince); break;
210210
case "validUntil": this.validUntil = value; this.checkDateFormat(validUntil); break;
211211
case "classificationID": this.classificationID = Integer.parseInt(value); break;

0 commit comments

Comments
 (0)