cn.lead2success.ddlutils.DMLHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ddlutils Show documentation
Show all versions of ddlutils Show documentation
Fork of Apache DdlUtils project without ant support.
package cn.lead2success.ddlutils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import javax.sql.DataSource;
import javax.sql.rowset.serial.SerialBlob;
import java.io.ByteArrayInputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.*;
/**
* DML生成、解析、执行器
*/
public class DMLHelper {
private final Log _log = LogFactory.getLog(DDLHelper.class);
public DataSource dataSource;
private Platform platform;
public DMLHelper(DataSource dataSource) {
this.dataSource = dataSource;
}
public void ececuteDml(String sqlContent, String dataContent) {
sqlContent.split("skip/update||aa,bb;");
String[] sqlArr = sqlContent.split(";");
String sqlHeader = sqlArr[0];
String[] headerArr = sqlHeader.split("||");
String mode = headerArr[0];
String[] pks = headerArr[1].split(",");
String sql = sqlArr[1];
}
/**
* sql解析,生成DmlSql对象
* @param sqlContent
* @return
*/
private DmlSql getSqlInfo(String sqlContent) {
try {
String[] sqlArr = sqlContent.split("]");
String mode = sqlArr[0].trim().replace("[", "").replace("]", "").trim();
String tableName = sqlArr[1].trim().replace("[", "").replace("]", "").trim();
String pkStr = sqlArr[2].trim().replace("[", "").replace("]", "").trim();
String[] pks = pkStr.split(",");
String sql = sqlArr[3];
String sqlStr = sql.split("\\(")[1];
sqlStr = sqlStr.split("\\)")[0];
String[] columns = sqlStr.split(",");
return new DmlSql(mode, tableName, Arrays.asList(pks), Arrays.asList(columns));
} catch (Exception e) {
throw new RuntimeException("SQL文件结构有误", e);
}
}
private List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy