@@ -20,13 +20,15 @@ public class MysqlUpsertAssembler implements UpsertAssembler {
2020 private final List <Tuple2 <EntityPropertyType <?, ?>, InParameter <?>>> insertValues ;
2121 private final List <Tuple2 <EntityPropertyType <?, ?>, UpsertSetValue >> setValues ;
2222 private final UpsertSetValue .Visitor upsertSetValueVisitor = new UpsertSetValueVisitor ();
23+ private final MysqlDialect .MySqlVersion version ;
2324
24- public MysqlUpsertAssembler (UpsertAssemblerContext context ) {
25+ public MysqlUpsertAssembler (UpsertAssemblerContext context , MysqlDialect . MySqlVersion version ) {
2526 this .buf = context .buf ;
2627 this .entityType = context .entityType ;
2728 this .duplicateKeyType = context .duplicateKeyType ;
2829 this .insertValues = context .insertValues ;
2930 this .setValues = context .setValues ;
31+ this .version = version ;
3032 this .upsertAssemblerSupport = new UpsertAssemblerSupport (context .naming , context .dialect );
3133 }
3234
@@ -50,7 +52,17 @@ public void assemble() {
5052 buf .appendSql (", " );
5153 }
5254 buf .cutBackSql (2 );
53- buf .appendSql (") " );
55+ switch (version ) {
56+ case V5 :
57+ buf .appendSql (") " );
58+ break ;
59+ case V8 :
60+ buf .appendSql (") as " );
61+ excludeAlias ();
62+ break ;
63+ default :
64+ throw new IllegalStateException (version .toString ());
65+ }
5466 if (duplicateKeyType == DuplicateKeyType .UPDATE ) {
5567 buf .appendSql (" on duplicate key update " );
5668 for (Tuple2 <EntityPropertyType <?, ?>, UpsertSetValue > setValue : setValues ) {
@@ -70,6 +82,11 @@ private void tableNameOnly(EntityType<?> entityType) {
7082 buf .appendSql (sql );
7183 }
7284
85+ private void excludeAlias () {
86+ String sql = this .upsertAssemblerSupport .excludeAlias ();
87+ buf .appendSql (sql );
88+ }
89+
7390 private void column (EntityPropertyType <?, ?> propertyType ) {
7491 String sql = this .upsertAssemblerSupport .prop (propertyType );
7592 buf .appendSql (sql );
@@ -83,12 +100,28 @@ public void visit(UpsertSetValue.Param param) {
83100
84101 @ Override
85102 public void visit (UpsertSetValue .Prop prop ) {
86- String sql =
87- upsertAssemblerSupport .excludeProp (
88- prop .propertyType , UpsertAssemblerSupport .ColumnNameType .NAME );
89- buf .appendSql ("values(" );
90- buf .appendSql (sql );
91- buf .appendSql (")" );
103+ switch (version ) {
104+ case V5 :
105+ {
106+ String sql =
107+ upsertAssemblerSupport .excludeProp (
108+ prop .propertyType , UpsertAssemblerSupport .ColumnNameType .NAME );
109+ buf .appendSql ("values(" );
110+ buf .appendSql (sql );
111+ buf .appendSql (")" );
112+ break ;
113+ }
114+ case V8 :
115+ {
116+ String sql =
117+ upsertAssemblerSupport .excludeProp (
118+ prop .propertyType , UpsertAssemblerSupport .ColumnNameType .NAME_ALIAS );
119+ buf .appendSql (sql );
120+ break ;
121+ }
122+ default :
123+ throw new IllegalStateException (version .toString ());
124+ }
92125 }
93126 }
94127}
0 commit comments