Skip to content

Commit 60587bd

Browse files
committed
introduce db-id, optimize maintenance tool
1 parent c367897 commit 60587bd

File tree

5 files changed

+18
-13
lines changed

5 files changed

+18
-13
lines changed

core/src/main/java/com/bc/fiduceo/core/SatelliteObservation.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
public class SatelliteObservation {
3232

33+
private int id;
3334
private Date startTime;
3435
private Date stopTime;
3536
private Geometry geoBounds;
@@ -41,6 +42,7 @@ public class SatelliteObservation {
4142

4243
public SatelliteObservation() {
4344
nodeType = NodeType.UNDEFINED;
45+
id = -1;
4446
}
4547

4648
public Geometry getGeoBounds() {
@@ -106,4 +108,12 @@ public void setVersion(String version) {
106108
public String getVersion() {
107109
return version;
108110
}
111+
112+
public int getId() {
113+
return id;
114+
}
115+
116+
public void setId(int id) {
117+
this.id = id;
118+
}
109119
}

core/src/main/java/com/bc/fiduceo/db/H2Driver.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,13 @@ public void insert(SatelliteObservation observation) throws SQLException {
112112
@Override
113113
public AbstractBatch updatePathBatch(SatelliteObservation satelliteObservation, String newPath, AbstractBatch batch) throws SQLException {
114114
if (batch == null) {
115-
final PreparedStatement preparedStatement = connection.prepareStatement("UPDATE SATELLITE_OBSERVATION SET DataFile = ? WHERE DataFile = ? ");
115+
final PreparedStatement preparedStatement = connection.prepareStatement("UPDATE SATELLITE_OBSERVATION SET DataFile = ? WHERE ID = ? ");
116116
batch = new JdbcBatch(preparedStatement);
117117
}
118118

119119
final PreparedStatement preparedStatement = (PreparedStatement) batch.getStatement();
120120
preparedStatement.setString(1, newPath);
121-
preparedStatement.setString(2, satelliteObservation.getDataFilePath().toString());
121+
preparedStatement.setInt(2, satelliteObservation.getId());
122122
preparedStatement.addBatch();
123123

124124
return batch;
@@ -139,9 +139,6 @@ public List<SatelliteObservation> get() throws SQLException {
139139

140140
@Override
141141
public List<SatelliteObservation> get(QueryParameter parameter) throws SQLException {
142-
143-
//org.h2.tools.Server.startWebServer(connection);
144-
145142
final Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
146143
final String sql = createSql(parameter);
147144
final ResultSet resultSet = statement.executeQuery(sql);
@@ -154,6 +151,7 @@ public List<SatelliteObservation> get(QueryParameter parameter) throws SQLExcept
154151
final SatelliteObservation observation = new SatelliteObservation();
155152

156153
final int observationId = resultSet.getInt("id");
154+
observation.setId(observationId);
157155

158156
final Timestamp startDate = resultSet.getTimestamp("StartDate");
159157
observation.setStartTime(TimeUtils.toDate(startDate));
@@ -199,8 +197,6 @@ public List<SatelliteObservation> get(QueryParameter parameter) throws SQLExcept
199197
resultList.add(observation);
200198
}
201199

202-
//org.h2.tools.Server.startWebServer(connection);
203-
204200
return resultList;
205201
}
206202

core/src/main/java/com/bc/fiduceo/db/PostGISDriver.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,13 @@ public void insert(SatelliteObservation observation) throws SQLException {
157157
@Override
158158
public AbstractBatch updatePathBatch(SatelliteObservation satelliteObservation, String newPath, AbstractBatch batch) throws SQLException {
159159
if (batch == null) {
160-
final PreparedStatement preparedStatement = connection.prepareStatement("UPDATE SATELLITE_OBSERVATION SET DataFile = ? WHERE DataFile = ?");
160+
final PreparedStatement preparedStatement = connection.prepareStatement("UPDATE SATELLITE_OBSERVATION SET DataFile = ? WHERE ID = ?");
161161
batch = new JdbcBatch(preparedStatement);
162162
}
163163

164164
final PreparedStatement preparedStatement = (PreparedStatement) batch.getStatement();
165165
preparedStatement.setString(1, newPath);
166-
preparedStatement.setString(2, satelliteObservation.getDataFilePath().toString());
166+
preparedStatement.setInt(2, satelliteObservation.getId());
167167
preparedStatement.addBatch();
168168

169169
return batch;
@@ -203,6 +203,7 @@ public List<SatelliteObservation> get(QueryParameter parameter) throws SQLExcept
203203

204204
currentId = observationId;
205205
currentObservation = new SatelliteObservation();
206+
currentObservation.setId(currentId);
206207

207208
final Timestamp startDate = resultSet.getTimestamp("StartDate");
208209
currentObservation.setStartTime(TimeUtils.toDate(startDate));

core/src/test/java/com/bc/fiduceo/core/SatelliteObservationTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public void setUp() {
3737
@Test
3838
public void testConstructor() {
3939
assertEquals(NodeType.UNDEFINED, observation.getNodeType());
40+
assertEquals(-1, observation.getId());
4041
}
4142

4243
@Test

core/src/test/java/com/bc/fiduceo/db/StorageTest_SatelliteObservation.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@
4141
import java.util.Date;
4242
import java.util.List;
4343

44-
import static org.junit.Assert.assertEquals;
45-
import static org.junit.Assert.assertFalse;
46-
import static org.junit.Assert.assertNotNull;
47-
import static org.junit.Assert.assertTrue;
44+
import static org.junit.Assert.*;
4845

4946
public abstract class StorageTest_SatelliteObservation {
5047

0 commit comments

Comments
 (0)