summaryrefslogtreecommitdiffstats
path: root/EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockJDBC.java
diff options
context:
space:
mode:
Diffstat (limited to 'EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockJDBC.java')
-rw-r--r--EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockJDBC.java42
1 files changed, 15 insertions, 27 deletions
diff --git a/EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockJDBC.java b/EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockJDBC.java
index e24a71b80..30ac5ae8e 100644
--- a/EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockJDBC.java
+++ b/EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockJDBC.java
@@ -1,11 +1,6 @@
package com.earth2me.essentials.protect.data;
-import com.mchange.v2.c3p0.ComboPooledDataSource;
-import java.beans.PropertyVetoException;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
+import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
@@ -16,7 +11,7 @@ import org.bukkit.block.Block;
public abstract class ProtectedBlockJDBC implements IProtectedBlock
{
protected static final Logger LOGGER = Logger.getLogger("Minecraft");
- protected final transient ComboPooledDataSource cpds;
+ protected String url;
protected abstract PreparedStatement getStatementCreateTable(Connection conn) throws SQLException;
@@ -34,22 +29,20 @@ public abstract class ProtectedBlockJDBC implements IProtectedBlock
protected abstract PreparedStatement getStatementAllBlocks(Connection conn) throws SQLException;
- public ProtectedBlockJDBC(String driver, String url) throws PropertyVetoException
+ public ProtectedBlockJDBC(String driver, String url) throws ClassNotFoundException
{
this(driver, url, null, null);
}
- public ProtectedBlockJDBC(String driver, String url, String username, String password) throws PropertyVetoException
+ public ProtectedBlockJDBC(String driver, String url, String username, String password) throws ClassNotFoundException
{
- cpds = new ComboPooledDataSource();
- cpds.setDriverClass(driver);
- cpds.setJdbcUrl(url);
+ Class.forName(driver);
+ this.url = url;
if (username != null)
{
- cpds.setUser(username);
- cpds.setPassword(password);
+ url += "?user=" + username;
+ url += "&password=" + password;
}
- cpds.setMaxStatements(20);
createAndConvertTable();
}
@@ -59,7 +52,7 @@ public abstract class ProtectedBlockJDBC implements IProtectedBlock
PreparedStatement ps = null;
try
{
- conn = cpds.getConnection();
+ conn = DriverManager.getConnection(url);
ps = getStatementCreateTable(conn);
ps.execute();
ps.close();
@@ -103,7 +96,7 @@ public abstract class ProtectedBlockJDBC implements IProtectedBlock
PreparedStatement ps = null;
try
{
- conn = cpds.getConnection();
+ conn = DriverManager.getConnection(url);
ps = getStatementDeleteAll(conn);
ps.executeUpdate();
}
@@ -158,7 +151,7 @@ public abstract class ProtectedBlockJDBC implements IProtectedBlock
List<OwnedBlock> blocks = new ArrayList<OwnedBlock>();
try
{
- conn = cpds.getConnection();
+ conn = DriverManager.getConnection(url);
ps = getStatementAllBlocks(conn);
rs = ps.executeQuery();
while (rs.next())
@@ -227,7 +220,7 @@ public abstract class ProtectedBlockJDBC implements IProtectedBlock
PreparedStatement ps = null;
try
{
- conn = cpds.getConnection();
+ conn = DriverManager.getConnection(url);
ps = getStatementInsert(conn, world, x, y, z, playerName);
ps.executeUpdate();
}
@@ -269,7 +262,7 @@ public abstract class ProtectedBlockJDBC implements IProtectedBlock
ResultSet rs = null;
try
{
- conn = cpds.getConnection();
+ conn = DriverManager.getConnection(url);
ps = getStatementPlayerCountByLocation(conn, block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), playerName);
rs = ps.executeQuery();
return rs.next() && rs.getInt(1) > 0 && rs.getInt(2) == 0;
@@ -325,7 +318,7 @@ public abstract class ProtectedBlockJDBC implements IProtectedBlock
List<String> owners = new ArrayList<String>();
try
{
- conn = cpds.getConnection();
+ conn = DriverManager.getConnection(url);
ps = getStatementPlayersByLocation(conn, block.getWorld().getName(), block.getX(), block.getY(), block.getZ());
rs = ps.executeQuery();
while (rs.next())
@@ -383,7 +376,7 @@ public abstract class ProtectedBlockJDBC implements IProtectedBlock
PreparedStatement ps = null;
try
{
- conn = cpds.getConnection();
+ conn = DriverManager.getConnection(url);
ps = getStatementDeleteByLocation(conn, block.getWorld().getName(), block.getX(), block.getY(), block.getZ());
return ps.executeUpdate();
}
@@ -418,9 +411,4 @@ public abstract class ProtectedBlockJDBC implements IProtectedBlock
}
}
}
-
- public void onPluginDeactivation()
- {
- cpds.close();
- }
}