How to use remove method of org.cerberus.crud.dao.impl.UserRoleDAO class

Best Cerberus-source code snippet using org.cerberus.crud.dao.impl.UserRoleDAO.remove

Source:UserRoleDAO.java Github

copy

Full Screen

...109 }110 return bool;111 }112 @Override113 public boolean removeRoleFromUser(UserRole role, User user) {114 boolean bool = false;115 final String query = "DELETE FROM userrole WHERE login = ? AND Role = ?";116 Connection connection = this.databaseSpring.connect();117 try {118 PreparedStatement preStat = connection.prepareStatement(query);119 try {120 preStat.setString(1, user.getLogin());121 preStat.setString(2, role.getRole());122 int res = preStat.executeUpdate();123 bool = res > 0;124 } catch (SQLException exception) {125 LOG.warn("Unable to execute query : "+exception.toString());126 } finally {127 preStat.close();128 }129 } catch (SQLException exception) {130 LOG.warn("Unable to execute query : "+exception.toString());131 } finally {132 try {133 if (connection != null) {134 connection.close();135 }136 } catch (SQLException e) {137 LOG.warn(e.toString());138 }139 }140 return bool;141 }142 @Override143 public List<UserRole> findRoleByKey(String login) {144 List<UserRole> list = null;145 final String query = "SELECT Role FROM userrole WHERE login = ? ORDER BY Role";146 Connection connection = this.databaseSpring.connect();147 try {148 PreparedStatement preStat = connection.prepareStatement(query);149 try {150 preStat.setString(1, login);151 ResultSet resultSet = preStat.executeQuery();152 try {153 list = new ArrayList<>();154 while (resultSet.next()) {155 UserRole role = factoryGroup.create(resultSet.getString("Role"));156 list.add(role);157 }158 } catch (SQLException exception) {159 LOG.warn("Unable to execute query : "+exception.toString());160 } finally {161 resultSet.close();162 }163 } catch (SQLException exception) {164 LOG.warn("Unable to execute query : "+exception.toString());165 } finally {166 preStat.close();167 }168 } catch (SQLException exception) {169 LOG.warn("Unable to execute query : "+exception.toString());170 } finally {171 try {172 if (connection != null) {173 connection.close();174 }175 } catch (SQLException e) {176 LOG.warn(e.toString());177 }178 }179 return list;180 }181 @Override182 public AnswerList<UserRole> readByUser(String login) {183 AnswerList<UserRole> ans = new AnswerList<>();184 MessageEvent msg = null;185 try (Connection connection = databaseSpring.connect();186 PreparedStatement preStat = connection.prepareStatement(Query.READ_BY_USER)) {187 // Prepare and execute query188 preStat.setString(1, login);189 try(ResultSet resultSet = preStat.executeQuery();){190 List<UserRole> result = new ArrayList<>();191 while (resultSet.next()) {192 result.add(loadUserGroupFromResultSet(resultSet));193 }194 ans.setDataList(result);195 // Set the final message196 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK).resolveDescription("ITEM", OBJECT_NAME)197 .resolveDescription("OPERATION", "CREATE");198 }catch (SQLException exception) {199 LOG.error("Unable to execute query : " + exception.toString());200 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);201 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));202 } 203 } catch (Exception e) {204 LOG.warn("Unable to read UserGroup: " + e.getMessage());205 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION",206 e.toString());207 } finally {208 ans.setResultMessage(msg);209 }210 return ans;211 }212 @Override213 public Answer create(UserRole role) {214 Answer ans = new Answer(new MessageEvent(MessageEventEnum.DATA_OPERATION_OK));215 MessageEvent msg = null;216 try (Connection connection = databaseSpring.connect();217 PreparedStatement preStat = connection.prepareStatement(Query.CREATE)) {218 // Prepare and execute query219 preStat.setString(1, role.getLogin());220 preStat.setString(2, role.getRole());221 preStat.executeUpdate();222 // Set the final message223 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK).resolveDescription("ITEM", OBJECT_NAME)224 .resolveDescription("OPERATION", "CREATE");225 } catch (Exception e) {226 LOG.warn("Unable to create userGroup: " + e.getMessage());227 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION",228 e.toString());229 } finally {230 ans.setResultMessage(msg);231 }232 return ans;233 }234 @Override235 public Answer remove(UserRole role) {236 Answer ans = new Answer(new MessageEvent(MessageEventEnum.DATA_OPERATION_OK));237 MessageEvent msg = null;238 try (Connection connection = databaseSpring.connect();239 PreparedStatement preStat = connection.prepareStatement(Query.DELETE)) {240 // Prepare and execute query241 preStat.setString(1, role.getLogin());242 preStat.setString(2, role.getRole());243 preStat.executeUpdate();244 // Set the final message245 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK).resolveDescription("ITEM", OBJECT_NAME)246 .resolveDescription("OPERATION", "DELETE");247 } catch (Exception e) {248 LOG.warn("Unable to delete userGroup: " + e.getMessage());249 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION",250 e.toString());251 } finally {252 ans.setResultMessage(msg);253 }254 return ans;255 }256 @Override257 public Answer removeRoleByUser(UserRole role, User user) {258 return null;259 }260 private UserRole loadUserGroupFromResultSet(ResultSet rs) throws SQLException {261 String login = ParameterParserUtil.parseStringParam(rs.getString("login"), "");262 String role = ParameterParserUtil.parseStringParam(rs.getString("Role"), "");263 return factoryGroup.create(login, role);264 }265}...

Full Screen

Full Screen

Source:UserRoleService.java Github

copy

Full Screen

...50 List<UserRole> oldRoles = this.findRoleByKey(user.getLogin());51 //delete if don't exist in new52 for (UserRole old : oldRoles) {53 if (!newRoles.contains(old)) {54 this.removeRoleFromUser(old, user);55 }56 }57 //insert if don't exist in old58 for (UserRole role : newRoles) {59 if (!oldRoles.contains(role)) {60 this.addRoleToUser(role, user);61 }62 }63 }64 private void addRoleToUser(UserRole role, User user) throws CerberusException {65 if (!userRoleDAO.addRoleToUser(role, user)) {66 //TODO define message => error occur trying to add role user67 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.NO_DATA_FOUND));68 }69 }70 private void removeRoleFromUser(UserRole role, User user) throws CerberusException {71 if (!userRoleDAO.removeRoleFromUser(role, user)) {72 //TODO define message => error occur trying to delete role user73 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.NO_DATA_FOUND));74 }75 }76 @Override77 public List<UserRole> findRoleByKey(String login) throws CerberusException {78 List<UserRole> list = userRoleDAO.findRoleByKey(login);79 if (list == null) {80 //TODO define message => error occur trying to find role user81 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.NO_DATA_FOUND));82 }83 return list;84 }85 @Override86 public AnswerList<UserRole> readByUser(String login) {87 return userRoleDAO.readByUser(login);88 }89 @Override90 public Answer updateRolesByUser(User user, List<UserRole> newRoles) {91 Answer a = new Answer(new MessageEvent(MessageEventEnum.DATA_OPERATION_OK).resolveDescription("ITEM", OBJECT_NAME)92 .resolveDescription("OPERATION", "UPDATE"));93 AnswerList<UserRole> an = this.readByUser(user.getLogin());94 if (an.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {95 List<UserRole> oldRoles = an.getDataList();96 //delete if don't exist in new97 for (UserRole old : oldRoles) {98 if (!newRoles.contains(old)) {99 Answer del = userRoleDAO.remove(old);100 if (!del.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {101 a = del;102 }103 }104 }105 //insert if don't exist in old106 for (UserRole role : newRoles) {107 if (!oldRoles.contains(role)) {108 Answer add = userRoleDAO.create(role);109 if (!add.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {110 a = add;111 }112 }113 }...

Full Screen

Full Screen

remove

Using AI Code Generation

copy

Full Screen

1package org.cerberus.crud.dao.impl;2import org.cerberus.crud.dao.IUserRoleDAO;3import org.cerberus.crud.entity.UserRole;4import org.cerberus.database.DatabaseSpring;5import org.cerberus.util.SqlUtil;6import org.springframework.beans.factory.annotation.Autowired;7import org.springframework.stereotype.Repository;8 * @author @author {author}9public class UserRoleDAO implements IUserRoleDAO {10 private DatabaseSpring databaseSpring;11 private final String OBJECT_NAME = "UserRole";12 private final int MAX_ROW_SELECTED = 100000;13 public void delete(UserRole userRole) {14 final String query = "DELETE FROM userrole WHERE User = ? AND System = ? AND Role = ?";15 try (Connection connection = this.databaseSpring.connect();16 PreparedStatement preStat = connection.prepareStatement(query);) {17 preStat.setString(1, userRole.getUser());18 preStat.setString(2, userRole.getSystem());19 preStat.setString(3, userRole.getRole());20 preStat.executeUpdate();21 } catch (SQLException exception) {22 LOG.error("Unable to execute query : " + exception.toString(), exception);23 }24 }25}26package org.cerberus.crud.dao.impl;27import java.sql.Connection;28import java.sql.PreparedStatement;29import java.sql.ResultSet;30import java.sql.SQLException;31import java.util.ArrayList;32import java.util.List;33import org.apache.logging.log4j.LogManager;34import org.apache.logging.log4j.Logger;35import org.cerberus.crud.dao.IUserRoleDAO;36import org.cerberus.crud.entity.UserRole;37import org.cerberus.database.DatabaseSpring;38import org.cerberus.util.SqlUtil;39import org.springframework.beans.factory.annotation.Autowired;40import org.springframework.stereotype.Repository;41 * @author @author {author}42public class UserRoleDAO implements IUserRoleDAO {43 private DatabaseSpring databaseSpring;44 private final String OBJECT_NAME = "UserRole";45 private final int MAX_ROW_SELECTED = 100000;46 public void update(UserRole userRole) {

Full Screen

Full Screen

remove

Using AI Code Generation

copy

Full Screen

1package org.cerberus.crud.dao.impl;2import org.cerberus.crud.entity.UserRole;3import org.cerberus.crud.entity.UserRolePK;4import org.cerberus.crud.factory.IFactoryUserRole;5import org.springframework.beans.factory.annotation.Autowired;6import org.springframework.stereotype.Repository;7public class UserRoleDAO implements IUserRoleDAO {8 private IFactoryUserRole factoryUserRole;9 public UserRole findUserRoleByKey(String system, String login) {10 }11 public UserRole findUserRoleByKey(UserRolePK userRolePK) {12 }13 public boolean createUserRole(UserRole userRole) {14 }15 public boolean deleteUserRole(UserRole userRole) {16 }17 public boolean updateUserRole(UserRole userRole) {18 }19 public boolean deleteUserRoleByKey(String system, String login) {20 }21 public boolean deleteUserRoleByKey(UserRolePK userRolePK) {22 }23 public boolean exist(String system, String login) {24 }25 public boolean exist(UserRolePK userRolePK) {26 }27}28package org.cerberus.crud.dao.impl;29import org.cerberus.crud.entity.User

Full Screen

Full Screen

remove

Using AI Code Generation

copy

Full Screen

1package org.cerberus.crud.dao.impl;2import java.util.List;3import org.cerberus.crud.entity.UserRole;4import org.cerberus.crud.dao.IUserRoleDAO;5import org.springframework.stereotype.Repository;6import org.springframework.transaction.annotation.Transactional;7import org.springframework.beans.factory.annotation.Autowired;8import org.springframework.orm.hibernate3.HibernateTemplate;9import org.springframework.orm.hibernate3.support.HibernateDaoSupport;10public class UserRoleDAO extends HibernateDaoSupport implements IUserRoleDAO {11 public UserRoleDAO(HibernateTemplate template) {12 super.setHibernateTemplate(template);13 }14 @Transactional(readOnly = true, timeout = 10000)15 public List<UserRole> findAll() {16 return super.getHibernateTemplate().loadAll(UserRole.class);17 }18 @Transactional(readOnly = true, timeout = 10000)19 public UserRole findUserRoleByKey(String system, String login) {20 return super.getHibernateTemplate().get(UserRole.class, new UserRole(system, login));21 }22 @Transactional(readOnly = false, timeout = 10000)23 public void insertUserRole(UserRole userRole) {24 super.getHibernateTemplate().save(userRole);25 }26 @Transactional(readOnly = false, timeout = 10000)27 public void updateUserRole(UserRole userRole) {28 super.getHibernateTemplate().update(userRole);29 }30 @Transactional(readOnly = false, timeout = 10000)31 public void deleteUserRole(UserRole userRole) {32 super.getHibernateTemplate().delete(userRole);33 }34 @Transactional(readOnly = false, timeout = 10000)35 public void deleteUserRoleByKey(String system, String login) {36 UserRole userRole = this.findUserRoleByKey(system, login);37 if (userRole != null) {38 super.getHibernateTemplate().delete(userRole);39 }40 }41}42package org.cerberus.crud.service.impl;43import java.util.List;44import org.cerberus.crud.entity.UserRole;45import org.cerberus.crud.dao.IUserRoleDAO;46import org.cerberus.crud.service.IUserRoleService;47import org.springframework.stereotype.Service;48import org.springframework.transaction.annotation.Transactional;49import org.springframework.beans.factory.annotation.Autowired;50import org.springframework.orm.hibernate3.HibernateTemplate;51import org.springframework

Full Screen

Full Screen

remove

Using AI Code Generation

copy

Full Screen

1package org.cerberus.crud.dao.impl;2import java.util.logging.Level;3import java.util.logging.Logger;4import org.cerberus.crud.dao.IUserRoleDAO;5import org.cerberus.crud.entity.UserRole;6import org.cerberus.database.DatabaseSpring;7import org.cerberus.exception.CerberusException;8import org.springframework.beans.factory.annotation.Autowired;9import org.springframework.stereotype.Repository;10public class UserRoleDAO implements IUserRoleDAO {11 private DatabaseSpring databaseSpring;12 private static final Logger LOG = Logger.getLogger(UserRoleDAO.class.getName());13 private final String OBJECT_NAME = "UserRole";14 private final int MAX_ROW_SELECTED = 10000;15 public void create(UserRole userRole) throws CerberusException {16 boolean throwExcep = false;17 StringBuilder query = new StringBuilder();18 query.append("INSERT INTO userrole (`User`, `Role`) VALUES (?, ?)");19 try (Connection connection = this.databaseSpring.connect();20 PreparedStatement preStat = connection.prepareStatement(query.toString())) {21 preStat.setString(1, userRole.getUser());22 preStat.setString(2, userRole.getRole());23 preStat.executeUpdate();24 throwExcep = false;25 } catch (SQLException exception) {26 LOG.log(Level.SEVERE, "Unable to execute query: {0} Exception: {1}", new Object[]{query.toString(), exception.toString()});27 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.EXECUTION_FA));28 }29 if (throwExcep) {30 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.EXECUTION_FA));31 }32 }33 public void delete(UserRole userRole) throws CerberusException {34 boolean throwExcep = false;35 final StringBuffer query = new StringBuffer("DELETE FROM userrole WHERE `User` = ? AND `Role` = ?");36 try (Connection connection = this.databaseSpring.connect();37 PreparedStatement preStat = connection.prepareStatement(query.toString())) {38 preStat.setString(1, userRole.getUser());39 preStat.setString(2, userRole.getRole());40 preStat.executeUpdate();41 throwExcep = false;42 } catch (SQLException exception) {43 LOG.log(Level.SEVERE, "Unable to execute query: {0} Exception: {1}", new Object[]{query

Full Screen

Full Screen

remove

Using AI Code Generation

copy

Full Screen

1package org.cerberus.crud.dao.impl;2import java.sql.Connection;3import java.sql.PreparedStatement;4import java.sql.SQLException;5import java.util.logging.Level;6import java.util.logging.Logger;7import org.cerberus.crud.dao.IUserRoleDAO;8import org.cerberus.database.DatabaseSpring;9import org.cerberus.exception.CerberusException;10import org.cerberus.log.MyLogger;11import org.springframework.beans.factory.annotation.Autowired;12import org.springframework.stereotype.Repository;13public class UserRoleDAO implements IUserRoleDAO {14 private DatabaseSpring databaseSpring;15 public void removeUserRole(String login, String role) throws CerberusException {16 final String query = "DELETE FROM userrole WHERE login = ? AND role = ?";17 Connection connection = this.databaseSpring.connect();18 try {19 PreparedStatement preStat = connection.prepareStatement(query);20 preStat.setString(1, login);21 preStat.setString(2, role);22 preStat.executeUpdate();23 preStat.close();24 } catch (SQLException exception) {25 MyLogger.log(UserRoleDAO.class.getName(), Level.FATAL, exception.toString());26 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.SQL_ERROR));27 } finally {28 this.databaseSpring.closeConnection(connection);29 }30 }31}32package org.cerberus.crud.dao.impl;33import java.sql.Connection;34import java.sql.PreparedStatement;35import java.sql.SQLException;36import java.util.logging.Level;37import java.util.logging.Logger;38import org.cerberus.crud.dao.IUserRoleDAO;39import org.cerberus.database.DatabaseSpring;40import org.cerberus.exception.CerberusException;41import org.cerberus.log.MyLogger;42import org.springframework.beans.factory.annotation.Autowired;43import org.springframework.stereotype.Repository;44public class UserRoleDAO implements IUserRoleDAO {

Full Screen

Full Screen

remove

Using AI Code Generation

copy

Full Screen

1package org.cerberus.crud.dao.impl;2import java.util.List;3import org.cerberus.crud.dao.IUserRoleDAO;4import org.cerberus.crud.entity.UserRole;5import org.cerberus.crud.factory.IFactoryUserRole;6import org.cerberus.database.DatabaseSpring;7import org.springframework.beans.factory.annotation.Autowired;8import org.springframework.stereotype.Repository;9public class UserRoleDAO implements IUserRoleDAO {10 private DatabaseSpring databaseSpring;11 private IFactoryUserRole factoryUserRole;12 private final String OBJECT_NAME = "UserRole";13 private final int MAX_ROW_SELECTED = 100000;14 public List<UserRole> findUserRoleBySystem(String system) {15 List<UserRole> result = null;16 final String query = "SELECT * FROM userrole WHERE system = ? LIMIT " + MAX_ROW_SELECTED;17 List<Object> param = new ArrayList<Object>();18 param.add(system);19 result = this.databaseSpring.query(query, param, factoryUserRole);20 return result;21 }22 public List<UserRole> findUserRoleByUser(String user) {23 List<UserRole> result = null;24 final String query = "SELECT * FROM userrole WHERE login = ? LIMIT " + MAX_ROW_SELECTED;25 List<Object> param = new ArrayList<Object>();26 param.add(user);27 result = this.databaseSpring.query(query, param, factoryUserRole);28 return result;29 }30 public void insertUserRole(UserRole userRole) {31 final String query = "INSERT INTO userrole (`login`, `system`, `role`) VALUES (?, ?, ?)";32 List<Object> param = new ArrayList<Object>();33 param.add(userRole.getLogin());34 param.add(userRole.getSystem());35 param.add(userRole.getRole());36 this.databaseSpring.update(query, param);37 }38 public void removeUserRole(UserRole userRole) {39 final String query = "DELETE FROM userrole WHERE login = ? AND system = ? AND role = ?";40 List<Object> param = new ArrayList<Object>();41 param.add(userRole.getLogin());42 param.add(userRole.getSystem());43 param.add(userRole.getRole());44 this.databaseSpring.update(query, param);45 }46 public boolean exist(UserRole userRole) {

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Cerberus-source automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful