CN102110111A - Method and system for processing database operating command - Google Patents
Method and system for processing database operating command Download PDFInfo
- Publication number
- CN102110111A CN102110111A CN2009102442072A CN200910244207A CN102110111A CN 102110111 A CN102110111 A CN 102110111A CN 2009102442072 A CN2009102442072 A CN 2009102442072A CN 200910244207 A CN200910244207 A CN 200910244207A CN 102110111 A CN102110111 A CN 102110111A
- Authority
- CN
- China
- Prior art keywords
- order
- database
- entityclass
- database manipulation
- operation command
- 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.)
- Pending
Links
- 238000000034 method Methods 0.000 title claims abstract description 38
- 238000012545 processing Methods 0.000 title abstract description 15
- 238000005538 encapsulation Methods 0.000 claims description 14
- 230000008569 process Effects 0.000 claims description 6
- 238000012217 deletion Methods 0.000 claims description 3
- 230000037430 deletion Effects 0.000 claims description 3
- 238000003780 insertion Methods 0.000 claims 1
- 230000037431 insertion Effects 0.000 claims 1
- 238000003672 processing method Methods 0.000 abstract description 8
- 230000002159 abnormal effect Effects 0.000 description 4
- 238000011161 development Methods 0.000 description 3
- 238000004458 analytical method Methods 0.000 description 2
- 230000008859 change Effects 0.000 description 2
- 238000010586 diagram Methods 0.000 description 2
- 230000000694 effects Effects 0.000 description 2
- 238000005516 engineering process Methods 0.000 description 2
- 230000010354 integration Effects 0.000 description 2
- 238000012423 maintenance Methods 0.000 description 2
- 238000012986 modification Methods 0.000 description 2
- 230000004048 modification Effects 0.000 description 2
- 238000012360 testing method Methods 0.000 description 2
- 230000005856 abnormality Effects 0.000 description 1
- 230000004888 barrier function Effects 0.000 description 1
- 238000013507 mapping Methods 0.000 description 1
- 238000005096 rolling process Methods 0.000 description 1
Images
Landscapes
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
本发明公开了一种数据库操作命令的处理方法及装置。其中,该方法包括:对数据库操作命令进行封装;对封装后的数据库操作命令进行调用。通过本发明,能够简便地实现对数据库的操作命令的处理。
The invention discloses a processing method and device for database operation commands. Wherein, the method includes: encapsulating the database operation command; calling the encapsulated database operation command. Through the present invention, the processing of the operation command to the database can be realized simply.
Description
技术领域technical field
本发明涉及计算机技术领域,具体而言,涉及一种数据库操作命令的处理方法及装置。The present invention relates to the field of computer technology, in particular to a method and device for processing database operation commands.
背景技术Background technique
本发明涉及数据库数据命令的处理方法的封装,为开发人员提供一种通用的数据库操作的方法,保证数据层操作的可重用性,统一性,从而保证系统的稳定。The invention relates to the encapsulation of the processing method of database data commands, provides developers with a general database operation method, ensures the reusability and unity of data layer operations, and thus ensures the stability of the system.
在项目开发的过程当中,项目组开发成员的编程风格差异和数据库操作语句SQL的灵活性给项目组带来了越来越多的操作和维护难度。比如:从user表中取出所有数据,有的人会写成select*fromuser;有的人会写成select all from user;有的人会写Select Name(所有的字段)from user。In the process of project development, the differences in programming styles of the project team development members and the flexibility of database operation statement SQL have brought more and more difficulties in operation and maintenance to the project team. For example: to fetch all the data from the user table, some people will write it as select*fromuser; some people will write it as select all from user; some people will write it as Select Name (all fields) from user.
虽然在操作中不会有任何的错误,但在其他人读程序的过程时就会产生不好的感觉,同时会产生冗余的代码,如果这种程序差异在项目中的数量级很多,那么在开发的过程当中程序就会出现各种各样的风格,维护的难度大大增加。Although there will be no errors in the operation, it will have a bad feeling when others read the program, and redundant code will be generated. If this program difference is many orders of magnitude in the project, then in During the development process, the program will appear in various styles, and the difficulty of maintenance is greatly increased.
目前,对于数据库操作封装用的最广的是Hibernate,优缺点如下。优点包括:抛弃了数据库中心的思想,完全的面向对象思想,不需要数据库知识,项目成员入门门槛低;缺点包括:在大量多表、复杂查询下难以驾驭,需要很深厚的功底;调试困难,不容易上手;映射复杂,集成环境比较烦锁。At present, Hibernate is the most widely used for database operation encapsulation. The advantages and disadvantages are as follows. The advantages include: abandoning the idea of the database center, complete object-oriented thinking, no need for database knowledge, and low entry barriers for project members; the disadvantages include: it is difficult to control under a large number of multi-table and complex queries, and requires a deep foundation; debugging is difficult, It is not easy to get started; the mapping is complicated, and the integration environment is more troublesome.
针对相关技术中对数据库的操作比较复杂的问题,目前尚未提出有效的解决方案。Aiming at the problem that the operation of the database is relatively complicated in the related art, no effective solution has been proposed yet.
发明内容Contents of the invention
针对相关技术中对数据库的操作比较复杂的问题而提出本发明,为此,本发明的主要目的在于提供一种数据库操作命令的处理方法及装置,以解决上述问题。The present invention is proposed to solve the problem of complex database operations in the related art. Therefore, the main purpose of the present invention is to provide a method and device for processing database operation commands to solve the above problems.
为了实现上述目的,根据本发明的一个方面,提供了一种数据库操作命令的处理方法。In order to achieve the above purpose, according to one aspect of the present invention, a method for processing database operation commands is provided.
根据本发明的数据库操作命令的处理方法包括:对数据库操作命令进行封装;对封装后的数据库操作命令进行调用。The processing method of the database operation command according to the present invention includes: encapsulating the database operation command; calling the encapsulated database operation command.
优选地,在对数据库操作命令进行封装之前,方法还包括:接收数据库操作命令。Preferably, before encapsulating the database operation command, the method further includes: receiving the database operation command.
优选地,数据库操作命令包括以下种类之一:插入操作命令、修改操作命令、删除操作命令、查询操作命令。Preferably, the database operation commands include one of the following types: insert operation commands, modify operation commands, delete operation commands, and query operation commands.
优选地,在数据库操作命令为插入操作命令、修改操作命令和删除操作命令之一的情况下,方法还包括:在执行数据库操作命令时判断是否存在异常;在存在异常的情况下,则进行数据回滚;在不存在异常的情况下,则提交数据。Preferably, when the database operation command is one of the insert operation command, modify operation command and delete operation command, the method further includes: judging whether there is an exception when executing the database operation command; Rollback; if there is no exception, submit the data.
优选地,在提交数据之后,方法还包括:返回对封装后的数据库操作命令进行调用的执行结果。Preferably, after the data is submitted, the method further includes: returning an execution result of calling the encapsulated database operation command.
优选地,在数据库操作命令为查询操作命令的情况下,方法还包括:在执行数据库操作命令时判断是否存在异常;在不存在异常的情况下,则返回执行查询操作命令的结果。Preferably, when the database operation command is a query operation command, the method further includes: judging whether there is an exception when executing the database operation command; if there is no exception, returning the result of executing the query operation command.
优选地,对封装后的数据库操作命令进行调用包括:创建数据库的实体类。Preferably, invoking the encapsulated database operation command includes: creating an entity class of the database.
优选地,对封装后的数据库操作命令进行调用包括设置用于调用的以下条件:调用数据库操作命令的表名、需要操作的字段、以及操作种类。Preferably, invoking the encapsulated database operation command includes setting the following conditions for invoking: the name of the table for invoking the database operation command, the field to be operated, and the type of operation.
为了实现上述目的,根据本发明的另一方面,提供了一种数据库操作命令的处理装置。In order to achieve the above purpose, according to another aspect of the present invention, a processing device for database operation commands is provided.
根据本发明的数据库操作命令的处理装置包括:封装模块,对数据库操作命令进行封装;调用模块,用于对封装后的数据库操作命令进行调用。The processing device of the database operation command according to the present invention includes: an encapsulation module for encapsulating the database operation command; and a calling module for invoking the encapsulated database operation command.
优选地,处理装置还包括:判断模块,用于判断在执行数据库操作命令时是否存在异常。Preferably, the processing device further includes: a judging module, configured to judge whether there is an abnormality when executing the database operation command.
通过本发明,采用对数据库操作命令进行封装;对封装后的数据库操作命令进行调用,解决了对数据库的操作比较复杂的问题,进而达到了简便地实现对数据库的操作的效果。Through the present invention, by encapsulating the database operation command and calling the encapsulated database operation command, the problem of relatively complicated operation on the database is solved, and the effect of simply realizing the operation on the database is achieved.
附图说明Description of drawings
此处所说明的附图用来提供对本发明的进一步理解,构成本申请的一部分,本发明的示意性实施例及其说明用于解释本发明,并不构成对本发明的不当限定。在附图中:The accompanying drawings described here are used to provide a further understanding of the present invention and constitute a part of the application. The schematic embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute improper limitations to the present invention. In the attached picture:
图1是根据本发明实施例的数据库操作命令的处理方法的流程图;Fig. 1 is the flow chart of the processing method of the database operation order according to the embodiment of the present invention;
图2是根据本发明实施例优选的数据库操作命令的处理方法的流程图;Fig. 2 is a flow chart of a preferred processing method of a database operation command according to an embodiment of the present invention;
图3是根据本发明实施例的数据库操作命令的处理装置的示意图。Fig. 3 is a schematic diagram of an apparatus for processing database operation commands according to an embodiment of the present invention.
具体实施方式Detailed ways
需要说明的是,在不冲突的情况下,本申请中的实施例及实施例中的特征可以相互组合。下面将参考附图并结合实施例来详细说明本发明。It should be noted that, in the case of no conflict, the embodiments in the present application and the features in the embodiments can be combined with each other. The present invention will be described in detail below with reference to the accompanying drawings and examples.
根据本发明的实施例,提供了一种数据库操作命令的处理方法及装置。According to an embodiment of the present invention, a method and device for processing a database operation command are provided.
图1是根据本发明实施例的数据库操作命令的处理方法的流程图。FIG. 1 is a flowchart of a method for processing database operation commands according to an embodiment of the present invention.
如图1所示,该方法包括如下的步骤S202至步骤S204:As shown in Figure 1, the method includes the following steps S202 to S204:
步骤S102,对数据库操作命令进行封装;Step S102, encapsulating the database operation command;
步骤S104,对封装后的数据库操作命令进行调用。Step S104, calling the encapsulated database operation command.
优选地,在对数据库操作命令进行封装之前,该方法还包括:接收数据库操作命令。Preferably, before encapsulating the database operation command, the method further includes: receiving the database operation command.
优选地,数据库操作命令包括以下种类之一:插入操作命令、修改操作命令、删除操作命令、查询操作命令。Preferably, the database operation commands include one of the following types: insert operation commands, modify operation commands, delete operation commands, and query operation commands.
优选地,在数据库操作命令为插入操作命令、修改操作命令和删除操作命令之一的情况下,该方法还包括:在执行数据库操作命令时判断是否存在异常;在存在异常的情况下,则进行数据回滚;在不存在异常的情况下,则提交数据。Preferably, when the database operation command is one of the insert operation command, modify operation command and delete operation command, the method also includes: judging whether there is an exception when executing the database operation command; The data is rolled back; if there is no exception, the data is submitted.
优选地,在提交数据之后,该方法还包括:返回对封装后的数据库操作命令进行调用的执行结果。Preferably, after the data is submitted, the method further includes: returning an execution result of calling the encapsulated database operation command.
优选地,在数据库操作命令为查询操作命令的情况下,该方法还包括:在执行数据库操作命令时判断是否存在异常;在不存在异常的情况下,则返回执行查询操作命令的结果。Preferably, when the database operation command is a query operation command, the method further includes: judging whether there is an exception when executing the database operation command; if there is no exception, returning the result of executing the query operation command.
优选地,对封装后的数据库操作命令进行调用包括:创建数据库的实体类。Preferably, invoking the encapsulated database operation command includes: creating an entity class of the database.
优选地,对封装后的数据库操作命令进行调用包括设置用于调用的以下条件:调用数据库操作命令的表名、需要操作的字段、以及操作种类。Preferably, invoking the encapsulated database operation command includes setting the following conditions for invoking: the name of the table for invoking the database operation command, the field to be operated, and the type of operation.
下面将结合实例对本发明实施例的实现过程进行详细描述。The implementation process of the embodiment of the present invention will be described in detail below with reference to examples.
图2是根据本发明实施例优选的数据库操作命令的处理方法的流程图。Fig. 2 is a flowchart of a preferred processing method of a database operation command according to an embodiment of the present invention.
本发明数据库操作命令的处理方法提供一种面对对象的数据库操作的封装方法,为开发人员提供统一的数据库操作的入口,提高软件开发的效率,从而提高软件的稳定性。对于数据库操作主要有四种:INSERT、UPDATE、DELETE、SELECT。The processing method of the database operation command of the present invention provides an object-oriented encapsulation method of the database operation, provides developers with a unified database operation entry, improves the efficiency of software development, and thus improves the stability of the software. There are four main types of database operations: INSERT, UPDATE, DELETE, and SELECT.
如图2所示,该方法包括如下步骤:As shown in Figure 2, the method includes the following steps:
步骤S201,创建实体类。数据库接收到操作请求之后,创建数据库的实体类;Step S201, creating an entity class. After the database receives the operation request, create the entity class of the database;
步骤S202,设置需要操作的数据库表名;Step S202, setting the name of the database table to be operated;
步骤S203,设置需要查询和修改的数据库字段和值;Step S203, setting database fields and values to be queried and modified;
步骤S204,设置条件(查询、修改、删除时);Step S204, setting conditions (when querying, modifying, deleting);
步骤S205,数据库数据命令处理,即对数据库进行相应操作;Step S205, database data command processing, that is, performing corresponding operations on the database;
步骤S206,插入INSET操作命令,之后转入步骤S210;Step S206, inserting the INSET operation command, and then turning to step S210;
步骤S207,修改UPDATE操作命令,之后转入步骤S210;Step S207, modify the UPDATE operation command, and then proceed to step S210;
步骤S208,删除DELETE操作命令,之后转入步骤S210;Step S208, delete the DELETE operation command, and then turn to step S210;
步骤S209,选择SELECT操作命令,之后转入步骤S211;Step S209, select the SELECT operation command, then proceed to step S211;
步骤S210,设置数据库操作命令自动提交;Step S210, setting the database operation command to submit automatically;
步骤S211,拼成SQL语句;Step S211, spelling SQL statements;
步骤S212,设置Prepared Statement数据;Step S212, setting Prepared Statement data;
步骤S213,执行数据库操作命令;Step S213, execute the database operation command;
步骤S214,判断操作命令是否有异常,如果异常转入步骤S215,否则,转入步骤S216;Step S214, judging whether the operation command is abnormal, if abnormal, go to step S215, otherwise, go to step S216;
步骤S215,回滚数据;Step S215, rolling back data;
步骤S216,提交数据,随后进入步骤S217;Step S216, submit the data, then enter step S217;
其中,步骤S218至步骤S221同步骤S211至步骤S214;Wherein, step S218 to step S221 are the same as step S211 to step S214;
步骤S221,判断操作命令是否有异常,如果异常结束该操作命令,否则,转入步骤S217;Step S221, judging whether the operation command is abnormal, if abnormal, end the operation command, otherwise, go to step S217;
步骤S217,返回结果。Step S217, return the result.
优选地,对该四个数据库操作进行实现的分析,这四种数据库操作的语句分析过程如下:Preferably, the analysis of the four database operations is implemented, and the statement analysis process of the four database operations is as follows:
插入INSERTinsert INSERT
INSERT语句如下:The INSERT statement is as follows:
INSERT INTO USER(SERID,USERNAME,PASSWORD)INSERT INTO USER(SERID, USERNAME, PASSWORD)
VALUES(100,‘test’,‘test’)VALUES(100, 'test', 'test')
对于Insert语句,主要是表名,字段名、字段值,我们建立一个实体类:For the Insert statement, mainly the table name, field name, and field value, we create an entity class:
类EntityClass是数据库表的实体类。Class EntityClass is the entity class of the database table.
private HashMap<String,Integer>intMap=null;//整型字段和值的mapprivate HashMap<String, Integer>intMap=null;//map of integer fields and values
private HashMap<String,String>stringMap=null;//字符串字段和值的mapprivate HashMap<String, String> stringMap=null; // map of string fields and values
private HashMap<String,Date>dateMap=null;//日期字段和值的。private HashMap<String, Date> dateMap=null; // date field and value.
private HashMap<String,Float>floatMap=null;//浮点型字段和值的private String tableName=null;//数据库表名private HashMap<String, Float>floatMap=null;//private String tableName=null for floating-point fields and values;//database table name
通过初始化设置类的表名,表示需要操作哪一个表,再设置字段值,这样就可以完成对数据库插入的操作,对于ID的生成可以用数据库自动生成或最大值加1。By initializing the table name of the setting class, it indicates which table needs to be operated, and then sets the field value, so that the operation of inserting into the database can be completed. For the ID generation, the database can be automatically generated or the maximum value can be increased by 1.
操作方法为:The operation method is:
EntityClass entityClass=new EntityClass(“USER”);EntityClass entityClass = new EntityClass("USER");
entityClass.put(“USERID”,”userid”);entityClass. put("USERID", "userid");
entityClass.put(“USERNAME”,”username”);entityClass. put("USERNAME", "username");
entityClass.put(“PASSWORD”,”password”);entityClass. put("PASSWORD","password");
EntityDAO.getInstance().save(entttyClass);EntityDAO.getInstance().save(entttyClass);
删除DELETEdelete DELETE
DELETE的语句如下:The DELETE statement is as follows:
DELETE FROM USER WHERE ID=123DELETE FROM USER WHERE ID=123
对于删除delete操作,只要一个表名和一个查询的条件即可,因些也可以用上面的实体类来封装。For the delete delete operation, only a table name and a query condition are required, so some of them can also be encapsulated by the above entity class.
封装方法为:The encapsulation method is:
EntityClass entityClass=new EntityClass(“USER”);EntityClass entityClass = new EntityClass("USER");
entityClass.setId(123);entityClass.setId(123);
EntityDAO.getInstance().delete(entityClass);EntityDAO.getInstance().delete(entityClass);
对于复杂的批量的删除也可以指定一个查询条件来删除,查询条件见查询SELETE语句,基本调用语句为:For complex batch deletion, you can also specify a query condition to delete. See the query SELETE statement for the query condition. The basic call statement is:
EntityDAO.getInstance().delete(entityClass,criteria);//criteria为查询条件。EntityDAO.getInstance().delete(entityClass, criteria); //criteria is the query condition.
修改UPDATEModify UPDATE
Update的语句如下:The Update statement is as follows:
UPDATE USER SET EMAIL=’aaa@aaa.com’WHERE ID=123UPDATE USER SET EMAIL=’aaa@aaa.com’ WHERE ID=123
对于update操作,有表名、要更新的字段名和值、更新的条件三个部分组成,因些也可以用上面的方法来封装,封装如下:For the update operation, it consists of three parts: the table name, the field name and value to be updated, and the update condition. Therefore, it can also be encapsulated by the above method. The package is as follows:
EntityClass entityClass=new EntityClass(“USER”);EntityClass entityClass = new EntityClass("USER");
entityClass.put(“EMAIL”,”aaa@aaa.com”);entityClass.put("EMAIL", "aaa@aaa.com");
entityClass.setId(123);entityClass.setId(123);
EntityDAO.getInstance().update(entityClass);EntityDAO.getInstance().update(entityClass);
同时,对于批量的更新也可以指定一个查询条件来更新,基本调用语句为:At the same time, for batch updates, you can also specify a query condition to update. The basic call statement is:
EntityDAO.getInstance().update(entityClass,criteria);//criteria为查询。EntityDAO.getInstance().update(entityClass, criteria); //criteria is the query.
查询SELECTQuerySELECT
Select的语句如下:The Select statement is as follows:
SELECT USERID,USERNAME,EMAIL FROM USER WHEREUSERNAME like=’%王%’;SELECT USERID, USERNAME, EMAIL FROM USER WHEREUSERNAME like='%王%';
对于update操作,有表名,查询的字段、查询的条件组成,查询的条件里也是字段名、条件、和字段值组成,所以查询条件类的定义如下:For the update operation, there are table names, query fields, and query conditions. The query conditions are also composed of field names, conditions, and field values, so the query condition class is defined as follows:
类Condition是条件类,主要有以下几个属性The class Condition is a conditional class, which mainly has the following attributes
private String fieldname=null;//字段名private String fieldname=null;//field name
private String stringValue=null;//字符串的字段值private String stringValue=null;//Field value of string
private Integer[]inIntList=null;//整型数组,用于in操作private Integer[]inIntList=null;//integer array, used for in operation
private String[]inStringList=null;//字符串数组,用于in操作private String[]inStringList=null;//String array, used for in operation
private Date dateValue=null;//日期的字段值private Date dateValue=null;// field value of date
private Integer intValue=null;//整型的字段值private Integer intValue=null;//integer field value
private Float floatValue=null;//浮点数private Float floatValue=null;//floating point number
类Criteria是条件的集合,主要有以下几种方法:Class Criteria is a collection of conditions, mainly has the following methods:
List<Condition>expressionlist=null;//查询条件列表List<Condition>expressionlist=null;//query condition list
List<Order>orderlist=null;//排序列表List<Order>orderlist=null;//Sorted list
类ConditionGroup条件组,通过ConditionGroup、Condition、Criteria三个类可以组成复杂的查询条件,满足各种数据库查询用。Class ConditionGroup condition group, through ConditionGroup, Condition, Criteria three classes can form complex query conditions, to meet various database queries.
封装方法如下:The encapsulation method is as follows:
EntityClass entityClass=new EntityClass(“USER”);EntityClass entityClass = new EntityClass("USER");
entityClass.putField(“USERID”);//设置查询字段entityClass.putField("USERID");//Set the query field
entityClass.putField(“USERNAME”);//设置查询字段entityClass.putField("USERNAME");//Set the query field
entityClass.putField(“EMAIL”);//设置查询字段entityClass.putField("EMAIL");//Set query field
Criteria criteria=new Criteria();Criteria criteria = new Criteria();
criteria.add(Expression.like(“USERNAME”,”王”));//设置like查询条件criteria.add(Expression.like("USERNAME","King"));//Set like query conditions
List<EntityClass>List<EntityClass>
list=EntityDAO.getInstance().findAll(entityClass,criteria);list = EntityDAO.getInstance().findAll(entityClass, criteria);
//criteria为查询条件。//criteria is the query condition.
返回结果为实体类的列表,对于多个表的查询,指定表名的时候可以指定多个表,同时查询的实体类也可以指定几个表相交的SQL条件。The returned result is a list of entity classes. For the query of multiple tables, multiple tables can be specified when specifying the table name. At the same time, the entity class of the query can also specify the SQL conditions for the intersection of several tables.
优选地,该方法基于JAVA环境下数据库操作的对象化封装,需要JDK1.5以上,优选的实施例如下:Preferably, the method is based on the object-based encapsulation of database operations in the JAVA environment, which requires JDK1.5 or above. Preferred embodiments are as follows:
优选地,以对数据表User进行增加、删除、修改、查询操作为例:Preferably, take adding, deleting, modifying, and querying the data table User as an example:
表User的数据结构为:The data structure of the table User is:
ID Number(10,0)NOT NULL PRIMARY KEY,ID Number(10, 0) NOT NULL PRIMARY KEY,
USERID VARCHAR2(40)NOT NULL,USERID VARCHAR2(40) NOT NULL,
USERNAME VARCHAR2(40)NOT NULL,USERNAME VARCHAR2(40) NOT NULL,
PAS SWORD VARCHAR2(20)NOT NULL,PAS SWORD VARCHAR2(20) NOT NULL,
EMAIL VARCHAR2(100)NULLEMAIL VARCHAR2(100)NULL
增加Increase
增加一条数据。Add a piece of data.
EntityClass entityClass=new EntityClass(“USER”);EntityClass entityClass = new EntityClass("USER");
entityClass.put(“USERID”,”userid”);entityClass. put("USERID", "userid");
entityClass.put(“USERNAME”,”username”);entityClass. put("USERNAME", "username");
entityClass.put(“PASSWORD”,”password”);entityClass. put("PASSWORD","password");
entityClass.put(“EMAIL”,”email”);entityClass. put("EMAIL","email");
EntityDAO.getInstance().save(entityClass);EntityDAO.getInstance().save(entityClass);
删除delete
删除一条ID为123的用户。Delete a user whose ID is 123.
EntityClass entityClass=new EntityClass(“USER”);EntityClass entityClass = new EntityClass("USER");
entityClass.setId(123);entityClass.setId(123);
EntityDAO.getInstance().delete(entityClass);EntityDAO.getInstance().delete(entityClass);
删除所有的姓“王“字的用户。Delete all users with the surname "王".
EntityClass entityClass=new EntityClass(“USER”);EntityClass entityClass = new EntityClass("USER");
Criteria criteria=new Criteria();Criteria criteria = new Criteria();
criteria.add(Expression.rightlike(“USERNAME”,”王”));//设置like查询条件。criteria.add(Expression.rightlike("USERNAME","King"));//Set like query conditions.
EntityDAO.getInstance().delete(entityClass,criteria);EntityDAO.getInstance().delete(entityClass, criteria);
修改Revise
把ID为123的用户的EMAIL修改成a.a@a.com。Change the EMAIL of the user whose ID is 123 to a.a@a.com.
EntityClass entityClass=new EntityClass(“USER”);EntityClass entityClass = new EntityClass("USER");
entityClass.put(“EMAIL”,”aaa@aaa.com”);entityClass.put("EMAIL", "aaa@aaa.com");
entityClass.setId(123);entityClass.setId(123);
EntityDAO.getInstance().update(entityClass);EntityDAO.getInstance().update(entityClass);
把所有姓王的EMAIL修改成a.a@a.com。Change all emails surnamed Wang to a.a@a.com.
EntityClass entityClass=new EntityClass(“USER”);EntityClass entityClass = new EntityClass("USER");
entityClass.put(“EMAIL”,”aaa@aaa.com”);entityClass.put("EMAIL", "aaa@aaa.com");
Criteria criteria=new Criteria();Criteria criteria = new Criteria();
criteria.add(Expression.rightlike(“USERNAME”,”王”));//设置like查询条件。criteria.add(Expression.rightlike("USERNAME","King"));//Set like query conditions.
EntityDAO.getInstance().update(entityClass,criteria);EntityDAO.getInstance().update(entityClass, criteria);
查询:Inquire:
查询所有姓王的用户:Query all users with the surname Wang:
EntityClass entityClass=new EntityClass(“USER”);EntityClass entityClass = new EntityClass("USER");
entityClass.putField(“*”);//设置查询字段。entityClass.putField("*");//Set the query field.
Criteria criteria=new Criteria();Criteria criteria = new Criteria();
criteria.add(Expression.rightlike(“USERNAME”,”王”));//设置like查询条件。criteria.add(Expression.rightlike("USERNAME","King"));//Set like query conditions.
List<EntityClass>List<EntityClass>
list=EntityDAO.getInstance().findAll(entityClass,criteria);list = EntityDAO.getInstance().findAll(entityClass, criteria);
//criteria为查询条件。//criteria is the query condition.
如果另外一个表(USERINFO)存在用户的年龄等其它信息,这个表有两个字段:If another table (USERINFO) has other information such as the user's age, this table has two fields:
ID NUMBER(10,0)NOT NULL,ID NUMBER(10,0) NOT NULL,
AGE NUMBER(3,0)NOT NULLAGE NUMBER(3,0) NOT NULL
调用方法如下:The calling method is as follows:
EntityClass entityClass=new EntityClass(“USER,USERINFO”);EntityClass entityClass = new EntityClass("USER, USERINFO");
entityClass.setJoinCondition(“USER.ID=USERINFO.ID);entityClass.setJoinCondition("USER.ID=USERINFO.ID);
entityClass.putField(“AGE”);//设置查询字段entityClass.putField("AGE");//Set the query field
entityClass.putField(“USERNAME”);//设置查询字段entityClass.putField("USERNAME");//Set the query field
entityClass.putField(“USERID”);//设置查询字段entityClass.putField("USERID");//Set the query field
entityClass.putField(“PASSWORD”);//设置查询字段entityClass.putField("PASSWORD");//Set the query field
Criteria criteria=new Criteria();Criteria criteria = new Criteria();
criteria.add(Expression.rightlike(“USERNAME”,”王”));//设置like查询条件。criteria.add(Expression.rightlike("USERNAME","King"));//Set like query conditions.
List<EntityClass>List<EntityClass>
list=EntityDAO.getInstance().findAll(entityClass,criteria);list = EntityDAO.getInstance().findAll(entityClass, criteria);
//criteria为查询条件。//criteria is the query condition.
从以上的描述中,可以看出,本发明实现了如下技术效果:利用现有技术实现数据库数据命令的对象化的处理方法,开发人员可以快速的掌握对数据库的编程,提高编程的效率,保证数据层操作的可重用性,从而提高软件的稳定性。包括对数据库的操作命令进行统一的封装,从而保证数据库操作层的可重用性,保证系统的稳定性;开发人员可以不管SQL语法就可以完成数据库的操作;所有的操作都用PreparedStatement,提高数据库操作的性能;调用简单,容易上手;集成环境简单;支持任意复杂的查询。From the above description, it can be seen that the present invention achieves the following technical effects: using the existing technology to realize the object-oriented processing method of database data commands, developers can quickly grasp the programming of the database, improve the efficiency of programming, and ensure The reusability of data layer operations improves the stability of the software. Including the uniform encapsulation of database operation commands to ensure the reusability of the database operation layer and the stability of the system; developers can complete database operations regardless of SQL syntax; all operations use PreparedStatement to improve database operations Excellent performance; simple call, easy to use; simple integration environment; support arbitrary complex queries.
根据本发明的实施例,提供了一种数据库操作命令的处理装置。According to an embodiment of the present invention, a processing device for a database operation command is provided.
需要说明的是,在附图的流程图示出的步骤可以在诸如一组计算机可执行指令的计算机系统中执行,并且,虽然在流程图中示出了逻辑顺序,但是在某些情况下,可以以不同于此处的顺序执行所示出或描述的步骤。It should be noted that the steps shown in the flowcharts of the accompanying drawings may be performed in a computer system, such as a set of computer-executable instructions, and that although a logical order is shown in the flowcharts, in some cases, The steps shown or described may be performed in an order different than here.
图3是根据本发明实施例的据库操作命令的处理装置的示意图。FIG. 3 is a schematic diagram of an apparatus for processing database operation commands according to an embodiment of the present invention.
如图3所示,该装置包括:封装模块301和调用模块302。As shown in FIG. 3 , the device includes: an encapsulation module 301 and a calling module 302 .
封装模块301,对数据库操作命令进行封装;Encapsulating module 301, encapsulating the database operation command;
调用模块302,用于对封装后的所述数据库操作命令进行调用。The calling module 302 is used to call the encapsulated database operation command.
优选地,所述处理装置还包括:判断模块303。Preferably, the processing device further includes: a judging module 303 .
判断模块303,用于判断在执行所述数据库操作命令时是否存在异常。A judging module 303, configured to judge whether there is an exception when executing the database operation command.
显然,本领域的技术人员应该明白,上述的本发明的各模块或各步骤可以用通用的计算装置来实现,它们可以集中在单个的计算装置上,或者分布在多个计算装置所组成的网络上,可选地,它们可以用计算装置可执行的程序代码来实现,从而,可以将它们存储在存储装置中由计算装置来执行,或者将它们分别制作成各个集成电路模块,或者将它们中的多个模块或步骤制作成单个集成电路模块来实现。这样,本发明不限制于任何特定的硬件和软件结合。Obviously, those skilled in the art should understand that each module or each step of the above-mentioned present invention can be realized by a general-purpose computing device, and they can be concentrated on a single computing device, or distributed in a network formed by multiple computing devices Optionally, they can be implemented with program codes executable by a computing device, so that they can be stored in a storage device and executed by a computing device, or they can be made into individual integrated circuit modules, or they can be integrated into Multiple modules or steps are fabricated into a single integrated circuit module to realize. As such, the present invention is not limited to any specific combination of hardware and software.
以上所述仅为本发明的优选实施例而已,并不用于限制本发明,对于本领域的技术人员来说,本发明可以有各种更改和变化。凡在本发明的精神和原则之内,所作的任何修改、等同替换、改进等,均应包含在本发明的保护范围之内。The above descriptions are only preferred embodiments of the present invention, and are not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and changes. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present invention shall be included within the protection scope of the present invention.
Claims (10)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN2009102442072A CN102110111A (en) | 2009-12-29 | 2009-12-29 | Method and system for processing database operating command |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN2009102442072A CN102110111A (en) | 2009-12-29 | 2009-12-29 | Method and system for processing database operating command |
Publications (1)
Publication Number | Publication Date |
---|---|
CN102110111A true CN102110111A (en) | 2011-06-29 |
Family
ID=44174274
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN2009102442072A Pending CN102110111A (en) | 2009-12-29 | 2009-12-29 | Method and system for processing database operating command |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN102110111A (en) |
Cited By (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102346774A (en) * | 2011-09-26 | 2012-02-08 | 深圳市信游天下网络科技有限公司 | Database operation method and device |
CN102360385A (en) * | 2011-10-14 | 2012-02-22 | 盛乐信息技术(上海)有限公司 | File searching method and system |
CN103577560A (en) * | 2013-10-24 | 2014-02-12 | 华为技术有限公司 | Method and device for inputting data base operating instructions |
CN103838574A (en) * | 2014-02-20 | 2014-06-04 | 浪潮集团山东通用软件有限公司 | General method for grouped summarizing of data tables |
CN104915383A (en) * | 2015-05-19 | 2015-09-16 | 中国电子科技集团公司第二十八研究所 | General method for automatic object adapting in database access |
CN106528256A (en) * | 2016-10-20 | 2017-03-22 | 国云科技股份有限公司 | A General Query Method of Entity BEAN Based on Java EJB Platform |
CN106610973A (en) * | 2015-10-21 | 2017-05-03 | 北京国双科技有限公司 | Television data query method and device |
CN114840551A (en) * | 2022-05-26 | 2022-08-02 | 中国平安财产保险股份有限公司 | Database table processing method and device, electronic equipment and storage medium |
Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1881242A (en) * | 2005-06-14 | 2006-12-20 | 张晓东 | Trans-enterprise supply chain system WEB application platform for automobile industry |
CN101110030A (en) * | 2007-08-23 | 2008-01-23 | 南京联创科技股份有限公司 | Developing method for data base persistence layer based on JAVA |
CN101256650A (en) * | 2008-03-21 | 2008-09-03 | 中国科学院软件研究所 | A business entity-based enterprise data extraction method and system |
-
2009
- 2009-12-29 CN CN2009102442072A patent/CN102110111A/en active Pending
Patent Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1881242A (en) * | 2005-06-14 | 2006-12-20 | 张晓东 | Trans-enterprise supply chain system WEB application platform for automobile industry |
CN101110030A (en) * | 2007-08-23 | 2008-01-23 | 南京联创科技股份有限公司 | Developing method for data base persistence layer based on JAVA |
CN101256650A (en) * | 2008-03-21 | 2008-09-03 | 中国科学院软件研究所 | A business entity-based enterprise data extraction method and system |
Non-Patent Citations (1)
Title |
---|
未知: "《使用XML封装数据库操作语句的实现》", 24 June 2005, HTTP://XIAORUANJIAN.ITEYE.COM/BLOG/1375221 * |
Cited By (11)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102346774A (en) * | 2011-09-26 | 2012-02-08 | 深圳市信游天下网络科技有限公司 | Database operation method and device |
CN102346774B (en) * | 2011-09-26 | 2013-09-18 | 深圳市信游天下网络科技有限公司 | Database operation method |
CN102360385A (en) * | 2011-10-14 | 2012-02-22 | 盛乐信息技术(上海)有限公司 | File searching method and system |
CN103577560A (en) * | 2013-10-24 | 2014-02-12 | 华为技术有限公司 | Method and device for inputting data base operating instructions |
CN103838574A (en) * | 2014-02-20 | 2014-06-04 | 浪潮集团山东通用软件有限公司 | General method for grouped summarizing of data tables |
CN104915383A (en) * | 2015-05-19 | 2015-09-16 | 中国电子科技集团公司第二十八研究所 | General method for automatic object adapting in database access |
CN104915383B (en) * | 2015-05-19 | 2018-03-02 | 中国电子科技集团公司第二十八研究所 | A kind of method of automatic adaptation object during Universal Database accesses |
CN106610973A (en) * | 2015-10-21 | 2017-05-03 | 北京国双科技有限公司 | Television data query method and device |
CN106528256A (en) * | 2016-10-20 | 2017-03-22 | 国云科技股份有限公司 | A General Query Method of Entity BEAN Based on Java EJB Platform |
CN106528256B (en) * | 2016-10-20 | 2019-06-21 | 国云科技股份有限公司 | Entity BEAN universal query method based on Java EJB platform |
CN114840551A (en) * | 2022-05-26 | 2022-08-02 | 中国平安财产保险股份有限公司 | Database table processing method and device, electronic equipment and storage medium |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN102110111A (en) | Method and system for processing database operating command | |
US8429601B2 (en) | Code completion for object relational mapping query language (OQL) queries | |
US7293254B2 (en) | Extensibility application programming interface and framework for meta-model objects | |
CN100578509C (en) | A method for implementing data persistence | |
US6243709B1 (en) | Method and apparatus for loading stored procedures in a database corresponding to object-oriented data dependencies | |
US8959106B2 (en) | Class loading using java data cartridges | |
US7873611B2 (en) | Boolean literal and parameter handling in object relational mapping | |
CN106126540B (en) | Data base access system and its access method | |
US10437564B1 (en) | Object mapping and conversion system | |
US20110161321A1 (en) | Extensibility platform using data cartridges | |
US8838654B1 (en) | Data modeling system for runtime schema extensibility | |
US9507820B1 (en) | Data modeling system for runtime schema extensibility | |
JPH0644128A (en) | Data base management system and method supporting object directional programming | |
US7996416B2 (en) | Parameter type prediction in object relational mapping | |
CN105447051A (en) | Database operation method and device | |
US9171036B2 (en) | Batching heterogeneous database commands | |
US10997131B1 (en) | Using a member attribute to perform a database operation on a computing device | |
US20070027849A1 (en) | Integrating query-related operators in a programming language | |
EP1040432A1 (en) | Method and apparatus for loading stored procedures in a database corresponding to object-oriented data dependencies | |
Yu | Embedded Internet of Things Applications of SQLite Based on WinCE Mobile Terminal | |
CN110647535A (en) | Method, terminal and storage medium for updating service data to Hive | |
Cobbs | Persistence programming | |
Roche et al. | Using the App Engine Datastore | |
CN114168144A (en) | Method and system for realizing connection of ES-JDBC and SQL-DML | |
CN119201076A (en) | A method for supporting custom business rules based on a low-code development platform |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
C12 | Rejection of a patent application after its publication | ||
RJ01 | Rejection of invention patent application after publication |
Application publication date: 20110629 |