Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="UTF-8"?>
- <persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
- <persistence-unit name="GestorPU" transaction-type="RESOURCE_LOCAL">
- <provider>org.hibernate.ejb.HibernatePersistence</provider>
- <class>Entity.Cadgru</class>
- <exclude-unlisted-classes>true</exclude-unlisted-classes>
- <properties>
- <property name="hibernate.connection.driver_class" value="org.firebirdsql.jdbc.FBDriver"/>
- <property name="hibernate.connection.url" value="jdbc:firebirdsql:localhost/3050:C:BANCOSGESTOR.FDB"/>
- <property name="hibernate.connection.username" value="SYSDBA"/>
- <property name="hibernate.connection.password" value="masterkey"/>
- <property name="hibernate.dialect" value="org.hibernate.dialect.FirebirdDialect"/>
- </properties>
- </persistence-unit>
- <persistence-unit name="MitryusPU" transaction-type="RESOURCE_LOCAL">
- <provider>org.hibernate.ejb.HibernatePersistence</provider>
- <class>Entity.Cadusr</class>
- <class>Entity.Cadloj</class>
- <class>Entity.Cadfun</class>
- <class>Entity.Tipcli</class>
- <class>Entity.Tipven</class>
- <class>Entity.Vendas</class>
- <class>Entity.Venda_Sintetico</class>
- <class>Entity.CodigoPin</class>
- <class>Entity.Codloc</class>
- <class>Entity.VendaEvolucao</class>
- <exclude-unlisted-classes>true</exclude-unlisted-classes>
- <properties>
- <property name="hibernate.connection.driver_class" value="org.firebirdsql.jdbc.FBDriver"/>
- <property name="hibernate.connection.username" value="SYSDBA"/>
- <property name="hibernate.connection.password" value="masterkey"/>
- <property name="hibernate.dialect" value="org.hibernate.dialect.FirebirdDialect"/>
- </properties>
- </persistence-unit>
- </persistence>
- package DAO;
- import java.util.Properties;
- import javax.persistence.EntityManager;
- import javax.persistence.EntityManagerFactory;
- import javax.persistence.Persistence;
- public class Conexao {
- private static EntityManagerFactory emf ;
- public static EntityManager getEntityManager(String PU, String Local) {
- if(PU.equals("0")){
- emf = Persistence.createEntityManagerFactory("GestorPU");
- }else{
- Properties props = new Properties();
- props.setProperty("hibernate.connection.url", "jdbc:firebirdsql:localhost/3050:" + Local);
- emf = Persistence.createEntityManagerFactory(PU, props);
- }
- return emf.createEntityManager();
- }
- public static EntityManager getEntity() {
- return emf.createEntityManager();
- }
- }
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package DAO;
- import Entity.Cadgru;
- import Entity.Cadusr;
- import java.io.UnsupportedEncodingException;
- import java.security.MessageDigest;
- import java.security.NoSuchAlgorithmException;
- import javax.ejb.Stateless;
- import javax.persistence.EntityManager;
- import javax.persistence.EntityTransaction;
- import javax.persistence.NoResultException;
- import javax.persistence.Query;
- /**
- *
- * @author Felipee
- */
- @Stateless
- public class GestorDAO {
- Cadusr retorno;
- public static Cadusr usu = new Cadusr();
- public Cadusr buscaPorId(String gr, String usr, String senha) {
- EntityManager em = Conexao.getEntityManager("0", null);
- EntityTransaction tx = em.getTransaction();
- tx.begin();
- Cadgru cadgru = em.find(Cadgru.class, gr);
- tx.commit();
- em.close();
- if (cadgru != null) {
- EntityManager em2 = Conexao.getEntityManager("MitryusPU", cadgru.getEndfdb());
- EntityTransaction tx2 = em2.getTransaction();
- tx2.begin();
- String jpql = "select a from Cadusr a where a.nomusr = :nomusr and a.pasusr = :pasusr";
- Query query = em2.createQuery(jpql, Cadusr.class);
- query.setParameter("nomusr", usr);
- query.setParameter("pasusr", senha);
- try {
- retorno = (Cadusr) query.getSingleResult();
- tx2.commit();
- em2.close();
- if (retorno == null) {
- em = Conexao.getEntityManager("0", cadgru.getEndfdb());
- tx = em.getTransaction();
- tx.begin();
- tx.commit();
- em.close();
- }
- } catch (NoResultException nre) {
- }
- } else {
- retorno = null;
- }
- return retorno;
- }
- public String usuarioLogado() {
- String Usuario = usu.getCodusr() + "-" + usu.getNomusr();
- return Usuario;
- }
- private String convertStringToMd5(String valor) {
- MessageDigest mDigest;
- try {
- //Instanciamos o nosso HASH MD5, poderíamos usar outro como
- //SHA, por exemplo, mas optamos por MD5.
- mDigest = MessageDigest.getInstance("MD5");
- //Convert a String valor para um array de bytes em MD5
- byte[] valorMD5 = mDigest.digest(valor.getBytes("UTF-8"));
- //Convertemos os bytes para hexadecimal, assim podemos salvar
- //no banco para posterior comparação se senhas
- StringBuffer sb = new StringBuffer();
- for (byte b : valorMD5) {
- sb.append(Integer.toHexString((b & 0xFF) | 0x100).substring(1, 3));
- }
- return sb.toString();
- } catch (NoSuchAlgorithmException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- return null;
- } catch (UnsupportedEncodingException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement