Change save

This commit is contained in:
Paulo Gustavo Veiga 2023-10-29 22:26:14 -07:00
parent 2bc9d41e2f
commit eddd6899db
3 changed files with 11 additions and 13 deletions

View File

@ -42,7 +42,7 @@ public class LabelManagerImpl
@Override @Override
public void saveLabel(@NotNull final Label label) { public void saveLabel(@NotNull final Label label) {
getSession().save(label); getSession().persist(label);
} }
private Session getSession() { private Session getSession() {

View File

@ -87,7 +87,7 @@ public class MindmapManagerImpl
@Override @Override
public void updateCollaboration(@NotNull Collaboration collaboration) { public void updateCollaboration(@NotNull Collaboration collaboration) {
final Session session = getSession(); final Session session = getSession();
session.save(collaboration); session.persist(collaboration);
} }
@Override @Override
@ -111,7 +111,7 @@ public class MindmapManagerImpl
public void addCollaborator(@NotNull Collaborator collaborator) { public void addCollaborator(@NotNull Collaborator collaborator) {
final Session session = getSession(); final Session session = getSession();
assert collaborator != null : "ADD MINDMAP COLLABORATOR: Collaborator is required!"; assert collaborator != null : "ADD MINDMAP COLLABORATOR: Collaborator is required!";
session.save(collaborator); session.persist(collaborator);
} }
@Override @Override
@ -158,7 +158,7 @@ public class MindmapManagerImpl
@Override @Override
public void saveMindmap(Mindmap mindMap) { public void saveMindmap(Mindmap mindMap) {
assert mindMap != null : "Save Mindmap: Mindmap is required!"; assert mindMap != null : "Save Mindmap: Mindmap is required!";
getSession().save(mindMap); getSession().persist(mindMap);
} }
@Override @Override

View File

@ -25,7 +25,6 @@ import jakarta.annotation.Resource;
import org.hibernate.ObjectNotFoundException; import org.hibernate.ObjectNotFoundException;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;
import org.hibernate.query.Query;
import org.hibernate.query.SelectionQuery; import org.hibernate.query.SelectionQuery;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -48,9 +47,8 @@ public class UserManagerImpl
this.passwordEncoder = passwordEncoder; this.passwordEncoder = passwordEncoder;
} }
@SuppressWarnings("unchecked")
public List<User> getAllUsers() { public List<User> getAllUsers() {
return getSession().createQuery("from com.wisemapping.model.User user").list(); return getSession().createSelectionQuery("from com.wisemapping.model.User user", User.class).getResultList();
} }
private Session getSession() { private Session getSession() {
@ -63,10 +61,10 @@ public class UserManagerImpl
public User getUserBy(@NotNull final String email) { public User getUserBy(@NotNull final String email) {
User user = null; User user = null;
var query = getSession().createQuery("from com.wisemapping.model.User colaborator where email=:email"); SelectionQuery<User> query = getSession().createSelectionQuery("from com.wisemapping.model.User colaborator where email=:email",User.class);
query.setParameter("email", email); query.setParameter("email", email);
final List<User> users = query.list(); final List<User> users = query.getResultList();
if (users != null && !users.isEmpty()) { if (users != null && !users.isEmpty()) {
assert users.size() == 1 : "More than one user with the same email!"; assert users.size() == 1 : "More than one user with the same email!";
user = users.get(0); user = users.get(0);
@ -113,7 +111,7 @@ public class UserManagerImpl
} else { } else {
user.setPassword(""); user.setPassword("");
} }
getSession().saveOrUpdate(user); getSession().persist(user);
} }
@Override @Override
@ -123,7 +121,7 @@ public class UserManagerImpl
// Migrate from previous temporal collab to new user ... // Migrate from previous temporal collab to new user ...
final Session session = getSession(); final Session session = getSession();
collaborator.setEmail(collaborator.getEmail() + "_toRemove"); collaborator.setEmail(collaborator.getEmail() + "_toRemove");
session.saveOrUpdate(collaborator); session.merge(collaborator);
session.flush(); session.flush();
// Save all new... // Save all new...
@ -147,7 +145,7 @@ public class UserManagerImpl
public void auditLogin(@NotNull AccessAuditory accessAuditory) { public void auditLogin(@NotNull AccessAuditory accessAuditory) {
assert accessAuditory != null : "accessAuditory is null"; assert accessAuditory != null : "accessAuditory is null";
getSession().save(accessAuditory); getSession().persist(accessAuditory);
} }
public void updateUser(@NotNull User user) { public void updateUser(@NotNull User user) {
@ -159,7 +157,7 @@ public class UserManagerImpl
user.setPassword(passwordEncoder.encode(user.getPassword())); user.setPassword(passwordEncoder.encode(user.getPassword()));
} }
getSession().update(user); getSession().merge(user);
} }
public User getUserByActivationCode(long code) { public User getUserByActivationCode(long code) {