forked from LogBlock/LogBlock
Improve stability for material table updates
This commit is contained in:
@ -18,7 +18,9 @@ public class EntityTypeConverter {
|
|||||||
|
|
||||||
public static int getOrAddEntityTypeId(EntityType entityType) {
|
public static int getOrAddEntityTypeId(EntityType entityType) {
|
||||||
Integer key = entityTypeToId.get(entityType);
|
Integer key = entityTypeToId.get(entityType);
|
||||||
while (key == null) {
|
int tries = 0;
|
||||||
|
while (key == null && tries < 10) {
|
||||||
|
tries++;
|
||||||
key = nextEntityTypeId;
|
key = nextEntityTypeId;
|
||||||
Connection conn = LogBlock.getInstance().getConnection();
|
Connection conn = LogBlock.getInstance().getConnection();
|
||||||
try {
|
try {
|
||||||
@ -34,8 +36,12 @@ public class EntityTypeConverter {
|
|||||||
} else {
|
} else {
|
||||||
initializeEntityTypes(conn);
|
initializeEntityTypes(conn);
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (Exception e) {
|
||||||
LogBlock.getInstance().getLogger().log(Level.SEVERE, "Could not update lb-entitytypes", e);
|
LogBlock.getInstance().getLogger().log(Level.SEVERE, "Could not update lb-entitytypes", e);
|
||||||
|
reinitializeEntityTypesCatchException();
|
||||||
|
if (tries == 10) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
conn.close();
|
conn.close();
|
||||||
@ -52,6 +58,21 @@ public class EntityTypeConverter {
|
|||||||
return idToEntityType[entityTypeId];
|
return idToEntityType[entityTypeId];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void reinitializeEntityTypesCatchException() {
|
||||||
|
Connection conn = LogBlock.getInstance().getConnection();
|
||||||
|
try {
|
||||||
|
initializeEntityTypes(conn);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogBlock.getInstance().getLogger().log(Level.SEVERE, "Could not reinitialize lb-entitytypes", e);
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
conn.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// ignored
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void initializeEntityTypes(Connection connection) throws SQLException {
|
public static void initializeEntityTypes(Connection connection) throws SQLException {
|
||||||
Statement smt = connection.createStatement();
|
Statement smt = connection.createStatement();
|
||||||
ResultSet rs = smt.executeQuery("SELECT id, name FROM `lb-entitytypes`");
|
ResultSet rs = smt.executeQuery("SELECT id, name FROM `lb-entitytypes`");
|
||||||
|
@ -42,7 +42,9 @@ public class MaterialConverter {
|
|||||||
materialString = blockDataString.substring(0, dataPart);
|
materialString = blockDataString.substring(0, dataPart);
|
||||||
}
|
}
|
||||||
Integer key = materialToID.get(materialString);
|
Integer key = materialToID.get(materialString);
|
||||||
while (key == null) {
|
int tries = 0;
|
||||||
|
while (key == null && tries < 10) {
|
||||||
|
tries++;
|
||||||
key = nextMaterialId;
|
key = nextMaterialId;
|
||||||
Connection conn = LogBlock.getInstance().getConnection();
|
Connection conn = LogBlock.getInstance().getConnection();
|
||||||
try {
|
try {
|
||||||
@ -58,8 +60,12 @@ public class MaterialConverter {
|
|||||||
} else {
|
} else {
|
||||||
initializeMaterials(conn);
|
initializeMaterials(conn);
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (Exception e) {
|
||||||
LogBlock.getInstance().getLogger().log(Level.SEVERE, "Could not update lb-materials", e);
|
LogBlock.getInstance().getLogger().log(Level.SEVERE, "Could not update lb-materials", e);
|
||||||
|
reinitializeMaterialsCatchException();
|
||||||
|
if (tries == 10) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
conn.close();
|
conn.close();
|
||||||
@ -79,7 +85,9 @@ public class MaterialConverter {
|
|||||||
}
|
}
|
||||||
String materialString = blockDataString.substring(dataPart);
|
String materialString = blockDataString.substring(dataPart);
|
||||||
Integer key = blockStateToID.get(materialString);
|
Integer key = blockStateToID.get(materialString);
|
||||||
while (key == null) {
|
int tries = 0;
|
||||||
|
while (key == null && tries < 10) {
|
||||||
|
tries++;
|
||||||
key = nextBlockStateId;
|
key = nextBlockStateId;
|
||||||
Connection conn = LogBlock.getInstance().getConnection();
|
Connection conn = LogBlock.getInstance().getConnection();
|
||||||
try {
|
try {
|
||||||
@ -95,8 +103,12 @@ public class MaterialConverter {
|
|||||||
} else {
|
} else {
|
||||||
initializeMaterials(conn);
|
initializeMaterials(conn);
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (Exception e) {
|
||||||
LogBlock.getInstance().getLogger().log(Level.SEVERE, "Could not update lb-blockstates", e);
|
LogBlock.getInstance().getLogger().log(Level.SEVERE, "Could not update lb-blockstates", e);
|
||||||
|
reinitializeMaterialsCatchException();
|
||||||
|
if (tries == 10) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
conn.close();
|
conn.close();
|
||||||
@ -121,6 +133,21 @@ public class MaterialConverter {
|
|||||||
return materialKeyToMaterial.get(idToMaterial[materialId]);
|
return materialKeyToMaterial.get(idToMaterial[materialId]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void reinitializeMaterialsCatchException() {
|
||||||
|
Connection conn = LogBlock.getInstance().getConnection();
|
||||||
|
try {
|
||||||
|
initializeMaterials(conn);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogBlock.getInstance().getLogger().log(Level.SEVERE, "Could not reinitialize lb-materials", e);
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
conn.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// ignored
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void initializeMaterials(Connection connection) throws SQLException {
|
public static void initializeMaterials(Connection connection) throws SQLException {
|
||||||
Statement smt = connection.createStatement();
|
Statement smt = connection.createStatement();
|
||||||
ResultSet rs = smt.executeQuery("SELECT id, name FROM `lb-materials`");
|
ResultSet rs = smt.executeQuery("SELECT id, name FROM `lb-materials`");
|
||||||
|
Reference in New Issue
Block a user