| At line 49 changed 1 line. |
| This class should extend [BaseObject|http://raibledesigns.com/downloads/appfuse/api/org/appfuse/model/BaseObject.java.html], which has 3 abstract methods: equals(), hashCode() and toString(). You will need to implement these methods in the Person class. The easiest way to do this is using [Commonclipse|http://commonclipse.sf.net]. More information on using this tool can be found on [Lee Grey's site|http://www.leegrey.com/hmm/2004/09/29/1096491256000.html]. |
| This class should extend [BaseObject|http://raibledesigns.com/downloads/appfuse/api/org/appfuse/model/BaseObject.java.html], which has 3 abstract methods: (equals(), hashCode() and toString()) that you will need to implement in the Person class. The first two are required by Hibernate. The easiest way to do this is using [Commonclipse|http://commonclipse.sf.net]. More information on using this tool can be found on [Lee Grey's site|http://www.leegrey.com/hmm/2004/09/29/1096491256000.html]. |
| At line 51 removed 5 lines. |
| ;:%%(color: blue)''I usually open an existing object (i.e. User.java or Resume.java) and save it as a new file. Then I delete all the methods and properties. This gives me the basic JavaDoc header. I'm sure I could edit Eclipse templates to do this, but since I develop on 3 different machines, this is just easier.''%% |
|
| In the code snippet above, we're extending [BaseObject|http://raibledesigns.com/downloads/appfuse/api/org/appfuse/model/BaseObject.java.html] because it has the following useful methods: toString(), equals(), hashCode() - the latter two |
| are required by Hibernate. |
|
| At line 172 changed 1 line. |
| To start, create a PersonDaoTest.java class in the test/dao/**/dao directory. This class should extend [BaseDaoTestCase|http://raibledesigns.com/downloads/appfuse/api/org/appfuse/dao/BaseDaoTestCase.java.html], which already exists in this package. This parent class is used to load [Spring's|http://www.springframework.org] ApplicationContext (since Spring binds the layers together), and for automatically loading a .properties file (ResourceBundle) that has the same name as your *Test.class. In this example, if you put a PersonDaoTest.properties file in the same directory as PersonDaoTest.java, this file's properties will be available via an "rb" variable. |
| To start, create a PersonDaoTest.java class in the test/dao/**/dao directory. This class should extend [BaseDaoTestCase|http://raibledesigns.com/downloads/appfuse/api/org/appfuse/dao/BaseDaoTestCase.java.html], which already exists in this package. This parent class is used to load [Spring's|http://www.springframework.org] ApplicationContext (since Spring binds the layers together), and for (optionally) loading a .properties file (ResourceBundle) that has the same name as your *Test.class. In this example, if you put a PersonDaoTest.properties file in the same directory as PersonDaoTest.java, this file's properties will be available via an "rb" variable. |
| At line 180 removed 2 lines. |
| import org.apache.commons.logging.Log; |
| import org.apache.commons.logging.LogFactory; |
| At line 187 removed 1 line. |
| //~ Instance fields ======================================================== |
| At line 191 removed 1 line. |
| //~ Methods ================================================================ |
| At line 193 removed 1 line. |
| log = LogFactory.getLog(PersonDaoTest.class); |
| At line 200 removed 4 lines. |
|
| public static void main(String[] args) { |
| junit.textui.TestRunner.run(PersonDaoTest.class); |
| } |
| At line 236 changed 1 line. |
| assertTrue(person.getLastName().equals("Last Name Updated")); |
| assertEquals(person.getLastName(), "Last Name Updated"); |
| At line 254 changed 1 line. |
| assertNull(dao.getPerson(person.getId())); |
|
| try { |
| person = dao.getPerson(person.getId()); |
| fail("Person found in database"); |
| } catch (DataAccessException dae) { |
| log.debug("Expected exception: " + dae.getMessage()); |
| assertNotNull(dae); |
| } |
| At line 278 changed 1 line. |
| ;:''I tend to just hard-code test values into Java code - but the .properties file is an option.'' |
| ;:''I tend to just hard-code test values into Java code - but the .properties file is an option that works great for large objects.'' |
| At line 326 removed 4 lines. |
| import org.apache.commons.logging.Log; |
| import org.apache.commons.logging.LogFactory; |
|
|
| At line 337 removed 2 lines. |
| private Log log = LogFactory.getLog(PersonDaoHibernate.class); |
|
| At line 344 changed 1 line. |
| return (Person) getHibernateTemplate().get(Person.class, id); |
| Person person = (Person) getHibernateTemplate().get(Person.class, id); |
|
| if (person == null) { |
| throw new ObjectRetrievalFailureException(Person.class, id); |
| } |
|
| return person; |
| At line 352 changed 2 lines. |
| Object person = getHibernateTemplate().load(Person.class, id); |
| getHibernateTemplate().delete(person); |
| // object must be loaded before it can be deleted |
| getHibernateTemplate().delete(getPerson(id)); |
| At line 366 changed 2 lines. |
| .excludeZeroes() //exclude zero valued properties |
| .ignoreCase(); //perform case insensitive string comparisons |
| .excludeZeroes() // exclude zero valued properties |
| .ignoreCase(); // perform case insensitive string comparisons |
| At line 373 changed 1 line. |
| throw new DAOException(e); |
| throw new DataAccessException(e.getMessage()); |
| At line 419 changed 1 line. |
| ''Next Up:'' __Part II:__ [Creating new Managers|CreateManager] - A HowTo for creating [Business Delegates|http://java.sun.com/blueprints/corej2eepatterns/Patterns/BusinessDelegate.html] that talk to the database tier (DAOs) and the web tier (Struts Actions). |
| ''Next Up:'' __Part II:__ [Creating new Managers|CreateManager] - A HowTo for creating Business Facades, which are similar to [Session Facades|http://java.sun.com/blueprints/patterns/SessionFacade.html], but don't use EJBs. These facades are used to provide communication from the front-end to the DAO layer. |