package br.com.fourdev.orderfood.repository.usuario;

import java.util.List;
import java.util.Optional;

import javax.persistence.EntityManager;

import org.springframework.beans.factory.annotation.Autowired;

import br.com.fourdev.orderfood.model.Usuario;

public class UsuariosImpl implements UsuariosQueries {

	@Autowired
	private EntityManager manager;

	@SuppressWarnings("unchecked")
	@Override
	public Optional<Usuario> porEmailEAtivo(String email) {
		String query = "SELECT  * from usuario WHERE email LIKE lower(:email) AND ativo = true";

		return manager
				.createNativeQuery(query, Usuario.class)
					.setParameter("email", email).getResultList()
						.stream().findFirst();
	}
	
	
	//jpql
	@Override
	public List<String> permissoes(Usuario usuario) {
		return manager.createQuery(
				"select distinct p.nome from Usuario u inner join u.grupos g inner join g.permissoes p where u = :usuario", String.class)
				.setParameter("usuario", usuario)
				.getResultList();
	}

}

@@ -115,97 +115,269 @@
 vax.
-persistence.EntityManager;%0A%0Aimport org.springframework.beans.factory.annotation.Autowired
+annotation.PostConstruct;%0Aimport javax.persistence.EntityManager;%0Aimport javax.persistence.Query;%0A%0Aimport org.springframework.beans.factory.annotation.Autowired;%0Aimport org.springframework.jdbc.core.JdbcTemplate;%0Aimport org.springframework.stereotype.Repository
 ;%0A%0Ai
@@ -423,16 +423,44 @@
 uario;%0A%0A
+@Repository(%22usuariosImpl%22)%0A
 public c
@@ -550,16 +550,66 @@
 manager;
+%0A%09%0A%09@Autowired%0A%09private JdbcTemplate jdbcTemplate;
 %0A%0A%09@Supp
@@ -702,16 +702,125 @@
 mail) %7B%0A
+%09%09String query1 = %22set search_path to orderfood, public%22;%0A%09%09jdbcTemplate.update(query1, new Object%5B%5D%7B%7D);%0A%0A%09%09%0A
 %09%09String
@@ -919,21 +919,16 @@
  manager
-%0A%09%09%09%09
 .createN
@@ -959,22 +959,16 @@
 o.class)
-%0A%09%09%09%09%09
 .setPara
@@ -1008,15 +1008,8 @@
 st()
-%0A%09%09%09%09%09%09
 .str
@@ -1013,16 +1013,21 @@
 stream()
+%0A%09%09%09%09
 .findFir
@@ -1039,15 +1039,13 @@
 %0A%09%7D%0A
-%09%0A%09
 %0A%09//
+ 
 jpql
@@ -1248,17 +1248,21 @@
 suario%22,
- 
+%0A%09%09%09%09
 String.c
@@ -1266,21 +1266,16 @@
 g.class)
-%0A%09%09%09%09
 .setPara
@@ -1299,21 +1299,16 @@
 usuario)
-%0A%09%09%09%09
 .getResu

ajuste para adicionar dinamicamente o schema padrão: "set search_path to orderfood"