Remove deprecated BasicDAO and dev.morphia and replace it with the proper dependency

This commit is contained in:
spacerocket62 2020-10-27 20:45:01 -07:00
parent fac87d8c66
commit f1744f2050
7 changed files with 36 additions and 27 deletions

View File

@ -49,9 +49,9 @@
<!-- DATABASING --> <!-- DATABASING -->
<dependency> <dependency>
<groupId>dev.morphia.morphia</groupId> <groupId>org.mongodb.morphia</groupId>
<artifactId>core</artifactId> <artifactId>morphia</artifactId>
<version>1.5.2</version> <version>1.3.2</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -1,9 +1,10 @@
package me.totalfreedom.plex.cache; package me.totalfreedom.plex.cache;
import dev.morphia.query.Query;
import dev.morphia.query.UpdateOperations;
import me.totalfreedom.plex.Plex; import me.totalfreedom.plex.Plex;
import me.totalfreedom.plex.player.PlexPlayer; import me.totalfreedom.plex.player.PlexPlayer;
import org.mongodb.morphia.query.FindOptions;
import org.mongodb.morphia.query.Query;
import org.mongodb.morphia.query.UpdateOperations;
import java.util.UUID; import java.util.UUID;
@ -21,7 +22,7 @@ public class MongoPlayerData
Query<PlexPlayer> query = plexPlayerDAO.createQuery(); Query<PlexPlayer> query = plexPlayerDAO.createQuery();
if (query.field("uuid").exists().field("uuid").equal(uuid.toString()).find().tryNext() != null) if (query.field("uuid").exists().field("uuid").equal(uuid.toString()).get() != null)
{ {
return true; return true;
} }
@ -35,7 +36,7 @@ public class MongoPlayerData
return PlayerCache.getPlexPlayerMap().get(uuid); return PlayerCache.getPlexPlayerMap().get(uuid);
} }
Query<PlexPlayer> query2 = plexPlayerDAO.createQuery().field("uuid").exists().field("uuid").equal(uuid.toString()); Query<PlexPlayer> query2 = plexPlayerDAO.createQuery().field("uuid").exists().field("uuid").equal(uuid.toString());
return query2.first(); return query2.get();
} }
public void update(PlexPlayer player) public void update(PlexPlayer player)
@ -48,7 +49,7 @@ public class MongoPlayerData
updateOps.set("name", player.getName()); updateOps.set("name", player.getName());
updateOps.set("loginMSG", player.getLoginMSG()); updateOps.set("loginMSG", player.getLoginMSG());
updateOps.set("prefix", player.getPrefix()); updateOps.set("prefix", player.getPrefix());
updateOps.set("rank", player.getRank() == null ? "" : player.getRank().name().toLowerCase()); updateOps.set("rank", player.getRank().toLowerCase());
updateOps.set("ips", player.getIps()); updateOps.set("ips", player.getIps());
updateOps.set("coins", player.getCoins()); updateOps.set("coins", player.getCoins());
plexPlayerDAO.update(filter, updateOps); plexPlayerDAO.update(filter, updateOps);

View File

@ -1,12 +1,12 @@
package me.totalfreedom.plex.cache; package me.totalfreedom.plex.cache;
import dev.morphia.Datastore;
import dev.morphia.Key;
import dev.morphia.dao.BasicDAO;
import dev.morphia.query.Query;
import dev.morphia.query.UpdateOperations;
import dev.morphia.query.UpdateResults;
import me.totalfreedom.plex.player.PlexPlayer; import me.totalfreedom.plex.player.PlexPlayer;
import org.mongodb.morphia.Datastore;
import org.mongodb.morphia.Key;
import org.mongodb.morphia.dao.BasicDAO;
import org.mongodb.morphia.query.Query;
import org.mongodb.morphia.query.UpdateOperations;
import org.mongodb.morphia.query.UpdateResults;
public class PlexPlayerDAO extends BasicDAO<PlexPlayer, Object> { public class PlexPlayerDAO extends BasicDAO<PlexPlayer, Object> {

View File

@ -60,7 +60,7 @@ public class SQLPlayerData
plexPlayer.setName(name); plexPlayer.setName(name);
plexPlayer.setLoginMSG(loginMSG); plexPlayer.setLoginMSG(loginMSG);
plexPlayer.setPrefix(prefix); plexPlayer.setPrefix(prefix);
plexPlayer.setRank(rankName.isEmpty() ? null : rank); plexPlayer.setRank(rankName.toLowerCase());
plexPlayer.setIps(ips); plexPlayer.setIps(ips);
plexPlayer.setCoins(coins); plexPlayer.setCoins(coins);
} }
@ -80,7 +80,7 @@ public class SQLPlayerData
statement.setString(1, player.getName()); statement.setString(1, player.getName());
statement.setString(2, player.getLoginMSG()); statement.setString(2, player.getLoginMSG());
statement.setString(3, player.getPrefix()); statement.setString(3, player.getPrefix());
statement.setString(4, player.getRank() == null ? "" : player.getRank().name().toLowerCase()); statement.setString(4, player.getRank().toLowerCase());
statement.setString(5, new Gson().toJson(player.getIps())); statement.setString(5, new Gson().toJson(player.getIps()));
statement.setLong(6, player.getCoins()); statement.setLong(6, player.getCoins());
statement.setString(7, player.getUuid()); statement.setString(7, player.getUuid());
@ -100,7 +100,7 @@ public class SQLPlayerData
statement.setString(2, player.getName()); statement.setString(2, player.getName());
statement.setString(3, player.getLoginMSG()); statement.setString(3, player.getLoginMSG());
statement.setString(4, player.getPrefix()); statement.setString(4, player.getPrefix());
statement.setString(5, player.getRank() == null ? "" : player.getRank().name().toLowerCase()); statement.setString(5, player.getRank().toLowerCase());
statement.setString(6, new Gson().toJson(player.getIps())); statement.setString(6, new Gson().toJson(player.getIps()));
statement.execute(); statement.execute();
} }

View File

@ -1,13 +1,13 @@
package me.totalfreedom.plex.player; package me.totalfreedom.plex.player;
import dev.morphia.annotations.Entity;
import dev.morphia.annotations.Id;
import dev.morphia.annotations.IndexOptions;
import dev.morphia.annotations.Indexed;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import me.totalfreedom.plex.rank.enums.Rank; import me.totalfreedom.plex.rank.enums.Rank;
import org.mongodb.morphia.annotations.Entity;
import org.mongodb.morphia.annotations.Id;
import org.mongodb.morphia.annotations.IndexOptions;
import org.mongodb.morphia.annotations.Indexed;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -35,7 +35,7 @@ public class PlexPlayer
private long coins; private long coins;
private Rank rank; private String rank;
private List<String> ips; private List<String> ips;
@ -56,7 +56,12 @@ public class PlexPlayer
this.ips = new ArrayList<>(); this.ips = new ArrayList<>();
this.rank = null; this.rank = "";
}
public Rank getRankFromString()
{
return Rank.valueOf(rank.toUpperCase());
} }
} }

View File

@ -2,10 +2,10 @@ package me.totalfreedom.plex.storage;
import com.mongodb.MongoClient; import com.mongodb.MongoClient;
import com.mongodb.MongoClientURI; import com.mongodb.MongoClientURI;
import dev.morphia.Datastore;
import dev.morphia.Morphia;
import me.totalfreedom.plex.Plex; import me.totalfreedom.plex.Plex;
import me.totalfreedom.plex.player.PlexPlayer; import me.totalfreedom.plex.player.PlexPlayer;
import org.mongodb.morphia.Datastore;
import org.mongodb.morphia.Morphia;
public class MongoConnection public class MongoConnection
{ {
@ -33,7 +33,7 @@ public class MongoConnection
Morphia morphia = new Morphia(); Morphia morphia = new Morphia();
Datastore datastore = morphia.createDatastore(client, database); Datastore datastore = morphia.createDatastore(client, database);
datastore.getMapper().addMappedClass(PlexPlayer.class); morphia.map(PlexPlayer.class);
datastore.ensureIndexes(); datastore.ensureIndexes();
plugin.setStorageType(StorageType.MONGO); plugin.setStorageType(StorageType.MONGO);

View File

@ -37,7 +37,9 @@ public class SQLConnection
} }
try { try {
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `players` (\n" + if (connection != null)
{
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `players` (\n" +
"\t`uuid` VARCHAR(46),\n" + "\t`uuid` VARCHAR(46),\n" +
"\t`name` VARCHAR(18),\n" + "\t`name` VARCHAR(18),\n" +
"\t`login_msg` VARCHAR(256),\n" + "\t`login_msg` VARCHAR(256),\n" +
@ -47,6 +49,7 @@ public class SQLConnection
"\t`coins` BIGINT,\n" + "\t`coins` BIGINT,\n" +
"\tPRIMARY KEY (`uuid`)\n" + "\tPRIMARY KEY (`uuid`)\n" +
");").execute(); ");").execute();
}
} catch (SQLException throwables) { } catch (SQLException throwables) {
throwables.printStackTrace(); throwables.printStackTrace();
} }