diff --git a/plugin/src/main/java/io/github/zrdzn/minecraft/lovelydrop/storage/Storage.java b/plugin/src/main/java/io/github/zrdzn/minecraft/lovelydrop/storage/Storage.java index af1d000..8f6d19f 100644 --- a/plugin/src/main/java/io/github/zrdzn/minecraft/lovelydrop/storage/Storage.java +++ b/plugin/src/main/java/io/github/zrdzn/minecraft/lovelydrop/storage/Storage.java @@ -1,9 +1,12 @@ package io.github.zrdzn.minecraft.lovelydrop.storage; +import org.jetbrains.annotations.Nullable; + import javax.sql.DataSource; /** * Class that represents storage by holding data source instance with associated storage type. + * Some storage types may not have data source instance, such as in-memory storage, therefore data source instance is nullable. */ public class Storage { @@ -15,6 +18,7 @@ public Storage(DataSource dataSource, StorageType type) { this.type = type; } + @Nullable public DataSource getDataSource() { return this.dataSource; } diff --git a/plugin/src/main/java/io/github/zrdzn/minecraft/lovelydrop/storage/StorageFactory.java b/plugin/src/main/java/io/github/zrdzn/minecraft/lovelydrop/storage/StorageFactory.java index 9e899d1..4d99761 100644 --- a/plugin/src/main/java/io/github/zrdzn/minecraft/lovelydrop/storage/StorageFactory.java +++ b/plugin/src/main/java/io/github/zrdzn/minecraft/lovelydrop/storage/StorageFactory.java @@ -122,6 +122,12 @@ public Storage createStorage() { break; case IN_MEMORY: + logger.info("Choosing in-memory as a storage provider."); + + dataSource = null; + storageType = StorageType.IN_MEMORY; + + break; default: throw new IllegalArgumentException("There is no such storage type."); } diff --git a/plugin/src/main/java/io/github/zrdzn/minecraft/lovelydrop/user/infra/SqlUserSettingRepository.java b/plugin/src/main/java/io/github/zrdzn/minecraft/lovelydrop/user/infra/SqlUserSettingRepository.java index 0596cd5..2bef47a 100644 --- a/plugin/src/main/java/io/github/zrdzn/minecraft/lovelydrop/user/infra/SqlUserSettingRepository.java +++ b/plugin/src/main/java/io/github/zrdzn/minecraft/lovelydrop/user/infra/SqlUserSettingRepository.java @@ -4,13 +4,7 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.UUID; +import java.util.*; import javax.sql.DataSource; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; @@ -31,8 +25,8 @@ class SqlUserSettingRepository implements UserSettingRepository { public SqlUserSettingRepository(DataSource dataSource, Gson gson, String createOrUpdateUserSettingQuery, String findUserSettingByPlayerId) { - this.dataSource = dataSource; - this.gson = gson; + this.dataSource = Objects.requireNonNull(dataSource, "Data source cannot be null."); + this.gson = Objects.requireNonNull(gson, "Gson cannot be null."); this.createOrUpdateUserSettingQuery = createOrUpdateUserSettingQuery; this.findUserSettingByPlayerId = findUserSettingByPlayerId;