File tree Expand file tree Collapse file tree 12 files changed +217
-9
lines changed
loader/plan/exec/query/internal Expand file tree Collapse file tree 12 files changed +217
-9
lines changed Original file line number Diff line number Diff line change 24
24
import java .util .Map ;
25
25
import java .util .Properties ;
26
26
import java .util .Set ;
27
+ import java .util .regex .Pattern ;
27
28
28
29
import org .hibernate .HibernateException ;
29
30
import org .hibernate .LockMode ;
@@ -140,6 +141,9 @@ public abstract class Dialect implements ConversionContext {
140
141
*/
141
142
public static final String CLOSED_QUOTE = "`\" ]" ;
142
143
144
+ private static final Pattern ESCAPE_CLOSING_COMMENT_PATTERN = Pattern .compile ( "\\ */" );
145
+ private static final Pattern ESCAPE_OPENING_COMMENT_PATTERN = Pattern .compile ( "/\\ *" );
146
+
143
147
private final TypeNames typeNames = new TypeNames ();
144
148
private final TypeNames hibernateTypeNames = new TypeNames ();
145
149
@@ -3002,6 +3006,14 @@ public String addSqlHintOrComment(
3002
3006
}
3003
3007
3004
3008
protected String prependComment (String sql , String comment ) {
3005
- return "/* " + comment + " */ " + sql ;
3009
+ return "/* " + escapeComment ( comment ) + " */ " + sql ;
3010
+ }
3011
+
3012
+ public static String escapeComment (String comment ) {
3013
+ if ( StringHelper .isNotEmpty ( comment ) ) {
3014
+ final String escaped = ESCAPE_CLOSING_COMMENT_PATTERN .matcher ( comment ).replaceAll ( "*\\ \\ /" );
3015
+ return ESCAPE_OPENING_COMMENT_PATTERN .matcher ( escaped ).replaceAll ( "/\\ \\ *" );
3016
+ }
3017
+ return comment ;
3006
3018
}
3007
3019
}
Original file line number Diff line number Diff line change @@ -187,7 +187,7 @@ public String toStatementString() {
187
187
StringBuilder buf = new StringBuilder ( guesstimatedBufferSize );
188
188
189
189
if ( StringHelper .isNotEmpty ( comment ) ) {
190
- buf .append ( "/* " ).append ( comment ).append ( " */ " );
190
+ buf .append ( "/* " ).append ( Dialect . escapeComment ( comment ) ).append ( " */ " );
191
191
}
192
192
193
193
buf .append ( "select " )
Original file line number Diff line number Diff line change 9
9
import java .util .LinkedHashMap ;
10
10
import java .util .Map ;
11
11
12
+ import org .hibernate .dialect .Dialect ;
13
+
12
14
/**
13
15
* An SQL <tt>DELETE</tt> statement
14
16
*
@@ -36,7 +38,7 @@ public Delete setTableName(String tableName) {
36
38
public String toStatementString () {
37
39
StringBuilder buf = new StringBuilder ( tableName .length () + 10 );
38
40
if ( comment !=null ) {
39
- buf .append ( "/* " ).append (comment ).append ( " */ " );
41
+ buf .append ( "/* " ).append ( Dialect . escapeComment ( comment ) ).append ( " */ " );
40
42
}
41
43
buf .append ( "delete from " ).append (tableName );
42
44
if ( where != null || !primaryKeyColumns .isEmpty () || versionColumnName != null ) {
Original file line number Diff line number Diff line change @@ -90,7 +90,7 @@ public Insert setTableName(String tableName) {
90
90
public String toStatementString () {
91
91
StringBuilder buf = new StringBuilder ( columns .size ()*15 + tableName .length () + 10 );
92
92
if ( comment != null ) {
93
- buf .append ( "/* " ).append ( comment ).append ( " */ " );
93
+ buf .append ( "/* " ).append ( Dialect . escapeComment ( comment ) ).append ( " */ " );
94
94
}
95
95
buf .append ("insert into " )
96
96
.append (tableName );
Original file line number Diff line number Diff line change @@ -65,7 +65,7 @@ public String toStatementString() {
65
65
66
66
StringBuilder buf = new StringBuilder ( (columnNames .size () * 15 ) + tableName .length () + 10 );
67
67
if ( comment !=null ) {
68
- buf .append ( "/* " ).append ( comment ).append ( " */ " );
68
+ buf .append ( "/* " ).append ( Dialect . escapeComment ( comment ) ).append ( " */ " );
69
69
}
70
70
buf .append ( "insert into " ).append ( tableName );
71
71
if ( !columnNames .isEmpty () ) {
Original file line number Diff line number Diff line change @@ -126,7 +126,7 @@ public void addOrderBy(String orderByString) {
126
126
public String toQueryString () {
127
127
StringBuilder buf = new StringBuilder ( 50 );
128
128
if ( comment != null ) {
129
- buf .append ( "/* " ).append ( comment ).append ( " */ " );
129
+ buf .append ( "/* " ).append ( Dialect . escapeComment ( comment ) ).append ( " */ " );
130
130
}
131
131
buf .append ( "select " );
132
132
if ( distinct ) {
Original file line number Diff line number Diff line change @@ -40,7 +40,7 @@ public Select(Dialect dialect) {
40
40
public String toStatementString () {
41
41
StringBuilder buf = new StringBuilder (guesstimatedBufferSize );
42
42
if ( StringHelper .isNotEmpty (comment ) ) {
43
- buf .append ("/* " ).append (comment ) .append (" */ " );
43
+ buf .append ( "/* " ).append ( Dialect . escapeComment ( comment ) ) .append ( " */ " );
44
44
}
45
45
46
46
buf .append ("select " ).append (selectClause )
Original file line number Diff line number Diff line change @@ -148,7 +148,7 @@ public String toStatementString() {
148
148
);
149
149
150
150
if ( comment != null ) {
151
- buf .append ( "/* " ).append ( comment ).append ( " */ " );
151
+ buf .append ( "/* " ).append ( Dialect . escapeComment ( comment ) ).append ( " */ " );
152
152
}
153
153
154
154
buf .append ( "select " );
Original file line number Diff line number Diff line change @@ -166,7 +166,7 @@ public Update setWhere(String where) {
166
166
public String toStatementString () {
167
167
StringBuilder buf = new StringBuilder ( (columns .size () * 15 ) + tableName .length () + 10 );
168
168
if ( comment !=null ) {
169
- buf .append ( "/* " ).append ( comment ).append ( " */ " );
169
+ buf .append ( "/* " ).append ( Dialect . escapeComment ( comment ) ).append ( " */ " );
170
170
}
171
171
buf .append ( "update " ).append ( tableName ).append ( " set " );
172
172
boolean assignmentsAppended = false ;
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Hibernate, Relational Persistence for Idiomatic Java
3
+ *
4
+ * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5
+ * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
6
+ */
7
+ package org .hibernate .test .comments ;
8
+
9
+ import javax .persistence .Entity ;
10
+ import javax .persistence .Id ;
11
+
12
+ /**
13
+ * @author Andrea Boriero
14
+ */
15
+ @ Entity
16
+ public class TestEntity {
17
+ @ Id
18
+ private String id ;
19
+
20
+ private String value ;
21
+
22
+ public TestEntity () {
23
+
24
+ }
25
+
26
+ public TestEntity (String id , String value ) {
27
+ this .id = id ;
28
+ this .value = value ;
29
+ }
30
+
31
+ public String getId () {
32
+ return id ;
33
+ }
34
+
35
+ public void setId (String id ) {
36
+ this .id = id ;
37
+ }
38
+
39
+ public String getValue () {
40
+ return value ;
41
+ }
42
+
43
+ public void setValue (String value ) {
44
+ this .value = value ;
45
+ }
46
+ }
You can’t perform that action at this time.
0 commit comments