| At line 131 changed 1 line. |
| ;:%%(color: blue)''Acho engraçado como segui tantos padrões para permitir __extendibilidade__ no AppFuse. Na realidade, na maioria dos projetos que participei - aprendi tanto em um ano que não quero extender a arquitetura - quero reescrevê-la. Espero que isto não ocorra tanto, utilizando minhas melhores práticas para manter o AppFuse em dia. A cada ano haverá apenas um upgrade para uma nova versão do AppFuse, ao invés de ter de reescrevê-lo. ;-)'' |
| ;:%%(color: blue)''Acho engraçado como segui tantos padrões para permitir __extendibilidade__ no AppFuse. Na realidade, na maioria dos projetos que participei, aprendi tanto em um ano que não queria extender a arquitetura - queria reescrevê-la. Espero que isto não ocorra tanto, utilizando minhas melhores práticas para manter o AppFuse em dia. A cada ano haverá apenas um upgrade para uma nova versão do AppFuse, ao invés de ter de reescrevê-lo. ;-)'' |
| At line 135 changed 1 line. |
| First off, create a PersonManager.java interface in the src/service/**/service directory and specify the basic CRUD methods for any implementation classes. ''I've eliminated the JavaDocs in the class below for display purposes.'' |
| Primeiramente, crie uma interface PersonManager.java no diretório src/service/**/service, e especifique os métodos CRUD básicos para implementações posteriores. ''Eliminei os JavaDocs na classe abaixo para não poluir o código.'' |
| At line 137 changed 1 line. |
| ;:%%(color: blue)''As usual, I usually duplicate (open → save as) an existing file (i.e. UserManager.java).''%% |
| ;:%%(color: blue)''Como sempre, duplico (open → save as) um arquivo existente (i.e. UserManager.java).''%% |
| At line 144 added 1 line. |
| import org.appfuse.dao.PersonDao; |
| At line 145 removed 2 lines. |
| import java.util.List; |
|
| At line 149 changed 1 line. |
| public List getPeople(Person person); |
| public void setPersonDao(PersonDao dao); |
| At line 159 changed 1 line. |
| Now let's create a PersonManagerImpl class that implements the methods in PersonManager. To do this, create a new class in src/service/**/service and name it PersonManagerImpl.java. It should extend BaseManager and implement PersonManager. |
| Agora vamos criar uma classe PersonManagerImpl que implementa os métodos da interface PersonManager. Para fazer isto, crie uma nova classe em src/service/**/service com o nome PersonManagerImpl.java. Esta classe deve estender BaseManager e implementar PersonManager. |
| At line 163 changed 1 line. |
| package org.appfuse.service; |
| package org.appfuse.service.impl; |
| At line 165 removed 3 lines. |
| import org.apache.commons.logging.Log; |
| import org.apache.commons.logging.LogFactory; |
|
| At line 166 added 1 line. |
| import org.appfuse.service.PersonManager; |
| At line 171 removed 6 lines. |
| import java.util.List; |
|
| /** |
| * @author mraible |
| * @version $Revision: $ $Date: May 25, 2004 11:46:54 PM $ |
| */ |
| At line 178 removed 1 line. |
| private static Log log = LogFactory.getLog(PersonManagerImpl.class); |
| At line 185 removed 4 lines. |
| public List getPeople(Person person) { |
| return dao.getPeople(person); |
| } |
|
| At line 193 changed 1 line. |
| public Person savePerson(Object person) { |
| public void savePerson(Person person) { |
| At line 195 removed 1 line. |
| return (Person) person; |
| At line 204 changed 2 lines. |
| One thing to note is the {{setPersonDao}} method. This is used by Spring to bind the PersonDao to this Manager. This is configured in the applicationContext-service.xml file. We'll get to configuring that in Step 3[3]. |
| You should be able to compile everything now using "ant compile-service"... |
| Uma coisa que deve ser notada é o método {{setPersonDao}}. Este método é utilizado pelo Spring para ligar o PersonDao a este Gerente(Manager). Isto é configurado no arquivo applicationContext-service.xml. Veremos como se configura este arquivo no Passo 3[3]. |
| Já nos é possível compilar tudo agora utilizando "ant compile-service"... |
| At line 207 changed 1 line. |
| Finally, we need to create the PersonManagerTest.properties file in test/service/**/service so that {{person = (Person) populate(person);}} will work in our test. |
| Agora necessitamos editar o arquivo de configuração do Spring para nossa camada Service para lhe dizer da existência do novo Manager. |
| At line 209 changed 1 line. |
| ;:''Duplicating (and renaming) the PersonDaoTest.properties is the easy route. Alternatively, you could set the properties manually.'' |
| !!Configurar o Spring para este Manager e as Transações [#3] |
| At line 211 changed 2 lines. |
| {{{firstName=Bill |
| lastName=Joy}}} |
| Para notificar o Spring da nossa interface PersonManager e sua implementação, abra o arquivo src/service/**/service/applicationContext-service.xml. Nele, veremos uma configuração comentada para o bean "PersonManager". Retire o comentário, ou adicione o seguinte código ao final do arquivo. |
| At line 214 removed 6 lines. |
| Now we need to edit Spring's config file for our services layer so it will know about this new Manager. |
|
| !!Configure Spring for this Manager and Transactions [#3] |
|
| To notify Spring of this our PersonManager interface and it's implementation, open the src/service/**/service/applicationContext-service.xml file. In here, you will see an existing configuration for the UserManager. You should be able to copy that and change a few things to get the XML fragment below. Add the following to the bottom of this file. |
|
| At line 222 changed 3 lines. |
| <!-- Person Manager --> |
| <bean id="personManagerTarget" class="org.appfuse.service.PersonManagerImpl" singleton="false"> |
| <property name="personDao"><ref bean="personDAO"/></property> |
| <bean id="personManager" parent="txProxyTemplate"> |
| <property name="target"> |
| <bean class="org.appfuse.service.impl.PersonManagerImpl" autowire="byName"/> |
| </property> |
| At line 226 removed 8 lines. |
| |
| <!-- Transaction declarations for business services. To apply a generic transaction proxy to |
| all managers, you might look into using the BeanNameAutoProxyCreator --> |
| <bean id="personManager" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> |
| <property name="transactionManager"><ref bean="transactionManager"/></property> |
| <property name="target"><ref local="personManagerTarget"/></property> |
| <property name="transactionAttributeSource"><ref local="defaultTxAttributes"/></property> |
| </bean> |
| At line 236 changed 1 line. |
| ''Note: [I|DaveKeller] had SAX throw an error because defaultTxAttributes was not defined so I replaced the transactionAttributeSource with this instead, which allowed my unit test to run successfully.'' |
| O atributo "parent" se refere a uma definição de bean para um [TransactionProxyFactoryBean|http://www.springframework.org/docs/api/org/springframework/transaction/interceptor/TransactionProxyFactoryBean.html], que possui todos os atributos de transação básicos inicializados. |
| At line 238 changed 1 line. |
| [{Java2HtmlPlugin |
| !!Rodar o ManagerTest [#4] |
| At line 240 changed 5 lines. |
| <property name="transactionAttributes"> |
| <props> |
| <prop key="*">PROPAGATION_REQUIRED</prop> |
| </props> |
| </property> |
| Salve todos os seus arquivos editados e tente rodar "ant test-service -Dtestcase=PersonManager" mais uma vez. |
| At line 246 removed 7 lines. |
| }] |
|
|
| !!Run the ManagerTest [#4] |
|
| Save all your edited files and try running "ant test-service -Dtestcase=PersonManager" one more time. |
|
| At line 259 changed 1 line. |
| ''Next Up:'' __Part III:__ [Creating Actions and JSPs|CreateActions] - A HowTo for creating Actions and JSPs in the AppFuse architecture. |
| Os arquivos modificados e adicionados nesta parte [podem ser baixados aqui|http://appfuse.dev.java.net/files/documents/1397/7484/appfuse-tutorial-managers-1.6.zip]. |
|
| ''Próxima:'' __Parte III:__ [Criando Actions e JSPs|CreateActions] - Um tutorial para criação de Actions e JSPs na arquitetura AppFuse. |