cache a few repo sql strings
This commit is contained in:
@@ -35,7 +35,6 @@ import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class BeaconBeamRepo extends AbstractDhRepo<DhBlockPos, BeaconBeamDTO>
|
||||
{
|
||||
@@ -96,20 +95,20 @@ public class BeaconBeamRepo extends AbstractDhRepo<DhBlockPos, BeaconBeamDTO>
|
||||
return dto;
|
||||
}
|
||||
|
||||
private final String insertSqlTemplate =
|
||||
"INSERT INTO "+this.getTableName() + " (\n" +
|
||||
" BlockPosX, BlockPosY, BlockPosZ, \n" +
|
||||
" ColorR, ColorG, ColorB, \n" +
|
||||
" LastModifiedUnixDateTime, CreatedUnixDateTime) \n" +
|
||||
"VALUES( \n" +
|
||||
" ?, ?, ?, \n" +
|
||||
" ?, ?, ?, \n" +
|
||||
" ?, ? \n" +
|
||||
");";
|
||||
@Override
|
||||
public PreparedStatement createInsertStatement(BeaconBeamDTO dto) throws SQLException
|
||||
{
|
||||
String sql =
|
||||
"INSERT INTO "+this.getTableName() + " (\n" +
|
||||
" BlockPosX, BlockPosY, BlockPosZ, \n" +
|
||||
" ColorR, ColorG, ColorB, \n" +
|
||||
" LastModifiedUnixDateTime, CreatedUnixDateTime) \n" +
|
||||
"VALUES( \n" +
|
||||
" ?, ?, ?, \n" +
|
||||
" ?, ?, ?, \n" +
|
||||
" ?, ? \n" +
|
||||
");";
|
||||
PreparedStatement statement = this.createPreparedStatement(sql);
|
||||
PreparedStatement statement = this.createPreparedStatement(this.insertSqlTemplate);
|
||||
if (statement == null)
|
||||
{
|
||||
return null;
|
||||
@@ -131,16 +130,16 @@ public class BeaconBeamRepo extends AbstractDhRepo<DhBlockPos, BeaconBeamDTO>
|
||||
return statement;
|
||||
}
|
||||
|
||||
private final String updateSqlTemplate =
|
||||
"UPDATE "+this.getTableName()+" \n" +
|
||||
"SET \n" +
|
||||
" ColorR = ?, ColorG = ?, ColorB = ?, \n" +
|
||||
" LastModifiedUnixDateTime = ? \n" +
|
||||
"WHERE BlockPosX = ? AND BlockPosY = ? AND BlockPosZ = ?";
|
||||
@Override
|
||||
public PreparedStatement createUpdateStatement(BeaconBeamDTO dto) throws SQLException
|
||||
{
|
||||
String sql =
|
||||
"UPDATE "+this.getTableName()+" \n" +
|
||||
"SET \n" +
|
||||
" ColorR = ?, ColorG = ?, ColorB = ?, \n" +
|
||||
" LastModifiedUnixDateTime = ? \n" +
|
||||
"WHERE BlockPosX = ? AND BlockPosY = ? AND BlockPosZ = ?";
|
||||
PreparedStatement statement = this.createPreparedStatement(sql);
|
||||
PreparedStatement statement = this.createPreparedStatement(this.updateSqlTemplate);
|
||||
if (statement == null)
|
||||
{
|
||||
return null;
|
||||
|
||||
@@ -21,7 +21,6 @@ package com.seibel.distanthorizons.core.sql.repo;
|
||||
|
||||
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
|
||||
import com.seibel.distanthorizons.core.pos.DhChunkPos;
|
||||
import com.seibel.distanthorizons.core.sql.dto.BeaconBeamDTO;
|
||||
import com.seibel.distanthorizons.core.sql.dto.ChunkHashDTO;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -30,7 +29,6 @@ import java.io.File;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Map;
|
||||
|
||||
public class ChunkHashRepo extends AbstractDhRepo<DhChunkPos, ChunkHashDTO>
|
||||
{
|
||||
@@ -87,20 +85,25 @@ public class ChunkHashRepo extends AbstractDhRepo<DhChunkPos, ChunkHashDTO>
|
||||
return dto;
|
||||
}
|
||||
|
||||
private final String insertSqlTemplate =
|
||||
"INSERT INTO "+this.getTableName() + " (\n" +
|
||||
" ChunkPosX, ChunkPosZ, \n" +
|
||||
" ChunkHash, \n" +
|
||||
" LastModifiedUnixDateTime, CreatedUnixDateTime) \n" +
|
||||
"VALUES( \n" +
|
||||
" ?, ?, \n" +
|
||||
" ?, \n" +
|
||||
" ?, ? \n" +
|
||||
");";
|
||||
@Override
|
||||
public PreparedStatement createInsertStatement(ChunkHashDTO dto) throws SQLException
|
||||
{
|
||||
String sql =
|
||||
"INSERT INTO "+this.getTableName() + " (\n" +
|
||||
" ChunkPosX, ChunkPosZ, \n" +
|
||||
" ChunkHash, \n" +
|
||||
" LastModifiedUnixDateTime, CreatedUnixDateTime) \n" +
|
||||
"VALUES( \n" +
|
||||
" ?, ?, \n" +
|
||||
" ?, \n" +
|
||||
" ?, ? \n" +
|
||||
");";
|
||||
PreparedStatement statement = this.createPreparedStatement(sql);
|
||||
PreparedStatement statement = this.createPreparedStatement(this.insertSqlTemplate);
|
||||
if (statement == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
int i = 1;
|
||||
statement.setObject(i++, dto.pos.getX());
|
||||
@@ -114,16 +117,21 @@ public class ChunkHashRepo extends AbstractDhRepo<DhChunkPos, ChunkHashDTO>
|
||||
return statement;
|
||||
}
|
||||
|
||||
private final String updateSqlTemplate =
|
||||
"UPDATE "+this.getTableName()+" \n" +
|
||||
"SET \n" +
|
||||
" ChunkHash = ? \n" +
|
||||
" ,LastModifiedUnixDateTime = ? \n" +
|
||||
"WHERE ChunkPosX = ? AND ChunkPosZ = ?";
|
||||
@Override
|
||||
public PreparedStatement createUpdateStatement(ChunkHashDTO dto) throws SQLException
|
||||
{
|
||||
String sql =
|
||||
"UPDATE "+this.getTableName()+" \n" +
|
||||
"SET \n" +
|
||||
" ChunkHash = ? \n" +
|
||||
" ,LastModifiedUnixDateTime = ? \n" +
|
||||
"WHERE ChunkPosX = ? AND ChunkPosZ = ?";
|
||||
PreparedStatement statement = this.createPreparedStatement(sql);
|
||||
PreparedStatement statement = this.createPreparedStatement(updateSqlTemplate);
|
||||
if (statement == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
int i = 1;
|
||||
statement.setObject(i++, dto.chunkHash);
|
||||
|
||||
+10
-10
@@ -312,22 +312,22 @@ public class FullDataSourceV2Repo extends AbstractDhRepo<Long, FullDataSourceV2D
|
||||
/** should be be very similar to {@link FullDataSourceV2Repo#getChildPositionsToUpdateSql} */
|
||||
private final String getParentPositionsToUpdateSql =
|
||||
"SELECT DetailLevel, PosX, PosZ, " +
|
||||
" abs((PosX << (6 + DetailLevel)) - ?) + abs((PosZ << (6 + DetailLevel)) - ?) AS Distance " +
|
||||
"FROM " + this.getTableName() + " " +
|
||||
"WHERE ApplyToParent = 1 " +
|
||||
"ORDER BY DetailLevel ASC, Distance ASC " +
|
||||
"LIMIT ?; ";
|
||||
" abs((PosX << (6 + DetailLevel)) - ?) + abs((PosZ << (6 + DetailLevel)) - ?) AS Distance " +
|
||||
"FROM " + this.getTableName() + " " +
|
||||
"WHERE ApplyToParent = 1 " +
|
||||
"ORDER BY DetailLevel ASC, Distance ASC " +
|
||||
"LIMIT ?; ";
|
||||
public LongArrayList getPositionsToUpdate(int targetBlockPosX, int targetBlockPosZ, int returnCount)
|
||||
{ return this.getPositionsToUpdate(targetBlockPosX, targetBlockPosZ, returnCount, true); }
|
||||
|
||||
/** should be be very similar to {@link FullDataSourceV2Repo#getParentPositionsToUpdateSql} */
|
||||
private final String getChildPositionsToUpdateSql =
|
||||
"SELECT DetailLevel, PosX, PosZ, " +
|
||||
" abs((PosX << (6 + DetailLevel)) - ?) + abs((PosZ << (6 + DetailLevel)) - ?) AS Distance " +
|
||||
"FROM " + this.getTableName() + " " +
|
||||
"WHERE ApplyToChildren = 1 " +
|
||||
"ORDER BY DetailLevel ASC, Distance ASC " +
|
||||
"LIMIT ?; ";
|
||||
" abs((PosX << (6 + DetailLevel)) - ?) + abs((PosZ << (6 + DetailLevel)) - ?) AS Distance " +
|
||||
"FROM " + this.getTableName() + " " +
|
||||
"WHERE ApplyToChildren = 1 " +
|
||||
"ORDER BY DetailLevel ASC, Distance ASC " +
|
||||
"LIMIT ?; ";
|
||||
public LongArrayList getChildPositionsToUpdate(int targetBlockPosX, int targetBlockPosZ, int returnCount)
|
||||
{ return this.getPositionsToUpdate(targetBlockPosX, targetBlockPosZ, returnCount, false); }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user