From e13c5580bc3146840df75d14cc01e8a1166dc36c Mon Sep 17 00:00:00 2001 From: Gravit Date: Mon, 3 Jun 2019 14:03:17 +0700 Subject: [PATCH] =?UTF-8?q?[FEATURE]=20=D0=9E=D0=B1=D0=BE=D0=B1=D1=89?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20UserDAO.=20=D0=9A=D0=BE=D0=BC=D0=B0?= =?UTF-8?q?=D0=BD=D0=B4=D0=B0=20=D1=80=D0=B5=D0=B3=D0=B8=D1=81=D1=82=D1=80?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D0=B8=20=D0=B8=20=D1=81=D1=82=D0=B0=D0=BD?= =?UTF-8?q?=D0=B4=D0=B0=D1=80=D1=82=D0=BD=D1=8B=D0=B9=20UserDAO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/handler/HibernateAuthHandler.java | 2 +- .../auth/provider/HibernateAuthProvider.java | 2 +- .../command/dao/RegisterCommand.java | 33 ++++++++++++++ .../HibernateConfiguratorComponent.java | 6 +-- .../dao/LaunchServerDaoFactory.java | 4 +- .../launchserver/{hibernate => dao}/User.java | 2 +- .../pro/gravit/launchserver/dao/UserDAO.java | 2 - .../gravit/launchserver/dao/UserService.java | 1 - .../dao/impl/DefaultUserDAOImpl.java | 45 +++++++++++++++++++ .../impl/HibernateUserDAOImpl.java} | 6 ++- 10 files changed, 91 insertions(+), 12 deletions(-) create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/RegisterCommand.java rename LaunchServer/src/main/java/pro/gravit/launchserver/{hibernate => dao}/User.java (97%) create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/DefaultUserDAOImpl.java rename LaunchServer/src/main/java/pro/gravit/launchserver/{hibernate/UserDAOImpl.java => dao/impl/HibernateUserDAOImpl.java} (92%) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/HibernateAuthHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/HibernateAuthHandler.java index c249d50d..c746232f 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/HibernateAuthHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/handler/HibernateAuthHandler.java @@ -1,7 +1,7 @@ package pro.gravit.launchserver.auth.handler; import pro.gravit.launchserver.LaunchServer; -import pro.gravit.launchserver.hibernate.User; +import pro.gravit.launchserver.dao.User; import java.io.IOException; import java.util.UUID; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/HibernateAuthProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/HibernateAuthProvider.java index d2bb7c22..cb4b6ab7 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/HibernateAuthProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/provider/HibernateAuthProvider.java @@ -2,7 +2,7 @@ import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.auth.AuthException; -import pro.gravit.launchserver.hibernate.User; +import pro.gravit.launchserver.dao.User; import pro.gravit.utils.helper.SecurityHelper; import java.io.IOException; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/RegisterCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/RegisterCommand.java new file mode 100644 index 00000000..83e0f5b3 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/dao/RegisterCommand.java @@ -0,0 +1,33 @@ +package pro.gravit.launchserver.command.dao; + +import pro.gravit.launchserver.LaunchServer; +import pro.gravit.launchserver.command.Command; +import pro.gravit.launchserver.dao.User; + +import java.util.UUID; + +public class RegisterCommand extends Command { + public RegisterCommand(LaunchServer server) { + super(server); + } + + @Override + public String getArgsDescription() { + return "[login] [password]"; + } + + @Override + public String getUsageDescription() { + return "Register new user"; + } + + @Override + public void invoke(String... args) throws Exception { + verifyArgs(args, 2); + User user = new User(); + user.username = args[0]; + user.setPassword(args[1]); + user.uuid = UUID.randomUUID(); + LaunchServer.server.userService.saveUser(user); + } +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/components/HibernateConfiguratorComponent.java b/LaunchServer/src/main/java/pro/gravit/launchserver/components/HibernateConfiguratorComponent.java index 7ecfb6fe..e3e03507 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/components/HibernateConfiguratorComponent.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/components/HibernateConfiguratorComponent.java @@ -4,8 +4,8 @@ import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.dao.LaunchServerDaoFactory; import pro.gravit.launchserver.hibernate.HibernateManager; -import pro.gravit.launchserver.hibernate.User; -import pro.gravit.launchserver.hibernate.UserDAOImpl; +import pro.gravit.launchserver.dao.User; +import pro.gravit.launchserver.dao.impl.HibernateUserDAOImpl; import pro.gravit.utils.helper.CommonHelper; import java.nio.file.Paths; @@ -20,7 +20,7 @@ public class HibernateConfiguratorComponent extends Component { public boolean parallelHibernateInit; @Override public void preInit(LaunchServer launchServer) { - LaunchServerDaoFactory.setUserDaoProvider(UserDAOImpl::new); + LaunchServerDaoFactory.setUserDaoProvider(HibernateUserDAOImpl::new); Runnable init = () -> { Configuration cfg = new Configuration() .addAnnotatedClass(User.class) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/LaunchServerDaoFactory.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/LaunchServerDaoFactory.java index 80509f86..86e69ab7 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/LaunchServerDaoFactory.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/LaunchServerDaoFactory.java @@ -1,9 +1,11 @@ package pro.gravit.launchserver.dao; +import pro.gravit.launchserver.dao.impl.DefaultUserDAOImpl; + import java.util.function.Supplier; public class LaunchServerDaoFactory { - private static Supplier getUserDao; + private static Supplier getUserDao = DefaultUserDAOImpl::new; public static void setUserDaoProvider(Supplier getDao) { LaunchServerDaoFactory.getUserDao = getDao; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/hibernate/User.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/User.java similarity index 97% rename from LaunchServer/src/main/java/pro/gravit/launchserver/hibernate/User.java rename to LaunchServer/src/main/java/pro/gravit/launchserver/dao/User.java index 54672c27..43c7c79e 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/hibernate/User.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/User.java @@ -1,4 +1,4 @@ -package pro.gravit.launchserver.hibernate; +package pro.gravit.launchserver.dao; import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.SecurityHelper; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserDAO.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserDAO.java index 605d52c8..e400ff79 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserDAO.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserDAO.java @@ -1,7 +1,5 @@ package pro.gravit.launchserver.dao; -import pro.gravit.launchserver.hibernate.User; - import java.util.List; import java.util.UUID; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserService.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserService.java index 8f647502..643a55d3 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserService.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/UserService.java @@ -1,7 +1,6 @@ package pro.gravit.launchserver.dao; import pro.gravit.launchserver.LaunchServer; -import pro.gravit.launchserver.hibernate.User; import java.util.List; import java.util.UUID; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/DefaultUserDAOImpl.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/DefaultUserDAOImpl.java new file mode 100644 index 00000000..54c34c4c --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/DefaultUserDAOImpl.java @@ -0,0 +1,45 @@ +package pro.gravit.launchserver.dao.impl; + +import pro.gravit.launchserver.dao.User; +import pro.gravit.launchserver.dao.UserDAO; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class DefaultUserDAOImpl implements UserDAO { + @Override + public User findById(int id) { + return null; + } + + @Override + public User findByUsername(String username) { + return null; + } + + @Override + public User findByUUID(UUID uuid) { + return null; + } + + @Override + public void save(User user) { + throw new UnsupportedOperationException(); + } + + @Override + public void update(User user) { + throw new UnsupportedOperationException(); + } + + @Override + public void delete(User user) { + throw new UnsupportedOperationException(); + } + + @Override + public List findAll() { + return new ArrayList<>(); + } +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/hibernate/UserDAOImpl.java b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/HibernateUserDAOImpl.java similarity index 92% rename from LaunchServer/src/main/java/pro/gravit/launchserver/hibernate/UserDAOImpl.java rename to LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/HibernateUserDAOImpl.java index 95c91009..4c385026 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/hibernate/UserDAOImpl.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/dao/impl/HibernateUserDAOImpl.java @@ -1,8 +1,10 @@ -package pro.gravit.launchserver.hibernate; +package pro.gravit.launchserver.dao.impl; import org.hibernate.Session; import org.hibernate.Transaction; +import pro.gravit.launchserver.dao.User; import pro.gravit.launchserver.dao.UserDAO; +import pro.gravit.launchserver.hibernate.HibernateManager; import javax.persistence.EntityManager; import javax.persistence.criteria.CriteriaBuilder; @@ -11,7 +13,7 @@ import java.util.List; import java.util.UUID; -public class UserDAOImpl implements UserDAO { +public class HibernateUserDAOImpl implements UserDAO { public User findById(int id) { return HibernateManager.sessionFactory.openSession().get(User.class, id);