iBATOR介紹,什麼是iBATOR?

iBATOR是一個代碼生成器,用於iBATIS。 iBATOR內部檢查的一個或多個數據庫表和將生成iBATIS的工件,可用於訪問表。

稍後,您可以編寫自定義的SQL代碼或存儲過程來滿足您的要求。 iBATOR產生以下項目:

  • SqlMap XML文件

  • Java類相匹配的表的主鍵和字段

  • 使用上述對象DAO類(可選)

iBATOR可以運行作爲一個獨立的JAR文件,或作爲一個Ant任務,或者作爲一個Eclipse插件。本教程將教你生成iBATIS的配置文件格式命令行的簡單的方法。

下載iBATOR:

如果您使用的IDE是Eclipse,比其他下載獨立的JAR。獨立的JAR包括一個Ant任務來運行iBATOR,或者您也可以從Java代碼中的命令行運行iBATOR。

Generating Configuration File:

To get up and running quickly with Abator, follow these steps:

Step 1:

Create and fill out a configuration file ibatorConfig.xml appropriately. At a minimum, you must specify:

  •  element to specify how to connect to the target database.

  •  element to specify target package and target project for generated Java model objects

  •  element to specify target package and target project for generated SQL map files.

  •  element to specify target package and target project for generated DAO interfaces and classes (you may omit the element if you don't wish to generate DAOs).

  • At least one database 

     element

    NOTE: See the XML Configuration File Reference page for an example of an Abator configuration file.

    Step 2:

    Save the file in some convenient location for example at: empibatorConfig.xml).

    Step 3:

    Now run Abator from the command line with a command line as follows:

    java -jar abator.jar -configfile empabatorConfig.xml -overwrite

    This will tell Abator to run using your configuration file. It will also tell Abator to overwrite any existing Java files with the same name. If you want to save any existing Java files, then omit the -overwriteparameter.

    If there is a conflict, Abator will save the newly generated file with a unique name.

    After running Abator, you will need to create or modify the standard iBATIS configuration files to make use of your newly generated code. This is explained in next section.

    Tasks After Running Abator:

    After you run Abator, you will need to create or modify other iBATIS configuration artifacts. The main tasks are as follows:

    • Create or Modify the SqlMapConfig.xml file.

    • Create or modify the dao.xml file (only if using the iBATIS DAO Framework).

    Each task is described in detail below:

    Updating the SqlMapConfig.xml File:

    iBATIS uses an XML file, commonly named SqlMapConfig.xml, to specify information for a database connection, a transaction management scheme, and SQL map XML files that will be used in an iBATIS session.

    Abator cannot create this file for you because Abator knows nothing about your execution environment. However, some of the items in this file relate directly to Abator generated items.

    Abator specific needs in the configuration file are as follows:

    • Statement namespaces must be enabled.

    • Abator generated SQL Map XML files must be listed .

    For example, suppose that Abator has generated an SQL Map XML file called MyTable_SqlMap.xml, and that the file has been placed in the test.xml package of your project. The SqlMapConfig.xml file should have these entries:

    <settings useStatementNamespaces="true" /> <transactionManager type="..."> <dataSource type="..."> <sqlMap resource="test/xml/MyTable_SqlMap.xml" />

    If there is more than one SQL Map XML file (as is quite common), then the files can be listed in any order with repeated elements after the element.

    Updating the dao.xml File:

    The iBATIS DAO framework is configured by an xml file commonly called dao.xml.

    The iBATIS DAO framework uses this file to control the database connection information for DAOs, and also to list the DAO implementation classes and DAO interfaces.

    In this file you should specify the path to your SqlMapConfig.xml file, and all the Abator generated DAO interfaces and implementation classes.

    For example, suppose that Abator has generated a DAO interface called MyTableDAO and a implementation class called MyTableDAOImpl, and that the files have been placed in the test.dao package of your project.

    dao.xml文件應該有這些項:

    <transactionManager type="SQLMAP"> <property name="SqlMapConfigResource" value="test/SqlMapConfig.xml"/> <dao interface="test.dao.MyTableDAO" implementation="test.dao.MyTableDAOImpl" />

    NOTE: This step is only required if you generated DAOs for the iBATIS DAO framework.


    Copyright © 2015-2023 億聚網.