该树形结构是一颗关于地理信息的一颗树:
step 1、构建数据库(cteate_table_sql)
/*==============================================================*/
/* Table: DIM_GEOGRAPHY */
/*==============================================================*/
create table DIM_GEOGRAPHY (
ID integer not null,
GEOGRAPHY_CODE VARCHAR(32) not null,
GEOGRAPHY_NAME VARCHAR(32) not null,
GEOGRAPHY_NAME_EN VARCHAR(32) null,
GEOGRAPHY_LEVEL integer not null,
CITY_TYPE1 integer not null,
CITY_TYPE2 integer null,
GEO_TREE_CODE VARCHAR(32) null,
PARENT_GEOGRAPHY_ID VARCHAR(32) null,
USAGE_FLAG VARCHAR(2) not null,
CREATE_BY VARCHAR(32) not null,
CREATE_DATE VARCHAR(30) not null,
LASTUPDATE_BY VARCHAR(32) not null,
LASTUPDATE_DATE VARCHAR(30) not null,
constraint PK_DIM_GEOGRAPHY primary key (ID),
constraint FK_993 foreign key (CITY_TYPE2)
references DIM_DICT_ITEM (ID),
constraint FK_333 foreign key (CITY_TYPE1)
references DIM_DICT_ITEM (ID)
)
go
其中DIM_DICT_ITEM是一个数据字典表,存一些系统中常用数据,在这里存储城市类型。
step 2、构建Hibernate PO
/*========================================================================================*/
/* Bean: DimGeography */
/*========================================================================================*/
- /*
- * Created Mon Oct 16 14:07:33 CST 2006 by MyEclipse Hibernate Tool.
- */
- package com.fzfx88.po.base;
- import java.io.Serializable;
- import com.winchannel.base.service.GeographyService;
- /**
- * A class that represents a row in the 'DIM_GEOGRAPHY' table.
- * This class may be customized as it is never re-generated
- * after being created.
- */
- public class DimGeography
- extends AbstractDimGeography
- implements Serializable
- {
- /**
- * Simple constructor of DimGeography instances.
- */
- public DimGeography()
- {
- }
- /**
- * Constructor of DimGeography instances given a simple primary key.
- * @param id
- */
- public DimGeography(java.lang.Integer id)
- {
- super(id);
- }
- /* Add customized code below */
- private DimGeography country;
- private DimGeography province;
- private DimGeography city;
- private Integer countryId;
- private Integer provinceId;
- private Integer cityId;
- private String countryName;
- private String provinceName;
- private String cityName;
- public void getParents(){
- String treeCode = this.getGeoTreeCode();
- int i = treeCode.length()/3;
- GeographyService gService =new GeographyService();
- // if(i>=1){
- // country= gService.retrieveOrgByTreeCode(treeCode,1);
- // this.countryId = country.getId();
- // this.countryName =country.getGeographyName();
- // }
- if(i>=1){
- province= gService.retrieveOrgByTreeCode(treeCode,1);
- if(province!=null){
- this.provinceId = province.getId();
- this.provinceName =province.getGeographyName();
- }
- }
- if(i>=2){
- city= gService.retrieveOrgByTreeCode(treeCode,2);
- if(city !=null){
- this.cityId = city.getId();
- this.cityName =city.getGeographyName();
- }
- }
- }
- /**
- * @return Returns the cityId.
- */
- public Integer getCityId() {
- return cityId;
- }
- /**
- * @param cityId The cityId to set.
- */
- public void setCityId(Integer cityId) {
- this.cityId = cityId;
- }
- /**
- * @return Returns the cityName.
- */
- public String getCityName() {
- return cityName;
- }
- /**
- * @param cityName The cityName to set.
- */
- public void setCityName(String cityName) {
- this.cityName = cityName;
- }
- /**
- * @return Returns the countryId.
- */
- public Integer getCountryId() {
- return countryId;
- }
- /**
- * @param countryId The countryId to set.
- */
- public void setCountryId(Integer countryId) {
- this.countryId = countryId;
- }
- /**
- * @return Returns the countryName.
- */
- public String getCountryName() {
- return countryName;
- }
- /**
- * @param countryName The countryName to set.
- */
- public void setCountryName(String countryName) {
- this.countryName = countryName;
- }
- /**
- * @return Returns the provinceId.
- */
- public Integer getProvinceId() {
- return provinceId;
- }
- /**
- * @param provinceId The provinceId to set.
- */
- public void setProvinceId(Integer provinceId) {
- this.provinceId = provinceId;
- }
- /**
- * @return Returns the provinceName.
- */
- public String getProvinceName() {
- return provinceName;
- }
- /**
- * @param provinceName The provinceName to set.
- */
- public void setProvinceName(String provinceName) {
- this.provinceName = provinceName;
- }
- /**
- * @return Returns the city.
- */
- public DimGeography getCity() {
- return city;
- }
- /**
- * @param city The city to set.
- */
- public void setCity(DimGeography city) {
- this.city = city;
- }
- /**
- * @return Returns the country.
- */
- public DimGeography getCountry() {
- return country;
- }
- /**
- * @param country The country to set.
- */
- public void setCountry(DimGeography country) {
- this.country = country;
- }
- /**
- * @return Returns the province.
- */
- public DimGeography getProvince() {
- return province;
- }
- /**
- * @param province The province to set.
- */
- public void setProvince(DimGeography province) {
- this.province = province;
- }
- }
/*========================================================================================*/
/* Bean: AbstractDimGeography */
/*========================================================================================*/
- /*
- * WARNING: DO NOT EDIT THIS FILE. This is a generated file that is synchronized
- * by MyEclipse Hibernate tool integration.
- *
- * Created Mon Oct 16 14:07:33 CST 2006 by MyEclipse Hibernate Tool.
- */
- package com.fzfx88.po.base;
- import java.io.Serializable;
- /**
- * A class that represents a row in the DIM_GEOGRAPHY table.
- * You can customize the behavior of this class by editing the class, {@link DimGeography()}.
- * WARNING: DO NOT EDIT THIS FILE. This is a generated file that is synchronized
- * by MyEclipse Hibernate tool integration.
- */
- public abstract class AbstractDimGeography
- implements Serializable
- {
- /** The cached hash code value for this instance. Settting to 0 triggers re-calculation. */
- private int hashValue = 0;
- /** The composite primary key value. */
- private java.lang.Integer id;
- private java.util.Set childGeo;
- /** The value of the dimDistrSet one-to-many association. */
- private java.lang.String geoTreeCode;
- /** The value of the dimDistrSet one-to-many association. */
- private java.util.Set dimDistrSet;
- /** The value of the dimStoreSet one-to-many association. */
- private java.util.Set dimStoreSet;
- /** The value of the simple geographyCode property. */
- private java.lang.String geographyCode;
- /** The value of the simple geographyName property. */
- private java.lang.String geographyName;
- /** The value of the simple geographyNameEn property. */
- private java.lang.String geographyNameEn;
- /** The value of the simple geographyLevel property. */
- private java.lang.Integer geographyLevel;
- /** The value of the simple cityLevel property. */
- private DimDictItem cityType1;
- /** The value of the simple cityLevel property. */
- private DimDictItem cityType2;
- /** The value of the simple parentGeographyId property. */
- private java.lang.Integer parentGeographyId;
- /** The value of the simple usageFlag property. */
- private java.lang.String usageFlag;
- /** The value of the simple createBy property. */
- private java.lang.String createBy;
- /** The value of the simple createDate property. */
- private java.lang.String createDate;
- /** The value of the simple lastupdateBy property. */
- private java.lang.String lastupdateBy;
- /** The value of the simple lastupdateDate property. */
- private java.lang.String lastupdateDate;
- private Integer parentGeo;
- /**
- * Simple constructor of AbstractDimGeography instances.
- */
- public AbstractDimGeography()
- {
- }
- /**
- * Constructor of AbstractDimGeography instances given a simple primary key.
- * @param id
- */
- public AbstractDimGeography(java.lang.Integer id)
- {
- this.setId(id);
- }
- /**
- * Return the simple primary key value that identifies this object.
- * @return java.lang.Integer
- */
- public java.lang.Integer getId()
- {
- return id;
- }
- /**
- * Set the simple primary key value that identifies this object.
- * @param id
- */
- public void setId(java.lang.Integer id)
- {
- this.hashValue = 0;
- this.id = id;
- }
- /**
- * Return the value of the GEOGRAPHY_CODE column.
- * @return java.lang.String
- */
- public java.lang.String getGeographyCode()
- {
- return this.geographyCode;
- }
- /**
- * Set the value of the GEOGRAPHY_CODE column.
- * @param geographyCode
- */
- public void setGeographyCode(java.lang.String geographyCode)
- {
- this.geographyCode = geographyCode;
- }
- /**
- * Return the value of the GEOGRAPHY_NAME column.
- * @return java.lang.String
- */
- public java.lang.String getGeographyName()
- {
- return this.geographyName;
- }
- /**
- * Set the value of the GEOGRAPHY_NAME column.
- * @param geographyName
- */
- public void setGeographyName(java.lang.String geographyName)
- {
- this.geographyName = geographyName;
- }
- /**
- * Return the value of the GEOGRAPHY_LEVEL column.
- * @return java.lang.Integer
- */
- public java.lang.Integer getGeographyLevel()
- {
- return this.geographyLevel;
- }
- /**
- * Set the value of the GEOGRAPHY_LEVEL column.
- * @param geographyLevel
- */
- public void setGeographyLevel(java.lang.Integer geographyLevel)
- {
- this.geographyLevel = geographyLevel;
- }
- /**
- * Return the value of the CITY_LEVEL column.
- * @return java.lang.Integer
- */
- public DimDictItem getCityType1()
- {
- return this.cityType1;
- }
- /**
- * Set the value of the CITY_LEVEL column.
- * @param cityLevel
- */
- public void setCityType1(DimDictItem cityType1)
- {
- this.cityType1 = cityType1;
- }
- /**
- * Return the value of the PARENT_GEOGRAPHY_ID column.
- * @return java.lang.Integer
- */
- public java.lang.Integer getParentGeographyId()
- {
- return this.parentGeographyId;
- }
- /**
- * Set the value of the PARENT_GEOGRAPHY_ID column.
- * @param parentGeographyId
- */
- public void setParentGeographyId(java.lang.Integer parentGeographyId)
- {
- this.parentGeographyId = parentGeographyId;
- }
- /**
- * Return the value of the USAGE_FLAG column.
- * @return java.lang.String
- */
- public java.lang.String getUsageFlag()
- {
- return this.usageFlag;
- }
- /**
- * Set the value of the USAGE_FLAG column.
- * @param usageFlag
- */
- public void setUsageFlag(java.lang.String usageFlag)
- {
- this.usageFlag = usageFlag;
- }
- /**
- * Return the value of the CREATE_BY column.
- * @return java.lang.String
- */
- public java.lang.String getCreateBy()
- {
- return this.createBy;
- }
- /**
- * Set the value of the CREATE_BY column.
- * @param createBy
- */
- public void setCreateBy(java.lang.String createBy)
- {
- this.createBy = createBy;
- }
- /**
- * Return the value of the CREATE_DATE column.
- * @return java.lang.String
- */
- public java.lang.String getCreateDate()
- {
- return this.createDate;
- }
- /**
- * Set the value of the CREATE_DATE column.
- &
本文介绍了一个用于存储地理信息的数据库表结构及对应的Java Hibernate POJO类。通过详细展示DIM_GEOGRAPHY表的设计,包括字段定义及其关联的数据字典表,文章阐述了如何通过Java类映射地理信息树形结构。
468

被折叠的 条评论
为什么被折叠?



