From 159519fefc8efe7ad1cbbba349d4014cf80ce4e7 Mon Sep 17 00:00:00 2001 From: vovasty Date: Fri, 20 Feb 2009 23:53:03 +0300 Subject: [PATCH] almost working inmporter --- .../java/ru/rentdom/entities/coords/District.java | 39 +++++++++++++++++++++ .../ru/rentdom/services/coords/CoordsImport.java | 40 ++++++++++++---------- .../rentdom/services/coords/CoordsImportTest.java | 2 +- 3 files changed, 61 insertions(+), 20 deletions(-) create mode 100644 rentdom-web/src/main/java/ru/rentdom/entities/coords/District.java diff --git a/rentdom-web/src/main/java/ru/rentdom/entities/coords/District.java b/rentdom-web/src/main/java/ru/rentdom/entities/coords/District.java new file mode 100644 index 0000000..84780ae --- /dev/null +++ b/rentdom-web/src/main/java/ru/rentdom/entities/coords/District.java @@ -0,0 +1,39 @@ +package ru.rentdom.entities.coords; + +import java.util.Set; + +import javax.persistence.CascadeType; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; +import javax.persistence.Table; + +import ru.rentdom.entities.housing.Housing; + +@Entity(name = "district") +@Table(name = "districts") +public class District extends Coord{ + private static final long serialVersionUID = -4821414637331301222L; + + private Town town; + + private Set housings; + + @ManyToOne(optional=false) + public Town getTown() { + return town; + } + public void setTown(Town town) { + this.town = town; + } + + @OneToMany(mappedBy="metroStation", fetch=FetchType.LAZY, cascade=CascadeType.ALL) + public Set getHousings() { + return housings; + } + public void setHousings(Set housings) { + this.housings = housings; + } + +} diff --git a/rentdom-web/src/main/java/ru/rentdom/services/coords/CoordsImport.java b/rentdom-web/src/main/java/ru/rentdom/services/coords/CoordsImport.java index a7dd42b..57bf0e9 100644 --- a/rentdom-web/src/main/java/ru/rentdom/services/coords/CoordsImport.java +++ b/rentdom-web/src/main/java/ru/rentdom/services/coords/CoordsImport.java @@ -54,23 +54,25 @@ public class CoordsImport { DataSet dataSet = dataContext.executeQuery(q); while (dataSet.next()) { - String sCountry=(String) dataSet.getRow().getValue(countryColumn); - String sTown=(String) dataSet.getRow().getValue(townColumn); - String sDistrict=(String) dataSet.getRow().getValue(districtColumn); - String sStreet=(String) dataSet.getRow().getValue(streetColumn); - String sMetro=(String) dataSet.getRow().getValue(metroColumn); + String sCountry=((String) dataSet.getRow().getValue(countryColumn)).trim(); + String sTown=((String) dataSet.getRow().getValue(townColumn)).trim(); + String sDistrict=((String) dataSet.getRow().getValue(districtColumn)).trim(); + String sStreet=((String) dataSet.getRow().getValue(streetColumn)).trim(); + String sMetro=((String) dataSet.getRow().getValue(metroColumn)).trim(); + if (sTown.isEmpty()) + continue; - Country country=getCountry(sCountry); - Town town=getTown(country, sTown); - District district=getDistrict(country, town, sDistrict); - Street street=getStreet(country, town, sStreet); - MetroStation metroStation=getMetroStation(country, town, sMetro); + Country country=allocateCountry(sCountry); + Town town=allocateTown(country, sTown); + allocateDistrict(country, town, sDistrict); + allocateStreet(country, town, sStreet); + allocateMetroStation(country, town, sMetro); } dataSet.close(); } - private Country getCountry(String name) + private Country allocateCountry(String name) { String key=getKey(name); Country country = countries.get(key); @@ -90,7 +92,7 @@ public class CoordsImport { return country; } - private Town getTown(Country country, String name) + private Town allocateTown(Country country, String name) { String key=getKey(country.getName(), name); Town town = towns.get(key); @@ -100,7 +102,7 @@ public class CoordsImport { town.setName(name); town.setCountry(country); town.setSearchable(name.toLowerCase()); - List l = coordsDao.findByExample(town, "name"); + List l = coordsDao.findByExample(town,false,"name"); if (l.size()>0) town=l.get(0); else @@ -113,7 +115,7 @@ public class CoordsImport { return town; } - private District getDistrict(Country country, Town town, String name) + private District allocateDistrict(Country country, Town town, String name) { String key=getKey(country.getName(), town.getName(), name); District district = districts.get(key); @@ -123,7 +125,7 @@ public class CoordsImport { district.setName(name); district.setTown(town); district.setSearchable(name.toLowerCase()); - List l = coordsDao.findByExample(district, "name"); + List l = coordsDao.findByExample(district, true, "name"); if (l.size()>0) district=l.get(0); else @@ -136,7 +138,7 @@ public class CoordsImport { return district; } - private MetroStation getMetroStation(Country country, Town town, String name) + private MetroStation allocateMetroStation(Country country, Town town, String name) { String key=getKey(country.getName(), town.getName(), name); MetroStation metroStation = metroStations.get(key); @@ -147,7 +149,7 @@ public class CoordsImport { metroStation.setTown(town); metroStation.setSearchable(name.toLowerCase()); - List l = coordsDao.findByExample(metroStation, "name"); + List l = coordsDao.findByExample(metroStation, true, "name"); if (l.size()>0) metroStation=l.get(0); else @@ -160,7 +162,7 @@ public class CoordsImport { return metroStation; } - private Street getStreet(Country country, Town town, String name) + private Street allocateStreet(Country country, Town town, String name) { String key=getKey(country.getName(), town.getName(), name); Street street = streets.get(key); @@ -171,7 +173,7 @@ public class CoordsImport { street.setTown(town); street.setSearchable(name.toLowerCase()); - List l = coordsDao.findByExample(street, "name"); + List l = coordsDao.findByExample(street, true, "name"); if (l.size()>0) street=l.get(0); else diff --git a/rentdom-web/src/test/ru/rentdom/services/coords/CoordsImportTest.java b/rentdom-web/src/test/ru/rentdom/services/coords/CoordsImportTest.java index ca3bddc..f2c97d3 100644 --- a/rentdom-web/src/test/ru/rentdom/services/coords/CoordsImportTest.java +++ b/rentdom-web/src/test/ru/rentdom/services/coords/CoordsImportTest.java @@ -12,6 +12,6 @@ public class CoordsImportTest extends TestService{ public void testProcess() { CoordsImport im=getService(CoordsImport.class); - im.process(new File("/Users/solomenchuk/Documents/SampleData.xls")); + im.process(new File("/Users/vovasty/Documents/SampleData.xls")); } } -- 2.11.4.GIT