Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding soft deletion #54

Merged
merged 1 commit into from
Jan 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
*.jar
!citadel.jar
*~
/target/
1 change: 1 addition & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ settings:
allowTriggeringLevers: false
togglerestartgroupcheck: false
displayOwnerOnSnitchBreak: true
softDelete: true
mercury:
broadcastallservers: false
6 changes: 3 additions & 3 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: JukeAlert
name: ${project.name}
main: com.untamedears.JukeAlert.JukeAlert
version: 1.3.5
version: ${project.version}
depend: [Citadel, NameLayer]
softdepend: [vanishnopacket, ItemExchange, Mercury]
description: JukeAlert provides an easy-to-use means by which one can record player activity within an 11 block radius. Anything someone does while within eleven blocks of a jukebox you've reinforced will be logged on it, and can be read by looking at the jukebox and typing '/jainfo'.
Expand Down Expand Up @@ -66,4 +66,4 @@ permissions:
default: true
jukealert.vanish:
description: Ability to avoid snitches.
default: op
default: op
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>com.untamedears</groupId>
<artifactId>JukeAlert</artifactId>
<packaging>jar</packaging>
<version>1.3.63</version>
<version>1.3.7</version>
<name>JukeAlert</name>
<url>https://github.com/Civcraft/JukeAlert/</url>

Expand All @@ -28,6 +28,7 @@
<include>*.yml</include>
<include>LICENSE.txt</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>
Expand Down
6 changes: 6 additions & 0 deletions src/com/untamedears/JukeAlert/manager/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class ConfigManager
private boolean enableInvisibility;
private boolean toggleRestartCheckGroup;
private boolean displayOwnerOnBreak;
private boolean softDelete;

private boolean broadcastAllServers;

Expand Down Expand Up @@ -114,6 +115,7 @@ private void load()
enableInvisibility = loadBoolean("settings.enableinvisiblity", false);
toggleRestartCheckGroup = loadBoolean("settings.togglerestartgroupcheck", false);
displayOwnerOnBreak = loadBoolean("settings.displayOwnerOnSnitchBreak", true);
softDelete = loadBoolean("settings.softDelete", true);

broadcastAllServers = loadBoolean("mercury.broadcastallservers", false);

Expand Down Expand Up @@ -367,6 +369,10 @@ public boolean isDisplayOwnerOnBreak() {
return displayOwnerOnBreak;
}

public boolean isSoftDelete() {
return softDelete;
}

public boolean getToggleRestartCheckGroup(){
return toggleRestartCheckGroup;
}
Expand Down
61 changes: 47 additions & 14 deletions src/com/untamedears/JukeAlert/storage/JukeAlertLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ public class JukeAlertLogger {
private PreparedStatement getSnitchLogStmt;
private PreparedStatement getSnitchLogGroupStmt;
private PreparedStatement getSnitchListStmt;
private PreparedStatement softDeleteSnitchLogStmt;
private PreparedStatement deleteSnitchLogStmt;
private PreparedStatement insertSnitchLogStmt;
private PreparedStatement insertNewSnitchStmt;
private PreparedStatement softDeleteSnitchStmt;
private PreparedStatement deleteSnitchStmt;
private PreparedStatement updateGroupStmt;
private PreparedStatement updateCuboidVolumeStmt;
Expand All @@ -87,6 +89,7 @@ public class JukeAlertLogger {
private final int maxEntryLifetimeDays;
private final int daysFromLastAdminVisitForLoggedSnitchCulling;
private final int daysFromLastAdminVisitForNonLoggedSnitchCulling;
private final boolean softDelete;
private final String host;
private final String dbname;
private final String username;
Expand All @@ -113,6 +116,7 @@ public JukeAlertLogger() {

daysFromLastAdminVisitForLoggedSnitchCulling = configManager.getDaysFromLastAdminVisitForLoggedSnitchCulling();
daysFromLastAdminVisitForNonLoggedSnitchCulling = configManager.getDaysFromLastAdminVisitForNonLoggedSnitchCulling();
softDelete = configManager.isSoftDelete();

logsPerPage = configManager.getLogsPerPage();
snitchsTbl = prefix + "snitchs";
Expand Down Expand Up @@ -204,6 +208,9 @@ private void genTables() {
db.silentExecute(String.format("UPDATE %s SET allow_triggering_lever = 0 WHERE allow_triggering_lever IS NULL;", snitchsTbl));
db.silentExecute(String.format("ALTER TABLE %s MODIFY COLUMN allow_triggering_lever bit NOT NULL;", snitchsTbl));

db.silentExecute(String.format("ALTER TABLE %s ADD COLUMN (soft_delete BOOL NOT NULL DEFAULT 0);", snitchsTbl));
db.silentExecute(String.format("ALTER TABLE %s ADD COLUMN (soft_delete BOOL NOT NULL DEFAULT 0);", snitchDetailsTbl));

try {

this.plugin.getLogger().log(Level.INFO, "Adding the log_hour column");
Expand Down Expand Up @@ -362,6 +369,7 @@ private void genTables() {
+ " {0} s \n"
+ " INNER JOIN GroupNames filter \n"
+ " ON filter.groupname = s.snitch_group \n"
+ " WHERE s.soft_delete = 0 \n"
+ " ORDER BY CASE \n"
+ " WHEN \n"
+ " (s.snitch_should_log = 1 AND daysFromLastAdminVisitForLoggedSnitchCulling >= 1) \n"
Expand Down Expand Up @@ -400,10 +408,10 @@ public PreparedStatement getNewUpdateSnitchSemiOwnerVisitStmt() {
private void initializeStatements() {

getAllSnitchesStmt = db.prepareStatement(String.format(
"SELECT * FROM %s", snitchsTbl));
"SELECT * FROM %s WHERE soft_delete = 0", snitchsTbl));

getAllSnitchesByWorldStmt = db.prepareStatement(String.format(
"SELECT * FROM %s WHERE snitch_world = ?", snitchsTbl));
"SELECT * FROM %s WHERE snitch_world = ? AND soft_delete = 0", snitchsTbl));

getLastSnitchID = db.prepareStatement(String.format(
"SHOW TABLE STATUS LIKE '%s'", snitchsTbl));
Expand All @@ -412,13 +420,13 @@ private void initializeStatements() {
// LIMIT ?,? means offset followed by max rows to return
getSnitchLogStmt = db.prepareStatement(String.format(
"SELECT * FROM %s"
+ " WHERE snitch_id=? ORDER BY snitch_log_time DESC LIMIT ?,?",
+ " WHERE snitch_id=? AND soft_delete = 0 ORDER BY snitch_log_time DESC LIMIT ?,?",
snitchDetailsTbl));

getSnitchLogGroupStmt = db.prepareStatement(MessageFormat.format(
"SELECT {0}.snitch_name, {1}.*"
+ " FROM {1} INNER JOIN {0} ON {0}.snitch_id = {1}.snitch_id"
+ " WHERE {0}.snitch_group=? ORDER BY {1}.snitch_log_time DESC LIMIT ?,{2}",
+ " WHERE {0}.snitch_group=? AND {0}.soft_delete = 0 AND {1}.soft_delete = 0 ORDER BY {1}.snitch_log_time DESC LIMIT ?,{2}",
snitchsTbl, snitchDetailsTbl, logsPerPage));

getSnitchListStmt = db.prepareStatement(MessageFormat.format(
Expand All @@ -429,7 +437,7 @@ private void initializeStatements() {

// statement to get the ID of a snitch in the main snitchsTbl based on a Location (x,y,z, world)
getSnitchIdFromLocationStmt = db.prepareStatement(String.format("SELECT snitch_id FROM %s"
+ " WHERE snitch_x=? AND snitch_y=? AND snitch_z=? AND snitch_world=?", snitchsTbl));
+ " WHERE snitch_x=? AND snitch_y=? AND snitch_z=? AND snitch_world=? AND soft_delete = 0", snitchsTbl));

// statement to insert a log entry into the snitchesDetailsTable
insertSnitchLogStmt = db.prepareStatement(String.format(
Expand All @@ -449,11 +457,21 @@ private void initializeStatements() {
"DELETE FROM %s WHERE snitch_id=?",
snitchDetailsTbl));

//
softDeleteSnitchLogStmt = db.prepareStatement(String.format(
"UPDATE %s SET soft_delete = 1 WHERE snitch_id=?",
snitchDetailsTbl));

//
deleteSnitchStmt = db.prepareStatement(String.format(
"DELETE FROM %s WHERE snitch_world=? AND snitch_x=? AND snitch_y=? AND snitch_z=?",
snitchsTbl));

//
softDeleteSnitchStmt = db.prepareStatement(String.format(
"UPDATE %s SET soft_delete = 1 WHERE snitch_world=? AND snitch_x=? AND snitch_y=? AND snitch_z=?",
snitchsTbl));

//
updateGroupStmt = db.prepareStatement(String.format(
"UPDATE %s SET snitch_group=? WHERE snitch_world=? AND snitch_x=? AND snitch_y=? AND snitch_z=?",
Expand Down Expand Up @@ -485,7 +503,7 @@ private void initializeStatements() {

//
getAllSnitchIdsStmt = db.prepareStatement(String.format(
"SELECT snitch_id FROM %s;", snitchsTbl));
"SELECT snitch_id FROM %s WHERE soft_delete = 0;", snitchsTbl));

//
cullSnitchEntriesStmt = db.prepareStatement(MessageFormat.format(
Expand Down Expand Up @@ -786,8 +804,13 @@ public Boolean deleteSnitchInfo(Location loc) {

public Boolean deleteSnitchInfo(int snitchId) {
try {
deleteSnitchLogStmt.setInt(1, snitchId);
deleteSnitchLogStmt.execute();
if (this.softDelete) {
softDeleteSnitchLogStmt.setInt(1, snitchId);
softDeleteSnitchLogStmt.execute();
} else {
deleteSnitchLogStmt.setInt(1, snitchId);
deleteSnitchLogStmt.execute();
}
return true;
} catch (SQLException ex) {
this.plugin.getLogger().log(Level.SEVERE, "Could not delete Snitch Details from the snitchesDetail table using the snitch id " + snitchId, ex);
Expand Down Expand Up @@ -1077,12 +1100,22 @@ public void logSnitchBreak(final String world, final int x, final int y, final i
public void run() {
try {
jukeinfobatch.flush();
synchronized (deleteSnitchStmt) {
deleteSnitchStmt.setString(1, world);
deleteSnitchStmt.setInt(2, (int) Math.floor(x));
deleteSnitchStmt.setInt(3, (int) Math.floor(y));
deleteSnitchStmt.setInt(4, (int) Math.floor(z));
deleteSnitchStmt.execute();
if (softDelete) {
synchronized (softDeleteSnitchStmt) {
softDeleteSnitchStmt.setString(1, world);
softDeleteSnitchStmt.setInt(2, (int) Math.floor(x));
softDeleteSnitchStmt.setInt(3, (int) Math.floor(y));
softDeleteSnitchStmt.setInt(4, (int) Math.floor(z));
softDeleteSnitchStmt.execute();
}
} else {
synchronized (deleteSnitchStmt) {
deleteSnitchStmt.setString(1, world);
deleteSnitchStmt.setInt(2, (int) Math.floor(x));
deleteSnitchStmt.setInt(3, (int) Math.floor(y));
deleteSnitchStmt.setInt(4, (int) Math.floor(z));
deleteSnitchStmt.execute();
}
}
} catch (SQLException ex) {
Logger.getLogger(JukeAlertLogger.class.getName()).log(Level.SEVERE, null, ex);
Expand Down