|
From: <gca...@us...> - 2011-11-30 17:24:45
|
Revision: 3713
http://openutils.svn.sourceforge.net/openutils/?rev=3713&view=rev
Author: gcatania
Date: 2011-11-30 17:24:37 +0000 (Wed, 30 Nov 2011)
Log Message:
-----------
BSHD-2 unit tests: reworked hibernate entities, added failing unit test for lookup by id
Modified Paths:
--------------
trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/HibernateDAOTest.java
trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/dao/PersonDAO.java
trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Person.java
trunk/openutils-bshd5/src/test/resources/hibernate.cfg.xml
Added Paths:
-----------
trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/dao/CarDAO.java
trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Car.java
trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/CarMaker.java
trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/CarModel.java
trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/CurrencyAmount.java
trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Owner.java
Removed Paths:
-------------
trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Chance.java
trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/FantasticThing.java
trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Wish.java
Modified: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/HibernateDAOTest.java
===================================================================
--- trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/HibernateDAOTest.java 2011-11-30 15:11:36 UTC (rev 3712)
+++ trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/HibernateDAOTest.java 2011-11-30 17:24:37 UTC (rev 3713)
@@ -25,16 +25,22 @@
package it.openutils.hibernate.test;
+import it.openutils.hibernate.test.dao.CarDAO;
import it.openutils.hibernate.test.dao.PersonDAO;
import it.openutils.hibernate.test.model.Address;
+import it.openutils.hibernate.test.model.Car;
+import it.openutils.hibernate.test.model.CarMaker;
+import it.openutils.hibernate.test.model.CarModel;
+import it.openutils.hibernate.test.model.CurrencyAmount;
import it.openutils.hibernate.test.model.FullName;
+import it.openutils.hibernate.test.model.Owner;
import it.openutils.hibernate.test.model.Person;
-import it.openutils.hibernate.test.model.Wish;
+import java.util.Calendar;
import java.util.Collections;
+import java.util.GregorianCalendar;
import java.util.List;
-import org.hibernate.Hibernate;
import org.hibernate.criterion.Example;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
@@ -52,28 +58,61 @@
/*
* TODO tests to perform: 1) find filtered with collection with zero, one or more elements 2) find filtered with
- * additional criteria 3) filter metadata support
+ * additional criteria 3) filter metadata support 4) find filtered with id 5) find filtered with backref
*/
@Autowired
private PersonDAO personDAO;
- private Person fifteenYearsOld()
+ @Autowired
+ private CarDAO carDAO;
+
+ private Person alice()
{
- return new Person(
- new FullName("Troy", "Jones"),
- 15,
- new Address("Long road", 15, "Smalltown", "MI", 14352),
- null);
+ FullName fullName = new FullName("Alice", "McBeal");
+ Calendar birthDate = new GregorianCalendar(1970, Calendar.MARCH, 7);
+ Address address = new Address("Long road", 15, "Smalltown", "MI", 14352);
+ Person p = new Person();
+ p.setName(fullName);
+ p.setBirthDate(birthDate);
+ p.setFiscalAddress(address);
+ p.setCurrentAddress(address);
+ return p;
}
+ private Owner bob()
+ {
+ FullName fullName = new FullName("Bob", "Kelso");
+ Calendar birthDate = new GregorianCalendar(1950, Calendar.MARCH, 7);
+ Address address = new Address("Sacred Heart Lane", 3, "Smalltown", "CA", 11243);
+ Owner o = new Owner();
+ o.setName(fullName);
+ o.setBirthDate(birthDate);
+ o.setFiscalAddress(address);
+ o.setCurrentAddress(address);
+ return o;
+ }
+
+ private Owner chuck()
+ {
+ FullName fullName = new FullName("Chuck", "Palahniuk");
+ Calendar birthDate = new GregorianCalendar(1962, Calendar.FEBRUARY, 21);
+ Address address = new Address("Awesome Street", 2, "Pasco", "WA", 13121);
+ Owner p = new Owner();
+ p.setName(fullName);
+ p.setBirthDate(birthDate);
+ p.setFiscalAddress(address);
+ p.setCurrentAddress(address);
+ return p;
+ }
+
/**
* basic save/evict/get test.
*/
@Test
public void testSaveAndRetrievePerson()
{
- Person person = fifteenYearsOld();
+ Person person = alice();
Long savedId = personDAO.save(person);
Assert.assertNotNull(savedId);
Long personId = person.getId();
@@ -86,52 +125,100 @@
@Test
public void testFindFilteredFirst()
{
- personDAO.save(fifteenYearsOld());
- List<Person> found = personDAO.findFiltered(new Person(new FullName(null, "Jones"), null, null, null));
- Assert.assertTrue(found.size() > 0, "No persons found.");
+ Person alice = alice();
+ personDAO.save(alice);
+ Person filter = new Person();
+ filter.setName(new FullName(null, "McBeal"));
+ List<Person> found = personDAO.findFiltered(filter);
+
+ Assert.assertEquals(found.size(), 1, "No persons found.");
+ Assert.assertEquals(found.get(0), alice);
}
@Test
- public void testExampleBasic()
+ public void testFindFilteredById()
{
- personDAO.save(fifteenYearsOld());
- Person outsideFilter = fifteenYearsOld();
- outsideFilter.getName().setFamilyName("Mahoney");
- personDAO.save(outsideFilter);
- Person filter = new Person(new FullName(null, "Jones"), null, null, null);
- List<Person> foundByExample = personDAO.find(Collections.singletonList(Example.create(filter)));
- Assert.assertNotNull(foundByExample);
- Assert.assertEquals(foundByExample.size(), 1);
- Assert.assertEquals(foundByExample.get(0).getName().getFamilyName(), "Jones");
+ Person alice = alice();
+ Long savedId = personDAO.save(alice);
+ Person filter = new Person();
+ filter.setId(savedId);
+ List<Person> found = personDAO.findFiltered(filter);
- List<Person> found = personDAO.findFiltered(filter);
- Assert.assertNotNull(found);
- Assert.assertEquals(found.size(), 1);
- Assert.assertEquals(found.get(0).getName().getFamilyName(), "Jones");
+ Assert.assertEquals(found.size(), 1, "No persons found.");
+ Assert.assertEquals(found.get(0), alice);
}
+ /*
+ * disabled: filter by id on child objects isn't working yet (see
+ * http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/querycriteria.html#querycriteria-examples and
+ * https://forum.hibernate.org/viewtopic.php?f=9&t=1004833&view=next )
+ */
+ @Test(enabled = false)
+ public void testFindFilteredByChildId()
+ {
+ Owner bob = bob();
+ CarMaker toyota = new CarMaker();
+ toyota.setName("Toyota");
+ toyota.setCapitalization(new CurrencyAmount(12000, "YEN"));
+ CarModel prius = new CarModel();
+ prius.setName("Prius");
+ prius.setYear(Integer.valueOf(2008));
+ toyota.setModels(Collections.singletonList(prius));
+
+ Car bobsPrius = new Car(new GregorianCalendar(2010, Calendar.OCTOBER, 12), prius, toyota);
+ bob.setCars(Collections.singleton(bobsPrius));
+ personDAO.save(bob);
+
+ Owner filter = new Owner();
+ Car carFilter = new Car(null, null, null);
+ carFilter.setId(bobsPrius.getId());
+ filter.setCars(Collections.singleton(carFilter));
+ Person found = personDAO.findFilteredFirst(filter);
+ Assert.assertEquals(found.getName(), bob.getName());
+ }
+
@Test
- public void testExampleAssociations()
+ public void testExampleBasic()
{
- Person fifteenYearsOld = fifteenYearsOld();
- fifteenYearsOld.setWish(new Wish(fifteenYearsOld, "because he's young"));
- personDAO.save(fifteenYearsOld);
- Person another = fifteenYearsOld();
- another.setWish(new Wish(another, "because he's a nerd"));
- personDAO.save(another);
-
+ personDAO.save(alice());
+ Person outsideFilter = alice();
+ outsideFilter.getName().setFamilyName("Mahoney");
+ personDAO.save(outsideFilter);
Person filter = new Person();
- filter.setWish(new Wish(null, "because he's young"));
+ filter.setName(new FullName(null, "McBeal"));
List<Person> foundByExample = personDAO.find(Collections.singletonList(Example.create(filter)));
- Hibernate.initialize(foundByExample);
Assert.assertNotNull(foundByExample);
- Assert.assertEquals(foundByExample.size(), 2);
+ Assert.assertEquals(foundByExample.size(), 1);
+ Assert.assertEquals(foundByExample.get(0).getName().getFamilyName(), "McBeal");
List<Person> found = personDAO.findFiltered(filter);
- Hibernate.initialize(found);
Assert.assertNotNull(found);
Assert.assertEquals(found.size(), 1);
- Assert.assertEquals(found.get(0).getWish().getReason(), "because he's young");
+ Assert.assertEquals(found.get(0).getName().getFamilyName(), "McBeal");
}
+ // @Test
+ // public void testExampleAssociations()
+ // {
+ // Person fifteenYearsOld = fifteenYearsOld();
+ // fifteenYearsOld.setWish(new Wish(fifteenYearsOld, "because he's young"));
+ // personDAO.save(fifteenYearsOld);
+ // Person another = fifteenYearsOld();
+ // another.setWish(new Wish(another, "because he's a nerd"));
+ // personDAO.save(another);
+ //
+ // Person filter = new Person();
+ // filter.setWish(new Wish(null, "because he's young"));
+ // List<Person> foundByExample = personDAO.find(Collections.singletonList(Example.create(filter)));
+ // Hibernate.initialize(foundByExample);
+ // Assert.assertNotNull(foundByExample);
+ // Assert.assertEquals(foundByExample.size(), 2);
+ //
+ // List<Person> found = personDAO.findFiltered(filter);
+ // Hibernate.initialize(found);
+ // Assert.assertNotNull(found);
+ // Assert.assertEquals(found.size(), 1);
+ // Assert.assertEquals(found.get(0).getWish().getReason(), "because he's young");
+ // }
+
}
Added: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/dao/CarDAO.java
===================================================================
--- trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/dao/CarDAO.java (rev 0)
+++ trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/dao/CarDAO.java 2011-11-30 17:24:37 UTC (rev 3713)
@@ -0,0 +1,55 @@
+/**
+ *
+ * openutils base Spring-Hibernate DAO (http://www.openmindlab.com/lab/products/bshd5.html)
+ *
+ * Copyright(C) 2005-2011, Openmind S.r.l. http://www.openmindonline.it
+ *
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl-2.1.html
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package it.openutils.hibernate.test.dao;
+
+import it.openutils.dao.hibernate.HibernateDAO;
+import it.openutils.dao.hibernate.HibernateDAOImpl;
+import it.openutils.hibernate.test.model.Person;
+
+import org.hibernate.SessionFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Repository;
+
+
+/**
+ * @author gcatania
+ */
+public interface CarDAO extends HibernateDAO<Person, Long>
+{
+
+ @Repository("carDAO")
+ class PersonDAOImpl extends HibernateDAOImpl<Person, Long> implements CarDAO
+ {
+
+ @Autowired
+ public PersonDAOImpl(SessionFactory factory)
+ {
+ super(Person.class);
+ setSessionFactory(factory);
+ }
+ }
+
+}
Property changes on: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/dao/CarDAO.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Modified: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/dao/PersonDAO.java
===================================================================
--- trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/dao/PersonDAO.java 2011-11-30 15:11:36 UTC (rev 3712)
+++ trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/dao/PersonDAO.java 2011-11-30 17:24:37 UTC (rev 3713)
@@ -40,9 +40,6 @@
public interface PersonDAO extends HibernateDAO<Person, Long>
{
- /**
- * @author gcatania
- */
@Repository("personDAO")
class PersonDAOImpl extends HibernateDAOImpl<Person, Long> implements PersonDAO
{
Added: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Car.java
===================================================================
--- trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Car.java (rev 0)
+++ trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Car.java 2011-11-30 17:24:37 UTC (rev 3713)
@@ -0,0 +1,150 @@
+/**
+ *
+ * openutils base Spring-Hibernate DAO (http://www.openmindlab.com/lab/products/bshd5.html)
+ *
+ * Copyright(C) 2005-2011, Openmind S.r.l. http://www.openmindonline.it
+ *
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl-2.1.html
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package it.openutils.hibernate.test.model;
+
+import java.util.Calendar;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+
+
+/**
+ * @author gcatania
+ */
+@Entity
+public class Car
+{
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ private Long id;
+
+ @ManyToOne
+ private final CarModel model;
+
+ @ManyToOne
+ private final CarMaker maker;
+
+ @ManyToOne
+ private Owner owner;
+
+ @Column
+ private Calendar registrationDate;
+
+ @Column
+ private CurrencyAmount marketValue;
+
+ public Car(Calendar registrationDate, CarModel model, CarMaker maker)
+ {
+ this.model = model;
+ this.maker = maker;
+ }
+
+ /**
+ * @return the id
+ */
+ public Long getId()
+ {
+ return id;
+ }
+
+ /**
+ * @param id the id to set
+ */
+ public void setId(Long id)
+ {
+ this.id = id;
+ }
+
+ /**
+ * @return the owner
+ */
+ public Owner getOwner()
+ {
+ return owner;
+ }
+
+ /**
+ * @param owner the owner to set
+ */
+ public void setOwner(Owner owner)
+ {
+ this.owner = owner;
+ }
+
+ /**
+ * @return the registrationDate
+ */
+ public Calendar getRegistrationDate()
+ {
+ return registrationDate;
+ }
+
+ /**
+ * @param registrationDate the registrationDate to set
+ */
+ public void setRegistrationDate(Calendar registrationDate)
+ {
+ this.registrationDate = registrationDate;
+ }
+
+ /**
+ * @return the marketValue
+ */
+ public CurrencyAmount getMarketValue()
+ {
+ return marketValue;
+ }
+
+ /**
+ * @param marketValue the marketValue to set
+ */
+ public void setMarketValue(CurrencyAmount marketValue)
+ {
+ this.marketValue = marketValue;
+ }
+
+ /**
+ * @return the model
+ */
+ public CarModel getModel()
+ {
+ return model;
+ }
+
+ /**
+ * @return the maker
+ */
+ public CarMaker getMaker()
+ {
+ return maker;
+ }
+
+}
Property changes on: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Car.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/CarMaker.java
===================================================================
--- trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/CarMaker.java (rev 0)
+++ trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/CarMaker.java 2011-11-30 17:24:37 UTC (rev 3713)
@@ -0,0 +1,119 @@
+/**
+ *
+ * openutils base Spring-Hibernate DAO (http://www.openmindlab.com/lab/products/bshd5.html)
+ *
+ * Copyright(C) 2005-2011, Openmind S.r.l. http://www.openmindonline.it
+ *
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl-2.1.html
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package it.openutils.hibernate.test.model;
+
+import java.util.List;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+
+
+/**
+ * @author gcatania
+ */
+@Entity
+public class CarMaker
+{
+
+ @Id
+ private Long id;
+
+ @Column
+ private String name;
+
+ @Column
+ private CurrencyAmount capitalization;
+
+ @OneToMany
+ private List<CarModel> models;
+
+ /**
+ * @return the id
+ */
+ public Long getId()
+ {
+ return id;
+ }
+
+ /**
+ * @param id the id to set
+ */
+ public void setId(Long id)
+ {
+ this.id = id;
+ }
+
+ /**
+ * @return the name
+ */
+ public String getName()
+ {
+ return name;
+ }
+
+ /**
+ * @param name the name to set
+ */
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ /**
+ * @return the capitalization
+ */
+ public CurrencyAmount getCapitalization()
+ {
+ return capitalization;
+ }
+
+ /**
+ * @param capitalization the capitalization to set
+ */
+ public void setCapitalization(CurrencyAmount capitalization)
+ {
+ this.capitalization = capitalization;
+ }
+
+ /**
+ * @return the models
+ */
+ public List<CarModel> getModels()
+ {
+ return models;
+ }
+
+ /**
+ * @param models the models to set
+ */
+ public void setModels(List<CarModel> models)
+ {
+ this.models = models;
+ }
+
+}
Property changes on: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/CarMaker.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Added: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/CarModel.java
===================================================================
--- trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/CarModel.java (rev 0)
+++ trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/CarModel.java 2011-11-30 17:24:37 UTC (rev 3713)
@@ -0,0 +1,97 @@
+/**
+ *
+ * openutils base Spring-Hibernate DAO (http://www.openmindlab.com/lab/products/bshd5.html)
+ *
+ * Copyright(C) 2005-2011, Openmind S.r.l. http://www.openmindonline.it
+ *
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl-2.1.html
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package it.openutils.hibernate.test.model;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+
+
+/**
+ * @author gcatania
+ */
+@Entity
+public class CarModel
+{
+
+ @Id
+ private Long id;
+
+ @Column
+ private String name;
+
+ @Column
+ private Integer year;
+
+ /**
+ * @return the id
+ */
+ public Long getId()
+ {
+ return id;
+ }
+
+ /**
+ * @param id the id to set
+ */
+ public void setId(Long id)
+ {
+ this.id = id;
+ }
+
+ /**
+ * @return the name
+ */
+ public String getName()
+ {
+ return name;
+ }
+
+ /**
+ * @param name the name to set
+ */
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ /**
+ * @return the year
+ */
+ public Integer getYear()
+ {
+ return year;
+ }
+
+ /**
+ * @param year the year to set
+ */
+ public void setYear(Integer year)
+ {
+ this.year = year;
+ }
+
+}
Property changes on: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/CarModel.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Deleted: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Chance.java
===================================================================
--- trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Chance.java 2011-11-30 15:11:36 UTC (rev 3712)
+++ trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Chance.java 2011-11-30 17:24:37 UTC (rev 3713)
@@ -1,35 +0,0 @@
-/**
- *
- * openutils base Spring-Hibernate DAO (http://www.openmindlab.com/lab/products/bshd5.html)
- *
- * Copyright(C) 2005-2011, Openmind S.r.l. http://www.openmindonline.it
- *
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * You may obtain a copy of the License at
- *
- * http://www.gnu.org/licenses/lgpl-2.1.html
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package it.openutils.hibernate.test.model;
-
-/**
- * @author gcatania
- */
-public enum Chance {
-
- /** chance. */
- TOTALLY_REMOTE, VAGUELY_POSSIBLE, QUITE_POSSIBLE, CAKEWALK_EASY
-}
Added: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/CurrencyAmount.java
===================================================================
--- trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/CurrencyAmount.java (rev 0)
+++ trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/CurrencyAmount.java 2011-11-30 17:24:37 UTC (rev 3713)
@@ -0,0 +1,65 @@
+/**
+ *
+ * openutils base Spring-Hibernate DAO (http://www.openmindlab.com/lab/products/bshd5.html)
+ *
+ * Copyright(C) 2005-2011, Openmind S.r.l. http://www.openmindonline.it
+ *
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl-2.1.html
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package it.openutils.hibernate.test.model;
+
+import javax.persistence.Embeddable;
+
+
+/**
+ * @author gcatania
+ */
+@Embeddable
+public class CurrencyAmount
+{
+
+ private final double amount;
+
+ private final String currency;
+
+ public CurrencyAmount(double amount, String currency)
+ {
+ super();
+ this.amount = amount;
+ this.currency = currency;
+ }
+
+ /**
+ * @return the amount
+ */
+ public double getAmount()
+ {
+ return amount;
+ }
+
+ /**
+ * @return the currency
+ */
+ public String getCurrency()
+ {
+ return currency;
+ }
+
+}
Property changes on: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/CurrencyAmount.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Deleted: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/FantasticThing.java
===================================================================
--- trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/FantasticThing.java 2011-11-30 15:11:36 UTC (rev 3712)
+++ trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/FantasticThing.java 2011-11-30 17:24:37 UTC (rev 3713)
@@ -1,214 +0,0 @@
-/**
- *
- * openutils base Spring-Hibernate DAO (http://www.openmindlab.com/lab/products/bshd5.html)
- *
- * Copyright(C) 2005-2011, Openmind S.r.l. http://www.openmindonline.it
- *
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * You may obtain a copy of the License at
- *
- * http://www.gnu.org/licenses/lgpl-2.1.html
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package it.openutils.hibernate.test.model;
-
-import java.util.Set;
-
-import javax.persistence.CascadeType;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.ManyToMany;
-
-
-/**
- * @author gcatania
- */
-@Entity
-public class FantasticThing
-{
-
- @Id
- @GeneratedValue(strategy = GenerationType.AUTO)
- private Long id;
-
- private String thingName;
-
- private Chance chanceOfAchievement;
-
- @ManyToMany(mappedBy = "objectsOfWish", cascade = CascadeType.ALL)
- private Set<Wish> wishes;
-
- public FantasticThing()
- {
- }
-
- public FantasticThing(String thingName, Chance chanceOfAchievement)
- {
- this.thingName = thingName;
- this.chanceOfAchievement = chanceOfAchievement;
- }
-
- /**
- * @return the id
- */
- public Long getId()
- {
- return id;
- }
-
- /**
- * @param id the id to set
- */
- public void setId(Long id)
- {
- this.id = id;
- }
-
- /**
- * @return the thingName
- */
- public String getThingName()
- {
- return thingName;
- }
-
- /**
- * @param thingName the thingName to set
- */
- public void setThingName(String thingName)
- {
- this.thingName = thingName;
- }
-
- /**
- * @return the chanceOfAchievement
- */
- public Chance getChanceOfAchievement()
- {
- return chanceOfAchievement;
- }
-
- /**
- * @param chanceOfAchievement the chanceOfAchievement to set
- */
- public void setChanceOfAchievement(Chance chanceOfAchievement)
- {
- this.chanceOfAchievement = chanceOfAchievement;
- }
-
- /**
- * @return the wishes
- */
- public Set<Wish> getWishes()
- {
- return wishes;
- }
-
- /**
- * @param wishes the wishes to set
- */
- public void setWishes(Set<Wish> wishes)
- {
- this.wishes = wishes;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int hashCode()
- {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((chanceOfAchievement == null) ? 0 : chanceOfAchievement.hashCode());
- result = prime * result + ((id == null) ? 0 : id.hashCode());
- result = prime * result + ((thingName == null) ? 0 : thingName.hashCode());
- return result;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals(Object obj)
- {
- if (this == obj)
- {
- return true;
- }
- if (obj == null)
- {
- return false;
- }
- if (getClass() != obj.getClass())
- {
- return false;
- }
- FantasticThing other = (FantasticThing) obj;
- if (chanceOfAchievement == null)
- {
- if (other.chanceOfAchievement != null)
- {
- return false;
- }
- }
- else if (!chanceOfAchievement.equals(other.chanceOfAchievement))
- {
- return false;
- }
- if (id == null)
- {
- if (other.id != null)
- {
- return false;
- }
- }
- else if (!id.equals(other.id))
- {
- return false;
- }
- if (thingName == null)
- {
- if (other.thingName != null)
- {
- return false;
- }
- }
- else if (!thingName.equals(other.thingName))
- {
- return false;
- }
- return true;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString()
- {
- return "FantasticThing [chanceOfAchievement="
- + chanceOfAchievement
- + ", id="
- + id
- + ", thingName="
- + thingName
- + "]";
- }
-
-}
Added: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Owner.java
===================================================================
--- trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Owner.java (rev 0)
+++ trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Owner.java 2011-11-30 17:24:37 UTC (rev 3713)
@@ -0,0 +1,87 @@
+/**
+ *
+ * openutils base Spring-Hibernate DAO (http://www.openmindlab.com/lab/products/bshd5.html)
+ *
+ * Copyright(C) 2005-2011, Openmind S.r.l. http://www.openmindonline.it
+ *
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl-2.1.html
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package it.openutils.hibernate.test.model;
+
+import java.util.Set;
+
+import javax.persistence.DiscriminatorColumn;
+import javax.persistence.DiscriminatorValue;
+import javax.persistence.Entity;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.OneToMany;
+import javax.persistence.Transient;
+
+
+/**
+ * @author gcatania
+ */
+@Entity
+@Inheritance(strategy = InheritanceType.JOINED)
+@DiscriminatorColumn(name = "personType")
+@DiscriminatorValue("owner")
+public class Owner extends Person
+{
+
+ @OneToMany
+ private Set<Car> cars;
+
+ @Transient
+ private CurrencyAmount totalValueOfCars;
+
+ /**
+ * @return the cars
+ */
+ public Set<Car> getCars()
+ {
+ return cars;
+ }
+
+ /**
+ * @param cars the cars to set
+ */
+ public void setCars(Set<Car> cars)
+ {
+ this.cars = cars;
+ }
+
+ /**
+ * @param totalValueOfCars the totalValueOfCars to set
+ */
+ public void setTotalValueOfCars(CurrencyAmount totalValueOfCars)
+ {
+ this.totalValueOfCars = totalValueOfCars;
+ }
+
+ /**
+ * @return the totalValueOfCars
+ */
+ public CurrencyAmount getTotalValueOfCars()
+ {
+ return totalValueOfCars;
+ }
+
+}
Property changes on: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Owner.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Author Date Id Revision
Added: svn:eol-style
+ native
Modified: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Person.java
===================================================================
--- trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Person.java 2011-11-30 15:11:36 UTC (rev 3712)
+++ trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Person.java 2011-11-30 17:24:37 UTC (rev 3713)
@@ -25,22 +25,28 @@
package it.openutils.hibernate.test.model;
+import java.util.Calendar;
+
import javax.persistence.CascadeType;
import javax.persistence.Column;
+import javax.persistence.DiscriminatorColumn;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
import javax.persistence.ManyToOne;
-import javax.persistence.OneToOne;
/**
* @author gcatania
*/
@Entity
+@Inheritance(strategy = InheritanceType.JOINED)
+@DiscriminatorColumn(name = "personType")
public class Person
{
@@ -51,8 +57,8 @@
@Embedded
private FullName name;
- @Column(nullable = false, scale = 3)
- private Integer age;
+ @Column(nullable = false)
+ private Calendar birthDate;
@ManyToOne(fetch = FetchType.EAGER, optional = false, cascade = CascadeType.ALL)
private Address currentAddress;
@@ -60,21 +66,6 @@
@ManyToOne(cascade = CascadeType.ALL)
private Address fiscalAddress;
- @OneToOne(cascade = CascadeType.ALL)
- private Wish wish;
-
- public Person()
- {
- }
-
- public Person(FullName name, Integer age, Address currentAddress, Address fiscalAddress)
- {
- this.name = name;
- this.age = age;
- this.currentAddress = currentAddress;
- this.fiscalAddress = fiscalAddress;
- }
-
/**
* @return the id
*/
@@ -108,6 +99,22 @@
}
/**
+ * @return the birthDate
+ */
+ public Calendar getBirthDate()
+ {
+ return birthDate;
+ }
+
+ /**
+ * @param birthDate the birthDate to set
+ */
+ public void setBirthDate(Calendar birthDate)
+ {
+ this.birthDate = birthDate;
+ }
+
+ /**
* @return the currentAddress
*/
public Address getCurrentAddress()
@@ -140,22 +147,6 @@
}
/**
- * @return the wish
- */
- public Wish getWish()
- {
- return wish;
- }
-
- /**
- * @param wish the wish to set
- */
- public void setWish(Wish wish)
- {
- this.wish = wish;
- }
-
- /**
* {@inheritDoc}
*/
@Override
@@ -163,12 +154,11 @@
{
final int prime = 31;
int result = 1;
- result = prime * result + ((age == null) ? 0 : age);
+ result = prime * result + ((birthDate == null) ? 0 : birthDate.hashCode());
result = prime * result + ((currentAddress == null) ? 0 : currentAddress.hashCode());
result = prime * result + ((fiscalAddress == null) ? 0 : fiscalAddress.hashCode());
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
- result = prime * result + ((wish == null) ? 0 : wish.hashCode());
return result;
}
@@ -191,14 +181,14 @@
return false;
}
Person other = (Person) obj;
- if (age == null)
+ if (birthDate == null)
{
- if (other.age != null)
+ if (other.birthDate != null)
{
return false;
}
}
- else if (!age.equals(other.age))
+ else if (!birthDate.equals(other.birthDate))
{
return false;
}
@@ -246,17 +236,6 @@
{
return false;
}
- if (wish == null)
- {
- if (other.wish != null)
- {
- return false;
- }
- }
- else if (!wish.equals(other.wish))
- {
- return false;
- }
return true;
}
@@ -266,9 +245,7 @@
@Override
public String toString()
{
- return "Person [age="
- + age
- + ", currentAddress="
+ return "Person [currentAddress="
+ currentAddress
+ ", fiscalAddress="
+ fiscalAddress
@@ -276,8 +253,6 @@
+ id
+ ", name="
+ name
- + ", wish="
- + wish
+ "]";
}
Deleted: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Wish.java
===================================================================
--- trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Wish.java 2011-11-30 15:11:36 UTC (rev 3712)
+++ trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Wish.java 2011-11-30 17:24:37 UTC (rev 3713)
@@ -1,260 +0,0 @@
-/**
- *
- * openutils base Spring-Hibernate DAO (http://www.openmindlab.com/lab/products/bshd5.html)
- *
- * Copyright(C) 2005-2011, Openmind S.r.l. http://www.openmindonline.it
- *
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * You may obtain a copy of the License at
- *
- * http://www.gnu.org/licenses/lgpl-2.1.html
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package it.openutils.hibernate.test.model;
-
-import java.util.Set;
-
-import javax.persistence.CascadeType;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.ManyToMany;
-import javax.persistence.OneToOne;
-import javax.persistence.Transient;
-
-
-/**
- * @author gcatania
- */
-@Entity
-public class Wish
-{
-
- @Id
- @GeneratedValue(strategy = GenerationType.AUTO)
- private Long id;
-
- @OneToOne(mappedBy = "wish", optional = false, cascade = CascadeType.ALL)
- private Person person;
-
- @Column(nullable = false)
- private String reason;
-
- @ManyToMany(cascade = CascadeType.ALL)
- private Set<FantasticThing> objectsOfWish;
-
- @Transient
- private Integer objectCount;
-
- public Wish()
- {
- }
-
- public Wish(Person person, String reason)
- {
- this.person = person;
- this.reason = reason;
- }
-
- /**
- * @return the id
- */
- public Long getId()
- {
- return id;
- }
-
- /**
- * @param id the id to set
- */
- public void setId(Long id)
- {
- this.id = id;
- }
-
- /**
- * @return the person
- */
- public Person getPerson()
- {
- return person;
- }
-
- /**
- * @param person the person to set
- */
- public void setPerson(Person person)
- {
- this.person = person;
- }
-
- /**
- * @return the reason
- */
- public String getReason()
- {
- return reason;
- }
-
- /**
- * @param reason the reason to set
- */
- public void setReason(String reason)
- {
- this.reason = reason;
- }
-
- /**
- * @return the objectsOfWish
- */
- public Set<FantasticThing> getObjectsOfWish()
- {
- return objectsOfWish;
- }
-
- /**
- * @param objectsOfWish the objectsOfWish to set
- */
- public void setObjectsOfWish(Set<FantasticThing> objectsOfWish)
- {
- this.objectsOfWish = objectsOfWish;
- }
-
- /**
- * @return the objectCount
- */
- public Integer getObjectCount()
- {
- if (objectCount == null)
- {
- objectCount = objectsOfWish.size();
- }
- return objectCount;
- }
-
- /**
- * @param objectCount the objectCount to set
- */
- public void setObjectCount(Integer objectCount)
- {
- if (objectCount != null && objectCount != objectsOfWish.size())
- {
- throw new IllegalArgumentException();
- }
- this.objectCount = objectCount;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int hashCode()
- {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((id == null) ? 0 : id.hashCode());
- result = prime * result + ((objectCount == null) ? 0 : objectCount.hashCode());
- result = prime * result + ((objectsOfWish == null) ? 0 : objectsOfWish.hashCode());
- result = prime * result + ((reason == null) ? 0 : reason.hashCode());
- return result;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean equals(Object obj)
- {
- if (this == obj)
- {
- return true;
- }
- if (obj == null)
- {
- return false;
- }
- if (getClass() != obj.getClass())
- {
- return false;
- }
- Wish other = (Wish) obj;
- if (id == null)
- {
- if (other.id != null)
- {
- return false;
- }
- }
- else if (!id.equals(other.id))
- {
- return false;
- }
- if (objectCount == null)
- {
- if (other.objectCount != null)
- {
- return false;
- }
- }
- else if (!objectCount.equals(other.objectCount))
- {
- return false;
- }
- if (objectsOfWish == null)
- {
- if (other.objectsOfWish != null)
- {
- return false;
- }
- }
- else if (!objectsOfWish.equals(other.objectsOfWish))
- {
- return false;
- }
- if (reason == null)
- {
- if (other.reason != null)
- {
- return false;
- }
- }
- else if (!reason.equals(other.reason))
- {
- return false;
- }
- return true;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString()
- {
- return "Wish [id="
- + id
- + ", objectCount="
- + objectCount
- + ", objectsOfWish="
- + objectsOfWish
- + ", reason="
- + reason
- + "]";
- }
-
-}
Modified: trunk/openutils-bshd5/src/test/resources/hibernate.cfg.xml
===================================================================
--- trunk/openutils-bshd5/src/test/resources/hibernate.cfg.xml 2011-11-30 15:11:36 UTC (rev 3712)
+++ trunk/openutils-bshd5/src/test/resources/hibernate.cfg.xml 2011-11-30 17:24:37 UTC (rev 3713)
@@ -4,9 +4,11 @@
<hibernate-configuration>
<session-factory>
<mapping class="it.openutils.hibernate.test.model.Address" />
- <mapping class="it.openutils.hibernate.test.model.FantasticThing" />
+ <mapping class="it.openutils.hibernate.test.model.Car" />
+ <mapping class="it.openutils.hibernate.test.model.CarMaker" />
+ <mapping class="it.openutils.hibernate.test.model.CarModel" />
<mapping class="it.openutils.hibernate.test.model.FullName" />
+ <mapping class="it.openutils.hibernate.test.model.Owner" />
<mapping class="it.openutils.hibernate.test.model.Person" />
- <mapping class="it.openutils.hibernate.test.model.Wish" />
</session-factory>
</hibernate-configuration>
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|