Ibatis.net series (3) mapping file foundation

xiaoxiao2021-03-31  185

The core of IBATI is the mapping file (Data Map XML file). In the mapping file, it can be defined including the associated relationships and delay loading between the objects to perform various SQL statements, stored procedures, input parameter mappings, return results mapping, and can be implemented through several relatively complicated configurations. This is also the IBATI distinguished ORM framework, with more flexible, higher performance.

The profile can be written very simple or complicated. Complex configuration files are also for better design, better performance, and better scalability. The complex configuration file is also limited, one mapping file includes: mapped statements, parameter Maps, Result Maps, Cache Models, several main configurations, including namespace configuration, type alias (in the previous article) configuration .

1. Mapped Statements: As the name suggests is the statement declaration of the map. It is the core of the entire iBATIS configuration core, and the SQL statement (or stored procedure) that will be executed must be explicitly declared here. In the mapped statements, you can include: Statement, Select, Insert, Update, Delete, Procedure These 6 different statement types. It is believed that these types of functionality can be learned from the term understanding. Statement can contain all types of SQL statements (stored procedures), which is a general statement configuration, no particularly clear duties. On the contrary, other five types of statement configuration are specially responsible for a variety of different SQL statements. This picture lists the different responsibilities and call methods of various types of statements.

2. Parameter Maps: The configuration of the parameter map is used to provide the configuration of the required parameters to an statement. Every Parameter Maps has a ID that needs to provide its ID in the Statement's parametermap property when needed. But for a statement, it is not a must. In the form of Inline Parameter Maps in iBatis, we do not need to write a parameter MAPS configuration separately, just provide parameters to ParameterClass, which can be Yuan Data type, composite data type, Idictionary number of weak type objects (key values ​​for Key, Value). Only use the # proty # to access the corresponding attribute values ​​in the form of # printding.

Note: ParameterClass types used anywhere If you are a metad, string etc, you need to access its value in the form of # value #.

3. Result Maps: The mapping relationship configuration of the return result is the correspondence between column and attributes. Use the ResultMap attribute in Statement to specify a result mapping. For a Statement, Resultmap is not necessary, the same, it can still be replaced by Resultclass, because if it returns the result of the result data set with the same properties of the data object, it will automatically match, but it does not Ensure that all columns are mapped correctly (this value will not be processed when some column name is not found in the object. Resultmap is different. If you have defined in ResultMap, you will be considered an error in the resulting set or data object in ResultMap, it will be considered an error. Three statement types of INSERT, UPDATE, DELETE are not ResultMap and Resultclass, as in principle, in principle, is not necessary to return the result set. Note: If you specify the ResultMap and Resultclass properties while specifying the ResultMap and ResultClass properties, it will prioritize ResultMap. At the same time, Result Map is also an important means of implementing the complex query function, such as: Result Map inheritance (use with Discriminator), the object's 1..1, 1..n relationship query.

4. Cache Model: Cache Model. Using the Cache Model defines a cache mechanism, you can easily cache the data set returned by the Cachemodel property configured in the query statement. Three types of cache modifications (Memory, LRU, FIFO) algorithms are provided in Ibatis. The three algorithms are mainly different in static expiration strategies, and they have the same dynamic expired dependencies, which can set which statements can be set, and the cache expires.

Note: IBAITS's cache model is very easy to use, but because of the encapsulation of the expired policy, it has its limitations in multiple servers and load balancing scenarios.

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

New Post(0)