Refactored DatabaseFactory.
This commit is contained in:
		
							
								
								
									
										6
									
								
								trunk/dist/game/config/General.ini
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										6
									
								
								trunk/dist/game/config/General.ini
									
									
									
									
										vendored
									
									
								
							| @@ -256,12 +256,6 @@ ListOfProtectedItems = 0 | ||||
| # Default: True | ||||
| DatabaseCleanUp = True | ||||
|  | ||||
| # The time before a database connection closes (in milliseconds) | ||||
| # If a query takes longer to execute than the time defined here, the server will throw "Unclosed Connection!" error. | ||||
| # If you get often this error message, try increasing this. | ||||
| # Default: 60000ms | ||||
| ConnectionCloseTime = 20000 | ||||
|  | ||||
| # This is the interval (in minutes), that the gameserver will update a players information such as location. | ||||
| # The higher you set this number, there will be less character information saving so you will have less accessessing of the database and your hard drive(s). | ||||
| # The lower you set this number, there will be more frequent character information saving so you will have more access to the database and your hard drive(s). | ||||
|   | ||||
							
								
								
									
										19
									
								
								trunk/dist/game/config/Server.ini
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										19
									
								
								trunk/dist/game/config/Server.ini
									
									
									
									
										vendored
									
									
								
							| @@ -42,27 +42,32 @@ GameserverPort = 7777 | ||||
| # Driver = org.hsqldb.jdbcDriver | ||||
| # Driver = com.microsoft.sqlserver.jdbc.SQLServerDriver | ||||
| Driver = com.mysql.jdbc.Driver | ||||
|  | ||||
| # Database URL | ||||
| # URL = jdbc:mysql://localhost/l2jmobius (default) | ||||
| # URL = jdbc:hsqldb:hsql://localhost/l2jmobius | ||||
| # URL = jdbc:sqlserver://localhost/database = l2jgs/user = sa/password =  | ||||
| # URL = jdbc:sqlserver://localhost/database = l2jmobius/user = sa/password =  | ||||
| URL = jdbc:mysql://localhost/l2jmobius?useUnicode=true&characterEncoding=utf-8 | ||||
|  | ||||
| # Database user info (default is "root" but it's not recommended) | ||||
| Login = root | ||||
|  | ||||
| # Database connection password | ||||
| Password =  | ||||
|  | ||||
| # Database Connection Pool | ||||
| # Default: C3P0 | ||||
| # Available: C3P0, HikariCP, BoneCP | ||||
| ConnectionPool = C3P0 | ||||
|  | ||||
| # Default: 500 | ||||
| MaximumDbConnections = 500 | ||||
|  | ||||
| # Default: 0 | ||||
| MaximumDbIdleTime = 0 | ||||
|  | ||||
| # The time before a database connection closes (in milliseconds) | ||||
| # If a query takes longer to execute than the time defined here, the server will throw "Unclosed Connection!" error. | ||||
| # If you get often this error message, try increasing this. | ||||
| # Default: 60000ms | ||||
| ConnectionCloseTime = 60000 | ||||
|  | ||||
|  | ||||
| # --------------------------------------------------------------------------- | ||||
| # Misc Server Settings | ||||
| # --------------------------------------------------------------------------- | ||||
| @@ -133,4 +138,4 @@ ClanNameTemplate = .* | ||||
|  | ||||
| # Maximum number of characters per account. | ||||
| # Default: 7 (client limit) | ||||
| CharMaxNumber = 7 | ||||
| CharMaxNumber = 7 | ||||
|   | ||||
| @@ -30,7 +30,7 @@ import java.util.Map; | ||||
| import java.util.concurrent.ScheduledFuture; | ||||
|  | ||||
| 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.cache.HtmCache; | ||||
| import com.l2jmobius.gameserver.data.sql.impl.ClanTable; | ||||
| @@ -844,7 +844,7 @@ public final class RainbowSpringsChateau extends ClanHallSiegeEngine | ||||
| 	 | ||||
| 	private static void removeAttacker(int clanId) | ||||
| 	{ | ||||
| 		try (Connection con = ConnectionFactory.getInstance().getConnection(); | ||||
| 		try (Connection con = DatabaseFactory.getInstance().getConnection(); | ||||
| 			PreparedStatement ps = con.prepareStatement("DELETE FROM rainbowsprings_attacker_list WHERE clanId = ?")) | ||||
| 		{ | ||||
| 			ps.setInt(1, clanId); | ||||
| @@ -858,7 +858,7 @@ public final class RainbowSpringsChateau extends ClanHallSiegeEngine | ||||
| 	 | ||||
| 	private static void addAttacker(int clanId, long count) | ||||
| 	{ | ||||
| 		try (Connection con = ConnectionFactory.getInstance().getConnection(); | ||||
| 		try (Connection con = DatabaseFactory.getInstance().getConnection(); | ||||
| 			PreparedStatement ps = con.prepareStatement("INSERT INTO rainbowsprings_attacker_list VALUES (?,?)")) | ||||
| 		{ | ||||
| 			ps.setInt(1, clanId); | ||||
| @@ -874,7 +874,7 @@ public final class RainbowSpringsChateau extends ClanHallSiegeEngine | ||||
| 	@Override | ||||
| 	public void loadAttackers() | ||||
| 	{ | ||||
| 		try (Connection con = ConnectionFactory.getInstance().getConnection(); | ||||
| 		try (Connection con = DatabaseFactory.getInstance().getConnection(); | ||||
| 			Statement s = con.createStatement(); | ||||
| 			ResultSet rset = s.executeQuery("SELECT * FROM rainbowsprings_attacker_list")) | ||||
| 		{ | ||||
|   | ||||
| @@ -25,7 +25,7 @@ import java.util.List; | ||||
| import java.util.Map; | ||||
| import java.util.Map.Entry; | ||||
|  | ||||
| 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.ai.L2SpecialSiegeGuardAI; | ||||
| @@ -760,7 +760,7 @@ public abstract class FlagWar extends ClanHallSiegeEngine | ||||
| 	@Override | ||||
| 	public final void loadAttackers() | ||||
| 	{ | ||||
| 		try (Connection con = ConnectionFactory.getInstance().getConnection(); | ||||
| 		try (Connection con = DatabaseFactory.getInstance().getConnection(); | ||||
| 			PreparedStatement ps = con.prepareStatement(SQL_LOAD_ATTACKERS)) | ||||
| 		{ | ||||
| 			ps.setInt(1, _hall.getId()); | ||||
| @@ -800,7 +800,7 @@ public abstract class FlagWar extends ClanHallSiegeEngine | ||||
| 			return; | ||||
| 		} | ||||
| 		 | ||||
| 		try (Connection con = ConnectionFactory.getInstance().getConnection(); | ||||
| 		try (Connection con = DatabaseFactory.getInstance().getConnection(); | ||||
| 			PreparedStatement ps = con.prepareStatement(SQL_LOAD_MEMEBERS)) | ||||
| 		{ | ||||
| 			ps.setInt(1, clanId); | ||||
| @@ -820,7 +820,7 @@ public abstract class FlagWar extends ClanHallSiegeEngine | ||||
| 	 | ||||
| 	private final void saveClan(int clanId, int flag) | ||||
| 	{ | ||||
| 		try (Connection con = ConnectionFactory.getInstance().getConnection(); | ||||
| 		try (Connection con = DatabaseFactory.getInstance().getConnection(); | ||||
| 			PreparedStatement ps = con.prepareStatement(SQL_SAVE_CLAN)) | ||||
| 		{ | ||||
| 			ps.setInt(1, _hall.getId()); | ||||
| @@ -837,7 +837,7 @@ public abstract class FlagWar extends ClanHallSiegeEngine | ||||
| 	 | ||||
| 	private final void saveNpc(int npc, int clanId) | ||||
| 	{ | ||||
| 		try (Connection con = ConnectionFactory.getInstance().getConnection(); | ||||
| 		try (Connection con = DatabaseFactory.getInstance().getConnection(); | ||||
| 			PreparedStatement ps = con.prepareStatement(SQL_SAVE_NPC)) | ||||
| 		{ | ||||
| 			ps.setInt(1, npc); | ||||
| @@ -852,7 +852,7 @@ public abstract class FlagWar extends ClanHallSiegeEngine | ||||
| 	 | ||||
| 	private final void saveMember(int clanId, int objectId) | ||||
| 	{ | ||||
| 		try (Connection con = ConnectionFactory.getInstance().getConnection(); | ||||
| 		try (Connection con = DatabaseFactory.getInstance().getConnection(); | ||||
| 			PreparedStatement ps = con.prepareStatement(SQL_SAVE_ATTACKER)) | ||||
| 		{ | ||||
| 			ps.setInt(1, _hall.getId()); | ||||
| @@ -868,7 +868,7 @@ public abstract class FlagWar extends ClanHallSiegeEngine | ||||
| 	 | ||||
| 	private void clearTables() | ||||
| 	{ | ||||
| 		try (Connection con = ConnectionFactory.getInstance().getConnection(); | ||||
| 		try (Connection con = DatabaseFactory.getInstance().getConnection(); | ||||
| 			PreparedStatement ps1 = con.prepareStatement(SQL_CLEAR_CLAN); | ||||
| 			PreparedStatement ps2 = con.prepareStatement(SQL_CLEAR_CLAN_ATTACKERS)) | ||||
| 		{ | ||||
|   | ||||
| @@ -21,7 +21,7 @@ import java.sql.PreparedStatement; | ||||
| import java.sql.SQLException; | ||||
|  | ||||
| import com.l2jmobius.Config; | ||||
| import com.l2jmobius.commons.database.pool.impl.ConnectionFactory; | ||||
| import com.l2jmobius.commons.database.DatabaseFactory; | ||||
| import com.l2jmobius.gameserver.data.xml.impl.AdminData; | ||||
| import com.l2jmobius.gameserver.handler.IAdminCommandHandler; | ||||
| import com.l2jmobius.gameserver.model.L2AccessLevel; | ||||
| @@ -73,7 +73,7 @@ public final class AdminChangeAccessLevel implements IAdminCommandHandler | ||||
| 			} | ||||
| 			else | ||||
| 			{ | ||||
| 				try (Connection con = ConnectionFactory.getInstance().getConnection(); | ||||
| 				try (Connection con = DatabaseFactory.getInstance().getConnection(); | ||||
| 					PreparedStatement ps = con.prepareStatement("UPDATE characters SET accesslevel=? WHERE char_name=?")) | ||||
| 				{ | ||||
| 					ps.setInt(1, lvl); | ||||
|   | ||||
| @@ -28,7 +28,7 @@ import java.util.StringTokenizer; | ||||
| 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.data.sql.impl.CharNameTable; | ||||
| import com.l2jmobius.gameserver.data.xml.impl.ClassListData; | ||||
| import com.l2jmobius.gameserver.data.xml.impl.SkillTreesData; | ||||
| @@ -576,7 +576,7 @@ public class AdminEditChar implements IAdminCommandHandler | ||||
| 				if (player == null) | ||||
| 				{ | ||||
| 					final String updateQuery = "UPDATE characters SET " + (changeCreateExpiryTime ? "clan_create_expiry_time" : "clan_join_expiry_time") + " WHERE char_name=? LIMIT 1"; | ||||
| 					try (Connection con = ConnectionFactory.getInstance().getConnection(); | ||||
| 					try (Connection con = DatabaseFactory.getInstance().getConnection(); | ||||
| 						PreparedStatement ps = con.prepareStatement(updateQuery)) | ||||
| 					{ | ||||
| 						ps.setString(1, playerName); | ||||
|   | ||||
| @@ -21,7 +21,7 @@ import java.sql.PreparedStatement; | ||||
| import java.util.logging.Level; | ||||
| import java.util.logging.Logger; | ||||
|  | ||||
| import com.l2jmobius.commons.database.pool.impl.ConnectionFactory; | ||||
| import com.l2jmobius.commons.database.DatabaseFactory; | ||||
| import com.l2jmobius.gameserver.data.sql.impl.CharNameTable; | ||||
| import com.l2jmobius.gameserver.handler.IAdminCommandHandler; | ||||
| import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance; | ||||
| @@ -63,7 +63,7 @@ public class AdminRepairChar implements IAdminCommandHandler | ||||
| 		 | ||||
| 		final String playerName = parts[1]; | ||||
| 		final String cmd = "UPDATE characters SET x=-84318, y=244579, z=-3730 WHERE char_name=?"; | ||||
| 		try (Connection con = ConnectionFactory.getInstance().getConnection()) | ||||
| 		try (Connection con = DatabaseFactory.getInstance().getConnection()) | ||||
| 		{ | ||||
| 			try (PreparedStatement ps = con.prepareStatement(cmd)) | ||||
| 			{ | ||||
|   | ||||
| @@ -21,7 +21,7 @@ import java.sql.PreparedStatement; | ||||
| import java.sql.ResultSet; | ||||
| import java.util.logging.Logger; | ||||
|  | ||||
| import com.l2jmobius.commons.database.pool.impl.ConnectionFactory; | ||||
| import com.l2jmobius.commons.database.DatabaseFactory; | ||||
| import com.l2jmobius.gameserver.handler.IAdminCommandHandler; | ||||
| import com.l2jmobius.gameserver.instancemanager.QuestManager; | ||||
| import com.l2jmobius.gameserver.model.L2Object; | ||||
| @@ -173,7 +173,7 @@ public class AdminShowQuests implements IAdminCommandHandler | ||||
| 	private static void showQuestMenu(L2PcInstance target, L2PcInstance actor, String[] val) | ||||
| 	{ | ||||
| 		// TODO(Zoey76): Refactor this into smaller methods and separate database access logic from HTML creation. | ||||
| 		try (Connection con = ConnectionFactory.getInstance().getConnection()) | ||||
| 		try (Connection con = DatabaseFactory.getInstance().getConnection()) | ||||
| 		{ | ||||
| 			ResultSet rs; | ||||
| 			PreparedStatement req; | ||||
|   | ||||
| @@ -24,7 +24,7 @@ import java.util.StringTokenizer; | ||||
| 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.ai.CtrlIntention; | ||||
| import com.l2jmobius.gameserver.datatables.SpawnTable; | ||||
| import com.l2jmobius.gameserver.handler.IAdminCommandHandler; | ||||
| @@ -525,7 +525,7 @@ public class AdminTeleport implements IAdminCommandHandler | ||||
| 		final int x = activeChar.getX(); | ||||
| 		final int y = activeChar.getY(); | ||||
| 		final int z = activeChar.getZ(); | ||||
| 		try (Connection con = ConnectionFactory.getInstance().getConnection(); | ||||
| 		try (Connection con = DatabaseFactory.getInstance().getConnection(); | ||||
| 			PreparedStatement ps = con.prepareStatement("UPDATE characters SET x=?, y=?, z=? WHERE char_name=?")) | ||||
| 		{ | ||||
| 			ps.setInt(1, x); | ||||
|   | ||||
| @@ -21,7 +21,7 @@ import java.sql.PreparedStatement; | ||||
| import java.sql.ResultSet; | ||||
| import java.text.SimpleDateFormat; | ||||
|  | ||||
| import com.l2jmobius.commons.database.pool.impl.ConnectionFactory; | ||||
| import com.l2jmobius.commons.database.DatabaseFactory; | ||||
| import com.l2jmobius.gameserver.cache.HtmCache; | ||||
| import com.l2jmobius.gameserver.handler.CommunityBoardHandler; | ||||
| import com.l2jmobius.gameserver.handler.IParseBoardHandler; | ||||
| @@ -61,7 +61,7 @@ public class FavoriteBoard implements IParseBoardHandler | ||||
| 			// Load Favorite links | ||||
| 			final String list = HtmCache.getInstance().getHtm(activeChar.getHtmlPrefix(), "html/CommunityBoard/favorite_list.html"); | ||||
| 			final StringBuilder sb = new StringBuilder(); | ||||
| 			try (Connection con = ConnectionFactory.getInstance().getConnection(); | ||||
| 			try (Connection con = DatabaseFactory.getInstance().getConnection(); | ||||
| 				PreparedStatement ps = con.prepareStatement(SELECT_FAVORITES)) | ||||
| 			{ | ||||
| 				ps.setInt(1, activeChar.getObjectId()); | ||||
| @@ -98,7 +98,7 @@ public class FavoriteBoard implements IParseBoardHandler | ||||
| 					return false; | ||||
| 				} | ||||
| 				 | ||||
| 				try (Connection con = ConnectionFactory.getInstance().getConnection(); | ||||
| 				try (Connection con = DatabaseFactory.getInstance().getConnection(); | ||||
| 					PreparedStatement ps = con.prepareStatement(ADD_FAVORITE)) | ||||
| 				{ | ||||
| 					ps.setInt(1, activeChar.getObjectId()); | ||||
| @@ -123,7 +123,7 @@ public class FavoriteBoard implements IParseBoardHandler | ||||
| 				return false; | ||||
| 			} | ||||
| 			 | ||||
| 			try (Connection con = ConnectionFactory.getInstance().getConnection(); | ||||
| 			try (Connection con = DatabaseFactory.getInstance().getConnection(); | ||||
| 				PreparedStatement ps = con.prepareStatement(DELETE_FAVORITE)) | ||||
| 			{ | ||||
| 				ps.setInt(1, activeChar.getObjectId()); | ||||
|   | ||||
| @@ -21,7 +21,7 @@ import java.sql.PreparedStatement; | ||||
| import java.sql.ResultSet; | ||||
|  | ||||
| import com.l2jmobius.Config; | ||||
| import com.l2jmobius.commons.database.pool.impl.ConnectionFactory; | ||||
| import com.l2jmobius.commons.database.DatabaseFactory; | ||||
| import com.l2jmobius.gameserver.cache.HtmCache; | ||||
| import com.l2jmobius.gameserver.data.sql.impl.ClanTable; | ||||
| import com.l2jmobius.gameserver.data.xml.impl.BuyListData; | ||||
| @@ -176,7 +176,7 @@ public final class HomeBoard implements IParseBoardHandler | ||||
| 	private static int getFavoriteCount(L2PcInstance player) | ||||
| 	{ | ||||
| 		int count = 0; | ||||
| 		try (Connection con = ConnectionFactory.getInstance().getConnection(); | ||||
| 		try (Connection con = DatabaseFactory.getInstance().getConnection(); | ||||
| 			PreparedStatement ps = con.prepareStatement(COUNT_FAVORITES)) | ||||
| 		{ | ||||
| 			ps.setInt(1, player.getObjectId()); | ||||
|   | ||||
| @@ -22,7 +22,7 @@ import java.sql.ResultSet; | ||||
| import java.util.logging.Level; | ||||
| import java.util.logging.Logger; | ||||
|  | ||||
| import com.l2jmobius.commons.database.pool.impl.ConnectionFactory; | ||||
| import com.l2jmobius.commons.database.DatabaseFactory; | ||||
| import com.l2jmobius.gameserver.handler.IUserCommandHandler; | ||||
| import com.l2jmobius.gameserver.model.L2Clan; | ||||
| import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance; | ||||
| @@ -82,7 +82,7 @@ public class ClanWarsList implements IUserCommandHandler | ||||
| 			query = WAR_LIST; | ||||
| 		} | ||||
| 		 | ||||
| 		try (Connection con = ConnectionFactory.getInstance().getConnection(); | ||||
| 		try (Connection con = DatabaseFactory.getInstance().getConnection(); | ||||
| 			PreparedStatement ps = con.prepareStatement(query)) | ||||
| 		{ | ||||
| 			ps.setInt(1, clan.getId()); | ||||
|   | ||||
| @@ -23,7 +23,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.GameTimeController; | ||||
| import com.l2jmobius.gameserver.ThreadPoolManager; | ||||
| import com.l2jmobius.gameserver.ai.CtrlIntention; | ||||
| @@ -208,7 +208,7 @@ public class Wedding implements IVoicedCommandHandler | ||||
| 		 | ||||
| 		// Check if target has player on friend list | ||||
| 		boolean foundOnFriendList = false; | ||||
| 		try (Connection con = ConnectionFactory.getInstance().getConnection(); | ||||
| 		try (Connection con = DatabaseFactory.getInstance().getConnection(); | ||||
| 			PreparedStatement statement = con.prepareStatement("SELECT friendId FROM character_friends WHERE charId=?")) | ||||
| 		{ | ||||
| 			statement.setInt(1, ptarget.getObjectId()); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 MobiusDev
					MobiusDev