Guest User

Untitled

a guest
Sep 19th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. private EntityManagerFactory emf;
  2. private EntityManager em;
  3. private List<Usuario> _Usuario;
  4. private Usuario Usuario;
  5.  
  6. public ControlUsuario() {
  7. this.emf = Persistence.createEntityManagerFactory("federacion");
  8. this.em = this.emf.createEntityManager();
  9. this._Usuario = consultarUsuario();
  10. this.Usuario = new Usuario();
  11. }
  12.  
  13. public List<Usuario> consultarUsuario() {
  14. String jpql = " select * from USUARIO";
  15. Query query = this.em.createQuery(jpql);
  16. List<Usuario> _Usuario = query.getResultList();
  17. return _Usuario;
  18. }
  19.  
  20. public Usuario loginUsuario(Usuario usuario) {
  21. for (int a = 0; a < _Usuario.size(); a++) {
  22. if (usuario.getIdUSUARIO() == _Usuario.get(a).getIdUSUARIO()
  23. && usuario.getUNIVERSIDAD_idUNIVERSIDAD() == _Usuario.get(a).getUNIVERSIDAD_idUNIVERSIDAD()) {
  24. System.out.println("logeo satisfactorio");
  25. } else {
  26. System.out.println("logeo no satisfactorio");
  27. usuario = null;
  28. }
  29. }
  30. return usuario;
  31. }
  32.  
  33. public void crearUsuario() {
  34. try {
  35. this.em.getTransaction().begin();
  36. this.em.persist(Usuario);
  37. this.em.getTransaction().commit();
  38. this.Usuario = new Usuario();
  39. } catch (Exception e) {
  40. System.out.println(e);
  41. }
  42. }
  43.  
  44. public List<Usuario> get_Usuario() {
  45. return _Usuario;
  46. }
  47.  
  48. public void set_Usuario(List<Usuario> _Usuario) {
  49. this._Usuario = _Usuario;
  50. }
  51.  
  52. public Usuario getUsuario() {
  53. return Usuario;
  54. }
  55.  
  56. public void setUsuario(Usuario Usuario) {
  57. this.Usuario = Usuario;
  58. }
  59.  
  60. <%
  61. ControlUsuario controlusuario = new ControlUsuario();
  62. Usuario usuario = new Usuario();
  63. %>
  64.  
  65. <properties>
  66. <property name="javax.persistence.jdbc.url"
  67. value="jdbc:mysql://localhost:3306/federacion" />
  68. <property name="javax.persistence.jdbc.user" value="root" />
  69. <property name="javax.persistence.jdbc.driver"
  70. value="com.mysql.cj.jdbc.Driver" />
  71. <property name="javax.persistence.jdbc.password"
  72. value="Unired2018*" />
  73. <property
  74. name="javax.persistence.schema-generation.database.action"
  75. value="create" />
  76. <property name="hibernate.hbm2ddl.auto" value="update" />
  77. <property name="hibernate.show_sql" value="true" />
  78. <property name="hibernate.dialect"
  79. value="org.hibernate.dialect.MySQL5InnoDBDialect" />
  80. </properties>
  81. </persistence-unit>
Add Comment
Please, Sign In to add comment