Browse Source

User_Role: implement deleteByCompositeId method

Signed-off-by: Pekka Helenius <fincer89@hotmail.com>
v0.0.4-alpha
Pekka Helenius 4 years ago
parent
commit
b78af35a58
2 changed files with 16 additions and 0 deletions
  1. +2
    -0
      bookstore/src/main/java/com/fjordtek/bookstore/model/auth/UserRoleRepositoryCustom.java
  2. +14
    -0
      bookstore/src/main/java/com/fjordtek/bookstore/model/auth/UserRoleRepositoryImpl.java

+ 2
- 0
bookstore/src/main/java/com/fjordtek/bookstore/model/auth/UserRoleRepositoryCustom.java View File

@ -11,4 +11,6 @@ package com.fjordtek.bookstore.model.auth;
public interface UserRoleRepositoryCustom { public interface UserRoleRepositoryCustom {
UserRole findByCompositeId(Long userId, Long roleId); UserRole findByCompositeId(Long userId, Long roleId);
void deleteByCompositeId(Long userId, Long roleId);
} }

+ 14
- 0
bookstore/src/main/java/com/fjordtek/bookstore/model/auth/UserRoleRepositoryImpl.java View File

@ -4,6 +4,7 @@ package com.fjordtek.bookstore.model.auth;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext; import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.persistence.TypedQuery; import javax.persistence.TypedQuery;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -45,4 +46,17 @@ public class UserRoleRepositoryImpl implements UserRoleRepositoryCustom {
} }
} }
@Override
public void deleteByCompositeId(Long userId, Long roleId) {
Query query = entityManager.createQuery(
"DELETE FROM UserRole" +
" WHERE user_id = :user_id" +
" AND role_id = :role_id"
);
query.setParameter("user_id", userId);
query.setParameter("role_id", roleId);
query.executeUpdate();
}
} }

Loading…
Cancel
Save