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. |
From: <gca...@us...> - 2011-12-01 08:26:35
|
Revision: 3714 http://openutils.svn.sourceforge.net/openutils/?rev=3714&view=rev Author: gcatania Date: 2011-12-01 08:26:28 +0000 (Thu, 01 Dec 2011) Log Message: ----------- BSHD-2 adding model objects for unit tests Modified Paths: -------------- trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Owner.java trunk/openutils-bshd5/src/test/resources/hibernate.cfg.xml Added Paths: ----------- trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Designer.java trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Employee.java Added: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Designer.java =================================================================== --- trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Designer.java (rev 0) +++ trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Designer.java 2011-12-01 08:26:28 UTC (rev 3714) @@ -0,0 +1,82 @@ +/** + * + * 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.Column; +import javax.persistence.DiscriminatorValue; +import javax.persistence.Entity; +import javax.persistence.ManyToMany; + + +/** + * @author gcatania + */ +@Entity +@DiscriminatorValue("designer") +public class Designer extends Employee +{ + + @Column + private int hipsterFactor; + + @ManyToMany + Set<CarModel> designedModels; + + /** + * @return the hipsterFactor + */ + public int getHipsterFactor() + { + return hipsterFactor; + } + + /** + * @param hipsterFactor the hipsterFactor to set + */ + public void setHipsterFactor(int hipsterFactor) + { + this.hipsterFactor = hipsterFactor; + } + + /** + * @return the designedModels + */ + public Set<CarModel> getDesignedModels() + { + return designedModels; + } + + /** + * @param designedModels the designedModels to set + */ + public void setDesignedModels(Set<CarModel> designedModels) + { + this.designedModels = designedModels; + } + +} Property changes on: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Designer.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/Employee.java =================================================================== --- trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Employee.java (rev 0) +++ trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Employee.java 2011-12-01 08:26:28 UTC (rev 3714) @@ -0,0 +1,139 @@ +/** + * + * 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.DiscriminatorValue; +import javax.persistence.Entity; +import javax.persistence.ManyToOne; + + +/** + * @author gcatania + */ +@Entity +@DiscriminatorValue("employee") +public class Employee extends Person +{ + + @ManyToOne + private CarMaker employer; + + @Column + private CurrencyAmount grossAnnualSalary; + + @Column + private String qualification; + + @Column + private String department; + + @Column + private Calendar employedSince; + + /** + * @return the employer + */ + public CarMaker getEmployer() + { + return employer; + } + + /** + * @param employer the employer to set + */ + public void setEmployer(CarMaker employer) + { + this.employer = employer; + } + + /** + * @return the grossAnnualSalary + */ + public CurrencyAmount getGrossAnnualSalary() + { + return grossAnnualSalary; + } + + /** + * @param grossAnnualSalary the grossAnnualSalary to set + */ + public void setGrossAnnualSalary(CurrencyAmount grossAnnualSalary) + { + this.grossAnnualSalary = grossAnnualSalary; + } + + /** + * @return the qualification + */ + public String getQualification() + { + return qualification; + } + + /** + * @param qualification the qualification to set + */ + public void setQualification(String qualification) + { + this.qualification = qualification; + } + + /** + * @return the department + */ + public String getDepartment() + { + return department; + } + + /** + * @param department the department to set + */ + public void setDepartment(String department) + { + this.department = department; + } + + /** + * @return the employedSince + */ + public Calendar getEmployedSince() + { + return employedSince; + } + + /** + * @param employedSince the employedSince to set + */ + public void setEmployedSince(Calendar employedSince) + { + this.employedSince = employedSince; + } + +} Property changes on: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Employee.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/Owner.java =================================================================== --- trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Owner.java 2011-11-30 17:24:37 UTC (rev 3713) +++ trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Owner.java 2011-12-01 08:26:28 UTC (rev 3714) @@ -27,11 +27,8 @@ 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; @@ -40,8 +37,6 @@ * @author gcatania */ @Entity -@Inheritance(strategy = InheritanceType.JOINED) -@DiscriminatorColumn(name = "personType") @DiscriminatorValue("owner") public class Owner extends Person { Modified: trunk/openutils-bshd5/src/test/resources/hibernate.cfg.xml =================================================================== --- trunk/openutils-bshd5/src/test/resources/hibernate.cfg.xml 2011-11-30 17:24:37 UTC (rev 3713) +++ trunk/openutils-bshd5/src/test/resources/hibernate.cfg.xml 2011-12-01 08:26:28 UTC (rev 3714) @@ -7,6 +7,8 @@ <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.Designer" /> + <mapping class="it.openutils.hibernate.test.model.Employee" /> <mapping class="it.openutils.hibernate.test.model.FullName" /> <mapping class="it.openutils.hibernate.test.model.Owner" /> <mapping class="it.openutils.hibernate.test.model.Person" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gca...@us...> - 2011-12-02 15:39:08
|
Revision: 3729 http://openutils.svn.sourceforge.net/openutils/?rev=3729&view=rev Author: gcatania Date: 2011-12-02 15:39:01 +0000 (Fri, 02 Dec 2011) Log Message: ----------- BSHD-2 more unit tests Modified Paths: -------------- trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/HibernateDAOTest.java trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Car.java trunk/openutils-bshd5/src/test/resources/hibernate.cfg.xml Added Paths: ----------- trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/dao/StickerDAO.java trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Sticker.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-12-02 15:18:01 UTC (rev 3728) +++ trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/HibernateDAOTest.java 2011-12-02 15:39:01 UTC (rev 3729) @@ -28,6 +28,7 @@ import it.openutils.hibernate.test.dao.CarDAO; import it.openutils.hibernate.test.dao.CarMakerDAO; import it.openutils.hibernate.test.dao.PersonDAO; +import it.openutils.hibernate.test.dao.StickerDAO; import it.openutils.hibernate.test.model.Address; import it.openutils.hibernate.test.model.Car; import it.openutils.hibernate.test.model.CarMaker; @@ -37,8 +38,10 @@ 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.Sticker; import java.util.ArrayList; +import java.util.Arrays; import java.util.Calendar; import java.util.Collections; import java.util.GregorianCalendar; @@ -73,6 +76,9 @@ @Autowired private CarDAO carDAO; + @Autowired + private StickerDAO stickerDAO; + private static Person alice() { FullName fullName = new FullName("Alice", "McBeal"); @@ -165,7 +171,7 @@ return p; } - private Car bobsPrius(Owner bob, CarModel prius) + private static Car bobsPrius(Owner bob, CarModel prius) { Car bobsPrius = new Car(); bobsPrius.setModel(prius); @@ -176,7 +182,7 @@ return bobsPrius; } - private Car chucksPrius(Owner chuck, CarModel prius) + private static Car chucksPrius(Owner chuck, CarModel prius) { Car chucksPrius = new Car(); chucksPrius.setModel(prius); @@ -387,6 +393,32 @@ Assert.assertEquals(shouldBeBob.getName(), bob.getName()); } + @Test + public void testFindFilteredChildEntity() + { + Sticker st1 = new Sticker(); + st1.setName("Warning! Baby on board!"); + st1.setHeight(20d); + st1.setWidth(10d); + Sticker st2 = new Sticker(); + st2.setName("Object in the mirror are losing"); + st2.setHeight(5d); + st2.setWidth(10d); + Sticker st3 = new Sticker(); + st3.setName("(tribal tattoo sticker)"); + st3.setHeight(35d); + st3.setWidth(18d); + + Car chucksPrius = chucksPrius(chuck(), prius(toyota())); + chucksPrius.setStickers(Arrays.asList(st1, st2, st3)); + carDAO.save(chucksPrius); + carDAO.evict(chucksPrius); + Sticker filter = new Sticker(); + filter.setWidth(10d); + List<Sticker> found = stickerDAO.findFiltered(filter); + Assert.assertEquals(found.size(), 2); + } + // @Test // public void testExampleAssociations() // { Added: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/dao/StickerDAO.java =================================================================== --- trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/dao/StickerDAO.java (rev 0) +++ trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/dao/StickerDAO.java 2011-12-02 15:39:01 UTC (rev 3729) @@ -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.Sticker; + +import org.hibernate.SessionFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + + +/** + * @author gcatania + */ +public interface StickerDAO extends HibernateDAO<Sticker, Long> +{ + + @Repository("stickerDAO") + class StickerDAOImpl extends HibernateDAOImpl<Sticker, Long> implements StickerDAO + { + + @Autowired + public StickerDAOImpl(SessionFactory factory) + { + super(Sticker.class); + setSessionFactory(factory); + } + } + +} Property changes on: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/dao/StickerDAO.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/Car.java =================================================================== --- trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Car.java 2011-12-02 15:18:01 UTC (rev 3728) +++ trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Car.java 2011-12-02 15:39:01 UTC (rev 3729) @@ -26,6 +26,7 @@ package it.openutils.hibernate.test.model; import java.util.Calendar; +import java.util.List; import javax.persistence.CascadeType; import javax.persistence.Column; @@ -34,6 +35,7 @@ import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; /** @@ -59,6 +61,9 @@ @Column private CurrencyAmount marketValue; + @OneToMany(cascade = CascadeType.ALL) + private List<Sticker> stickers; + /** * @return the id */ @@ -140,6 +145,22 @@ } /** + * @return the stickers + */ + public List<Sticker> getStickers() + { + return stickers; + } + + /** + * @param stickers the stickers to set + */ + public void setStickers(List<Sticker> stickers) + { + this.stickers = stickers; + } + + /** * {@inheritDoc} */ @Override @@ -149,9 +170,8 @@ int result = 1; result = prime * result + ((id == null) ? 0 : id.hashCode()); result = prime * result + ((marketValue == null) ? 0 : marketValue.hashCode()); - result = prime * result + ((model == null) ? 0 : model.hashCode()); - result = prime * result + ((owner == null) ? 0 : owner.hashCode()); result = prime * result + ((registrationDate == null) ? 0 : registrationDate.hashCode()); + result = prime * result + ((stickers == null) ? 0 : stickers.hashCode()); return result; } @@ -196,39 +216,28 @@ { return false; } - if (model == null) + if (registrationDate == null) { - if (other.model != null) + if (other.registrationDate != null) { return false; } } - else if (!model.equals(other.model)) + else if (!registrationDate.equals(other.registrationDate)) { return false; } - if (owner == null) + if (stickers == null) { - if (other.owner != null) + if (other.stickers != null) { return false; } } - else if (!owner.equals(other.owner)) + else if (!stickers.equals(other.stickers)) { return false; } - if (registrationDate == null) - { - if (other.registrationDate != null) - { - return false; - } - } - else if (!registrationDate.equals(other.registrationDate)) - { - return false; - } return true; } @@ -242,14 +251,12 @@ builder .append("Car [id=") .append(id) - .append(", model=") - .append(model) - .append(", owner=") - .append(owner) .append(", registrationDate=") .append(registrationDate) .append(", marketValue=") .append(marketValue) + .append(", stickers=") + .append(stickers) .append("]"); return builder.toString(); } Added: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Sticker.java =================================================================== --- trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Sticker.java (rev 0) +++ trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Sticker.java 2011-12-02 15:39:01 UTC (rev 3729) @@ -0,0 +1,219 @@ +/** + * + * 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.GeneratedValue; +import javax.persistence.Id; + + +/** + * @author gcatania + */ +@Entity +public class Sticker +{ + + @Id + @GeneratedValue + private Long id; + + @Column + private String name; + + @Column + private Double height; + + @Column + private Double width; + + /** + * @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 height + */ + public Double getHeight() + { + return height; + } + + /** + * @param height the height to set + */ + public void setHeight(Double height) + { + this.height = height; + } + + /** + * @return the width + */ + public Double getWidth() + { + return width; + } + + /** + * @param width the width to set + */ + public void setWidth(Double width) + { + this.width = width; + } + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() + { + final int prime = 31; + int result = 1; + result = prime * result + ((height == null) ? 0 : height.hashCode()); + result = prime * result + ((id == null) ? 0 : id.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((width == null) ? 0 : width.hashCode()); + return result; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object obj) + { + if (this == obj) + { + return true; + } + if (obj == null) + { + return false; + } + if (!(obj instanceof Sticker)) + { + return false; + } + Sticker other = (Sticker) obj; + if (height == null) + { + if (other.height != null) + { + return false; + } + } + else if (!height.equals(other.height)) + { + return false; + } + if (id == null) + { + if (other.id != null) + { + return false; + } + } + else if (!id.equals(other.id)) + { + return false; + } + if (name == null) + { + if (other.name != null) + { + return false; + } + } + else if (!name.equals(other.name)) + { + return false; + } + if (width == null) + { + if (other.width != null) + { + return false; + } + } + else if (!width.equals(other.width)) + { + return false; + } + return true; + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() + { + StringBuilder builder = new StringBuilder(); + builder + .append("Sticker [id=") + .append(id) + .append(", name=") + .append(name) + .append(", height=") + .append(height) + .append(", width=") + .append(width) + .append("]"); + return builder.toString(); + } + +} Property changes on: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Sticker.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/resources/hibernate.cfg.xml =================================================================== --- trunk/openutils-bshd5/src/test/resources/hibernate.cfg.xml 2011-12-02 15:18:01 UTC (rev 3728) +++ trunk/openutils-bshd5/src/test/resources/hibernate.cfg.xml 2011-12-02 15:39:01 UTC (rev 3729) @@ -12,5 +12,6 @@ <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.Sticker" /> </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. |
From: <gca...@us...> - 2013-03-11 15:03:22
|
Revision: 4195 http://openutils.svn.sourceforge.net/openutils/?rev=4195&view=rev Author: gcatania Date: 2013-03-11 15:03:14 +0000 (Mon, 11 Mar 2013) Log Message: ----------- BSHD-19 failing tests added (currently disabled) Modified Paths: -------------- trunk/openutils-bshd5/src/test/resources/hibernate.cfg.xml Added Paths: ----------- trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/HibernateDAOLazyLoadTest.java trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/dao/BarDAO.java trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/dao/FooDAO.java trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Bar.java trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Foo.java trunk/openutils-bshd5/src/test/resources/preload-data.sql Added: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/HibernateDAOLazyLoadTest.java =================================================================== --- trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/HibernateDAOLazyLoadTest.java (rev 0) +++ trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/HibernateDAOLazyLoadTest.java 2013-03-11 15:03:14 UTC (rev 4195) @@ -0,0 +1,147 @@ +/** + * + * openutils base Spring-Hibernate DAO (http://www.openmindlab.com/lab/products/bshd5.html) + * + * Copyright(C) 2005-2012, 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; + +import it.openutils.hibernate.test.dao.BarDAO; +import it.openutils.hibernate.test.dao.FooDAO; +import it.openutils.hibernate.test.model.Bar; +import it.openutils.hibernate.test.model.Foo; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.testng.AbstractTransactionalTestNGSpringContextTests; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + + +/** + * @author gcatania + */ +@ContextConfiguration(locations = "/spring-tests.xml") +public class HibernateDAOLazyLoadTest extends AbstractTransactionalTestNGSpringContextTests +{ + + @Autowired + private FooDAO fooDAO; + + @Autowired + private BarDAO barDAO; + + @BeforeClass + protected final void preloadData() + { + executeSqlScript("/preload-data.sql", false); + } + + private List<Foo> findFoo(String s, Bar bar) + { + Foo filter = new Foo(); + filter.setBar(bar); + filter.setS(s); + List<Foo> found = fooDAO.findFiltered(filter); + return found; + } + + private void testFind(long barId, String fooStr, Bar bar) + { + List<Foo> found = findFoo(fooStr, bar); + Assert.assertEquals(found.size(), 1); + Foo foo = found.get(0); + Assert.assertEquals(foo.getS(), fooStr); + Assert.assertEquals(foo.getBar().getId().longValue(), barId); + } + + private void testDontFind(String fooStr, Bar bar) + { + List<Foo> found = findFoo(fooStr, bar); + Assert.assertEquals(found.size(), 0); + } + + private void testFindEager(long barId, String fooStr) + { + Bar bar = barDAO.get(barId); + testFind(barId, fooStr, bar); + } + + private void testFindLazy(long barId, String fooStr) + { + Bar bar = barDAO.load(barId); + testFind(barId, fooStr, bar); + } + + @Test + public void testFindWithEagerParent1() + { + testFindEager(1L, "foo1_2"); + } + + @Test + public void testFindWithEagerParent2() + { + testFindEager(1L, "fooX_X"); + } + + @Test + public void testFindWithLazyParent1() + { + testFindLazy(1L, "foo1_2"); + } + + /** + * FIXME enable this test and fix BSHD-19 + */ + @Test(enabled = false) + public void testFindWithLazyParent2() + { + testFindLazy(1L, "fooX_X"); + } + + @Test + public void testDontFindWithEagerParent() + { + long barId = 1L; + String fooStr = "foo2_2"; + + Bar bar1 = barDAO.get(barId); + testDontFind(fooStr, bar1); + } + + /** + * FIXME enable this test and fix BSHD-19 + */ + @Test(enabled = false) + public void testDontFindWithLazyParent() + { + long barId = 1L; + String fooStr = "foo2_2"; + + Bar bar1 = barDAO.load(barId); + testDontFind(fooStr, bar1); + } +} Property changes on: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/HibernateDAOLazyLoadTest.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/dao/BarDAO.java =================================================================== --- trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/dao/BarDAO.java (rev 0) +++ trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/dao/BarDAO.java 2013-03-11 15:03:14 UTC (rev 4195) @@ -0,0 +1,55 @@ +/** + * + * openutils base Spring-Hibernate DAO (http://www.openmindlab.com/lab/products/bshd5.html) + * + * Copyright(C) 2005-2012, 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.Bar; + +import org.hibernate.SessionFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + + +/** + * @author gcatania + */ +public interface BarDAO extends HibernateDAO<Bar, Long> +{ + + @Repository("barDAO") + class PersonDAOImpl extends HibernateDAOImpl<Bar, Long> implements BarDAO + { + + @Autowired + public PersonDAOImpl(SessionFactory factory) + { + super(Bar.class); + setSessionFactory(factory); + } + } + +} Property changes on: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/dao/BarDAO.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/dao/FooDAO.java =================================================================== --- trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/dao/FooDAO.java (rev 0) +++ trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/dao/FooDAO.java 2013-03-11 15:03:14 UTC (rev 4195) @@ -0,0 +1,55 @@ +/** + * + * openutils base Spring-Hibernate DAO (http://www.openmindlab.com/lab/products/bshd5.html) + * + * Copyright(C) 2005-2012, 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.Foo; + +import org.hibernate.SessionFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Repository; + + +/** + * @author gcatania + */ +public interface FooDAO extends HibernateDAO<Foo, Long> +{ + + @Repository("fooDAO") + class PersonDAOImpl extends HibernateDAOImpl<Foo, Long> implements FooDAO + { + + @Autowired + public PersonDAOImpl(SessionFactory factory) + { + super(Foo.class); + setSessionFactory(factory); + } + } + +} Property changes on: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/dao/FooDAO.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/Bar.java =================================================================== --- trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Bar.java (rev 0) +++ trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Bar.java 2013-03-11 15:03:14 UTC (rev 4195) @@ -0,0 +1,80 @@ +/** + * + * openutils base Spring-Hibernate DAO (http://www.openmindlab.com/lab/products/bshd5.html) + * + * Copyright(C) 2005-2012, 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.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + + +/** + * @author gcatania + * @version $Id$ + */ +@Entity +public class Bar implements Cloneable +{ + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + private String s; + + /** + * @return the id + */ + public Long getId() + { + return id; + } + + /** + * @param id the id to set + */ + public void setId(Long id) + { + this.id = id; + } + + /** + * @return the s + */ + public String getS() + { + return s; + } + + /** + * @param s the s to set + */ + public void setS(String s) + { + this.s = s; + } + +} Property changes on: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Bar.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/Foo.java =================================================================== --- trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Foo.java (rev 0) +++ trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Foo.java 2013-03-11 15:03:14 UTC (rev 4195) @@ -0,0 +1,102 @@ +/** + * + * openutils base Spring-Hibernate DAO (http://www.openmindlab.com/lab/products/bshd5.html) + * + * Copyright(C) 2005-2012, 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.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.ManyToOne; + + +/** + * @author gcatania + * @version $Id$ + */ +@Entity +public class Foo implements Cloneable +{ + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + @ManyToOne + private Bar bar; + + @Column + private String s; + + /** + * @return the id + */ + public Long getId() + { + return id; + } + + /** + * @param id the id to set + */ + public void setId(Long id) + { + this.id = id; + } + + /** + * @return the bar + */ + public Bar getBar() + { + return bar; + } + + /** + * @param bar the bar to set + */ + public void setBar(Bar bar) + { + this.bar = bar; + } + + /** + * @return the s + */ + public String getS() + { + return s; + } + + /** + * @param s the s to set + */ + public void setS(String s) + { + this.s = s; + } + +} Property changes on: trunk/openutils-bshd5/src/test/java/it/openutils/hibernate/test/model/Foo.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/resources/hibernate.cfg.xml =================================================================== --- trunk/openutils-bshd5/src/test/resources/hibernate.cfg.xml 2013-02-14 16:17:10 UTC (rev 4194) +++ trunk/openutils-bshd5/src/test/resources/hibernate.cfg.xml 2013-03-11 15:03:14 UTC (rev 4195) @@ -13,5 +13,8 @@ <mapping class="it.openutils.hibernate.test.model.Owner" /> <mapping class="it.openutils.hibernate.test.model.Person" /> <mapping class="it.openutils.hibernate.test.model.Sticker" /> + + <mapping class="it.openutils.hibernate.test.model.Foo" /> + <mapping class="it.openutils.hibernate.test.model.Bar" /> </session-factory> </hibernate-configuration> \ No newline at end of file Added: trunk/openutils-bshd5/src/test/resources/preload-data.sql =================================================================== --- trunk/openutils-bshd5/src/test/resources/preload-data.sql (rev 0) +++ trunk/openutils-bshd5/src/test/resources/preload-data.sql 2013-03-11 15:03:14 UTC (rev 4195) @@ -0,0 +1,17 @@ +insert into bar (id, s) +values (1, 'bar1'); +insert into bar (id, s) +values (2, 'bar2'); + +insert into foo (id, bar_id, s) +values ( 1, 1, 'foo1_1' ); +insert into foo (id, bar_id, s) +values ( 2, 1, 'foo1_2' ); +insert into foo (id, bar_id, s) +values ( 3, 1, 'fooX_X' ); +insert into foo (id, bar_id, s) +values ( 4, 2, 'foo2_1' ); +insert into foo (id, bar_id, s) +values ( 5, 2, 'foo2_2' ); +insert into foo (id, bar_id, s) +values ( 6, 2, 'fooX_X' ); \ No newline at end of file Property changes on: trunk/openutils-bshd5/src/test/resources/preload-data.sql ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |