Commit 4f142907 authored by hewei's avatar hewei

对于Model生成WithBLOBs类时,upsert插件实现行为和官方插件保持一致

parent 2b88b81d
...@@ -169,7 +169,7 @@ public class SelectiveEnhancedPlugin extends BasePlugin { ...@@ -169,7 +169,7 @@ public class SelectiveEnhancedPlugin extends BasePlugin {
List<XmlElement> eles = this.findEle(xmlElement, "trim"); List<XmlElement> eles = this.findEle(xmlElement, "trim");
this.replaceEle(eles.get(0), "record."); this.replaceEle(eles.get(0), "record.");
// upsertByExampleSelective的第二个trim比较特殊,需另行处理 // upsertByExampleSelective的第二个trim比较特殊,需另行处理
this.replaceEleForUpsertByExampleSelective(eles.get(1), "record.", introspectedTable, false); this.replaceEleForUpsertByExampleSelective(eles.get(1), "record.", introspectedTable, !introspectedTable.getRules().generateRecordWithBLOBsClass());
List<XmlElement> eles1 = this.findEle(xmlElement, "set"); List<XmlElement> eles1 = this.findEle(xmlElement, "set");
for (XmlElement ele : eles1) { for (XmlElement ele : eles1) {
...@@ -280,15 +280,15 @@ public class SelectiveEnhancedPlugin extends BasePlugin { ...@@ -280,15 +280,15 @@ public class SelectiveEnhancedPlugin extends BasePlugin {
* @param element * @param element
* @param prefix * @param prefix
* @param introspectedTable * @param introspectedTable
* @param withBLOBs * @param allColumns
*/ */
private void replaceEleForUpsertByExampleSelective(XmlElement element, String prefix, IntrospectedTable introspectedTable, boolean withBLOBs) { private void replaceEleForUpsertByExampleSelective(XmlElement element, String prefix, IntrospectedTable introspectedTable, boolean allColumns) {
// choose // choose
XmlElement chooseEle = new XmlElement("choose"); XmlElement chooseEle = new XmlElement("choose");
// when // when
XmlElement whenEle = new XmlElement("when"); XmlElement whenEle = new XmlElement("when");
whenEle.addAttribute(new Attribute("test", prefix + "isSelective()")); whenEle.addAttribute(new Attribute("test", prefix + "isSelective()"));
for (IntrospectedColumn introspectedColumn : withBLOBs ? introspectedTable.getAllColumns() : introspectedTable.getNonBLOBColumns()) { for (IntrospectedColumn introspectedColumn : (allColumns ? introspectedTable.getAllColumns() : introspectedTable.getNonBLOBColumns())) {
XmlElement eleIf = new XmlElement("if"); XmlElement eleIf = new XmlElement("if");
eleIf.addAttribute(new Attribute("test", prefix + "isSelective(\'" + MyBatis3FormattingUtilities.getEscapedColumnName(introspectedColumn) + "\')")); eleIf.addAttribute(new Attribute("test", prefix + "isSelective(\'" + MyBatis3FormattingUtilities.getEscapedColumnName(introspectedColumn) + "\')"));
......
...@@ -340,6 +340,10 @@ public class UpsertPlugin extends BasePlugin { ...@@ -340,6 +340,10 @@ public class UpsertPlugin extends BasePlugin {
* @param introspectedTable * @param introspectedTable
*/ */
private void generateXmlElementWithoutBLOBs(Document document, IntrospectedTable introspectedTable){ private void generateXmlElementWithoutBLOBs(Document document, IntrospectedTable introspectedTable){
// WithoutBLOBs也会存在只有一个时,不生成WithBLOBs对象的情况
boolean flag = !introspectedTable.getRules().generateRecordWithBLOBsClass();
List<IntrospectedColumn> columns = flag ? introspectedTable.getAllColumns() : introspectedTable.getNonBLOBColumns();
// ====================================== 1. upsert ====================================== // ====================================== 1. upsert ======================================
XmlElement eleUpsert = new XmlElement("insert"); XmlElement eleUpsert = new XmlElement("insert");
eleUpsert.addAttribute(new Attribute("id", METHOD_UPSERT)); eleUpsert.addAttribute(new Attribute("id", METHOD_UPSERT));
...@@ -354,11 +358,11 @@ public class UpsertPlugin extends BasePlugin { ...@@ -354,11 +358,11 @@ public class UpsertPlugin extends BasePlugin {
// insert // insert
eleUpsert.addElement(new TextElement("insert into " + introspectedTable.getFullyQualifiedTableNameAtRuntime())); eleUpsert.addElement(new TextElement("insert into " + introspectedTable.getFullyQualifiedTableNameAtRuntime()));
eleUpsert.addElement(XmlElementGeneratorTools.generateKeys(introspectedTable.getNonBLOBColumns())); eleUpsert.addElement(XmlElementGeneratorTools.generateKeys(columns));
eleUpsert.addElement(new TextElement("values")); eleUpsert.addElement(new TextElement("values"));
eleUpsert.addElement(XmlElementGeneratorTools.generateValues(introspectedTable.getNonBLOBColumns())); eleUpsert.addElement(XmlElementGeneratorTools.generateValues(columns));
eleUpsert.addElement(new TextElement("on duplicate key update ")); eleUpsert.addElement(new TextElement("on duplicate key update "));
eleUpsert.addElement(XmlElementGeneratorTools.generateSets(introspectedTable.getNonBLOBColumns())); eleUpsert.addElement(XmlElementGeneratorTools.generateSets(columns));
document.getRootElement().addElement(eleUpsert); document.getRootElement().addElement(eleUpsert);
logger.debug("itfsw(存在即更新插件):" + introspectedTable.getMyBatis3XmlMapperFileName() + "增加upsert实现方法。"); logger.debug("itfsw(存在即更新插件):" + introspectedTable.getMyBatis3XmlMapperFileName() + "增加upsert实现方法。");
...@@ -377,11 +381,11 @@ public class UpsertPlugin extends BasePlugin { ...@@ -377,11 +381,11 @@ public class UpsertPlugin extends BasePlugin {
// insert // insert
eleUpsertSelective.addElement(new TextElement("insert into " + introspectedTable.getFullyQualifiedTableNameAtRuntime())); eleUpsertSelective.addElement(new TextElement("insert into " + introspectedTable.getFullyQualifiedTableNameAtRuntime()));
eleUpsertSelective.addElement(XmlElementGeneratorTools.generateKeysSelective(introspectedTable.getNonBLOBColumns())); eleUpsertSelective.addElement(XmlElementGeneratorTools.generateKeysSelective(columns));
eleUpsertSelective.addElement(new TextElement("values")); eleUpsertSelective.addElement(new TextElement("values"));
eleUpsertSelective.addElement(XmlElementGeneratorTools.generateValuesSelective(introspectedTable.getNonBLOBColumns())); eleUpsertSelective.addElement(XmlElementGeneratorTools.generateValuesSelective(columns));
eleUpsertSelective.addElement(new TextElement("on duplicate key update ")); eleUpsertSelective.addElement(new TextElement("on duplicate key update "));
eleUpsertSelective.addElement(XmlElementGeneratorTools.generateSetsSelective(introspectedTable.getNonBLOBColumns(), null, false)); eleUpsertSelective.addElement(XmlElementGeneratorTools.generateSetsSelective(columns, null, false));
document.getRootElement().addElement(eleUpsertSelective); document.getRootElement().addElement(eleUpsertSelective);
logger.debug("itfsw(存在即更新插件):" + introspectedTable.getMyBatis3XmlMapperFileName() + "增加upsertSelective实现方法。"); logger.debug("itfsw(存在即更新插件):" + introspectedTable.getMyBatis3XmlMapperFileName() + "增加upsertSelective实现方法。");
...@@ -400,8 +404,8 @@ public class UpsertPlugin extends BasePlugin { ...@@ -400,8 +404,8 @@ public class UpsertPlugin extends BasePlugin {
// insert // insert
eleUpsertByExample.addElement(new TextElement("insert into " + introspectedTable.getFullyQualifiedTableNameAtRuntime())); eleUpsertByExample.addElement(new TextElement("insert into " + introspectedTable.getFullyQualifiedTableNameAtRuntime()));
eleUpsertByExample.addElement(XmlElementGeneratorTools.generateKeys(introspectedTable.getNonBLOBColumns())); eleUpsertByExample.addElement(XmlElementGeneratorTools.generateKeys(columns));
this.generateExistsClause(introspectedTable, eleUpsertByExample, false, false); this.generateExistsClause(introspectedTable, eleUpsertByExample, false, flag);
// multiQueries // multiQueries
eleUpsertByExample.addElement(new TextElement(";")); eleUpsertByExample.addElement(new TextElement(";"));
...@@ -409,7 +413,7 @@ public class UpsertPlugin extends BasePlugin { ...@@ -409,7 +413,7 @@ public class UpsertPlugin extends BasePlugin {
// update // update
eleUpsertByExample.addElement(new TextElement("update " + introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime())); eleUpsertByExample.addElement(new TextElement("update " + introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime()));
eleUpsertByExample.addElement(new TextElement("set")); eleUpsertByExample.addElement(new TextElement("set"));
eleUpsertByExample.addElement(XmlElementGeneratorTools.generateSets(ListUtilities.removeIdentityAndGeneratedAlwaysColumns(introspectedTable.getNonBLOBColumns()), "record.")); eleUpsertByExample.addElement(XmlElementGeneratorTools.generateSets(ListUtilities.removeIdentityAndGeneratedAlwaysColumns(columns), "record."));
// update where // update where
eleUpsertByExample.addElement(XmlElementGeneratorTools.getUpdateByExampleIncludeElement(introspectedTable)); eleUpsertByExample.addElement(XmlElementGeneratorTools.getUpdateByExampleIncludeElement(introspectedTable));
...@@ -429,8 +433,8 @@ public class UpsertPlugin extends BasePlugin { ...@@ -429,8 +433,8 @@ public class UpsertPlugin extends BasePlugin {
// insert // insert
eleUpsertByExampleSelective.addElement(new TextElement("insert into " + introspectedTable.getFullyQualifiedTableNameAtRuntime())); eleUpsertByExampleSelective.addElement(new TextElement("insert into " + introspectedTable.getFullyQualifiedTableNameAtRuntime()));
eleUpsertByExampleSelective.addElement(XmlElementGeneratorTools.generateKeysSelective(introspectedTable.getNonBLOBColumns(), "record.")); eleUpsertByExampleSelective.addElement(XmlElementGeneratorTools.generateKeysSelective(columns, "record."));
this.generateExistsClause(introspectedTable, eleUpsertByExampleSelective, true, false); this.generateExistsClause(introspectedTable, eleUpsertByExampleSelective, true, flag);
// multiQueries // multiQueries
eleUpsertByExampleSelective.addElement(new TextElement(";")); eleUpsertByExampleSelective.addElement(new TextElement(";"));
...@@ -438,7 +442,7 @@ public class UpsertPlugin extends BasePlugin { ...@@ -438,7 +442,7 @@ public class UpsertPlugin extends BasePlugin {
// update // update
eleUpsertByExampleSelective.addElement(new TextElement("update " + introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime())); eleUpsertByExampleSelective.addElement(new TextElement("update " + introspectedTable.getAliasedFullyQualifiedTableNameAtRuntime()));
eleUpsertByExampleSelective.addElement(new TextElement("set")); eleUpsertByExampleSelective.addElement(new TextElement("set"));
eleUpsertByExampleSelective.addElement(XmlElementGeneratorTools.generateSetsSelective(ListUtilities.removeIdentityAndGeneratedAlwaysColumns(introspectedTable.getNonBLOBColumns()), "record.")); eleUpsertByExampleSelective.addElement(XmlElementGeneratorTools.generateSetsSelective(ListUtilities.removeIdentityAndGeneratedAlwaysColumns(columns), "record."));
// update where // update where
eleUpsertByExampleSelective.addElement(XmlElementGeneratorTools.getUpdateByExampleIncludeElement(introspectedTable)); eleUpsertByExampleSelective.addElement(XmlElementGeneratorTools.getUpdateByExampleIncludeElement(introspectedTable));
...@@ -454,12 +458,11 @@ public class UpsertPlugin extends BasePlugin { ...@@ -454,12 +458,11 @@ public class UpsertPlugin extends BasePlugin {
* @param introspectedTable * @param introspectedTable
* @param element * @param element
* @param selective * @param selective
* @param withBLOBs * @param allColumns
*/ */
private void generateExistsClause(IntrospectedTable introspectedTable, XmlElement element, boolean selective, boolean withBLOBs){ private void generateExistsClause(IntrospectedTable introspectedTable, XmlElement element, boolean selective, boolean allColumns){
List<IntrospectedColumn> columns = allColumns ? introspectedTable.getAllColumns() : introspectedTable.getNonBLOBColumns();
List<IntrospectedColumn> columns = withBLOBs ? introspectedTable.getAllColumns() : introspectedTable.getNonBLOBColumns();
logger.warn(withBLOBs + " ::::: " + columns.size());
element.addElement(new TextElement("select")); element.addElement(new TextElement("select"));
if (selective){ if (selective){
element.addElement(XmlElementGeneratorTools.generateValuesSelective(columns, "record.", false)); element.addElement(XmlElementGeneratorTools.generateValuesSelective(columns, "record.", false));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment