Improved some documentation and added some nullability annotations in database code

This commit is contained in:
Florian CUNY 2019-06-22 09:43:32 +02:00
parent 3b0613c22a
commit 5dcec3ee1b
11 changed files with 34 additions and 13 deletions

View File

@ -1,9 +1,9 @@
package world.bentobox.bentobox.database;
import org.eclipse.jdt.annotation.NonNull;
/**
*
* Creates a connection to a database.
*
*/
public interface DatabaseConnector {
@ -28,13 +28,16 @@ public interface DatabaseConnector {
/**
* Looks through the database (or files) and returns a known unique key
*
* @param tableName - name of the table
* @return a unique key for this record
*/
@NonNull
String getUniqueId(String tableName);
/**
* Check if a key exists in the database in this table or not
*
* @param tableName - name of the table
* @param key - key to check
* @return true if it exists

View File

@ -6,6 +6,9 @@ import world.bentobox.bentobox.database.DatabaseSetup;
public class JSONDatabase implements DatabaseSetup {
/* (non-Javadoc)
* @see world.bentobox.bentobox.database.DatabaseSetup#getHandler(java.lang.Class)
*/
@Override
public <T> AbstractDatabaseHandler<T> getHandler(Class<T> dataObjectClass) {
return new JSONDatabaseHandler<>(BentoBox.getInstance(), dataObjectClass, new JSONDatabaseConnector(BentoBox.getInstance()));

View File

@ -3,6 +3,7 @@ package world.bentobox.bentobox.database.json;
import java.io.File;
import java.util.UUID;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.database.DatabaseConnector;
@ -18,6 +19,7 @@ public class JSONDatabaseConnector implements DatabaseConnector {
}
@Override
@NonNull
public String getUniqueId(String tableName) {
UUID uuid = UUID.randomUUID();
File file = new File(dataFolder, tableName + File.separator + uuid.toString() + JSON);

View File

@ -12,7 +12,7 @@ import world.bentobox.bentobox.database.DatabaseSetup;
public class MariaDBDatabase implements DatabaseSetup {
/* (non-Javadoc)
* @see world.bentobox.bentobox.database.BSBDbSetup#getHandler(java.lang.Class)
* @see world.bentobox.bentobox.database.DatabaseSetup#getHandler(java.lang.Class)
*/
@Override
public <T> AbstractDatabaseHandler<T> getHandler(Class<T> type) {

View File

@ -6,6 +6,7 @@ import java.sql.SQLException;
import org.bukkit.Bukkit;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.database.DatabaseConnectionSettingsImpl;
import world.bentobox.bentobox.database.DatabaseConnector;
@ -45,6 +46,7 @@ public class MariaDBDatabaseConnector implements DatabaseConnector {
}
@Override
@NonNull
public String getUniqueId(String tableName) {
// Not used
return "";

View File

@ -9,6 +9,9 @@ import world.bentobox.bentobox.database.DatabaseSetup;
public class MongoDBDatabase implements DatabaseSetup {
/* (non-Javadoc)
* @see world.bentobox.bentobox.database.DatabaseSetup#getHandler(java.lang.Class)
*/
@Override
public <T> AbstractDatabaseHandler<T> getHandler(Class<T> type) {
BentoBox plugin = BentoBox.getInstance();

View File

@ -6,6 +6,7 @@ import com.mongodb.MongoCredential;
import com.mongodb.ServerAddress;
import com.mongodb.client.MongoDatabase;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.database.DatabaseConnectionSettingsImpl;
import world.bentobox.bentobox.database.DatabaseConnector;
@ -38,6 +39,7 @@ public class MongoDBDatabaseConnector implements DatabaseConnector {
}
@Override
@NonNull
public String getUniqueId(String tableName) {
// Not used
return "";

View File

@ -7,9 +7,8 @@ import world.bentobox.bentobox.database.DatabaseSetup;
public class MySQLDatabase implements DatabaseSetup {
/* (non-Javadoc)
* @see world.bentobox.bentobox.database.BSBDbSetup#getHandler(java.lang.Class)
* @see world.bentobox.bentobox.database.DatabaseSetup#getHandler(java.lang.Class)
*/
@Override
public <T> AbstractDatabaseHandler<T> getHandler(Class<T> type) {

View File

@ -6,6 +6,7 @@ import java.sql.SQLException;
import org.bukkit.Bukkit;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.database.DatabaseConnectionSettingsImpl;
import world.bentobox.bentobox.database.DatabaseConnector;
@ -41,6 +42,7 @@ public class MySQLDatabaseConnector implements DatabaseConnector {
}
@Override
@NonNull
public String getUniqueId(String tableName) {
// Not used
return "";

View File

@ -16,6 +16,9 @@ public class YamlDatabase implements DatabaseSetup {
return new ConfigHandler<>(BentoBox.getInstance(), type, new YamlDatabaseConnector(BentoBox.getInstance()));
}
/* (non-Javadoc)
* @see world.bentobox.bentobox.database.DatabaseSetup#getHandler(java.lang.Class)
*/
@Override
public <T> AbstractDatabaseHandler<T> getHandler(Class<T> type) {
return new YamlDatabaseHandler<>(BentoBox.getInstance(), type, new YamlDatabaseConnector(BentoBox.getInstance()));

View File

@ -27,6 +27,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
import com.google.common.base.Charsets;
import org.eclipse.jdt.annotation.NonNull;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.database.DatabaseConnector;
@ -191,6 +192,7 @@ public class YamlDatabaseConnector implements DatabaseConnector {
}
@Override
@NonNull
public String getUniqueId(String tableName) {
UUID uuid = UUID.randomUUID();
File file = new File(dataFolder, tableName + File.separator + uuid.toString() + YML);