CN102566990A - Method and device for performing data manipulation in Java application - Google Patents
Method and device for performing data manipulation in Java application Download PDFInfo
- Publication number
- CN102566990A CN102566990A CN2010105933134A CN201010593313A CN102566990A CN 102566990 A CN102566990 A CN 102566990A CN 2010105933134 A CN2010105933134 A CN 2010105933134A CN 201010593313 A CN201010593313 A CN 201010593313A CN 102566990 A CN102566990 A CN 102566990A
- Authority
- CN
- China
- Prior art keywords
- data
- domain object
- structural information
- class file
- data access
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
- 238000000034 method Methods 0.000 title claims abstract description 30
- 238000013507 mapping Methods 0.000 claims abstract description 25
- 230000006870 function Effects 0.000 claims description 31
- 238000012545 processing Methods 0.000 claims description 13
- 238000012986 modification Methods 0.000 claims description 4
- 230000004048 modification Effects 0.000 claims description 4
- 238000012217 deletion Methods 0.000 claims 1
- 230000037430 deletion Effects 0.000 claims 1
- 230000008569 process Effects 0.000 description 7
- 238000011161 development Methods 0.000 description 5
- 239000011800 void material Substances 0.000 description 3
- 239000003607 modifier Substances 0.000 description 2
- 235000000332 black box Nutrition 0.000 description 1
- 230000008859 change Effects 0.000 description 1
- 238000010586 diagram Methods 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 230000007246 mechanism Effects 0.000 description 1
- 238000000926 separation method Methods 0.000 description 1
- 230000003068 static effect Effects 0.000 description 1
Images
Landscapes
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
- Devices For Executing Special Programs (AREA)
Abstract
Description
技术领域 technical field
本发明涉及计算机领域,尤其涉及一种在Java应用中进行数据操作的方法及装置。The invention relates to the field of computers, in particular to a method and device for performing data operations in Java applications.
背景技术 Background technique
在基于Java的项目开发过程中,需要频繁的对数据库进行增加、删除、修改、查询的操作,而在采用Java数据库连接(Java Database Connectivity,JDBC)连接数据库时,开发人员面对的都是原始数据集合。在业务逻辑开发过程中,开发人员需要根据预先获知的数据库中相关表的结构信息,从数据库中获取需要的数据,这就增加了开发人员的工作量,降低了开发效率。In the Java-based project development process, it is necessary to frequently add, delete, modify, and query operations on the database. When using Java Database Connectivity (JDBC) to connect to the database, developers are faced with primitive collection of data. In the process of business logic development, developers need to obtain the required data from the database according to the structure information of related tables in the database known in advance, which increases the workload of the developers and reduces the development efficiency.
为了解决这一问题,需要进行对象关系映射,所谓对象关系映射即是将数据库中的数据映射为对象,这就引入了数据访问对象(Data Access Object,DAO)模式,DAO是对象关系映射的一种实现方式。DAO模式通过对底层数据进行封装,为业务层提供一个面向对象的接口,使得业务逻辑开发人员可以专注于面向业务中的实体进行编码,使得业务逻辑更加清晰,DAO模式是数据访问类Data Accessor和域对象类Domain Object的组合,其中,Data Accessor是将数据访问的实现机制加以封装,与数据的使用代码相分离,从外部来看,Data Accessor提供了黑盒式的数据存取接口,而Domain Object是领域内涉及的各个数据对象,提供了对所面向领域内对象的封闭。In order to solve this problem, object-relational mapping is required. The so-called object-relational mapping is to map the data in the database into objects, which introduces the Data Access Object (DAO) mode. DAO is a part of object-relational mapping. way of realization. The DAO mode provides an object-oriented interface for the business layer by encapsulating the underlying data, so that business logic developers can focus on coding entities in the business, making the business logic clearer. The DAO mode is the data access class Data Accessor and A combination of domain object classes Domain Object, in which Data Accessor encapsulates the implementation mechanism of data access and separates it from the data usage code. From an external point of view, Data Accessor provides a black-box data access interface, while Domain Object is the various data objects involved in the domain, and provides the closure of the objects in the targeted domain.
虽然通过DAO模式可以实现业务逻辑与数据逻辑的分离,在实现复杂性和结构清晰性上达到较好的平衡,通常是一个对象对应数据库中的一个表,对象中的多个属性分别对应表的多个字段,在实际对DAO模式的开发过程中,需要手动将数据库中的表转换为DAO模式的对象,如需要处理数据库中的多个表,则需要针对多个表分别转换为相应的对象,使得开发效率较低,并且由于手动将数据块中的表转换为DAO模式的对象,使得稳定性不高,易出错。Although the separation of business logic and data logic can be achieved through the DAO mode, a better balance can be achieved in terms of complexity and structural clarity. Usually, an object corresponds to a table in the database, and multiple attributes in the object correspond to the table. Multiple fields, in the actual development process of the DAO mode, it is necessary to manually convert the tables in the database into the objects of the DAO mode. If you need to process multiple tables in the database, you need to convert multiple tables into corresponding objects , so that the development efficiency is low, and because the table in the data block is manually converted to the object of the DAO mode, the stability is not high and error-prone.
发明内容 Contents of the invention
本发明提供一种在Java应用中进行数据操作的方法及装置,用以将数据表映射为源代码形式,提高对象关系映射的效率以及准确率。The invention provides a method and device for data operation in Java applications, which are used to map data tables into source codes and improve the efficiency and accuracy of object-relational mapping.
本发明实施例提供的具体技术方案如下:The specific technical scheme that the embodiment of the present invention provides is as follows:
一种在Java应用中进行数据操作的方法,包括:A method for performing data manipulation in a Java application, comprising:
从数据库中获取至少一个表的结构信息;obtaining structural information of at least one table from the database;
将所述至少一个表的结构信息映射为域对象类文件和数据访问类文件;Mapping the structural information of the at least one table into a domain object class file and a data access class file;
在接收到数据操作指示时,基于所述数据访问类文件包含的函数对所述域对象类文件进行数据操作。When receiving the data operation instruction, perform data operation on the domain object class file based on the functions contained in the data access class file.
一种在Java应用中进行数据操作的装置,包括:A device for performing data manipulation in a Java application, comprising:
第一处理单元,用于从数据库中获取至少一个表的结构信息;A first processing unit, configured to obtain structural information of at least one table from the database;
第二处理单元,用于将所述至少一个表的结构信息映射为域对象类文件和数据访问类文件;The second processing unit is configured to map the structural information of the at least one table into a domain object class file and a data access class file;
第三处理单元,用于在接收到数据操作指示时,基于所述数据访问类文件包含的函数对所述域对象类文件进行数据操作。The third processing unit is configured to perform data operations on the domain object class file based on the functions contained in the data access class file when receiving the data operation instruction.
基于上述技术方案,在建立数据库连接后,从数据库中获取表的结构信息,将表的结构信息映射为域对象类文件和数据访问类文件,从而能够将数据库中表的结构信息映射为域对象类文件,即将表的结构转换为源代码的形式,将对数据库中表的数据操作映射为数据访问类文件,将针对表的数据操作转换为源代码的形式,在接收到数据操作指示时,基于数据库访问类文件包含的函数对域对象类文件进行数据操作,从而能够自动获取表中的记录,而无需人工读取数据库中的原始数据,从而提高了对象关系映射的效率和准确率。Based on the above technical solution, after the database connection is established, the structural information of the table is obtained from the database, and the structural information of the table is mapped to a domain object class file and a data access class file, so that the structural information of the table in the database can be mapped to a domain object The class file is to convert the structure of the table into the form of source code, map the data operation on the table in the database to a data access class file, and convert the data operation on the table into the form of source code. When receiving the data operation instruction, Based on the functions contained in the database access class file, the data operation is performed on the domain object class file, so that the records in the table can be automatically obtained without manually reading the original data in the database, thereby improving the efficiency and accuracy of object-relational mapping.
附图说明 Description of drawings
图1为本发明在Java应用中进行数据操作的方法流程图;Fig. 1 is the method flowchart that the present invention carries out data operation in Java application;
图2为本发明在Java应用中进行数据操作的装置结构图。FIG. 2 is a structural diagram of a device for performing data operations in a Java application according to the present invention.
具体实施方式 Detailed ways
为了提高对象关系映射的效率以及准确率,本发明实施例提供了一种在Java应用中进行数据操作的方法及装置,能够提高对象关系映射的效率,并提高准确率。该方法为:从数据库中获取至少一个表的结构信息,将该至少一个表的结构信息映射为域对象类文件和数据访问类文件,在接收到数据操作指示时,基于数据访问类文件包含的函数对域对象类文件进行数据操作。In order to improve the efficiency and accuracy of object-relational mapping, embodiments of the present invention provide a method and device for data manipulation in Java applications, which can improve the efficiency and accuracy of object-relational mapping. The method is as follows: obtaining the structural information of at least one table from the database, mapping the structural information of the at least one table into a domain object class file and a data access class file, and when receiving a data operation instruction, based on the data contained in the data access class file Functions perform data operations on domain object class files.
下面结合附图对本发明优选的实施例进行详细说明。Preferred embodiments of the present invention will be described in detail below in conjunction with the accompanying drawings.
参阅附图1所示,本发明实施例中,在Java应用中进行数据操作的具体方法流程如下:Referring to shown in accompanying drawing 1, in the embodiment of the present invention, the concrete method flow process that carries out data operation in Java application is as follows:
步骤101:从数据库中获取至少一个表的结构信息。Step 101: Obtain structural information of at least one table from a database.
在Java应用中,可以通过Java数据库连接方式进行数据库连接,即通过数据库连接对象(Connection对象)建立数据库连接,并在建立数据库连接后,从数据库中获取数据库的整体综合信息对象,该整体综合信息对象中包含数据库中所有表的结构信息,本发明实施例中,从数据库的整体综合信息对象中获取至少一个表的结构信息。In the Java application, the database connection can be performed through the Java database connection method, that is, the database connection is established through the database connection object (Connection object), and after the database connection is established, the overall comprehensive information object of the database is obtained from the database. The overall comprehensive information The object includes structural information of all tables in the database. In the embodiment of the present invention, the structural information of at least one table is obtained from the overall comprehensive information object of the database.
其中,一个表的结构信息至少包含一个表的字段名称,字段的数据类型,字段精度以及字段是否为空。Wherein, the structural information of a table includes at least a field name of a table, a data type of a field, a precision of a field, and whether the field is empty.
本发明实施例中,在获取至少一个表的结构信息时,首先获取该表的主键,如果该表不存在主键,则结束。表的主键是指表中记录的唯一标识字段,表的主键不能重复,也不能为空值。In the embodiment of the present invention, when obtaining the structure information of at least one table, first obtain the primary key of the table, and if the primary key does not exist in the table, the process ends. The primary key of the table refers to the unique identification field of the records in the table. The primary key of the table cannot be repeated, nor can it be empty.
步骤102:将至少一个表的结构信息映射为域对象类文件和数据访问类文件。Step 102: Map the structural information of at least one table into a domain object class file and a data access class file.
其中,在将至少一个表的结构信息映射为域对象类文件时,针对至少一个表定义域对象类,并在该域对象类中预设获取数据和设置数据的外部接口,将表的结构信息映射为域对象类的私有数据。Wherein, when the structural information of at least one table is mapped to a domain object class file, a domain object class is defined for at least one table, and the external interface for obtaining data and setting data is preset in the domain object class, and the structural information of the table is Mapped as private data of the domain object class.
在将至少一个表的结构信息映射为数据访问类文件时,针对上述至少一个表定义数据访问类,基于该至少一个表的结构信息生成数据访问类包含的函数。该数据访问类包含的函数至少包括数据的增加函数、删除函数、修改函数和查询函数。When the structural information of at least one table is mapped to a data access class file, a data access class is defined for the at least one table, and functions contained in the data access class are generated based on the structural information of the at least one table. The functions contained in the data access class include at least the functions of adding data, deleting functions, modifying functions and querying functions.
一个表对应一个域对象类文件和一个数据访问类文件,可以针对数据库中的全部或部分表的结构信息。A table corresponds to a domain object class file and a data access class file, which can be for all or part of the table structure information in the database.
在生成域对象类文件和数据访问类文件后,将生成的域对象类文件和数据访问类文件保存至指定位置,以直接从该指定位置进行调用。After the domain object class file and the data access class file are generated, the generated domain object class file and data access class file are saved to a specified location, so as to be called directly from the specified location.
步骤103:在接收到数据操作指示时,基于数据库访问类文件包含的函数对域对象类文件进行数据操作。Step 103: When receiving the data operation instruction, perform data operation on the domain object class file based on the functions contained in the database access class file.
下面针对步骤102中将至少一个表的信息映射为域对象文件和数据访问类文件的过程进行详细说明。The process of mapping information of at least one table into domain object files and data access class files in
其中,在将至少一个表的结构信息映射为域对象文件时,首先针对该至少一个表预定义域对象类,包括定义域对象类的命名规则,域对象类私有数据成员的命名规则,数据类型映射规则,构造函数,以及获取数据和设置数据的外部接口;再将表的结构信息映射为域对象类的私有数据。Wherein, when mapping the structural information of at least one table into a domain object file, firstly, a domain object class is predefined for the at least one table, including naming rules for defining domain object classes, naming rules for private data members of domain object classes, and data types Mapping rules, constructors, and external interfaces for getting data and setting data; and then mapping the structural information of the table to the private data of the domain object class.
例1,域对象类的命名规则设置为:如表1所示,域对象类的名称和相应的表的名称一致,并且第一个字母大写,后面的字母小写,在表的名称中有下划线时,在相对应的域对象类的名称中将下划线去除,将下划线后面的第一个字母大写,并且后面的字母小写。Example 1, the naming rules of the domain object class are set as follows: as shown in Table 1, the name of the domain object class is consistent with the name of the corresponding table, and the first letter is capitalized, the following letters are lowercase, and there is an underscore in the name of the table , remove the underscore from the name of the corresponding domain object class, capitalize the first letter after the underscore, and lowercase the following letter.
表1Table 1
例2,将表的结构信息中包含的字段映射为域对象类的私有数据时,采用的命名规则设置如下:参阅表2所示,域对象类的私有数据名称和表结构信息中的字段名称一致,并且所有字母小写,在字段名称中有下划线时,转换为域对象类的私有数据名称时,将相对应的私有数据名称中将下划线去除,并且下划线后面的第一个字母大写,后续字母小写。Example 2, when mapping the fields contained in the structure information of the table to the private data of the domain object class, the naming rules used are set as follows: Refer to Table 2, the private data name of the domain object class and the field name in the table structure information Consistent, and all letters are lowercase. When there is an underscore in the field name, when converting to the private data name of the domain object class, the underscore will be removed from the corresponding private data name, and the first letter after the underscore is capitalized, and the subsequent letters lower case.
表2Table 2
例3,域对象类的数据类型映射规则设置为:在Java应用中,可以通过整体综合信息对象中的getColumnType函数获取表的某个字段的数据类型,通过isNullable函数获知表的某个字段是否为空值,根据字段的数据类型和字段是否为空值决定数据类型映射规则,具体参见表3所示。在将表的结构映射为域对象类的私有数据成员时,可以按照表3中的规则进行映射。Example 3, the data type mapping rule of the domain object class is set as follows: In Java applications, the data type of a certain field of the table can be obtained through the getColumnType function in the overall comprehensive information object, and whether a certain field of the table is known through the isNullable function For null values, the data type mapping rules are determined according to the data type of the field and whether the field is null, as shown in Table 3 for details. When mapping the structure of the table as a private data member of the domain object class, it can be mapped according to the rules in Table 3.
表3table 3
例4,针对数据库中的表APP_ROLE,采用本发明实施例中的方法将该表的结构信息映射为域对象,表APP_ROLE的结构信息如表4所示。Example 4, for the table APP_ROLE in the database, use the method in the embodiment of the present invention to map the structure information of the table into a domain object, and the structure information of the table APP_ROLE is shown in Table 4.
表4Table 4
采用本发明实施例的方法,以及上述例1-例3设置的规则,将上述表APP_ROLE的结构信息映射为域对象类,该域对象类如下所示:Using the method of the embodiment of the present invention and the rules set in the above-mentioned examples 1-3, the structural information of the above-mentioned table APP_ROLE is mapped to a domain object class, and the domain object class is as follows:
public class AppRole implementsjava.io.Serializable //AppRole为映射的域对象类的名称{ 定义构造函数,代码部分省略public class AppRole implementsjava.io.Serializable //AppRole is the name of the mapped domain object class { Define the constructor, the code part is omitted
private long id;//根据表的结构信息映射的私有数据private long id;//Private data mapped according to the structure information of the table
private String name;private String name;
将表的结构信息映射为私有数据,代码省略Map the structural information of the table to private data, the code is omitted
针对每个私有数据均分别设置获取数据和设置数据的外部接口,代码省略。For each private data, the external interface for obtaining data and setting data is set separately, and the code is omitted.
}}
其中,在将至少一个表的结构信息映射为数据访问类文件时,针对上述至少一个表定义数据访问类,基于该至少一个表的结构信息生成数据访问类包含的函数,通过函数自动生成进行数据操作的结构化查询语言(Structured QueryLanguage,SQL),实现数据操作。Wherein, when the structural information of at least one table is mapped to a data access class file, a data access class is defined for the above at least one table, the functions contained in the data access class are generated based on the structural information of the at least one table, and the data is automatically generated through the function. Operational Structured Query Language (Structured Query Language, SQL), to achieve data manipulation.
例5,将数据访问类的命名规则设置为由相对应的域对象类的名称加上Dao组成,针对数据库中的表APP_ROLE,参阅表4所示,采用本发明实施例中的方法将表的结构信息映射为数据访问对象,该数据访问类对象如下所示:Example 5, the naming rule of the data access class is set to be composed of the name of the corresponding domain object class plus Dao, for the table APP_ROLE in the database, refer to Table 4, adopt the method in the embodiment of the present invention to change the table Structural information is mapped to a data access object, and the data access class object is as follows:
public class AppRoleDao extends BaseDao //与域对象类AppRole相对应的数据访问类AppRoleDaopublic class AppRoleDao extends BaseDao //The data access class AppRoleDao corresponding to the domain object class AppRole
{{
public final static String TABLE_NAME=″APP_ROLE″;//APP_ROLE为表的名称public final static String TABLE_NAME="APP_ROLE"; //APP_ROLE is the name of the table
定义构造函数,包括无参数的构造函数和带数据库连接对象的构造函数,代码部分省略Define constructors, including constructors without parameters and constructors with database connection objects, the code part is omitted
public AppRole getAppRole(ResultSet rs)throws SQLException//为域对象中的每个私有数据设置具体数据,并返回public AppRole getAppRole(ResultSet rs) throws SQLException//Set specific data for each private data in the domain object and return
{{
AppRole obj=new AppRole();AppRole obj = new AppRole();
obj.setId(rs.getLong(″ID″));//设置ID的数据Obj.setId(rs.getLong(″ID″));//Set ID data
obj.setName(rs.getString(″NAME″));//设置NAME的数据Obj.setName(rs.getString("NAME"));//Set the data of NAME
对每个私有数据进行相同的操作,在设置完成后,返回该对象,具体代码省略Perform the same operation on each private data, and return the object after the setting is completed, the specific code is omitted
}}
public AppRole getAppRole(long id)throws SQLException//通过主键获取表中与主键id相对应的记录,并返回与主键对应的域对象,实现数据查询Public AppRole getAppRole(long id) throws SQLException//Get the record corresponding to the primary key id in the table through the primary key, and return the domain object corresponding to the primary key to realize data query
{初始化定义省略{Initialization definition omitted
sql=″select*from″+TABLE_NAME+″where ID=″+id+″″;生成查询SQL语句,通过执行该SQL语句获取与id相对应的域对象并返回 sql = "select*from" + TABLE_NAME + "where ID = "+id+""; generate a query SQL statement, and execute the SQL statement to obtain the domain object corresponding to the id and return
}}
public void insert(AppRole obj)throws Exception//以AppRole域对象作为参数,实现以插入方式增加记录的数据操作Public void insert(AppRole obj)throws Exception//Use the AppRole domain object as a parameter to implement the data operation of adding records by inserting
{初始定义,为了防止字段名和数据库中的关键字同名,在初始定义中定义字符串变量P,并在P中保存获取的数据库字段修饰符,如双引号,具体代码略{Initial definition, in order to prevent the field name from having the same name as the keyword in the database, define a string variable P in the initial definition, and save the obtained database field modifiers in P, such as double quotation marks, the specific code is omitted
String sql=″insert into″+TABLE_NAME +″(″+P+″ID″+P+″,″+P+″NAME″+P+″,″+P+″DESCRIPTION″+P+″,″+P+″GUID″+P+″,″+P+″CREATEDDATE″+P+″,″+P+″MODIFIEDDATE″+P+″,″+P+″READONLY″+P+″,″+P+″DISPLAYNAME″+P+″,″+P+″COORDINATORID″+P+″,″+P+″SHUXING2″+P+″,″+P+″SORTORDER″+P+″)values(?,?,?,?,?,?,?,?,?,?,?)″;//生成插入SQL语句,该SQL语句为:insert into表名(”ID”,”NAME”,”DESCRIPTION”,”GUID”,”CREATEDDATE”,”MODIFIEDDATE”,”READONLY”,”DISPLAYNAME”,”COORDINATORID”,”SHUXING2”,”SORTORDER”)values(?,?,?,?,?,?,?,?,?,?,?)String sql="insert into"+TABLE_NAME +"("+P+"ID"+P+", "+P+"NAME"+P+", "+P+"DESCRIPTION"+P+", "+P+"GUID"+P+ ″, ″+P+″CREATEDDATE″+P+″, ″+P+″MODIFIEDDATE″+P+″, ″+P+″READONLY″+P+″, ″+P+″DISPLAYNAME″+P+″, ″+P+″COORDINATORID″+P+ ″,″+P+″SHUXING2″+P+″,″+P+″SORTORDER″+P+″)values(?,?,?,?,?,?,?,?,?,?,?)″;// Generate an insert SQL statement, the SQL statement is: insert into table name ("ID", "NAME", "DESCRIPTION", "GUID", "CREATEDDATE", "MODIFIEDDATE", "READONLY", "DISPLAYNAME", "COORDINATORID" ,"SHUXING2","SORTORDER") values(?,?,?,?,?,?,?,?,?,?,?)
依次获取的各个私有数据的具体数据,依次对SQL语句中的字段进行赋值,实现插入方式增加记录的数据操作The specific data of each private data obtained in turn, and the fields in the SQL statement are assigned in turn to realize the data operation of adding records by inserting
}}
public void update(AppRole obj)throws Exception//AppRole域对象作为参数,实现更新记录的数据操作public void update(AppRole obj)throws Exception//AppRole domain object is used as a parameter to implement the data operation of updating records
{{
初始定义,为了防止字段名和数据库中的关键字同名,在初始定义中定义字符串变量P,并在P中保存获取的数据库字段修饰符,如双引号,具体代码略Initial definition, in order to prevent the field name from having the same name as the keyword in the database, define a string variable P in the initial definition, and save the obtained database field modifiers in P, such as double quotation marks, the specific code is omitted
String sql=″update″+TABLE_NAME+″set″+P+″NAME″+P+″=?,″+P+″DESCRIPTION″+P+″=?,″+P+″GUID″+P+″=?,″+P+″CREATEDDATE″+P+″=?,″+P+″MODIFIEDDATE″+P+″=?,″+P+″READONLY″+P+″=?,″+P+″DISPLAYNAME″+P+″=?,″+P+″COORDINATORID″+P+″=?,″+P+″SHUXING2″+P+″=?,″+P+″SORTORDER″+P+″=?where″+P+″ID″+P+″=?″;//生成更新SQL语句String sql=″update″+TABLE_NAME+″set″+P+″NAME″+P+″=?, ″+P+″DESCRIPTION″+P+″=?, ″+P+″GUID″+P+″=?, ″+P+″ CREATEDDATE″+P+″=?, ″+P+″MODIFIEDDATE″+P+″=?, ″+P+″READONLY″+P+″=?, ″+P+″DISPLAYNAME″+P+″=?, ″+P+″COORDINATORID” +P+"=?, "+P+"SHUXING2"+P+"=?, "+P+"SORTORDER"+P+"=?where"+P+"ID"+P+"=?";//generate update SQL statement
依次获取的各个私有数据的具体数据,依次对SQL语句中的字段进行赋值,实现插入方式增加记录的数据操作The specific data of each private data is obtained in turn, and the fields in the SQL statement are assigned in turn to realize the data operation of adding records by inserting
}}
public void delete(long id)throws SQLException//通过主键删除表中与主键相应的记录,实现删除数据操作Public void delete(long id)throws SQLException//Delete the record corresponding to the primary key in the table through the primary key to realize the operation of deleting data
{ 初始定义省略{ Initial definition omitted
sql=″delete from″+TABLE_NAME+″where ID=″+id+″″;sql="delete from"+TABLE_NAME+"where ID="+id+"";
生成删除SQL语句,并基于该SQL语句执行删除,具体代码略Generate a delete SQL statement, and execute the delete based on the SQL statement, the specific code is abbreviated
}}
}}
基于上述方法流程,参阅附图2所示,本发明实施例中还提供一种在Java应用中进行数据操作的装置,主要由以下处理单元组成,Based on the above method flow, as shown in accompanying drawing 2, an embodiment of the present invention also provides a device for performing data operations in Java applications, which mainly consists of the following processing units,
第一处理单元201,用于从数据库中获取至少一个表的结构信息;The
第二处理单元202,用于将上述至少一个表的结构信息映射为域对象类文件和数据访问类文件;The
第三处理单元203,用于在接收到数据操作指示时,基于数据访问类文件包含的函数对域对象类文件进行数据操作。The
基于上述技术方案,本发明实施例中,在建立数据库连接后,从数据库中获取表的结构信息,将表的结构信息映射为域对象类文件和数据访问类文件,从而能够将数据库中表的结构信息映射为域对象类文件,即将表的结构转换为源代码的形式,将对数据库中表的数据操作映射为数据访问类文件,将针对表的数据操作转换为源代码的形式,在接收到数据操作指示时,基于数据库访问类文件包含的函数对域对象类文件进行数据操作,从而能够自动获取表中的记录,而无需人工读取数据库中的原始数据,从而提高了对象关系映射的效率和准确率。Based on the above technical solution, in the embodiment of the present invention, after the database connection is established, the structural information of the table is obtained from the database, and the structural information of the table is mapped to a domain object class file and a data access class file, so that the table in the database can be The structural information is mapped to the domain object class file, that is, the structure of the table is converted into the form of source code, the data operation on the table in the database is mapped into a data access class file, and the data operation on the table is converted into the form of source code. When the data operation instruction is received, the data operation is performed on the domain object class file based on the functions contained in the database access class file, so that the records in the table can be automatically obtained without manually reading the original data in the database, thereby improving the object-relational mapping. efficiency and accuracy.
显然,本领域的技术人员可以对本发明进行各种改动和变型而不脱离本发明的精神和范围。这样,倘若本发明的这些修改和变型属于本发明权利要求及其等同技术的范围之内,则本发明也意图包含这些改动和变型在内。Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and equivalent technologies thereof, the present invention also intends to include these modifications and variations.
Claims (10)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201010593313.4A CN102566990B (en) | 2010-12-09 | 2010-12-09 | Method and device for performing data manipulation in Java application |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201010593313.4A CN102566990B (en) | 2010-12-09 | 2010-12-09 | Method and device for performing data manipulation in Java application |
Publications (2)
Publication Number | Publication Date |
---|---|
CN102566990A true CN102566990A (en) | 2012-07-11 |
CN102566990B CN102566990B (en) | 2015-03-11 |
Family
ID=46412505
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201010593313.4A Expired - Fee Related CN102566990B (en) | 2010-12-09 | 2010-12-09 | Method and device for performing data manipulation in Java application |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN102566990B (en) |
Cited By (10)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN103020318A (en) * | 2013-01-10 | 2013-04-03 | 北京锐安科技有限公司 | Method for maintenance of database tables in database |
CN103942281A (en) * | 2014-04-02 | 2014-07-23 | 北京中交兴路车联网科技有限公司 | Method and device for operating object persistently stored |
CN104199907A (en) * | 2014-08-28 | 2014-12-10 | 广州华多网络科技有限公司 | Data inserting method and device |
CN104765596A (en) * | 2014-01-08 | 2015-07-08 | 腾讯科技(深圳)有限公司 | Request handling method and device |
CN106126224A (en) * | 2016-06-21 | 2016-11-16 | 浪潮软件集团有限公司 | Tool, system and method for generating program object |
CN108388588A (en) * | 2018-01-30 | 2018-08-10 | 福建星瑞格软件有限公司 | The offline read method of database functions and system of sql sentence Auto-Generation Tools |
CN109471619A (en) * | 2018-11-20 | 2019-03-15 | 北京千丁互联科技有限公司 | Mybatis code generating method, device and terminal |
CN109491649A (en) * | 2018-11-20 | 2019-03-19 | 北京千丁互联科技有限公司 | Dao code generating method and terminal |
CN109542453A (en) * | 2018-11-20 | 2019-03-29 | 北京千丁互联科技有限公司 | Database information recognition methods, device and terminal |
CN111966704A (en) * | 2020-07-09 | 2020-11-20 | 杭州传化智能制造科技有限公司 | ORM framework implementation method, system, computer equipment and storage medium |
Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101339559A (en) * | 2008-07-18 | 2009-01-07 | 北京航空航天大学 | A method for implementing data persistence |
CN101819530A (en) * | 2010-04-30 | 2010-09-01 | 山东中创软件工程股份有限公司 | Program object generation method and device and computer |
-
2010
- 2010-12-09 CN CN201010593313.4A patent/CN102566990B/en not_active Expired - Fee Related
Patent Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101339559A (en) * | 2008-07-18 | 2009-01-07 | 北京航空航天大学 | A method for implementing data persistence |
CN101819530A (en) * | 2010-04-30 | 2010-09-01 | 山东中创软件工程股份有限公司 | Program object generation method and device and computer |
Cited By (12)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN103020318A (en) * | 2013-01-10 | 2013-04-03 | 北京锐安科技有限公司 | Method for maintenance of database tables in database |
CN104765596A (en) * | 2014-01-08 | 2015-07-08 | 腾讯科技(深圳)有限公司 | Request handling method and device |
CN103942281A (en) * | 2014-04-02 | 2014-07-23 | 北京中交兴路车联网科技有限公司 | Method and device for operating object persistently stored |
CN103942281B (en) * | 2014-04-02 | 2017-07-25 | 北京中交兴路车联网科技有限公司 | The method and device that a kind of object to persistent storage is operated |
CN104199907A (en) * | 2014-08-28 | 2014-12-10 | 广州华多网络科技有限公司 | Data inserting method and device |
CN104199907B (en) * | 2014-08-28 | 2017-08-25 | 广州华多网络科技有限公司 | Insert the method and device of data |
CN106126224A (en) * | 2016-06-21 | 2016-11-16 | 浪潮软件集团有限公司 | Tool, system and method for generating program object |
CN108388588A (en) * | 2018-01-30 | 2018-08-10 | 福建星瑞格软件有限公司 | The offline read method of database functions and system of sql sentence Auto-Generation Tools |
CN109471619A (en) * | 2018-11-20 | 2019-03-15 | 北京千丁互联科技有限公司 | Mybatis code generating method, device and terminal |
CN109491649A (en) * | 2018-11-20 | 2019-03-19 | 北京千丁互联科技有限公司 | Dao code generating method and terminal |
CN109542453A (en) * | 2018-11-20 | 2019-03-29 | 北京千丁互联科技有限公司 | Database information recognition methods, device and terminal |
CN111966704A (en) * | 2020-07-09 | 2020-11-20 | 杭州传化智能制造科技有限公司 | ORM framework implementation method, system, computer equipment and storage medium |
Also Published As
Publication number | Publication date |
---|---|
CN102566990B (en) | 2015-03-11 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN102566990B (en) | Method and device for performing data manipulation in Java application | |
US10657112B2 (en) | External system integration into automated attribute discovery | |
US7412455B2 (en) | Software framework that facilitates design and implementation of database applications | |
US8402062B2 (en) | Data export/import from multiple data source to a destination data repository using corresponding data exporters and an importer | |
CN100557609C (en) | A kind of persistent layer generation method and device | |
US7136873B2 (en) | Dynamic filtering in a database system | |
US7359912B2 (en) | Result set formatting and processing | |
US7461053B2 (en) | System and interface for manipulating a database | |
CN103810275B (en) | Method and apparatus for data interaction between non-relation and relevant database | |
US20060195460A1 (en) | Data model for object-relational data | |
US20040015489A1 (en) | Querying an object for properties | |
US8838654B1 (en) | Data modeling system for runtime schema extensibility | |
US20040015496A1 (en) | Performing operations on a set of objects in a database system | |
US7523141B2 (en) | Synchronization operations involving entity identifiers | |
CN109753537A (en) | An Interactive Data Migration Method from Relational Data to Graph Data | |
CN102426582B (en) | Data manipulation management devices and data manipulation management method | |
US20120110021A1 (en) | Generating data models | |
CA2413183A1 (en) | System and method for sharing data between hierarchical databases | |
US20200364100A1 (en) | Memory abstraction for lock-free inter-process communication | |
US20040015473A1 (en) | Method for specifying and parsing expressions | |
CN103186628B (en) | A kind of mapping method between common information model and relevant database | |
CN103049251A (en) | Database persistent layer device and database operation method | |
CN105740383A (en) | Method and system for realizing data consistency of database and cache in big data platform | |
CN109194704A (en) | A kind of end B/S three-dimensional modeling data storage method, device and storage medium | |
CN110059086A (en) | Structuring automatic storage method based on IFC mode and its mapping model |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
C14 | Grant of patent or utility model | ||
GR01 | Patent grant | ||
CF01 | Termination of patent right due to non-payment of annual fee | ||
CF01 | Termination of patent right due to non-payment of annual fee |
Granted publication date: 20150311 Termination date: 20191209 |