Dropped IdFactory temporary object SQL table.
This commit is contained in:
@@ -20,6 +20,9 @@ import java.sql.Connection;
|
|||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@@ -57,6 +60,16 @@ public abstract class IdFactory
|
|||||||
"SELECT object_id FROM itemsonground WHERE object_id >= ? AND object_id < ?"
|
"SELECT object_id FROM itemsonground WHERE object_id >= ? AND object_id < ?"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//@formatter:off
|
||||||
|
private static final String[][] ID_EXTRACTS =
|
||||||
|
{
|
||||||
|
{"characters", "obj_Id"},
|
||||||
|
{"items", "object_id"},
|
||||||
|
{"clan_data", "clan_id"},
|
||||||
|
{"itemsonground", "object_id"}
|
||||||
|
};
|
||||||
|
//@formatter:on
|
||||||
|
|
||||||
protected boolean _initialized;
|
protected boolean _initialized;
|
||||||
|
|
||||||
public static final int FIRST_OID = 0x10000000;
|
public static final int FIRST_OID = 0x10000000;
|
||||||
@@ -166,47 +179,35 @@ public abstract class IdFactory
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int[] extractUsedObjectIDTable() throws SQLException
|
/**
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
* @throws SQLException
|
||||||
|
*/
|
||||||
|
protected final Integer[] extractUsedObjectIDTable() throws Exception
|
||||||
{
|
{
|
||||||
try (Connection con = DatabaseFactory.getConnection())
|
final List<Integer> temp = new ArrayList<>();
|
||||||
|
try (Connection con = DatabaseFactory.getConnection();
|
||||||
|
Statement s = con.createStatement())
|
||||||
{
|
{
|
||||||
// create a temporary table
|
String extractUsedObjectIdsQuery = "";
|
||||||
final Statement s = con.createStatement();
|
|
||||||
try
|
for (String[] tblClmn : ID_EXTRACTS)
|
||||||
{
|
{
|
||||||
s.executeUpdate("drop table temporaryObjectTable");
|
extractUsedObjectIdsQuery += "SELECT " + tblClmn[1] + " FROM " + tblClmn[0] + " UNION ";
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
s.executeUpdate("delete from itemsonground where object_id in (select object_id from items)");
|
|
||||||
s.executeUpdate("create table temporaryObjectTable (object_id int NOT NULL PRIMARY KEY)");
|
|
||||||
|
|
||||||
s.executeUpdate("insert into temporaryObjectTable (object_id) select obj_id from characters");
|
|
||||||
s.executeUpdate("insert into temporaryObjectTable (object_id) select object_id from items");
|
|
||||||
s.executeUpdate("insert into temporaryObjectTable (object_id) select clan_id from clan_data");
|
|
||||||
s.executeUpdate("insert into temporaryObjectTable (object_id) select object_id from itemsonground");
|
|
||||||
|
|
||||||
ResultSet result = s.executeQuery("select count(object_id) from temporaryObjectTable");
|
|
||||||
|
|
||||||
result.next();
|
|
||||||
final int size = result.getInt(1);
|
|
||||||
final int[] tmp_obj_ids = new int[size];
|
|
||||||
result.close();
|
|
||||||
|
|
||||||
result = s.executeQuery("select object_id from temporaryObjectTable ORDER BY object_id");
|
|
||||||
|
|
||||||
int idx = 0;
|
|
||||||
while (result.next())
|
|
||||||
{
|
|
||||||
tmp_obj_ids[idx++] = result.getInt(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
result.close();
|
extractUsedObjectIdsQuery = extractUsedObjectIdsQuery.substring(0, extractUsedObjectIdsQuery.length() - 7); // Remove the last " UNION "
|
||||||
s.close();
|
try (ResultSet rs = s.executeQuery(extractUsedObjectIdsQuery))
|
||||||
|
{
|
||||||
return tmp_obj_ids;
|
while (rs.next())
|
||||||
|
{
|
||||||
|
temp.add(rs.getInt(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Collections.sort(temp);
|
||||||
|
return temp.toArray(new Integer[temp.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInitialized()
|
public boolean isInitialized()
|
||||||
|
@@ -43,17 +43,19 @@ public class StackIDFactory extends IdFactory
|
|||||||
|
|
||||||
try (Connection con = DatabaseFactory.getConnection())
|
try (Connection con = DatabaseFactory.getConnection())
|
||||||
{
|
{
|
||||||
final int[] tmpObjIds = extractUsedObjectIDTable();
|
// con.createStatement().execute("drop table if exists tmp_obj_id");
|
||||||
|
|
||||||
|
final Integer[] tmpObjIds = extractUsedObjectIDTable();
|
||||||
if (tmpObjIds.length > 0)
|
if (tmpObjIds.length > 0)
|
||||||
{
|
{
|
||||||
_curOID = tmpObjIds[tmpObjIds.length - 1];
|
_curOID = tmpObjIds[tmpObjIds.length - 1];
|
||||||
}
|
}
|
||||||
LOGGER.info("Max Id = " + _curOID);
|
LOGGER.info("Max Id = " + _curOID);
|
||||||
|
|
||||||
int N = tmpObjIds.length;
|
int n = tmpObjIds.length;
|
||||||
for (int idx = 0; idx < N; idx++)
|
for (int idx = 0; idx < n; idx++)
|
||||||
{
|
{
|
||||||
N = insertUntil(tmpObjIds, idx, N, con);
|
n = insertUntil(tmpObjIds, idx, n, con);
|
||||||
}
|
}
|
||||||
|
|
||||||
_curOID++;
|
_curOID++;
|
||||||
@@ -66,7 +68,7 @@ public class StackIDFactory extends IdFactory
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int insertUntil(int[] tmpObjIds, int idx, int n, Connection con) throws SQLException
|
private int insertUntil(Integer[] tmpObjIds, int idx, int n, Connection con) throws SQLException
|
||||||
{
|
{
|
||||||
final int id = tmpObjIds[idx];
|
final int id = tmpObjIds[idx];
|
||||||
if (id == _tempOID)
|
if (id == _tempOID)
|
||||||
|
Reference in New Issue
Block a user