diff options
author | md_5 <md_5@bigpond.com> | 2012-03-02 21:48:03 +1100 |
---|---|---|
committer | md_5 <md_5@bigpond.com> | 2012-03-02 21:48:03 +1100 |
commit | 7b8a9d60d7da4cba5013671920b1064f711b4538 (patch) | |
tree | 7d1d954de52cafa24c7ef5194a40297eb86addbd /EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockJDBC.java | |
parent | 3b76bbfe78914230a6d0c24567eb31465f0b0ef1 (diff) | |
download | Essentials-7b8a9d60d7da4cba5013671920b1064f711b4538.tar Essentials-7b8a9d60d7da4cba5013671920b1064f711b4538.tar.gz Essentials-7b8a9d60d7da4cba5013671920b1064f711b4538.tar.lz Essentials-7b8a9d60d7da4cba5013671920b1064f711b4538.tar.xz Essentials-7b8a9d60d7da4cba5013671920b1064f711b4538.zip |
I honestly have no idea if this works, but on paper it does. Will be great, now to figure out how to test.
Diffstat (limited to 'EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockJDBC.java')
-rw-r--r-- | EssentialsProtect/src/com/earth2me/essentials/protect/data/ProtectedBlockJDBC.java | 42 |
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(); - } } |