diff --git a/core/src/main/java/com/seibel/distanthorizons/core/sql/repo/AbstractDhRepo.java b/core/src/main/java/com/seibel/distanthorizons/core/sql/repo/AbstractDhRepo.java index adcb35b00..bacaa652d 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/sql/repo/AbstractDhRepo.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/sql/repo/AbstractDhRepo.java @@ -283,6 +283,17 @@ public abstract class AbstractDhRepo> implemen return new ArrayList<>(); } } + public List> queryDictionary(PreparedStatement preparedStatement) + { + try + { + return this.query(preparedStatement); + } + catch (DbConnectionClosedException e) + { + return new ArrayList<>(); + } + } @Nullable public Map queryDictionaryFirst(String sql) { @@ -296,6 +307,19 @@ public abstract class AbstractDhRepo> implemen return null; } } + @Nullable + public Map queryDictionaryFirst(PreparedStatement preparedStatement) + { + try + { + List> objectList = this.query(preparedStatement); + return !objectList.isEmpty() ? objectList.get(0) : null; + } + catch (DbConnectionClosedException e) + { + return null; + } + } /** note: this can only handle 1 command at a time */ diff --git a/core/src/main/java/com/seibel/distanthorizons/core/sql/repo/FullDataSourceV2Repo.java b/core/src/main/java/com/seibel/distanthorizons/core/sql/repo/FullDataSourceV2Repo.java index 630e476ad..787756706 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/sql/repo/FullDataSourceV2Repo.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/sql/repo/FullDataSourceV2Repo.java @@ -27,6 +27,7 @@ import com.seibel.distanthorizons.core.sql.dto.FullDataSourceV2DTO; import com.seibel.distanthorizons.core.util.objects.dataStreams.DhDataInputStream; import it.unimi.dsi.fastutil.longs.LongArrayList; import org.apache.logging.log4j.Logger; +import org.jetbrains.annotations.Nullable; import java.io.ByteArrayInputStream; import java.io.File; @@ -35,6 +36,7 @@ import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; public class FullDataSourceV2Repo extends AbstractDhRepo { @@ -199,7 +201,9 @@ public class FullDataSourceV2Repo extends AbstractDhRepo> row = this.queryDictionary(preparedStatement); + return !row.isEmpty() ? (Long) row.get(0).get("LastModifiedUnixDateTime") : null; + } + catch (SQLException e) + { + throw new RuntimeException(e); + } + } + + public Map getTimestampsForRange(byte detailLevel, int startPosX, int startPosZ, int endPosX, int endPosZ) + { + try + { + PreparedStatement preparedStatement = this.createPreparedStatement( + "SELECT PosX, PosZ, LastModifiedUnixDateTime " + + "FROM " + this.getTableName() + " " + + "WHERE DetailLevel = ? " + + "AND PosX BETWEEN ? AND ? " + + "AND PosZ BETWEEN ? AND ?;" + ); + + int i = 1; + preparedStatement.setInt(i++, detailLevel - DhSectionPos.SECTION_MINIMUM_DETAIL_LEVEL); + preparedStatement.setInt(i++, startPosX); + preparedStatement.setInt(i++, endPosX); + preparedStatement.setInt(i++, startPosZ); + preparedStatement.setInt(i++, endPosZ); + + return this.queryDictionary(preparedStatement) + .stream().collect(Collectors.toMap( + row -> DhSectionPos.encode(detailLevel, (int) row.get("PosX"), (int) row.get("PosZ")), + row -> (long) row.get("LastModifiedUnixDateTime")) + ); + } + catch (SQLException e) + { + throw new RuntimeException(e); + } + } + + + //===================// // compression tests // //===================//