Raible's Wiki

Raible Designs
Wiki Home
News
Recent Changes

AppFuse

Homepage
  - Korean
  - Chinese
  - Italian
  - Japanese

QuickStart Guide
  - Chinese
  - French
  - German
  - Italian
  - Korean
  - Portuguese
  - Spanish
  - Japanese

User Guide
  - Korean
  - Chinese

Tutorials
  - Chinese
  - German
  - Italian
  - Korean
  - Portuguese
  - Spanish

FAQ
  - Korean

Latest Downloads

Other Applications

Struts Resume
Security Example
Struts Menu

Set your name in
UserPreferences


Referenced by
Articles
Articles_pt
CreateManager_pt
LeftMenu




JSPWiki v2.2.33

[RSS]


Hide Menu

CreateDAO_pt


Difference between version 14 and version 13:

At line 292 changed 2 lines.
!!Create a new DAO to perform CRUD on the object [#4]
First off, create a PersonDao.java interface in the src/dao/**/dao directory and specify the basic CRUD methods for any implementation classes. ''I've eliminated the JavaDocs in the class below for display purposes.''
!!Criar uma nova classe DAO para efetuar CRUD no objeto [#4]
At line 294 added 2 lines.
Primeiro, crie a interface PessoaDAO.java no diretório src/dao/**/dao e especifique os métodos CRUD básicos para qualquer classe de implementação. Eliminei as partes JavaDocs na classe abaixo apenas por propósito de visualização.''
At line 315 changed 1 line.
Notice in the class above there are no exceptions on the method signatures. This is due to the power of [Spring|http://www.springframework.org] and how it wraps Exceptions with RuntimeExceptions. At this point, you should be able to compile all the source in src/dao and test/dao using "ant compile-dao". However, if you try to run "ant test-dao -Dtestcase=PersonDao", you will get an error: <span style="color: red">No bean named 'personDao' is defined</span>. This is an error message from Spring - indicating that we need to specify a bean named ''personDAO'' in applicationContext-hibernate.xml. Before we do that, we need to create the PersonDao implementation class.
Note na classe acima que não há exceções nas assinaturas dos métodos. Isto devido à força do [Spring|http://www.springframework.org] e como ele encapsula Exceptions com RuntimeExceptions. Neste ponto, você deve ser capaz de compilar todo fonte em src/dao e test/dao usando “ant compile-dao”. No entanto, se você tentar executar “ant -Dtestcase=PessoaDAO”, você receberá um erro: <span style="color: red">No bean named 'pessoaDAO' is defined</span>. Esta é uma mensagem de erro do Spring – indicando que nós precisamos especificar um bean nomeado pessoaDAO no arquivo ApplicationContex-hibernate.xml. Antes de fazê-lo, precisamos criar a classe que implementa a interface PessoaDAO.
At line 317 changed 1 line.
;:''The ant task for running dao tests is called "test-dao". If you pass in a testcase parameter (using -Dtestcase=name), it will look for **/*${testcase}* - allowing us to pass in Person, PersonDao, or PersonDaoTest - all of which will execute the PersonDaoTest class.''
;:''A tarefa Ant para executar os testes dao é chamada “test-dao”. Se você passar um parâmetro testcase (usando -Dtestcase=nome), a tarefa irá procurar por **/*${testcase}* - nos permitindo passar Pessoa, PessoaDAO ou PessoaDaoTest – todos o qual executará a classe PessoaDAOTest.''
At line 319 changed 1 line.
Let's start by creating a PersonDaoHibernate class that implements the methods in PersonDao and uses Hibernate to get/save/delete the Person object. To do this, create a new class in src/dao/**/dao/hibernate and name it PersonDAOHibernate.java. It should extend [BaseDaoHibernate|http://raibledesigns.com/downloads/appfuse/api/org/appfuse/dao/BaseDAOHibernate.java.html] and implement PersonDAO. ''Javadocs eliminated for brevity.''
Vamos começar, criando uma classe PessoaDAOHibernate que implementa os métodos em PessoaDAO e usa Hibernate para get/save/delete o objeto Pessoa. Para fazê-lo, crie uma nova classe em src/dao/**/dao/hibernate e a nomeie PessoaDAOHibernate.java. Ela deverá estender [BaseDaoHibernate|http://raibledesigns.com/downloads/appfuse/api/org/appfuse/dao/BaseDAOHibernate.java.html] e implementar PessoaDAO. ''JavaDocs eliminados por brevidade.''
At line 357 changed 1 line.
You'll notice here that we're doing nothing with the ''person'' parameter. This is just a placeholder for now - in the future you may want to filter on it's properties using [Hibernate's Query Language|http://www.hibernate.org/hib_docs/reference/en/html/queryhql.html] (HQL) or using [Criteria Queries|http://www.hibernate.org/hib_docs/reference/en/html/querycriteria.html].
Você notará aqui que não estamos fazendo nada com o parâmetro pessoa. Isto é somente um “place holder” por enquanto – no futuro você pode filtrar suas propriedades usando [Hibernate's Query Language|http://www.hibernate.org/hib_docs/reference/en/html/queryhql.html] (HQL) ou usando [Criteria Queries|http://www.hibernate.org/hib_docs/reference/en/html/querycriteria.html].
At line 359 changed 1 line.
''An example using a Criteria Query:''
''Um exemplo usando Criteria Query:''
At line 377 changed 1 line.
Now, if you try to run "ant test-dao -Dtestcase=PersonDao", you will get the same error. We need to configure Spring so it knows that PersonDaoHibernate is the implementation of PersonDAO, and we also need to tell it about the Person object.
Agora, se você tentar executar “ant test-dao -Dtestcase=PessoaDAO”, você obterá o mesmo erro. Precisamos configurar Spring de forma que ele saiba que PessoaDAOHibernate é a implementação de PessoaDAO, e precisamos também informá-lo sobre o objeto Pessoa.
At line 379 changed 1 line.
!!Configure Spring for the Person object and PersonDao [#5]
!!Configurar o framework Spring para o objeto Pessoa e PessoaDAO [#5]
At line 381 changed 1 line.
First, we need to tell Spring where the Hibernate mapping file is located. To do this, open src/dao/**/dao/hibernate/applicationContext-hibernate.xml and add {{Person.hbm.xml}} to the following code block.
Primeiro, necessitamos dizer ao Spring onde o arquivo de mapeamento do Hibernate está localizado. Para isso, abra src/dao/**/dao/hibernate/ApplicationContext.xml e adicione {{Pessoa.hbm.xml}} ao seguinte bloco de código.
At line 396 changed 1 line.
Now we need to add some XML to this file to bind PersonDaoHibernate to PersonDao. To do this, add the following at the bottom of the file:
Agora precisamos adicionar algum XML a este arquivo para ligar PessoaDAOHibernate à PessoaDAO. Para fazê-lo, adicione o seguinte na parte inferior do arquivo:
At line 406 changed 1 line.
;:''You could also use __autowire="byName"__ to the &lt;bean&gt; and get rid of the "sessionFactory" property. Personally, I like having the dependencies of my objects documented (in XML).''
;:''Você poderia também usar __autowire="byName"__ ao &lt;bean&gt; e se livrar da propriedade “sessionFactory”. Pessoalmente, gosto de ter as dependências de meus objetos documentadas (em XML).''
At line 408 changed 2 lines.
!!Run the DaoTest [#6]
Save all your edited files and try running "ant test-dao -Dtestcase=PersonDao" one more time.
!!Executar o DaoTest [#6]
At line 411 added 2 lines.
Salve todos os arquivos editados e tente executar “ant test-dao -Dtestcase=PessoaDAO” uma vez mais.
At line 417 added 2 lines.
Nota:
Antes que você envie críticas, peço que compreenda que estou apenas contribuindo com o projeto e que não sou um profundo conhecedor da idioma Inglês. Sinta-se no direito de corrigir os erros de tradução ou mesmo os erros ortográficos – não sou perfeito!;-)

Back to CreateDAO_pt, or to the Page History.