|
@@ -19,7 +19,6 @@
|
|
package com.l2jserver;
|
|
package com.l2jserver;
|
|
|
|
|
|
import java.sql.Connection;
|
|
import java.sql.Connection;
|
|
-import java.sql.PreparedStatement;
|
|
|
|
import java.sql.SQLException;
|
|
import java.sql.SQLException;
|
|
import java.util.concurrent.Executors;
|
|
import java.util.concurrent.Executors;
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
@@ -37,18 +36,8 @@ public class L2DatabaseFactory
|
|
{
|
|
{
|
|
private static final Logger _log = Logger.getLogger(L2DatabaseFactory.class.getName());
|
|
private static final Logger _log = Logger.getLogger(L2DatabaseFactory.class.getName());
|
|
|
|
|
|
- /**
|
|
|
|
- * The Enum ProviderType.
|
|
|
|
- */
|
|
|
|
- private static enum ProviderType
|
|
|
|
- {
|
|
|
|
- MySql,
|
|
|
|
- MsSql
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
private static L2DatabaseFactory _instance;
|
|
private static L2DatabaseFactory _instance;
|
|
private static volatile ScheduledExecutorService _executor;
|
|
private static volatile ScheduledExecutorService _executor;
|
|
- private ProviderType _providerType;
|
|
|
|
private ComboPooledDataSource _source;
|
|
private ComboPooledDataSource _source;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -114,15 +103,6 @@ public class L2DatabaseFactory
|
|
{
|
|
{
|
|
_log.fine("Database Connection Working");
|
|
_log.fine("Database Connection Working");
|
|
}
|
|
}
|
|
-
|
|
|
|
- if (Config.DATABASE_DRIVER.toLowerCase().contains("microsoft"))
|
|
|
|
- {
|
|
|
|
- _providerType = ProviderType.MsSql;
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- _providerType = ProviderType.MySql;
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
catch (SQLException x)
|
|
catch (SQLException x)
|
|
{
|
|
{
|
|
@@ -143,33 +123,6 @@ public class L2DatabaseFactory
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * Prepared query select.
|
|
|
|
- * @param fields the fields
|
|
|
|
- * @param tableName the table name
|
|
|
|
- * @param whereClause the where clause
|
|
|
|
- * @param returnOnlyTopRecord the return only top record
|
|
|
|
- * @return the string
|
|
|
|
- */
|
|
|
|
- public final String prepQuerySelect(String[] fields, String tableName, String whereClause, boolean returnOnlyTopRecord)
|
|
|
|
- {
|
|
|
|
- String msSqlTop1 = "";
|
|
|
|
- String mySqlTop1 = "";
|
|
|
|
- if (returnOnlyTopRecord)
|
|
|
|
- {
|
|
|
|
- if (getProviderType() == ProviderType.MsSql)
|
|
|
|
- {
|
|
|
|
- msSqlTop1 = " Top 1 ";
|
|
|
|
- }
|
|
|
|
- if (getProviderType() == ProviderType.MySql)
|
|
|
|
- {
|
|
|
|
- mySqlTop1 = " Limit 1 ";
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- String query = "SELECT " + msSqlTop1 + safetyString(fields) + " FROM " + tableName + " WHERE " + whereClause + mySqlTop1;
|
|
|
|
- return query;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* Shutdown.
|
|
* Shutdown.
|
|
*/
|
|
*/
|
|
@@ -193,52 +146,6 @@ public class L2DatabaseFactory
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * Safety string.
|
|
|
|
- * @param whatToCheck the what to check
|
|
|
|
- * @return the string
|
|
|
|
- */
|
|
|
|
- public final String safetyString(String... whatToCheck)
|
|
|
|
- {
|
|
|
|
- // NOTE: Use brace as a safety precaution just in case name is a reserved word
|
|
|
|
- final char braceLeft;
|
|
|
|
- final char braceRight;
|
|
|
|
-
|
|
|
|
- if (getProviderType() == ProviderType.MsSql)
|
|
|
|
- {
|
|
|
|
- braceLeft = '[';
|
|
|
|
- braceRight = ']';
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- braceLeft = '`';
|
|
|
|
- braceRight = '`';
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- int length = 0;
|
|
|
|
-
|
|
|
|
- for (String word : whatToCheck)
|
|
|
|
- {
|
|
|
|
- length += word.length() + 4;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- final StringBuilder sbResult = new StringBuilder(length);
|
|
|
|
-
|
|
|
|
- for (String word : whatToCheck)
|
|
|
|
- {
|
|
|
|
- if (sbResult.length() > 0)
|
|
|
|
- {
|
|
|
|
- sbResult.append(", ");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- sbResult.append(braceLeft);
|
|
|
|
- sbResult.append(word);
|
|
|
|
- sbResult.append(braceRight);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return sbResult.toString();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* Gets the single instance of L2DatabaseFactory.
|
|
* Gets the single instance of L2DatabaseFactory.
|
|
* @return single instance of L2DatabaseFactory
|
|
* @return single instance of L2DatabaseFactory
|
|
@@ -364,32 +271,4 @@ public class L2DatabaseFactory
|
|
{
|
|
{
|
|
return _source.getNumIdleConnectionsDefaultUser();
|
|
return _source.getNumIdleConnectionsDefaultUser();
|
|
}
|
|
}
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Gets the provider type.
|
|
|
|
- * @return the provider type
|
|
|
|
- */
|
|
|
|
- public final ProviderType getProviderType()
|
|
|
|
- {
|
|
|
|
- return _providerType;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Designed to execute simple db operations like INSERT, UPDATE, DELETE.
|
|
|
|
- * @param query
|
|
|
|
- * @param params
|
|
|
|
- * @throws SQLException
|
|
|
|
- */
|
|
|
|
- public void executeQuery(String query, Object... params) throws SQLException
|
|
|
|
- {
|
|
|
|
- try (Connection con = getConnection();
|
|
|
|
- PreparedStatement st = con.prepareStatement(query))
|
|
|
|
- {
|
|
|
|
- for (int i = 0; i < params.length; i++)
|
|
|
|
- {
|
|
|
|
- st.setObject(i + 1, params[i]);
|
|
|
|
- }
|
|
|
|
- st.execute();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
}
|
|
}
|