From 791583ef2af232bfe703815132c12cd4cf368b7f Mon Sep 17 00:00:00 2001 From: Humeid Ussene Jocordasse Date: Wed, 25 Sep 2019 15:39:33 +0300 Subject: [PATCH] Quem fez a maior parte foi Edson --- .gitignore | 2 + build/classes/.netbeans_automatic_build | 0 build/classes/.netbeans_update_resources | 0 build/classes/META-INF/persistence.xml | 14 ++++++ build/classes/hibernate.cfg.xml | 56 +++++++++++++++++++++++ lib/nblibraries.properties | 57 ++++++++++++++++++++++++ nbproject/build-impl.xml | 10 ++--- nbproject/genfiles.properties | 8 ++-- nbproject/private/private.properties | 3 +- nbproject/private/private.xml | 4 +- nbproject/project.properties | 19 +++++--- nbproject/project.xml | 2 +- sgcalamidades.sql | 47 +++++++++++++++++++ src/Arquivo/NewHibernateUtil.java | 36 +++++++++++++++ src/Controller/TodosDao.java | 52 +++++++++++++++++++++ src/META-INF/persistence.xml | 14 ++++++ src/Model/Funcionario.java | 32 +++++++++++-- src/Model/Operador.java | 11 +++++ src/TodosDao/Todos.java | 34 ++++++++++++++ src/hibernate.cfg.xml | 56 +++++++++++++++++++++++ 20 files changed, 434 insertions(+), 23 deletions(-) create mode 100644 build/classes/.netbeans_automatic_build create mode 100644 build/classes/.netbeans_update_resources create mode 100644 build/classes/META-INF/persistence.xml create mode 100644 build/classes/hibernate.cfg.xml create mode 100644 sgcalamidades.sql create mode 100644 src/Arquivo/NewHibernateUtil.java create mode 100644 src/Controller/TodosDao.java create mode 100644 src/META-INF/persistence.xml create mode 100644 src/TodosDao/Todos.java create mode 100644 src/hibernate.cfg.xml diff --git a/.gitignore b/.gitignore index a1c2a23..d92af07 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,8 @@ *.zip *.tar.gz *.rar +*.xml +*.mf # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* diff --git a/build/classes/.netbeans_automatic_build b/build/classes/.netbeans_automatic_build new file mode 100644 index 0000000..e69de29 diff --git a/build/classes/.netbeans_update_resources b/build/classes/.netbeans_update_resources new file mode 100644 index 0000000..e69de29 diff --git a/build/classes/META-INF/persistence.xml b/build/classes/META-INF/persistence.xml new file mode 100644 index 0000000..cbd5c64 --- /dev/null +++ b/build/classes/META-INF/persistence.xml @@ -0,0 +1,14 @@ + + + + org.hibernate.ejb.HibernatePersistence + + + + + + + + + + diff --git a/build/classes/hibernate.cfg.xml b/build/classes/hibernate.cfg.xml new file mode 100644 index 0000000..75d10b4 --- /dev/null +++ b/build/classes/hibernate.cfg.xml @@ -0,0 +1,56 @@ + + + + + + org.hibernate.dialect.MySQLDialect + com.mysql.jdbc.Driver + jdbc:mysql://localhost:3306/sgcalamidades?zeroDateTimeBehavior=convertToNull + root + update + true + true + + + + + + diff --git a/lib/nblibraries.properties b/lib/nblibraries.properties index 1c91935..4d6f10f 100644 --- a/lib/nblibraries.properties +++ b/lib/nblibraries.properties @@ -2,3 +2,60 @@ libs.CopyLibs.classpath=\ ${base}/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar libs.CopyLibs.displayName=CopyLibs Task libs.CopyLibs.prop-version=2.0 +libs.hibernate4-persistence.classpath=\ + ${base}/hibernate4-persistence/antlr-2.7.7.jar;\ + ${base}/hibernate4-persistence/c3p0-0.9.2.1.jar;\ + ${base}/hibernate4-persistence/hibernate-c3p0-4.3.1.Final.jar;\ + ${base}/hibernate4-persistence/mchange-commons-java-0.2.3.4.jar;\ + ${base}/hibernate4-persistence/dom4j-1.6.1.jar;\ + ${base}/hibernate4-persistence/ehcache-core-2.4.3.jar;\ + ${base}/hibernate4-persistence/hibernate-ehcache-4.3.1.Final.jar;\ + ${base}/hibernate4-persistence/hibernate-core-4.3.1.Final.jar;\ + ${base}/hibernate4-persistence/jboss-logging-3.1.3.GA.jar;\ + ${base}/hibernate4-persistence/hibernate-commons-annotations-4.0.4.Final.jar;\ + ${base}/hibernate4-persistence/hibernate-entitymanager-4.3.1.Final.jar;\ + ${base}/hibernate4-persistence/javassist-3.18.1-GA.jar;\ + ${base}/hibernate4-persistence/jboss-transaction-api_1.2_spec-1.0.0.Final.jar;\ + ${base}/hibernate4-persistence/slf4j-api-1.6.1.jar;\ + ${base}/hibernate4-persistence/slf4j-simple-1.6.1.jar;\ + ${base}/hibernate4-persistence/hibernate-jpa-2.1-api-1.0.0.Final.jar +libs.hibernate4-persistence.displayName=Hibernate 4.3.x(JPA2.1) +libs.hibernate4-persistence.javadoc=\ + ${base}/hibernate4-persistence/javax.persistence-2.1.0-doc.zip +libs.hibernate4-persistence.prop-maven-dependencies=\n org.hibernate:hibernate-entitymanager:4.3.1.Final:jar\n +libs.hibernate4-persistencemodelgen.classpath=\ + ${base}/hibernate4-persistencemodelgen/hibernate-jpamodelgen-4.3.1.Final.jar +libs.hibernate4-persistencemodelgen.displayName=Hibernate 4.3.x Modelgen +libs.hibernate4-persistencemodelgen.prop-maven-dependencies=\n org.hibernate:hibernate-jpamodelgen-4.3.1.Final:jar\n +libs.hibernate4-support.classpath=\ + ${base}/hibernate4-support/antlr-2.7.7.jar;\ + ${base}/hibernate4-support/c3p0-0.9.2.1.jar;\ + ${base}/hibernate4-support/hibernate-c3p0-4.3.1.Final.jar;\ + ${base}/hibernate4-support/mchange-commons-java-0.2.3.4.jar;\ + ${base}/hibernate4-support/dom4j-1.6.1.jar;\ + ${base}/hibernate4-support/ehcache-core-2.4.3.jar;\ + ${base}/hibernate4-support/hibernate-ehcache-4.3.1.Final.jar;\ + ${base}/hibernate4-support/hibernate-core-4.3.1.Final.jar;\ + ${base}/hibernate4-support/jboss-logging-3.1.3.GA.jar;\ + ${base}/hibernate4-support/hibernate-commons-annotations-4.0.4.Final.jar;\ + ${base}/hibernate4-support/hibernate-entitymanager-4.3.1.Final.jar;\ + ${base}/hibernate4-support/javassist-3.18.1-GA.jar;\ + ${base}/hibernate4-support/jboss-transaction-api_1.2_spec-1.0.0.Final.jar;\ + ${base}/hibernate4-support/slf4j-api-1.6.1.jar;\ + ${base}/hibernate4-support/slf4j-simple-1.6.1.jar +libs.hibernate4-support.displayName=Hibernate 4.3.x +libs.hibernate4-support.javadoc=\ + ${base}/hibernate4-support/javax.persistence-2.1.0-doc.zip +libs.hibernate4-support.prop-maven-dependencies=\n org.hibernate:hibernate-entitymanager:4.3.1.Final:jar\n +libs.JAVADB_DRIVER_LABEL.classpath=\ + ${base}/JAVADB_DRIVER_LABEL/derby.jar;\ + ${base}/JAVADB_DRIVER_LABEL/derbyclient.jar;\ + ${base}/JAVADB_DRIVER_LABEL/derbynet.jar +libs.JAVADB_DRIVER_LABEL.displayName=Java DB Driver +libs.JAVADB_DRIVER_LABEL.prop-maven-dependencies=\norg.apache.derby:derby:10.11.1.1:jar\norg.apache.derby:derbyclient:10.11.1.1:jar\norg.apache.derby:derbynet:10.11.1.1:jar\n +libs.jpa2-persistence.classpath=\ + ${base}/jpa2-persistence/hibernate-jpa-2.1-api-1.0.0.Final.jar +libs.jpa2-persistence.displayName=Persistence JPA2.1 +libs.jpa2-persistence.javadoc=\ + ${base}/jpa2-persistence/javax.persistence-2.1.0-doc.zip +libs.jpa2-persistence.prop-maven-dependencies=org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final:jar diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml index 92a749c..74e4004 100644 --- a/nbproject/build-impl.xml +++ b/nbproject/build-impl.xml @@ -19,7 +19,7 @@ is divided into following sections: - cleanup --> - + @@ -475,7 +475,7 @@ is divided into following sections: - + @@ -626,7 +626,7 @@ is divided into following sections: - + @@ -918,7 +918,7 @@ is divided into following sections: - + @@ -1403,7 +1403,7 @@ is divided into following sections: - + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties index 3e5da6e..8d55b30 100644 --- a/nbproject/genfiles.properties +++ b/nbproject/genfiles.properties @@ -1,8 +1,8 @@ -build.xml.data.CRC32=b93c3ca9 -build.xml.script.CRC32=5ac61e61 +build.xml.data.CRC32=00d123d9 +build.xml.script.CRC32=1d244edd build.xml.stylesheet.CRC32=8064a381@1.80.1.48 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=b93c3ca9 -nbproject/build-impl.xml.script.CRC32=16c7fbbd +nbproject/build-impl.xml.data.CRC32=00d123d9 +nbproject/build-impl.xml.script.CRC32=b07f15fa nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48 diff --git a/nbproject/private/private.properties b/nbproject/private/private.properties index 7c0b2d3..4bcebbb 100644 --- a/nbproject/private/private.properties +++ b/nbproject/private/private.properties @@ -1 +1,2 @@ -user.properties.file=C:\\Users\\Humeid Ussene\\AppData\\Roaming\\NetBeans\\8.2\\build.properties +compile.on.save=true +user.properties.file=C:\\Users\\Edson Nhancale\\AppData\\Roaming\\NetBeans\\8.2\\build.properties diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml index ca4a365..6807a2b 100644 --- a/nbproject/private/private.xml +++ b/nbproject/private/private.xml @@ -2,8 +2,6 @@ - - file:/C:/Users/Humeid%20Ussene/Desktop/Cadeiras/4%20semestre/POO/POO%202019/ProjectoSemestPoo/src/Model/Funcionario.java - + diff --git a/nbproject/project.properties b/nbproject/project.properties index 6595579..dd6df86 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -1,6 +1,6 @@ annotation.processing.enabled=true annotation.processing.enabled.in.editor=false -annotation.processing.processor.options= +annotation.processing.processor.options=-Aeclipselink.canonicalmodel.use_static_factory=false annotation.processing.processors.list= annotation.processing.run.all.processors=true annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output @@ -24,18 +24,27 @@ debug.test.classpath=\ dist.archive.excludes= # This directory is removed when the project is cleaned: dist.dir=dist -dist.jar=${dist.dir}/ProjetoPoo.jar +dist.jar=${dist.dir}/ProjectoSemestral.jar dist.javadoc.dir=${dist.dir}/javadoc excludes= +file.reference.mysql-connector-java-5.1.23-bin.jar=lib/mysql-connector-java-5.1.23-bin.jar +file.reference.mysql-connector-java-5.1.47.jar=lib\\mysql-connector-java-5.1.47.jar includes=** jar.compress=false -javac.classpath= +javac.classpath=\ + ${file.reference.mysql-connector-java-5.1.47.jar}:\ + ${libs.hibernate4-support.classpath}:\ + ${libs.JAVADB_DRIVER_LABEL.classpath}:\ + ${libs.jpa2-persistence.classpath}:\ + ${libs.hibernate4-persistence.classpath}:\ + ${file.reference.mysql-connector-java-5.1.23-bin.jar} # Space-separated list of extra javac options javac.compilerargs= javac.deprecation=false javac.external.vm=true javac.processorpath=\ - ${javac.classpath} + ${javac.classpath}:\ + ${libs.hibernate4-persistencemodelgen.classpath} javac.source=1.8 javac.target=1.8 javac.test.classpath=\ @@ -54,7 +63,7 @@ javadoc.splitindex=true javadoc.use=true javadoc.version=false javadoc.windowtitle= -main.class=projetopoo.ProjetoPoo +main.class=Conex\u00e3o.Conection manifest.file=manifest.mf meta.inf.dir=${src.dir}/META-INF mkdist.disabled=false diff --git a/nbproject/project.xml b/nbproject/project.xml index 07f2378..d621d61 100644 --- a/nbproject/project.xml +++ b/nbproject/project.xml @@ -3,7 +3,7 @@ org.netbeans.modules.java.j2seproject - ProjetoPoo + ProjectoSemestral diff --git a/sgcalamidades.sql b/sgcalamidades.sql new file mode 100644 index 0000000..778d2ea --- /dev/null +++ b/sgcalamidades.sql @@ -0,0 +1,47 @@ +/* +SQLyog Ultimate v10.00 Beta1 +MySQL - 5.7.14 : Database - sgcalamidades +********************************************************************* +*/ + +/*!40101 SET NAMES utf8 */; + +/*!40101 SET SQL_MODE=''*/; + +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; +CREATE DATABASE /*!32312 IF NOT EXISTS*/`sgcalamidades` /*!40100 DEFAULT CHARACTER SET latin1 */; + +USE `sgcalamidades`; + +/*Table structure for table `funcionario` */ + +DROP TABLE IF EXISTS `funcionario`; + +CREATE TABLE `funcionario` ( + `DTYPE` varchar(31) NOT NULL, + `id_funcionario` int(11) NOT NULL AUTO_INCREMENT, + `contacto` varchar(255) DEFAULT NULL, + `dataNascimento` datetime DEFAULT NULL, + `email` varchar(255) DEFAULT NULL, + `estado` bit(1) DEFAULT NULL, + `nome` varchar(255) DEFAULT NULL, + `nrDocumento` varchar(255) DEFAULT NULL, + `sexo` varchar(255) DEFAULT NULL, + `tipoDeDocumento` varchar(255) DEFAULT NULL, + `idCentro` varchar(255) DEFAULT NULL, + `senha` varchar(255) DEFAULT NULL, + `usuario` varchar(255) DEFAULT NULL, + PRIMARY KEY (`id_funcionario`) +) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=latin1; + +/*Data for the table `funcionario` */ + +insert into `funcionario`(`DTYPE`,`id_funcionario`,`contacto`,`dataNascimento`,`email`,`estado`,`nome`,`nrDocumento`,`sexo`,`tipoDeDocumento`,`idCentro`,`senha`,`usuario`) values ('Operador',4,NULL,NULL,NULL,'\0','Humei Jocordasse',NULL,'Masculino',NULL,NULL,NULL,NULL),('Operador',3,NULL,NULL,NULL,'\0','Humei Jocordasse Kazembe',NULL,'Masculino',NULL,NULL,NULL,NULL); + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; diff --git a/src/Arquivo/NewHibernateUtil.java b/src/Arquivo/NewHibernateUtil.java new file mode 100644 index 0000000..ea9da80 --- /dev/null +++ b/src/Arquivo/NewHibernateUtil.java @@ -0,0 +1,36 @@ +/* + * 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 Arquivo; + +import org.hibernate.cfg.AnnotationConfiguration; +import org.hibernate.SessionFactory; + +/** + * Hibernate Utility class with a convenient method to get Session Factory + * object. + * + * @author Edson Nhancale + */ +public class NewHibernateUtil { + + private static final SessionFactory sessionFactory; + + static { + try { + // Create the SessionFactory from standard (hibernate.cfg.xml) + // config file. + sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory(); + } catch (Throwable ex) { + // Log the exception. + System.err.println("Initial SessionFactory creation failed." + ex); + throw new ExceptionInInitializerError(ex); + } + } + + public static SessionFactory getSessionFactory() { + return sessionFactory; + } +} diff --git a/src/Controller/TodosDao.java b/src/Controller/TodosDao.java new file mode 100644 index 0000000..28b389b --- /dev/null +++ b/src/Controller/TodosDao.java @@ -0,0 +1,52 @@ +/* + * 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 Controller; + +import Arquivo.NewHibernateUtil; +import Model.Operador; +import java.util.List; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; + +/** + * + * @author Edson Nhancale + */ +public class TodosDao { + public boolean salvar(T t){ + SessionFactory sf = NewHibernateUtil.getSessionFactory(); + Session s = sf.openSession(); + Transaction tx = s.beginTransaction(); + + try { + s.saveOrUpdate( t); + tx.commit(); + return true; + + } catch (Exception e) { + System.out.println(e.getStackTrace()); + return false; + } + finally { + s.close(); + sf.close(); + } + } + + public static List Listar(){ + SessionFactory sf = NewHibernateUtil.getSessionFactory(); + Session s = sf.openSession(); + List lista =null; + try { + lista = s.createQuery("from Funcionario").list(); + } catch (Exception e) { + }finally{ +s.close(); + } + return lista; + } +} diff --git a/src/META-INF/persistence.xml b/src/META-INF/persistence.xml new file mode 100644 index 0000000..cbd5c64 --- /dev/null +++ b/src/META-INF/persistence.xml @@ -0,0 +1,14 @@ + + + + org.hibernate.ejb.HibernatePersistence + + + + + + + + + + diff --git a/src/Model/Funcionario.java b/src/Model/Funcionario.java index 08ea3e3..29ace35 100644 --- a/src/Model/Funcionario.java +++ b/src/Model/Funcionario.java @@ -5,23 +5,47 @@ */ package Model; +import java.io.Serializable; import java.util.Date; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; /** * * @author hp */ -public abstract class Funcionario { +@Entity (name="Funcionario") +@Table(name="Funcionario") +public abstract class Funcionario implements Serializable{ + @Id + @GeneratedValue + @Column(name="id_funcionario") + private int id; + @Column(name="nome") private String nome; + @Column(name="contacto") private String contacto; + @Column(name="email") private String email; + @Column(name="tipoDeDocumento") private String tipoDeDocumento; + @Column(name="nrDocumento") private String nrDocumento; - private int id; + @Column(name="estado") private boolean estado; + @Column(name="dataNascimento") private Date dataNascimento; + @Column(name="sexo") private String sexo; + @Override + public String toString() { + return "Funcionario{" + "id=" + id + ", nome=" + nome + ", contacto=" + contacto + ", email=" + email + ", tipoDeDocumento=" + tipoDeDocumento + ", nrDocumento=" + nrDocumento + ", estado=" + estado + ", dataNascimento=" + dataNascimento + ", sexo=" + sexo + '}'; + } + public Funcionario(String nome, String contacto, String email, String tipoDeDocumento, String nrDocumento, Date dataNascimento, String sexo) { this.nome = nome; this.contacto = contacto; @@ -114,11 +138,11 @@ public void setEmail(String email) { this.email = email; } - public String getTipoDeDocumento() { + public String getTipo() { return tipoDeDocumento; } - public void setTipoDeDocumento(String tipo) { + public void setTipo(String tipo) { this.tipoDeDocumento = tipo; } diff --git a/src/Model/Operador.java b/src/Model/Operador.java index 598e1ed..93e94ad 100644 --- a/src/Model/Operador.java +++ b/src/Model/Operador.java @@ -6,19 +6,30 @@ package Model; import java.util.Date; +import javax.persistence.Column; +import javax.persistence.Entity; /** * * @author hp */ +@Entity (name="Operador") public class Operador extends Funcionario{ + @Column(name="idCentro") private String idCentro; + @Column(name="usuario") private String usuario; + @Column(name="senha") private String senha; public Operador() { } + @Override + public String toString() { + return "Operador{" + "idCentro=" + idCentro + ", usuario=" + usuario + ", senha=" + senha + '}'; + } + public Operador(String nome, String contacto, String email, String tipoDeDocumento, String nrDocumento, Date dataNascimento, String sexo,String idCentro, String usuario, String senha) { super(nome, contacto, email, tipoDeDocumento, nrDocumento, dataNascimento, sexo); this.idCentro = idCentro; diff --git a/src/TodosDao/Todos.java b/src/TodosDao/Todos.java new file mode 100644 index 0000000..d3706d7 --- /dev/null +++ b/src/TodosDao/Todos.java @@ -0,0 +1,34 @@ +/* + * 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 TodosDao; + +import Controller.TodosDao; +import Model.*; +import java.util.List; +/** + * + * @author Edson Nhancale + */ +public class Todos { + public static void main(String[] args) { + + + List po = TodosDao.Listar(); + +// for (Operador func: po) { +// System.out.println("Nome"+func.getNome()); +// } + + TodosDao crud = new TodosDao(); + Operador teste = new Operador(); + teste.setId(3); + teste.setNome("Humei Jocordasse Kazembe"); + teste.setSexo("Masculino"); + crud.salvar(teste); + + } + +} diff --git a/src/hibernate.cfg.xml b/src/hibernate.cfg.xml new file mode 100644 index 0000000..75d10b4 --- /dev/null +++ b/src/hibernate.cfg.xml @@ -0,0 +1,56 @@ + + + + + + org.hibernate.dialect.MySQLDialect + com.mysql.jdbc.Driver + jdbc:mysql://localhost:3306/sgcalamidades?zeroDateTimeBehavior=convertToNull + root + update + true + true + + + + + +