SQLMAP file gadgets for generating Ibatis in Oralce

xiaoxiao2021-03-06  70

If the complete code or suggestion is required to send to zhobekui@eyou.com. Metadata class, can achieve corresponding data table information under Oralce, and generate file SQLMAP files * Currently generated IBATIS from database tables to iBATIS SQLMAP types Main SELECT, INSERT, UPDATE * Because of projects, just temporarily, No development of ResultMap and ParameterMap generation * Practice to develop this tool, graphize it, first listen to you, I hope to communicate with you. * Call the program, just call the getMetadata () method * Database configuration cn / card / mofit / demap-config.xml, * Modify the JDBC.Properties database configuration in the current directory It is possible to use its main class implementation method: package cn.com.mofit.util.jdbc; import java.io.File; import java.io.RIXCEPTION; import java.ioException; import java.io.reader; import java .sql.Connection; import java.sql.DatabaseMetaData; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; import java.sql.Types; import java. util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Vector; import org.springframework.dao.DataAccessException; import org.springframework.orm.ibatis.SqlMapClientTemplate; import cn.com. mofit.util.spring.orm.ibatis.SqlMapDaoSupportPlus; import com.ibatis.common.resources.Resources; import com.ibatis.sqlmap.client.SqlMapClient; import com.ibatis.sqlmap.engine.builder.xml.XmlSqlMapClientBuilder; / *** * @author Zhou Weikui * 2004-10-15 * @Email: zhobe @DepRecated metadata class, can achieve the corresponding data table information under Oralce, and generate file SQLMAP files * At present, IBATIS can be generated from the database table to the ibatis Sqlmap type. There is mainly SELECT, INSERT, UPDATE * Because the project is too urgent, it is only temporary, there is no development of ResultMap and ParameterMap generation * Practice plan to develop this tool, and graphically, first Listen to you, I hope to communicate with you.

* Call the program, just call the getMetadata () method * Database configuration cn / card / mofit / demap-config.xml, * Modify the JDBC.Properties database configuration in the current directory You can use the path name generated by * / public class rsmetataracle {/ ** filepath sqlmap file, is an absolute path * / private string filepath = "c: /"; / ** maptablename to map the table name * / private string maptablename = "BK_BILL"; // System.getProperty ( "user.dir") "/ config / sqlmap /"; private static SqlMapClientTemplate sqlTemp; static {try {SqlMapDaoSupportPlus sqlsu = new SqlMapDaoSupportPlus (); String resource = "cn / com /mofit/demo/system/dao/maps/sqlMap-config.xml";Reader read; read = Resources.getResourceAsReader (resource); XmlSqlMapClientBuilder xmlBuilder = new XmlSqlMapClientBuilder (); SqlMapClient sqlMap = xmlBuilder.buildSqlMap (read); sqlsu. setSqlMapClient (sqlMap); sqlsu.afterPropertiesSet (); sqlTemp = sqlsu.getSqlMapClientTemplate ();} catch (IOException e1) {e1.printStackTrace ();} catch (Exception e) {e.printStackTrace ();}} private static SqlMapClientTemplate GetsqlmapTempinstance () {return sqltemp;} public void getmetata () T hrows DataAccessException {try {//DaoCommon.startTransaction();SqlMapClientTemplate sqlTemp = RsMetaDataOracle.getSqlMapTempInstance (); // SqlMap sqlMap = DaoCommon.getSqlMap (this); Connection conn = sqlTemp.getDataSource () getConnection ();. Statement stmt = Conn.createStatement (); list list = gettablenames (); for (item t = list.iterator (); it.hasnext () {string element = (String) iter.next (); resultset = stmt.executeQuery (" Select * from " Element); ResultSetMetadata RSMD = rs.getMetadata (); int numberofcolumns = rsmd.getColumnCount ();

IF (Element.startSwith ())) {file file = new file (filepath); if (! file.exists ()) {file.mkdir ();} file = new file (FilePath Element.tolowerCase () ".xml"); string XML = " / n"; XML = " / n"; XML = (" / n"); XML = GetXML (RSMD, Numberofcolumns, ELEMENT); XML = "/ n "; FileWriter Writer = New FileWriter (File); Writer.write (XML); Writer.clush (); Writer.close ();}}} catch DataAccessException e) {e.printStackTrace ();} catch (SQLException e) {e.printStackTrace ();} catch (IOException e) {e.printStackTrace ();}} private String getXml (ResultSetMetaData rsmd, int numberOfColumns, String tableName ) throws sqlexception {string result = ""; result = (CreateFindsql (RSMD, NumberOfColumns, Tablename); Result = (CreateInsertsql (RSMD, Numberofcolumns, Tablena me)); result = (createUpdateSql (rsmd, numberOfColumns, tableName)); return result;} private String createfindSql (ResultSetMetaData rsmd, int numberOfColumns, String tableName) throws SQLException {String result;! result = "<- == =================================================== / n mapped-statement Find / n =

===================================================== -> "; Result = ("/ n

CopyRight © 2020 All Rights Reserved
Processed: 0.039, SQL: 9