Ibatisnet Series (1) Total Overview

xiaoxiao2021-03-30  217

Learning and using iBatisnet has been a period of time, and there are some blogs related to IBATIS. I have also promised some friends to comprehensively introduce iBATIs, share their own learning processes and experience, and record some common and easily problems. However, due to the preparation of exams for some time, and the current project time progress is also tight, so it has not started to start, and apologize here, I hope not to be late. However, the recent community (blog garden) is constantly, I found that more and more people have begun to pay attention to ibatis, and there are also enthusiastic users to promote it, if you already have some understanding it, then you should read your Shanyou Article, the article he wrote may be more suitable for you. I am also an initiator. Some things recorded here may not have a lot of theoretical knowledge (the theoretical knowledge is not enough), more may be some problems that need to be solved for a long time in their own learning process, or It is a detail that individuals think is particularly important and easy to forget. The level is limited, there is a problem that there is inevitable, please call us if you are in this process, and please don't give you.

After returning, enter today's topic. Today's theme is the Chinese version of Introduction, unofficial official introduction, more detailed introduction, please refer to the official documentation. We must use it, you must know what it is to do, what work can be done for us, how to develop efficiency, how to perform efficiency, how to technical difficulties.

Ibatis mentioned, everyone may link ORM technology. Yes, it's right, it has a certain degree of contact with ORM technology, but it is more precisely that it is not a very orthodox ORM solution. Because it is unlike NHibernate, there is a fully automatic data operation, including query, insert, update, delete; there is also a close relationship with the constraint relationship of the database (not much about NHIBERNATE, if there is no Where you want to leave your stinky eggs, wait for the next use). Ibatis provides us with a more flexible and convenient and controlled way to implement class ORM solutions. We need yourself to control the SQL statement, which is good to do, we can more flexibly prepare more performance, functional advantageful SQL statements, but it is also the same obvious, we still need to manage and write SQL statements . But it is worth a happy thing that we only need to provide these SQL statements, and provide it with the parameters they need, there is no need to participate. This is also the core function of Ibatis, but it is also the most working for us. Depending on the configuration of the SQL statement and parameter conditions, it dynamically generates an executable SQL statement and then provides different specific values ​​for these SQL parameters depending on the specific passing parameter values. Then use the DBCommand to add DBPARAMETER to DBCommand, automatically execute the SQL statement, to generate and return one or more power type data class objects (Data Set IList Collection Objects) using iDataReader. I have seen similar to the implementation of the strong type data object in Community Server, but there is a lot of code that repeats the code more than DataTable directly. All of these in iBatis, only need to provide a configuration file, calling the method in the SQLMAPPER instance object it provides, it can be easily and easy. Of course, you may say that if the system is bigger, there may be a lot of configuration files. Yes, it is trapped in another extreme. How to do it? No way, fish and bear palms can't be both. I have to focus here. If you are often splicing the SQL statement during the stored procedure, then I will recommend you to use iBatis soon. If you mention the data operation, you can't mention the security and integrity issues of the data, that is, the transaction problem of data operations. If you use ADO.NET to use ADO.NET, you may need to write more code, of course we can use Enterprise Library to simplify our work. Then look at a simple code, look at how to implement transactions in iBatis:

Using (iDalSession session = sqlmap.begintransaction ())

{

Item item = (item) SQLMap.QueryForObject ("GetItem", itemid);

Item.description = newDescription;

SQLMap.Update ("UpdateItem", Item);

session.complete (); //commit

}

As soon as this simple code, it will help us automatically manage your business. During this period, we can still capture exception information if we appear.

OK, through the above introduction, we have been able to understand a probably. Summary, it helps us automatically manage and execute the SQL statement and return a strong type of data object. From a simple code from the above, you may have feeled how simple it is! And if you need to return to the generated dbcommand, we support us returns to DataTable or other ADO operations. However, at this time, you will have another doubt right away. Our work is still a lot, such as writing data classes and profiles, possibly workload is not asked directly using ADO.net to return the code written by DataTable, and will be more There is no technical content. So, for these code, we try to automatically generate a large part by some code generation tools (I am using CODesmith), and then modify according to what we need. Let's take a look at the execution efficiency, although Ibatis is more or less reflection technology, the performance impact has fallen to the lower due to the form of the configuration file. I have done a test, use it to add multiple records and use Updatedataset to submit data (the same data), the overall time efficiency is not worse, but will be faster.

Finally, it has to be mentioned, its caching mechanism is well done, the same SQL statement, can cache output data when performing queries with this condition according to different conditions values. Its buffer expiration strategy is closed. Detailed details, I believe that with the in-depth will be involved.

Introduction to it, the first step, the next article will first introduce its configuration working environment, focusing on how to use the log4net log log.

转载请注明原文地址:https://www.9cbs.com/read-130722.html

New Post(0)