Remove unused OldSectionPos methods and add serialize methods to V1 repo
This commit is contained in:
@@ -175,16 +175,6 @@ public class OldDhSectionPos
|
||||
this.z * BitShiftUtil.powerOfTwo(offset));
|
||||
}
|
||||
|
||||
public OldDhSectionPos getMinCornerPos(byte returnDetailLevel)
|
||||
{
|
||||
LodUtil.assertTrue(returnDetailLevel <= this.detailLevel, "returnDetailLevel must be less than sectionDetail");
|
||||
|
||||
byte offset = (byte) (this.detailLevel - returnDetailLevel);
|
||||
return new OldDhSectionPos(returnDetailLevel,
|
||||
this.x * BitShiftUtil.powerOfTwo(offset),
|
||||
this.z * BitShiftUtil.powerOfTwo(offset));
|
||||
}
|
||||
|
||||
/**
|
||||
* A detail level of X lower than this section's detail level will return: <br>
|
||||
* 0 -> 1 <br>
|
||||
@@ -291,27 +281,6 @@ public class OldDhSectionPos
|
||||
// comparisons //
|
||||
//=============//
|
||||
|
||||
public boolean overlapsExactly(OldDhSectionPos other)
|
||||
{
|
||||
// original logic from DhLodPos
|
||||
if (this.equals(other))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (this.detailLevel == other.detailLevel)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (this.detailLevel > other.detailLevel)
|
||||
{
|
||||
return this.equals(other.convertNewToDetailLevel(this.detailLevel));
|
||||
}
|
||||
else
|
||||
{
|
||||
return other.equals(this.convertNewToDetailLevel(other.detailLevel));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean contains(OldDhSectionPos otherPos)
|
||||
{
|
||||
DhBlockPos2D thisMinBlockPos = this.getMinCornerLodPos(LodUtil.BLOCK_DETAIL_LEVEL).getCornerBlockPos();
|
||||
@@ -383,27 +352,6 @@ public class OldDhSectionPos
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//===============//
|
||||
// serialization //
|
||||
//===============//
|
||||
|
||||
/** Serialize() is different from toString() as it must NEVER be changed, and should be in a short format */
|
||||
public String serialize() { return "[" + this.detailLevel + ',' + this.x + ',' + this.z + ']'; }
|
||||
|
||||
@Nullable
|
||||
public static OldDhSectionPos deserialize(String value)
|
||||
{
|
||||
if (value.charAt(0) != '[' || value.charAt(value.length() - 1) != ']') return null;
|
||||
String[] split = value.substring(1, value.length() - 1).split(",");
|
||||
if (split.length != 3) return null;
|
||||
return new OldDhSectionPos(Byte.parseByte(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2]));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//===========//
|
||||
// overrides //
|
||||
//===========//
|
||||
|
||||
+27
-6
@@ -20,9 +20,11 @@
|
||||
package com.seibel.distanthorizons.core.sql.repo;
|
||||
|
||||
import com.seibel.distanthorizons.api.enums.worldGeneration.EDhApiWorldGenerationStep;
|
||||
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
||||
import com.seibel.distanthorizons.core.pos.OldDhSectionPos;
|
||||
import com.seibel.distanthorizons.core.sql.dto.FullDataSourceV1DTO;
|
||||
import com.seibel.distanthorizons.coreapi.util.StringUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
@@ -55,7 +57,7 @@ public class FullDataSourceV1Repo extends AbstractDhRepo<OldDhSectionPos, FullDa
|
||||
public String getTableName() { return TABLE_NAME; }
|
||||
|
||||
@Override
|
||||
public String createWhereStatement(OldDhSectionPos pos) { return "DhSectionPos = '"+pos.serialize()+"'"; }
|
||||
public String createWhereStatement(OldDhSectionPos pos) { return "DhSectionPos = '"+serializeSectionPos(pos)+"'"; }
|
||||
|
||||
|
||||
|
||||
@@ -67,7 +69,7 @@ public class FullDataSourceV1Repo extends AbstractDhRepo<OldDhSectionPos, FullDa
|
||||
public FullDataSourceV1DTO convertDictionaryToDto(Map<String, Object> objectMap) throws ClassCastException
|
||||
{
|
||||
String posString = (String) objectMap.get("DhSectionPos");
|
||||
OldDhSectionPos pos = OldDhSectionPos.deserialize(posString);
|
||||
OldDhSectionPos pos = deserializeSectionPos(posString);
|
||||
|
||||
// meta data
|
||||
int checksum = (Integer) objectMap.get("Checksum");
|
||||
@@ -106,7 +108,7 @@ public class FullDataSourceV1Repo extends AbstractDhRepo<OldDhSectionPos, FullDa
|
||||
PreparedStatement statement = this.createPreparedStatement(sql);
|
||||
|
||||
int i = 1;
|
||||
statement.setObject(i++, dto.pos.serialize());
|
||||
statement.setObject(i++, serializeSectionPos(dto.pos));
|
||||
|
||||
statement.setObject(i++, dto.checksum);
|
||||
statement.setObject(i++, 0 /*dto.dataVersion*/);
|
||||
@@ -149,7 +151,7 @@ public class FullDataSourceV1Repo extends AbstractDhRepo<OldDhSectionPos, FullDa
|
||||
|
||||
statement.setObject(i++, dto.dataArray);
|
||||
|
||||
statement.setObject(i++, dto.pos.serialize());
|
||||
statement.setObject(i++, serializeSectionPos(dto.pos));
|
||||
|
||||
return statement;
|
||||
}
|
||||
@@ -218,7 +220,7 @@ public class FullDataSourceV1Repo extends AbstractDhRepo<OldDhSectionPos, FullDa
|
||||
for (Map<String, Object> resultMap : resultMapList)
|
||||
{
|
||||
// returned in the format [sectionDetailLevel,x,z] IE [6,0,0]
|
||||
OldDhSectionPos sectionPos = OldDhSectionPos.deserialize((String) resultMap.get("DhSectionPos"));
|
||||
OldDhSectionPos sectionPos = deserializeSectionPos((String) resultMap.get("DhSectionPos"));
|
||||
list.add(sectionPos);
|
||||
}
|
||||
|
||||
@@ -230,7 +232,7 @@ public class FullDataSourceV1Repo extends AbstractDhRepo<OldDhSectionPos, FullDa
|
||||
String sql =
|
||||
"UPDATE "+this.getTableName()+" \n" +
|
||||
"SET MigrationFailed = 1 \n" +
|
||||
"WHERE DhSectionPos = '"+pos.serialize()+"'";
|
||||
"WHERE DhSectionPos = '"+serializeSectionPos(pos)+"'";
|
||||
|
||||
this.queryDictionaryFirst(sql);
|
||||
}
|
||||
@@ -283,4 +285,23 @@ public class FullDataSourceV1Repo extends AbstractDhRepo<OldDhSectionPos, FullDa
|
||||
this.queryDictionaryFirst("delete from " + this.getTableName() + " where DhSectionPos in (" + sectionPosCsv + ")");
|
||||
}
|
||||
|
||||
|
||||
|
||||
//=====================//
|
||||
// section pos helpers //
|
||||
//=====================//
|
||||
|
||||
private static String serializeSectionPos(OldDhSectionPos pos) { return "[" + pos.getDetailLevel() + ',' + pos.getX() + ',' + pos.getZ() + ']'; }
|
||||
|
||||
|
||||
@Nullable
|
||||
private static OldDhSectionPos deserializeSectionPos(String value)
|
||||
{
|
||||
if (value.charAt(0) != '[' || value.charAt(value.length() - 1) != ']') return null;
|
||||
String[] split = value.substring(1, value.length() - 1).split(",");
|
||||
if (split.length != 3) return null;
|
||||
return new OldDhSectionPos(Byte.parseByte(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2]));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user