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

@@ -34,7 +34,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.communitybbs.BB.Forum;
import com.l2jmobius.gameserver.communitybbs.Manager.ForumsBBSManager;
import com.l2jmobius.gameserver.data.sql.impl.CharNameTable;
@@ -246,7 +246,7 @@ public class L2Clan implements IIdentifiable, INamable
}
else
{
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement("UPDATE characters SET clan_privs = ? WHERE charId = ?"))
{
ps.setInt(1, 0);
@@ -286,7 +286,7 @@ public class L2Clan implements IIdentifiable, INamable
}
else
{
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement("UPDATE characters SET clan_privs = ? WHERE charId = ?"))
{
ps.setInt(1, EnumIntBitmask.getAllBitmask(ClanPrivilege.class));
@@ -881,7 +881,7 @@ public class L2Clan implements IIdentifiable, INamable
*/
public void updateBloodAllianceCountInDB()
{
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement("UPDATE clan_data SET blood_alliance_count=? WHERE clan_id=?"))
{
ps.setInt(1, getBloodAllianceCount());
@@ -925,7 +925,7 @@ public class L2Clan implements IIdentifiable, INamable
*/
public void updateBloodOathCountInDB()
{
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement("UPDATE clan_data SET blood_oath_count=? WHERE clan_id=?"))
{
ps.setInt(1, getBloodOathCount());
@@ -943,7 +943,7 @@ public class L2Clan implements IIdentifiable, INamable
*/
public void updateClanScoreInDB()
{
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement("UPDATE clan_data SET reputation_score=? WHERE clan_id=?"))
{
ps.setInt(1, getReputationScore());
@@ -972,7 +972,7 @@ public class L2Clan implements IIdentifiable, INamable
*/
public void updateClanInDB()
{
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement("UPDATE clan_data SET leader_id=?,ally_id=?,ally_name=?,reputation_score=?,ally_penalty_expiry_time=?,ally_penalty_type=?,char_penalty_expiry_time=?,dissolving_expiry_time=?,new_leader_id=? WHERE clan_id=?"))
{
ps.setInt(1, getLeaderId());
@@ -1014,7 +1014,7 @@ public class L2Clan implements IIdentifiable, INamable
*/
public void store()
{
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement(INSERT_CLAN_DATA))
{
ps.setInt(1, getId());
@@ -1050,7 +1050,7 @@ public class L2Clan implements IIdentifiable, INamable
*/
private void removeMemberInDatabase(int playerId, long clanJoinExpiryTime, long clanCreateExpiryTime)
{
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps1 = con.prepareStatement("UPDATE characters SET clanid=0, title=?, clan_join_expiry_time=?, clan_create_expiry_time=?, clan_privs=0, wantspeace=0, subpledge=0, lvl_joined_academy=0, apprentice=0, sponsor=0 WHERE charId=?");
PreparedStatement ps2 = con.prepareStatement("UPDATE characters SET apprentice=0 WHERE apprentice=?");
PreparedStatement ps3 = con.prepareStatement("UPDATE characters SET sponsor=0 WHERE sponsor=?"))
@@ -1076,7 +1076,7 @@ public class L2Clan implements IIdentifiable, INamable
private void restore()
{
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement(SELECT_CLAN_DATA))
{
ps.setInt(1, getId());
@@ -1156,7 +1156,7 @@ public class L2Clan implements IIdentifiable, INamable
private void restoreNotice()
{
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement("SELECT enabled,notice FROM clan_notices WHERE clan_id=?"))
{
ps.setInt(1, getId());
@@ -1187,7 +1187,7 @@ public class L2Clan implements IIdentifiable, INamable
notice = notice.substring(0, MAX_NOTICE_LENGTH - 1);
}
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement("INSERT INTO clan_notices (clan_id,notice,enabled) values (?,?,?) ON DUPLICATE KEY UPDATE notice=?,enabled=?"))
{
ps.setInt(1, getId());
@@ -1246,7 +1246,7 @@ public class L2Clan implements IIdentifiable, INamable
private void restoreSkills()
{
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement("SELECT skill_id,skill_level,sub_pledge_id FROM clan_skills WHERE clan_id=?"))
{
// Retrieve all skills of this L2PcInstance from the database
@@ -1369,7 +1369,7 @@ public class L2Clan implements IIdentifiable, INamable
}
}
try (Connection con = ConnectionFactory.getInstance().getConnection())
try (Connection con = DatabaseFactory.getInstance().getConnection())
{
if (oldSkill != null)
{
@@ -1805,7 +1805,7 @@ public class L2Clan implements IIdentifiable, INamable
private void restoreSubPledges()
{
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement("SELECT sub_pledge_id,name,leader_id FROM clan_subpledges WHERE clan_id=?"))
{
// Retrieve all subpledges of this clan from the database
@@ -1905,7 +1905,7 @@ public class L2Clan implements IIdentifiable, INamable
return null;
}
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement("INSERT INTO clan_subpledges (clan_id,sub_pledge_id,name,leader_id) values (?,?,?,?)"))
{
ps.setInt(1, getId());
@@ -1993,7 +1993,7 @@ public class L2Clan implements IIdentifiable, INamable
public void updateSubPledgeInDB(int pledgeType)
{
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement("UPDATE clan_subpledges SET leader_id=?, name=? WHERE clan_id=? AND sub_pledge_id=?"))
{
ps.setInt(1, getSubPledge(pledgeType).getLeaderId());
@@ -2014,7 +2014,7 @@ public class L2Clan implements IIdentifiable, INamable
private void restoreRankPrivs()
{
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement("SELECT privs,rank,party FROM clan_privs WHERE clan_id=?"))
{
// Retrieve all skills of this L2PcInstance from the database
@@ -2067,7 +2067,7 @@ public class L2Clan implements IIdentifiable, INamable
{
_privs.get(rank).setPrivs(privs);
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement("INSERT INTO clan_privs (clan_id,rank,party,privs) VALUES (?,?,?,?) ON DUPLICATE KEY UPDATE privs = ?"))
{
// Retrieve all skills of this L2PcInstance from the database
@@ -2103,7 +2103,7 @@ public class L2Clan implements IIdentifiable, INamable
{
_privs.put(rank, new RankPrivs(rank, privs));
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement("INSERT INTO clan_privs (clan_id,rank,party,privs) VALUES (?,?,?,?)"))
{
// Retrieve all skills of this L2PcInstance from the database
@@ -2241,7 +2241,7 @@ public class L2Clan implements IIdentifiable, INamable
if (storeInDb)
{
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement("UPDATE clan_data SET auction_bid_at=? WHERE clan_id=?"))
{
ps.setInt(1, id);
@@ -2802,7 +2802,7 @@ public class L2Clan implements IIdentifiable, INamable
public void changeLevel(int level)
{
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement("UPDATE clan_data SET clan_level = ? WHERE clan_id = ?"))
{
ps.setInt(1, level);
@@ -2848,7 +2848,7 @@ public class L2Clan implements IIdentifiable, INamable
setCrestId(crestId);
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement("UPDATE clan_data SET crest_id = ? WHERE clan_id = ?"))
{
ps.setInt(1, crestId);
@@ -2885,7 +2885,7 @@ public class L2Clan implements IIdentifiable, INamable
allyId = getAllyId();
}
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement(sqlStatement))
{
ps.setInt(1, crestId);
@@ -2931,7 +2931,7 @@ public class L2Clan implements IIdentifiable, INamable
setCrestLargeId(crestId);
try (Connection con = ConnectionFactory.getInstance().getConnection();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement("UPDATE clan_data SET crest_large_id = ? WHERE clan_id = ?"))
{
ps.setInt(1, crestId);