dizda13 2017-03-23 02:17:08 +01:00
commit 26d383d3f1
4 changed files with 70 additions and 13 deletions

View File

@ -0,0 +1,16 @@
package ba.steleks.repository;
/**
* Created by ensar on 22/03/17.
*/
import ba.steleks.repository.model.User;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import java.util.List;
public interface UserRolesJpaRepository extends CrudRepository<User, Long> {
List<User> findByUsername(@Param("username") String username);
}

View File

@ -4,15 +4,9 @@ package ba.steleks.repository;
* Created by ensar on 22/03/17. * Created by ensar on 22/03/17.
*/ */
import ba.steleks.repository.model.User; import ba.steleks.repository.model.UserRole;
import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import java.util.List; public interface UsersJpaRepository extends CrudRepository<UserRole, Long> {
public interface UsersJpaRepository extends PagingAndSortingRepository<User, Long> {
List<User> findByUsername(@Param("username") String username);
User findById(@Param("id") Long id);
} }

View File

@ -2,10 +2,8 @@ package ba.steleks.repository.model;/**
* Created by ensar on 22/03/17. * Created by ensar on 22/03/17.
*/ */
import javax.persistence.Entity; import javax.persistence.*;
import javax.persistence.GeneratedValue; import java.util.Set;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.util.logging.Logger; import java.util.logging.Logger;
@Entity @Entity
@ -29,6 +27,10 @@ public class User {
private long courseId; private long courseId;
private long membershipTypeId; private long membershipTypeId;
@ManyToMany
@JoinColumn
private Set<UserRole> userRoles;
public long getId() { public long getId() {
return id; return id;
} }
@ -124,4 +126,12 @@ public class User {
public void setMembershipTypeId(long membershipTypeId) { public void setMembershipTypeId(long membershipTypeId) {
this.membershipTypeId = membershipTypeId; this.membershipTypeId = membershipTypeId;
} }
public Set<UserRole> getUserRoles() {
return userRoles;
}
public void setUserRoles(Set<UserRole> userRoles) {
this.userRoles = userRoles;
}
} }

View File

@ -0,0 +1,37 @@
package ba.steleks.repository.model;/**
* Created by ensar on 22/03/17.
*/
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.util.logging.Logger;
@Entity
public class UserRole {
private static final Logger logger =
Logger.getLogger(UserRole.class.getName());
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
private String roleName;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getRoleName() {
return roleName;
}
public void setRoleName(String roleName) {
this.roleName = roleName;
}
}