mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-09-24 21:02:48 +02:00
Improved some documentation and added some nullability annotations in database code
This commit is contained in:
parent
3b0613c22a
commit
5dcec3ee1b
@ -1,9 +1,9 @@
|
|||||||
package world.bentobox.bentobox.database;
|
package world.bentobox.bentobox.database;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.annotation.NonNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* Creates a connection to a database.
|
* Creates a connection to a database.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public interface DatabaseConnector {
|
public interface DatabaseConnector {
|
||||||
|
|
||||||
@ -12,9 +12,9 @@ public interface DatabaseConnector {
|
|||||||
*
|
*
|
||||||
* @return A new connection to the database using the settings provided
|
* @return A new connection to the database using the settings provided
|
||||||
*/
|
*/
|
||||||
Object createConnection();
|
Object createConnection();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Close the database connection
|
* Close the database connection
|
||||||
*/
|
*/
|
||||||
void closeConnection();
|
void closeConnection();
|
||||||
@ -24,22 +24,25 @@ public interface DatabaseConnector {
|
|||||||
*
|
*
|
||||||
* @return the connector's URL
|
* @return the connector's URL
|
||||||
*/
|
*/
|
||||||
String getConnectionUrl();
|
String getConnectionUrl();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Looks through the database (or files) and returns a known unique key
|
* Looks through the database (or files) and returns a known unique key
|
||||||
|
*
|
||||||
* @param tableName - name of the table
|
* @param tableName - name of the table
|
||||||
* @return a unique key for this record
|
* @return a unique key for this record
|
||||||
*/
|
*/
|
||||||
String getUniqueId(String tableName);
|
@NonNull
|
||||||
|
String getUniqueId(String tableName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a key exists in the database in this table or not
|
* Check if a key exists in the database in this table or not
|
||||||
|
*
|
||||||
* @param tableName - name of the table
|
* @param tableName - name of the table
|
||||||
* @param key - key to check
|
* @param key - key to check
|
||||||
* @return true if it exists
|
* @return true if it exists
|
||||||
*/
|
*/
|
||||||
boolean uniqueIdExists(String tableName, String key);
|
boolean uniqueIdExists(String tableName, String key);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,9 @@ import world.bentobox.bentobox.database.DatabaseSetup;
|
|||||||
|
|
||||||
public class JSONDatabase implements DatabaseSetup {
|
public class JSONDatabase implements DatabaseSetup {
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see world.bentobox.bentobox.database.DatabaseSetup#getHandler(java.lang.Class)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public <T> AbstractDatabaseHandler<T> getHandler(Class<T> dataObjectClass) {
|
public <T> AbstractDatabaseHandler<T> getHandler(Class<T> dataObjectClass) {
|
||||||
return new JSONDatabaseHandler<>(BentoBox.getInstance(), dataObjectClass, new JSONDatabaseConnector(BentoBox.getInstance()));
|
return new JSONDatabaseHandler<>(BentoBox.getInstance(), dataObjectClass, new JSONDatabaseConnector(BentoBox.getInstance()));
|
||||||
|
@ -3,6 +3,7 @@ package world.bentobox.bentobox.database.json;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.annotation.NonNull;
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.database.DatabaseConnector;
|
import world.bentobox.bentobox.database.DatabaseConnector;
|
||||||
|
|
||||||
@ -18,6 +19,7 @@ public class JSONDatabaseConnector implements DatabaseConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@NonNull
|
||||||
public String getUniqueId(String tableName) {
|
public String getUniqueId(String tableName) {
|
||||||
UUID uuid = UUID.randomUUID();
|
UUID uuid = UUID.randomUUID();
|
||||||
File file = new File(dataFolder, tableName + File.separator + uuid.toString() + JSON);
|
File file = new File(dataFolder, tableName + File.separator + uuid.toString() + JSON);
|
||||||
|
@ -12,7 +12,7 @@ import world.bentobox.bentobox.database.DatabaseSetup;
|
|||||||
public class MariaDBDatabase implements DatabaseSetup {
|
public class MariaDBDatabase implements DatabaseSetup {
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see world.bentobox.bentobox.database.BSBDbSetup#getHandler(java.lang.Class)
|
* @see world.bentobox.bentobox.database.DatabaseSetup#getHandler(java.lang.Class)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public <T> AbstractDatabaseHandler<T> getHandler(Class<T> type) {
|
public <T> AbstractDatabaseHandler<T> getHandler(Class<T> type) {
|
||||||
|
@ -6,6 +6,7 @@ import java.sql.SQLException;
|
|||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.annotation.NonNull;
|
||||||
import world.bentobox.bentobox.database.DatabaseConnectionSettingsImpl;
|
import world.bentobox.bentobox.database.DatabaseConnectionSettingsImpl;
|
||||||
import world.bentobox.bentobox.database.DatabaseConnector;
|
import world.bentobox.bentobox.database.DatabaseConnector;
|
||||||
|
|
||||||
@ -45,6 +46,7 @@ public class MariaDBDatabaseConnector implements DatabaseConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@NonNull
|
||||||
public String getUniqueId(String tableName) {
|
public String getUniqueId(String tableName) {
|
||||||
// Not used
|
// Not used
|
||||||
return "";
|
return "";
|
||||||
|
@ -9,6 +9,9 @@ import world.bentobox.bentobox.database.DatabaseSetup;
|
|||||||
|
|
||||||
public class MongoDBDatabase implements DatabaseSetup {
|
public class MongoDBDatabase implements DatabaseSetup {
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see world.bentobox.bentobox.database.DatabaseSetup#getHandler(java.lang.Class)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public <T> AbstractDatabaseHandler<T> getHandler(Class<T> type) {
|
public <T> AbstractDatabaseHandler<T> getHandler(Class<T> type) {
|
||||||
BentoBox plugin = BentoBox.getInstance();
|
BentoBox plugin = BentoBox.getInstance();
|
||||||
|
@ -6,6 +6,7 @@ import com.mongodb.MongoCredential;
|
|||||||
import com.mongodb.ServerAddress;
|
import com.mongodb.ServerAddress;
|
||||||
import com.mongodb.client.MongoDatabase;
|
import com.mongodb.client.MongoDatabase;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.annotation.NonNull;
|
||||||
import world.bentobox.bentobox.database.DatabaseConnectionSettingsImpl;
|
import world.bentobox.bentobox.database.DatabaseConnectionSettingsImpl;
|
||||||
import world.bentobox.bentobox.database.DatabaseConnector;
|
import world.bentobox.bentobox.database.DatabaseConnector;
|
||||||
|
|
||||||
@ -38,6 +39,7 @@ public class MongoDBDatabaseConnector implements DatabaseConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@NonNull
|
||||||
public String getUniqueId(String tableName) {
|
public String getUniqueId(String tableName) {
|
||||||
// Not used
|
// Not used
|
||||||
return "";
|
return "";
|
||||||
|
@ -7,9 +7,8 @@ import world.bentobox.bentobox.database.DatabaseSetup;
|
|||||||
|
|
||||||
public class MySQLDatabase implements DatabaseSetup {
|
public class MySQLDatabase implements DatabaseSetup {
|
||||||
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see world.bentobox.bentobox.database.BSBDbSetup#getHandler(java.lang.Class)
|
* @see world.bentobox.bentobox.database.DatabaseSetup#getHandler(java.lang.Class)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public <T> AbstractDatabaseHandler<T> getHandler(Class<T> type) {
|
public <T> AbstractDatabaseHandler<T> getHandler(Class<T> type) {
|
||||||
|
@ -6,6 +6,7 @@ import java.sql.SQLException;
|
|||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.annotation.NonNull;
|
||||||
import world.bentobox.bentobox.database.DatabaseConnectionSettingsImpl;
|
import world.bentobox.bentobox.database.DatabaseConnectionSettingsImpl;
|
||||||
import world.bentobox.bentobox.database.DatabaseConnector;
|
import world.bentobox.bentobox.database.DatabaseConnector;
|
||||||
|
|
||||||
@ -41,6 +42,7 @@ public class MySQLDatabaseConnector implements DatabaseConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@NonNull
|
||||||
public String getUniqueId(String tableName) {
|
public String getUniqueId(String tableName) {
|
||||||
// Not used
|
// Not used
|
||||||
return "";
|
return "";
|
||||||
|
@ -16,6 +16,9 @@ public class YamlDatabase implements DatabaseSetup {
|
|||||||
return new ConfigHandler<>(BentoBox.getInstance(), type, new YamlDatabaseConnector(BentoBox.getInstance()));
|
return new ConfigHandler<>(BentoBox.getInstance(), type, new YamlDatabaseConnector(BentoBox.getInstance()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see world.bentobox.bentobox.database.DatabaseSetup#getHandler(java.lang.Class)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public <T> AbstractDatabaseHandler<T> getHandler(Class<T> type) {
|
public <T> AbstractDatabaseHandler<T> getHandler(Class<T> type) {
|
||||||
return new YamlDatabaseHandler<>(BentoBox.getInstance(), type, new YamlDatabaseConnector(BentoBox.getInstance()));
|
return new YamlDatabaseHandler<>(BentoBox.getInstance(), type, new YamlDatabaseConnector(BentoBox.getInstance()));
|
||||||
|
@ -27,6 +27,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
|||||||
|
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.annotation.NonNull;
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.database.DatabaseConnector;
|
import world.bentobox.bentobox.database.DatabaseConnector;
|
||||||
|
|
||||||
@ -191,6 +192,7 @@ public class YamlDatabaseConnector implements DatabaseConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@NonNull
|
||||||
public String getUniqueId(String tableName) {
|
public String getUniqueId(String tableName) {
|
||||||
UUID uuid = UUID.randomUUID();
|
UUID uuid = UUID.randomUUID();
|
||||||
File file = new File(dataFolder, tableName + File.separator + uuid.toString() + YML);
|
File file = new File(dataFolder, tableName + File.separator + uuid.toString() + YML);
|
||||||
|
Loading…
Reference in New Issue
Block a user