最近几年来,地理信息系统无论是在理论上还是应用上都处在一个飞速发展的阶段。 GIS被应用于多个领域的建模和决策支持,如城市管理、区划、环境整治等等,地理信息成为信息时代重要的组成部分之一; “数字地球”概念的提出,更进一步推动了作为其技术支撑的GIS的发展。 与此同时,一些学者致力于相关的理论研究,如空间感知、空间数据误差、空间关系的形式化等等。 这恰好说明了地理信息系统作为应用技术和学科的两个方面,并且这两个方面构成了相互促进的发展过程。
The data access object pattern (Data Access Object Pattern) or DAO pattern is used to separate low-level data access API or operations from high-level business services. The following are the participants in the data access object pattern.
数据访问对象接口(Data Access Object Interface) -this interface defines the standard operations to be performed on a model object.
数据访问对象实体类(Data Access Object concrete class) -this class implements the above interface. This class is responsible for fetching data from a data source, which can be a database, xml, or other storage mechanism.
模型对象/数值对象(Model Object/Value Object) This object is a simple POJO that contains get/set methods to store the data retrieved by using the DAO class.
6.31.1. Realize ¶
We will create a model object or a numeric object Student Object. StudentDao Is the data access object interface. StudentDaoImpl Is an entity class that implements the data access object interface. DaoPatternDemo Our demo class uses the StudentDao To demonstrate the use of the data access object pattern.

6.31.2. Step 1 ¶
Create numeric objects.Student.java ¶
publicclassStudent{privateStringname;privateintrollNo;Student(Stringname,introllNo){this.name=name;this.rollNo=rollNo;}publicStringgetName(){returnname;}publicvoidsetName(Stringname){this.name=name;}publicintgetRollNo(){returnrollNo;}publicvoidsetRollNo(introllNo){this.rollNo=rollNo;}}
6.31.3. Step 2 ¶
Create a data access object interface.StudentDao.java ¶
importjava.util.List;publicinterfaceStudentDao{publicList<Student>getAllStudents();publicStudentgetStudent(introllNo);publicvoidupdateStudent(Studentstudent);publicvoiddeleteStudent(Studentstudent);}
6.31.4. Step 3 ¶
Create an entity class that implements the above interface. Use StudentDao To demonstrate the use of the data access object pattern. Execute the program and output the result: StudentDaoImpl.java ¶
importjava.util.ArrayList;importjava.util.List;publicclassStudentDaoImplimplementsStudentDao{//列表是当作一个数据库List<Student>students;publicStudentDaoImpl(){students=newArrayList<Student>();Studentstudent1=newStudent("Robert",0);Studentstudent2=newStudent("John",1);students.add(student1);students.add(student2);}@OverridepublicvoiddeleteStudent(Studentstudent){students.remove(student.getRollNo());System.out.println("Student: Roll No"+student.getRollNo()+", deleted from database");}//从数据库中检索学生名单@OverridepublicList
6.31.5. Step 4 ¶
DaoPatternDemo.java ¶
publicclassDaoPatternDemo{publicstaticvoidmain(String[]args){StudentDaostudentDao=newStudentDaoImpl();//输出所有的学生for(Studentstudent:studentDao.getAllStudents()){System.out.println("Student: [RollNo :"+student.getRollNo()+", Name :"+student.getName()+"]");}//更新学生Studentstudent=studentDao.getAllStudents().get(0);student.setName("Michael");studentDao.updateStudent(student);//获取学生studentDao.getStudent(0);System.out.println("Student: [RollNo :"+student.getRollNo()+", Name :"+student.getName()+"]");}}
6.31.6. Step 5 ¶
Student: [RollNo : 0, Name : Robert ] Student: [RollNo : 1, Name : John ] Student: Roll No 0, updated in the database Student: [RollNo : 0, Name : Michael ]