iBATIS Plugin User Guide

 

   

     The iBATIS plugin is a plugin to accelerate iBATIS development in the IntelliJ IDEA environment. The iBATIS is not a particularly well-known framework, and plugins for iBATIS are few and between. Abator may be run as a plugin in Eclipse, but it is still only a code generator. The iBATIS plugin's aim to accelerate all-around development, such as SQL Map xml file editing, SQL Map statement navigation, code completion and so on. The following project in this manual is from the iBATIS website, and uses the "JPetStore 5.0 Example Application".

 

Now let's get started...
   

 1. Creating a datasource for the jPetStore application. Click "Tools" menu and select "Data Sources...". In the datasource setting dialog, create a new data source as follows:


 

[image]

 

 

     2. Add the iBATIS facet to the module. Open "Settings" and click  "Project Structure", and select the module, right click and select iBATIS facet support. 

 

[image]

3. In the iBATIS facet configuration tab, select a datasource. iBATIS plugin will use the datasource information for some features. If you want to use code generation feature, then you should take a look at templates.

[image]  
   Note: The iBATIS configuration xml file is the core of this plugin. If this file is missing, the plugin can't work. During project startup, the iBATIS plugin will scan the module looking for the configuration file in the source content directory. When the plugin finds the configuration file, it will parse this file and all SQL Map files in the configuration file.  
            If you want to use code generation feature, you should fill SQL Map file suffix to "-sqlmap.xml", and SQL Map package  to contains sqlmap xml file, and Bean package to include Java file. 

   4. Code completion for SQL Map configuration file, such as properties file or SQL Map files.

 

 

[image][image] 

   5. Code completion for SQL Map file, most references are supported now. If anything is not available, please report as a bug - thanks!

[image]
  6. Code completion for SqlMapClient method invocation. If you invoke  an insert method only insertable statement ids will be displayed, etc. The use of SqlMapClientTemplate in Spring is supported now.
 
[image] 
 7. Live templates: now the plugin use Spring's SqlMapClientTemplate for live template. If you use SqlMapClient for your own client, please modify the live template yourself. The followings are the introductions for all the templates:
   ibb: batch execution
   ibd: delete
   ibe: execute multi statements
   ibi:  insert
   ibl:  query for list
   ibm: query for map
   ibo:  query for object, please fill the the left side or return first.
   ibu:  update 
   [image] 
8. Table fields code completion. ResultMap is a very important element in the sql map file. If we want to implement table fields code completion for a domain object, first we add some meta information for domain class via the @table and @column javadoc tag, where the tag's value is the table name. iBATIS can find table information for this domain object. Please see the following diagrams.
[image] 
==>[image]
  [image]
Note: We want to introduce Java's annotation just like JPA, but iBATIS is different from these frameworks, so two javadoc tags are introduced instead: @table and @column.
9. Inline parameter and table column name completion in SQL sentence. If parameterClass is absent, the default parameter is "#value#".  Recursive field reference is also implemented, such as #first.second.three#. If you want to use column name completion, please fill the table information first, such as "from table1", "insert into table2", "update table3" for "delete from table4" and so on. Table alias also supported, but you should use following synax: tablename as tablealias. Code completion for table name has also been implemented for convenience. If you want to implement jdbc type completion for in line parameter, please press Ctrl+Space after ":". Now iBATIS plugin scans the SQL to get the table name and implement column name completion. Now this feature is not perfect, interface is not good enough. :)
   Note: If SQL code surrounded with CDATA, and code completion can not work.
[image]

10. Copy SQL code in statement. Now you want to copy the SQL code in statement and paste it into SQLPlus and execute it.  You should clean inline parameter first, and it is a trivial work. With "Copy SQL code in statement", and the plugin will clean the inline parameter for you and also fill with suitable type for SQL code. If #userId#'s type is java.lang.Integer, and it will be replaced with default number value 1. If it's type is String, and default value is ''. Clean inline parameter and filled with default value, it is the feature.  How to use it? Place a caret in statement, and right click mouse, and select "Copy SQL code".  When you press Ctrl+V, and clean SQL code will be pasted. 
[image]
  SQL code preview is another feature, and you can set inline parameter's value, and SQL code will updated dynamically, and you can copy the code to 'SQL Query Plugin' and execute it.
[image]
   For resultMap, the plugin will generate SQL select sentence according to columns and table name, and it is very useful for select generation.
[image]
11. Intention Action: Now iBATIS plugin contains two intention actions: generate result for resultMap and generate SQL code for select.  Put cursor in tag name, and press Alt+Enter;
      * Generate result for resultMap, and make resultMap mapping writting easy. 
     
[image]

      * Generate SQL select for select element with resultMap. if you want to write SQL sentence to return special resultMap, this intention will make it easy.
          
[image]
12. Statement xml code generation: it is an intention action, and it should be listed in previous paragraph. But I think it is very import, so it is here. :) Statement xml code generation action gives you another way to create statement xml code. You write SqlMapClient invocation code first, then action collects related information, such as statement id, result class, parameter class and operation, and creates statement xml code in a SQL Map file for you. The action works just like following:
[image]
    This can get tricky. The plug-in finds the destination SQL Map file according to statement id, so your statement id should indicate the file. Currently, the rules for finding the destination are as follows:
    1. The destination XML file must be listed in configuration file. (That should be OK, because there is an inspection to help make sure that it is.)
    2. If you have enabled name spaces and statement id includes a name space, then the plug-in can find a destination according to the name space. This should be the case most of the time (i.e., use name spaces!).
    3. If name spaces are not enabled, but your statement id contains a dot (like "category.getList"), the plug-in will split the statement id by the dot and compare the parts with XML file names, and if a file name contains a word, this file will be the destination file.
    4. If name spaces are not enabled, and your statement is just words concatenated together, such as "getCategoryList", the plug-in will split the statement id by camel cased words and compare the words with XML file names. If it finds a match, the file will be the destination file.
    5. Gah, at this point, if we don't have some sort of match...then we use the last SQL Map file in the SQL Map configuration file as the destination file.
    Note:  If you use generics in Java 5, it can help the plug-in to find the result class in collection. After the statement is created, the plug-in will open the SQL Map file and navigate to the new element. The caret is in the id attribute value. If you want to input SQL code, please press Shift+Enter to start new line and begin. Now absent statement id not hight light, and I will try to fix this problem soon. 
   If you have any idea to make the intention more convenient, please give me feedback. :)

13. Model  class generation: Now use "Model Creation" and you can create model class easy. A model class will be created with @table and @column meta information included. A sql map file will be created for this class at the same time.
   
[image]

14. Code inspection: Currently only three rules are implemented, although more inspections will be implemented soon. Your feedback is welcome. Inspection List:
     * SQL Map file not included by SQL Map configuration file
     * No nullValue attribute for the variable with primary data types.
     * Field absent in SQL select sentence when resultMap introduced.
     * Invalid inline parameter inspection
     * Inspection for parameterMap using
[image] 
[image]
  15. Other features: Goto Symbol.
 [image]
16. Find usages and rename refator for statment id: if you want to know how many usages for the statement id, please use Alt+F7 or Ctrl+Alt+F7. With this shortcut, you can find use usages with statement id anywhere. Rename refactor can make you change statement id, and all the ferenced statement id will be changed to the new name. Current renmae for typealias, parameterMap is not supported.
[image]
       
17. iBATIS config and SQL Map file structure viewer: it is a minor feature, and you can understand the information quickly in the xml file.
[image]
  18. Abator editing support. Abator is a code generator for iBATIS.  Abatis uses a core configuration and generates other codes, such as Java model class, SQL Map files and Java DAO. Now iBATIS plugin only supports Abator configuration xml file editing. Code generator action is on the way.
[image]
Summary:  Thanks for your reading. My English is not so good, and Gwyn sent me an email to correct this guide, Gwyn, thanks. If you have any feedback, please give me an email(linux_china at hotmail.com). Your help will make this plugin professional, and it will be all free for every iBATIS developer. 
Attention: iBATIS plugins use some features in IDEA 7051+ version, please download last EAP to try the experience.

 



You are viewing a mobilized version of this site...
View original page here

Mobilized by Mowser Mowser