Refactored DatabaseFactory.

This commit is contained in:
MobiusDev
2016-01-11 21:31:45 +00:00
parent d288d505a9
commit 2684901232
140 changed files with 668 additions and 955 deletions

View File

@ -45,7 +45,7 @@ import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Level;
import com.l2jmobius.Config;
import com.l2jmobius.commons.database.pool.impl.ConnectionFactory;
import com.l2jmobius.commons.database.DatabaseFactory;
import com.l2jmobius.gameserver.GameTimeController;
import com.l2jmobius.gameserver.GeoData;
import com.l2jmobius.gameserver.ItemsAutoDestroy;
@ -1397,7 +1397,7 @@ public final class L2PcInstance extends L2Playable
private void insertNewRecipeData(int recipeId, boolean isDwarf)
{
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement("INSERT INTO character_recipebook (charId, id, classIndex, type) values(?,?,?,?)"))
{
ps.setInt(1, getObjectId());
@ -1414,7 +1414,7 @@ public final class L2PcInstance extends L2Playable
private void deleteRecipeData(int recipeId, boolean isDwarf)
{
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement("DELETE FROM character_recipebook WHERE charId=? AND id=? AND classIndex=?"))
{
ps.setInt(1, getObjectId());
@ -7052,7 +7052,7 @@ public final class L2PcInstance extends L2Playable
*/
public void updateOnlineStatus()
{
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement("UPDATE characters SET online=?, lastAccess=? WHERE charId=?"))
{
ps.setInt(1, isOnlineInt());
@ -7072,7 +7072,7 @@ public final class L2PcInstance extends L2Playable
*/
private boolean createDb()
{
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement(INSERT_CHARACTER))
{
ps.setString(1, _accountName);
@ -7136,7 +7136,7 @@ public final class L2PcInstance extends L2Playable
double currentCp = 0;
double currentHp = 0;
double currentMp = 0;
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement(RESTORE_CHARACTER))
{
// Retrieve the L2PcInstance from the characters table of the database
@ -7470,7 +7470,7 @@ public final class L2PcInstance extends L2Playable
*/
private static boolean restoreSubClassData(L2PcInstance player)
{
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement(RESTORE_CHAR_SUBCLASSES))
{
ps.setInt(1, player.getObjectId());
@ -7553,7 +7553,7 @@ public final class L2PcInstance extends L2Playable
private void restoreRecipeBook(boolean loadCommon)
{
final String sql = loadCommon ? "SELECT id, type, classIndex FROM character_recipebook WHERE charId=?" : "SELECT id FROM character_recipebook WHERE charId=? AND classIndex=? AND type = 1";
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement(sql))
{
ps.setInt(1, getObjectId());
@ -7606,7 +7606,7 @@ public final class L2PcInstance extends L2Playable
private void loadPremiumItemList()
{
final String sql = "SELECT itemNum, itemId, itemCount, itemSender FROM character_premium_items WHERE charId=?";
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement(sql))
{
ps.setInt(1, getObjectId());
@ -7630,7 +7630,7 @@ public final class L2PcInstance extends L2Playable
public void updatePremiumItem(int itemNum, long newcount)
{
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement("UPDATE character_premium_items SET itemCount=? WHERE charId=? AND itemNum=? "))
{
ps.setLong(1, newcount);
@ -7646,7 +7646,7 @@ public final class L2PcInstance extends L2Playable
public void deletePremiumItem(int itemNum)
{
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement("DELETE FROM character_premium_items WHERE charId=? AND itemNum=? "))
{
ps.setInt(1, getObjectId());
@ -7705,7 +7705,7 @@ public final class L2PcInstance extends L2Playable
final long exp = getStat().getBaseExp();
final int level = getStat().getBaseLevel();
final long sp = getStat().getBaseSp();
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement(UPDATE_CHARACTER))
{
ps.setInt(1, level);
@ -7793,7 +7793,7 @@ public final class L2PcInstance extends L2Playable
}
// TODO(Zoey76): Refactor this to use batch.
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement(UPDATE_CHAR_SUBCLASS))
{
for (SubClass subClass : getSubClasses().values())
@ -7824,7 +7824,7 @@ public final class L2PcInstance extends L2Playable
return;
}
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement delete = con.prepareStatement(DELETE_SKILL_SAVE);
PreparedStatement statement = con.prepareStatement(ADD_SKILL_SAVE);)
{
@ -7927,7 +7927,7 @@ public final class L2PcInstance extends L2Playable
private void storeItemReuseDelay()
{
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps1 = con.prepareStatement(DELETE_ITEM_REUSE_SAVE);
PreparedStatement ps2 = con.prepareStatement(ADD_ITEM_REUSE_SAVE))
{
@ -8042,7 +8042,7 @@ public final class L2PcInstance extends L2Playable
final Skill oldSkill = super.removeSkill(skill, true);
if (oldSkill != null)
{
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement(DELETE_SKILL_FROM_CHAR))
{
// Remove or update a L2PcInstance skill from the character_skills table of the database
@ -8085,7 +8085,7 @@ public final class L2PcInstance extends L2Playable
private void storeSkill(Skill newSkill, Skill oldSkill, int newClassIndex)
{
final int classIndex = (newClassIndex > -1) ? newClassIndex : _classIndex;
try (Connection con = ConnectionFactory.getInstance().getConnection())
try (Connection con = DatabaseFactory.getInstance().getConnection())
{
if ((oldSkill != null) && (newSkill != null))
{
@ -8133,7 +8133,7 @@ public final class L2PcInstance extends L2Playable
}
final int classIndex = (newClassIndex > -1) ? newClassIndex : _classIndex;
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement(ADD_NEW_SKILLS))
{
con.setAutoCommit(false);
@ -8159,7 +8159,7 @@ public final class L2PcInstance extends L2Playable
*/
private void restoreSkills()
{
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement(RESTORE_SKILLS_FOR_CHAR))
{
// Retrieve all skills of this L2PcInstance from the database
@ -8210,7 +8210,7 @@ public final class L2PcInstance extends L2Playable
@Override
public void restoreEffects()
{
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement(RESTORE_SKILL_SAVE))
{
ps.setInt(1, getObjectId());
@ -8267,7 +8267,7 @@ public final class L2PcInstance extends L2Playable
*/
private void restoreItemReuse()
{
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement(RESTORE_ITEM_REUSE_SAVE);
PreparedStatement delete = con.prepareStatement(DELETE_ITEM_REUSE_SAVE);)
{
@ -8338,7 +8338,7 @@ public final class L2PcInstance extends L2Playable
_henna[i] = null;
}
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement(RESTORE_CHAR_HENNAS))
{
ps.setInt(1, getObjectId());
@ -8426,7 +8426,7 @@ public final class L2PcInstance extends L2Playable
_henna[slot] = null;
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement(DELETE_CHAR_HENNA))
{
ps.setInt(1, getObjectId());
@ -8500,7 +8500,7 @@ public final class L2PcInstance extends L2Playable
}
}
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement(ADD_CHAR_HENNA))
{
ps.setInt(1, getObjectId());
@ -10534,7 +10534,7 @@ public final class L2PcInstance extends L2Playable
newClass.setLevel(Config.BASE_DUALCLASS_LEVEL);
}
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement(ADD_CHAR_SUBCLASS))
{
// Store the basic info about this new sub-class.
@ -10601,7 +10601,7 @@ public final class L2PcInstance extends L2Playable
try
{
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement deleteHennas = con.prepareStatement(DELETE_CHAR_HENNAS);
PreparedStatement deleteShortcuts = con.prepareStatement(DELETE_CHAR_SHORTCUTS);
PreparedStatement deleteSkillReuse = con.prepareStatement(DELETE_SKILL_SAVE);
@ -13298,7 +13298,7 @@ public final class L2PcInstance extends L2Playable
if ((_controlItemId != 0) && (petId != 0))
{
final String req = "UPDATE pets SET fed=? WHERE item_obj_id = ?";
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement(req))
{
ps.setInt(1, getCurrentFeed());
@ -13450,7 +13450,7 @@ public final class L2PcInstance extends L2Playable
bookmark.setTag(tag);
bookmark.setName(name);
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement(UPDATE_TP_BOOKMARK))
{
ps.setInt(1, icon);
@ -13473,7 +13473,7 @@ public final class L2PcInstance extends L2Playable
{
if (_tpbookmarks.remove(id) != null)
{
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement(DELETE_TP_BOOKMARK))
{
ps.setInt(1, getObjectId());
@ -13616,7 +13616,7 @@ public final class L2PcInstance extends L2Playable
sm.addItemName(20033);
sendPacket(sm);
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement(INSERT_TP_BOOKMARK))
{
ps.setInt(1, getObjectId());
@ -13638,7 +13638,7 @@ public final class L2PcInstance extends L2Playable
public void restoreTeleportBookmark()
{
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement(RESTORE_TP_BOOKMARK))
{
ps.setInt(1, getObjectId());
@ -13869,7 +13869,7 @@ public final class L2PcInstance extends L2Playable
public void updateMemos()
{
final String sqlQuery = "UPDATE character_friends SET memo=? WHERE charId=? AND friendId=? AND relation=0";
try (Connection con = ConnectionFactory.getInstance().getConnection())
try (Connection con = DatabaseFactory.getInstance().getConnection())
{
for (int target : _updateMemos)
{
@ -13901,7 +13901,7 @@ public final class L2PcInstance extends L2Playable
_friendList.clear();
final String sqlQuery = "SELECT friendId, memo FROM character_friends WHERE charId=? AND relation=0";
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement(sqlQuery))
{
ps.setInt(1, getObjectId());
@ -13949,7 +13949,7 @@ public final class L2PcInstance extends L2Playable
final Friend friend = _friendList.get(friendId);
int bClassId = 0;
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement("SELECT * FROM characters WHERE charId=?");)
{
ps.setInt(1, friendId);
@ -13974,7 +13974,7 @@ public final class L2PcInstance extends L2Playable
}
if (friend.getClassId() != bClassId)
{
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement("SELECT level FROM character_subclasses WHERE charId=? AND class_id=?");)
{
ps.setInt(1, friendId);
@ -13997,7 +13997,7 @@ public final class L2PcInstance extends L2Playable
}
if (friend.getClanId() != 0)
{
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement("SELECT * FROM clan_data WHERE clan_id=?");)
{
ps.setInt(1, friend.getClanId());
@ -14088,7 +14088,7 @@ public final class L2PcInstance extends L2Playable
{
if (hasManufactureShop())
{
try (Connection con = ConnectionFactory.getInstance().getConnection())
try (Connection con = DatabaseFactory.getInstance().getConnection())
{
try (PreparedStatement st = con.prepareStatement(DELETE_CHAR_RECIPE_SHOP))
{
@ -14126,7 +14126,7 @@ public final class L2PcInstance extends L2Playable
_manufactureItems.clear();
}
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement(RESTORE_CHAR_RECIPE_SHOP))
{
ps.setInt(1, getObjectId());
@ -14579,7 +14579,7 @@ public final class L2PcInstance extends L2Playable
*/
private void restorePetInventoryItems()
{
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement("SELECT object_id FROM `items` WHERE `owner_id`=? AND (`loc`='PET' OR `loc`='PET_EQUIP') LIMIT 1;"))
{
ps.setInt(1, getObjectId());
@ -14619,7 +14619,7 @@ public final class L2PcInstance extends L2Playable
*/
private void loadRecommendations()
{
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement("SELECT rec_have,rec_left,time_left FROM character_reco_bonus WHERE charId=? LIMIT 1"))
{
ps.setInt(1, getObjectId());
@ -14643,7 +14643,7 @@ public final class L2PcInstance extends L2Playable
*/
public void storeRecommendations()
{
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement("REPLACE INTO character_reco_bonus (charId,rec_have,rec_left,time_left) VALUES (?,?,?,?)"))
{
ps.setInt(1, getObjectId());
@ -14703,7 +14703,7 @@ public final class L2PcInstance extends L2Playable
private static void restorePremiumSystemData(L2PcInstance player, String account)
{
boolean success = false;
try (Connection con = ConnectionFactory.getInstance().getConnection())
try (Connection con = DatabaseFactory.getInstance().getConnection())
{
final PreparedStatement ps = con.prepareStatement(RESTORE_PREMIUMSERVICE);
ps.setString(1, account);

View File

@ -26,7 +26,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import com.l2jmobius.Config;
import com.l2jmobius.commons.database.pool.impl.ConnectionFactory;
import com.l2jmobius.commons.database.DatabaseFactory;
import com.l2jmobius.gameserver.ThreadPoolManager;
import com.l2jmobius.gameserver.ai.CtrlIntention;
import com.l2jmobius.gameserver.data.sql.impl.CharSummonTable;
@ -793,7 +793,7 @@ public class L2PetInstance extends L2Summon
}
// pet control item no longer exists, delete the pet from the db
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement("DELETE FROM pets WHERE item_obj_id = ?"))
{
ps.setInt(1, getControlObjectId());
@ -851,7 +851,7 @@ public class L2PetInstance extends L2Summon
private static L2PetInstance restore(L2ItemInstance control, L2NpcTemplate template, L2PcInstance owner)
{
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement("SELECT item_obj_id, name, level, curHp, curMp, exp, sp, fed FROM pets WHERE item_obj_id=?"))
{
L2PetInstance pet;
@ -952,7 +952,7 @@ public class L2PetInstance extends L2Summon
req = "UPDATE pets SET name=?,level=?,curHp=?,curMp=?,exp=?,sp=?,fed=?,ownerId=?,restore=? " + "WHERE item_obj_id = ?";
}
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement(req))
{
ps.setString(1, getName());
@ -1002,7 +1002,7 @@ public class L2PetInstance extends L2Summon
// Clear list for overwrite
SummonEffectsTable.getInstance().clearPetEffects(getControlObjectId());
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps1 = con.prepareStatement(DELETE_SKILL_SAVE);
PreparedStatement ps2 = con.prepareStatement(ADD_SKILL_SAVE))
{
@ -1069,7 +1069,7 @@ public class L2PetInstance extends L2Summon
@Override
public void restoreEffects()
{
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps1 = con.prepareStatement(RESTORE_SKILL_SAVE);
PreparedStatement ps2 = con.prepareStatement(DELETE_SKILL_SAVE))
{

View File

@ -26,7 +26,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import com.l2jmobius.Config;
import com.l2jmobius.commons.database.pool.impl.ConnectionFactory;
import com.l2jmobius.commons.database.DatabaseFactory;
import com.l2jmobius.gameserver.ThreadPoolManager;
import com.l2jmobius.gameserver.ai.CtrlIntention;
import com.l2jmobius.gameserver.data.sql.impl.CharSummonTable;
@ -224,7 +224,7 @@ public class L2ServitorInstance extends L2Summon implements Runnable
// Clear list for overwrite
SummonEffectsTable.getInstance().clearServitorEffects(getOwner(), getReferenceSkill());
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement(DELETE_SKILL_SAVE))
{
// Delete all current stored effects for summon to avoid dupe
@ -302,7 +302,7 @@ public class L2ServitorInstance extends L2Summon implements Runnable
return;
}
try (Connection con = ConnectionFactory.getInstance().getConnection())
try (Connection con = DatabaseFactory.getInstance().getConnection())
{
if (!SummonEffectsTable.getInstance().containsSkill(getOwner(), getReferenceSkill()))
{