mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-15 04:31:34 +01:00
StringProvider store transaction
This commit is contained in:
parent
7d13012371
commit
129db2d941
@ -38,6 +38,6 @@ public class ExtensionProviderTable {
|
|||||||
|
|
||||||
public static final String PROVIDED_CONDITION = "provided_condition"; // Can be null
|
public static final String PROVIDED_CONDITION = "provided_condition"; // Can be null
|
||||||
public static final String FORMAT_TYPE = "format_type"; // Can be null
|
public static final String FORMAT_TYPE = "format_type"; // Can be null
|
||||||
public static final String PLAYER_NAME = "player_name"; // default false
|
public static final String IS_PLAYER_NAME = "player_name"; // default false
|
||||||
|
|
||||||
}
|
}
|
@ -16,12 +16,23 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.extension.implementation.storage.transactions.providers;
|
package com.djrapitops.plan.extension.implementation.storage.transactions.providers;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.db.access.ExecStatement;
|
||||||
|
import com.djrapitops.plan.db.access.Executable;
|
||||||
import com.djrapitops.plan.db.access.transactions.Transaction;
|
import com.djrapitops.plan.db.access.transactions.Transaction;
|
||||||
|
import com.djrapitops.plan.db.sql.tables.ExtensionIconTable;
|
||||||
|
import com.djrapitops.plan.db.sql.tables.ExtensionPluginTable;
|
||||||
|
import com.djrapitops.plan.db.sql.tables.ExtensionTabTable;
|
||||||
import com.djrapitops.plan.extension.implementation.ProviderInformation;
|
import com.djrapitops.plan.extension.implementation.ProviderInformation;
|
||||||
import com.djrapitops.plan.extension.implementation.providers.DataProvider;
|
import com.djrapitops.plan.extension.implementation.providers.DataProvider;
|
||||||
|
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static com.djrapitops.plan.db.sql.parsing.Sql.AND;
|
||||||
|
import static com.djrapitops.plan.db.sql.parsing.Sql.WHERE;
|
||||||
|
import static com.djrapitops.plan.db.sql.tables.ExtensionProviderTable.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transaction to store information about a {@link com.djrapitops.plan.extension.implementation.providers.StringDataProvider}.
|
* Transaction to store information about a {@link com.djrapitops.plan.extension.implementation.providers.StringDataProvider}.
|
||||||
*
|
*
|
||||||
@ -29,20 +40,87 @@ import java.util.UUID;
|
|||||||
*/
|
*/
|
||||||
public class StoreStringProviderTransaction extends Transaction {
|
public class StoreStringProviderTransaction extends Transaction {
|
||||||
|
|
||||||
private final DataProvider<String> provider;
|
|
||||||
private final boolean playerName;
|
private final boolean playerName;
|
||||||
private final UUID serverUUID;
|
private final UUID serverUUID;
|
||||||
|
private ProviderInformation providerInformation;
|
||||||
|
|
||||||
public StoreStringProviderTransaction(DataProvider<String> provider, boolean playerName, UUID serverUUID) {
|
public StoreStringProviderTransaction(DataProvider<String> provider, boolean playerName, UUID serverUUID) {
|
||||||
this.provider = provider;
|
|
||||||
this.playerName = playerName;
|
this.playerName = playerName;
|
||||||
this.serverUUID = serverUUID;
|
this.serverUUID = serverUUID;
|
||||||
|
providerInformation = provider.getProviderInformation();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void performOperations() {
|
protected void performOperations() {
|
||||||
ProviderInformation providerInformation = provider.getProviderInformation();
|
execute(storeProvider());
|
||||||
|
}
|
||||||
|
|
||||||
// TODO Store provider in a table
|
private Executable storeProvider() {
|
||||||
|
return connection -> {
|
||||||
|
if (!updateProvider().execute(connection)) {
|
||||||
|
return insertProvider().execute(connection);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private Executable updateProvider() {
|
||||||
|
String sql = "UPDATE " + TABLE_NAME +
|
||||||
|
" SET (" +
|
||||||
|
TEXT + "=?," +
|
||||||
|
DESCRIPTION + "=?," +
|
||||||
|
PRIORITY + "=?," +
|
||||||
|
CONDITION + "=?," +
|
||||||
|
IS_PLAYER_NAME + "=?," +
|
||||||
|
TAB_ID + "=" + ExtensionTabTable.STATEMENT_SELECT_TAB_ID + "," +
|
||||||
|
ICON_ID + "=" + ExtensionIconTable.STATEMENT_SELECT_ICON_ID +
|
||||||
|
")" + WHERE + PLUGIN_ID + "=" + ExtensionPluginTable.STATEMENT_SELECT_PLUGIN_ID +
|
||||||
|
AND + PROVIDER_NAME + "=?";
|
||||||
|
|
||||||
|
return new ExecStatement(sql) {
|
||||||
|
@Override
|
||||||
|
public void prepare(PreparedStatement statement) throws SQLException {
|
||||||
|
statement.setString(1, providerInformation.getText());
|
||||||
|
statement.setString(2, providerInformation.getDescription());
|
||||||
|
statement.setInt(3, providerInformation.getPriority());
|
||||||
|
statement.setString(4, providerInformation.getCondition().orElse(null));
|
||||||
|
statement.setBoolean(5, playerName);
|
||||||
|
ExtensionTabTable.set3TabValuesToStatement(statement, 6, providerInformation.getTab().orElse(null), providerInformation.getPluginName(), serverUUID);
|
||||||
|
ExtensionIconTable.set3IconValuesToStatement(statement, 9, providerInformation.getIcon());
|
||||||
|
ExtensionPluginTable.set2PluginValuesToStatement(statement, 11, providerInformation.getPluginName(), serverUUID);
|
||||||
|
statement.setString(13, providerInformation.getName());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private Executable insertProvider() {
|
||||||
|
String sql = "INSERT INTO " + TABLE_NAME + "(" +
|
||||||
|
PROVIDER_NAME + "," +
|
||||||
|
TEXT + "," +
|
||||||
|
DESCRIPTION + "," +
|
||||||
|
PRIORITY + "," +
|
||||||
|
CONDITION + "," +
|
||||||
|
IS_PLAYER_NAME + "," +
|
||||||
|
TAB_ID + "," +
|
||||||
|
ICON_ID + "," +
|
||||||
|
PLUGIN_ID +
|
||||||
|
") VALUES (?,?,?,?,?,?," +
|
||||||
|
ExtensionTabTable.STATEMENT_SELECT_TAB_ID + "," +
|
||||||
|
ExtensionIconTable.STATEMENT_SELECT_ICON_ID + "," +
|
||||||
|
ExtensionPluginTable.STATEMENT_SELECT_PLUGIN_ID + ")";
|
||||||
|
return new ExecStatement(sql) {
|
||||||
|
@Override
|
||||||
|
public void prepare(PreparedStatement statement) throws SQLException {
|
||||||
|
statement.setString(1, providerInformation.getName());
|
||||||
|
statement.setString(2, providerInformation.getText());
|
||||||
|
statement.setString(3, providerInformation.getDescription());
|
||||||
|
statement.setInt(4, providerInformation.getPriority());
|
||||||
|
statement.setString(5, providerInformation.getCondition().orElse(null));
|
||||||
|
statement.setBoolean(6, playerName);
|
||||||
|
ExtensionTabTable.set3TabValuesToStatement(statement, 7, providerInformation.getTab().orElse(null), providerInformation.getPluginName(), serverUUID);
|
||||||
|
ExtensionIconTable.set3IconValuesToStatement(statement, 10, providerInformation.getIcon());
|
||||||
|
ExtensionPluginTable.set2PluginValuesToStatement(statement, 12, providerInformation.getPluginName(), serverUUID);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user