From 7ddf4e9da9ea981aee01288875aee6326c515228 Mon Sep 17 00:00:00 2001 From: xujianxie Date: Mon, 14 Mar 2022 05:51:18 +0000 Subject: [PATCH] =?UTF-8?q?add=20src/main/java/com/jfinal/plugin/activerec?= =?UTF-8?q?ord/dialect/InformixDialect.=20infromix=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E6=96=B9=E8=A8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../activerecord/dialect/InformixDialect | 185 ++++++++++++++++++ 1 file changed, 185 insertions(+) create mode 100644 src/main/java/com/jfinal/plugin/activerecord/dialect/InformixDialect diff --git a/src/main/java/com/jfinal/plugin/activerecord/dialect/InformixDialect b/src/main/java/com/jfinal/plugin/activerecord/dialect/InformixDialect new file mode 100644 index 0000000..f67b03f --- /dev/null +++ b/src/main/java/com/jfinal/plugin/activerecord/dialect/InformixDialect @@ -0,0 +1,185 @@ +package com.jfinal.plugin.activerecord.dialect; +import com.jfinal.plugin.activerecord.Record; +import com.jfinal.plugin.activerecord.Table; +import com.jfinal.plugin.activerecord.dialect.Dialect; + +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.util.List; +import java.util.Map; +import java.util.Set; +public class InformixDialect extends Dialect { + public String forTableBuilderDoBuild(String tableName) { + return "select * from " + tableName + " where 1 = 2"; + } + + public void forModelSave(Table table, Map attrs, StringBuilder sql, List paras) { + sql.append("insert into ").append(table.getName()).append('('); + StringBuilder temp = new StringBuilder(") values("); + for (Map.Entry e: attrs.entrySet()) { + String colName = e.getKey(); + if (table.hasColumnLabel(colName)) { + if (paras.size() > 0) { + sql.append(", "); + temp.append(", "); + } + sql.append(colName); + temp.append('?'); + paras.add(e.getValue()); + } + } + sql.append(temp.toString()).append(')'); + } + + public String forModelDeleteById(Table table) { + String[] pKeys = table.getPrimaryKey(); + StringBuilder sql = new StringBuilder(45); + sql.append("delete from "); + sql.append(table.getName()); + sql.append(" where "); + for (int i=0; i 0) { + sql.append(" and "); + } + sql.append(pKeys[i]).append(" = ?"); + } + return sql.toString(); + } + + public void forModelUpdate(Table table, Map attrs, Set modifyFlag, StringBuilder sql, List paras) { + sql.append("update ").append(table.getName()).append(" set "); + String[] pKeys = table.getPrimaryKey(); + for (Map.Entry e : attrs.entrySet()) { + String colName = e.getKey(); + if (modifyFlag.contains(colName) && !isPrimaryKey(colName, pKeys) && table.hasColumnLabel(colName)) { + if (paras.size() > 0) { + sql.append(", "); + } + sql.append(colName).append(" = ? "); + paras.add(e.getValue()); + } + } + sql.append(" where "); + for (int i=0; i 0) { + sql.append(" and "); + } + sql.append(pKeys[i]).append(" = ?"); + paras.add(attrs.get(pKeys[i])); + } + } + + public String forModelFindById(Table table, String columns) { + StringBuilder sql = new StringBuilder("select ").append(columns).append(" from "); + sql.append(table.getName()); + sql.append(" where "); + String[] pKeys = table.getPrimaryKey(); + for (int i=0; i 0) { + sql.append(" and "); + } + sql.append(pKeys[i]).append(" = ?"); + } + return sql.toString(); + } + + public String forDbFindById(String tableName, String[] pKeys) { + tableName = tableName.trim(); + trimPrimaryKeys(pKeys); + + StringBuilder sql = new StringBuilder("select * from ").append(tableName).append(" where "); + for (int i=0; i 0) { + sql.append(" and "); + } + sql.append(pKeys[i]).append(" = ?"); + } + return sql.toString(); + } + + public String forDbDeleteById(String tableName, String[] pKeys) { + tableName = tableName.trim(); + trimPrimaryKeys(pKeys); + + StringBuilder sql = new StringBuilder("delete from ").append(tableName).append(" where "); + for (int i=0; i 0) { + sql.append(" and "); + } + sql.append(pKeys[i]).append(" = ?"); + } + return sql.toString(); + } + + public void forDbSave(String tableName, String[] pKeys, Record record, StringBuilder sql, List paras) { + tableName = tableName.trim(); + trimPrimaryKeys(pKeys); + + sql.append("insert into "); + sql.append(tableName).append('('); + StringBuilder temp = new StringBuilder(); + temp.append(") values("); + + for (Map.Entry e: record.getColumns().entrySet()) { + if (paras.size() > 0) { + sql.append(", "); + temp.append(", "); + } + sql.append(e.getKey()); + temp.append('?'); + paras.add(e.getValue()); + } + sql.append(temp.toString()).append(')'); + } + + public void forDbUpdate(String tableName, String[] pKeys, Object[] ids, Record record, StringBuilder sql, List paras) { + tableName = tableName.trim(); + trimPrimaryKeys(pKeys); + + sql.append("update ").append(tableName).append(" set "); + for (Map.Entry e: record.getColumns().entrySet()) { + String colName = e.getKey(); + if (!isPrimaryKey(colName, pKeys)) { + if (paras.size() > 0) { + sql.append(", "); + } + sql.append(colName).append(" = ? "); + paras.add(e.getValue()); + } + } + sql.append(" where "); + for (int i=0; i 0) { + sql.append(" and "); + } + sql.append(pKeys[i]).append(" = ?"); + paras.add(ids[i]); + } + } + + /** + * sql.replaceFirst("(?i)select", "") 正则中带有 "(?i)" 前缀,指定在匹配时不区分大小写 + */ + public String forPaginate(int pageNumber, int pageSize, StringBuilder findSql) { + int end = pageNumber * pageSize; + if (end <= 0) { + end = pageSize; + } + int begin = (pageNumber - 1) * pageSize; + if (begin < 0) { + begin = 0; + } + StringBuilder ret = new StringBuilder(); + ret.append(String.format("select skip %s first %s ", begin+"",pageSize+"")); + ret.append(findSql.toString().replaceFirst("(?i)select", "")); + return ret.toString(); + } + + public void fillStatement(PreparedStatement pst, List paras) throws SQLException { + fillStatementHandleDateType(pst, paras); + } + + public void fillStatement(PreparedStatement pst, Object... paras) throws SQLException { + fillStatementHandleDateType(pst, paras); + } +} \ No newline at end of file -- Gitee