Fixed PlotMe convert for some cases of SQLite

This commit is contained in:
boy0001 2015-03-12 23:25:59 +11:00
parent 27f6675d8f
commit d0fe132c82
2 changed files with 52 additions and 12 deletions

View File

@ -164,7 +164,7 @@ public class Set extends SubCommand {
final String world = plr.getLocation().getWorld(); final String world = plr.getLocation().getWorld();
final Location base = MainUtil.getPlotBottomLoc(world, plot.id); final Location base = MainUtil.getPlotBottomLoc(world, plot.id);
base.setY(0); base.setY(0);
final Location relative = plr.getLocation().subtract(base.getX(), base.getZ(), base.getY()); final Location relative = plr.getLocation().subtract(base.getX(), base.getY(), base.getZ());
final BlockLoc blockloc = new BlockLoc(relative.getX(), relative.getY(), relative.getZ()); final BlockLoc blockloc = new BlockLoc(relative.getX(), relative.getY(), relative.getZ());
plot.settings.setPosition(blockloc); plot.settings.setPosition(blockloc);
DBFunc.setPosition(loc.getWorld(), plot, relative.getX() + "," + relative.getY() + "," + relative.getZ()); DBFunc.setPosition(loc.getWorld(), plot, relative.getX() + "," + relative.getY() + "," + relative.getZ());

View File

@ -26,6 +26,7 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.sql.Timestamp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -241,7 +242,7 @@ public class SQLManager implements AbstractDB {
if (PlotSquared.getMySQL() != null) { if (PlotSquared.getMySQL() != null) {
packet = Math.min(size, 50000); packet = Math.min(size, 50000);
} else { } else {
packet = Math.min(size, 5000); packet = Math.min(size, 100);
} }
final int amount = size / packet; final int amount = size / packet;
for (int j = 0; j <= amount; j++) { for (int j = 0; j <= amount; j++) {
@ -271,7 +272,45 @@ public class SQLManager implements AbstractDB {
stmt.executeUpdate(); stmt.executeUpdate();
stmt.close(); stmt.close();
} catch (final Exception e) { } catch (final Exception e) {
e.printStackTrace(); try {
// TODO UNION
/*
INSERT INTO `" + this.prefix + "plot`(`plot_id_x`, `plot_id_z`, `owner`, `world`) values
INSERT INTO 'tablename'
SELECT 'data1' AS 'column1', 'data2' AS 'column2'
UNION SELECT 'data3', 'data4'
UNION SELECT 'data5', 'data6'
UNION SELECT 'data7', 'data8'
*/
StringBuilder unionstmt = new StringBuilder("INSERT INTO `" + this.prefix + "plot` SELECT ? AS `id`, ? AS `plot_id_x`, ? AS `plot_id_z`, ? AS `owner`, ? AS `world`, ? AS `timestamp` ");
for (int i = 0; i < (plots.size() - 2); i++) {
unionstmt.append("UNION SELECT ?, ?, ?, ?, ?, ? ");
}
unionstmt.append("UNION SELECT ?, ?, ?, ?, ?, ? ");
stmt = this.connection.prepareStatement(unionstmt.toString());
for (int i = 0; i < plots.size(); i++) {
final Plot plot = plots.get(i);
stmt.setNull((i * 6) + 1, 4);
stmt.setInt((i * 6) + 2, plot.id.x);
stmt.setInt((i * 6) + 3, plot.id.y);
try {
stmt.setString((i * 6) + 4, plot.owner.toString());
} catch (final Exception e1) {
stmt.setString((i * 6) + 4, DBFunc.everyone.toString());
}
stmt.setString((i * 6) + 5, plot.world);
stmt.setTimestamp((i * 6) + 6, new Timestamp(System.currentTimeMillis()));
}
stmt.executeUpdate();
stmt.close();
}
catch (Exception e2) {
e2.printStackTrace();
PlotSquared.log("&6[WARN] " + "Could not bulk save. Conversion may be slower..."); PlotSquared.log("&6[WARN] " + "Could not bulk save. Conversion may be slower...");
try { try {
for (final Plot plot : plots) { for (final Plot plot : plots) {
@ -281,13 +320,14 @@ public class SQLManager implements AbstractDB {
PlotSquared.log("&c[ERROR] " + "Failed to save plot: " + plot.id); PlotSquared.log("&c[ERROR] " + "Failed to save plot: " + plot.id);
} }
} }
} catch (final Exception e2) { } catch (final Exception e4) {
e2.printStackTrace(); e4.printStackTrace();
PlotSquared.log("&c[ERROR] " + "Failed to save plots!"); PlotSquared.log("&c[ERROR] " + "Failed to save plots!");
} }
} }
} }
} }
}
/** /**
* Create a plot * Create a plot